\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
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
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
\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
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
\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