]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
refs #4856
authorvillberg <villberg@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Mon, 19 May 2014 06:29:16 +0000 (06:29 +0000)
committervillberg <villberg@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Mon, 19 May 2014 06:29:16 +0000 (06:29 +0000)
git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@29507 ac1ea38d-2e2b-0410-8846-a27921b304fc

42 files changed:
org.simantics.sysdyn.ui/META-INF/MANIFEST.MF
org.simantics.sysdyn.ui/icons/box.png [new file with mode: 0644]
org.simantics.sysdyn.ui/plugin.xml
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/AbstractNodeImager.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/AnnotationContribution.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/AnnotationContribution2.java [moved from org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/SharedOntology.java with 53% similarity]
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/LibraryContribution.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/Project.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/SharedOntologyImager.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/SharedOntologyLabeler.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/SharedOntologyNode.java [deleted file]
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/SCLModule.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/SharedOntologyNode.java [new file with mode: 0644]
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/ExportSharedOntologyHandler.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/NewAnnotationTypeHandler.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/NewAnnotationValueHandler.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/NewLibraryHandler.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/SaveHistoryDialog.java [new file with mode: 0644]
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/SaveHistoryHandler.java [new file with mode: 0644]
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/game/ReloadGameExperimentHandler.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/game/StepHandler.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewGameExperimentNodeHandler.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/listeners/SysdynExperimentManagerListener.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/menu/GameStepDurationContribution.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/ParameterExpression.java
org.simantics.sysdyn/src/org/simantics/sysdyn/adapter/TimeIndexVariable.java
org.simantics.sysdyn/src/org/simantics/sysdyn/adapter/ValueIndexVariableBase.java
org.simantics.sysdyn/src/org/simantics/sysdyn/adapter/ValuesIndexVariable.java
org.simantics.sysdyn/src/org/simantics/sysdyn/manager/GameResult.java [new file with mode: 0644]
org.simantics.sysdyn/src/org/simantics/sysdyn/manager/MemoryResult.java
org.simantics.sysdyn/src/org/simantics/sysdyn/manager/OldSysdynExperiment.java
org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SimulateDurationJob.java [new file with mode: 0644]
org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynGameExperiment.java
org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynGameExperimentBase.java [new file with mode: 0644]
org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynGameExperimentInternal.java [new file with mode: 0644]
org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynModel.java
org.simantics.sysdyn/src/org/simantics/sysdyn/representation/utils/RepresentationUtils.java
org.simantics.sysdyn/src/org/simantics/sysdyn/simulation/SimulationJob.java
org.simantics.sysdyn/src/org/simantics/sysdyn/solver/ISolver.java
org.simantics.sysdyn/src/org/simantics/sysdyn/solver/InternalSolver.java
org.simantics.sysdyn/src/org/simantics/sysdyn/solver/ModelicaSolver.java [new file with mode: 0644]
org.simantics.sysdyn/src/org/simantics/sysdyn/solver/SysdynSimulationJob.java

index 31b9e04a7272d40ce50ebd8891137e91fb5bf2ec..790eeb2db7de587632a2ccb2f0a7f048096208b7 100644 (file)
@@ -59,7 +59,8 @@ Require-Bundle: org.simantics.layer0.utils;bundle-version="0.6.2",
  org.simantics.db.indexing;bundle-version="1.1.0",
  org.simantics.workbench,
  org.simantics.annotation.ui;bundle-version="1.0.0",
- org.simantics.annotation.ontology;bundle-version="1.0.0"
+ org.simantics.annotation.ontology;bundle-version="1.0.0",
+ org.simantics.spreadsheet.common;bundle-version="1.1.0"
 Bundle-Activator: org.simantics.sysdyn.ui.Activator
 Bundle-ActivationPolicy: lazy
 Export-Package: org.simantics.sysdyn.ui.browser.nodes
diff --git a/org.simantics.sysdyn.ui/icons/box.png b/org.simantics.sysdyn.ui/icons/box.png
new file mode 100644 (file)
index 0000000..8443c23
Binary files /dev/null and b/org.simantics.sysdyn.ui/icons/box.png differ
index 1c55f8fb80e2db98a07dab9892476000dcd74798..b16564db14da697dfbd49bc802ce6c20cbfcf550 100644 (file)
                            ifEmpty="false"\r
                            operator="or">\r
                         <equals\r
-                              value="org.simantics.sysdyn.ui.basicExperiment">\r
+                              value="org.simantics.sysdyn.ui.gameExperiment">\r
+                        </equals>\r
+                     </iterate>\r
+                  </with>\r
+               </visibleWhen>\r
+            </command>\r
+            <command\r
+                  commandId="org.simantics.sysdyn.ui.saveHistory"\r
+                  icon="platform:/plugin/com.famfamfam.silk/icons/table_save.png"\r
+                  id="org.simantics.sysdyn.ui.savehistory.button"\r
+                  label="Save History">\r
+               <visibleWhen>\r
+                  <with\r
+                        variable="activeContexts">\r
+                     <iterate\r
+                           ifEmpty="false"\r
+                           operator="or">\r
+                        <equals\r
+                              value="org.simantics.sysdyn.ui.gameExperiment">\r
                         </equals>\r
                      </iterate>\r
                   </with>\r
                      checkEnabled="true">\r
                   <with\r
                         variable="selection">\r
+                     <or>\r
                         <test\r
                               args="http://www.simantics.org/Layer0-0.0/Library"\r
                               property="org.simantics.graph.resourceType"\r
                               value="true">\r
                         </test>\r
+                     <test\r
+                           args="org.simantics.sysdyn.ui.browser.nodes.ModelNode"\r
+                           property="org.simantics.sysdyn.ui.nodeClass">\r
+                     </test>\r
+                     </or>\r
                   </with>\r
                </visibleWhen>\r
             </command>\r
             <command\r
                   commandId="org.simantics.sysdyn.ui.newModuleNode"\r
+                  icon="platform:/plugin/com.famfamfam.silk/icons/bricks.png"\r
                   id="org.simantics.sysdyn.ui.browser.newModule"\r
                   label="Module type"\r
                   style="push">\r
                label="Export">\r
             <command\r
                   commandId="org.simantics.sysdyn.ui.exportSharedOntology"\r
-                  icon="platform:/plugin/com.famfamfam.silk/icons/application_form.png"\r
+                  icon="platform:/plugin/com.famfamfam.silk/icons/folder.png"\r
                   id="org.simantics.sysdyn.ui.exportSharedOntology"\r
                   label="Shared Library"\r
                   style="push">\r
                         variable="selection">\r
                      <or>\r
                         <test\r
-                              args="org.simantics.sysdyn.ui.browser.contributions.SharedOntologyNode"\r
+                              args="org.simantics.sysdyn.ui.browser.nodes.SharedOntologyNode"\r
                               property="org.simantics.sysdyn.ui.nodeClass">\r
                         </test>\r
                      </or>\r
             id="org.simantics.sysdyn.ui.saveIC"\r
             name="Save Initial Condition">\r
       </command>\r
+      <command\r
+            defaultHandler="org.simantics.sysdyn.ui.handlers.SaveHistoryHandler"\r
+            id="org.simantics.sysdyn.ui.saveHistory"\r
+            name="Save History">\r
+      </command>\r
       <command\r
             defaultHandler="org.simantics.sysdyn.ui.handlers.ToggleResultActivation"\r
             id="org.simantics.sysdyn.ui.activateResult"\r
             <with\r
                   variable="selection">\r
                <or>\r
-                 <test\r
-                       args="http://www.simantics.org/Layer0-0.0/Library"\r
-                       property="org.simantics.graph.resourceType"\r
-                       value="true">\r
-                 </test>\r
+                        <test\r
+                              args="http://www.simantics.org/Layer0-0.0/Library"\r
+                              property="org.simantics.graph.resourceType"\r
+                              value="true">\r
+                        </test>\r
+                     <test\r
+                           args="org.simantics.sysdyn.ui.browser.nodes.ModelNode"\r
+                           property="org.simantics.sysdyn.ui.nodeClass">\r
+                     </test>\r
                </or>\r
             </with>\r
          </activeWhen>\r
                   variable="selection">\r
                <or>\r
                   <test\r
-                        args="org.simantics.sysdyn.ui.browser.contributions.SharedOntologyNode"\r
+                        args="org.simantics.sysdyn.ui.browser.nodes.SharedOntologyNode"\r
                         property="org.simantics.sysdyn.ui.nodeClass">\r
                   </test>\r
                </or>\r
                preference="2.0">\r
          </implementation>\r
          <implementation\r
-               class="org.simantics.sysdyn.ui.browser.contributions.LibraryContribution"\r
+               class="org.simantics.sysdyn.ui.browser.contributions.AnnotationContribution2"\r
                preference="2.0">\r
          </implementation>\r
          <implementation\r
-               class="org.simantics.sysdyn.ui.browser.contributions.SharedOntology"\r
+               class="org.simantics.sysdyn.ui.browser.contributions.LibraryContribution"\r
                preference="2.0">\r
          </implementation>\r
          <implementation\r
index 244ef889292b52b65f7934b1b22c62874bfd8bc2..2106ce5ea9956315dd097a0dd97835247a162858 100644 (file)
@@ -77,7 +77,7 @@ public class AbstractNodeImager extends ImagerContributor<AbstractNode<Resource>
         else if (node instanceof ModuleTypeNode || node instanceof ModuleNode || node instanceof ConfigurationNode)\r
             image = "icons/bricks.png";\r
         else if (node instanceof SCLModule)\r
