]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
SCL command session variable under runs
authorvillberg <villberg@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Thu, 25 Sep 2014 09:40:40 +0000 (09:40 +0000)
committervillberg <villberg@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Thu, 25 Sep 2014 09:40:40 +0000 (09:40 +0000)
refs #5335

git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@30319 ac1ea38d-2e2b-0410-8846-a27921b304fc

org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynModel.java

index 0d4a811a69c992bbfb6441c1bc2175b3116700e1..93df521edd922040c6ddd910180dc3eb182c6302 100644 (file)
@@ -23,9 +23,11 @@ import java.util.Set;
 import java.util.concurrent.CopyOnWriteArrayList;\r
 \r
 import org.simantics.Simantics;\r
+import org.simantics.databoard.Bindings;\r
 import org.simantics.db.ReadGraph;\r
 import org.simantics.db.Resource;\r
 import org.simantics.db.Session;\r
+import org.simantics.db.WriteGraph;\r
 import org.simantics.db.common.utils.NameUtils;\r
 import org.simantics.db.exception.DatabaseException;\r
 import org.simantics.db.exception.ManyObjectsForFunctionalRelationException;\r
@@ -34,11 +36,14 @@ import org.simantics.db.procedure.Listener;
 import org.simantics.db.request.Read;\r
 import org.simantics.db.service.VirtualGraphSupport;\r
 import org.simantics.layer0.Layer0;\r
+import org.simantics.modeling.ModelingResources;\r
 import org.simantics.objmap.IMapping;\r
 import org.simantics.objmap.IMappingListener;\r
 import org.simantics.objmap.MappingException;\r
 import org.simantics.objmap.Mappings;\r
 import org.simantics.project.IProject;\r
+import org.simantics.scl.runtime.function.Function2;\r
+import org.simantics.scl.runtime.function.FunctionImpl2;\r
 import org.simantics.simulation.experiment.IExperiment;\r
 import org.simantics.simulation.model.IModel;\r
 import org.simantics.simulation.ontology.SimulationResource;\r
@@ -453,8 +458,27 @@ public class SysdynModel implements IModel, IMappingListener, VariableSubscripti
             \r
             exp.init(g);\r
             \r
+            Function2<WriteGraph, Resource, Object> scl = new FunctionImpl2<WriteGraph, Resource, Object>() {\r
+\r
+                               @Override\r
+                               public Object apply(WriteGraph graph, Resource run) {\r
+                                       try {\r
+                                               Layer0 L0 = Layer0.getInstance(graph);\r
+                                               ModelingResources MOD = ModelingResources.getInstance(graph);\r
+                                               Resource session = graph.newResource();\r
+                                               graph.claim(session, L0.InstanceOf, MOD.SCLCommandSession);\r
+                                               graph.addLiteral(session, L0.HasName, L0.NameOf, L0.String, "__scl__", Bindings.STRING);\r
+                                               graph.claim(run, L0.ConsistsOf, session);\r
+                                       } catch (DatabaseException e) {\r
+                                               e.printStackTrace();\r
+                                       }\r
+                                       return null;\r
+                               }\r
+                               \r
+                       };\r
+            \r
             VirtualGraphSupport support = g.getSession().getService(VirtualGraphSupport.class);\r
-            ExperimentRuns.createRun(g.getSession(), support.getWorkspacePersistent("experiments"), experiment, exp, SysdynResource.URIs.Experiment_Run, listener, null);\r
+            ExperimentRuns.createRun(g.getSession(), support.getWorkspacePersistent("experiments"), experiment, exp, SysdynResource.URIs.Experiment_Run, listener, scl, null);\r
             if(listener != null)\r
                 listener.onExperimentActivated(exp);\r
             return exp;\r