]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
More SCL functions for experiment and run handling 40/2040/2
authorAntti Villberg <antti.villberg@semantum.fi>
Tue, 28 Aug 2018 07:36:05 +0000 (10:36 +0300)
committerAntti Villberg <antti.villberg@semantum.fi>
Tue, 28 Aug 2018 07:51:14 +0000 (10:51 +0300)
gitlab #91

Change-Id: I8ee4adbc8f375a7dc61df45e21f5ffe5582d84b8

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

index 72166303ea6ec97967454ac9607671dbaf1af7b7..2a721ee21d69f873b024b9506466f262d64490d5 100644 (file)
@@ -6,8 +6,13 @@ importJava "org.simantics.simulation.experiment.ExperimentUtil" where
     stepExperiment :: IExperiment -> Double -> <Proc> ()
     simulateExperiment :: IExperiment -> Boolean -> <Proc> ()
     disposeExperiment :: IExperiment -> <Proc> ()
+    refreshExperiment :: IExperiment -> <ReadGraph> ()
     getExperimentState :: IExperiment -> <ReadGraph> ExperimentState
     possibleActiveRunVariable ::Resource -> <ReadGraph> Maybe Variable
+    activateExperiment :: Resource -> <WriteGraph> Resource
+    createExperimentRun :: Resource -> <WriteGraph> Resource
+    createExperimentRunWithType :: Resource -> Resource -> <WriteGraph> Resource
+    activateRun :: Resource -> <WriteGraph> ()
     
 importJava "org.simantics.simulation.experiment.IExperiment" where
     data IExperiment
index 449afe59f3209d26e229b57c0da30bb4c05ccc95..fb9f6780551ba488e32d838bc9ac9597cdcf61fc 100644 (file)
@@ -37,6 +37,10 @@ import org.simantics.simulation.project.IExperimentManager;
  */
 public final class ExperimentUtil {
 
+    public static void refreshExperiment(ReadGraph graph, IExperiment experiment) {
+        experiment.refresh(graph);
+    }
+
     public static void stepExperiment(IExperiment experiment, double duration) {
         if(experiment instanceof IDynamicExperiment)
             ((IDynamicExperiment)experiment).simulateDuration(duration);
@@ -202,7 +206,20 @@ public final class ExperimentUtil {
         }
     }
 
-    private static Resource activateExperiment(WriteGraph graph, Resource experiment) throws DatabaseException {
+    public static Resource activateExperiment(WriteGraph graph, Resource experiment) throws DatabaseException {
+
+        VirtualGraphSupport vgs = graph.getService(VirtualGraphSupport.class);
+        return graph.syncRequest(new WriteResultRequest<Resource>(vgs.getMemoryPersistent("experiments")) {
+            @Override
+            public Resource perform(WriteGraph graph) throws DatabaseException {
+                return createExperimentRun(graph, experiment);
+            }
+        });
+        
+    }
+
+    public static Resource createExperimentRun(WriteGraph graph, Resource experiment) throws DatabaseException {
+       
         Layer0 L0 = Layer0.getInstance(graph);
         SimulationResource SIMU = SimulationResource.getInstance(graph);
 
@@ -213,35 +230,35 @@ public final class ExperimentUtil {
         if (runTypes.size() != 1)
             throw new DatabaseException("No unique run type was found for experiment " + graph.getPossibleURI(experiment));
         final Resource runType = runTypes.iterator().next();
+        
+        return createExperimentRunWithType(graph, experiment, runType);
+        
+    }
 
-        VirtualGraphSupport vgs = graph.getService(VirtualGraphSupport.class);
-        return graph.syncRequest(new WriteResultRequest<Resource>(vgs.getMemoryPersistent("experiments")) {
-            @Override
-            public Resource perform(WriteGraph graph) throws DatabaseException {
-                Layer0 L0 = Layer0.getInstance(graph);
-                Resource run = graph.newResource();
-                graph.claim(run, L0.InstanceOf, runType);
-                graph.addLiteral(run, L0.HasName, L0.NameOf, L0.String, UUID.randomUUID().toString(), Bindings.STRING);
-                graph.claim(experiment, L0.ConsistsOf, run);
-
-                Resource activeRun = graph.syncRequest(new PossibleActiveExperiment(experiment));
-                if (activeRun != null) {
-                    graph.deny(activeRun, SIMU.IsActive, activeRun);
-                }
-                graph.claim(run, SIMU.IsActive, run);
+    public static Resource createExperimentRunWithType(WriteGraph graph, Resource experiment, Resource runType) throws DatabaseException {
+       
+        Layer0 L0 = Layer0.getInstance(graph);
 
-                return run;
-            }
-        });
+        Resource run = graph.newResource();
+        graph.claim(run, L0.InstanceOf, runType);
+        graph.addLiteral(run, L0.HasName, L0.NameOf, L0.String, UUID.randomUUID().toString(), Bindings.STRING);
+        graph.claim(experiment, L0.ConsistsOf, run);
+
+        activateRun(graph, run);
+        
+        return run;
+        
     }
 
-    private static void activateRun(WriteGraph graph, Resource run) throws DatabaseException {
+    public static void activateRun(WriteGraph graph, Resource run) throws DatabaseException {
+       
         SimulationResource SIMU = SimulationResource.getInstance(graph);
         Resource activeRun = graph.syncRequest(new PossibleActiveExperiment(run));
         if (activeRun != null) {
             graph.deny(activeRun, SIMU.IsActive, activeRun);
         }
         graph.claim(run, SIMU.IsActive, run);
+        
     }
 
 }