]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
Ignore step commands while already stepping a simulation. Documentation cannot yet...
authorlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Fri, 29 Jun 2012 12:19:55 +0000 (12:19 +0000)
committerlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Fri, 29 Jun 2012 12:19:55 +0000 (12:19 +0000)
git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@25269 ac1ea38d-2e2b-0410-8846-a27921b304fc

org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/game/StepHandler.java
org.simantics.sysdyn/src/org/simantics/sysdyn/adapter/ModuleVariable.java
org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynGameExperiment.java

index d7b5b2a2a5af402dc206f67d0dd9abdb381b2442..7435b4cf490a1b3fa689046fcbd478c41465238f 100644 (file)
@@ -36,6 +36,7 @@ public class StepHandler extends AbstractHandler implements IElementUpdater {
     \r
        private boolean started = false;\r
        private boolean initialized = false;\r
+       private boolean running = false;        \r
     \r
     private SysdynGameExperiment getGameExperiment() {\r
         // Find active experiment\r
@@ -79,17 +80,23 @@ public class StepHandler extends AbstractHandler implements IElementUpdater {
                if(state==ExperimentState.INITIALIZING) {\r
                        started = false;\r
                        initialized = false;\r
+                       running = false;\r
                } else if(state==ExperimentState.RUNNING) {\r
                        started = true;\r
-                       initialized = false;\r
+                       initialized = initialized == true ? true : false;\r
+                       running = true;\r
                } else if(state==ExperimentState.STOPPED) {\r
                        if(started && !initialized) {\r
                                initialized = true;\r
                        } \r
+                       running = false;\r
                }\r
         \r
         if(initialized) {\r
-            this.setBaseEnabled(true);\r
+               if(!running)\r
+                       this.setBaseEnabled(true);\r
+               else\r
+                       this.setBaseEnabled(false);\r
             element.setTooltip("Step");\r
         } else {\r
             this.setBaseEnabled(false);\r
index bfc5120f574c2aa28479c882da2fc5501383edc2..28b1140e2314d11e6016770e3193ba4670f9b066 100644 (file)
@@ -44,7 +44,10 @@ public class ModuleVariable extends ChildVariable {
                        throw new MissingVariableException("No configuration for " + NameUtils.getSafeName(graph, instanceOf));\r
                Map<String, Resource> children = graph.syncRequest(new UnescapedChildMapOfResource(configuration));\r
                Resource child = children.get(name);\r
-               return graph.adaptContextual(child, this, Variable.class, Variable.class);\r
+               if(child == null)\r
+                       return null;\r
+               else\r
+                       return graph.adaptContextual(child, this, Variable.class, Variable.class);\r
        }\r
 \r
 \r
index f5918430342fe8f5c4e5cc89513366cb7490802e..9de739b9bc911026dbe61e7101cf30dea069f855 100644 (file)
@@ -222,7 +222,7 @@ public class SysdynGameExperiment extends SysdynExperiment {
 \r
        @Override\r
        public void simulateDuration(double duration) {\r
-               Job job = new simulateDurationJob("Simulate steps", duration);\r
+               Job job = new simulateDurationJob("Simulate steps", this, duration);\r
                // Start the Job\r
                job.schedule();\r
        }\r
@@ -230,13 +230,19 @@ public class SysdynGameExperiment extends SysdynExperiment {
        private class simulateDurationJob extends Job {\r
 \r
                private double duration;\r
-               public simulateDurationJob(String name, double duration) {\r
+               private 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 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
@@ -287,6 +293,8 @@ public class SysdynGameExperiment extends SysdynExperiment {
                                \r
                                sysdynModel.resultChanged();\r
                                monitor.worked(1);\r
+                               changeState(ExperimentState.STOPPED);\r
+\r
                                \r
                        } catch (FMUJNIException e) {\r
                                System.err.println("SysdynGameExperiment simulateDuration failed: \n\t" + e.getMessage());\r