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
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 {
@Override
public ExperimentState getState(ReadGraph graph) throws DatabaseException {
- throw new UnsupportedOperationException();
+ return graph.syncRequest(EXPERIMENT_STATE_READ);
}
public void changeState(ExperimentState newState) {
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);
+
}