]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
Save and show results
authorlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Mon, 2 Aug 2010 10:28:50 +0000 (10:28 +0000)
committerlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Mon, 2 Aug 2010 10:28:50 +0000 (10:28 +0000)
git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@16898 ac1ea38d-2e2b-0410-8846-a27921b304fc

org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/InputFactory.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/project/HistoryVariable.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/TrendView.java
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

index dfc9cfef02054cba247a22708be82e585702ed9d..d59bc3b339d8b8b28da3c1d23b98c2fad8447072 100644 (file)
@@ -118,11 +118,11 @@ public class InputFactory extends SysdynElementFactory {
                         refersTo = graph.getSingleObject(dep, sr.HasTail);\r
                         referenceName = (String) graph.getPossibleRelatedValue(refersTo, b.HasName);\r
                         moduleRepresentation = graph.getPossibleResource(variable.substring(0, variable.lastIndexOf("/")));\r
-                        Resource parent = graph.getSingleObject(moduleRepresentation, b.PartOf);\r
-                        module = graph.getSingleObject(moduleRepresentation, b.Represents);\r
+                        Resource parent = graph.getPossibleObject(moduleRepresentation, b.PartOf);\r
                         String parentURI = graph.getURI(parent);\r
                         String modelURI =  diagram.getHint((DiagramModelHints.KEY_DIAGRAM_MODEL_URI));\r
-                        if(parentURI.equals(modelURI))\r
+                        module = graph.getPossibleObject(moduleRepresentation, b.Represents);\r
+                        if(parentURI.equals(modelURI) || module == null)\r
                             moduleName = "";\r
                         else {\r
                             moduleName = (String) graph.getPossibleRelatedValue(module, b.HasName);\r
@@ -133,7 +133,7 @@ public class InputFactory extends SysdynElementFactory {
         }\r
 \r
         String inputReference = null;\r
-        if (module != null && refersTo != null) {\r
+        if (moduleName != null && refersTo != null) {\r
             inputReference = moduleName + "." + referenceName;\r
         }\r
         if (inputReference == null) {\r
index af2a129a307868035e5dabfa418b716c77e1071a..b686274dd2b05a3479ce1ad65f0cdd42d93c34db 100644 (file)
@@ -30,7 +30,7 @@ public class HistoryVariable extends ResourceVariable {
                        Resource model = Variables.getModel(graph, this);\r
                        Resource configuration = graph.getPossibleObject(model, b.HasConfiguration);\r
                        SysdynModel sm = SysdynModelManager.getInstance(graph.getSession()).getModel(graph, configuration);\r
-                       SysdynResult sr = new SysdynResult(sm.getSimulationResult());\r
+                       SysdynResult sr = sm.getSysdynResult();\r
                        String rvi = Variables.getRVI(graph, this);\r
                        System.out.println("HistoryVariable rvi='" + rvi + "'");\r
                        rvi = rvi.substring(1).replace("/", ".");\r
index 6b034f5f52dd74cfd7fb38b64defd8e4162abed4..b9179b93078fd835c3fdd7e9bb79e55a38fd704d 100644 (file)
@@ -13,6 +13,7 @@ package org.simantics.sysdyn.ui.trend;
 \r
 import java.awt.Frame;\r
 import java.util.ArrayList;\r
+import java.util.Collection;\r
 import java.util.List;\r
 import java.util.Set;\r
 \r
@@ -32,10 +33,6 @@ import org.jfree.chart.axis.NumberAxis;
 import org.jfree.chart.plot.XYPlot;\r
 import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer;\r
 import org.jfree.data.xy.AbstractXYDataset;\r
-import org.simantics.databoard.Bindings;\r
-import org.simantics.databoard.accessor.Accessor;\r
-import org.simantics.databoard.accessor.error.AccessorException;\r
-import org.simantics.databoard.binding.error.RuntimeBindingConstructionException;\r
 import org.simantics.db.Builtins;\r
 import org.simantics.db.ReadGraph;\r
 import org.simantics.db.Resource;\r
@@ -49,6 +46,9 @@ import org.simantics.diagram.stubs.DiagramResource;
 import org.simantics.modeling.ModelingUtils;\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.ui.SimanticsUI;\r
 import org.simantics.utils.ui.ISelectionUtils;\r
 import org.simantics.utils.ui.jface.ActiveSelectionProvider;\r
@@ -138,10 +138,10 @@ public class TrendView extends ViewPart {
                     return;\r
                 if(selection instanceof IStructuredSelection) {\r
                     Set<Resource> ress = ISelectionUtils.filterSetSelection(selection, Resource.class);\r
-                       List<Resource> runtimes = ISelectionUtils.getPossibleKeys(selection, SelectionHints.KEY_VARIABLE_RESOURCE, Resource.class);\r
-                       if(runtimes.isEmpty())\r
-                           return;\r
-                       Resource runtime = runtimes.get(0);\r
+                    List<Resource> runtimes = ISelectionUtils.getPossibleKeys(selection, SelectionHints.KEY_VARIABLE_RESOURCE, Resource.class);\r
+                    if(runtimes.isEmpty())\r
+                        return;\r
+                    Resource runtime = runtimes.get(0);\r
                     setSelection(ress.toArray(Resource.NONE), runtime);\r
                 }                \r
             }\r
@@ -159,7 +159,7 @@ public class TrendView extends ViewPart {
     }\r
 \r
     public void updateView() {\r
-       \r
+\r
         Session session = SimanticsUI.peekSession();\r
         if (session == null)\r
             return;\r
@@ -170,11 +170,14 @@ public class TrendView extends ViewPart {
 \r
                 final ArrayList<SysdynDataSet> datasets = new ArrayList<SysdynDataSet>();\r
                 for(Resource resource : resources) {\r
-                    SysdynDataSet set = load(g, resource, runtime);\r
-                    if(set == null) {\r
-                        return;\r
-                    }\r
-                    datasets.add(set);\r
+//                    SysdynDataSet set = load(g, resource, runtime);\r
+//                    if(set == null) {\r
+//                        return;\r
+//                    }\r
+//                    datasets.add(set);\r
+                    Collection<SysdynDataSet> activeDataSets = loadAllActive(g, resource, runtime);\r
+                    if(activeDataSets != null && !activeDataSets.isEmpty())\r
+                        datasets.addAll(activeDataSets);\r
                 }
 \r
                 SwingUtilities.invokeLater(new Runnable() {\r
@@ -190,27 +193,28 @@ public class TrendView extends ViewPart {
         });\r
     }\r
 \r
+    /*\r
     protected SysdynDataSet load(ReadGraph g, Resource element, Resource runtime) throws DatabaseException {\r
 \r
        Builtins b = g.getBuiltins();\r
-       \r
+\r
         SysdynResource sr = SysdynResource.getInstance(g);\r
 \r
         DiagramResource dr = DiagramResource.getInstance(g);\r
-        \r
+\r
         if(runtime == null) return null;\r
         Resource resource = ModelingUtils.getPossibleElementCorrespondendence(g, element);\r
         if(resource == null || !g.isInstanceOf(resource, sr.Variable)) return null;\r
 \r
         String variableURI = g.getPossibleRelatedValue(runtime, dr.HasVariable);\r
-               \r
+\r
         System.out.println("load dataset for '"+ g.getPossibleRelatedValue(resource, b.HasName) + "'in composite '" + variableURI + "'");\r
         Variable compositeVariable = Variables.getVariable(g, variableURI);\r
         Variable item = compositeVariable.browsePossible(g, resource);\r
         if(item == null) return null;\r
-        \r
+\r
         System.out.println("load dataset for '" + item.getURI(g) + "'");\r
-        \r
+\r
         Accessor accessor = item.getInterface(g, Accessor.class);\r
         if(accessor == null) return null;\r
         try {\r
@@ -223,6 +227,7 @@ public class TrendView extends ViewPart {
                return null;\r
 \r
     }\r
+     */\r
 \r
     @Override\r
     public void setFocus() {\r
@@ -230,4 +235,43 @@ public class TrendView extends ViewPart {
             panel.requestFocus();      \r
     }\r
 \r
+    protected Collection<SysdynDataSet> loadAllActive(ReadGraph g, Resource element, Resource runtime) throws DatabaseException {\r
+\r
+        ArrayList<SysdynDataSet> dataSets = new ArrayList<SysdynDataSet>();\r
+        Builtins b = g.getBuiltins();\r
+\r
+        SysdynResource sr = SysdynResource.getInstance(g);\r
+\r
+        DiagramResource dr = DiagramResource.getInstance(g);\r
+\r
+        if(runtime == null) return null;\r
+        Resource resource = ModelingUtils.getPossibleElementCorrespondendence(g, element);\r
+        if(resource == null || !g.isInstanceOf(resource, sr.Variable)) return null;\r
+\r
+        String variableURI = g.getPossibleRelatedValue(runtime, dr.HasVariable);\r
+\r
+        System.out.println("load dataset for '"+ g.getPossibleRelatedValue(resource, b.HasName) + "'in composite '" + variableURI + "'");\r
+        Variable compositeVariable = Variables.getVariable(g, variableURI);\r
+        Variable item = compositeVariable.browsePossible(g, resource);\r
+        if(item == null) return null;\r
+\r
+        String rvi = Variables.getRVI(g, item);\r
+        System.out.println("HistoryVariable rvi='" + rvi + "'");\r
+\r
+        System.out.println("load dataset for '" + item.getURI(g) + "'");\r
+\r
+        Resource model = Variables.getModel(g, item);\r
+        Resource configuration = g.getPossibleObject(model, b.HasConfiguration);\r
+        SysdynModel sm = SysdynModelManager.getInstance(g.getSession()).getModel(g, configuration);\r
+\r
+        Collection<SysdynResult> activeResults = sm.getActiveResults(g);\r
+        for(SysdynResult sysdynResult : activeResults) {\r
+            SysdynDataSet sds = sysdynResult.getDataSet(rvi.substring(1).replace("/", "."));\r
+            if(sds != null)\r
+                dataSets.add(sds);\r
+        }\r
+        return dataSets;\r
+\r
+    }\r
+\r
 }\r
index 2b2a3149b0dc9f4df695f9effcfbc12c9087409a..efb17d00b8e5ab49e57c2e18f314e8a79b4b2c59 100644 (file)
@@ -32,7 +32,6 @@ public class SysdynExperiment extends Experiment implements IDynamicExperiment {
     Runnable modificationListener;\r
     Resource experiment;\r
     SysdynModel sysdynModel;\r
-    SysdynResult result;\r
 \r
     public SysdynExperiment(Resource experiment, Resource model) {\r
         super(model);\r
@@ -54,7 +53,7 @@ public class SysdynExperiment extends Experiment implements IDynamicExperiment {
     public void saveState() {\r
         // TODO Auto-generated method stub\r
         System.out.println("saveState");\r
-        if(sysdynModel.getSimulationResult() == null) return;\r
+        if(sysdynModel.getSysdynResult() == null) return;\r
 \r
         try {\r
             session.syncRequest(new WriteRequest() {\r
@@ -77,7 +76,7 @@ public class SysdynExperiment extends Experiment implements IDynamicExperiment {
                             b.PartOf, model,\r
                             sr.HasResultFile, file.getAbsolutePath());\r
                     graph.claim(experiment, sr.HasResult, res);\r
-                    result.saveToFile(file);\r
+                    sysdynModel.getSysdynResult().saveToFile(file);\r
                 }\r
             });\r
             session.getService(LifecycleSupport.class).save();\r
@@ -158,7 +157,6 @@ 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
@@ -166,14 +164,6 @@ public class SysdynExperiment extends Experiment implements IDynamicExperiment {
             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
                 toggleActivation(graph, true);\r
             }\r
         });\r
index 3bc827215eccbdbb25239be5271db9733dc9f4e7..dfb8d396a194e05f04943b2f5f17583d1e8c2729 100644 (file)
@@ -55,6 +55,7 @@ public class SysdynModel implements IMappingListener, IModel {
     Configuration configuration;\r
     Set<Configuration> modules = new HashSet<Configuration>();\r
     SimulationResult result;\r
+    SysdynResult sysdynResult;\r
 \r
     CopyOnWriteArrayList<Runnable> modificationListeners =\r
         new CopyOnWriteArrayList<Runnable>();\r
@@ -107,6 +108,8 @@ public class SysdynModel implements IMappingListener, IModel {
         } catch(DatabaseException e) {\r
             e.printStackTrace();\r
         }\r
+        sysdynResult = new SysdynResult();\r
+        sysdynResult.setResult(new SimulationResult());\r
     }\r
 \r
 \r
@@ -134,7 +137,8 @@ public class SysdynModel implements IMappingListener, IModel {
                     writer.toString(), \r
                     monitor,\r
                     configuration.startTime,\r
-                    configuration.stopTime);            \r
+                    configuration.stopTime);       \r
+            sysdynResult.setResult(result);\r
         } catch(Exception e) {\r
             e.printStackTrace();\r
             result = null;\r
@@ -162,6 +166,10 @@ public class SysdynModel implements IMappingListener, IModel {
     public SimulationResult getSimulationResult() {\r
         return result;\r
     }\r
+    \r
+    public SysdynResult getSysdynResult() {\r
+        return sysdynResult;\r
+    }\r
 \r
     public void addResultListener(Runnable listener) {\r
         synchronized(resultListeners) {\r
@@ -259,8 +267,8 @@ public class SysdynModel implements IMappingListener, IModel {
             e.printStackTrace();\r
         }\r
 \r
-        if(getSimulationResult() != null)\r
-            results.add(0, new SysdynResult(getSimulationResult()));\r
+        if(getSysdynResult() != null)\r
+            results.add(0, getSysdynResult() );\r
 \r
 \r
 \r
index bc38975ec9bbbd43337afbcbb28ef09e6c9233ac..85efa71a61aa2af5c17dce1bb82f64b9363b672e 100644 (file)
@@ -32,7 +32,7 @@ import org.simantics.modelica.data.DataSet;
 import org.simantics.modelica.data.SimulationResult;\r
 \r
 public class SysdynResult {\r
-    \r
+\r
     RecordingSession recordingSession;\r
     RecordAccessor accessor;\r
     String resultName;\r
@@ -47,14 +47,13 @@ public class SysdynResult {
     }\r
 \r
     public SysdynResult(String result, String path) {\r
-       System.out.println("sysdynresult " + result + " " + path);\r
         this.resultName = result;\r
         File file = new File(path);\r
         try {\r
             BinaryVariant bv = (BinaryVariant)Accessors.openAccessor(file);\r
             BinaryRecord br = bv.getValueAccessor();\r
             accessor = br;\r
-         } catch (AccessorConstructionException e) {\r
+        } catch (AccessorConstructionException e) {\r
             e.printStackTrace();\r
         } \r
     }\r
@@ -72,13 +71,13 @@ public class SysdynResult {
         try {  \r
             Binding stringBinding = StringBindingDefault.INSTANCE;\r
             Binding recordBinding = Bindings.getBinding( Recording.class );\r
-            \r
+\r
             recordingSession = new RecordingSession();\r
             recordingSession.recordings = new TreeMap<Variant, Variant>();\r
             MutableVariant timeVariableId = new MutableVariant();\r
             timeVariableId.setValue(stringBinding, "timeVariableId");\r
             recordingSession.timeVariableId = timeVariableId;\r
-            \r
+\r
 \r
 \r
             for(DataSet ds : result.getVariableDataSets()){\r
@@ -110,6 +109,25 @@ public class SysdynResult {
         } catch (Exception e) {\r
             e.printStackTrace();\r
         } \r
+\r
+        if(recordingSession == null) return;\r
+\r
+\r
+        try {\r
+            Binding recordBinding = Bindings.getBinding( RecordingSession.class );\r
+            if(accessor == null) {\r
+                accessor = (JavaRecord)Accessors.getAccessor(recordBinding, recordingSession);\r
+            } else {\r
+                accessor.setValue(recordBinding, recordingSession);\r
+            }\r
+        } catch (AccessorConstructionException e) {\r
+            e.printStackTrace();\r
+        } catch (BindingConstructionException e) {\r
+            e.printStackTrace();\r
+        } catch (AccessorException e) {\r
+            e.printStackTrace();\r
+        }\r
+\r
     }\r
 \r
     public void saveToFile(File file) {\r
@@ -126,7 +144,7 @@ public class SysdynResult {
         } catch (BindingException e) {\r
             e.printStackTrace();\r
         }\r
-        \r
+\r
     }\r
 \r
 \r
@@ -176,19 +194,8 @@ public class SysdynResult {
     public static class NodeId {\r
         public String nodeId;\r
     }\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
@@ -209,7 +216,7 @@ public class SysdynResult {
                 VariantAccessor va = ma.getValueAccessor( MutableVariantBinding.INSTANCE, tmpVariant);\r
                 Accessor valueAccessor = va.getValueAccessor();\r
                 rec = (Recording)valueAccessor.getValue( Bindings.getBinding(Recording.class));\r
-                \r
+\r
                 va = ma.getValueAccessor( MutableVariantBinding.INSTANCE, tmpVariant2);\r
                 valueAccessor = va.getValueAccessor();\r
                 time = (Recording)valueAccessor.getValue( Bindings.getBinding(Recording.class));\r