From: Antti Villberg Date: Mon, 20 Mar 2017 05:44:48 +0000 (+0200) Subject: Experiment state request X-Git-Tag: v1.28.0~53 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=0eef0d4984f3fbd757f0421cc71f1428ec1235a1;p=simantics%2Fplatform.git Experiment state request refs #7036 Change-Id: I2704afcc626a3deb7430eb1a42ea453f71e931d6 --- diff --git a/bundles/org.simantics.modeling/scl/Simantics/Simulation.scl b/bundles/org.simantics.modeling/scl/Simantics/Simulation.scl index 4935fafcd..460d1cd0e 100644 --- a/bundles/org.simantics.modeling/scl/Simantics/Simulation.scl +++ b/bundles/org.simantics.modeling/scl/Simantics/Simulation.scl @@ -6,10 +6,15 @@ importJava "org.simantics.simulation.experiment.ExperimentUtil" where stepExperiment :: IExperiment -> Double -> () simulateExperiment :: IExperiment -> Boolean -> () disposeExperiment :: IExperiment -> () + getExperimentState :: IExperiment -> ExperimentState possibleActiveRunVariable ::Resource -> Variable importJava "org.simantics.simulation.experiment.IExperiment" where data IExperiment + +importJava "org.simantics.simulation.experiment.ExperimentState" where + data ExperimentState + INITIALIZING, RUNNING, STOPPED, DISPOSED :: ExperimentState experimentFromRun :: Variable -> IExperiment experimentFromRun run = (run#iExperiment) :: IExperiment \ No newline at end of file diff --git a/bundles/org.simantics.simulation/src/org/simantics/simulation/experiment/Experiment.java b/bundles/org.simantics.simulation/src/org/simantics/simulation/experiment/Experiment.java index b4222df01..41125d0a0 100644 --- a/bundles/org.simantics.simulation/src/org/simantics/simulation/experiment/Experiment.java +++ b/bundles/org.simantics.simulation/src/org/simantics/simulation/experiment/Experiment.java @@ -19,6 +19,8 @@ import org.simantics.databoard.accessor.Accessor; import org.simantics.db.ReadGraph; import org.simantics.db.Resource; import org.simantics.db.exception.DatabaseException; +import org.simantics.db.procedure.Listener; +import org.simantics.db.request.ExternalRead; import org.simantics.utils.datastructures.ListenerList; public abstract class Experiment implements IExperiment { @@ -64,7 +66,7 @@ public abstract class Experiment implements IExperiment { @Override public ExperimentState getState(ReadGraph graph) throws DatabaseException { - throw new UnsupportedOperationException(); + return graph.syncRequest(EXPERIMENT_STATE_READ); } public void changeState(ExperimentState newState) { @@ -136,4 +138,37 @@ public abstract class Experiment implements IExperiment { return identifier; } + static class ExperimentStateRead implements ExternalRead, Runnable { + + final private Experiment experiment; + private Listener listener = null; + + ExperimentStateRead(Experiment experiment) { + this.experiment = experiment; + } + + @Override + public void register(ReadGraph graph, final Listener procedure) { + //System.out.println("IcTrackerRequest.register: " + procedure); + listener = procedure; + procedure.execute(experiment.state); + } + + @Override + public void unregistered() { + //System.out.println("IcTrackerRequest.unregister: " + listener); + listener = null; + } + + @Override + public void run() { + Listener l = listener; + //System.out.println("IcTrackerRequest.run: " + l); + if (l != null) + l.execute(experiment.state); + } + } + + private ExperimentStateRead EXPERIMENT_STATE_READ = new ExperimentStateRead(this); + } diff --git a/bundles/org.simantics.simulation/src/org/simantics/simulation/experiment/ExperimentUtil.java b/bundles/org.simantics.simulation/src/org/simantics/simulation/experiment/ExperimentUtil.java index 24f6065c5..a819ef8ed 100644 --- a/bundles/org.simantics.simulation/src/org/simantics/simulation/experiment/ExperimentUtil.java +++ b/bundles/org.simantics.simulation/src/org/simantics/simulation/experiment/ExperimentUtil.java @@ -47,6 +47,10 @@ public final class ExperimentUtil { ((IDynamicExperiment)experiment).simulate(enabled); } + public static ExperimentState getExperimentState(ReadGraph graph, IExperiment experiment) throws DatabaseException { + return experiment.getState(graph); + } + public static void disposeExperiment(final IExperiment experiment) { if(experiment instanceof IDynamicExperiment) {