From f56ec38061a86776aaf2eb86d796515f9565b6c6 Mon Sep 17 00:00:00 2001 From: villberg Date: Wed, 13 Apr 2011 13:21:22 +0000 Subject: [PATCH] Aihio Teemulle. git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@20474 ac1ea38d-2e2b-0410-8846-a27921b304fc --- org.simantics.sysdyn.ontology/graph.tg | Bin 53397 -> 53413 bytes .../graph/Sysdyn.pgraph | 2 +- org.simantics.sysdyn.ui/adapters.xml | 2 +- .../ui/browser/contributions/Model.java | 5 +- .../ui/editor/SysdynCreationInstruction.java | 1 + .../ConfigurationDiagramClassAdapter.java | 2 +- .../ui/handlers/ImportModelHandler.java | 14 ++- .../DefaultRealizationVirtualGraph.java | 2 +- .../HistoryRealizationVirtualGraph.java | 10 +- .../sysdyn/ui/project/SysdynProject.java | 81 ++++++------ .../SysdynDatasetSelectionListener.java | 5 +- org.simantics.sysdyn/META-INF/MANIFEST.MF | 3 +- org.simantics.sysdyn/adapters.xml | 18 +++ .../sysdyn/adapter/ChildVariable.java | 23 ++++ .../sysdyn/adapter/ChildVariableAdapter.java | 16 +++ .../sysdyn/adapter/ConfigurationVariable.java | 40 ++++++ .../sysdyn/adapter/HistoryVariable.java | 117 ++++++++++++++++++ .../simantics/sysdyn/adapter/RunVariable.java | 52 ++++++++ 18 files changed, 331 insertions(+), 62 deletions(-) create mode 100644 org.simantics.sysdyn/src/org/simantics/sysdyn/adapter/ChildVariable.java create mode 100644 org.simantics.sysdyn/src/org/simantics/sysdyn/adapter/ChildVariableAdapter.java create mode 100644 org.simantics.sysdyn/src/org/simantics/sysdyn/adapter/ConfigurationVariable.java create mode 100644 org.simantics.sysdyn/src/org/simantics/sysdyn/adapter/HistoryVariable.java create mode 100644 org.simantics.sysdyn/src/org/simantics/sysdyn/adapter/RunVariable.java diff --git a/org.simantics.sysdyn.ontology/graph.tg b/org.simantics.sysdyn.ontology/graph.tg index 9a68098c766626247ed43a53e91f70f5df4a794d..70f588911261395275b73f94a76cb7f2a65d53fe 100644 GIT binary patch delta 85 zcmbQbka_7s<_$mj7#%nN;=9em=&<>k^a*yx2bwS4dUA& P@$J$04x8_<-lhToApR7T delta 69 zcmZ3wka_At<_$mj7#%kM;=9em=(zcs^a*yxJDcY#%XcU`GB7YW0I>uE1M>wS4dUA& M@$EOiU%gEQ01crNC;$Ke diff --git a/org.simantics.sysdyn.ontology/graph/Sysdyn.pgraph b/org.simantics.sysdyn.ontology/graph/Sysdyn.pgraph index b0bdaa24..0161567e 100644 --- a/org.simantics.sysdyn.ontology/graph/Sysdyn.pgraph +++ b/org.simantics.sysdyn.ontology/graph/Sysdyn.pgraph @@ -68,7 +68,7 @@ SYSDYN.SysdynDiagramModelingRules : MOD.MappedModelingRules SYSDYN.SymbolReferences : DIA.SymbolReferenceLibrary BasicSymbols = SYSDYN.SymbolReferences.BasicSymbols : DIA.SymbolReferenceLibrary -SYSDYN.Configuration - none 0 fill 1 + none 0 fill 1 \ No newline at end of file diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/Model.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/Model.java index bf6a2270..71db1e0b 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/Model.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/Model.java @@ -18,10 +18,9 @@ import org.simantics.browsing.ui.common.node.AbstractNode; import org.simantics.browsing.ui.graph.contributor.viewpoint.ViewpointContributor; import org.simantics.db.ReadGraph; import org.simantics.db.Resource; -import org.simantics.db.common.request.PossibleObjectWithType; +import org.simantics.db.common.primitiverequest.PossibleObject; import org.simantics.db.exception.DatabaseException; import org.simantics.layer0.Layer0; -import org.simantics.sysdyn.SysdynResource; import org.simantics.sysdyn.ui.browser.nodes.ConfigurationNode; import org.simantics.sysdyn.ui.browser.nodes.ExperimentsFolder; import org.simantics.sysdyn.ui.browser.nodes.FunctionsFolder; @@ -36,7 +35,7 @@ public class Model extends ViewpointContributor { ArrayList> result = new ArrayList>(); Layer0 l0 = Layer0.getInstance(graph); - Resource baseRealization = graph.syncRequest(new PossibleObjectWithType(model.data, l0.ConsistsOf, SysdynResource.getInstance(graph).DefaultRealization)); + Resource baseRealization = graph.syncRequest(new PossibleObject(model.data, l0.HasBaseRealization)); if (baseRealization != null) { result.add(new ConfigurationNode(baseRealization)); } diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/SysdynCreationInstruction.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/SysdynCreationInstruction.java index f35891b3..d7f1c632 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/SysdynCreationInstruction.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/SysdynCreationInstruction.java @@ -49,6 +49,7 @@ public class SysdynCreationInstruction extends CreationInstruction { Resource result = GraphUtils.create(g, g.getBuiltins().HasName, proposition ); + g.claim(result, g.getBuiltins().Represents, result); return result; } catch (NamingException e1) { throw new DatabaseException(e1); diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/ConfigurationDiagramClassAdapter.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/ConfigurationDiagramClassAdapter.java index b1d0059c..b102a163 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/ConfigurationDiagramClassAdapter.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/ConfigurationDiagramClassAdapter.java @@ -28,7 +28,7 @@ import org.simantics.g2d.routing.RouterFactory; public class ConfigurationDiagramClassAdapter implements ResourceAdapter { @Override - public void adapt(AsyncReadGraph g, Resource r, AsyncProcedure procedure) { + public void adapt(AsyncReadGraph g, Resource source, Resource r, AsyncProcedure procedure) { procedure.execute(g, DiagramClassAdapter.INSTANCE.newClassWith( Initializer.INSTANCE )); diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/ImportModelHandler.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/ImportModelHandler.java index 566f520b..027c4a9a 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/ImportModelHandler.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/ImportModelHandler.java @@ -62,13 +62,13 @@ public class ImportModelHandler extends AbstractHandler { } if(tg == null) return null; - DefaultPasteImportAdvisor ia = new DefaultPasteImportAdvisor(project); - DefaultPasteHandler.defaultExecute(tg, SimanticsUI.getProject().get(), ia); - - - // FIXME: the links should be exported and imported automatically - final Resource root = ia.getRoot(); try { + + DefaultPasteImportAdvisor ia = new DefaultPasteImportAdvisor(project); + DefaultPasteHandler.defaultExecute(tg, SimanticsUI.getProject().get(), ia); + + // FIXME: the links should be exported and imported automatically + final Resource root = ia.getRoot(); SimanticsUI.getSession().syncRequest(new WriteRequest() { @Override @@ -84,6 +84,8 @@ public class ImportModelHandler extends AbstractHandler { }); } catch (DatabaseException e) { e.printStackTrace(); + } catch (Exception e) { + e.printStackTrace(); } return null; diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/project/DefaultRealizationVirtualGraph.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/project/DefaultRealizationVirtualGraph.java index 76d3ac62..f8b1cc35 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/project/DefaultRealizationVirtualGraph.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/project/DefaultRealizationVirtualGraph.java @@ -38,7 +38,7 @@ public class DefaultRealizationVirtualGraph extends RealizationVirtualGraph { graph.claim(model, L0.ConsistsOf, null, defaultsResource); graph.claim(model, L0.HasBaseRealization, null, defaultsResource); - undiscovered.put(defaultsNode, new ResourceData(modelNode, configuration, L0.Realization, "BaseRealization", null, null)); +// undiscovered.put(defaultsNode, new ResourceData(modelNode, configuration, L0.Realization, "BaseRealization", null, null)); } diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/project/HistoryRealizationVirtualGraph.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/project/HistoryRealizationVirtualGraph.java index 7fcc060c..a70d2368 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/project/HistoryRealizationVirtualGraph.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/project/HistoryRealizationVirtualGraph.java @@ -98,7 +98,7 @@ public class HistoryRealizationVirtualGraph extends RealizationVirtualGraph { Resource partResource = graph.newResource(); int partNode = context.getIndex(partResource); graph.claim(run, l0.ConsistsOf, null, partResource); - undiscovered.put(partNode, new ResourceData(runNode, part.second, valuation, part.first, experimentName, null)); +// undiscovered.put(partNode, new ResourceData(runNode, part.second, valuation, part.first, experimentName, null)); } } }); @@ -112,10 +112,10 @@ public class HistoryRealizationVirtualGraph extends RealizationVirtualGraph { Integer key = null; for(int k : undiscovered.keySet()) { ResourceData rd = undiscovered.get(k); - if (rd.name.equals(part.first) && rd.structureResource.equals(part.second)) { - key = k; - break; - } +// if (rd.name.equals(part.first) && rd.structureResource.equals(part.second)) { +// key = k; +// break; +// } } if(key != null) { Resource r = context.getResource(key); diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/project/SysdynProject.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/project/SysdynProject.java index 23f182ed..fd21b27a 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/project/SysdynProject.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/project/SysdynProject.java @@ -137,6 +137,7 @@ public class SysdynProject extends AbstractProjectFeature { Resource conf = GraphUtils.create2(g, sr.Configuration, l0.PartOf, model, + l0.IsBaseRealizationOf, model, l0.HasName, modelName ); @@ -239,46 +240,46 @@ public class SysdynProject extends AbstractProjectFeature { VirtualGraphSupport support = session.getService(VirtualGraphSupport.class); - final VirtualGraph graph = session.getService(VirtualGraph.class); - - SysdynResource SYSDYN = SysdynResource.getInstance(session); - session.asyncRequest(new ObjectsWithType(projectResource, l0.ConsistsOf, SYSDYN.SysdynModel), new SingleSetSyncListener() { - - @Override - public void add(ReadGraph g, final Resource model) throws DatabaseException { - - GenericRelationIndex index = g.adapt(l0.DependenciesRelation, GenericRelationIndex.class); - index.trackAndIndex(g.getSession(), model); - - // FIXME: - Simantics.async(new Runnable() { - - @Override - public void run() { - try { - // This creates experiment realizations - graph.register(new HistoryRealizationVirtualGraph(session, model)); - // This creates the BaseRealization - graph.register(new DefaultRealizationVirtualGraph(session, model)); - } catch (DatabaseException e) { - e.printStackTrace(); - } - } - - }); - } - - @Override - public void exception(ReadGraph graph, Throwable t) { - t.printStackTrace(); - } - - @Override - public boolean isDisposed() { - return false; - } - - }); +// final VirtualGraph graph = session.getService(VirtualGraph.class); + +// SysdynResource SYSDYN = SysdynResource.getInstance(session); +// session.asyncRequest(new ObjectsWithType(projectResource, l0.ConsistsOf, SYSDYN.SysdynModel), new SingleSetSyncListener() { +// +// @Override +// public void add(ReadGraph g, final Resource model) throws DatabaseException { +// +// GenericRelationIndex index = g.adapt(l0.DependenciesRelation, GenericRelationIndex.class); +// index.trackAndIndex(g.getSession(), model); +// +// // FIXME: +// Simantics.async(new Runnable() { +// +// @Override +// public void run() { +// try { +// // This creates experiment realizations +// graph.register(new HistoryRealizationVirtualGraph(session, model)); +// // This creates the BaseRealization +// graph.register(new DefaultRealizationVirtualGraph(session, model)); +// } catch (DatabaseException e) { +// e.printStackTrace(); +// } +// } +// +// }); +// } +// +// @Override +// public void exception(ReadGraph graph, Throwable t) { +// t.printStackTrace(); +// } +// +// @Override +// public boolean isDisposed() { +// return false; +// } +// +// }); support.getWorkspacePersistent("experiments"); diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/viewUtils/SysdynDatasetSelectionListener.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/viewUtils/SysdynDatasetSelectionListener.java index 38e7b92c..5eece715 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/viewUtils/SysdynDatasetSelectionListener.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/viewUtils/SysdynDatasetSelectionListener.java @@ -152,9 +152,8 @@ public abstract class SysdynDatasetSelectionListener implements ISelectionListen rvi = rvi.length() > 0 ? rvi.substring(1) : rvi; rvi = rvi.replace("/", "."); - - RepresentsProperty rp = (RepresentsProperty)variable.getProperty(g, Variables.REPRESENTS); - Resource r = rp.getValue(g); + + Resource r = variable.getPropertyValue(g, Variables.REPRESENTS); SysdynResource sr = SysdynResource.getInstance(g); Resource arrayIndexes = g.getPossibleObject(r, sr.HasArrayIndexes); diff --git a/org.simantics.sysdyn/META-INF/MANIFEST.MF b/org.simantics.sysdyn/META-INF/MANIFEST.MF index 1e115e11..fd145491 100644 --- a/org.simantics.sysdyn/META-INF/MANIFEST.MF +++ b/org.simantics.sysdyn/META-INF/MANIFEST.MF @@ -21,7 +21,8 @@ Require-Bundle: org.simantics.objmap;bundle-version="0.1.0", org.simantics.modeling;bundle-version="1.1.1", org.simantics.diagram;bundle-version="1.1.1", org.simantics.diagram.ontology;bundle-version="1.1.1", - org.simantics.scl.runtime;bundle-version="0.1.3" + org.simantics.scl.runtime;bundle-version="0.1.3", + org.simantics.db.layer0;bundle-version="1.1.0" Export-Package: org.simantics.sysdyn, org.simantics.sysdyn.expressionParser, org.simantics.sysdyn.manager, diff --git a/org.simantics.sysdyn/adapters.xml b/org.simantics.sysdyn/adapters.xml index 6734fa55..2d68b7c8 100644 --- a/org.simantics.sysdyn/adapters.xml +++ b/org.simantics.sysdyn/adapters.xml @@ -20,4 +20,22 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/adapter/ChildVariable.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/adapter/ChildVariable.java new file mode 100644 index 00000000..a572ce8a --- /dev/null +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/adapter/ChildVariable.java @@ -0,0 +1,23 @@ +package org.simantics.sysdyn.adapter; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.variable.StandardGraphChildVariable; +import org.simantics.db.layer0.variable.Variable; + +public class ChildVariable extends StandardGraphChildVariable { + + final private Variable parent; + + public ChildVariable(Variable parent, Resource resource) { + super(resource); + this.parent = parent; + } + + @Override + public Variable getParent(ReadGraph graph) throws DatabaseException { + return parent; + } + +} diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/adapter/ChildVariableAdapter.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/adapter/ChildVariableAdapter.java new file mode 100644 index 00000000..2bd1a8c3 --- /dev/null +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/adapter/ChildVariableAdapter.java @@ -0,0 +1,16 @@ +package org.simantics.sysdyn.adapter; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.adaption.SimpleContextualAdapter; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.variable.Variable; + +public class ChildVariableAdapter extends SimpleContextualAdapter{ + + @Override + public Variable adapt(ReadGraph g, Resource source, Variable context) throws DatabaseException { + return new ChildVariable(context, source); + } + +} diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/adapter/ConfigurationVariable.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/adapter/ConfigurationVariable.java new file mode 100644 index 00000000..244afb73 --- /dev/null +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/adapter/ConfigurationVariable.java @@ -0,0 +1,40 @@ +package org.simantics.sysdyn.adapter; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Map; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.uri.UnescapedChildMapOfResource; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.variable.StandardGraphChildVariable; +import org.simantics.db.layer0.variable.Variable; + +public class ConfigurationVariable extends StandardGraphChildVariable { + + public ConfigurationVariable(Resource resource) { + super(resource); + } + + @Override + public Variable getPossibleChild(ReadGraph graph, String name) throws DatabaseException { + Map children = graph.syncRequest(new UnescapedChildMapOfResource(resource)); + Resource child = children.get(name); + if(child == null) { + return getPossibleSpecialChild(graph, name); + } + else return graph.adaptContextual(child, this, Variable.class, Variable.class); + } + + + @Override + public Collection browseChildren(ReadGraph graph) throws DatabaseException { + ArrayList result = new ArrayList(); + for(Resource child : graph.syncRequest(new UnescapedChildMapOfResource(resource)).values()) + result.add(graph.adaptContextual(child, this, Variable.class, Variable.class)); + collectSpecialChildren(graph, result); + return result; + } + +} diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/adapter/HistoryVariable.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/adapter/HistoryVariable.java new file mode 100644 index 00000000..c416b5cc --- /dev/null +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/adapter/HistoryVariable.java @@ -0,0 +1,117 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.adapter; + +import java.util.ArrayList; + +import org.simantics.databoard.Accessors; +import org.simantics.databoard.Bindings; +import org.simantics.databoard.accessor.Accessor; +import org.simantics.databoard.accessor.RecordAccessor; +import org.simantics.databoard.accessor.error.AccessorConstructionException; +import org.simantics.databoard.accessor.error.AccessorException; +import org.simantics.databoard.binding.error.RuntimeBindingConstructionException; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.variable.ResourceVariable; +import org.simantics.db.layer0.variable.Variable; +import org.simantics.db.layer0.variable.Variables; +import org.simantics.simulation.ontology.SimulationResource; +import org.simantics.sysdyn.manager.SysdynDataSet; +import org.simantics.sysdyn.manager.SysdynModel; +import org.simantics.sysdyn.manager.SysdynModelManager; +import org.simantics.sysdyn.manager.SysdynResult; + +public class HistoryVariable extends ResourceVariable { + + final private Variable parent; + + public HistoryVariable(Variable parent, Resource resource) { + super(resource); + this.parent = parent; + } + +// @Override +// public T getInterface(ReadGraph graph, Class clazz) throws DatabaseException { +// if(Accessor.class.equals(clazz)) { +// +// SimulationResource SIMU = SimulationResource.getInstance(graph); +// Resource model = Variables.getModel(graph, this); +// Resource configuration = graph.getPossibleObject(model, SIMU.HasConfiguration); +// SysdynModel sm = SysdynModelManager.getInstance(graph.getSession()).getModel(graph, configuration); +// SysdynResult sr = sm.getSysdynResult(); +// String rvi = Variables.getRVI(graph, this); +// System.out.println("HistoryVariable rvi='" + rvi + "'"); +// rvi = rvi.substring(1).replace("/", "."); +// SysdynDataSet ds = sr.getDataSet(rvi); +// +// try { +// return (T)Accessors.getAccessor(Bindings.getBindingUnchecked(SysdynDataSet.class), ds); +// } catch (RuntimeBindingConstructionException e) { +// e.printStackTrace(); +// } catch (AccessorConstructionException e) { +// e.printStackTrace(); +// } +// return null; +// +// } +// return super.getInterface(graph, clazz); +// } + + @SuppressWarnings("unchecked") + @Override + public T getInterface(ReadGraph graph, Class clazz) throws DatabaseException { + if(RecordAccessor.class.equals(clazz) || Accessor.class.equals(clazz)) { + SimulationResource SIMU = SimulationResource.getInstance(graph); + Resource model = Variables.getModel(graph, this); + Resource configuration = graph.getPossibleObject(model, SIMU.HasConfiguration); + final SysdynModel sm = SysdynModelManager.getInstance(graph.getSession()).getModel(graph, configuration); + SysdynResult sr = new SysdynResult(sm.getSimulationResult()); // TODO: copy or not to copy ... + + String tmp = Variables.getRVI(graph, this); + System.out.println("HistoryVariable rvi='" + tmp + "'"); + final String rvi = tmp.substring(1).replace("/", "."); + SysdynDataSet ds = sr.getDataSet(rvi); + if(ds == null) ds = new SysdynDataSet("", "", new ArrayList(), new ArrayList()); // We need a dataset, so if not set, create it + try { + final RecordAccessor ac = (RecordAccessor)Accessors.getAccessor(Bindings.getBindingUnchecked(SysdynDataSet.class), ds); + + sm.addResultListener(new Runnable() { // FIXME: remove listener at some point.. + @Override + public void run() { + SysdynResult sr = new SysdynResult(sm.getSimulationResult()); + SysdynDataSet ds = sr.getDataSet(rvi); + if(ds == null) return; + try { + if(ds.result == null) ds.result = ""; + ac.setValue(Bindings.getBindingUnchecked(SysdynDataSet.class), ds); + } catch (RuntimeBindingConstructionException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (AccessorException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + }}); + return (T)ac; + } catch (RuntimeBindingConstructionException e) { + e.printStackTrace(); + } catch (AccessorConstructionException e) { + e.printStackTrace(); + } + return null; + + } + return super.getInterface(graph, clazz); + } +} diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/adapter/RunVariable.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/adapter/RunVariable.java new file mode 100644 index 00000000..aab21ce3 --- /dev/null +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/adapter/RunVariable.java @@ -0,0 +1,52 @@ +package org.simantics.sysdyn.adapter; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Map; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.request.PropertyMapOfResource; +import org.simantics.db.common.uri.UnescapedChildMapOfResource; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.variable.GraphPropertyFactory; +import org.simantics.db.layer0.variable.StandardGraphChildVariable; +import org.simantics.db.layer0.variable.Variable; +import org.simantics.layer0.Layer0; + +public class RunVariable extends StandardGraphChildVariable { + + public RunVariable(Resource resource) { + super(resource); + } + + @Override + public Variable getPossibleChild(ReadGraph graph, String name) throws DatabaseException { + Resource config = getConfiguration(graph); + Map children = graph.syncRequest(new UnescapedChildMapOfResource(config)); + Resource child = children.get(name); + if(child == null) { + return getPossibleSpecialChild(graph, name); + } + else return new HistoryVariable(this, child); + } + + + @Override + public Collection browseChildren(ReadGraph graph) throws DatabaseException { + ArrayList result = new ArrayList(); + Resource config = getConfiguration(graph); + for(Resource child : graph.syncRequest(new UnescapedChildMapOfResource(config)).values()) + result.add(new HistoryVariable(this, child)); + collectSpecialChildren(graph, result); + return result; + } + + Resource getConfiguration(ReadGraph graph) throws DatabaseException { + Layer0 L0 = Layer0.getInstance(graph); + Resource experiment = graph.getPossibleObject(resource, L0.PartOf); + Resource model = graph.getPossibleObject(experiment, L0.PartOf); + return graph.getPossibleObject(model, L0.HasBaseRealization); + } + +} -- 2.47.1