From 39329bb1692092a7bba745820581ae0297dbecdf Mon Sep 17 00:00:00 2001 From: "jussi.koskela" Date: Thu, 5 Jun 2014 12:20:16 +0000 Subject: [PATCH] refs #4928 git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@29591 ac1ea38d-2e2b-0410-8846-a27921b304fc --- .../sysdyn/manager/SysdynGameExperiment.java | 43 ------------- .../manager/SysdynGameExperimentBase.java | 63 +++++++++++++++++++ .../manager/SysdynGameExperimentInternal.java | 2 - 3 files changed, 63 insertions(+), 45 deletions(-) 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 145262d7..d3f8f19f 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynGameExperiment.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynGameExperiment.java @@ -81,49 +81,6 @@ public class SysdynGameExperiment extends SysdynGameExperimentBase { results = new HashMap>(); - g.asyncRequest(new Read>() { - - @Override - public Quad perform(ReadGraph graph) - throws DatabaseException { - SysdynResource sr = SysdynResource.getInstance(graph); - Double stepDuration = graph.getPossibleRelatedValue(experiment, sr.GameExperiment_stepDuration); - Double stepLength = graph.getPossibleRelatedValue(experiment, sr.GameExperiment_stepLength); - Double outputInterval = graph.getPossibleRelatedValue(model, sr.SysdynModel_outputInterval); - Double startTime = graph.getPossibleRelatedValue(model, sr.SysdynModel_startTime); - return new Quad(stepDuration, stepLength, outputInterval, startTime); - } - }, new AsyncListener>() { - - @Override - public void execute(AsyncReadGraph graph, - Quad result) { - setStepDuration(result.first != null ? result.first : DEFAULT_STEP_DURATION); - setStepLength(result.second != null ? result.second : DEFAULT_STEP_LENGTH); - setStartTime(result.fourth != null ? result.fourth : DEFAULT_START_TIME); - - if(result.third == null) { - setOutputInterval(DEFAULT_OUTPUT_INTERVAL); - } else { - int interval = (int)getInterval(result.third, getStepLength()); - setOutputInterval(interval); - } - } - - @Override - public void exception(AsyncReadGraph graph, Throwable throwable) { - throwable.printStackTrace(); - setStepDuration(DEFAULT_STEP_DURATION); - setStepLength(DEFAULT_STEP_LENGTH); - setStartTime(DEFAULT_START_TIME); - setOutputInterval(DEFAULT_OUTPUT_INTERVAL); - } - - @Override - public boolean isDisposed() { - return getState().equals(ExperimentState.DISPOSED); - } - }); } @Override diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynGameExperimentBase.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynGameExperimentBase.java index 7c5a8ede..91f8e118 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynGameExperimentBase.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynGameExperimentBase.java @@ -16,9 +16,17 @@ import java.util.HashMap; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.jobs.Job; +import org.simantics.db.AsyncReadGraph; +import org.simantics.db.ReadGraph; import org.simantics.db.Resource; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.procedure.AsyncListener; +import org.simantics.db.request.Read; import org.simantics.fmu.FMUJNIException; +import org.simantics.simulation.experiment.ExperimentState; +import org.simantics.sysdyn.SysdynResource; import org.simantics.sysdyn.solver.ISolver; +import org.simantics.utils.datastructures.Quad; /** * Game experiment @@ -132,4 +140,59 @@ abstract public class SysdynGameExperimentBase extends OldSysdynExperiment { public abstract ISolver getSolver(); + @Override + public void init(ReadGraph g) { + + super.init(g); + + try { + g.syncRequest(new Read>() { + + @Override + public Quad perform(ReadGraph graph) + throws DatabaseException { + SysdynResource sr = SysdynResource.getInstance(graph); + Double stepDuration = graph.getPossibleRelatedValue(experiment, sr.GameExperiment_stepDuration); + Double stepLength = graph.getPossibleRelatedValue(experiment, sr.GameExperiment_stepLength); + Double outputInterval = graph.getPossibleRelatedValue(model, sr.SysdynModel_outputInterval); + Double startTime = graph.getPossibleRelatedValue(model, sr.SysdynModel_startTime); + return new Quad(stepDuration, stepLength, outputInterval, startTime); + } + }, new AsyncListener>() { + + @Override + public void execute(AsyncReadGraph graph, + Quad result) { + setStepDuration(result.first != null ? result.first : DEFAULT_STEP_DURATION); + setStepLength(result.second != null ? result.second : DEFAULT_STEP_LENGTH); + setStartTime(result.fourth != null ? result.fourth : DEFAULT_START_TIME); + + if(result.third == null) { + setOutputInterval(DEFAULT_OUTPUT_INTERVAL); + } else { + int interval = (int)getInterval(result.third, getStepLength()); + setOutputInterval(interval); + } + } + + @Override + public void exception(AsyncReadGraph graph, Throwable throwable) { + throwable.printStackTrace(); + setStepDuration(DEFAULT_STEP_DURATION); + setStepLength(DEFAULT_STEP_LENGTH); + setStartTime(DEFAULT_START_TIME); + setOutputInterval(DEFAULT_OUTPUT_INTERVAL); + } + + @Override + public boolean isDisposed() { + return getState().equals(ExperimentState.DISPOSED); + } + }); + } catch (DatabaseException e) { + e.printStackTrace(); + } + + } + } diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynGameExperimentInternal.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynGameExperimentInternal.java index 07226b80..a3864dfe 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynGameExperimentInternal.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynGameExperimentInternal.java @@ -87,8 +87,6 @@ public class SysdynGameExperimentInternal extends SysdynGameExperimentBase { solver.initialize(); solver.buildModel(); - solver.setStepLength(stepLength); // FIXME: fixed step length - //solver.setTime(startTime); subscription = solver.solver.keys(); -- 2.47.1