]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
Experiment control for basic simulation and simulate on change. Needs refactoring.
authorlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Thu, 3 Jun 2010 14:25:43 +0000 (14:25 +0000)
committerlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Thu, 3 Jun 2010 14:25:43 +0000 (14:25 +0000)
git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@16032 ac1ea38d-2e2b-0410-8846-a27921b304fc

35 files changed:
org.simantics.sysdyn.ui/META-INF/MANIFEST.MF
org.simantics.sysdyn.ui/adapters.xml
org.simantics.sysdyn.ui/icons/chart_bar.png [new file with mode: 0644]
org.simantics.sysdyn.ui/icons/control_eject.png [new file with mode: 0644]
org.simantics.sysdyn.ui/icons/control_eject_blue.png [new file with mode: 0644]
org.simantics.sysdyn.ui/icons/control_play_blue.png [new file with mode: 0644]
org.simantics.sysdyn.ui/icons/control_repeat.png [new file with mode: 0644]
org.simantics.sysdyn.ui/icons/control_repeat_blue.png [new file with mode: 0644]
org.simantics.sysdyn.ui/icons/disk.png [new file with mode: 0644]
org.simantics.sysdyn.ui/icons/time.png [new file with mode: 0644]
org.simantics.sysdyn.ui/plugin.xml
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/actions/ToggleSimulation.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/Experiment.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/ExperimentImager.java [new file with mode: 0644]
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/ExperimentLabeler.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/ExperimentNode.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/equation/EquationView.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/DisposeExperiment.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/RunBasicExperiment.java [new file with mode: 0644]
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/SaveResultsHandler.java [new file with mode: 0644]
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/SysdynExperimentActivator.java [new file with mode: 0644]
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/listeners/SysdynExperimentListener.java [new file with mode: 0644]
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/listeners/SysdynExperimentManagerListener.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/project/SysdynProjectLifeCycle.java [new file with mode: 0644]
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/TrendView.java
org.simantics.sysdyn/META-INF/MANIFEST.MF
org.simantics.sysdyn/adapters.xml [new file with mode: 0644]
org.simantics.sysdyn/src/org/simantics/sysdyn/SysdynResource.java
org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynExperiment.java [new file with mode: 0644]
org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynModel.java
org.simantics.sysdyn/src/org/simantics/sysdyn/simulation/SimulationJob.java [moved from org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/simulation/SimulationJob.java with 91% similarity]
org.simantics.sysdyn/src/org/simantics/sysdyn/simulation/SimulationScheduler.java [moved from org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/simulation/SimulationScheduler.java with 86% similarity]
sysdyn_ontologies/sysdyn.graph

index a253c6027ae0d551fbe7e55baa29cab87628b197..8454a01de30588d04fbba4261fe0e7d1854ec214 100644 (file)
@@ -31,6 +31,9 @@ Require-Bundle: org.simantics.h2d;bundle-version="1.0.0",
  org.simantics.modeling;bundle-version="1.0.0",
  org.simantics.mapping;bundle-version="1.0.0",
  org.simantics.structural.stubs;bundle-version="1.0.0",
- gnu.trove2;bundle-version="2.0.4"
+ gnu.trove2;bundle-version="2.0.4",
+ org.simantics.simulation;bundle-version="1.0.0",
+ org.simantics.data;bundle-version="0.6.3",
+ org.simantics.message;bundle-version="0.9.0"
 Bundle-Activator: org.simantics.sysdyn.ui.Activator
 Bundle-ActivationPolicy: lazy
index 61ee59d8daefd97729cb4077c0c2977e667e82ab..49125c616a5a43d918301a07d8dd629c39e00e6d 100644 (file)
@@ -16,7 +16,7 @@
                <resource\r
                        uri="http://www.simantics.org/Sysdyn-1.0/SysdynProject"\r
                        class="org.simantics.sysdyn.ui.project.SysdynProject" />\r
-               <resource\r                      uri="http://www.simantics.org/Sysdyn-1.0/SysdynSymbols"\r                        class="org.simantics.sysdyn.ui.editor.SymbolsFeature" />\r       </target>\r      \r
+               <resource\r                      uri="http://www.simantics.org/Sysdyn-1.0/SysdynSymbols"\r                        class="org.simantics.sysdyn.ui.editor.SymbolsFeature" />\r               <resource\r            uri="http://www.simantics.org/Sysdyn-1.0/SysdynModelManager"\r            class="org.simantics.sysdyn.ui.project.SysdynProject" />\r        </target>\r      \r       <target interface="org.simantics.project.IProjectLifeCycle">\r           <resource\r                      uri="http://www.simantics.org/Sysdyn-1.0/SysdynProject"\r                        class="org.simantics.sysdyn.ui.project.SysdynProjectLifeCycle" />\r      </target>\r      \r
        <target\r
                interface="org.simantics.scenegraph.adapters.ISceneGraphProvider">\r
                <type\r
@@ -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        </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        </target>\r      \r
 </adapters>
\ No newline at end of file
diff --git a/org.simantics.sysdyn.ui/icons/chart_bar.png b/org.simantics.sysdyn.ui/icons/chart_bar.png
new file mode 100644 (file)
index 0000000..9051fbc
Binary files /dev/null and b/org.simantics.sysdyn.ui/icons/chart_bar.png differ
diff --git a/org.simantics.sysdyn.ui/icons/control_eject.png b/org.simantics.sysdyn.ui/icons/control_eject.png
new file mode 100644 (file)
index 0000000..924d817
Binary files /dev/null and b/org.simantics.sysdyn.ui/icons/control_eject.png differ
diff --git a/org.simantics.sysdyn.ui/icons/control_eject_blue.png b/org.simantics.sysdyn.ui/icons/control_eject_blue.png
new file mode 100644 (file)
index 0000000..2bd4963
Binary files /dev/null and b/org.simantics.sysdyn.ui/icons/control_eject_blue.png differ
diff --git a/org.simantics.sysdyn.ui/icons/control_play_blue.png b/org.simantics.sysdyn.ui/icons/control_play_blue.png
new file mode 100644 (file)
index 0000000..f8c8ec6
Binary files /dev/null and b/org.simantics.sysdyn.ui/icons/control_play_blue.png differ
diff --git a/org.simantics.sysdyn.ui/icons/control_repeat.png b/org.simantics.sysdyn.ui/icons/control_repeat.png
new file mode 100644 (file)
index 0000000..1c4f57a
Binary files /dev/null and b/org.simantics.sysdyn.ui/icons/control_repeat.png differ
diff --git a/org.simantics.sysdyn.ui/icons/control_repeat_blue.png b/org.simantics.sysdyn.ui/icons/control_repeat_blue.png
new file mode 100644 (file)
index 0000000..406ec33
Binary files /dev/null and b/org.simantics.sysdyn.ui/icons/control_repeat_blue.png differ
diff --git a/org.simantics.sysdyn.ui/icons/disk.png b/org.simantics.sysdyn.ui/icons/disk.png
new file mode 100644 (file)
index 0000000..99d532e
Binary files /dev/null and b/org.simantics.sysdyn.ui/icons/disk.png differ
diff --git a/org.simantics.sysdyn.ui/icons/time.png b/org.simantics.sysdyn.ui/icons/time.png
new file mode 100644 (file)
index 0000000..911da3f
Binary files /dev/null and b/org.simantics.sysdyn.ui/icons/time.png differ
index 45c158bab2b7a1627159044858cb31ed7b5e82c4..bb6143f7719a2d0d99409812121bd8981e3c4356 100644 (file)
    <extension\r
          point="org.eclipse.ui.menus">\r
       <menuContribution\r
-            locationURI="toolbar:org.simantics.sysdyn.ui.trend.view">\r
-         <command\r
-               commandId="org.simantics.sysdyn.ui.trend.view.pin"\r
-               icon="icons/table_multiple_pinned.png"\r
-               label="Pin Trend"\r
-               style="toggle"\r
-               tooltip="Pins the trend so that it does not react to selection changes">\r
-         </command>\r
-      </menuContribution>\r
-      <menuContribution\r
-            locationURI="toolbar:org.eclipse.ui.main.toolbar?after=additions">\r
+            locationURI="toolbar:org.eclipse.ui.main.toolbar">\r
          <toolbar\r
-               id="org.simantics.sysdyn.ui.sysdynToolbar">\r
+               id="org.simantics.sysdyn.ui.experimentControlToolbar">\r
             <command\r
-                  commandId="org.simantics.sysdyn.ui.simulate"\r
+                  commandId="org.simantics.sysdyn.ui.run"\r
+                  hoverIcon="icons/control_play_blue.png"\r
                   icon="icons/control_play.png"\r
+                  id="org.simantics.sysdyn.ui.run.button"\r
                   label="Simulate"\r