-            image = "icons/bullet_gray.png";\r
+            image = "icons/box.png";\r
         else if (node instanceof InitialCondition)\r
             image = "icons/table.png";\r
         else if (node instanceof ExperimentNode) {\r
index 3ec613f81cd08d5fcfe6b2f66f778320bb648e18..19d9ce12f8a0e2c88fd00df744cca380e30b0dc7 100644 (file)
@@ -33,9 +33,10 @@ public class AnnotationContribution  extends ViewpointContributor<AbstractNode<R
        \r
         ArrayList<AbstractNode<Resource>> result = new ArrayList<AbstractNode<Resource>>();\r
         \r
+        Layer0 L0 = Layer0.getInstance(graph);\r
+        \r
         if(node instanceof ISpecialFolder) return result;\r
         \r
-        Layer0 L0 = Layer0.getInstance(graph);\r
        AnnotationResource ANNO = AnnotationResource.getInstance(graph);\r
         if(graph.isInstanceOf(node.data, L0.Library)) {\r
                for(Resource anno : graph.syncRequest(new ObjectsWithType(node.data, L0.ConsistsOf, ANNO.AnnotationType))) {\r
similarity index 53%
rename from org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/SharedOntology.java
rename to org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/AnnotationContribution2.java
index 9645b36112cbcdc5f57f6d6a5dfbe02bd05e1865..a29c1dab3c60df9f0cc22b7afba953e0651fda31 100644 (file)
@@ -14,21 +14,38 @@ package org.simantics.sysdyn.ui.browser.contributions;
 import java.util.ArrayList;\r
 import java.util.Collection;\r
 \r
+import org.simantics.annotation.ontology.AnnotationResource;\r
 import org.simantics.browsing.ui.common.node.AbstractNode;\r
 import org.simantics.browsing.ui.graph.contributor.viewpoint.ViewpointContributor;\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.SCLModulesFolder;\r
+import org.simantics.layer0.Layer0;\r
+import org.simantics.sysdyn.ui.browser.nodes.AnnotationType;\r
+import org.simantics.sysdyn.ui.browser.nodes.AnnotationValue;\r
 \r
-public class SharedOntology  extends ViewpointContributor<SharedOntologyNode> {\r
+public class AnnotationContribution2  extends ViewpointContributor<Resource> {\r
 \r
     @Override\r
-    public Collection<?> getContribution(ReadGraph graph, SharedOntologyNode model)\r
-    throws DatabaseException {\r
+    public Collection<?> getContribution(ReadGraph graph, Resource res) throws DatabaseException {\r
+       \r
         ArrayList<AbstractNode<Resource>> result = new ArrayList<AbstractNode<Resource>>();\r
-        result.add(new SCLModulesFolder(model.data));\r
+        \r
+        Layer0 L0 = Layer0.getInstance(graph);\r
+        \r
+       AnnotationResource ANNO = AnnotationResource.getInstance(graph);\r
+        if(graph.isInstanceOf(res, L0.Library)) {\r
+               for(Resource anno : graph.syncRequest(new ObjectsWithType(res, L0.ConsistsOf, ANNO.AnnotationType))) {\r
+                result.add(new AnnotationType(anno));\r
+               }\r
+        }\r
+       for(Resource anno : graph.syncRequest(new ObjectsWithType(res, L0.ConsistsOf, ANNO.Annotation))) {\r
+            result.add(new AnnotationValue(anno));\r
+       }\r
+        \r
         return result;\r
+        \r
     }\r
 \r
     @Override\r
index e35d00f0627c8bec2d08773f03a9dac54c37fbe1..879cb666933ed76323db427abf0c77eabc57eb06 100644 (file)
@@ -34,7 +34,7 @@ public class LibraryContribution  extends ViewpointContributor<AbstractNode<Reso
         if(node instanceof ISpecialFolder) return result;\r
         \r
         Layer0 L0 = Layer0.getInstance(graph);\r
-        if(graph.isInstanceOf(node.data, L0.Library)) {\r
+        if(!graph.isInstanceOf(node.data, L0.SharedOntology)) {\r
                for(Resource lib : graph.syncRequest(new ObjectsWithType(node.data, L0.ConsistsOf, L0.Library))) {\r
                 result.add(new Library(lib));\r
                }\r
index ee58e8e8a704dbc5f0697ef0e082dc2c15a9a765..73725ccb3ca2949de236e4f28e484687e72c2152 100644 (file)
@@ -25,6 +25,7 @@ import org.simantics.db.exception.DatabaseException;
 import org.simantics.layer0.Layer0;\r
 import org.simantics.project.ontology.ProjectResource;\r
 import org.simantics.sysdyn.SysdynResource;\r
+import org.simantics.sysdyn.ui.browser.nodes.SharedOntologyNode;\r
 \r
 public class Project extends ViewpointContributor<Resource> {\r
 \r
index 44155c2c34c86f5a4678fa3a1458d3ec4f12b138..5c51a8f6f8da272e6ba7d01bd1a76be06bd488ae 100644 (file)
@@ -7,6 +7,7 @@ import org.eclipse.jface.resource.ImageDescriptor;
 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.browser.nodes.SharedOntologyNode;\r
 \r
 public class SharedOntologyImager extends ImagerContributor<SharedOntologyNode> {\r
 \r
index 1868c6fa466af323c18a9820c1cb39e2de8ffc0b..9ebfc57987ea9214ada506195ad8fa4fe9e09146 100644 (file)
@@ -2,13 +2,15 @@ package org.simantics.sysdyn.ui.browser.contributions;
 \r
 import org.simantics.browsing.ui.graph.contributor.labeler.LabelerContributor;\r
 import org.simantics.db.ReadGraph;\r
+import org.simantics.db.common.utils.Versions;\r
 import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.sysdyn.ui.browser.nodes.SharedOntologyNode;\r
 \r
 public class SharedOntologyLabeler extends LabelerContributor<SharedOntologyNode> {\r
 \r
     @Override\r
     public String getLabel(ReadGraph graph, SharedOntologyNode node) throws DatabaseException {\r
-       return graph.getURI(node.data);\r
+       return Versions.getStandardNameString(graph, node.data);\r
     }\r
     \r
     @Override\r
diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/SharedOntologyNode.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/SharedOntologyNode.java
deleted file mode 100644 (file)
index 2013ec2..0000000
+++ /dev/null
@@ -1,25 +0,0 @@
-package org.simantics.sysdyn.ui.browser.contributions;\r
-\r
-import org.simantics.browsing.ui.common.node.AbstractNode;\r
-import org.simantics.browsing.ui.common.node.DeleteException;\r
-import org.simantics.browsing.ui.common.node.IDeletableNode;\r
-import org.simantics.browsing.ui.common.node.IModifiableNode;\r
-import org.simantics.browsing.ui.content.Labeler.Modifier;\r
-import org.simantics.db.Resource;\r
-\r
-public class SharedOntologyNode extends AbstractNode<Resource> implements IDeletableNode, IModifiableNode {\r
-\r
-    public SharedOntologyNode(Resource data) {\r
-        super(data);\r
-    }\r
-    \r
-    @Override\r
-    public void delete() throws DeleteException {\r
-    }\r
-\r
-       @Override\r
-       public Modifier getModifier(String columnId) {\r
-               return null;\r
-       }\r
-\r
-}\r
index c695ca63c248b630796104300e30c0e81a16aff6..70815ee471a1201b004dd4e31c91f74462f6079b 100644 (file)
@@ -46,7 +46,6 @@ public class SCLModule extends AbstractNode<Resource> implements IDeletableNode,
         } catch (DatabaseException e) {\r
             ExceptionUtils.logAndShowError(e);\r
         }    \r
-\r
     }\r
 \r
     @Override\r
diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/SharedOntologyNode.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/SharedOntologyNode.java
new file mode 100644 (file)
index 0000000..6e6d595
--- /dev/null
@@ -0,0 +1,42 @@
+package org.simantics.sysdyn.ui.browser.nodes;\r
+\r
+import org.simantics.browsing.ui.common.node.AbstractNode;\r
+import org.simantics.browsing.ui.common.node.DeleteException;\r
+import org.simantics.browsing.ui.common.node.IDeletableNode;\r
+import org.simantics.browsing.ui.common.node.IModifiableNode;\r
+import org.simantics.browsing.ui.content.Labeler.Modifier;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.WriteGraph;\r
+import org.simantics.db.common.request.WriteRequest;\r
+import org.simantics.db.exception.CancelTransactionException;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.db.layer0.util.RemoverUtil;\r
+import org.simantics.ui.SimanticsUI;\r
+import org.simantics.utils.ui.ExceptionUtils;\r
+\r
+public class SharedOntologyNode extends AbstractNode<Resource> implements IDeletableNode, IModifiableNode {\r
+\r
+    public SharedOntologyNode(Resource data) {\r
+        super(data);\r
+    }\r
+    \r
+    @Override\r
+    public void delete() throws DeleteException {\r
+        try {\r
+            SimanticsUI.getSession().syncRequest(new WriteRequest() {\r
+                @Override\r
+                public void perform(WriteGraph graph) throws DatabaseException, CancelTransactionException {\r
+                    RemoverUtil.remove(graph, data);\r
+                }\r
+            });\r
+        } catch (DatabaseException e) {\r
+            ExceptionUtils.logAndShowError(e);\r
+        }    \r
+    }\r
+\r
+       @Override\r
+       public Modifier getModifier(String columnId) {\r
+               return null;\r
+       }\r
+\r
+}\r
index b322db1e26c461cc80b442512fccbf4a8c01f54e..9d2f67034a150b66424769d85b2c2008a79908fd 100644 (file)
@@ -6,7 +6,7 @@ import org.eclipse.core.commands.ExecutionException;
 import org.eclipse.jface.viewers.ISelection;\r
 import org.eclipse.ui.handlers.HandlerUtil;\r
 import org.simantics.modeling.ModelingUtils;\r
-import org.simantics.sysdyn.ui.browser.contributions.SharedOntologyNode;\r
+import org.simantics.sysdyn.ui.browser.nodes.SharedOntologyNode;\r
 import org.simantics.utils.ui.AdaptionUtils;\r
 \r
 public class ExportSharedOntologyHandler  extends AbstractHandler {\r
index 133962ee2d5f56823a549263bda9c42b3c9ace53..ee052f8b9d68333ebb5727d48331704d14a5e2b5 100644 (file)
@@ -25,11 +25,15 @@ public class NewAnnotationTypeHandler  extends AbstractHandler {
         ISelection sel = HandlerUtil.getCurrentSelection(event);\r
         \r
         @SuppressWarnings("unchecked")\r
-               AbstractNode<Resource> node = AdaptionUtils.adaptToSingle(sel, AbstractNode.class);\r
-        if (node == null)\r
-            return null;\r
+               Resource res = AdaptionUtils.adaptToSingle(sel, Resource.class);\r
+        if(res == null) {\r
+               AbstractNode<Resource> node = AdaptionUtils.adaptToSingle(sel, AbstractNode.class);\r
+               if (node == null)\r
+                       return null;\r
+               res = node.data;\r
+        }\r
 \r
-        final Resource parent = node.data;\r
+        final Resource parent = res;\r
         \r
         SimanticsUI.getSession().asyncRequest(new WriteRequest() {\r
                \r
index 2f679c1ca4fbd8b5aaf6d6dd29ee7415943a20b6..29ad88db5c82df8c958e85ed0d10be6d29d88bc6 100644 (file)
@@ -21,11 +21,15 @@ public class NewAnnotationValueHandler  extends AbstractHandler {
         ISelection sel = HandlerUtil.getCurrentSelection(event);\r
         \r
         @SuppressWarnings("unchecked")\r
-               AbstractNode<Resource> node = AdaptionUtils.adaptToSingle(sel, AbstractNode.class);\r
-        if (node == null)\r
-            return null;\r
+               Resource res = AdaptionUtils.adaptToSingle(sel, Resource.class);\r
+        if(res == null) {\r
+               AbstractNode<Resource> node = AdaptionUtils.adaptToSingle(sel, AbstractNode.class);\r
+               if (node == null)\r
+                       return null;\r
+               res = node.data;\r
+        }\r
 \r
-        final Resource parent = node.data;\r
+        final Resource parent = res;\r
                try {\r
                        Resource model = Simantics.getSession().syncRequest(new PossibleIndexRoot(parent));\r
                        if(model == null) return null;\r
index ae1b293307c3afcf168d4ab1b7bd6137bb168f44..009d225cf91950be5549ec42556d7ff012247ca0 100644 (file)
@@ -22,11 +22,15 @@ public class NewLibraryHandler  extends AbstractHandler {
         ISelection sel = HandlerUtil.getCurrentSelection(event);\r
         \r
         @SuppressWarnings("unchecked")\r
-               AbstractNode<Resource> node = AdaptionUtils.adaptToSingle(sel, AbstractNode.class);\r
-        if (node == null)\r
-            return null;\r
+               Resource res = AdaptionUtils.adaptToSingle(sel, Resource.class);\r
+        if(res == null) {\r
+               AbstractNode<Resource> node = AdaptionUtils.adaptToSingle(sel, AbstractNode.class);\r
+               if (node == null)\r
+                       return null;\r
+               res = node.data;\r
+        }\r
 \r
-        final Resource parent = node.data;\r
+        final Resource parent = res;\r
         \r
         SimanticsUI.getSession().asyncRequest(new WriteRequest() {\r
                \r
diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/SaveHistoryDialog.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/SaveHistoryDialog.java
new file mode 100644 (file)
index 0000000..08882f8
--- /dev/null
@@ -0,0 +1,149 @@
+/*******************************************************************************\r
+ * Copyright (c) 2013 Association for Decentralized Information Management in\r
+ * 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
+ *     Semantum Oy - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.sysdyn.ui.handlers;\r
+\r
+import java.util.Map;\r
+\r
+import org.eclipse.core.runtime.Status;\r
+import org.eclipse.jface.dialogs.IDialogSettings;\r
+import org.eclipse.jface.layout.GridDataFactory;\r
+import org.eclipse.jface.layout.GridLayoutFactory;\r
+import org.eclipse.jface.resource.ImageDescriptor;\r
+import org.eclipse.jface.viewers.StructuredSelection;\r
+import org.eclipse.swt.SWT;\r
+import org.eclipse.swt.events.ModifyEvent;\r
+import org.eclipse.swt.events.ModifyListener;\r
+import org.eclipse.swt.widgets.Composite;\r
+import org.eclipse.swt.widgets.Control;\r
+import org.eclipse.swt.widgets.Label;\r
+import org.eclipse.swt.widgets.Shell;\r
+import org.eclipse.swt.widgets.Text;\r
+import org.eclipse.ui.PlatformUI;\r
+import org.simantics.annotation.ui.Activator;\r
+import org.simantics.modelica.data.DataSet;\r
+import org.simantics.spreadsheet.util.SpreadsheetUtils;\r
+import org.simantics.ui.workbench.dialogs.ResourceSelectionDialog3;\r
+import org.simantics.utils.datastructures.Pair;\r
+\r
+public class SaveHistoryDialog extends ResourceSelectionDialog3<DataSet> {\r
+\r
+       private String sheetName;\r
+       private String sheetLocation;\r
+\r
+       public SaveHistoryDialog(Shell shell,\r
+                       Map<DataSet, Pair<String, ImageDescriptor>> parameter, String title) {\r
+               super(shell, parameter, title);\r
+               this.sheetName = "";\r
+               this.sheetLocation = "";\r
+       }\r
+\r
+       @Override\r
+       protected IDialogSettings getBaseDialogSettings() {\r
+               return Activator.getDefault().getDialogSettings();\r
+       }\r
+       \r
+       @Override\r
+       protected void setSelectionResult(Object[] newResult) {\r
+               super.setSelectionResult(newResult);\r
+               validatePage();\r
+       }\r
+\r
+       @Override\r
+       protected Control createExtendedContentArea(Composite parent_) {\r
+\r
+               Composite parent = new Composite(parent_, SWT.NONE);\r
+               GridLayoutFactory.swtDefaults().numColumns(2).applyTo(parent);\r
+               GridDataFactory.fillDefaults().grab(true, false).applyTo(parent);\r
+\r
+               Label l = new Label(parent, SWT.NONE); \r
+               l.setText("Select a sheet:");\r
+               GridDataFactory.fillDefaults().grab(false, false).applyTo(l);\r
+               final Text t = new Text(parent,SWT.BORDER);\r
+               t.addModifyListener(new ModifyListener() {\r
+                       @Override\r
+                       public void modifyText(ModifyEvent e) {\r
+                               sheetName = t.getText();\r
+                               validatePage();\r
+                       }\r
+               });\r
+               GridDataFactory.fillDefaults().grab(true, false).applyTo(t);\r
+               Label l2 = new Label(parent, SWT.NONE); \r
+               l2.setText("Select cell in sheet:");\r
+               GridDataFactory.fillDefaults().grab(false, false).applyTo(l2);\r
+               final Text t2 = new Text(parent,SWT.BORDER);\r
+               t2.addModifyListener(new ModifyListener() {\r
+                       @Override\r
+                       public void modifyText(ModifyEvent e) {\r
+                               sheetLocation = t2.getText();\r
+                               validatePage();\r
+                       }\r
+               });\r
+               GridDataFactory.fillDefaults().grab(true, false).applyTo(t2);\r
+               validatePage();\r
+               return super.createExtendedContentArea(parent);\r
+       }\r
+\r
+       @Override\r
+       protected void handleSelected(StructuredSelection selection) {\r
+               super.handleSelected(selection);\r
+               validatePage(); \r
+       }\r
+\r
+       protected void validatePage() {\r
+               \r
+               if(getSelectedItems().size() == 0) {\r
+                       updateStatus(new Status(Status.ERROR, PlatformUI.PLUGIN_ID, "Please select some variable(s)"));\r
+                       return;\r
+               }\r
+               \r
+               String error = validateSheet(sheetName);\r
+               if (error != null) {\r
+                       updateStatus(new Status(Status.ERROR, PlatformUI.PLUGIN_ID, error));\r
+                       return;\r
+               }\r
+\r
+               error = validateLocation(sheetLocation);\r
+               if (error != null) {\r
+                       updateStatus(new Status(Status.ERROR, PlatformUI.PLUGIN_ID, error));\r
+                       return;\r
+               }\r
+               \r
+               updateStatus(new Status(Status.OK, Activator.PLUGIN_ID, ""));\r
+               \r
+       }\r
+\r
+       protected String validateSheet(String name) {\r
+               if (name.trim().isEmpty())\r
+                       return "Sheet name cannot be empty";\r
+               return null;\r
+       }\r
+\r
+       protected String validateLocation(String location) {\r
+               try {\r
+                       if(location.isEmpty())\r
+                               return "Empty location";\r
+                       SpreadsheetUtils.decodeCellAbsolute(location);\r
+                       return null;\r
+               } catch (Exception e) {\r
+                       return e.getMessage();\r
+               }\r
+       }\r
+\r
+       public String getSheetName() {\r
+               return sheetName;\r
+       }\r
+\r
+       public String getSheetLocation() {\r
+               return sheetLocation;\r
+       }\r
+       \r
+}
\ No newline at end of file
diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/SaveHistoryHandler.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/SaveHistoryHandler.java
new file mode 100644 (file)
index 0000000..054beef
--- /dev/null
@@ -0,0 +1,142 @@
+/*******************************************************************************\r
+ * Copyright (c) 2010 Association for Decentralized Information Management in\r
+ * 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
+package org.simantics.sysdyn.ui.handlers;\r
+\r
+import java.util.HashMap;\r
+import java.util.List;\r
+import java.util.Map;\r
+\r
+import org.eclipse.core.commands.AbstractHandler;\r
+import org.eclipse.core.commands.ExecutionEvent;\r
+import org.eclipse.core.commands.ExecutionException;\r
+import org.eclipse.jface.resource.ImageDescriptor;\r
+import org.eclipse.jface.window.Window;\r
+import org.eclipse.swt.widgets.Shell;\r
+import org.eclipse.ui.PlatformUI;\r
+import org.simantics.Simantics;\r
+import org.simantics.databoard.Bindings;\r
+import org.simantics.databoard.binding.mutable.Variant;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.WriteGraph;\r
+import org.simantics.db.common.request.WriteRequest;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.db.layer0.request.PossibleModel;\r
+import org.simantics.db.layer0.variable.Variable;\r
+import org.simantics.db.layer0.variable.Variables;\r
+import org.simantics.layer0.Layer0;\r
+import org.simantics.modelica.data.DataSet;\r
+import org.simantics.modelica.data.SimulationResult;\r
+import org.simantics.modeling.ModelingUtils;\r
+import org.simantics.simulation.experiment.IExperiment;\r
+import org.simantics.simulation.project.IExperimentManager;\r
+import org.simantics.spreadsheet.Range;\r
+import org.simantics.spreadsheet.resource.SpreadsheetResource;\r
+import org.simantics.spreadsheet.util.SpreadsheetUtils;\r
+import org.simantics.sysdyn.manager.MemoryResult;\r
+import org.simantics.sysdyn.manager.SysdynGameExperimentBase;\r
+import org.simantics.sysdyn.manager.SysdynResult;\r
+import org.simantics.sysdyn.ui.utils.HandlerUtils;\r
+import org.simantics.ui.SimanticsUI;\r
+import org.simantics.utils.datastructures.Pair;\r
+       \r
+public class SaveHistoryHandler extends AbstractHandler {\r
+\r
+    @Override\r
+    public Object execute(ExecutionEvent event) throws ExecutionException {\r
+        HandlerUtils.saveBeforeExperimentRun(event);\r
+        \r
+        IExperimentManager manager = \r
+            SimanticsUI.getProject().getHint(IExperimentManager.KEY_EXPERIMENT_MANAGER);\r
+        IExperiment experiment = manager.getActiveExperiment();\r
+        if(experiment instanceof SysdynGameExperimentBase) {\r
+            final SysdynGameExperimentBase exp = (SysdynGameExperimentBase)experiment;\r
+               try {\r
+                       \r
+                       Map<DataSet, Pair<String,ImageDescriptor>> map = new HashMap<DataSet, Pair<String,ImageDescriptor>>();\r
+\r
+                       SysdynResult r = exp.getCurrentResult(); \r
+                       if(r instanceof MemoryResult) {\r
+                               MemoryResult gr = (MemoryResult)r;\r
+                               SimulationResult sr = gr.getSimulationResult();\r
+                               for(DataSet ds : sr.getVariableDataSets()) {\r
+                                       map.put(ds, new Pair<String,ImageDescriptor>(ds.name, null));\r
+                               }\r
+                       }\r
+                       \r
+                Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();\r
+                SaveHistoryDialog dialog = new SaveHistoryDialog(shell, map, "Select variables");\r
+                if (dialog.open() == Window.OK) {\r
+                    final Object[] result = dialog.getResult();\r
+                    final String sheetName = dialog.getSheetName();\r
+                    final String sheetLocation = dialog.getSheetLocation();\r
+                    Simantics.getSession().syncRequest(new WriteRequest() {\r
+\r
+                       public void writeCell(WriteGraph graph, Variable sheet, String cellName, String value) throws DatabaseException {\r
+                               SpreadsheetResource SHEET = SpreadsheetResource.getInstance(graph);\r
+                               Variable child = sheet.getPossibleChild(graph, cellName);\r
+                               if(child != null) {\r
+                                       child.setPropertyValue(graph, SHEET.Cell_content, Variant.ofInstance(value), Bindings.VARIANT);\r
+                               } else {\r
+                                       Layer0 L0 = Layer0.getInstance(graph);\r
+                                       Resource container = sheet.getRepresents(graph);\r
+                                       Resource cell = graph.newResource();\r
+                                       graph.claim(cell, L0.InstanceOf, null, SHEET.TextCell);\r
+                                       graph.addLiteral(cell, L0.HasName, L0.NameOf, L0.String, cellName, Bindings.STRING);\r
+                                       graph.addLiteral(cell, SHEET.Cell_content, SHEET.Cell_content_Inverse, L0.Variant, Variant.ofInstance(value), Bindings.VARIANT);\r
+                                       graph.claim(cell, L0.PartOf, container);\r
+                               }\r
+                       }\r
+                       \r
+                       @Override\r
+                       public void perform(WriteGraph graph) throws DatabaseException {\r
+                               \r
+                               SpreadsheetResource SHEET = SpreadsheetResource.getInstance(graph);\r
+                               Resource modelResource = graph.syncRequest(new PossibleModel(exp.getResource()));\r
+                               if(modelResource == null) return;\r
+                               List<Resource> sheets = ModelingUtils.searchByTypeAndName(graph, modelResource, SHEET.Spreadsheet, sheetName);\r
+                               if(sheets.size() != 1) return;\r
+                               Variable sheet = Variables.getVariable(graph, sheets.get(0));\r
+                               \r
+                               Range base = SpreadsheetUtils.decodeCellAbsolute(sheetLocation);\r
+                               \r
+                               DataSet first = (DataSet)result[0];\r
+                               writeCell(graph, sheet, sheetLocation, "times");\r
+                               for(int i=0;i<first.times.length;i++) {\r
+                                       String loc = SpreadsheetUtils.cellName(base.startRow+1+i, base.startColumn);\r
+                                       writeCell(graph, sheet, loc, "" + first.times[i]);      \r
+                               }\r
+                               \r
+                               for(int j=0;j<result.length;j++) {\r
+\r
+                                       first = (DataSet)result[j];\r
+                                       writeCell(graph, sheet, SpreadsheetUtils.cellName(base.startRow, base.startColumn+1+j), first.name);\r
+                                       for(int i=0;i<first.values.length;i++) {\r
+                                               String loc = SpreadsheetUtils.cellName(base.startRow+1+i, base.startColumn+1+j);\r
+                                               writeCell(graph, sheet, loc, "" + first.values[i]);     \r
+                                       }\r
+\r
+                               }\r
+                               \r
+                       }\r
+\r
+                    });\r
+                }\r
+                       \r
+                \r
+                       } catch (Throwable e) {\r
+                               e.printStackTrace();\r
+                       }\r
+        }\r
+        return null;\r
+    }\r
+\r
+}\r
index de0c36abd29c7a527f8c54d4d3cf7c4e47f8dd48..72d6970ca335943aa74d1cf73b8c7d61bd92c994 100644 (file)
@@ -21,6 +21,7 @@ import org.simantics.simulation.experiment.ExperimentState;
 import org.simantics.simulation.experiment.IExperiment;\r
 import org.simantics.simulation.project.IExperimentManager;\r
 import org.simantics.sysdyn.manager.SysdynGameExperiment;\r
+import org.simantics.sysdyn.manager.SysdynGameExperimentBase;\r
 import org.simantics.sysdyn.ui.handlers.RunBasicExperiment;\r
 import org.simantics.ui.SimanticsUI;\r
 \r
@@ -40,7 +41,7 @@ public class ReloadGameExperimentHandler extends RunBasicExperiment {
     \r
     @Override\r
     public Object execute(ExecutionEvent event) throws ExecutionException {\r
-        SysdynGameExperiment game = getGameExperiment();\r
+       SysdynGameExperimentBase game = getGameExperiment();\r
         if(game != null)\r
             game.simulate(true);\r
         return null;\r
@@ -50,7 +51,7 @@ public class ReloadGameExperimentHandler extends RunBasicExperiment {
      * Find currently active game experiment\r
      * @return Currently active game experiment or null if game experiment not active\r
      */\r
-    private SysdynGameExperiment getGameExperiment() {\r
+    private SysdynGameExperimentBase getGameExperiment() {\r
         // Find active experiment\r
         IProject project = SimanticsUI.peekProject();\r
         if (project == null)\r
@@ -59,10 +60,10 @@ public class ReloadGameExperimentHandler extends RunBasicExperiment {
         IExperimentManager manager = project.getHint(IExperimentManager.KEY_EXPERIMENT_MANAGER);\r
 \r
         IExperiment active = manager.getActiveExperiment();\r
-        if (!(active instanceof SysdynGameExperiment))\r
+        if (!(active instanceof SysdynGameExperimentBase))\r
             return null;\r
         \r
-        return (SysdynGameExperiment) active;\r
+        return (SysdynGameExperimentBase) active;\r
     }\r
        \r
        @SuppressWarnings("rawtypes")\r
@@ -73,7 +74,7 @@ public class ReloadGameExperimentHandler extends RunBasicExperiment {
                \r
                \r
                // Change tooltip according to the current status\r
-        SysdynGameExperiment game = getGameExperiment();   \r
+               SysdynGameExperimentBase game = getGameExperiment();   \r
 \r
         if(game == null) {\r
                        started = false;\r
index 6164c97aecdfae096c520504aac8fea3cb872108..ecb69ef56f660ff29eb05fbe8d38938a404f9548 100644 (file)
@@ -22,7 +22,7 @@ import org.simantics.project.IProject;
 import org.simantics.simulation.experiment.ExperimentState;\r
 import org.simantics.simulation.experiment.IExperiment;\r
 import org.simantics.simulation.project.IExperimentManager;\r
-import org.simantics.sysdyn.manager.SysdynGameExperiment;\r
+import org.simantics.sysdyn.manager.SysdynGameExperimentBase;\r
 import org.simantics.sysdyn.ui.utils.HandlerUtils;\r
 import org.simantics.ui.SimanticsUI;\r
 \r
@@ -39,7 +39,7 @@ public class StepHandler extends AbstractHandler implements IElementUpdater {
        private boolean initialized = false;\r
        private boolean running = false;        \r
     \r
-    private SysdynGameExperiment getGameExperiment() {\r
+    private SysdynGameExperimentBase getGameExperiment() {\r
         // Find active experiment\r
         IProject project = SimanticsUI.peekProject();\r
         if (project == null)\r
@@ -48,17 +48,17 @@ public class StepHandler extends AbstractHandler implements IElementUpdater {
         IExperimentManager manager = project.getHint(IExperimentManager.KEY_EXPERIMENT_MANAGER);\r
 \r
         IExperiment active = manager.getActiveExperiment();\r
-        if (!(active instanceof SysdynGameExperiment))\r
+        if (!(active instanceof SysdynGameExperimentBase))\r
             return null;\r
         \r
-        return (SysdynGameExperiment) active;\r
+        return (SysdynGameExperimentBase) active;\r
     }\r
 \r
     @Override\r
     public Object execute(ExecutionEvent event) throws ExecutionException {\r
         HandlerUtils.saveBeforeExperimentRun(event);\r
         \r
-        SysdynGameExperiment game = getGameExperiment();\r
+        SysdynGameExperimentBase game = getGameExperiment();\r
         if(game != null)\r
                game.simulateDuration(game.getStepDuration());\r
        return null;\r
@@ -69,7 +69,7 @@ public class StepHandler extends AbstractHandler implements IElementUpdater {
        public void updateElement(UIElement element, Map parameters) {\r
                \r
                // Disable button when model has not been initialized and change tooltip accordingly\r
-        SysdynGameExperiment game = getGameExperiment();   \r
+               SysdynGameExperimentBase game = getGameExperiment();   \r
 \r
         if(game == null) {\r
                        started = false;\r
index 7d759c34380b201a45a6be7eed0d5ee236fa8d47..601de37a31498bc9a046a8113c793a0b057938c1 100644 (file)
@@ -16,7 +16,7 @@ import org.simantics.db.Resource;
 import org.simantics.db.WriteGraph;\r
 import org.simantics.db.exception.DatabaseException;\r
 import org.simantics.sysdyn.SysdynResource;\r
-import org.simantics.sysdyn.manager.SysdynGameExperiment;\r
+import org.simantics.sysdyn.manager.SysdynGameExperimentBase;\r
 \r
 /**\r
  * Handler for creating a new Game Experiment\r
@@ -34,8 +34,8 @@ public class NewGameExperimentNodeHandler extends NewExperimentNodeHandler  {
      */\r
     protected void configureExperiment(WriteGraph graph, Resource experiment) throws DatabaseException {\r
        SysdynResource sr = SysdynResource.getInstance(graph);\r
-        graph.claimLiteral(experiment, sr.GameExperiment_stepDuration, SysdynGameExperiment.DEFAULT_STEP_DURATION);\r
-        graph.claimLiteral(experiment, sr.GameExperiment_stepLength, SysdynGameExperiment.DEFAULT_STEP_LENGTH);\r
+        graph.claimLiteral(experiment, sr.GameExperiment_stepDuration, SysdynGameExperimentBase.DEFAULT_STEP_DURATION);\r
+        graph.claimLiteral(experiment, sr.GameExperiment_stepLength, SysdynGameExperimentBase.DEFAULT_STEP_LENGTH);\r
     }\r
 \r
     protected String getNameSuggestion() {\r
index d9c50e813e291796c9a38d658d492ac4126b705b..09da1d46358c3925dfa6abbc38578ca595e9df56 100644 (file)
@@ -24,7 +24,7 @@ import org.simantics.simulation.experiment.IExperiment;
 import org.simantics.simulation.project.IExperimentManager;\r
 import org.simantics.simulation.project.IExperimentManagerListener;\r
 import org.simantics.sysdyn.manager.SysdynExperiment;\r
-import org.simantics.sysdyn.manager.SysdynGameExperiment;\r
+import org.simantics.sysdyn.manager.SysdynGameExperimentBase;\r
 import org.simantics.sysdyn.manager.SysdynPlaybackExperiment;\r
 import org.simantics.sysdyn.manager.SysdynSensitivityAnalysisExperiment;\r
 \r
@@ -73,7 +73,7 @@ public class SysdynExperimentManagerListener implements IExperimentManagerListen
                     if(experiment instanceof SysdynPlaybackExperiment) {\r
                         contextActivations.add(contextService.activateContext(PLAYBACK_EXPERIMENT_CONTEXT));\r
                         experiment.addListener(new SysdynPlaybackExperimentListener((SysdynPlaybackExperiment)experiment));\r
-                    } else if(experiment instanceof SysdynGameExperiment) {\r
+                    } else if(experiment instanceof SysdynGameExperimentBase) {\r
                         contextActivations.add(contextService.activateContext(GAME_EXPERIMENT_CONTEXT));\r
                         // TODO: some listener?\r
                     } else if(experiment instanceof SysdynSensitivityAnalysisExperiment) {\r
index 4281055f17f59c4341a97a5b2595533857803b59..fb1e41c7ff6bcf78128f20def65eefe171175c28 100644 (file)
@@ -26,7 +26,7 @@ import org.simantics.project.IProject;
 import org.simantics.simulation.experiment.IExperiment;\r
 import org.simantics.simulation.project.IExperimentManager;\r
 import org.simantics.sysdyn.SysdynResource;\r
-import org.simantics.sysdyn.manager.SysdynGameExperiment;\r
+import org.simantics.sysdyn.manager.SysdynGameExperimentBase;\r
 import org.simantics.sysdyn.ui.properties.SysdynBasicColorProvider;\r
 import org.simantics.sysdyn.ui.properties.widgets.factories.DoublePropertyFactory;\r
 import org.simantics.sysdyn.ui.properties.widgets.factories.DoublePropertyModifier;\r
@@ -70,10 +70,10 @@ public class GameStepDurationContribution extends CompoundContributionItem {
         IExperimentManager manager = project.getHint(IExperimentManager.KEY_EXPERIMENT_MANAGER);\r
 \r
         IExperiment active = manager.getActiveExperiment();\r
-        if (!(active instanceof SysdynGameExperiment))\r
+        if (!(active instanceof SysdynGameExperimentBase))\r
             return;\r
 \r
-        final SysdynGameExperiment game = (SysdynGameExperiment) active;\r
+        final SysdynGameExperimentBase game = (SysdynGameExperimentBase) active;\r
         \r
         // Create the text\r
         \r
index 5b2a3e755b06bdee6d47cc43e5d3ab957b5ad4fb..772f083b2767c48ee8462467b2d08fca3781f547 100644 (file)
@@ -32,7 +32,7 @@ import org.simantics.simulation.experiment.ExperimentState;
 import org.simantics.simulation.experiment.IExperiment;\r
 import org.simantics.simulation.project.IExperimentManager;\r
 import org.simantics.sysdyn.SysdynResource;\r
-import org.simantics.sysdyn.manager.SysdynGameExperiment;\r
+import org.simantics.sysdyn.manager.SysdynGameExperimentBase;\r
 import org.simantics.sysdyn.ui.utils.ExpressionUtils;\r
 import org.simantics.ui.SimanticsUI;\r
 \r
@@ -77,11 +77,11 @@ public class ParameterExpression extends BasicExpression {
        public void readData(final Resource expression, Map<String, Object> data) {\r
                IExperimentManager manager = SimanticsUI.getProject().getHint(IExperimentManager.KEY_EXPERIMENT_MANAGER);\r
                IExperiment experiment = manager.getActiveExperiment();\r
-               if(experiment == null || !(experiment instanceof SysdynGameExperiment)) {\r
+               if(experiment == null || !(experiment instanceof SysdynGameExperimentBase)) {\r
                        super.readData(expression, data);\r
                } else {\r
                        Double value;\r
-                       ExperimentState state = ((SysdynGameExperiment)experiment).getSysdynExperimentState();\r
+                       ExperimentState state = ((SysdynGameExperimentBase)experiment).getSysdynExperimentState();\r
                        if(ExperimentState.RUNNING.equals(state) || ExperimentState.STOPPED.equals(state)) {\r
                            try {\r
                                value = SimanticsUI.getSession().syncRequest(new Read<Double>() {\r
@@ -114,7 +114,7 @@ public class ParameterExpression extends BasicExpression {
 \r
                IExperimentManager manager = SimanticsUI.getProject().getHint(IExperimentManager.KEY_EXPERIMENT_MANAGER);\r
                IExperiment experiment = manager.getActiveExperiment();\r
-               if(experiment != null && experiment instanceof SysdynGameExperiment) {\r
+               if(experiment != null && experiment instanceof SysdynGameExperimentBase) {\r
                        final String currentText = this.expression.getExpression();\r
                        final String oldEquation = (String)data.get("equation");\r
                        if(oldEquation == null || \r
@@ -122,7 +122,7 @@ public class ParameterExpression extends BasicExpression {
                            if(ExpressionUtils.isParameter(currentText)) {\r
                                Boolean savedIntoFMU = false;\r
 \r
-                               ExperimentState state = ((SysdynGameExperiment)experiment).getSysdynExperimentState();\r
+                               ExperimentState state = ((SysdynGameExperimentBase)experiment).getSysdynExperimentState();\r
                                // Set value to control only if the simulation is running or stopped, not before initialization\r
                                if(ExperimentState.RUNNING.equals(state) || ExperimentState.STOPPED.equals(state)) {\r
                                    try {\r
index 65c34770d98bbacc27b54808f123734567b798c7..9a44eacf90aabddee6e7aea497165a0f8f84fbd8 100644 (file)
@@ -4,7 +4,7 @@ import org.simantics.db.ReadGraph;
 import org.simantics.db.WriteGraph;\r
 import org.simantics.db.exception.DatabaseException;\r
 import org.simantics.db.layer0.variable.Variable;\r
-import org.simantics.sysdyn.manager.SysdynGameExperiment;\r
+import org.simantics.sysdyn.manager.SysdynGameExperimentBase;\r
 import org.simantics.sysdyn.manager.SysdynPlaybackExperiment;\r
 \r
 public class TimeIndexVariable extends IndexVariable<Double> {\r
@@ -18,8 +18,8 @@ public class TimeIndexVariable extends IndexVariable<Double> {
        public Double getValue() {\r
            if(experiment != null && experiment instanceof SysdynPlaybackExperiment)\r
                return ((SysdynPlaybackExperiment)experiment).getTime();\r
-           if(experiment != null && experiment instanceof SysdynGameExperiment)\r
-               return ((SysdynGameExperiment)experiment).getTime();\r
+           if(experiment != null && experiment instanceof SysdynGameExperimentBase)\r
+               return ((SysdynGameExperimentBase)experiment).getSolver().getTime();\r
            return null;\r
        }\r
 \r
index 83bfbba889dd60987a00878844a319bc7402d65a..567b18748ba6796bd65454f9439c4d46a42f2c48 100644 (file)
@@ -6,16 +6,16 @@ import java.util.Collection;
 import org.simantics.db.ReadGraph;\r
 import org.simantics.db.Resource;\r
 import org.simantics.db.WriteGraph;\r
+import org.simantics.db.common.utils.Logger;\r
 import org.simantics.db.common.utils.NameUtils;\r
 import org.simantics.db.exception.DatabaseException;\r
 import org.simantics.db.layer0.variable.Variable;\r
-import org.simantics.fmu.FMUControlJNI;\r
-import org.simantics.fmu.FMUJNIException;\r
 import org.simantics.simulation.experiment.ExperimentState;\r
 import org.simantics.sysdyn.SysdynResource;\r
 import org.simantics.sysdyn.manager.SysdynDataSet;\r
-import org.simantics.sysdyn.manager.SysdynGameExperiment;\r
+import org.simantics.sysdyn.manager.SysdynGameExperimentBase;\r
 import org.simantics.sysdyn.manager.SysdynResult;\r
+import org.simantics.sysdyn.solver.ISolver;\r
 \r
 abstract public class ValueIndexVariableBase<T> extends IndexVariable<T> {\r
 \r
@@ -36,8 +36,8 @@ abstract public class ValueIndexVariableBase<T> extends IndexVariable<T> {
                double[] result = new double[variableNames.size()];\r
                for(int i = 0; i < variableNames.size(); i++) {\r
                    for(SysdynResult r : results) {            \r
-                       if(experiment instanceof SysdynGameExperiment) {\r
-                           Double d = ((SysdynGameExperiment)experiment).getCurrentValue(variableNames.get(i)); \r
+                       if(experiment instanceof SysdynGameExperimentBase) {\r
+                           Double d = ((SysdynGameExperimentBase)experiment).getCurrentValue(variableNames.get(i)); \r
                            result[i] = d != null ? d : 0;\r
                        } else {\r
                            SysdynDataSet ds = r.getDataSet(variableNames.get(i));\r
@@ -63,30 +63,32 @@ abstract public class ValueIndexVariableBase<T> extends IndexVariable<T> {
                \r
                double[] values = (double[]) value;\r
                \r
-               FMUControlJNI control = null;\r
-               if(experiment instanceof SysdynGameExperiment) { // Support only game experiments for now..\r
+//             FMUControlJNI control = null;\r
+               if(experiment instanceof SysdynGameExperimentBase) { // Support only game experiments for now..\r
                    \r
-                   SysdynGameExperiment exp = (SysdynGameExperiment)experiment;\r
+                       SysdynGameExperimentBase exp = (SysdynGameExperimentBase)experiment;\r
                    ExperimentState state = exp.getSysdynExperimentState();\r
                    // Set value to control only if the simulation is running or stopped, not before initialization\r
                    if(!(ExperimentState.RUNNING.equals(state) || ExperimentState.STOPPED.equals(state)))\r
                        return;\r
                    \r
-                   control = ((SysdynGameExperiment)this.experiment).getFMUControl();\r
-                   if(control == null) \r
-                       return;\r
+//                 control = ((SysdynGameExperimentBase)this.experiment).getFMUControl();\r
+//                 if(control == null) \r
+//                     return;\r
                        \r
+                       ISolver solver = exp.getSolver();\r
+\r
+                       try {\r
                        \r
+                               ArrayList<String> variableNames = getVariableNamesWithIndexNumbers();\r
+                               for(int i = 0; i < variableNames.size() && i < values.length; i++) {\r
+\r
+                                       if(values[i] == Double.NaN)\r
+                                               continue;\r
 \r
-                       ArrayList<String> variableNames = getVariableNamesWithIndexNumbers();\r
-                       for(int i = 0; i < variableNames.size() && i < values.length; i++) {\r
-                               if(values[i] == Double.NaN)\r
-                                       continue;\r
-                               \r
-                               try {\r
                                        String name = variableNames.get(i);\r
-                                       control.setRealValue(name, values[i]);\r
-                                       \r
+                                       solver.setRealValue(name, values[i]);\r
+\r
                                        // Set value for all referred variables in modules\r
                                        SysdynResource sr = SysdynResource.getInstance(graph);\r
                                        for(Resource dependency : graph.getObjects(resource, sr.Variable_isTailOf)) {\r
@@ -97,13 +99,19 @@ abstract public class ValueIndexVariableBase<T> extends IndexVariable<T> {
                                                        if(name.indexOf(".") > 0)\r
                                                                module = name.substring(0, name.lastIndexOf(".") + 1);\r
                                                        String refName = module + NameUtils.getSafeName(graph, head) + "." + NameUtils.getSafeName(graph, ref);\r
-                                                       control.setRealValue(refName, values[i]);\r
+                                                       solver.setRealValue(refName, values[i]);\r
                                                } \r
                                        }\r
-                               } catch (FMUJNIException e) {\r
+\r
                                }\r
+                               exp.updateSubscriptions();\r
+                       \r
+                       } catch (Exception e) {\r
+                               \r
+                               Logger.defaultLogError(e);\r
+                               \r
                        }\r
-                       exp.updateSubscriptions();\r
+                       \r
                }\r
        }\r
 \r
index 17f315203ce1c8fa15ea51ec56f9bbf98354cdca..d0eb203211131a0e690262c92d5e0b02c69cee25 100644 (file)
@@ -8,7 +8,7 @@ import org.simantics.db.WriteGraph;
 import org.simantics.db.exception.DatabaseException;\r
 import org.simantics.db.layer0.variable.Variable;\r
 import org.simantics.sysdyn.manager.SysdynDataSet;\r
-import org.simantics.sysdyn.manager.SysdynGameExperiment;\r
+import org.simantics.sysdyn.manager.SysdynGameExperimentBase;\r
 import org.simantics.sysdyn.manager.SysdynResult;\r
 \r
 public class ValuesIndexVariable extends IndexVariable<double[][]> {\r
@@ -39,8 +39,8 @@ public class ValuesIndexVariable extends IndexVariable<double[][]> {
                             * get the last value from experiment. It might be different from the result\r
                             * file, if it has been modified in current time step \r
                             */\r
-                           if(experiment instanceof SysdynGameExperiment && ds.result == null) {\r
-                               double d = ((SysdynGameExperiment)experiment).getCurrentValue(variableNames.get(i));\r
+                           if(experiment instanceof SysdynGameExperimentBase && ds.result == null) {\r
+                               double d = ((SysdynGameExperimentBase)experiment).getCurrentValue(variableNames.get(i));\r
                                result[i][ds.values.length - 1] = d;\r
                            }\r
                            break; // Show the first result found. (i.e. do not show history datasets)\r
diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/GameResult.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/GameResult.java
new file mode 100644 (file)
index 0000000..dc08d76
--- /dev/null
@@ -0,0 +1,45 @@
+package org.simantics.sysdyn.manager;\r
+\r
+import java.util.ArrayList;\r
+import java.util.HashMap;\r
+\r
+import org.simantics.modelica.data.DataSet;\r
+import org.simantics.modelica.data.SimulationResult;\r
+\r
+/**\r
+ * Game results\r
+ * @author Teemu Lempinen\r
+ *\r
+ */\r
+public class GameResult extends SimulationResult {\r
+       \r
+       private final SysdynGameExperimentBase base;\r
+\r
+       public GameResult(SysdynGameExperimentBase sysdynGameExperiment, HashMap<String, ArrayList<Double>> results, String[] subscription) {\r
+               \r
+               base = sysdynGameExperiment;\r
+               // Get times\r
+               ArrayList<Double> timeList = results.get("time");\r
+               double[] times = new double[timeList.size()];\r
+               for(int i = 0; i < timeList.size(); i++) {\r
+                       times[i] = timeList.get(i);\r
+               }\r
+               \r
+               String name;\r
+               double[] values;\r
+               ArrayList<Double> valueList;\r
+               for(int k = 0; k < subscription.length; k++) {\r
+                       name = subscription[k];\r
+                       values = new double[timeList.size()];\r
+                       valueList = results.get(name);\r
+                       if(valueList.size() ==  timeList.size()) {\r
+                               for(int i = 0; i < valueList.size(); i++) {\r
+                                       values[i] = valueList.get(i);\r
+                               }\r
+                               this.variables.add(new DataSet(name, times, values));\r
+                       } else {\r
+                               System.err.println("wrong amount of values " + name);\r
+                       }\r
+               }\r
+       }\r
+}
\ No newline at end of file
index ded4dd63f56e60ef157455d2fab75f27962a51cd..f6ef5bb51d4e70796ea7bd1e013264a087ddbbd5 100644 (file)
@@ -108,7 +108,7 @@ public class MemoryResult extends SysdynResult {
             addAllInitialValues(result); // For legacy reasons\r
     }\r
     \r
-    private SimulationResult getSimulationResult() {\r
+    public SimulationResult getSimulationResult() {\r
         return this.simulationResult;\r
     }\r
 \r
index 1338ecd5b92454b8db4dde2e8c416818e119bfaf..326e8cbe52702437ad9c2b18221c1ad08eefd1f1 100644 (file)
@@ -36,6 +36,7 @@ import org.simantics.db.VirtualGraph;
 import org.simantics.db.WriteGraph;\r
 import org.simantics.db.common.request.ReadRequest;\r
 import org.simantics.db.common.request.WriteRequest;\r
+import org.simantics.db.common.utils.Logger;\r
 import org.simantics.db.common.utils.NameUtils;\r
 import org.simantics.db.exception.DatabaseException;\r
 import org.simantics.db.service.VirtualGraphSupport;\r
@@ -125,15 +126,19 @@ public class OldSysdynExperiment extends SysdynExperiment {
         for(IExperimentListener listener : listeners.getListeners())\r
             listener.stateChanged(state);\r
 \r
-        session.asyncRequest(new ReadRequest() {\r
-\r
-            @Override\r
-            public void run(ReadGraph graph) throws DatabaseException {\r
-                final Resource configuration = graph.getPossibleObject(model, SimulationResource.getInstance(graph).HasConfiguration);\r
-                sysdynModel = SysdynModelManager.getInstance(session).getModel(graph, configuration);\r
-                toggleActivation(graph, true);\r
-            }\r
-        });\r
+        try {\r
+                       g.syncRequest(new ReadRequest() {\r
+\r
+                           @Override\r
+                           public void run(ReadGraph graph) throws DatabaseException {\r
+                               final Resource configuration = graph.getPossibleObject(model, SimulationResource.getInstance(graph).HasConfiguration);\r
+                               sysdynModel = SysdynModelManager.getInstance(session).getModel(graph, configuration);\r
+                               toggleActivation(graph, true);\r
+                           }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       Logger.defaultLogError(e);\r
+               }\r
 \r
         setSysdynExperimentState(ExperimentState.INITIALIZING);\r
     }\r
diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SimulateDurationJob.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SimulateDurationJob.java
new file mode 100644 (file)
index 0000000..6f03e6e
--- /dev/null
@@ -0,0 +1,96 @@
+package org.simantics.sysdyn.manager;\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.simulation.experiment.ExperimentState;\r
+import org.simantics.sysdyn.solver.ISolver;\r
+\r
+class SimulateDurationJob extends Job {\r
+\r
+       private boolean canceled = false;\r
+       private double duration;\r
+       private final SysdynGameExperimentBase base;\r
+       private final ISolver solver;\r
+       \r
+       public SimulateDurationJob(SysdynGameExperimentBase base, String name, double duration) {\r
+               super(name);\r
+               this.base = base;\r
+               this.solver = base.getSolver();\r
+               this.duration = duration;\r
+       }\r
+\r
+       @Override\r
+       protected void canceling() {\r
+               canceled = true;\r
+       }\r
+\r
+       @Override\r
+       protected IStatus run(IProgressMonitor monitor) {\r
+               if(base == null || base.getState() != ExperimentState.STOPPED)\r
+                       return Status.OK_STATUS;\r
+\r
+               base.changeState(ExperimentState.RUNNING);\r
+               int nSteps = (int)(duration / base.stepLength); \r
+               int work = 1 + nSteps * 3 + 2; // initialization + number of steps * number of phases per step + set result + call result listeners \r
+\r
+               monitor.beginTask("Simulating " + duration + " time steps", work);\r
+               monitor.subTask("Initialize step simulation");\r
+\r
+               if(base.subscription == null || base.results == null)\r
+                       return Status.OK_STATUS;\r
+\r
+               if(duration <= 0.0)\r
+                       duration = base.stepDuration;\r
+\r
+\r
+               try {\r
+\r
+                       solver.prepareToStep();\r
+\r
+                       double time = solver.getTime();\r
+                       double eTime = time + duration;\r
+\r
+                       monitor.worked(1);\r
+\r
+                       base.setSubscribedResults(monitor, time);\r
+\r
+                       int stepNumber = 1;\r
+                       while(time < eTime && !canceled) {\r
+                               \r
+                               if(eTime - time < base.stepLength)\r
+                                       solver.setStepLength(eTime - time);\r
+\r
+                               monitor.subTask("Simulate step (time = " + time + ")");\r
+                               solver.simulateStep();\r
+                               monitor.worked(1);\r
+\r
+                               time = solver.getTime();\r
+\r
+                               if(stepNumber % base.savePer == 0) {\r
+                                       base.setSubscribedResults(monitor, time);\r
+                               } else {\r
+                                       monitor.worked(1);\r
+                               }\r
+                               stepNumber++;\r
+                               monitor.worked(1);\r
+\r
+                       }\r
+\r
+                       monitor.subTask("Display results");\r
+                       ((MemoryResult)base.getCurrentResult()).setResult(new GameResult(base, base.results, base.subscription));\r
+                       monitor.worked(1);\r
+\r
+                       base.resultsChanged(true);\r
+                       monitor.worked(1);\r
+                       base.changeState(ExperimentState.STOPPED);\r
+\r
+               } catch (Exception e) {\r
+                       e.printStackTrace();\r
+                       System.err.println("SysdynGameExperiment simulateDuration failed: \n\t" + e.getMessage());\r
+               }\r
+               return Status.OK_STATUS;\r
+               \r
+       }\r
+}
\ No newline at end of file
index ced8ad76f115788c4effedb47dc93ff51a78eee3..bf07d3d09ae7d7effe6e1aea4de54ad6de838339 100644 (file)
@@ -21,9 +21,7 @@ import java.util.ArrayList;
 import java.util.HashMap;\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.eclipse.core.runtime.NullProgressMonitor;\r
 import org.simantics.databoard.Bindings;\r
 import org.simantics.db.AsyncReadGraph;\r
 import org.simantics.db.ReadGraph;\r
@@ -31,6 +29,7 @@ import org.simantics.db.Resource;
 import org.simantics.db.Session;\r
 import org.simantics.db.WriteGraph;\r
 import org.simantics.db.common.request.WriteRequest;\r
+import org.simantics.db.common.utils.Logger;\r
 import org.simantics.db.exception.DatabaseException;\r
 import org.simantics.db.layer0.util.Layer0Utils;\r
 import org.simantics.db.layer0.util.Simantics;\r
@@ -43,11 +42,12 @@ import org.simantics.fmu.FMUJNIException;
 import org.simantics.modelica.IModelicaMonitor;\r
 import org.simantics.modelica.ModelicaManager;\r
 import org.simantics.modelica.SimulationLocation;\r
-import org.simantics.modelica.data.DataSet;\r
-import org.simantics.modelica.data.SimulationResult;\r
 import org.simantics.modeling.PartialIC;\r
 import org.simantics.simulation.experiment.ExperimentState;\r
 import org.simantics.sysdyn.SysdynResource;\r
+import org.simantics.sysdyn.simulation.SimulationJob.HeadlessModelicaMonitor;\r
+import org.simantics.sysdyn.solver.ISolver;\r
+import org.simantics.sysdyn.solver.ModelicaSolver;\r
 import org.simantics.utils.datastructures.Quad;\r
 \r
 /**\r
@@ -55,69 +55,23 @@ import org.simantics.utils.datastructures.Quad;
  * @author Teemu Lempinen\r
  *\r
  */\r
-public class SysdynGameExperiment extends OldSysdynExperiment {\r
-\r
-       private FMUControlJNI control;\r
-       private String[] subscription;\r
-       private HashMap<String, Integer> subscriptionIndexes;\r
-       private HashMap<String, ArrayList<Double>> results;\r
-       private double stepLength = DEFAULT_STEP_LENGTH;\r
-       private double startTime = DEFAULT_START_TIME;\r
-       private double stepDuration = DEFAULT_STEP_DURATION;\r
-       private int savePer = 1;\r
-       private static boolean fortranLibrariesLoaded = false;\r
+public class SysdynGameExperiment extends SysdynGameExperimentBase {\r
+\r
+       private ModelicaSolver solver;\r
+       public FMUControlJNI control;\r
+       private boolean loaded = false;\r
        \r
-       public static double DEFAULT_STEP_DURATION = 1.0;\r
-       public static double DEFAULT_STEP_LENGTH        = 0.1;\r
-       public static double DEFAULT_START_TIME         = 0.0;\r
-       public static int DEFAULT_OUTPUT_INTERVAL       = 1;\r
+       private static boolean fortranLibrariesLoaded = false;\r
        \r
-       double[] currentValues; // Current values from FMU. Updated with updateSubscriptions\r
-\r
        public SysdynGameExperiment(Resource experiment, Resource model) {\r
                super(experiment, model);\r
+               this.solver = new ModelicaSolver(this);\r
        }\r
-\r
-       public double getStepDuration() {\r
-               return stepDuration;\r
-       }\r
-       \r
-       public void setStepDuration(double duration) {\r
-               this.stepDuration = duration;\r
-       }\r
-       \r
-       public double getStepLength() {\r
-               return stepLength;\r
-       }\r
-       \r
-       public void setStepLength(double stepLength) {\r
-               this.stepLength = stepLength;\r
-       }\r
-       \r
-       public void setStartTime(double startTime) {\r
-               this.startTime = startTime;\r
-       }\r
-\r
-       public void setOutputInterval(int interval) {\r
-               this.savePer = interval;\r
-       }\r
-\r
        \r
        public FMUControlJNI getFMUControl() {\r
                return control;\r
        }\r
        \r
-       public double getTime() {\r
-           if(control != null) {\r
-               try {\r
-                   return control.getTime();\r
-               } catch (FMUJNIException e) {\r
-               }\r
-           }\r
-           return 0.0;\r
-       }\r
-       \r
-\r
        @Override\r
        public void init(ReadGraph g) {\r
                super.init(g);\r
@@ -178,6 +132,7 @@ public class SysdynGameExperiment extends OldSysdynExperiment {
                if(control!=null) {\r
                        try {\r
                                control.unloadFMU();\r
+                               loaded = false;\r
                        } catch (FMUJNIException e) {\r
                                e.printStackTrace();\r
                        }\r
@@ -268,6 +223,7 @@ public class SysdynGameExperiment extends OldSysdynExperiment {
                                }\r
                 \r
                                control.loadFMUFile(simulationLocation.executableFile.getAbsolutePath()); // unzip and load fmu\r
+                               loaded = true;\r
                                instantiate();\r
                                \r
                        } catch (FMUJNIException e) {\r
@@ -368,178 +324,18 @@ public class SysdynGameExperiment extends OldSysdynExperiment {
 \r
 \r
        @Override\r
-       public void simulateDuration(double duration) {\r
-               Job job = new simulateDurationJob("Simulate steps", this, duration);\r
-               // Start the Job\r
-               job.schedule();\r
-       }\r
-       \r
-       private double lastResultTime = Double.NaN;\r
-\r
-       public void setSubscribedResults(IProgressMonitor monitor, double time) throws FMUJNIException {\r
-\r
-//             System.err.println("setSubscribedResults " + time);\r
-               \r
-               monitor.subTask("Get results (time = " + time + ")");\r
-               currentValues = control.getSubscribedResults(currentValues);\r
-               monitor.worked(1);\r
-\r
-               monitor.subTask("Save results (time = " + time + ")");\r
-               for(int k = 0; k < subscription.length; k++) {\r
-                       setResults(time, subscription[k], currentValues[k]);\r
-               }\r
-               \r
-               lastResultTime = time;\r
-               \r
-       }\r
-       \r
-       public void setResults(double time, String key, Double value) {\r
-               ArrayList<Double> list = results.get(key);\r
-               if(list == null) {\r
-                       list = new ArrayList<Double>();\r
-                       results.put(key, list);\r
-               }\r
-               if(time == lastResultTime) {\r
-                       list.set(list.size()-1, value);\r
-               } else {\r
-                       list.add(value);\r
-               }\r
-//             System.err.println("setResults " + time + " " + key + " = " + list);\r
-       }\r
-       \r
-       public void clearResults() {\r
-               lastResultTime = Double.NaN;\r
-               results.clear();\r
-       }\r
-       \r
-       private class simulateDurationJob extends Job {\r
-\r
-           private boolean canceled = false;\r
-               private double duration;\r
-               private final SysdynGameExperiment experiment;\r
-               public simulateDurationJob(String name, SysdynGameExperiment experiment, double duration) {\r
-                       super(name);\r
-                       this.duration = duration;\r
-                       this.experiment = experiment;\r
-               }\r
-               \r
-               @Override\r
-               protected void canceling() {\r
-                   canceled = true;\r
-               }\r
-\r
-               @Override\r
-               protected IStatus run(IProgressMonitor monitor) {\r
-                       if(experiment == null || experiment.getState() != ExperimentState.STOPPED)\r
-                               return Status.OK_STATUS;\r
-                       \r
-                       changeState(ExperimentState.RUNNING);\r
-                       int nSteps = (int)(duration / stepLength); \r
-                       int work = 1 + nSteps * 3 + 2; // initialization + number of steps * number of phases per step + set result + call result listeners \r
-                       \r
-                       monitor.beginTask("Simulating " + duration + " time steps", work);\r
-                       monitor.subTask("Initialize step simulation");\r
-\r
-                       if(subscription == null || SysdynGameExperiment.this.results == null || control == null)\r
-                               return Status.OK_STATUS;\r
-                       \r
-                       if(duration <= 0.0)\r
-                               duration = stepDuration;\r
-                       \r
-                       \r
-                       try {\r
-\r
-                           // initialize if not initialized\r
-                           if(!control.isInitialized()) {\r
-                               control.setTime(startTime);\r
-                               control.initializeSimulation();\r
-                               clearResults();\r
-//                             getInitialResultValues();\r
-                           }\r
-                           \r
-                               control.setStepLength(stepLength); // Set step length each time in case there has been changes\r
-\r
-                               double time = control.getTime();\r
-                               double eTime = time + duration;\r
-                               \r
-                               monitor.worked(1);\r
-\r
-                               setSubscribedResults(monitor, time);\r
-\r
-                               int stepNumber = 1;\r
-                               while(time < eTime && !canceled) {\r
-                                   if(eTime - time < stepLength)\r
-                                       control.setStepLength(eTime - time);\r
-                                   \r
-                                       monitor.subTask("Simulate step (time = " + time + ")");\r
-                                       control.simulateStep();\r
-                                       monitor.worked(1);\r
-\r
-                                       time = control.getTime();\r
-\r
-                                       if(stepNumber % savePer == 0) {\r
-                                               setSubscribedResults(monitor, time);\r
-                                       } else {\r
-                                               monitor.worked(1);\r
-                                       }\r
-                                       stepNumber++;\r
-                                       monitor.worked(1);\r
-                                       \r
-                               }\r
-                               \r
-                               monitor.subTask("Display results");\r
-                               ((MemoryResult)getCurrentResult()).setResult(new GameResult(SysdynGameExperiment.this.results, SysdynGameExperiment.this.subscription));\r
-                               monitor.worked(1);\r
-                               \r
-                               resultsChanged(true);\r
-                               monitor.worked(1);\r
-                               changeState(ExperimentState.STOPPED);\r
-                               \r
-                       } catch (FMUJNIException e) {\r
-                               System.err.println("SysdynGameExperiment simulateDuration failed: \n\t" + e.getMessage());\r
-                       }\r
-                       return Status.OK_STATUS;\r
-               }\r
-       }\r
-       \r
-       /**\r
-        * Game results\r
-        * @author Teemu Lempinen\r
-        *\r
-        */\r
-       public class GameResult extends SimulationResult {\r
-               \r
-               public GameResult(HashMap<String, ArrayList<Double>> results, String[] subscription) {\r
-                       \r
-                       // Get times\r
-                       ArrayList<Double> timeList = results.get("time");\r
-                       double[] times = new double[timeList.size()];\r
-                       for(int i = 0; i < timeList.size(); i++) {\r
-                               times[i] = timeList.get(i);\r
-                       }\r
-                       \r
-                       String name;\r
-                       double[] values;\r
-                       ArrayList<Double> valueList;\r
-                       for(int k = 0; k < subscription.length; k++) {\r
-                               name = subscription[k];\r
-                               values = new double[timeList.size()];\r
-                               valueList = results.get(name);\r
-                               for(int i = 0; i < valueList.size(); i++) {\r
-                                       values[i] = valueList.get(i);\r
-                               }\r
-                               this.variables.add(new DataSet(name, times, values));\r
-                       }\r
-               }\r
-       }\r
-       \r
-    @Override\r
     public void rewindTo(double time) {\r
+       \r
         if(control == null)\r
             return;\r
         \r
         if(time >-0.001 && time < 0.001) {\r
-            instantiate();\r
+               try {\r
+                               simulate(new HeadlessModelicaMonitor(), new NullProgressMonitor(), sysdynModel.getConfiguration().getLabel());\r
+                   //instantiate();\r
+                       } catch (IOException e) {\r
+                               Logger.defaultLogError(e);\r
+                       }\r
         } else {\r
             System.out.println("rewindTo");\r
         }\r
@@ -564,11 +360,11 @@ public class SysdynGameExperiment extends OldSysdynExperiment {
             control.setStepLength(stepLength); // FIXME: fixed step lenghth\r
             control.setTime(startTime);\r
             control.instantiateSimulation(); // instantiate simulation\r
-            \r
-                   if(!control.isInitialized()) {\r
+\r
+            if(!control.isInitialized()) {\r
                        control.initializeSimulation();\r
                    }\r
-            \r
+\r
             if(inits.get("variableFilter") == null || inits.get("variableFilter").equals(".*"))\r
                 subscription = control.getAllVariables();\r
             else\r
@@ -644,6 +440,9 @@ public class SysdynGameExperiment extends OldSysdynExperiment {
     \r
     @Override\r
     public void updateSubscriptions() {\r
+       \r
+       if(!loaded) return;\r
+       \r
         try {\r
             if(control.isInitialized())\r
                 currentValues = control.getSubscribedResults(currentValues);\r
@@ -652,14 +451,10 @@ public class SysdynGameExperiment extends OldSysdynExperiment {
         }\r
         super.updateSubscriptions();\r
     }\r
+\r
+       @Override\r
+       public ISolver getSolver() {\r
+               return solver;\r
+       }\r
     \r
-    public Double getCurrentValue(String name) {\r
-        if(subscriptionIndexes != null && name != null) {\r
-            Integer index = subscriptionIndexes.get(name);\r
-            if(index != null) {\r
-                return currentValues[index];\r
-            }\r
-        }\r
-        return null;\r
-    }\r
  }\r
diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynGameExperimentBase.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynGameExperimentBase.java
new file mode 100644 (file)
index 0000000..16ab3a5
--- /dev/null
@@ -0,0 +1,132 @@
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2012 Association for Decentralized Information Management in\r
+ * 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
+package org.simantics.sysdyn.manager;\r
+\r
+import java.util.ArrayList;\r
+import java.util.HashMap;\r
+\r
+import org.eclipse.core.runtime.IProgressMonitor;\r
+import org.eclipse.core.runtime.jobs.Job;\r
+import org.simantics.db.Resource;\r
+import org.simantics.fmu.FMUJNIException;\r
+import org.simantics.sysdyn.solver.ISolver;\r
+\r
+/**\r
+ * Game experiment\r
+ * @author Teemu Lempinen\r
+ *\r
+ */\r
+abstract public class SysdynGameExperimentBase extends OldSysdynExperiment {\r
+\r
+       public double stepLength = DEFAULT_STEP_LENGTH;\r
+       public double startTime = DEFAULT_START_TIME;\r
+       protected double stepDuration = DEFAULT_STEP_DURATION;\r
+       protected int savePer = 1;\r
+\r
+       protected HashMap<String, Integer> subscriptionIndexes;\r
+       protected double[] currentValues; // Current values from FMU. Updated with updateSubscriptions\r
+       \r
+       HashMap<String, ArrayList<Double>> results;\r
+\r
+       protected String[] subscription;\r
+       \r
+       public static double DEFAULT_STEP_DURATION = 1.0;\r
+       public static double DEFAULT_STEP_LENGTH        = 0.1;\r
+       public static double DEFAULT_START_TIME         = 0.0;\r
+       public static int DEFAULT_OUTPUT_INTERVAL       = 1;\r
+       \r
+       public SysdynGameExperimentBase(Resource experiment, Resource model) {\r
+               super(experiment, model);\r
+       }\r
+\r
+       public double getStepDuration() {\r
+               return stepDuration;\r
+       }\r
+       \r
+       public void setStepDuration(double duration) {\r
+               this.stepDuration = duration;\r
+       }\r
+       \r
+       public double getStepLength() {\r
+               return stepLength;\r
+       }\r
+       \r
+       public void setStepLength(double stepLength) {\r
+               this.stepLength = stepLength;\r
+       }\r
+       \r
+       public void setStartTime(double startTime) {\r
+               this.startTime = startTime;\r
+       }\r
+\r
+       public void setOutputInterval(int interval) {\r
+               this.savePer = interval;\r
+       }\r
+       \r
+    public Double getCurrentValue(String name) {\r
+        if(subscriptionIndexes != null && name != null) {\r
+            Integer index = subscriptionIndexes.get(name);\r
+            if(index != null) {\r
+                return currentValues[index];\r
+            }\r
+        }\r
+        return null;\r
+    }\r
+\r
+       public void setSubscribedResults(IProgressMonitor monitor, double time) throws FMUJNIException {\r
+\r
+//             System.err.println("setSubscribedResults " + time);\r
+               \r
+               monitor.subTask("Get results (time = " + time + ")");\r
+               currentValues = getSolver().getSubscribedResults(currentValues);\r
+               monitor.worked(1);\r
+\r
+               monitor.subTask("Save results (time = " + time + ")");\r
+               for(int k = 0; k < subscription.length; k++) {\r
+                       setResults(time, subscription[k], currentValues[k]);\r
+               }\r
+               \r
+               lastResultTime = time;\r
+               \r
+       }\r
+    \r
+       private double lastResultTime = Double.NaN;\r
+\r
+       public void setResults(double time, String key, Double value) {\r
+               ArrayList<Double> list = results.get(key);\r
+               if(list == null) {\r
+                       list = new ArrayList<Double>();\r
+                       results.put(key, list);\r
+               }\r
+               if(time == lastResultTime) {\r
+                       list.set(list.size()-1, value);\r
+               } else {\r
+                       list.add(value);\r
+               }\r
+//             System.err.println("setResults " + time + " " + key + " = " + list);\r
+       }\r
+       \r
+       public void clearResults() {\r
+               lastResultTime = Double.NaN;\r
+               results.clear();\r
+       }\r
+       \r
+       @Override\r
+       public void simulateDuration(double duration) {\r
+               Job job = new SimulateDurationJob(this, "Simulate steps", duration);\r
+               // Start the Job\r
+               job.schedule();\r
+       }\r
+       \r
+    public abstract ISolver getSolver();\r
+    \r
+}\r
diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynGameExperimentInternal.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynGameExperimentInternal.java
new file mode 100644 (file)
index 0000000..c67ba48
--- /dev/null
@@ -0,0 +1,170 @@
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2012 Association for Decentralized Information Management in\r
+ * 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
+package org.simantics.sysdyn.manager;\r
+\r
+import java.io.IOException;\r
+import java.util.ArrayList;\r
+import java.util.HashMap;\r
+\r
+import org.eclipse.core.runtime.IProgressMonitor;\r
+import org.eclipse.core.runtime.NullProgressMonitor;\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.WriteGraph;\r
+import org.simantics.db.common.request.WriteRequest;\r
+import org.simantics.db.common.utils.Logger;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.db.layer0.util.Layer0Utils;\r
+import org.simantics.db.layer0.util.Simantics;\r
+import org.simantics.db.layer0.variable.Variable;\r
+import org.simantics.db.layer0.variable.Variables;\r
+import org.simantics.modelica.IModelicaMonitor;\r
+import org.simantics.modeling.PartialIC;\r
+import org.simantics.simulation.experiment.ExperimentState;\r
+import org.simantics.sysdyn.SysdynResource;\r
+import org.simantics.sysdyn.simulation.SimulationJob.HeadlessModelicaMonitor;\r
+import org.simantics.sysdyn.solver.ISolver;\r
+import org.simantics.sysdyn.solver.ISolverMonitor;\r
+import org.simantics.sysdyn.solver.InternalSolver;\r
+\r
+\r
+public class SysdynGameExperimentInternal extends SysdynGameExperimentBase {\r
+\r
+       public InternalSolver solver;\r
+       \r
+       public SysdynGameExperimentInternal(Resource experiment, Resource model) {\r
+               super(experiment, model);\r
+       }\r
+\r
+       @Override\r
+       public ISolver getSolver() {\r
+               return solver;\r
+       }\r
+       \r
+       @Override\r
+       public void init(ReadGraph g) {\r
+               \r
+               super.init(g);\r
+               \r
+               results = new HashMap<String, ArrayList<Double>>();\r
+\r
+               solver = new InternalSolver(this, sysdynModel, true, new ISolverMonitor() {\r
+                       \r
+                       @Override\r
+                       public void showConsole() {\r
+                               // TODO Auto-generated method stub\r
+                               \r
+                       }\r
+                       \r
+                       @Override\r
+                       public void message(String message) {\r
+                               System.err.println("Internal solver:" + message);\r
+                       }\r
+                       \r
+                       @Override\r
+                       public void clearConsole() {\r
+                               // TODO Auto-generated method stub\r
+                               \r
+                       }\r
+               });\r
+\r
+       }\r
+\r
+       @Override\r
+    public synchronized void simulate(final IModelicaMonitor monitor, final IProgressMonitor progressMonitor, String modelName) throws IOException {\r
+               \r
+               new Exception().printStackTrace();\r
+               \r
+       try {\r
+\r
+               solver.initialize();\r
+               solver.buildModel();\r
+\r
+            solver.setStepLength(stepLength); // FIXME: fixed step length\r
+\r
+            //solver.setTime(startTime);\r
+\r
+            subscription = solver.solver.keys();\r
+            \r
+            // Initialize subscription indexes map for fast result reading in getValue()\r
+            if(subscriptionIndexes == null)\r
+                subscriptionIndexes = new HashMap<String, Integer>();\r
+            \r
+            subscriptionIndexes.clear();\r
+            for(int i = 0; i < subscription.length; i++) {\r
+                subscriptionIndexes.put(subscription[i], i);\r
+            }\r
+\r
+            // Initialize container for current simulation results\r
+            currentValues = new double[subscription.length];\r
+            \r
+            // subscribe all variables\r
+            //solver.subscribe(subscription); \r
+\r
+            clearResults();\r
+            //getInitialResultValues();\r
+            \r
+                       Simantics.getSession().syncRequest(new WriteRequest() {\r
+\r
+                               @Override\r
+                               public void perform(WriteGraph graph) throws DatabaseException {\r
+\r
+                                       Resource run = Layer0Utils.getPossibleChild(graph, SysdynGameExperimentInternal.this.experiment, getIdentifier());\r
+                                       if(run == null) {\r
+                                               System.err.println("No run");\r
+                                               return;\r
+                                       }\r
+                                       \r
+                                       Variable base = Variables.getVariable(graph, run);\r
+                                       \r
+                                       SysdynResource SYSDYN = SysdynResource.getInstance(graph);\r
+                                       \r
+                                       Resource ic = graph.getPossibleObject(SysdynGameExperimentInternal.this.experiment, SYSDYN.Experiment_ic);\r
+                                       if(ic == null) return;\r
+                                       \r
+                                       PartialIC data = graph.getPossibleRelatedValue(ic, SYSDYN.InitialCondition_HasInitialValues, PartialIC.BINDING);\r
+                                       data.apply(graph, base);\r
+                                       \r
+                               }\r
+                               \r
+                       });\r
+                       \r
+                       \r
+                       setSubscribedResults(new NullProgressMonitor(), solver.getTime());\r
+\r
+                       ((MemoryResult)getCurrentResult()).setResult(new GameResult(this, this.results, this.subscription));\r
+\r
+                       resultsChanged(true);\r
+                       \r
+               changeState(ExperimentState.STOPPED);\r
+               \r
+               } catch (Exception e) {\r
+                       Logger.defaultLogError(e);\r
+               }\r
+    }\r
+       \r
+       @Override\r
+    public void rewindTo(double time) {\r
+        \r
+        if(time >-0.001 && time < 0.001) {\r
+               try {\r
+                               simulate(new HeadlessModelicaMonitor(), new NullProgressMonitor(), sysdynModel.getConfiguration().getLabel());\r
+                   //instantiate();\r
+                       } catch (IOException e) {\r
+                               Logger.defaultLogError(e);\r
+                       }\r
+        } else {\r
+            System.out.println("rewindTo");\r
+        }\r
+    }\r
+\r
+ }\r
index feb0734133fc55dee667e372a6ade1923a46dfb8..ab040550c3ac762df896a04c2aa97183e7b9c8e1 100644 (file)
@@ -427,7 +427,12 @@ public class SysdynModel implements IModel, IMappingListener, VariableSubscripti
             if(g.isInstanceOf(experiment, sr.PlaybackExperiment)) {\r
                 exp = new SysdynPlaybackExperiment(experiment, modelResource);\r
             } else if(g.isInstanceOf(experiment, sr.GameExperiment)) {\r
-                exp = new SysdynGameExperiment(experiment, modelResource);\r
+               if (SolverType.INTERNAL.equals(SolverSettings.getSelectedSolverType())) {\r
+                       exp = new SysdynGameExperimentInternal(experiment, modelResource);\r
+               }\r
+               else {\r
+                    exp = new SysdynGameExperiment(experiment, modelResource);\r
+               }\r
             } else if(g.isInstanceOf(experiment, sr.SensitivityAnalysisExperiment)) {\r
                 exp = new SysdynSensitivityAnalysisExperiment(experiment, modelResource);\r
             } else if(g.isInstanceOf(experiment, sr.BasicExperiment)) {\r
index 6c5e35420c0a9b21fa6b100ba190009637c83f4b..cac1aea8f188382406a4d54b109b1e1a75e9d9f0 100644 (file)
@@ -20,7 +20,7 @@ import org.simantics.simulation.experiment.IExperiment;
 import org.simantics.simulation.project.IExperimentManager;\r
 import org.simantics.sysdyn.expressionParser.ExpressionParser;\r
 import org.simantics.sysdyn.expressionParser.ParseException;\r
-import org.simantics.sysdyn.manager.SysdynGameExperiment;\r
+import org.simantics.sysdyn.manager.SysdynGameExperimentBase;\r
 import org.simantics.sysdyn.representation.Configuration;\r
 import org.simantics.sysdyn.representation.IElement;\r
 import org.simantics.sysdyn.representation.IndependentVariable;\r
@@ -46,7 +46,7 @@ public class RepresentationUtils {
                IExperimentManager manager = project.getHint(IExperimentManager.KEY_EXPERIMENT_MANAGER);\r
 \r
                IExperiment active = manager.getActiveExperiment();\r
-               if (active instanceof SysdynGameExperiment)\r
+               if (active instanceof SysdynGameExperimentBase)\r
                        return true;\r
                else\r
                        return false;\r
index 92e8c99e0c1e05a6a5c6ede417b9c48a84a452a4..75e177f2bd1302f4cc322331a84173073bbfa75a 100644 (file)
@@ -69,7 +69,7 @@ public class SimulationJob extends Job {
         return "SimulationJob".equals(family);\r
     }\r
 \r
-    private class HeadlessModelicaMonitor implements IModelicaMonitor {\r
+    public static class HeadlessModelicaMonitor implements IModelicaMonitor {\r
         public HeadlessModelicaMonitor() {\r
         }\r
 \r
index d52a67c7f28463387b05903b3ef5e4812fe11918..a2a14fbcb978b5f9f898492dfa216e5cae7e04a4 100644 (file)
@@ -10,4 +10,14 @@ public interface ISolver {
        public void updateResults() throws Exception;\r
        public SolverType getType();\r
        \r
+       public double[] getSubscribedResults(double[] array);\r
+       \r
+       public void prepareToStep() throws Exception;\r
+       public void simulateStep() throws Exception ;\r
+       \r
+       public void setStepLength(double length) throws Exception ;\r
+       public double getTime();\r
+       \r
+       public void setRealValue(String name, double value) throws Exception ;\r
+\r
 }\r
index 7cf327b9ced155a6123581e6c8a6718e25d0f91d..6835e191eb061b9a06a78ddb85c9d37882ac2f42 100644 (file)
@@ -23,21 +23,24 @@ public class InternalSolver implements ISolver {
        private SysdynExperiment experiment;\r
        private SysdynModel model;\r
        private ISolverMonitor monitor;\r
-       private Solver solver;\r
+       public Solver solver;\r
        \r
        private double start;\r
        private double stop;\r
        private double step;\r
        private double interval;\r
        \r
+       private final boolean isGame;\r
+       \r
        private SimulationLocation location;\r
 \r
        private HashMap<String, SysdynDataSet> results;\r
 \r
-       public InternalSolver(SysdynExperiment experiment, SysdynModel model, ISolverMonitor monitor) {\r
+       public InternalSolver(SysdynExperiment experiment, SysdynModel model, boolean isGame, ISolverMonitor monitor) {\r
                this.experiment = experiment;\r
                this.model = model;\r
                this.monitor = monitor;\r
+               this.isGame = isGame;\r
                \r
                solver = new Solver();\r
                \r
@@ -61,7 +64,7 @@ public class InternalSolver implements ISolver {
                        stop = representation.getStopTime();\r
                \r
 //             String omVersion = ModelicaManager.getDefaultOMVersion();\r
-               String modelContent = ModelicaWriter.write(model.getModules(), start, false, "1.9");\r
+               String modelContent = ModelicaWriter.write(model.getModules(), start, isGame, "1.9");\r
 \r
                // update some stuff\r
                FunctionUtils.updateFunctionFilesForExperiment(experiment);\r
@@ -181,5 +184,34 @@ public class InternalSolver implements ISolver {
        public SolverType getType() {\r
                return SolverType.INTERNAL;\r
        }\r
+       \r
+       @Override\r
+       public double[] getSubscribedResults(double[] array) {\r
+               return solver.values();\r
+       }\r
+       \r
+       @Override\r
+       public double getTime() {\r
+               return solver.getTime();\r
+       }\r
+       \r
+       @Override\r
+       public void prepareToStep() throws Exception {\r
+       }\r
+       \r
+       @Override\r
+       public void setRealValue(String name, double value) throws Exception {\r
+               solver.setValue(name, value);\r
+       }\r
+\r
+       @Override\r
+       public void simulateStep() throws Exception {\r
+               solver.step();\r
+       }\r
+\r
+       @Override\r
+       public void setStepLength(double length) throws Exception {\r
+               solver.setStep(length);\r
+       }\r
 \r
 }\r
diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/solver/ModelicaSolver.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/solver/ModelicaSolver.java
new file mode 100644 (file)
index 0000000..2538068
--- /dev/null
@@ -0,0 +1,93 @@
+package org.simantics.sysdyn.solver;\r
+\r
+import org.simantics.fmu.FMUJNIException;\r
+import org.simantics.sysdyn.manager.SysdynGameExperiment;\r
+import org.simantics.sysdyn.solver.SolverSettings.SolverType;\r
+\r
+public class ModelicaSolver implements ISolver {\r
+       \r
+       SysdynGameExperiment exp;\r
+       \r
+       public ModelicaSolver(SysdynGameExperiment exp) {\r
+               this.exp = exp;\r
+       }\r
+       \r
+       @Override\r
+       public void initialize() throws Exception {\r
+               // TODO Auto-generated method stub\r
+               \r
+       }\r
+\r
+       @Override\r
+       public void buildModel() throws Exception {\r
+               // TODO Auto-generated method stub\r
+               \r
+       }\r
+\r
+       @Override\r
+       public void runSolver() throws Exception {\r
+               // TODO Auto-generated method stub\r
+               \r
+       }\r
+\r
+       @Override\r
+       public void updateResults() throws Exception {\r
+               // TODO Auto-generated method stub\r
+               \r
+       }\r
+\r
+       @Override\r
+       public SolverType getType() {\r
+               // TODO Auto-generated method stub\r
+               return null;\r
+       }\r
+\r
+       @Override\r
+       public double[] getSubscribedResults(double[] array) {\r
+               // TODO Auto-generated method stub\r
+               return null;\r
+       }\r
+\r
+       @Override\r
+       public void prepareToStep() throws Exception {\r
+\r
+               // initialize if not initialized\r
+               if(!exp.control.isInitialized()) {\r
+                       exp.control.setTime(exp.startTime);\r
+                       exp.control.initializeSimulation();\r
+                       exp.clearResults();\r
+                       //                              getInitialResultValues();\r
+               }\r
+\r
+               exp.control.setStepLength(exp.stepLength); // Set step length each time in case there has been changes\r
+               \r
+       }\r
+\r
+       @Override\r
+       public void simulateStep() throws Exception {\r
+               exp.control.simulateStep();\r
+       }\r
+\r
+       @Override\r
+       public void setStepLength(double length) throws Exception {\r
+               exp.control.setStepLength(length);\r
+       }\r
+\r
+       @Override\r
+       public double getTime() {\r
+               if(exp.control != null) {\r
+                       try {\r
+                               return exp.control.getTime();\r
+                       } catch (FMUJNIException e) {\r
+                       }\r
+               }\r
+               return 0.0;\r
+       }\r
+\r
+       @Override\r
+       public void setRealValue(String name, double value) throws Exception {\r
+               exp.control.setRealValue(name, value);\r
+       }\r
+\r
+       \r
+}\r
index e12c6e3d97d019adb7b59331e35240e5bfbc72c0..eed1f064751012d383c4f64634ceec06addbaee5 100644 (file)
@@ -62,7 +62,7 @@ public class SysdynSimulationJob extends Job {
                // has changed, a new solver must be created\r
                if (solver == null || !solver.getType().equals(type)) {\r
                        if (SolverType.INTERNAL.equals(type)) {\r
-                               solver = new InternalSolver(experiment, experiment.sysdynModel, solverMonitor);\r
+                               solver = new InternalSolver(experiment, experiment.sysdynModel, false, solverMonitor);\r
                        }\r
                        else if (SolverType.OPENMODELICA.equals(type)) {\r
                                return new Status(Status.ERROR, pluginId, "The experiment should be reloaded");\r