]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
Simulation results using databoard
authorlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Thu, 10 Jun 2010 11:26:26 +0000 (11:26 +0000)
committerlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Thu, 10 Jun 2010 11:26:26 +0000 (11:26 +0000)
git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@16106 ac1ea38d-2e2b-0410-8846-a27921b304fc

22 files changed:
org.simantics.modelica/META-INF/MANIFEST.MF
org.simantics.modelica/src/org/simantics/modelica/data/SimulationResult.java
org.simantics.sysdyn.ui/adapters.xml
org.simantics.sysdyn.ui/plugin.xml
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/ExperimentLabeler.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/SimulationResult.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/SimulationResultDecorator.java [new file with mode: 0644]
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/SimulationResultLabeler.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/ExperimentNode.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/SimulationResultNode.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/NewModelHandler.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/SysdynExperimentActivator.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/ToggleResultActivation.java [new file with mode: 0644]
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/project/SysdynProject.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/TrendView.java
org.simantics.sysdyn/META-INF/MANIFEST.MF
org.simantics.sysdyn/src/org/simantics/sysdyn/SysdynResource.java
org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynDataSet.java [new file with mode: 0644]
org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynExperiment.java
org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynModel.java
org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynResult.java [new file with mode: 0644]
sysdyn_ontologies/sysdyn.graph

index 3a07eb40f65f8d4ccecac0d4d7b61429e5f05417..17b60bc2496e0b8c01e027d9d08826256fc4f915 100644 (file)
@@ -4,6 +4,7 @@ Bundle-Name: Modelica
 Bundle-SymbolicName: org.simantics.modelica
 Bundle-Version: 1.0.0.qualifier
 Bundle-RequiredExecutionEnvironment: JavaSE-1.6
-Require-Bundle: gnu.trove2;bundle-version="2.0.4"
+Require-Bundle: gnu.trove2;bundle-version="2.0.4",
+ org.simantics.databoard;bundle-version="0.5.2"
 Export-Package: org.simantics.modelica,
  org.simantics.modelica.data