+                  style="push">\r
+               <visibleWhen>\r
+                  <with\r
+                        variable="activeContexts">\r
+                     <iterate\r
+                           ifEmpty="false"\r
+                           operator="or">\r
+                        <equals\r
+                              value="org.simantics.sysdyn.ui.basicExperiment">\r
+                        </equals>\r
+                     </iterate>\r
+                  </with>\r
+               </visibleWhen>\r
+            </command>\r
+            <command\r
+                  commandId="org.simantics.sysdyn.ui.toggleSimulation"\r
+                  hoverIcon="icons/control_repeat_blue.png"\r
+                  icon="icons/control_repeat.png"\r
+                  label="Simulate On Change"\r
                   style="toggle"\r
-                  tooltip="Toggle simulation">\r
-               <visibleWhen\r
-                     checkEnabled="true">\r
+                  tooltip="Simulate On Change">\r
+               <visibleWhen>\r
+                  <with\r
+                        variable="activeContexts">\r
+                     <iterate\r
+                           ifEmpty="false"\r
+                           operator="or">\r
+                        <equals\r
+                              value="org.simantics.sysdyn.ui.basicExperiment">\r
+                        </equals>\r
+                     </iterate>\r
+                  </with>\r
+               </visibleWhen>\r
+            </command>\r
+            <command\r
+                  commandId="org.simantics.sysdyn.ui.dispose"\r
+                  hoverIcon="icons/control_eject_blue.png"\r
+                  icon="icons/control_eject.png"\r
+                  id="org.simantics.sysdyn.ui.dispose.button"\r
+                  label="Quit Experiment">\r
+               <visibleWhen>\r
                   <with\r
-                        variable="activeWorkbenchWindow.activePerspective">\r
-                     <equals\r
-                           value="org.simantics.sysdyn.ui.perspective">\r
-                     </equals>\r
+                        variable="activeContexts">\r
+                     <iterate\r
+                           ifEmpty="false"\r
+                           operator="or">\r
+                        <equals\r
+                              value="org.simantics.sysdyn.ui.basicExperiment">\r
+                        </equals>\r
+                     </iterate>\r
+                  </with>\r
+               </visibleWhen>\r
+            </command>\r
+            <command\r
+                  commandId="org.simantics.sysdyn.ui.saveResults"\r
+                  icon="icons/disk.png"\r
+                  id="org.simantics.sysdyn.ui.save.button">\r
+               <visibleWhen>\r
+                  <with\r
+                        variable="activeContexts">\r
+                     <iterate\r
+                           ifEmpty="false"\r
+                           operator="or">\r
+                        <equals\r
+                              value="org.simantics.sysdyn.ui.basicExperiment">\r
+                        </equals>\r
+                     </iterate>\r
                   </with>\r
                </visibleWhen>\r
             </command>\r
          </toolbar>\r
       </menuContribution>\r
+      <menuContribution\r
+            locationURI="toolbar:org.simantics.sysdyn.ui.trend.view">\r
+         <command\r
+               commandId="org.simantics.sysdyn.ui.trend.view.pin"\r
+               icon="icons/table_multiple_pinned.png"\r
+               label="Pin Trend"\r
+               style="toggle"\r
+               tooltip="Pins the trend so that it does not react to selection changes">\r
+         </command>\r
+      </menuContribution>\r
       <menuContribution\r
             locationURI="popup:#SysdynBrowserPopup?after=wbStart">\r
          <dynamic\r
       </command>\r
       <command\r
             defaultHandler="org.simantics.sysdyn.ui.actions.ToggleSimulation"\r
-            id="org.simantics.sysdyn.ui.simulate"\r
+            id="org.simantics.sysdyn.ui.toggleSimulation"\r
             name="Toggle Simulate">\r
          <state\r
                class="org.eclipse.jface.commands.ToggleState"\r
-               id="org.simantics.sysdyn.ui.simulate.state">\r
+               id="org.simantics.sysdyn.ui.toggleSimulation.state">\r
          </state>\r
       </command>\r
       <command\r
             id="org.simantics.sysdyn.ui.newModel"\r
             name="New Model">\r
       </command>\r
+      <command\r
+            id="org.simantics.sysdyn.ui.activateExperiment"\r
+            name="Activate Experiment">\r
+      </command>\r
+      <command\r
+            defaultHandler="org.simantics.sysdyn.ui.handlers.RunBasicExperiment"\r
+            id="org.simantics.sysdyn.ui.run"\r
+            name="Run Basic Simulation">\r
+      </command>\r
+      <command\r
+            defaultHandler="org.simantics.sysdyn.ui.handlers.DisposeExperiment"\r
+            id="org.simantics.sysdyn.ui.dispose"\r
+            name="Quit Experiment">\r
+      </command>\r
+      <command\r
+            defaultHandler="org.simantics.sysdyn.ui.handlers.SaveResultsHandler"\r
+            id="org.simantics.sysdyn.ui.saveResults"\r
+            name="Save Results">\r
+      </command>\r
    </extension>\r
    <extension\r
          point="org.eclipse.ui.handlers">\r
                class="org.simantics.sysdyn.ui.browser.contributions.ModelChildren"\r
                preference="2.0">\r
          </implementation>\r
+         <implementation\r
+               class="org.simantics.sysdyn.ui.browser.contributions.Experiment"\r
+               preference="1.0">\r
+         </implementation>\r
       </binding>\r
    </extension>\r
    <extension\r
                class="org.simantics.sysdyn.ui.browser.contributions.OperatingInterfacesLabeler"\r
                preference="2.0">\r
          </implementation>\r
+         <implementation\r
+               class="org.simantics.sysdyn.ui.browser.contributions.ExperimentLabeler"\r
+               preference="2.0">\r
+         </implementation>\r
       </binding>\r
    </extension>\r
    <extension\r
                class="org.simantics.sysdyn.ui.browser.contributions.VariableImager"\r
                preference="2.0">\r
          </implementation>\r
+         <implementation\r
+               class="org.simantics.sysdyn.ui.browser.contributions.ExperimentImager"\r
+               preference="2.0">\r
+         </implementation>\r
       </binding>\r
    </extension>\r
    <extension\r
             properties="nodeClass"\r
             type="org.eclipse.jface.viewers.IStructuredSelection">\r
       </propertyTester>\r
+   </extension>\r
+   <extension\r
+         point="org.eclipse.ui.contexts">\r
+      <context\r
+            id="org.simantics.sysdyn.ui.basicExperiment"\r
+            name="Basic Experiment">\r
+      </context>\r
    </extension>
 </plugin>\r
index ff731f51935f702aa7305b2c3254daa653fc1be4..d92a2de7e467d8b76a10f1fe6d1de63f8867808f 100644 (file)
  *******************************************************************************/\r
 package org.simantics.sysdyn.ui.actions;\r
 \r
+\r
+import java.util.Map;\r
+\r
 import org.eclipse.core.commands.AbstractHandler;\r
 import org.eclipse.core.commands.Command;\r
 import org.eclipse.core.commands.ExecutionEvent;\r
 import org.eclipse.core.commands.ExecutionException;\r
 import org.eclipse.core.commands.State;\r
-import org.eclipse.ui.IEditorInput;\r
-import org.eclipse.ui.IEditorPart;\r
 import org.eclipse.ui.PlatformUI;\r
 import org.eclipse.ui.commands.ICommandService;\r
-import org.simantics.sysdyn.manager.SysdynModel;\r
-import org.simantics.sysdyn.manager.SysdynModelManager;\r
-import org.simantics.sysdyn.ui.editor.SysdynDiagramEditor;\r
+import org.eclipse.ui.commands.IElementUpdater;\r
+import org.eclipse.ui.menus.UIElement;\r
+import org.simantics.simulation.experiment.IDynamicExperiment;\r
+import org.simantics.simulation.experiment.IExperiment;\r
+import org.simantics.simulation.project.IExperimentManager;\r
+import org.simantics.sysdyn.manager.SysdynExperiment;\r
+import org.simantics.sysdyn.ui.handlers.RunBasicExperiment;\r
 import org.simantics.ui.SimanticsUI;\r
-import org.simantics.ui.workbench.ResourceEditorInput;\r
 \r
