import org.simantics.layer0.Layer0;\r
import org.simantics.modeling.ModelingResources;\r
import org.simantics.modeling.PartialIC;\r
+import org.simantics.modeling.scl.SCLRealm;\r
+import org.simantics.modeling.scl.SCLSessionManager;\r
import org.simantics.project.IProject;\r
import org.simantics.scl.runtime.tuple.Tuple2;\r
import org.simantics.simulation.experiment.ExperimentState;\r
return saveIC(graph, input, name);\r
}\r
\r
- public static Resource saveIC(WriteGraph graph, Variable input, String name) throws DatabaseException {\r
+ public static Resource saveIC(WriteGraph graph, Variable input, String name) throws DatabaseException {\r
+ return saveIC2(graph, null, input, name);\r
+ }\r
+ \r
+ public static Resource saveIC2(WriteGraph graph, Variable session, Variable input, String name) throws DatabaseException {\r
+\r
graph.markUndoPoint();\r
Resource model = Variables.getModel(graph, input);\r
Resource child = Layer0Utils.getPossibleChild(graph, model, name);\r
\r
Resource represents = input.getPossibleRepresents(graph);\r
if(represents != null) {\r
- Resource state = Layer0Utils.getPossibleChild(graph, represents, "__simupedia__"); \r
- Layer0Utils.copyTo(graph, ic, state, null, new DefaultCopyHandler(state) {\r
- \r
- @Override\r
- protected boolean ignoreVirtualResources() {\r
- return false;\r
- }\r
- \r
- }, new DefaultPasteHandler(ic));\r
- \r
-// String id = input.getName(graph);\r
-// SCLRealm realm = SCLSessionManager.sclRealmById(id);\r
-// if(realm != null) {\r
-// byte[] blob = realm.serialize();\r
-// //graph.addLiteral(ic, SYSDYN.InitialCondition_HasInitialValues, SYSDYN.InitialCondition_HasInitialValues_Inverse, MOD.PartialIC, IC, PartialIC.BINDING);\r
-// }\r
- \r
+ Resource state = Layer0Utils.getPossibleChild(graph, represents, "__simupedia__");\r
+ if(state != null) {\r
+ Layer0Utils.copyTo(graph, ic, state, null, new DefaultCopyHandler(state) {\r
+ \r
+ @Override\r
+ protected boolean ignoreVirtualResources() {\r
+ return false;\r
+ }\r
+ \r
+ }, new DefaultPasteHandler(ic));\r
+ }\r
+ }\r
+ \r
+ if(session != null) {\r
+ \r
+ SCLRealm realm = SCLSessionManager.sclRealmById(session.getURI(graph) + "/__icstate__");\r
+ byte[] values = realm.serialize();\r
+ \r
+ Resource sclState = graph.newResource();\r
+ graph.claim(sclState, L0.InstanceOf, MOD.SCLState);\r
+ graph.claimLiteral(sclState, MOD.SCLState_identifier, MOD.SCLState_identifier_Inverse, L0.String, "__icstate__", Bindings.STRING);\r
+ graph.claimLiteral(sclState, MOD.SCLState_blob, MOD.SCLState_blob_Inverse, L0.ByteArray, values, Bindings.BYTE_ARRAY);\r
+ graph.claim(ic, MOD.InitialCondition_HasSCLState, sclState);\r
+ \r
}\r
\r
Layer0Utils.addCommentMetadata(graph, "Saved new Initial Condition " + name + " " + ic);\r
}\r
\r
public static void applyIC(WriteGraph graph, Variable experiment, String name) throws DatabaseException {\r
+ applyIC2(graph, null, experiment, name);\r
+ }\r
+\r
+ public static void applyIC2(WriteGraph graph, Variable session, Variable experiment, String name) throws DatabaseException {\r
\r
Layer0 L0 = Layer0.getInstance(graph);\r
SysdynResource SYSDYN = SysdynResource.getInstance(graph);\r
PartialIC data = graph.getPossibleRelatedValue(ic, SYSDYN.InitialCondition_HasInitialValues, PartialIC.BINDING);\r
data.apply(graph, base);\r
\r
+ if(session != null) {\r
+ ModelingResources MOD = ModelingResources.getInstance(graph);\r
+ for(Resource sclState : graph.getObjects(ic, MOD.InitialCondition_HasSCLState)) {\r
+ String identifier = graph.getRelatedValue(sclState, MOD.SCLState_identifier);\r
+ if("__icstate__".equals(identifier)) {\r
+ byte[] blob = graph.getRelatedValue(sclState, MOD.SCLState_blob);\r
+ SCLRealm realm = SCLSessionManager.sclRealmById(session.getURI(graph) + "/__icstate__");\r
+ realm.applyState(blob);\r
+ realm.refreshVariablesSync();\r
+ }\r
+ }\r
+ }\r
+ \r
SysdynExperiments.setPublishResults(graph, base, true);\r
\r
\r