index 888d2cee90860b1caa3ad658530806abf24000e3..6b0b44755d842d41a911095df1689e3d83d21f7f 100644 (file)
@@ -30,7 +30,8 @@ import java.util.regex.Pattern;
  */\r
 public class SimulationResult {    \r
 \r
-    List<DataSet> dataSets = new ArrayList<DataSet>();\r
+    List<DataSet> variables = new ArrayList<DataSet>();\r
+    List<DataSet> initials = new ArrayList<DataSet>();\r
 \r
     static String getLine(InputStream stream) {\r
         if(stream == null)\r
@@ -90,7 +91,7 @@ public class SimulationResult {
         \r
         for(String key : mappedInitials.keySet()) {\r
             double[] values = {mappedInitials.get(key), mappedInitials.get(key)};\r
-            dataSets.add(new DataSet(key, times , values));\r
+            initials.add(new DataSet(key, times , values));\r
         }\r
     }\r
 \r
@@ -130,25 +131,33 @@ public class SimulationResult {
                 values.add(Double.parseDouble(nn[1]));\r
             }\r
 \r
-            dataSets.add(new DataSet(name, times.toNativeArray(), values.toNativeArray()));\r
+            variables.add(new DataSet(name, times.toNativeArray(), values.toNativeArray()));\r
         }\r
     }\r
 \r
     public void filter() {\r
-        ArrayList<DataSet> newDataSets = new ArrayList<DataSet>();\r
-        for(DataSet dataSet : dataSets) {\r
-            if(!dataSet.name.equals("time") && !dataSet.name.contains("$") && !dataSet.name.contains("der("))\r
-                newDataSets.add(dataSet);\r
+        ArrayList<DataSet> newVariables = new ArrayList<DataSet>();\r
+        for(DataSet dataSet : variables) {\r
+            if(!dataSet.name.contains("$") && !dataSet.name.contains("der("))\r
+                newVariables.add(dataSet);\r
         }\r
-        dataSets = newDataSets;\r
+        variables = newVariables;\r
     }\r
 \r
-    public List<DataSet> getDataSets() {\r
-        return dataSets;\r
+    public List<DataSet> getVariableDataSets() {\r
+        return variables;\r
     }\r
 \r
+    /**\r
+     * Gets DataSet for variable. Loops first the variables and then initials.  \r
+     * @param name the name of the variable\r
+     * @return DataSet for the variable or null if DataSet not found\r
+     */\r
     public DataSet getDataSet(String name) {\r
-        for(DataSet set : dataSets)\r
+        for(DataSet set : variables)\r
+            if(set.name.equals(name))\r
+                return set;\r
+        for(DataSet set : initials)\r
             if(set.name.equals(name))\r
                 return set;\r
         return null;\r
index 7518623becf067e6cbe145abef620853c0175dfd..4b5529598a7614f442a76c8ef3d3c2561e690753 100644 (file)
@@ -25,5 +25,5 @@
                        <graph />\r
                        <this />\r
                </type>\r
-       </target>\r      \r       <target\r                interface="org.simantics.sysdyn.ui.browser.nodes.AbstractNode">\r                <type\r                  uri="http://www.simantics.org/Sysdyn-1.0/SysdynModel"\r                  class="org.simantics.sysdyn.ui.browser.nodes.ModelNode">\r                       <this />\r               </type>\r                \r               <type\r                  uri="http://www.simantics.org/Sysdyn-1.0/IndependentVariable"\r                  class="org.simantics.sysdyn.ui.browser.nodes.VariableNode">\r                    <this />\r               </type>\r                \r               <type\r                  uri="http://www.simantics.org/Simulation-1.0/Types/Experiment"\r                 class="org.simantics.sysdyn.ui.browser.nodes.ExperimentNode">\r                  <this />\r               </type>\r                \r               <type\r                  uri="http://www.simantics.org/Simulation-1.0/Types/Run"\r                        class="org.simantics.sysdyn.ui.browser.nodes.SimulationResultNode">\r                    <this />\r               </type>\r        </target>\r      \r
+       </target>\r      \r       <target\r                interface="org.simantics.sysdyn.ui.browser.nodes.AbstractNode">\r                <type\r                  uri="http://www.simantics.org/Sysdyn-1.0/SysdynModel"\r                  class="org.simantics.sysdyn.ui.browser.nodes.ModelNode">\r                       <this />\r               </type>\r                \r               <type\r                  uri="http://www.simantics.org/Sysdyn-1.0/IndependentVariable"\r                  class="org.simantics.sysdyn.ui.browser.nodes.VariableNode">\r                    <this />\r               </type>\r                \r               <type\r                  uri="http://www.simantics.org/Simulation-1.0/Types/Experiment"\r                 class="org.simantics.sysdyn.ui.browser.nodes.ExperimentNode">\r                  <this />\r               </type>\r                \r               <type\r                  uri="http://www.simantics.org/Sysdyn-1.0/Result"\r                       class="org.simantics.sysdyn.ui.browser.nodes.SimulationResultNode">\r                    <this />\r               </type>\r        </target>\r      \r
 </adapters>
\ No newline at end of file
index e7a97cbd598661f4d9096daedc4d21c2fad87795..402d10a1ed41bcab896b92952e742ce348adf2fb 100644 (file)
       </menuContribution>\r
       <menuContribution\r
             locationURI="popup:#SysdynBrowserPopup?after=wbStart">\r
+         <command\r
+               commandId="org.simantics.sysdyn.ui.activateResult"\r
+               id="org.simantics.sysdyn.ui.browser.activateResult"\r
+               label="Activate"\r
+               style="push">\r
+            <visibleWhen\r
+                  checkEnabled="true">\r
+               <with\r
+                     variable="selection">\r
+                  <test\r
+                        args="org.simantics.sysdyn.ui.browser.nodes.SimulationResultNode"\r
+                        property="org.simantics.sysdyn.ui.nodeClass">\r
+                  </test>\r
+               </with>\r
+            </visibleWhen>\r
+         </command>\r
          <dynamic\r
                class="org.simantics.ui.contribution.OpenWithMenuContribution"\r
                id="org.simantics.sysdyn.ui.browser.openWithMenu">\r
             id="org.simantics.sysdyn.ui.saveResults"\r
             name="Save Results">\r
       </command>\r
+      <command\r
+            defaultHandler="org.simantics.sysdyn.ui.handlers.ToggleResultActivation"\r
+            id="org.simantics.sysdyn.ui.activateResult"\r
+            name="Activate Result">\r
+      </command>\r
    </extension>\r
    <extension\r
          point="org.eclipse.ui.handlers">\r
          </implementation>\r
       </binding>\r
    </extension>\r
+   <extension\r
+         point="org.simantics.browsing.ui.common.labelDecoratorBinding">\r
+      <binding\r
+            browseContext="http://www.simantics.org/Sysdyn-1.0/Browser">\r
+         <implementation\r
+               class="org.simantics.sysdyn.ui.browser.contributions.SimulationResultDecorator"\r
+               preference="2.0">\r
+         </implementation>\r
+      </binding>\r
+   </extension>\r
    <extension\r
          point="org.eclipse.core.expressions.propertyTesters">\r
       <propertyTester\r
index 2e7b49f99fcb38b4993f2455809522c11dea4497..7779cc8329257fb9a7b4f8921948c1695603b670 100644 (file)
@@ -21,7 +21,7 @@ public class ExperimentLabeler extends LabelerContributor<ExperimentNode>{
 \r
     @Override\r
     public String getLabel(ReadGraph graph, ExperimentNode experiment) throws DatabaseException {\r
-        String name = graph.getPossibleRelatedValue(experiment.resource, graph.getBuiltins().HasName);\r
+        String name = graph.getPossibleRelatedValue(experiment.resource, graph.getBuiltins().HasLabel);\r
         return name == null ? "Experiment (no name)" : name;\r
     }\r
 \r
index d91d306bdd9b94102bc4278cfa982d7fb0de794d..7133bd17f95d9ba0ebaead3da509f9effe7ed3e6 100644 (file)
@@ -9,6 +9,7 @@ import org.simantics.db.ReadGraph;
 import org.simantics.db.Resource;\r
 import org.simantics.db.common.request.ObjectsWithType;\r
 import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.sysdyn.SysdynResource;\r
 import org.simantics.sysdyn.ui.browser.nodes.AbstractNode;\r
 import org.simantics.sysdyn.ui.browser.nodes.ExperimentNode;\r
 \r
@@ -18,7 +19,8 @@ public class SimulationResult  extends ViewpointContributor<ExperimentNode> {
     public Collection<?> getContribution(ReadGraph graph, ExperimentNode experiment) throws DatabaseException {\r
         ArrayList<AbstractNode> result = new ArrayList<AbstractNode>();\r
         Builtins b = graph.getBuiltins();\r
-        for(Resource r : graph.syncRequest(new ObjectsWithType(experiment.resource, b.ConsistsOf, b.Run))) {\r
+        SysdynResource sr = SysdynResource.getInstance(graph);\r
+        for(Resource r : graph.syncRequest(new ObjectsWithType(experiment.resource, sr.HasResult, sr.Result))) {\r
             try {\r
                 result.add(graph.adapt(r, AbstractNode.class));\r
             } catch(DatabaseException e) {\r
diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/SimulationResultDecorator.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/SimulationResultDecorator.java
new file mode 100644 (file)
index 0000000..78333c5
--- /dev/null
@@ -0,0 +1,26 @@
+package org.simantics.sysdyn.ui.browser.contributions;\r
+\r
+import org.simantics.browsing.ui.content.LabelDecorator;\r
+import org.simantics.browsing.ui.graph.contributor.labeler.LabelDecoratorContributor;\r
+import org.simantics.db.Builtins;\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.sysdyn.ui.browser.nodes.SimulationResultNode;\r
+\r
+public class SimulationResultDecorator extends LabelDecoratorContributor<SimulationResultNode>{\r
+\r
+    @Override\r
+    public LabelDecorator getDecorator(ReadGraph graph, SimulationResultNode result) throws DatabaseException {\r
+        Builtins b = graph.getBuiltins();\r
+        if (graph.hasStatement(result.resource, b.IsActive)) {\r
+            return new LabelDecorator.Stub() {\r
+                @Override\r
+                public String decorateLabel(String label, String column, int itemIndex) {\r
+                    return label + " [ACTIVE]";\r
+                }\r
+            };\r
+        }\r
+        return null;\r
+    }\r
+\r
+}\r
index cf5b808c181ef918a14e02bc19d70547905b8523..c74bb40496d3a958106a3a28615c3f39fb12eead 100644 (file)
@@ -9,7 +9,7 @@ public class SimulationResultLabeler extends LabelerContributor<SimulationResult
 \r
     @Override\r
     public String getLabel(ReadGraph graph, SimulationResultNode result) throws DatabaseException {\r
-        String name = graph.getPossibleRelatedValue(result.resource, graph.getBuiltins().HasName);\r
+        String name = graph.getPossibleRelatedValue(result.resource, graph.getBuiltins().HasLabel);\r
         return name == null ? "Experiment (no name)" : name;\r
     }\r
 \r
index e7286e1fac1bf7c930f3357f3ff1e88ad25ba87d..a04e596860fbd7d0d42bebf2b0a3fd463aea05e6 100644 (file)
  *******************************************************************************/\r
 package org.simantics.sysdyn.ui.browser.nodes;\r
 \r
+import org.simantics.browsing.ui.common.node.IDeletable;\r
 import org.simantics.browsing.ui.common.node.IDoubleClickableNode;\r
+import org.simantics.browsing.ui.common.node.IModifiableNode;\r
+import org.simantics.browsing.ui.content.Labeler.Modifier;\r
+import org.simantics.browsing.ui.graph.impl.LabelModifier;\r
 import org.simantics.db.Resource;\r
 import org.simantics.project.IProject;\r
 import org.simantics.simulation.project.IExperimentManager;\r
@@ -19,7 +23,7 @@ import org.simantics.sysdyn.ui.handlers.SysdynExperimentActivator;
 import org.simantics.ui.SimanticsUI;\r
 import org.simantics.utils.ui.ErrorLogger;\r
 \r
-public class ExperimentNode extends AbstractNode implements IDoubleClickableNode{\r
+public class ExperimentNode extends AbstractNode implements IDoubleClickableNode, IDeletable, IModifiableNode{\r
 \r
     public ExperimentNode(Resource resource) {\r
         super(resource);\r
@@ -38,5 +42,18 @@ public class ExperimentNode extends AbstractNode implements IDoubleClickableNode
         SysdynExperimentActivator.scheduleActivation(SimanticsUI.getSession(), project, experimentManager, resource);\r
         return true;\r
     }\r
+    \r
+    @Override\r
+    public Modifier getModifier(String columnId) {\r
+        LabelModifier modifier = new LabelModifier(SimanticsUI.getSession(), resource) {\r
+            @Override\r
+            public String isValid(String label) {\r
+                if (label.isEmpty())\r
+                    return "Empty label not allowed";\r
+                return null;\r
+            }\r
+        };\r
+        return modifier;\r
+    }\r
 \r
 }\r
index 28be114c04c2a76ec7936b8cb484c3113b18cba4..ef28f83e77c8755d366283c09acba607dd7334c0 100644 (file)
@@ -1,12 +1,29 @@
 package org.simantics.sysdyn.ui.browser.nodes;\r
 \r
 import org.simantics.browsing.ui.common.node.IDeletable;\r
+import org.simantics.browsing.ui.common.node.IModifiableNode;\r
+import org.simantics.browsing.ui.content.Labeler.Modifier;\r
+import org.simantics.browsing.ui.graph.impl.LabelModifier;\r
 import org.simantics.db.Resource;\r
+import org.simantics.ui.SimanticsUI;\r
 \r
-public class SimulationResultNode  extends AbstractNode implements IDeletable {\r
+public class SimulationResultNode  extends AbstractNode implements IDeletable, IModifiableNode {\r
 \r
     public SimulationResultNode(Resource resource) {\r
         super(resource);\r
     }\r
     \r
+    \r
+    @Override\r
+    public Modifier getModifier(String columnId) {\r
+        LabelModifier modifier = new LabelModifier(SimanticsUI.getSession(), resource) {\r
+            @Override\r
+            public String isValid(String label) {\r
+                if (label.isEmpty())\r
+                    return "Empty label not allowed";\r
+                return null;\r
+            }\r
+        };\r
+        return modifier;\r
+    }\r
 }\r
index bc71e8e74af73542b73e7978b566606adc150c50..06c34c2ae5531e6e377e3673a4ad8b9d8f333a6d 100644 (file)
@@ -61,12 +61,8 @@ public class NewModelHandler extends AbstractHandler {
                 Resource report = GraphUtils.create2(g, mu.b.Report,  mu.b.HasDocumentation, "===Report===");\r
 \r
                 Resource experiment = GraphUtils.create2(g, mu.b.Experiment,\r
-                        mu.b.HasName, "Experiment 1",\r
-                        mu.b.HasReportFactory, report,\r
-                        mu.b.PartOf, model);\r
-                \r
-                experiment = GraphUtils.create2(g, mu.b.Experiment,\r
-                        mu.b.HasName, "Experiment 2",\r
+                        mu.b.HasName, "Experiment",\r
+                        mu.b.HasLabel, "Experiment",\r
                         mu.b.HasReportFactory, report,\r
                         mu.b.PartOf, model);\r
             }\r
index 85823f834a2a6a83b8fb7ed768712d5467e09d69..fc5461a42219b2c019089061266cd0873506976f 100644 (file)
@@ -159,6 +159,7 @@ public class SysdynExperimentActivator {
                     for (IProjectElement member : ((IModelDescriptor) model).members()) {\r
                         if (member instanceof IExperimentDescriptor && experiment.equals(member.get())) {\r
                             model.setHint(ProjectKeys.KEY_SELECTED_EXPERIMENT, member);\r
+                            System.out.println("MOIOI" + member);\r
                             project.setHint(ProjectKeys.KEY_SELECTED_UI_EXPERIMENT, member);\r
                             break;\r
                         }\r
diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/ToggleResultActivation.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/ToggleResultActivation.java
new file mode 100644 (file)
index 0000000..6d9cf3f
--- /dev/null
@@ -0,0 +1,55 @@
+package org.simantics.sysdyn.ui.handlers;\r
+\r
+import org.eclipse.core.commands.AbstractHandler;\r
+import org.eclipse.core.commands.ExecutionEvent;\r
+import org.eclipse.core.commands.ExecutionException;\r
+import org.eclipse.jface.viewers.ISelection;\r
+import org.eclipse.ui.handlers.HandlerUtil;\r
+import org.simantics.db.Builtins;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.WriteGraph;\r
+import org.simantics.db.common.request.WriteRequest;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.sysdyn.SysdynResource;\r
+import org.simantics.ui.SimanticsUI;\r
+import org.simantics.ui.utils.ResourceAdaptionUtils;\r
+\r
+public class ToggleResultActivation extends AbstractHandler {\r
+\r
+    @Override\r
+    public Object execute(ExecutionEvent event) throws ExecutionException {\r
+        ISelection sel = HandlerUtil.getCurrentSelection(event);\r
+        Resource[] resources = ResourceAdaptionUtils.toResources(sel);\r
+        if (resources.length == 0)\r
+            return null;\r
+        \r
+        toggleActivation(resources);\r
+        \r
+        return null;\r
+    }\r
+\r
+    private void toggleActivation(final Resource[] resources) {\r
+        try {\r
+            SimanticsUI.getSession().syncRequest(new WriteRequest() {\r
+\r
+                @Override\r
+                public void perform(WriteGraph graph) throws DatabaseException {\r
+                    SysdynResource sr = SysdynResource.getInstance(graph);\r
+                    Builtins b = graph.getBuiltins();\r
+                    for(Resource r : resources) {\r
+                        if(graph.isInstanceOf(r, sr.Result)) {\r
+                            if (graph.hasStatement(r, b.IsActive)) {\r
+                                graph.deny(r, b.IsActive, r);\r
+                            } else {\r
+                                graph.claim(r, b.IsActive, r);\r
+                            }\r
+                        }\r
+                    }\r
+                }\r
+                \r
+            });\r
+        } catch (DatabaseException e) {\r
+            \r
+        }\r
+    }\r
+}\r
index bc58ec64e3b7f48f66ae2d091a2bc597e6d9d4ac..aeeaa4a598ad8cfd53e5fe9cad0da1dd177f25cd 100644 (file)
@@ -111,11 +111,7 @@ public class SysdynProject extends AbstractProjectFeature {
 \r
                 Resource experiment = GraphUtils.create2(g, mu.b.Experiment,\r
                         mu.b.HasName, "Experiment",\r
-                        mu.b.HasReportFactory, report,\r
-                        mu.b.PartOf, model);\r
-                \r
-                experiment = GraphUtils.create2(g, mu.b.Experiment,\r
-                        mu.b.HasName, "Experiment 2",\r
+                        mu.b.HasLabel, "Experiment",\r
                         mu.b.HasReportFactory, report,\r
                         mu.b.PartOf, model);\r
                 \r
index 13b91a111172891b3936aba144b44fadb30e5687..fc730f2994755b501a5a70f0aad4e71d74c97628 100644 (file)
@@ -12,6 +12,8 @@
 package org.simantics.sysdyn.ui.trend;\r
 \r
 import java.awt.Frame;\r
+import java.util.ArrayList;\r
+import java.util.Collection;\r
 import java.util.HashMap;\r
 import java.util.Set;\r
 \r
@@ -37,12 +39,12 @@ import org.simantics.db.Resource;
 import org.simantics.db.Session;\r
 import org.simantics.db.common.request.ReadRequest;\r
 import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.modelica.data.DataSet;\r
-import org.simantics.modelica.data.SimulationResult;\r
 import org.simantics.modeling.ModelingResources;\r
 import org.simantics.sysdyn.SysdynResource;\r
+import org.simantics.sysdyn.manager.SysdynDataSet;\r
 import org.simantics.sysdyn.manager.SysdynModel;\r
 import org.simantics.sysdyn.manager.SysdynModelManager;\r
+import org.simantics.sysdyn.manager.SysdynResult;\r
 import org.simantics.sysdyn.representation.IElement;\r
 import org.simantics.sysdyn.representation.Variable;\r
 import org.simantics.ui.SimanticsUI;\r
@@ -53,83 +55,88 @@ public class TrendView extends ViewPart {
 \r
     Frame frame;\r
     ChartPanel panel;\r
-    SysdynDataset sysdynDataset = new SysdynDataset();\r
-    \r
+    SysdynDatasets sysdynDatasets = new SysdynDatasets();\r
+\r
+\r
     @SuppressWarnings("serial")\r
-    class SysdynDataset extends AbstractXYDataset {\r
+    class SysdynDatasets extends AbstractXYDataset {\r
+\r
+        SysdynDataSet[] sets = new SysdynDataSet[0];\r
 \r
-        DataSet[] sets = new DataSet[0];\r
-        \r
-        public void setDatasets(DataSet[] sets) {\r
+        public void setDatasets(SysdynDataSet[] sets) {\r
             this.sets = sets;\r
             fireDatasetChanged();\r
         }\r
-        \r
+\r
         @Override\r
         public Number getY(int series, int item) {\r
             return sets[series].values[item];\r
         }\r
-        \r
+\r
         @Override\r
         public Number getX(int series, int item) {\r
             return sets[series].times[item];\r
         }\r
-        \r
+\r
         @Override\r
         public int getItemCount(int series) {\r
             return sets[series].times.length;\r
         }\r
-        \r
+\r
         @SuppressWarnings("unchecked")\r
         @Override\r
-        public Comparable getSeriesKey(int series) {\r
-            return sets[series].name;\r
+        public Comparable getSeriesKey(int series) {    \r
+            SysdynDataSet sds = sets[series];\r
+            if(sds.result == null)\r
+                return sds.name;\r
+            else\r
+                return sds.name + " : " + sds.result;\r
         }\r
-        \r
+\r
         @Override\r
         public int getSeriesCount() {            \r
             return sets.length;\r
         }\r
-        \r
+\r
     }\r
-    \r
+\r
     @Override\r
     public void createPartControl(Composite parent) {        \r
         final ActiveSelectionProvider selectionProvider = new ActiveSelectionProvider();\r
         getSite().setSelectionProvider(selectionProvider);\r
-        \r
+\r
         final Composite composite = new Composite(parent, \r
                 SWT.NO_BACKGROUND | SWT.EMBEDDED);\r
         frame = SWT_AWT.new_Frame(composite);\r
-        \r
+\r
         SwingUtilities.invokeLater(new Runnable() {\r
 \r
             @Override\r
             public void run() {              \r
                 XYPlot plot = new XYPlot(\r
-                        sysdynDataset,\r
+                        sysdynDatasets,\r
                         new NumberAxis("time"),\r
                         new NumberAxis("x"),\r
                         new XYLineAndShapeRenderer(true, false)\r
-                        );\r
-                \r
+                );\r
+\r
                 JFreeChart chart = new JFreeChart(plot);\r
                 panel = new ChartPanel(chart);\r
                 frame.add(panel);\r
-                             \r
+\r
                 panel.requestFocus();\r
             }\r
-            \r
+\r
         });\r
-        \r
+\r
         getSite().getWorkbenchWindow().getSelectionService().addPostSelectionListener(new ISelectionListener() {\r
-            \r
+\r
             @Override\r
             public void selectionChanged(IWorkbenchPart part, ISelection selection) {\r
                 if(selection.isEmpty() || Boolean.TRUE.equals(PinTrend.getState()))\r
                     return;\r
                 if(selection instanceof IStructuredSelection) {\r
-                       Set<Resource> ress = ISelectionUtils.filterSetSelection(selection, Resource.class);\r
+                    Set<Resource> ress = ISelectionUtils.filterSetSelection(selection, Resource.class);\r
 //                    Object[] els = ((IStructuredSelection) selection).toArray();\r
 //                    Resource[] resources = new Resource[els.length];\r
 //                    for(int i=0;i<els.length;++i) {\r
@@ -142,24 +149,24 @@ public class TrendView extends ViewPart {
                 }                \r
             }\r
         });\r
-                \r
-                /*composite.getDisplay().asyncExec(new Runnable() {\r
+\r
+        /*composite.getDisplay().asyncExec(new Runnable() {\r
 \r
                     @Override\r
                     public void run() {\r
                         // Do something\r
                     }\r
-                    \r
+\r
                 });*/            \r
     }\r
-    \r
+\r
     Resource[] resources;\r
-    \r
+\r
     protected void setSelection(Resource[] resources) {\r
         this.resources = resources;\r
         updateView();\r
     }\r
-    \r
+\r
     public void updateView() {\r
         Session session = SimanticsUI.peekSession();\r
         if (session == null)\r
@@ -168,39 +175,34 @@ public class TrendView extends ViewPart {
         session.asyncRequest(new ReadRequest() {\r
             @Override\r
             public void run(ReadGraph g) throws DatabaseException {\r
-                \r
-                final DataSet[] sets = new DataSet[resources.length];\r
-                for(int i=0;i<resources.length;++i) {\r
-                    try {\r
-                        sets[i] = load(g, resources[i]);\r
-                    } catch(Exception e) {\r
-                        e.printStackTrace();\r
-                        return;\r
-                    }\r
-                    if(sets[i] == null)\r
-                        return;\r
-                }\r
-                \r
+\r
+                final ArrayList<SysdynDataSet> datasets = new ArrayList<SysdynDataSet>();\r
+                for(Resource resource : resources) {\r
+                    Collection<SysdynDataSet> set = load(g, resource);\r
+                    if(set == null) return;\r
+                    datasets.addAll(load(g, resource));\r
+                }
+\r
                 SwingUtilities.invokeLater(new Runnable() {\r
 \r
                     @Override\r
                     public void run() {              \r
-                        sysdynDataset.setDatasets(sets);\r
+                        sysdynDatasets.setDatasets(datasets.toArray(new SysdynDataSet[datasets.size()]));\r
                     }\r
-                    \r
+\r
                 });\r
-               \r
+\r
             }\r
         });\r
     }\r
-    \r
+\r
     Runnable updater = new Runnable() {\r
         @Override\r
         public void run() {\r
             updateView();\r
         }        \r
     };\r
-    \r
+\r
     HashMap<Resource, SysdynModel> models = new HashMap<Resource, SysdynModel>(); \r
     protected SysdynModel getModel(ReadGraph g, Resource configuration) {\r
         synchronized(models) {\r
@@ -215,28 +217,32 @@ public class TrendView extends ViewPart {
             return model;\r
         }\r
     }\r
-    \r
-    protected DataSet load(ReadGraph g, Resource resource) throws DatabaseException {\r
+\r
+    protected Collection<SysdynDataSet> load(ReadGraph g, Resource resource) throws DatabaseException {\r
         Builtins b = g.getBuiltins();\r
         SysdynResource sr = SysdynResource.getInstance(g);\r
-        \r
+\r
         ModelingResources mr = ModelingResources.getInstance(g);\r
         Resource map = g.getPossibleObject(resource, mr.ElementToComponent);\r
         if(map != null) resource = map;\r
-        \r
+\r
         if(g.isInstanceOf(resource, sr.Variable)) {\r
             Resource configuration = g.getPossibleObject(resource, b.PartOf);\r
             if(g.isInstanceOf(configuration, sr.Configuration)) {\r
                 SysdynModel model = getModel(g, configuration);\r
                 if(model == null)\r
                     return null;\r
+\r
                 IElement element = model.getElement(resource);\r
                 if(element instanceof Variable) {\r
-                    Variable var = (Variable)element;                   \r
-                    SimulationResult result = model.getResult();\r
-                    if(result == null)\r
-                        return null;\r
-                    return result.getDataSet(var.getName());\r
+                    Variable var = (Variable)element;      \r
+\r
+                    Collection<SysdynResult> activeResults =  model.getActiveResults(g);\r
+                    ArrayList<SysdynDataSet> datasets = new ArrayList<SysdynDataSet>();\r
+                    for(SysdynResult r : activeResults) {\r
+                        datasets.add(r.getDataSet(var.getName()));\r
+                    }\r
+                    return datasets;\r
                 }                       \r
 \r
             }\r
index 473016548b1a335cf4d29e1f839eb0ed33b5b485..801b2fe2986bed356977d0cbffbae953e158971b 100644 (file)
@@ -13,7 +13,8 @@ Require-Bundle: org.simantics.objmap;bundle-version="0.1.0",
  org.eclipse.ui.console;bundle-version="3.4.0",
  org.eclipse.core.runtime;bundle-version="3.5.0",
  org.eclipse.jface;bundle-version="3.5.2",
- org.simantics.project;bundle-version="1.0.0"
+ org.simantics.project;bundle-version="1.0.0",
+ org.simantics.layer0.utils;bundle-version="0.8.0"
 Export-Package: org.simantics.sysdyn,
  org.simantics.sysdyn.expressionParser,
  org.simantics.sysdyn.manager,
index 668279e108956a71d77892b266cf53fd1fed48f0..3be2eda9527daef26bbff47fac35d4bb34279a0b 100644 (file)
@@ -44,6 +44,9 @@ public class SysdynResource {
     public final Resource HasMaxY;\r
     public final Resource HasMinX;\r
     public final Resource HasMinY;\r
+    public final Resource HasParameterFile;\r
+    public final Resource HasResult;\r
+    public final Resource HasResultFile;\r
     public final Resource HasStartTime;\r
     public final Resource HasStopTime;\r
     public final Resource HasTail;\r
@@ -61,6 +64,7 @@ public class SysdynResource {
     public final Resource ParameterExpression;\r
     public final Resource PhantomTerminal;\r
     public final Resource RefersTo;\r
+    public final Resource Result;\r
     public final Resource SimulateOnChangeExperiment;\r
     public final Resource Stock;\r
     public final Resource StockExpression;\r
@@ -101,6 +105,9 @@ public class SysdynResource {
         public static final String HasMaxY = "http://www.simantics.org/Sysdyn-1.0/HasMaxY";\r
         public static final String HasMinX = "http://www.simantics.org/Sysdyn-1.0/HasMinX";\r
         public static final String HasMinY = "http://www.simantics.org/Sysdyn-1.0/HasMinY";\r
+        public static final String HasParameterFile = "http://www.simantics.org/Sysdyn-1.0/HasParameterFile";\r
+        public static final String HasResult = "http://www.simantics.org/Sysdyn-1.0/HasResult";\r
+        public static final String HasResultFile = "http://www.simantics.org/Sysdyn-1.0/HasResultFile";\r
         public static final String HasStartTime = "http://www.simantics.org/Sysdyn-1.0/HasStartTime";\r
         public static final String HasStopTime = "http://www.simantics.org/Sysdyn-1.0/HasStopTime";\r
         public static final String HasTail = "http://www.simantics.org/Sysdyn-1.0/HasTail";\r
@@ -118,6 +125,7 @@ public class SysdynResource {
         public static final String ParameterExpression = "http://www.simantics.org/Sysdyn-1.0/ParameterExpression";\r
         public static final String PhantomTerminal = "http://www.simantics.org/Sysdyn-1.0/PhantomTerminal";\r
         public static final String RefersTo = "http://www.simantics.org/Sysdyn-1.0/RefersTo";\r
+        public static final String Result = "http://www.simantics.org/Sysdyn-1.0/Result";\r
         public static final String SimulateOnChangeExperiment = "http://www.simantics.org/Sysdyn-1.0/SimulateOnChangeExperiment";\r
         public static final String Stock = "http://www.simantics.org/Sysdyn-1.0/Stock";\r
         public static final String StockExpression = "http://www.simantics.org/Sysdyn-1.0/StockExpression";\r
@@ -168,6 +176,9 @@ public class SysdynResource {
         HasMaxY = getResourceOrNull(graph, URIs.HasMaxY);\r
         HasMinX = getResourceOrNull(graph, URIs.HasMinX);\r
         HasMinY = getResourceOrNull(graph, URIs.HasMinY);\r
+        HasParameterFile = getResourceOrNull(graph, URIs.HasParameterFile);\r
+        HasResult = getResourceOrNull(graph, URIs.HasResult);\r
+        HasResultFile = getResourceOrNull(graph, URIs.HasResultFile);\r
         HasStartTime = getResourceOrNull(graph, URIs.HasStartTime);\r
         HasStopTime = getResourceOrNull(graph, URIs.HasStopTime);\r
         HasTail = getResourceOrNull(graph, URIs.HasTail);\r
@@ -185,6 +196,7 @@ public class SysdynResource {
         ParameterExpression = getResourceOrNull(graph, URIs.ParameterExpression);\r
         PhantomTerminal = getResourceOrNull(graph, URIs.PhantomTerminal);\r
         RefersTo = getResourceOrNull(graph, URIs.RefersTo);\r
+        Result = getResourceOrNull(graph, URIs.Result);\r
         SimulateOnChangeExperiment = getResourceOrNull(graph, URIs.SimulateOnChangeExperiment);\r
         Stock = getResourceOrNull(graph, URIs.Stock);\r
         StockExpression = getResourceOrNull(graph, URIs.StockExpression);\r
diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynDataSet.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynDataSet.java
new file mode 100644 (file)
index 0000000..88ca787
--- /dev/null
@@ -0,0 +1,14 @@
+package org.simantics.sysdyn.manager;\r
+\r
+import org.simantics.modelica.data.DataSet;\r
+\r
+public class SysdynDataSet extends DataSet {\r
+\r
+    public String result;\r
+\r
+    public SysdynDataSet(String name, String result, double[] times, double[] values) {\r
+        super(name, times, values);\r
+        this.result = result;\r
+    }\r
+\r
+}\r
index 1297dba999d642ddec699336a8bf8be9c7062696..c89d0a63c6ffe5d4889e33a81ac9c7a8c9c720bf 100644 (file)
@@ -1,24 +1,39 @@
 package org.simantics.sysdyn.manager;\r
 \r
+import java.io.File;\r
+import java.util.ArrayList;\r
+import java.util.TreeMap;\r
+import java.util.UUID;\r
+\r
+import org.eclipse.core.runtime.Platform;\r
+import org.simantics.databoard.annotations.Optional;\r
+import org.simantics.databoard.binding.mutable.Variant;\r
+import org.simantics.db.Builtins;\r
 import org.simantics.db.ReadGraph;\r
 import org.simantics.db.Resource;\r
 import org.simantics.db.Session;\r
+import org.simantics.db.WriteGraph;\r
 import org.simantics.db.common.request.ReadRequest;\r
+import org.simantics.db.common.request.WriteRequest;\r
 import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.db.request.Read;\r
+import org.simantics.layer0.utils.direct.GraphUtils;\r
 import org.simantics.simulation.experiment.Experiment;\r
 import org.simantics.simulation.experiment.ExperimentState;\r
 import org.simantics.simulation.experiment.IDynamicExperiment;\r
+import org.simantics.sysdyn.SysdynResource;\r
 import org.simantics.sysdyn.simulation.SimulationScheduler;\r
 \r
 public class SysdynExperiment extends Experiment implements IDynamicExperiment {\r
 \r
     Session session;\r
     Runnable modificationListener;\r
+    Resource experiment;\r
+    SysdynModel sysdynModel;\r
+    SysdynResult result;\r
 \r
-    public SysdynExperiment(Resource model) {\r
+    public SysdynExperiment(Resource experiment, Resource model) {\r
         super(model);\r
-        System.out.println(this.getIdentifier());\r
+        this.experiment = experiment;\r
         // TODO Auto-generated constructor stub\r
     }\r
 \r
@@ -32,11 +47,33 @@ public class SysdynExperiment extends Experiment implements IDynamicExperiment {
     public void saveState() {\r
         // TODO Auto-generated method stub\r
         System.out.println("saveState");\r
+\r
+        try {\r
+            session.syncRequest(new WriteRequest() {\r
+\r
+                @Override\r
+                public void perform(WriteGraph graph) throws DatabaseException {\r
+                    File root = new File(Platform.getLocation().toOSString(), "www.simantics.org");\r
+                    if(!root.isDirectory())\r
+                        root.mkdir();\r
+                    File file = new File( root, UUID.randomUUID().toString() + ".dbb");\r
+                    Builtins b = graph.getBuiltins();\r
+                    SysdynResource sr = SysdynResource.getInstance(graph);\r
+                    Resource res = GraphUtils.create2(graph, sr.Result,\r
+                            b.HasLabel, "Result x",\r
+                            b.HasName, "Result x",\r
+                            sr.HasResultFile, file.getAbsolutePath());\r
+                    graph.claim(experiment, sr.HasResult, res);\r
+                    result.saveToFile(file);\r
+\r
+                }\r
+            });\r
+        } catch (DatabaseException e) {\r
+            e.printStackTrace();\r
+        }\r
     }\r
 \r
-    /**\r
-     * enabled: is simulate on change enabled\r
-     */\r
+\r
     @Override\r
     public void simulate(boolean enabled) {\r
         System.out.println("simulate");\r
@@ -47,31 +84,25 @@ public class SysdynExperiment extends Experiment implements IDynamicExperiment {
     }\r
 \r
 \r
-    private SysdynModel startSimulation() {\r
+    private void startSimulation() {\r
         try {\r
-            return session.syncRequest(new Read<SysdynModel>() {\r
+            session.syncRequest(new ReadRequest() {\r
 \r
                 @Override\r
-                public SysdynModel perform(ReadGraph graph) throws DatabaseException {\r
-                    final Resource configuration = graph.getPossibleObject(model, graph.getBuiltins().HasConfiguration);\r
-                    SysdynModel sysdynmodel = \r
-                        SysdynModelManager.getInstance(session).getModel(graph, configuration);\r
-                    SimulationScheduler.start(sysdynmodel);\r
-                    return sysdynmodel;\r
+                public void run(ReadGraph graph) throws DatabaseException {\r
+                    SimulationScheduler.start(sysdynModel);\r
                 }\r
             });\r
         } catch (DatabaseException e) {\r
             e.printStackTrace();\r
         }\r
-        return null;\r
     }\r
 \r
     public void toggleSimulation(boolean enabled) {\r
         if(enabled) {\r
             changeState(ExperimentState.RUNNING);\r
-            if(modificationListener == null) {       \r
-                SysdynModel sysdynModel = startSimulation();\r
-\r
+            if(modificationListener == null) {   \r
+                \r
                 modificationListener = new Runnable() {\r
 \r
                     @Override\r
@@ -81,10 +112,7 @@ public class SysdynExperiment extends Experiment implements IDynamicExperiment {
                             @Override\r
                             public void run(ReadGraph graph) throws DatabaseException {\r
                                 if(getState() == ExperimentState.RUNNING) {\r
-                                    Resource configuration = graph.getPossibleObject(model, graph.getBuiltins().HasConfiguration);\r
-                                    SysdynModel sysdynmodel = \r
-                                        SysdynModelManager.getInstance(session).getModel(graph, configuration);\r
-                                    SimulationScheduler.start(sysdynmodel);\r
+                                    SimulationScheduler.start(sysdynModel);\r
                                 }\r
 \r
                             }\r
@@ -117,6 +145,25 @@ public class SysdynExperiment extends Experiment implements IDynamicExperiment {
         System.out.println("init");\r
         changeState(ExperimentState.STOPPED);\r
         this.session = g.getSession();\r
+        result = new SysdynResult();\r
+        \r
+        session.asyncRequest(new ReadRequest() {\r
+            \r
+            @Override\r
+            public void run(ReadGraph graph) throws DatabaseException {\r
+                final Resource configuration = graph.getPossibleObject(model, graph.getBuiltins().HasConfiguration);\r
+                sysdynModel = SysdynModelManager.getInstance(session).getModel(graph, configuration);\r
+                sysdynModel.addResultListener(new Runnable() {\r
+                    \r
+                    @Override\r
+                    public void run() {\r
+                        result.setResult(sysdynModel.getSimulationResult());\r
+                    }\r
+                });\r
+            }\r
+        });\r
+        \r
+        \r
     }\r
 \r
     @Override\r
@@ -128,10 +175,7 @@ public class SysdynExperiment extends Experiment implements IDynamicExperiment {
 \r
                     @Override\r
                     public void run(ReadGraph graph) throws DatabaseException {\r
-                        final Resource configuration = graph.getPossibleObject(model, graph.getBuiltins().HasConfiguration);\r
-                        SysdynModel sysdynmodel = \r
-                            SysdynModelManager.getInstance(session).getModel(graph, configuration);\r
-                        sysdynmodel.removeModificationListener(modificationListener);\r
+                        sysdynModel.removeModificationListener(modificationListener);\r
                         modificationListener = null;\r
 \r
                     }\r
@@ -139,6 +183,54 @@ public class SysdynExperiment extends Experiment implements IDynamicExperiment {
                 break;\r
         }\r
     }\r
+  \r
+    public static class Sample {\r
+        public double value;\r
+        \r
+        @Override\r
+        public String toString() {\r
+            return ""+value;\r
+        }\r
+    }\r
+    \r
+    public static class Segment {\r
+        public int startTime, endTime;\r
+        public ArrayList<Sample> samples;\r
+        \r
+        @Override\r
+        public String toString() {\r
+            return "[startTime="+startTime+", endTime="+endTime+", samples="+samples+"]";\r
+        }\r
+        \r
+    }\r
+\r
+    public static class Recording {\r
+        public String id;\r
+        public TreeMap<String, String> labels;\r
+        public ArrayList<Segment> segments;\r
+        \r
+        @Override\r
+        public String toString() {\r
+            return "id="+id+", labels="+labels+", segments="+segments;\r
+        }\r
+    \r
+    }\r
+\r
+    public static class RecordingSession {\r
+        public @Optional Variant datasource;\r
+        public Variant timeVarialbeId;\r
+        public TreeMap<Variant, Variant> recordings;\r
+        \r
+        @Override\r
+        public String toString() {\r
+            return recordings.toString();\r
+        }\r
+    }\r
+    \r
+    public static class NodeId {\r
+        public String nodeId;\r
+    }\r
 \r
 \r
 }\r
+\r
index 65d31d32586dbc4e585a52eaa47da551d3166f0e..0d888a64b5eae03581c7ba32ac2bcba661ae6b58 100644 (file)
 package org.simantics.sysdyn.manager;\r
 \r
 import java.io.IOException;\r
+import java.util.ArrayList;\r
+import java.util.Collection;\r
 import java.util.HashMap;\r
 import java.util.Map;\r
 import java.util.concurrent.CopyOnWriteArrayList;\r
 \r
+import org.simantics.db.Builtins;\r
 import org.simantics.db.ReadGraph;\r
 import org.simantics.db.Resource;\r
 import org.simantics.db.Session;\r
@@ -30,6 +33,7 @@ import org.simantics.objmap.Mappings;
 import org.simantics.simulation.experiment.IExperiment;\r
 import org.simantics.simulation.model.IModel;\r
 import org.simantics.simulation.project.IExperimentActivationListener;\r
+import org.simantics.sysdyn.SysdynResource;\r
 import org.simantics.sysdyn.modelica.ModelicaWriter;\r
 import org.simantics.sysdyn.representation.Configuration;\r
 import org.simantics.sysdyn.representation.IElement;\r
@@ -72,8 +76,8 @@ public class SysdynModel implements IMappingListener, IModel {
             e.printStackTrace();\r
         }\r
     }\r
-    \r
-    \r
+\r
+\r
     /*\r
      * some dummy(?) stuff for experiments\r
      */\r
@@ -116,7 +120,7 @@ public class SysdynModel implements IMappingListener, IModel {
             return false;\r
     }\r
 \r
-    public SimulationResult getResult() {\r
+    public SimulationResult getSimulationResult() {\r
         return result;\r
     }\r
 \r
@@ -182,7 +186,7 @@ public class SysdynModel implements IMappingListener, IModel {
 \r
     @Override\r
     public IExperiment loadExperiment(ReadGraph g, Resource experiment, IExperimentActivationListener listener) {\r
-        SysdynExperiment exp = new SysdynExperiment(configurationResource);\r
+        SysdynExperiment exp = new SysdynExperiment(experiment, configurationResource);\r
         try {\r
             exp.init(g);\r
             listener.onExperimentActivated(exp);\r
@@ -192,4 +196,36 @@ public class SysdynModel implements IMappingListener, IModel {
             return null;\r
         }\r
     }   \r
+\r
+    public Collection<SysdynResult> getActiveResults(ReadGraph graph) {\r
+        ArrayList<SysdynResult> results = new ArrayList<SysdynResult>();\r
+\r
+        try {\r
+            Builtins b = graph.getBuiltins();\r
+            SysdynResource sr = SysdynResource.getInstance(graph);\r
+            Resource model = graph.getSingleObject(configurationResource, b.IsConfigurationOf);\r
+            Collection<Resource> experiments = graph.getObjects(model, b.ConsistsOf);\r
+            for(Resource experiment : experiments) {\r
+                Collection<Resource> experimentResults = graph.getObjects(experiment, sr.HasResult);\r
+                for(Resource result : experimentResults) {\r
+                    if(graph.hasStatement(result, b.IsActive)) {\r
+                        SysdynResult sysdynResult = new SysdynResult(\r
+                                (String) graph.getPossibleRelatedValue(result, b.HasLabel),\r
+                                (String) graph.getPossibleRelatedValue(result, sr.HasResultFile));\r
+                        results.add(sysdynResult);\r
+                    }\r
+                }\r
+            }\r
+        } catch (Exception e) {\r
+            e.printStackTrace();\r
+        }\r
+\r
+        if(getSimulationResult() != null)\r
+            results.add(0, new SysdynResult(getSimulationResult()));\r
+\r
+\r
+\r
+        return results;\r
+    }\r
+\r
 }\r
diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynResult.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynResult.java
new file mode 100644 (file)
index 0000000..e0783bb
--- /dev/null
@@ -0,0 +1,233 @@
+package org.simantics.sysdyn.manager;\r
+\r
+\r
+import java.io.File;\r
+import java.io.IOException;\r
+import java.util.ArrayList;\r
+import java.util.TreeMap;\r
+\r
+import org.simantics.databoard.Accessors;\r
+import org.simantics.databoard.Bindings;\r
+import org.simantics.databoard.accessor.Accessor;\r
+import org.simantics.databoard.accessor.MapAccessor;\r
+import org.simantics.databoard.accessor.RecordAccessor;\r
+import org.simantics.databoard.accessor.VariantAccessor;\r
+import org.simantics.databoard.accessor.binary.BinaryRecord;\r
+import org.simantics.databoard.accessor.binary.BinaryVariant;\r
+import org.simantics.databoard.accessor.error.AccessorConstructionException;\r
+import org.simantics.databoard.accessor.error.AccessorException;\r
+import org.simantics.databoard.accessor.java.JavaRecord;\r
+import org.simantics.databoard.annotations.Optional;\r
+import org.simantics.databoard.binding.Binding;\r
+import org.simantics.databoard.binding.error.BindingConstructionException;\r
+import org.simantics.databoard.binding.error.BindingException;\r
+import org.simantics.databoard.binding.java.StringJavaBinding;\r
+import org.simantics.databoard.binding.mutable.Variant;\r
+import org.simantics.databoard.binding.mutable.VariantContainerBinding;\r
+import org.simantics.databoard.serialization.SerializationException;\r
+import org.simantics.modelica.data.DataSet;\r
+import org.simantics.modelica.data.SimulationResult;\r
+\r
+public class SysdynResult {\r
+    \r
+    RecordingSession recordingSession;\r
+    RecordAccessor accessor;\r
+    String resultName;\r
+\r
+    public SysdynResult() {\r
+\r
+    }\r
+\r
+    public SysdynResult(SimulationResult result) {\r
+        if(result != null)\r
+            setResult(result);\r
+    }\r
+\r
+    public SysdynResult(String result, String path) {\r
+        this.resultName = result;\r
+        File file = new File(path);\r
+        try {\r
+            BinaryVariant bv = (BinaryVariant)Accessors.openFile(file);\r
+            BinaryRecord br = bv.getValueAccessor();\r
+            accessor = br;\r
+         } catch (AccessorConstructionException e) {\r
+            e.printStackTrace();\r
+        } \r
+    }\r
+\r
+    public Accessor getAccessor() {\r
+        try {\r
+            return Accessors.getAccessor(recordingSession);\r
+        } catch (AccessorConstructionException e) {\r
+            e.printStackTrace();\r
+        }\r
+        return null;\r
+    }\r
+\r
+    public void setResult(SimulationResult result) {\r
+        try {  \r
+            Binding stringBinding = StringJavaBinding.INSTANCE;\r
+            Binding recordBinding = Bindings.getBinding( Recording.class );\r
+            \r
+            recordingSession = new RecordingSession();\r
+            recordingSession.recordings = new TreeMap<Variant, Variant>();\r
+            Variant timeVariableId = new Variant();\r
+            timeVariableId.setValue(stringBinding, "timeVariableId");\r
+            recordingSession.timeVariableId = timeVariableId;\r
+            \r
+\r
+\r
+            for(DataSet ds : result.getVariableDataSets()){\r
+                Recording rec = new Recording();\r
+                rec.labels = new TreeMap<String, String>();\r
+                String name = ds.name;\r
+                rec.id = name;\r
+                rec.labels.put("en", name); \r
+                rec.segments = new ArrayList<Segment>();  \r
+\r
+                Segment seg = new Segment();\r
+                seg.startTime = 0;\r
+                seg.endTime = ds.values.length;\r
+                seg.samples = new ArrayList<Sample>();\r
+                for(double value : ds.values) {\r
+                    Sample samp = new Sample();\r
+                    samp.value = value;\r
+                    seg.samples.add(samp);                                \r
+                }\r
+\r
+                rec.segments.add(seg);\r
+\r
+                Variant tmpVariant = new Variant();\r
+                Variant tmpVariant2 = new Variant();\r
+                tmpVariant.setValue(recordBinding, rec);\r
+                tmpVariant2.setValue(stringBinding, name);\r
+                recordingSession.recordings.put(tmpVariant2, tmpVariant);\r
+            }\r
+        } catch (Exception e) {\r
+            e.printStackTrace();\r
+        } \r
+    }\r
+\r
+    public void saveToFile(File file) {\r
+        try {\r
+            Binding binding = Bindings.getBinding( recordingSession.getClass() );\r
+            Accessors.createFile(file, binding, recordingSession);\r
+        } catch (IOException e) {\r
+            e.printStackTrace();\r
+        } catch (BindingConstructionException e) {\r
+            e.printStackTrace();\r
+        } catch (SerializationException e) {\r
+            e.printStackTrace();\r
+        } catch (BindingException e) {\r
+            e.printStackTrace();\r
+        }\r
+        \r
+    }\r
+\r
+\r
+    public static class Sample {\r
+        public double value;\r
+\r
+        @Override\r
+        public String toString() {\r
+            return ""+value;\r
+        }\r
+    }\r
+\r
+    public static class Segment {\r
+        public int startTime, endTime;\r
+        public ArrayList<Sample> samples;\r
+\r
+        @Override\r
+        public String toString() {\r
+            return "[startTime="+startTime+", endTime="+endTime+", samples="+samples+"]";\r
+        }\r
+\r
+    }\r
+\r
+    public static class Recording {\r
+        public String id;\r
+        public TreeMap<String, String> labels;\r
+        public ArrayList<Segment> segments;\r
+\r
+        @Override\r
+        public String toString() {\r
+            return "id="+id+", labels="+labels+", segments="+segments;\r
+        }\r
+\r
+    }\r
+\r
+    public static class RecordingSession {\r
+        public @Optional Variant datasource;\r
+        public Variant timeVariableId;\r
+        public TreeMap<Variant, Variant> recordings;\r
+\r
+        @Override\r
+        public String toString() {\r
+            return recordings.toString();\r
+        }\r
+    }\r
+\r
+    public static class NodeId {\r
+        public String nodeId;\r
+    }\r
+    \r
+    public SysdynDataSet getDataSet(String variable) {\r
+        if(accessor == null && recordingSession != null) {\r
+            try {\r
+                Binding recordBinding = Bindings.getBinding( RecordingSession.class );\r
+                accessor = (JavaRecord)Accessors.getAccessor(recordBinding, recordingSession);\r
+            } catch (AccessorConstructionException e) {\r
+                e.printStackTrace();\r
+            } catch (BindingConstructionException e) {\r
+                e.printStackTrace();\r
+            }\r
+        }\r
+        \r
+        if(accessor != null) {\r
+            MapAccessor ma;\r
+            try {\r
+                ma = accessor.getFieldAccessor("recordings");\r
+            } catch (AccessorConstructionException e1) {\r
+                e1.printStackTrace();\r
+                return null;\r
+            }\r
+            Binding stringBinding = StringJavaBinding.INSTANCE;\r
+            Variant tmpVariant = new Variant();\r
+            tmpVariant.setValue(stringBinding, variable);\r
+            Variant tmpVariant2 = new Variant();\r
+            tmpVariant2.setValue(stringBinding, "time");\r
+            Recording rec;\r
+            Recording time;\r
+            try {\r
+                VariantAccessor va = ma.getValueAccessor( VariantContainerBinding.INSTANCE, tmpVariant);\r
+                Accessor valueAccessor = va.getValueAccessor();\r
+                rec = (Recording)valueAccessor.getValue( Bindings.getBinding(Recording.class));\r
+                \r
+                va = ma.getValueAccessor( VariantContainerBinding.INSTANCE, tmpVariant2);\r
+                valueAccessor = va.getValueAccessor();\r
+                time = (Recording)valueAccessor.getValue( Bindings.getBinding(Recording.class));\r
+                if( rec == null || time == null) return null;\r
+            } catch (AccessorException e) {\r
+                e.printStackTrace();\r
+                return null;\r
+            } catch (BindingConstructionException e) {\r
+                e.printStackTrace();\r
+                return null;\r
+            } catch (AccessorConstructionException e) {\r
+                e.printStackTrace();\r
+                return null;\r
+            }\r
+            ArrayList<Sample> samples =  rec.segments.get(0).samples;\r
+            double[] values = new double[samples.size()];\r
+            ArrayList<Sample> timeSamples = time.segments.get(0).samples;\r
+            double[] times = new double[samples.size()];\r
+            for(int i = 0; i < samples.size(); i++) {\r
+                values[i] = samples.get(i).value;\r
+                times[i] = timeSamples.get(i).value;\r
+            }\r
+            return new SysdynDataSet(variable, resultName, times, values);\r
+        }\r
+        return null;\r
+    }\r
+}\r
index 69216fb49828d7b79c16caa9805c3d9379a24119..326a0f44beb3cc5e9d64a9a04564f2b981324c83 100644 (file)
         L0.Asserts _ : L0.Assertion\r
             L0.HasPredicate $pred\r
             L0.HasObject    $obj\r
+            \r
+%define tag($pred)\r
+    $subject\r
+        $pred $subject\r
 \r
 ######################################################################\r
 # Defines ontology and attaches it to SimanticsDomain\r
@@ -32,8 +36,7 @@ Sysdyn @ "Sysdyn-1.0" : L0.Ontology
         Symbols : L0.Library\r
 \r
 SysdynProject : PROJ.Feature\r
-    PROJ.LifecycleFeature\r
-      SysdynProject\r
+    tag(PROJ.LifecycleFeature)\r
     L0.HasLabel "System Dynamics Project" : L0.String\r
     L0.HasDescription """System dynamics modelling project. Create system dynamics models and simulate them with OpenModelica.""" : L0.String\r
     L0.PartOf Sysdyn\r
@@ -126,7 +129,7 @@ HasUnit <R L0.HasProperty
     L0.HasRange L0.String\r
 \r
 IndependentVariable <T Variable\r
-    [L0.HasName card "1"]\r
+    \r
     [HasType card "1"]\r
     [HasUnit card "0..1"]\r
     [HasExpression card "0..1"]    \r
@@ -246,6 +249,8 @@ WithLookupExpression <T Expression
 ######################################################################\r
       \r
 Experiment <T L0.Entity\r
+    [HasResult]\r
+\r
 \r
 BasicExperiment <T Experiment\r
 \r
@@ -253,6 +258,26 @@ GameExperiment <T Experiment
 \r
 SimulateOnChangeExperiment <T Experiment\r
 \r
+HasResult <R L0.IsRelatedTo\r
+    L0.HasRange [Result]\r
+\r
+######################################################################\r
+# Results\r
+######################################################################\r
+\r
+Result <T L0.Entity\r
+    SIMU.IsActive\r
+    [L0.HasName card "1"]\r
+    [HasParameterFile card "0..1"]\r
+    [HasResultFile card "0..1"]\r
+\r
+HasParameterFile <R L0.HasProperty\r
+    L0.HasRange L0.String  \r
+\r
+HasResultFile <R L0.HasProperty\r
+    L0.HasRange L0.String\r
+\r
+    \r
 ######################################################################\r
 # Symbols\r
 ######################################################################\r