-public class ToggleSimulation extends AbstractHandler {\r
+public class ToggleSimulation extends AbstractHandler implements IElementUpdater {\r
 \r
-    public static final String COMMAND = "org.simantics.sysdyn.ui.simulate";\r
-    public static final String STATE = "org.simantics.sysdyn.ui.simulate.state";\r
+    public static final String COMMAND = "org.simantics.sysdyn.ui.toggleSimulation";\r
+    public static final String STATE = "org.simantics.sysdyn.ui.toggleSimulation.state";\r
 \r
     @Override\r
     public Object execute(ExecutionEvent event) throws ExecutionException {\r
@@ -39,19 +43,20 @@ public class ToggleSimulation extends AbstractHandler {
         Boolean value = (Boolean) state.getValue();\r
         value = !value;\r
         state.setValue(value);\r
-        // If turned back on, simulate to apply any changes\r
-        if(value) {\r
-            IEditorPart editor =\r
-                PlatformUI.getWorkbench()\r
-                .getActiveWorkbenchWindow().getActivePage().getActiveEditor();\r
-            if (editor instanceof SysdynDiagramEditor) {\r
-                IEditorInput input =  editor.getEditorInput();\r
-                ResourceEditorInput rei = (ResourceEditorInput) input;\r
-                SysdynModelManager sdm = SysdynModelManager.getInstance(SimanticsUI.getSession());\r
-                SysdynModel model = sdm.getModel(rei.getResource());\r
-                model.domainModified();\r
+        service.refreshElements(RunBasicExperiment.COMMAND, null);\r
+        \r
+        IExperimentManager manager = \r
+            SimanticsUI.getProject().getHint(IExperimentManager.KEY_EXPERIMENT_MANAGER);\r
+        IExperiment experiment = manager.getActiveExperiment();\r
+        if(experiment instanceof SysdynExperiment) {\r
+            if(getState()) {\r
+                ((SysdynExperiment)experiment).toggleSimulation(true);\r
+            } else {\r
+                ((SysdynExperiment)experiment).toggleSimulation(false);\r
             }\r
         }\r
+            \r
+        \r
         return null;\r
     }\r
 \r
@@ -62,4 +67,13 @@ public class ToggleSimulation extends AbstractHandler {
         return (Boolean)state.getValue();\r
     }\r
 \r
+    @SuppressWarnings("unchecked")\r
+    @Override\r
+    public void updateElement(UIElement element, Map parameters) {\r
+        ICommandService commandService =\r
+            (ICommandService) PlatformUI.getWorkbench().getService(ICommandService.class);\r
+        Command command = commandService.getCommand(COMMAND);\r
+        boolean checked = (Boolean) command.getState(STATE).getValue();\r
+        element.setChecked(checked);\r
+    }\r
 }\r
index 4d5766a47b0f0ef5e07d7206726b35b7fb96da61..34bc6adc955a40665fb92ead91c24d127de29d73 100644 (file)
  *******************************************************************************/\r
 package org.simantics.sysdyn.ui.browser.contributions;\r
 \r
+import java.util.ArrayList;\r
 import java.util.Collection;\r
-import java.util.Collections;\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.ExperimentsFolder;\r
 \r
 public class Experiment extends ViewpointContributor<ExperimentsFolder> {\r
 \r
     @Override\r
-    public Collection<?> getContribution(ReadGraph graph, ExperimentsFolder input) throws DatabaseException {\r
-        // hasExperiment or something\r
-        return Collections.EMPTY_LIST;\r
+    public Collection<?> getContribution(ReadGraph graph, ExperimentsFolder experimentsFolder) throws DatabaseException {\r
+        ArrayList<AbstractNode> result = new ArrayList<AbstractNode>();\r
+        Builtins b = graph.getBuiltins();\r
+        for(Resource r : graph.syncRequest(new ObjectsWithType(experimentsFolder.resource, b.ConsistsOf, b.Experiment))) {\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
diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/ExperimentImager.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/ExperimentImager.java
new file mode 100644 (file)
index 0000000..a426223
--- /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.ExperimentNode;\r
+\r
+public class ExperimentImager extends ImagerContributor<ExperimentNode> {\r
+    \r
+    @Override\r
+    public ImageDescriptor getDescriptor(ReadGraph graph, ExperimentNode experiment) throws DatabaseException {\r
+        return ImageDescriptor.createFromURL(Activator.getDefault().getBundle().getResource("icons/time.png"));\r
+    }\r
+\r
+}\r
index f78e77ea18e9c59d8b1742dfc38d30be87b134fd..2e7b49f99fcb38b4993f2455809522c11dea4497 100644 (file)
@@ -20,9 +20,9 @@ import org.simantics.sysdyn.ui.browser.nodes.ExperimentNode;
 public class ExperimentLabeler extends LabelerContributor<ExperimentNode>{\r
 \r
     @Override\r
-    public String getLabel(ReadGraph graph, ExperimentNode input) throws DatabaseException {\r
-        // TODO Auto-generated method stub\r
-        return null;\r
+    public String getLabel(ReadGraph graph, ExperimentNode experiment) throws DatabaseException {\r
+        String name = graph.getPossibleRelatedValue(experiment.resource, graph.getBuiltins().HasName);\r
+        return name == null ? "Experiment (no name)" : name;\r
     }\r
 \r
 }\r
index adea16cd0b912eaf8b189cdb56047ca091683058..e7286e1fac1bf7c930f3357f3ff1e88ad25ba87d 100644 (file)
  *******************************************************************************/\r
 package org.simantics.sysdyn.ui.browser.nodes;\r
 \r
+import org.simantics.browsing.ui.common.node.IDoubleClickableNode;\r
 import org.simantics.db.Resource;\r
+import org.simantics.project.IProject;\r
+import org.simantics.simulation.project.IExperimentManager;\r
+import org.simantics.sysdyn.ui.handlers.SysdynExperimentActivator;\r
+import org.simantics.ui.SimanticsUI;\r
+import org.simantics.utils.ui.ErrorLogger;\r
 \r
-public class ExperimentNode extends AbstractNode {\r
+public class ExperimentNode extends AbstractNode implements IDoubleClickableNode{\r
 \r
     public ExperimentNode(Resource resource) {\r
         super(resource);\r
     }\r
 \r
+    @Override\r
+    public boolean handleDoubleClick() {\r
+        if (resource == null)\r
+            return false;\r
+        IProject project = SimanticsUI.getProject();\r
+        IExperimentManager experimentManager = project.getHint(IExperimentManager.KEY_EXPERIMENT_MANAGER);\r
+        if (experimentManager == null) {\r
+            ErrorLogger.defaultLogWarning("Experiment manager not available.", new Exception());\r
+            return false;\r
+        }\r
+        SysdynExperimentActivator.scheduleActivation(SimanticsUI.getSession(), project, experimentManager, resource);\r
+        return true;\r
+    }\r
+\r
 }\r
index 967fc89cd04173800729ee2f626b847a7d350ddc..4404ca06c5ac461a5c6087131ff4c5483bbd4671 100644 (file)
@@ -184,9 +184,7 @@ public class EquationView extends ViewPart implements ISelectionListener {
             variable = resource;\r
             a.configuration = graph.getPossibleObject(variable, b.PartOf);\r
             a.name = graph.getPossibleRelatedValue(resource, b.HasName);\r
-            a.isVariable = graph.isInstanceOf(variable, sr.Auxiliary) ||\r
-            graph.isInstanceOf(variable, sr.Stock) ||\r
-            graph.isInstanceOf(variable, sr.Valve);\r
+            a.isVariable = graph.isInstanceOf(variable, sr.IndependentVariable);\r
             if(a.name == null)\r
                 a.name = "";\r
             return a;\r
@@ -252,7 +250,7 @@ public class EquationView extends ViewPart implements ISelectionListener {
                                                 unitSelector.clear(); // empty units\r
                                                 shortcutTabs.updateTables(variable);\r
                                                 expressionController.setExpressionTypes(null);   \r
-                                                nameComposite.setName(result.name);\r
+                                                nameComposite.setName("");\r
                                                 expressionComposite.resetExpressionView(variable);\r
                                             }\r
                                         }\r
diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/DisposeExperiment.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/DisposeExperiment.java
new file mode 100644 (file)
index 0000000..13bc387
--- /dev/null
@@ -0,0 +1,35 @@
+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.simantics.project.IExperimentDescriptor;\r
+import org.simantics.project.IProject;\r
+import org.simantics.project.ProjectKeys;\r
+import org.simantics.simulation.experiment.IExperiment;\r
+import org.simantics.simulation.project.IExperimentManager;\r
+import org.simantics.ui.SimanticsUI;\r
+\r
+public class DisposeExperiment extends AbstractHandler {\r
+\r
+    @Override\r
+    public Object execute(ExecutionEvent event) throws ExecutionException {\r
+        IProject project = SimanticsUI.getProject();\r
+        IExperimentManager manager = \r
+            project.getHint(IExperimentManager.KEY_EXPERIMENT_MANAGER);\r
+        IExperiment experiment = manager.getActiveExperiment();\r
+        if (experiment != null)\r
+            experiment.shutdown();\r
+\r
+        /*\r
+        // Keep the UI happy.\r
+        IExperimentDescriptor ed = project.getHint(ProjectKeys.KEY_SELECTED_UI_EXPERIMENT);\r
+        if (ed != null) {\r
+            ed.getParent().removeHint(ProjectKeys.KEY_SELECTED_EXPERIMENT);\r
+            project.removeHint(ProjectKeys.KEY_SELECTED_UI_EXPERIMENT);\r
+        }\r
+        */\r
+        return null;\r
+    }\r
+\r
+}\r
index 2168b7b6bacb552b18dbee6f002b0847d6d1d991..0d4047a53fadcb4e21497540fc0720bc9c566bf6 100644 (file)
@@ -26,37 +26,44 @@ public class NewModelHandler extends AbstractHandler {
         SimanticsUI.getSession().asyncRequest(new WriteRequest() {\r
             \r
             @Override\r
-            public void perform(WriteGraph graph) throws DatabaseException {\r
+            public void perform(WriteGraph g) throws DatabaseException {\r
                 // Same as in SysdynProject.java. Should use the same code, not copy.\r
-                Builtins b = graph.getBuiltins();\r
-                SysdynResource sr = SysdynResource.getInstance(graph);\r
-                ModelingResources mr = ModelingResources.getInstance(graph);\r
-                ModelingUtils mu = new ModelingUtils(graph);\r
+                Builtins b = g.getBuiltins();\r
+                SysdynResource sr = SysdynResource.getInstance(g);\r
+                ModelingResources mr = ModelingResources.getInstance(g);\r
+                ModelingUtils mu = new ModelingUtils(g);\r
                 \r
-                Resource model = graph.newResource();\r
-                graph.claimValue(model, b.HasName, "Model1");\r
-                graph.claimValue(model, b.HasLabel, "Model1");\r
-                graph.claim(model, b.InstanceOf, sr.SysdynModel);\r
-                graph.claim(model, b.PartOf, SimanticsUI.getProject().get());\r
+                Resource model = g.newResource();\r
+                g.claimValue(model, b.HasName, "Model1");\r
+                g.claimValue(model, b.HasLabel, "Model1");\r
+                g.claim(model, b.InstanceOf, sr.SysdynModel);\r
+                g.claim(model, b.PartOf, SimanticsUI.getProject().get());\r
                 \r
                 \r
-                Resource diagram = OrderedSetUtils.create(graph, sr.ConfigurationDiagram);\r
-                GraphLayer l = new GraphLayerUtil(graph).createLayer(DiagramConstants.DEFAULT_LAYER_NAME, true);\r
-                graph.claim(diagram, mu.dr.HasLayer, l.getLayer());\r
-                graph.claimValue(diagram, b.HasName, "Diagrammi", StringJavaBinding.INSTANCE);\r
+                Resource diagram = OrderedSetUtils.create(g, sr.ConfigurationDiagram);\r
+                GraphLayer l = new GraphLayerUtil(g).createLayer(DiagramConstants.DEFAULT_LAYER_NAME, true);\r
+                g.claim(diagram, mu.dr.HasLayer, l.getLayer());\r
+                g.claimValue(diagram, b.HasName, "Diagrammi", StringJavaBinding.INSTANCE);\r
                 \r
-                Resource conf = GraphUtils.create2(graph\r
+                Resource conf = GraphUtils.create2(g, \r
                         sr.Configuration,\r
                         b.HasName, "Configuration",\r
                         sr.HasStartTime, 0.0,\r
                         sr.HasStopTime, 10.0);\r
 \r
-                graph.claim(conf, mr.CompositeToDiagram, diagram);\r
-                graph.claim(model, b.HasConfiguration, conf);\r
+                g.claim(conf, mr.CompositeToDiagram, diagram);\r
+                g.claim(model, b.HasConfiguration, conf);\r
                 \r
-                Resource mapping = graph.newResource();\r
-                graph.claim(mapping, b.InstanceOf, null, sr.DiagramToCompositeMapping);\r
-                graph.claim(diagram, b.HasTrigger, mapping);\r
+                Resource mapping = g.newResource();\r
+                g.claim(mapping, b.InstanceOf, null, sr.DiagramToCompositeMapping);\r
+                g.claim(diagram, b.HasTrigger, mapping);\r
+                \r
+                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.HasReportFactory, report,\r
+                        mu.b.PartOf, model);\r
             }\r
         });\r
         return null;\r
diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/RunBasicExperiment.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/RunBasicExperiment.java
new file mode 100644 (file)
index 0000000..8b81ffc
--- /dev/null
@@ -0,0 +1,47 @@
+package org.simantics.sysdyn.ui.handlers;\r
+\r
+\r
+import java.util.Map;\r
+\r
+import org.eclipse.core.commands.AbstractHandler;\r
+import org.eclipse.core.commands.Command;\r
+import org.eclipse.core.commands.ExecutionEvent;\r
+import org.eclipse.core.commands.ExecutionException;\r
+import org.eclipse.ui.PlatformUI;\r
+import org.eclipse.ui.commands.ICommandService;\r
+import org.eclipse.ui.commands.IElementUpdater;\r
+import org.eclipse.ui.menus.UIElement;\r
+import org.simantics.simulation.experiment.IDynamicExperiment;\r
+import org.simantics.simulation.experiment.IExperiment;\r
+import org.simantics.simulation.project.IExperimentManager;\r
+import org.simantics.sysdyn.ui.actions.ToggleSimulation;\r
+import org.simantics.ui.SimanticsUI;\r
+\r
+public class RunBasicExperiment extends AbstractHandler implements IElementUpdater {\r
+    \r
+    public static final String COMMAND = "org.simantics.sysdyn.ui.run";\r
+    \r
+    @Override\r
+    public Object execute(ExecutionEvent event) throws ExecutionException {\r
+        IExperimentManager manager = \r
+            SimanticsUI.getProject().getHint(IExperimentManager.KEY_EXPERIMENT_MANAGER);\r
+        IExperiment experiment = manager.getActiveExperiment();\r
+        if(experiment instanceof IDynamicExperiment)\r
+            ((IDynamicExperiment)experiment).simulate(true);\r
+        return null;\r
+    }\r
+\r
+    @SuppressWarnings("unchecked")\r
+    @Override\r
+    public void updateElement(UIElement element, Map parameters) {\r
+        ICommandService commandService =\r
+            (ICommandService) PlatformUI.getWorkbench().getService(ICommandService.class);\r
+        Command command = commandService.getCommand(ToggleSimulation.COMMAND);\r
+        boolean checked = (Boolean) command.getState(ToggleSimulation.STATE).getValue();\r
+        if(checked)\r
+            this.setBaseEnabled(false);\r
+        else\r
+            this.setBaseEnabled(true);\r
+\r
+    }\r
+}\r
diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/SaveResultsHandler.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/SaveResultsHandler.java
new file mode 100644 (file)
index 0000000..9d7beed
--- /dev/null
@@ -0,0 +1,24 @@
+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.simantics.simulation.experiment.IDynamicExperiment;\r
+import org.simantics.simulation.experiment.IExperiment;\r
+import org.simantics.simulation.project.IExperimentManager;\r
+import org.simantics.ui.SimanticsUI;\r
+\r
+public class SaveResultsHandler extends AbstractHandler {\r
+\r
+    @Override\r
+    public Object execute(ExecutionEvent event) throws ExecutionException {\r
+        IExperimentManager manager = \r
+            SimanticsUI.getProject().getHint(IExperimentManager.KEY_EXPERIMENT_MANAGER);\r
+        IExperiment experiment = manager.getActiveExperiment();\r
+        if(experiment instanceof IDynamicExperiment) {\r
+            ((IDynamicExperiment)experiment).saveState();\r
+        }\r
+        return null;\r
+    }\r
+\r
+}\r
diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/SysdynExperimentActivator.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/SysdynExperimentActivator.java
new file mode 100644 (file)
index 0000000..4b68160
--- /dev/null
@@ -0,0 +1,162 @@
+package org.simantics.sysdyn.ui.handlers;\r
+\r
+import java.util.concurrent.Semaphore;\r
+\r
+import org.eclipse.core.runtime.IProgressMonitor;\r
+import org.eclipse.core.runtime.IStatus;\r
+import org.eclipse.core.runtime.Status;\r
+import org.eclipse.core.runtime.jobs.Job;\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.RequestProcessor;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.exception.AdaptionException;\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.message.MessageService;\r
+import org.simantics.project.IExperimentDescriptor;\r
+import org.simantics.project.IModelDescriptor;\r
+import org.simantics.project.IProject;\r
+import org.simantics.project.IProjectElement;\r
+import org.simantics.project.ProjectKeys;\r
+import org.simantics.project.exception.ProjectException;\r
+import org.simantics.simulation.experiment.IExperiment;\r
+import org.simantics.simulation.model.ExperimentLoadingFailed;\r
+import org.simantics.simulation.project.IExperimentActivationListener;\r
+import org.simantics.simulation.project.IExperimentManager;\r
+import org.simantics.sysdyn.ui.listeners.SysdynExperimentManagerListener;\r
+import org.simantics.utils.DataContainer;\r
+import org.simantics.utils.ui.ErrorLogger;\r
+import org.simantics.utils.ui.ExceptionUtils;\r
+import org.simantics.utils.ui.dialogs.ShowMessage;\r
+\r
+public class SysdynExperimentActivator {\r
+    /**\r
+     * @param project\r
+     * @param experimentManager\r
+     * @param experiment\r
+     */\r
+    public static void scheduleActivation(RequestProcessor processor, final IProject project, final IExperimentManager experimentManager, final Resource experiment) {\r
+        String jobName = "Activate Experiment";\r
+        String experimentName = getName(processor, experiment);\r
+        if (experimentName != null)\r
+            jobName += " '" + experimentName + "'";\r
+\r
+        scheduleActivation(jobName, project, experimentManager, experiment);\r
+    }\r
+\r
+    /**\r
+     * @param project\r
+     * @param experimentManager\r
+     * @param experiment\r
+     */\r
+    public static void scheduleActivation(String jobName, final IProject project, final IExperimentManager experimentManager, final Resource experiment) {\r
+        new Job(jobName) {\r
+            @Override\r
+            protected IStatus run(final IProgressMonitor monitor) {\r
+                return SysdynExperimentActivator.activate(monitor, project, experimentManager, experiment);\r
+            }\r
+        }.schedule();\r
+    }\r
+\r
+    public static IStatus activate(IProgressMonitor monitor, IProject project, IExperimentManager experimentManager, Resource experiment) {\r
+        return new SysdynExperimentActivator().activateExperiment(monitor, project, experimentManager, experiment);\r
+    }\r
+\r
+    private static String getName(RequestProcessor processor, final Resource resource) {\r
+        try {\r
+            return processor.syncRequest(new Read<String>() {\r
+                @Override\r
+                public String perform(ReadGraph graph) throws DatabaseException {\r
+                    try {\r
+                        return graph.adapt(resource, String.class);\r
+                    } catch (AdaptionException e) {\r
+                        return GraphUtils.getReadableName(graph, resource);\r
+                    }\r
+                }\r
+            });\r
+        } catch (DatabaseException e) {\r
+            ErrorLogger.defaultLogWarning(e);\r
+            return null;\r
+        }\r
+    }\r
+\r
+    private IStatus activateExperiment(final IProgressMonitor monitor, final IProject project, final IExperimentManager manager, final Resource experimentResource) {\r
+        monitor.beginTask("Activating experiment", IProgressMonitor.UNKNOWN);\r
+        try {\r
+            SysdynExperimentManagerListener.listenManager(manager);\r
+            final Semaphore activated = new Semaphore(0);\r
+            final DataContainer<Throwable> problem = new DataContainer<Throwable>();\r
+            manager.startExperiment(experimentResource, new IExperimentActivationListener() {\r
+                \r
+                @Override\r
+                public void onExperimentActivated(final IExperiment experiment) {\r
+\r
+                    MessageService.defaultLog(new org.eclipse.core.runtime.Status(IStatus.INFO, "org.simantics.simulation.ui", 0, "Activated experiment " + experiment.getIdentifier() , null));\r
+                    \r
+                    \r
+                    activated.release();\r
+                    // Set the selected experiment into the the model descriptor.\r
+                    new Thread("Set Selected Experiment") {\r
+                        @Override\r
+                        public void run() {\r
+                            setSelectedExperiment(project, experimentResource);\r
+                        }\r
+                    }.start();\r
+                }\r
+                @Override\r
+                public void onFailure(Throwable e) {\r
+                    problem.set(e);\r
+                    activated.release();\r
+                }\r
+                @Override\r
+                public void onMessage(IStatus message) {\r
+                    MessageService.getDefault().log(message);\r
+                    /*ILogger logger = MessageService.getDefault();\r
+                    MultiStatus init = new MultiStatus(Activator.PLUGIN_ID, 0, "Activating experiment", null);\r
+                    for (String msg : messages) {\r
+                        init.add(new Status(IStatus.INFO, Activator.PLUGIN_ID, msg));\r
+                    }\r
+                    logger.log(init);*/\r
+                }\r
+            }, true);\r
+            try {\r
+                activated.acquire();\r
+                Throwable t = problem.get();\r
+                if (t != null) {\r
+                    if (t instanceof ExperimentLoadingFailed) {\r
+                        ErrorLogger.defaultLogError(t);\r
+                        ShowMessage.showError("Experiment Activation Failed", t.getMessage());\r
+                    } else {\r
+                        ExceptionUtils.logAndShowError(t);\r
+                    }\r
+                }\r
+                \r
+                return Status.OK_STATUS;\r
+                //return new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Experiment activation failed, see exception for details.", problem.get());\r
+            } catch (InterruptedException e) {\r
+                return Status.CANCEL_STATUS;\r
+            }\r
+        } finally {\r
+            monitor.done();\r
+        }\r
+    }\r
+\r
+    private void setSelectedExperiment(IProject project, Resource experiment) {\r
+        try {\r
+            for (IProjectElement model : project.members()) {\r
+                if (model instanceof IModelDescriptor) {\r
+                    for (IProjectElement member : ((IModelDescriptor) model).members()) {\r
+                        if (member instanceof IExperimentDescriptor && experiment.equals(member.get())) {\r
+                            model.setHint(ProjectKeys.KEY_SELECTED_EXPERIMENT, member);\r
+                            project.setHint(ProjectKeys.KEY_SELECTED_UI_EXPERIMENT, member);\r
+                            break;\r
+                        }\r
+                    }\r
+                }\r
+            }\r
+        } catch (ProjectException e) {\r
+            ErrorLogger.defaultLogError(e);\r
+        }\r
+    }\r
+}\r
diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/listeners/SysdynExperimentListener.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/listeners/SysdynExperimentListener.java
new file mode 100644 (file)
index 0000000..bd81f37
--- /dev/null
@@ -0,0 +1,40 @@
+package org.simantics.sysdyn.ui.listeners;\r
+\r
+import org.eclipse.core.commands.Command;\r
+import org.eclipse.core.commands.State;\r
+import org.eclipse.ui.PlatformUI;\r
+import org.eclipse.ui.commands.ICommandService;\r
+import org.eclipse.ui.contexts.IContextActivation;\r
+import org.simantics.simulation.experiment.ExperimentState;\r
+import org.simantics.simulation.experiment.IExperimentListener;\r
+import org.simantics.sysdyn.ui.actions.ToggleSimulation;\r
+import org.simantics.sysdyn.ui.handlers.RunBasicExperiment;\r
+\r
+public class SysdynExperimentListener  implements IExperimentListener {\r
+\r
+    IContextActivation contextActivation;\r
+\r
+    @Override\r
+    public void stateChanged(final ExperimentState state) {\r
+        PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {\r
+\r
+            @Override\r
+            public void run() {\r
+                ICommandService commandService =\r
+                    (ICommandService) PlatformUI.getWorkbench().getService(ICommandService.class);\r
+                Command command = commandService.getCommand(ToggleSimulation.COMMAND);\r
+                State buttonState = command.getState(ToggleSimulation.STATE);\r
+                                \r
+                switch(state) {\r
+                case DISPOSED:\r
+                    buttonState.setValue(false); \r
+                    break;\r
+                }\r
+                commandService.refreshElements(command.getId(), null); \r
+                commandService.refreshElements(RunBasicExperiment.COMMAND, null);\r
+            }\r
+            \r
+        });\r
+    }\r
+\r
+}\r
diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/listeners/SysdynExperimentManagerListener.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/listeners/SysdynExperimentManagerListener.java
new file mode 100644 (file)
index 0000000..5c385fd
--- /dev/null
@@ -0,0 +1,96 @@
+package org.simantics.sysdyn.ui.listeners;\r
+\r
+import java.util.ArrayList;\r
+import java.util.Collection;\r
+import java.util.HashSet;\r
+import java.util.Set;\r
+\r
+import org.eclipse.ui.IWorkbench;\r
+import org.eclipse.ui.PlatformUI;\r
+import org.eclipse.ui.contexts.IContextActivation;\r
+import org.eclipse.ui.contexts.IContextService;\r
+import org.simantics.simulation.experiment.IExperiment;\r
+import org.simantics.simulation.project.IExperimentManager;\r
+import org.simantics.simulation.project.IExperimentManagerListener;\r
+\r
+public class SysdynExperimentManagerListener implements IExperimentManagerListener{\r
+\r
+    public static final String BASIC_EXPERIMENT_CONTEXT = "org.simantics.sysdyn.ui.basicExperiment";\r
+    \r
+    static Set<IExperimentManager> managers = \r
+        new HashSet<IExperimentManager>();\r
+    \r
+    IExperimentManager manager;\r
+    \r
+    Collection<IContextActivation> contextActivations = \r
+        new ArrayList<IContextActivation>();\r
+        \r
+    public SysdynExperimentManagerListener(IExperimentManager manager) {\r
+        this.manager = manager;\r
+    }\r
+\r
+    public static void listenManager(IExperimentManager manager) {\r
+        synchronized(managers) {\r
+            if(managers.contains(manager))\r
+                return;\r
+            SysdynExperimentManagerListener listener = \r
+                new SysdynExperimentManagerListener(manager);\r
+            manager.addListener(listener);\r
+            managers.add(manager);\r
+        }\r
+    }\r
+    \r
+    @Override\r
+    public void activeExperimentLoaded(final IExperiment experiment) {        \r
+        experiment.addListener(new SysdynExperimentListener());\r
+\r
+        PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {\r
+\r
+            @Override\r
+            public void run() {\r
+                IContextService contextService =\r
+                    (IContextService)PlatformUI.getWorkbench()\r
+                    .getActiveWorkbenchWindow().getService(IContextService.class);\r
+                synchronized(contextActivations) {\r
+                    contextActivations.add(contextService.activateContext(BASIC_EXPERIMENT_CONTEXT));\r
+                }\r
+            }\r
+            \r
+        });\r
+    }\r
+\r
+    @Override\r
+    public void activeExperimentUnloaded() {\r
+        \r
+        synchronized(contextActivations) {\r
+            final Collection<IContextActivation> oldContextActivations = \r
+                contextActivations;\r
+            \r
+            contextActivations = new ArrayList<IContextActivation>();\r
+            \r
+            final IWorkbench workbench = PlatformUI.getWorkbench();\r
+            workbench.getDisplay().asyncExec(new Runnable() {\r
+    \r
+                @Override\r
+                public void run() {\r
+                    if (workbench.isClosing())\r
+                        return;\r
+                    \r
+                    IContextService contextService =\r
+                        (IContextService)workbench.getActiveWorkbenchWindow().getService(IContextService.class);\r
+                    contextService.deactivateContexts(oldContextActivations);                                \r
+                }\r
+                \r
+            });\r
+        }\r
+            \r
+    }\r
+\r
+    @Override\r
+    public void managerDisposed() {\r
+        synchronized(managers) {\r
+            managers.remove(manager);\r
+        }\r
+    }\r
+\r
+}\r
index 178089b8df98095b5f4d6978cdf483f4aa26a61c..3ccec2064ed29930aea34a5cae8a417e3d49da58 100644 (file)
@@ -25,6 +25,7 @@ import org.simantics.db.service.LifecycleSupport;
 import org.simantics.diagram.DiagramConstants;\r
 import org.simantics.diagram.synchronization.graph.layer.GraphLayer;\r
 import org.simantics.diagram.synchronization.graph.layer.GraphLayerUtil;\r
+import org.simantics.layer0.utils.direct.GraphUtils;\r
 import org.simantics.modeling.ModelingResources;\r
 import org.simantics.modeling.ModelingUtils;\r
 import org.simantics.project.ProjectElementType;\r
@@ -105,7 +106,14 @@ public class SysdynProject extends AbstractProjectFeature {
                 Resource mapping = g.newResource();\r
                 g.claim(mapping, b.InstanceOf, null, mr.DiagramToCompositeMapping);\r
                 g.claim(diagram, b.HasTrigger, mapping);\r
+                \r
+                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.HasReportFactory, report,\r
+                        mu.b.PartOf, model);\r
+                \r
                 callback.run(model);\r
             } catch(Exception e) {\r
                 errorCallback.run(e);\r
diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/project/SysdynProjectLifeCycle.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/project/SysdynProjectLifeCycle.java
new file mode 100644 (file)
index 0000000..d012708
--- /dev/null
@@ -0,0 +1,156 @@
+package org.simantics.sysdyn.ui.project;\r
+\r
+import java.util.Timer;\r
+\r
+import org.simantics.databoard.accessor.Accessor;\r
+import org.simantics.db.Builtins;\r
+import org.simantics.db.RequestProcessor;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.Session;\r
+import org.simantics.db.VirtualGraph;\r
+import org.simantics.db.WriteGraph;\r
+import org.simantics.db.common.procedure.single.SingleSetListener;\r
+import org.simantics.db.common.request.ObjectsWithType;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.db.layer0.adapter.ActivationManager;\r
+import org.simantics.db.layer0.adapter.RuntimeValuations;\r
+import org.simantics.db.layer0.adapter.TrendVariable;\r
+import org.simantics.db.layer0.adapter.ValuationVirtualGraph;\r
+import org.simantics.db.layer0.util.Simantics;\r
+import org.simantics.db.management.ISessionContext;\r
+import org.simantics.db.service.VirtualGraphSupport;\r
+import org.simantics.project.IProject;\r
+import org.simantics.project.IProjectLifeCycle;\r
+import org.simantics.simulation.experiment.IExperiment;\r
+import org.simantics.simulation.project.IExperimentManager;\r
+import org.simantics.ui.SimanticsUI;\r
+import org.simantics.utils.datastructures.hints.IHintContext.Key;\r
+import org.simantics.utils.datastructures.hints.IHintContext.KeyOf;\r
+\r
+public class SysdynProjectLifeCycle implements IProjectLifeCycle{\r
+\r
+    public static final Key INITIALIZED = new KeyOf(Boolean.class, "SYSDYN_LIFECYCLE_INITIALIZED");\r
+\r
+    static Timer timer = new Timer();\r
+\r
+    @Override\r
+    public void onCreate(WriteGraph g, Resource project) {\r
+//        System.out.println("onCreate Apros Project: " + GraphUtils.getReadableName(g, project));\r
+    }\r
+\r
+    @Override\r
+    public void onDestroy(WriteGraph g, Resource project) {\r
+//        System.out.println("onDestroy Apros Project: " + GraphUtils.getReadableName(g, project));\r
+    }\r
+\r
+    @Override\r
+    public void onActivated(RequestProcessor processor, final IProject project) {\r
+\r
+//      System.out.println("onActivated DEVS Project");\r
+\r
+        ISessionContext context = SimanticsUI.getSessionContext();\r
+        if (context.getHint(INITIALIZED) == null) {\r
+\r
+            try {\r
+\r
+                Resource projectResource = project.get();\r
+\r
+                final Session session = context.getSession();\r
+\r
+                session.registerService(RuntimeValuations.class, new RuntimeValuations() {\r
+\r
+                    @Override\r
+                    public boolean supports(String valuation) {\r
+\r
+                        IExperimentManager expMan = project.getHint(IExperimentManager.KEY_EXPERIMENT_MANAGER);\r
+                        IExperiment experiment = expMan.getExperiment(valuation);\r
+\r
+                        return experiment != null;\r
+\r
+                    }\r
+\r
+                    @Override\r
+                    public Accessor getAccessor(String variableIdentityPrefix, String valuation, String suffix) {\r
+                        return null;\r
+                    }\r
+\r
+                    @Override\r
+                    public TrendVariable getVariable(String variableIdentityPrefix, String valuation, String suffix) {\r
+\r
+                        return null;\r
+\r
+                    }\r
+\r
+                });\r
+\r
+\r
+//                System.out.println("A1");\r
+\r
+                Builtins b = session.getBuiltins();\r
+                ActivationManager activationManager = session.getService(ActivationManager.class);\r
+                if (activationManager != null) {\r
+                    activationManager.activate(processor, projectResource);\r
+                }\r
+\r
+//                System.out.println("A2");\r
+\r
+                VirtualGraphSupport support = session.getService(VirtualGraphSupport.class);\r
+                final VirtualGraph graph = support.create();\r
+                session.registerService(VirtualGraph.class, graph);\r
+\r
+//                System.out.println("A3");\r
+\r
+                session.asyncRequest(new ObjectsWithType(projectResource, b.ConsistsOf, b.Model), new SingleSetListener<Resource>() {\r
+\r
+                    @Override\r
+                    public void add(final Resource model) {\r
+                        // FIXME:\r
+//                      System.out.println("A4");\r
+                        Simantics.async(new Runnable() {\r
+\r
+                            @Override\r
+                            public void run() {\r
+                                try {\r
+//                                  System.out.println("A5 " + model);\r
+                                    graph.register(new ValuationVirtualGraph(session, model));\r
+                                } catch (DatabaseException e) {\r
+                                    e.printStackTrace();\r
+                                }\r
+                            }\r
+\r
+                        });\r
+                    }\r
+\r
+                    @Override\r
+                    public void exception(Throwable t) {\r
+                        t.printStackTrace();\r
+                    }\r
+\r
+                    @Override\r
+                    public boolean isDisposed() {\r
+                        return false;\r
+                    }\r
+\r
+                });\r
+\r
+                support.resume("experiments");\r
+\r
+            } catch (DatabaseException e) {\r
+\r
+                e.printStackTrace();\r
+\r
+            }\r
+\r
+\r
+\r
+            context.setHint(INITIALIZED, Boolean.TRUE);\r
+\r
+        }\r
+\r
+    }\r
+\r
+    @Override\r
+    public void onDeactivated(IProject project) {\r
+//        System.out.println("onDeactivated Apros Project: " + project.getName());\r
+    }\r
+}\r
index 0a04685d3229e428fdf84dbda0a371fd0195b1a5..13b91a111172891b3936aba144b44fadb30e5687 100644 (file)
@@ -45,7 +45,6 @@ import org.simantics.sysdyn.manager.SysdynModel;
 import org.simantics.sysdyn.manager.SysdynModelManager;\r
 import org.simantics.sysdyn.representation.IElement;\r
 import org.simantics.sysdyn.representation.Variable;\r
-import org.simantics.sysdyn.ui.simulation.SimulationScheduler;\r
 import org.simantics.ui.SimanticsUI;\r
 import org.simantics.utils.ui.ISelectionUtils;\r
 import org.simantics.utils.ui.jface.ActiveSelectionProvider;\r
@@ -209,7 +208,7 @@ public class TrendView extends ViewPart {
             if(model == null) {\r
                 model = \r
                     SysdynModelManager.getInstance(g.getSession()).getModel(g, configuration);\r
-                SimulationScheduler.start(model);\r
+                // SimulationScheduler.start(model); Don't want this to operate simulation\r
                 model.addResultListener(updater);\r
                 models.put(configuration, model);\r
             }\r
@@ -229,6 +228,8 @@ public class TrendView extends ViewPart {
             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
                 IElement element = model.getElement(resource);\r
                 if(element instanceof Variable) {\r
                     Variable var = (Variable)element;                   \r
index c7a329ca1c7ffea0eda01656b2ce7bf67cc16c3b..d10349c079bd7ad17754ad07a3a5d30c382dc59f 100644 (file)
@@ -7,11 +7,17 @@ Bundle-RequiredExecutionEnvironment: JavaSE-1.6
 Require-Bundle: org.simantics.objmap;bundle-version="0.1.0",
  org.simantics.db;bundle-version="0.6.2",
  org.simantics.modelica;bundle-version="1.0.0",
- org.simantics.db.common;bundle-version="0.8.0"
+ org.simantics.db.common;bundle-version="0.8.0",
+ org.simantics.simulation;bundle-version="1.0.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"
 Export-Package: org.simantics.sysdyn,
  org.simantics.sysdyn.expressionParser,
  org.simantics.sysdyn.manager,
  org.simantics.sysdyn.modelica,
  org.simantics.sysdyn.representation,
  org.simantics.sysdyn.representation.visitors,
+ org.simantics.sysdyn.simulation,
  org.simantics.sysdyn.tableParser
diff --git a/org.simantics.sysdyn/adapters.xml b/org.simantics.sysdyn/adapters.xml
new file mode 100644 (file)
index 0000000..1bd8953
--- /dev/null
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>\r
+<!--\r
+    Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
+    in Industry THTH ry.\r
+    All rights reserved. This program and the accompanying materials\r
+    are made available under the terms of the Eclipse Public License v1.0\r
+    which accompanies this distribution, and is available at\r
+    http://www.eclipse.org/legal/epl-v10.html\r
+   \r
+    Contributors:\r
+        VTT Technical Research Centre of Finland - initial API and implementation\r
+ -->\r
+\r
+<adapters>    \r
+    <target\r
+        interface="org.simantics.simulation.model.IModel">\r
+        <type\r
+            uri="http://www.simantics.org/Sysdyn-1.0/SysdynModel"\r
+            class="org.simantics.sysdyn.manager.SysdynModel">\r
+            <this />\r
+        </type>\r
+    </target>\r
+</adapters>
\ No newline at end of file
index c8231e16abdc74c8c58b252addefa842146f9270..668279e108956a71d77892b266cf53fd1fed48f0 100644 (file)
@@ -22,6 +22,7 @@ public class SysdynResource {
     \r
     public final Resource Auxiliary;\r
     public final Resource AuxiliarySymbol;\r
+    public final Resource BasicExperiment;\r
     public final Resource Cloud;\r
     public final Resource Configuration;\r
     public final Resource ConfigurationDiagram;\r
@@ -29,8 +30,10 @@ public class SysdynResource {
     public final Resource DelayExpression;\r
     public final Resource Dependency;\r
     public final Resource DiagramToCompositeMapping;\r
+    public final Resource Experiment;\r
     public final Resource Expression;\r
     public final Resource Flow;\r
+    public final Resource GameExperiment;\r
     public final Resource HasAngle;\r
     public final Resource HasEquation;\r
     public final Resource HasExpression;\r
@@ -58,11 +61,13 @@ public class SysdynResource {
     public final Resource ParameterExpression;\r
     public final Resource PhantomTerminal;\r
     public final Resource RefersTo;\r
+    public final Resource SimulateOnChangeExperiment;\r
     public final Resource Stock;\r
     public final Resource StockExpression;\r
     public final Resource StockSymbol;\r
     public final Resource SysdynConnectionType;\r
     public final Resource SysdynModel;\r
+    public final Resource SysdynModelManager;\r
     public final Resource SysdynProject;\r
     public final Resource SysdynSymbols;\r
     public final Resource Terminal;\r
@@ -74,6 +79,7 @@ public class SysdynResource {
     public static class URIs {\r
         public static final String Auxiliary = "http://www.simantics.org/Sysdyn-1.0/Auxiliary";\r
         public static final String AuxiliarySymbol = "http://www.simantics.org/Sysdyn-1.0/AuxiliarySymbol";\r
+        public static final String BasicExperiment = "http://www.simantics.org/Sysdyn-1.0/BasicExperiment";\r
         public static final String Cloud = "http://www.simantics.org/Sysdyn-1.0/Cloud";\r
         public static final String Configuration = "http://www.simantics.org/Sysdyn-1.0/Configuration";\r
         public static final String ConfigurationDiagram = "http://www.simantics.org/Sysdyn-1.0/ConfigurationDiagram";\r
@@ -81,8 +87,10 @@ public class SysdynResource {
         public static final String DelayExpression = "http://www.simantics.org/Sysdyn-1.0/DelayExpression";\r
         public static final String Dependency = "http://www.simantics.org/Sysdyn-1.0/Dependency";\r
         public static final String DiagramToCompositeMapping = "http://www.simantics.org/Sysdyn-1.0/DiagramToCompositeMapping";\r
+        public static final String Experiment = "http://www.simantics.org/Sysdyn-1.0/Experiment";\r
         public static final String Expression = "http://www.simantics.org/Sysdyn-1.0/Expression";\r
         public static final String Flow = "http://www.simantics.org/Sysdyn-1.0/Flow";\r
+        public static final String GameExperiment = "http://www.simantics.org/Sysdyn-1.0/GameExperiment";\r
         public static final String HasAngle = "http://www.simantics.org/Sysdyn-1.0/HasAngle";\r
         public static final String HasEquation = "http://www.simantics.org/Sysdyn-1.0/HasEquation";\r
         public static final String HasExpression = "http://www.simantics.org/Sysdyn-1.0/HasExpression";\r
@@ -110,11 +118,13 @@ 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 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
         public static final String StockSymbol = "http://www.simantics.org/Sysdyn-1.0/StockSymbol";\r
         public static final String SysdynConnectionType = "http://www.simantics.org/Sysdyn-1.0/SysdynConnectionType";\r
         public static final String SysdynModel = "http://www.simantics.org/Sysdyn-1.0/SysdynModel";\r
+        public static final String SysdynModelManager = "http://www.simantics.org/Sysdyn-1.0/SysdynModelManager";\r
         public static final String SysdynProject = "http://www.simantics.org/Sysdyn-1.0/SysdynProject";\r
         public static final String SysdynSymbols = "http://www.simantics.org/Sysdyn-1.0/SysdynSymbols";\r
         public static final String Terminal = "http://www.simantics.org/Sysdyn-1.0/Terminal";\r
@@ -136,6 +146,7 @@ public class SysdynResource {
     public SysdynResource(ReadGraph graph) {\r
         Auxiliary = getResourceOrNull(graph, URIs.Auxiliary);\r
         AuxiliarySymbol = getResourceOrNull(graph, URIs.AuxiliarySymbol);\r
+        BasicExperiment = getResourceOrNull(graph, URIs.BasicExperiment);\r
         Cloud = getResourceOrNull(graph, URIs.Cloud);\r
         Configuration = getResourceOrNull(graph, URIs.Configuration);\r
         ConfigurationDiagram = getResourceOrNull(graph, URIs.ConfigurationDiagram);\r
@@ -143,8 +154,10 @@ public class SysdynResource {
         DelayExpression = getResourceOrNull(graph, URIs.DelayExpression);\r
         Dependency = getResourceOrNull(graph, URIs.Dependency);\r
         DiagramToCompositeMapping = getResourceOrNull(graph, URIs.DiagramToCompositeMapping);\r
+        Experiment = getResourceOrNull(graph, URIs.Experiment);\r
         Expression = getResourceOrNull(graph, URIs.Expression);\r
         Flow = getResourceOrNull(graph, URIs.Flow);\r
+        GameExperiment = getResourceOrNull(graph, URIs.GameExperiment);\r
         HasAngle = getResourceOrNull(graph, URIs.HasAngle);\r
         HasEquation = getResourceOrNull(graph, URIs.HasEquation);\r
         HasExpression = getResourceOrNull(graph, URIs.HasExpression);\r
@@ -172,11 +185,13 @@ public class SysdynResource {
         ParameterExpression = getResourceOrNull(graph, URIs.ParameterExpression);\r
         PhantomTerminal = getResourceOrNull(graph, URIs.PhantomTerminal);\r
         RefersTo = getResourceOrNull(graph, URIs.RefersTo);\r
+        SimulateOnChangeExperiment = getResourceOrNull(graph, URIs.SimulateOnChangeExperiment);\r
         Stock = getResourceOrNull(graph, URIs.Stock);\r
         StockExpression = getResourceOrNull(graph, URIs.StockExpression);\r
         StockSymbol = getResourceOrNull(graph, URIs.StockSymbol);\r
         SysdynConnectionType = getResourceOrNull(graph, URIs.SysdynConnectionType);\r
         SysdynModel = getResourceOrNull(graph, URIs.SysdynModel);\r
+        SysdynModelManager = getResourceOrNull(graph, URIs.SysdynModelManager);\r
         SysdynProject = getResourceOrNull(graph, URIs.SysdynProject);\r
         SysdynSymbols = getResourceOrNull(graph, URIs.SysdynSymbols);\r
         Terminal = getResourceOrNull(graph, URIs.Terminal);\r
diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynExperiment.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynExperiment.java
new file mode 100644 (file)
index 0000000..5a1a29f
--- /dev/null
@@ -0,0 +1,143 @@
+package org.simantics.sysdyn.manager;\r
+\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.Session;\r
+import org.simantics.db.common.request.ReadRequest;\r
+import org.simantics.db.exception.DatabaseException;\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.simulation.SimulationScheduler;\r
+\r
+public class SysdynExperiment extends Experiment implements IDynamicExperiment {\r
+\r
+    Session session;\r
+    Runnable modificationListener;\r
+\r
+    public SysdynExperiment(Resource model) {\r
+        super(model);\r
+        // TODO Auto-generated constructor stub\r
+    }\r
+\r
+    @Override\r
+    public void rewindTo(double time) {\r
+        // TODO Auto-generated method stub\r
+        System.out.println("rewindTo");\r
+    }\r
+\r
+    @Override\r
+    public void saveState() {\r
+        // TODO Auto-generated method stub\r
+        System.out.println("saveState");\r
+    }\r
+\r
+    /**\r
+     * enabled: is simulate on change enabled\r
+     */\r
+    @Override\r
+    public void simulate(boolean enabled) {\r
+        System.out.println("simulate");\r
+        if(enabled) {\r
+            changeState(ExperimentState.STOPPED);\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 sysdynmodel = \r
+                        SysdynModelManager.getInstance(session).getModel(graph, configuration);\r
+                    SimulationScheduler.start(sysdynmodel);\r
+                }\r
+            });\r
+        }\r
+\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
+            } \r
+        }\r
+        else {\r
+            changeState(ExperimentState.STOPPED);            \r
+        }\r
+\r
+    }\r
+\r
+    @Override\r
+    public void simulateDuration(double duration) {\r
+        // TODO Auto-generated method stub\r
+        System.out.println("simulateDuartion");\r
+    }\r
+\r
+    @Override\r
+    public void refresh(Session session) {\r
+        // TODO Auto-generated method stub\r
+        System.out.println("refresh");\r
+    }\r
+\r
+    public void init(ReadGraph g) {\r
+        System.out.println("init");\r
+        changeState(ExperimentState.STOPPED);\r
+        this.session = g.getSession();\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
+                    @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
+                        modificationListener = null;\r
+                        \r
+                    }\r
+                });\r
+                break;\r
+            }\r
+    }\r
+\r
+\r
+}\r
index 28c98110937f67c331a9d4588fa7d952f2c1b53d..65d31d32586dbc4e585a52eaa47da551d3166f0e 100644 (file)
@@ -27,6 +27,9 @@ import org.simantics.modelica.data.SimulationResult;
 import org.simantics.objmap.IMapping;\r
 import org.simantics.objmap.IMappingListener;\r
 import org.simantics.objmap.Mappings;\r
+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.modelica.ModelicaWriter;\r
 import org.simantics.sysdyn.representation.Configuration;\r
 import org.simantics.sysdyn.representation.IElement;\r
@@ -36,7 +39,7 @@ import org.simantics.sysdyn.representation.SysdynSchema;
  * Maintains a Java representation of system dynamic model.\r
  * @author Hannu Niemistö\r
  */\r
-public class SysdynModel implements IMappingListener {\r
+public class SysdynModel implements IMappingListener, IModel {\r
 \r
     Session session;\r
     Resource configurationResource;    \r
@@ -69,6 +72,14 @@ public class SysdynModel implements IMappingListener {
             e.printStackTrace();\r
         }\r
     }\r
+    \r
+    \r
+    /*\r
+     * some dummy(?) stuff for experiments\r
+     */\r
+    public SysdynModel(Resource configurationResource) {\r
+        this.configurationResource = configurationResource;        \r
+    }\r
 \r
     public synchronized void simulate(IModelicaMonitor monitor) throws IOException {\r
         try {\r
@@ -169,4 +180,16 @@ public class SysdynModel implements IMappingListener {
         }\r
     }\r
 \r
+    @Override\r
+    public IExperiment loadExperiment(ReadGraph g, Resource experiment, IExperimentActivationListener listener) {\r
+        SysdynExperiment exp = new SysdynExperiment(configurationResource);\r
+        try {\r
+            exp.init(g);\r
+            listener.onExperimentActivated(exp);\r
+            return exp;\r
+        } catch(Exception e) {\r
+            listener.onFailure(e);\r
+            return null;\r
+        }\r
+    }   \r
 }\r
similarity index 91%
rename from org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/simulation/SimulationJob.java
rename to org.simantics.sysdyn/src/org/simantics/sysdyn/simulation/SimulationJob.java
index afeb86b07468e6418d9710930e9f66b78c92857a..5b08665906dc3ec2a921b80db783063791890252 100644 (file)
@@ -9,7 +9,7 @@
  * Contributors:\r
  *     VTT Technical Research Centre of Finland - initial API and implementation\r
  *******************************************************************************/\r
-package org.simantics.sysdyn.ui.simulation;\r
+package org.simantics.sysdyn.simulation;\r
 \r
 import org.eclipse.core.runtime.IProgressMonitor;\r
 import org.eclipse.core.runtime.IStatus;\r
@@ -22,7 +22,6 @@ import org.eclipse.ui.console.MessageConsole;
 import org.eclipse.ui.console.MessageConsoleStream;\r
 import org.simantics.modelica.IModelicaMonitor;\r
 import org.simantics.sysdyn.manager.SysdynModel;\r
-import org.simantics.sysdyn.ui.actions.ToggleSimulation;\r
 \r
 public class SimulationJob extends Job {\r
 \r
@@ -40,8 +39,7 @@ public class SimulationJob extends Job {
         this.monitor.clearConsole();\r
         try {\r
             model.update();\r
-            if(ToggleSimulation.getState())\r
-                model.simulate(this.monitor);\r
+            model.simulate(this.monitor);\r
         } catch (Exception e) {\r
             e.printStackTrace();\r
             return new Status(\r
similarity index 86%
rename from org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/simulation/SimulationScheduler.java
rename to org.simantics.sysdyn/src/org/simantics/sysdyn/simulation/SimulationScheduler.java
index b90d68e561f24042dc930d46a69dfeaefe49493f..cd048be4a506e3cedae267c5055fbc80f9acb624 100644 (file)
@@ -9,7 +9,7 @@
  * Contributors:\r
  *     VTT Technical Research Centre of Finland - initial API and implementation\r
  *******************************************************************************/\r
-package org.simantics.sysdyn.ui.simulation;\r
+package org.simantics.sysdyn.simulation;\r
 \r
 import org.simantics.sysdyn.manager.SysdynModel;\r
 \r
@@ -25,6 +25,8 @@ public class SimulationScheduler {
     \r
     private void start() {\r
         job.schedule();\r
+        /*\r
+         * Don't want this behavior. Use this in simulate on change or somewhere\r
         model.addModificationListener(new Runnable() {\r
 \r
             @Override\r
@@ -33,6 +35,7 @@ public class SimulationScheduler {
             }\r
             \r
         });\r
+        */\r
     }\r
 \r
     public static synchronized SimulationScheduler start(SysdynModel model) {\r
@@ -41,6 +44,8 @@ public class SimulationScheduler {
             scheduler = new SimulationScheduler(model);\r
             model.addService(SimulationScheduler.class, scheduler);\r
             scheduler.start();\r
+        } else {\r
+            scheduler.start();\r
         }\r
         return scheduler;\r
     }\r
index 1256c67ed5ca5282031afbaca4d62b2aa3f4b99b..69216fb49828d7b79c16caa9805c3d9379a24119 100644 (file)
@@ -32,6 +32,8 @@ Sysdyn @ "Sysdyn-1.0" : L0.Ontology
         Symbols : L0.Library\r
 \r
 SysdynProject : PROJ.Feature\r
+    PROJ.LifecycleFeature\r
+      SysdynProject\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
@@ -42,6 +44,13 @@ SysdynProject : PROJ.Feature
         PROJ.RequiresNamespace\r
           "http://www.simantics.org/Sysdyn-1.0" : L0.URI\r
       SysdynSymbols\r
+      PROJ.ExperimentControl\r
+      SysdynModelManager : PROJ.Feature\r
+        L0.PartOf Sysdyn\r
+        L0.HasLabel "Sysdyn Model Manager" : L0.String\r
+        L0.HasDescription "Sysdyn Model Manager." : L0.String\r
+        PROJ.RequiresFeature MOD.ModelingProject\r
+        PROJ.RequiresFeature PROJ.ExperimentControl\r
 \r
 SysdynSymbols : PROJ.Feature\r
     L0.PartOf Sysdyn\r
@@ -232,6 +241,18 @@ WithLookupExpression <T Expression
     [HasMaxY card "1"]\r
     \r
       \r
+######################################################################\r
+# Experiments\r
+######################################################################\r
+      \r
+Experiment <T L0.Entity\r
+\r
+BasicExperiment <T Experiment\r
+\r
+GameExperiment <T Experiment\r
+\r
+SimulateOnChangeExperiment <T Experiment\r
+\r
 ######################################################################\r
 # Symbols\r
 ######################################################################\r