]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
Simulation run to GE and better toggle simulation handling
authorlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Mon, 7 Jun 2010 07:32:19 +0000 (07:32 +0000)
committerlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Mon, 7 Jun 2010 07:32:19 +0000 (07:32 +0000)
git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@16054 ac1ea38d-2e2b-0410-8846-a27921b304fc

org.simantics.sysdyn.ui/adapters.xml
org.simantics.sysdyn.ui/plugin.xml
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/SimulationResult.java [new file with mode: 0644]
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/SimulationResultImager.java [new file with mode: 0644]
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/SimulationResultLabeler.java [new file with mode: 0644]
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/SimulationResultNode.java [new file with mode: 0644]
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/project/SysdynProject.java
org.simantics.sysdyn/META-INF/MANIFEST.MF
org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynExperiment.java

index 49125c616a5a43d918301a07d8dd629c39e00e6d..7518623becf067e6cbe145abef620853c0175dfd 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        </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/Simulation-1.0/Types/Run"\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 bb6143f7719a2d0d99409812121bd8981e3c4356..e7a97cbd598661f4d9096daedc4d21c2fad87795 100644 (file)
                class="org.simantics.sysdyn.ui.browser.contributions.Experiment"\r
                preference="1.0">\r
          </implementation>\r
+         <implementation\r
+               class="org.simantics.sysdyn.ui.browser.contributions.SimulationResult"\r
+               preference="2.0">\r
+         </implementation>\r
       </binding>\r
    </extension>\r
    <extension\r
                class="org.simantics.sysdyn.ui.browser.contributions.ExperimentLabeler"\r
                preference="2.0">\r
          </implementation>\r
+         <implementation\r
+               class="org.simantics.sysdyn.ui.browser.contributions.SimulationResultLabeler"\r
+               preference="2.0">\r
+         </implementation>\r
       </binding>\r
    </extension>\r
    <extension\r
                class="org.simantics.sysdyn.ui.browser.contributions.ExperimentImager"\r
                preference="2.0">\r
          </implementation>\r
+         <implementation\r
+               class="org.simantics.sysdyn.ui.browser.contributions.SimulationResultImager"\r
+               preference="2.0">\r
+         </implementation>\r
       </binding>\r
    </extension>\r
    <extension\r
diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/SimulationResult.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/SimulationResult.java
new file mode 100644 (file)
index 0000000..d91d306
--- /dev/null
@@ -0,0 +1,36 @@
+package org.simantics.sysdyn.ui.browser.contributions;\r
+\r
+import java.util.ArrayList;\r
+import java.util.Collection;\r
+\r
+import org.simantics.browsing.ui.graph.contributor.viewpoint.ViewpointContributor;\r
+import org.simantics.db.Builtins;\r
+import org.simantics.db.ReadGraph;\r
+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.ui.browser.nodes.AbstractNode;\r
+import org.simantics.sysdyn.ui.browser.nodes.ExperimentNode;\r
+\r
+public class SimulationResult  extends ViewpointContributor<ExperimentNode> {\r
+\r
+    @Override\r
+    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
+            try {\r
+                result.add(graph.adapt(r, AbstractNode.class));\r
+            } catch(DatabaseException e) {\r
+                e.printStackTrace();\r
+            }\r
+        }\r
+        return result;\r
+    }\r
+\r
+    @Override\r
+    public String getViewpointId() {\r
+        return "Standard";\r
+    }\r
+\r
+}\r
diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/SimulationResultImager.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/SimulationResultImager.java
new file mode 100644 (file)
index 0000000..1aef442
--- /dev/null
@@ -0,0 +1,17 @@
+package org.simantics.sysdyn.ui.browser.contributions;\r
+\r
+import org.eclipse.jface.resource.ImageDescriptor;\r
+import org.simantics.browsing.ui.swt.ImagerContributor;\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.sysdyn.ui.Activator;\r
+import org.simantics.sysdyn.ui.browser.nodes.SimulationResultNode;\r
+\r
+public class SimulationResultImager extends ImagerContributor<SimulationResultNode>{\r
+\r
+    @Override\r
+    public ImageDescriptor getDescriptor(ReadGraph graph, SimulationResultNode input) throws DatabaseException {\r
+        return ImageDescriptor.createFromURL(Activator.getDefault().getBundle().getResource("icons/chart_bar.png"));\r
+    }\r
+\r
+}\r
diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/SimulationResultLabeler.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/SimulationResultLabeler.java
new file mode 100644 (file)
index 0000000..cf5b808
--- /dev/null
@@ -0,0 +1,16 @@
+package org.simantics.sysdyn.ui.browser.contributions;\r
+\r
+import org.simantics.browsing.ui.graph.contributor.labeler.LabelerContributor;\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 SimulationResultLabeler extends LabelerContributor<SimulationResultNode>{\r
+\r
+    @Override\r
+    public String getLabel(ReadGraph graph, SimulationResultNode result) throws DatabaseException {\r
+        String name = graph.getPossibleRelatedValue(result.resource, graph.getBuiltins().HasName);\r
+        return name == null ? "Experiment (no name)" : name;\r
+    }\r
+\r
+}\r
diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/SimulationResultNode.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/SimulationResultNode.java
new file mode 100644 (file)
index 0000000..28be114
--- /dev/null
@@ -0,0 +1,12 @@
+package org.simantics.sysdyn.ui.browser.nodes;\r
+\r
+import org.simantics.browsing.ui.common.node.IDeletable;\r
+import org.simantics.db.Resource;\r
+\r
+public class SimulationResultNode  extends AbstractNode implements IDeletable {\r
+\r
+    public SimulationResultNode(Resource resource) {\r
+        super(resource);\r
+    }\r
+    \r
+}\r
index 0d4047a53fadcb4e21497540fc0720bc9c566bf6..bc71e8e74af73542b73e7978b566606adc150c50 100644 (file)
@@ -61,7 +61,12 @@ 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",\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.HasReportFactory, report,\r
                         mu.b.PartOf, model);\r
             }\r
