From 9780de36a75e71e7af8234215c3fea9aedc2354d Mon Sep 17 00:00:00 2001 From: lempinen Date: Fri, 29 Jun 2012 12:19:55 +0000 Subject: [PATCH] Ignore step commands while already stepping a simulation. Documentation cannot yet disable simulation buttons while simulating. (refs #3511) git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@25269 ac1ea38d-2e2b-0410-8846-a27921b304fc --- .../sysdyn/ui/handlers/game/StepHandler.java | 11 +++++++++-- .../org/simantics/sysdyn/adapter/ModuleVariable.java | 5 ++++- .../sysdyn/manager/SysdynGameExperiment.java | 12 ++++++++++-- 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/game/StepHandler.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/game/StepHandler.java index d7b5b2a2..7435b4cf 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/game/StepHandler.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/game/StepHandler.java @@ -36,6 +36,7 @@ public class StepHandler extends AbstractHandler implements IElementUpdater { private boolean started = false; private boolean initialized = false; + private boolean running = false; private SysdynGameExperiment getGameExperiment() { // Find active experiment @@ -79,17 +80,23 @@ public class StepHandler extends AbstractHandler implements IElementUpdater { if(state==ExperimentState.INITIALIZING) { started = false; initialized = false; + running = false; } else if(state==ExperimentState.RUNNING) { started = true; - initialized = false; + initialized = initialized == true ? true : false; + running = true; } else if(state==ExperimentState.STOPPED) { if(started && !initialized) { initialized = true; } + running = false; } if(initialized) { - this.setBaseEnabled(true); + if(!running) + this.setBaseEnabled(true); + else + this.setBaseEnabled(false); element.setTooltip("Step"); } else { this.setBaseEnabled(false); diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/adapter/ModuleVariable.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/adapter/ModuleVariable.java index bfc5120f..28b1140e 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/adapter/ModuleVariable.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/adapter/ModuleVariable.java @@ -44,7 +44,10 @@ public class ModuleVariable extends ChildVariable { throw new MissingVariableException("No configuration for " + NameUtils.getSafeName(graph, instanceOf)); Map children = graph.syncRequest(new UnescapedChildMapOfResource(configuration)); Resource child = children.get(name); - return graph.adaptContextual(child, this, Variable.class, Variable.class); + if(child == null) + return null; + else + return graph.adaptContextual(child, this, Variable.class, Variable.class); } diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynGameExperiment.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynGameExperiment.java index f5918430..9de739b9 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynGameExperiment.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynGameExperiment.java @@ -222,7 +222,7 @@ public class SysdynGameExperiment extends SysdynExperiment { @Override public void simulateDuration(double duration) { - Job job = new simulateDurationJob("Simulate steps", duration); + Job job = new simulateDurationJob("Simulate steps", this, duration); // Start the Job job.schedule(); } @@ -230,13 +230,19 @@ public class SysdynGameExperiment extends SysdynExperiment { private class simulateDurationJob extends Job { private double duration; - public simulateDurationJob(String name, double duration) { + private SysdynGameExperiment experiment; + public simulateDurationJob(String name, SysdynGameExperiment experiment, double duration) { super(name); this.duration = duration; + this.experiment = experiment; } @Override protected IStatus run(IProgressMonitor monitor) { + if(experiment == null || experiment.getState() != ExperimentState.STOPPED) + return Status.OK_STATUS; + + changeState(ExperimentState.RUNNING); int nSteps = (int)(duration / stepLength); int work = 1 + nSteps * 3 + 2; // initialization + number of steps * number of phases per step + set result + call result listeners @@ -287,6 +293,8 @@ public class SysdynGameExperiment extends SysdynExperiment { sysdynModel.resultChanged(); monitor.worked(1); + changeState(ExperimentState.STOPPED); + } catch (FMUJNIException e) { System.err.println("SysdynGameExperiment simulateDuration failed: \n\t" + e.getMessage()); -- 2.47.1