From c706978d91e7d9b370c13053596345c04bbdebaa Mon Sep 17 00:00:00 2001 From: villberg Date: Fri, 12 Sep 2014 18:05:56 +0000 Subject: [PATCH] Save/assign IC copies server state refs #5300 git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@30271 ac1ea38d-2e2b-0410-8846-a27921b304fc --- .../sysdyn/manager/SysdynExperiments.java | 43 ++++++++++++++++--- 1 file changed, 38 insertions(+), 5 deletions(-) diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynExperiments.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynExperiments.java index 34302b38..7b918f14 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynExperiments.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynExperiments.java @@ -14,13 +14,17 @@ import org.simantics.db.ReadGraph; import org.simantics.db.Resource; import org.simantics.db.WriteGraph; import org.simantics.db.common.request.ObjectsWithType; +import org.simantics.db.common.request.WriteRequest; import org.simantics.db.common.utils.NameUtils; import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.adapter.impl.DefaultCopyHandler; +import org.simantics.db.layer0.adapter.impl.DefaultPasteHandler; import org.simantics.db.layer0.util.Layer0Utils; import org.simantics.db.layer0.util.RemoverUtil; import org.simantics.db.layer0.variable.RVI; import org.simantics.db.layer0.variable.Variable; import org.simantics.db.layer0.variable.Variables; +import org.simantics.db.service.VirtualGraphSupport; import org.simantics.layer0.Layer0; import org.simantics.modeling.ModelingResources; import org.simantics.modeling.PartialIC; @@ -213,7 +217,7 @@ public class SysdynExperiments { PartialIC IC = new PartialIC(); processChild(graph, input, IC); - + Layer0 L0 = Layer0.getInstance(graph); ModelingResources MOD = ModelingResources.getInstance(graph); Resource ic = graph.newResource(); @@ -221,6 +225,19 @@ public class SysdynExperiments { graph.addLiteral(ic, L0.HasName, L0.NameOf, L0.String, name, Bindings.STRING); graph.addLiteral(ic, SYSDYN.InitialCondition_HasInitialValues, SYSDYN.InitialCondition_HasInitialValues_Inverse, MOD.PartialIC, IC, PartialIC.BINDING); graph.claim(model, L0.ConsistsOf, ic); + + Resource represents = input.getPossibleRepresents(graph); + if(represents != null) { + Resource state = Layer0Utils.getPossibleChild(graph, represents, "__simupedia__"); + Layer0Utils.copyTo(graph, ic, state, null, new DefaultCopyHandler(state) { + + @Override + protected boolean ignoreVirtualResources() { + return false; + } + + }, new DefaultPasteHandler(ic)); + } Layer0Utils.addCommentMetadata(graph, "Saved new Initial Condition " + name + " " + ic); return ic; @@ -229,12 +246,11 @@ public class SysdynExperiments { public static void assignIC(WriteGraph graph, Variable experiment, String name) throws DatabaseException { graph.markUndoPoint(); - System.err.println("assignIC " + experiment.getURI(graph)); Layer0 L0 = Layer0.getInstance(graph); SysdynResource SYSDYN = SysdynResource.getInstance(graph); - Resource run = experiment.getPossibleRepresents(graph); + final Resource run = experiment.getPossibleRepresents(graph); if(run == null) return; Resource exp = graph.getPossibleObject(run, L0.PartOf); if(exp == null) return; @@ -248,12 +264,29 @@ public class SysdynExperiments { graph.deny(exp, SYSDYN.Experiment_ic); graph.claim(exp, SYSDYN.Experiment_ic, ic); Layer0Utils.addCommentMetadata(graph, "Assigned Initial Condition " + graph.getRelatedValue2(ic, L0.HasName, Bindings.STRING) + " to experiment " + graph.getRelatedValue2(exp, L0.HasName, Bindings.STRING)); + + Resource oldState = Layer0Utils.getPossibleChild(graph, run, "__simupedia__"); + if(oldState != null) { + graph.deny(run, L0.ConsistsOf, oldState); + } + + final Resource storedState = Layer0Utils.getPossibleChild(graph, ic, "__simupedia__"); + if(storedState != null) { + VirtualGraphSupport vgs = graph.getService(VirtualGraphSupport.class); + graph.syncRequest(new WriteRequest(vgs.getMemoryPersistent("experiments")) { + + @Override + public void perform(WriteGraph graph) throws DatabaseException { + Layer0Utils.copyTo(graph, run, storedState, null, new DefaultCopyHandler(storedState), new DefaultPasteHandler(run)); + } + + }); + } + } public static void deassignIC(WriteGraph graph, Variable experiment) throws DatabaseException { - System.err.println("deassignIC " + experiment.getURI(graph)); - Layer0 L0 = Layer0.getInstance(graph); SysdynResource SYSDYN = SysdynResource.getInstance(graph); -- 2.47.1