]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Experiment state request 66/366/1
authorAntti Villberg <antti.villberg@semantum.fi>
Mon, 20 Mar 2017 05:44:48 +0000 (07:44 +0200)
committerAntti Villberg <antti.villberg@semantum.fi>
Mon, 20 Mar 2017 05:44:48 +0000 (07:44 +0200)
refs #7036

Change-Id: I2704afcc626a3deb7430eb1a42ea453f71e931d6

bundles/org.simantics.modeling/scl/Simantics/Simulation.scl
bundles/org.simantics.simulation/src/org/simantics/simulation/experiment/Experiment.java
bundles/org.simantics.simulation/src/org/simantics/simulation/experiment/ExperimentUtil.java

index 4935fafcd043c547853d18984e15eab1380e272c..460d1cd0edf41e2259427ed574417f80178abadd 100644 (file)
@@ -6,10 +6,15 @@ importJava "org.simantics.simulation.experiment.ExperimentUtil" where
     stepExperiment :: IExperiment -> Double -> <Proc> ()
     simulateExperiment :: IExperiment -> Boolean -> <Proc> ()
     disposeExperiment :: IExperiment -> <Proc> ()
+    getExperimentState :: IExperiment -> <ReadGraph> ExperimentState
     possibleActiveRunVariable ::Resource -> <ReadGraph> 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 -> <ReadGraph> IExperiment
 experimentFromRun run = (run#iExperiment) :: IExperiment
\ No newline at end of file
index b4222df012e4a56d8533914fa0c751adfd724fef..41125d0a0ad2f086cb90201c05f15c432d8bebcc 100644 (file)
@@ -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<ExperimentState>, Runnable {
+       
+       final private Experiment experiment;
+        private Listener<ExperimentState> listener = null;
+        
+        ExperimentStateRead(Experiment experiment) {
+               this.experiment = experiment;
+        }
+
+        @Override
+        public void register(ReadGraph graph, final Listener<ExperimentState> 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<ExperimentState> l = listener;
+            //System.out.println("IcTrackerRequest.run: " + l);
+            if (l != null)
+                l.execute(experiment.state);
+        }
+    }
+
+    private ExperimentStateRead EXPERIMENT_STATE_READ = new ExperimentStateRead(this);
+    
 }
index 24f6065c5117a6e6660d336edfeefa3c56f43593..a819ef8ed915462da196d5e120ceee3a6a070021 100644 (file)
@@ -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) {