index 4b681603e6111d3de9da9bc5e60af52bcea4ceb9..85823f834a2a6a83b8fb7ed768712d5467e09d69 100644 (file)
@@ -41,7 +41,13 @@ public class SysdynExperimentActivator {
         String experimentName = getName(processor, experiment);\r
         if (experimentName != null)\r
             jobName += " '" + experimentName + "'";\r
-\r
+        /*\r
+        // Shut down the previous active experiment\r
+        IExperiment activeExperiment = experimentManager.getActiveExperiment();\r
+        if (experiment != null)\r
+            activeExperiment.shutdown();\r
+        */\r
+        // Activate a new experiment\r
         scheduleActivation(jobName, project, experimentManager, experiment);\r
     }\r
 \r
@@ -85,6 +91,10 @@ public class SysdynExperimentActivator {
         monitor.beginTask("Activating experiment", IProgressMonitor.UNKNOWN);\r
         try {\r
             SysdynExperimentManagerListener.listenManager(manager);\r
+            IExperiment experiment = manager.getActiveExperiment();\r
+            if(experiment != null) {\r
+                experiment.shutdown();\r
+            }\r
             final Semaphore activated = new Semaphore(0);\r
             final DataContainer<Throwable> problem = new DataContainer<Throwable>();\r
             manager.startExperiment(experimentResource, new IExperimentActivationListener() {\r
index 3ccec2064ed29930aea34a5cae8a417e3d49da58..bc58ec64e3b7f48f66ae2d091a2bc597e6d9d4ac 100644 (file)
@@ -114,6 +114,11 @@ public class SysdynProject extends AbstractProjectFeature {
                         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.HasReportFactory, report,\r
+                        mu.b.PartOf, model);\r
+                \r
                 callback.run(model);\r
             } catch(Exception e) {\r
                 errorCallback.run(e);\r
index d10349c079bd7ad17754ad07a3a5d30c382dc59f..473016548b1a335cf4d29e1f839eb0ed33b5b485 100644 (file)
@@ -12,7 +12,8 @@ Require-Bundle: org.simantics.objmap;bundle-version="0.1.0",
  org.simantics.data;bundle-version="0.6.3",
  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.eclipse.jface;bundle-version="3.5.2",
+ org.simantics.project;bundle-version="1.0.0"
 Export-Package: org.simantics.sysdyn,
  org.simantics.sysdyn.expressionParser,
  org.simantics.sysdyn.manager,
index 5a1a29f999aa317c95edb483ff5d1bf69a07d363..1297dba999d642ddec699336a8bf8be9c7062696 100644 (file)
@@ -5,6 +5,7 @@ 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.db.request.Read;\r
 import org.simantics.simulation.experiment.Experiment;\r
 import org.simantics.simulation.experiment.ExperimentState;\r
 import org.simantics.simulation.experiment.IDynamicExperiment;\r
@@ -17,6 +18,7 @@ public class SysdynExperiment extends Experiment implements IDynamicExperiment {
 \r
     public SysdynExperiment(Resource model) {\r
         super(model);\r
+        System.out.println(this.getIdentifier());\r
         // TODO Auto-generated constructor stub\r
     }\r
 \r
@@ -40,58 +42,57 @@ public class SysdynExperiment extends Experiment implements IDynamicExperiment {
         System.out.println("simulate");\r
         if(enabled) {\r
             changeState(ExperimentState.STOPPED);\r
-            session.asyncRequest(new ReadRequest() {\r
+            startSimulation();\r
+        }\r
+    }\r
+\r
+\r
+    private SysdynModel startSimulation() {\r
+        try {\r
+            return session.syncRequest(new Read<SysdynModel>() {\r
 \r
                 @Override\r
-                public void run(ReadGraph graph) throws DatabaseException {\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
                 }\r
             });\r
+        } catch (DatabaseException e) {\r
+            e.printStackTrace();\r
         }\r
-\r
+        return null;\r
     }\r
 \r
     public void toggleSimulation(boolean enabled) {\r
         if(enabled) {\r
             changeState(ExperimentState.RUNNING);\r
             if(modificationListener == null) {       \r
-                try {\r
-                    session.syncRequest(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 sysdynmodel = \r
-                                SysdynModelManager.getInstance(session).getModel(graph, configuration);\r
-                            SimulationScheduler.start(sysdynmodel);\r
-\r
-                            modificationListener = new Runnable() {\r
-\r
-                                @Override\r
-                                public void run() {\r
-                                    session.asyncRequest(new ReadRequest() {\r
-\r
-                                        @Override\r
-                                        public void run(ReadGraph graph) throws DatabaseException {\r
-                                            if(getState() == ExperimentState.RUNNING) {\r
-                                                SysdynModel sysdynmodel = \r
-                                                    SysdynModelManager.getInstance(session).getModel(graph, configuration);\r
-                                                SimulationScheduler.start(sysdynmodel);\r
-                                            }\r
-\r
-                                        }\r
-                                    });\r
-\r
-                                };\r
-                            };\r
-                            sysdynmodel.addModificationListener(modificationListener);\r
-                        }});\r
-                } catch (DatabaseException e) {\r
-                    e.printStackTrace();\r
-                }\r
+                SysdynModel sysdynModel = startSimulation();\r
+\r
+                modificationListener = new Runnable() {\r
+\r
+                    @Override\r
+                    public void run() {\r
+                        session.asyncRequest(new ReadRequest() {\r
+\r
+                            @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
+                                }\r
+\r
+                            }\r
+                        });\r
+\r
+                    };\r
+                };\r
+                sysdynModel.addModificationListener(modificationListener);\r
             } \r
         }\r
         else {\r
@@ -117,14 +118,14 @@ public class SysdynExperiment extends Experiment implements IDynamicExperiment {
         changeState(ExperimentState.STOPPED);\r
         this.session = g.getSession();\r
     }\r
-    \r
+\r
     @Override\r
     protected void localStateChange() {\r
         ExperimentState state = getState();\r
         switch(state) {\r
             case DISPOSED:\r
                 session.asyncRequest(new ReadRequest() {\r
-                    \r
+\r
                     @Override\r
                     public void run(ReadGraph graph) throws DatabaseException {\r
                         final Resource configuration = graph.getPossibleObject(model, graph.getBuiltins().HasConfiguration);\r
@@ -132,11 +133,11 @@ public class SysdynExperiment extends Experiment implements IDynamicExperiment {
                             SysdynModelManager.getInstance(session).getModel(graph, configuration);\r
                         sysdynmodel.removeModificationListener(modificationListener);\r
                         modificationListener = null;\r
-                        \r
+\r
                     }\r
                 });\r
                 break;\r
-            }\r
+        }\r
     }\r
 \r
 \r