import org.simantics.modeling.ModelingResources;\r
import org.simantics.structural.stubs.StructuralResource2;\r
import org.simantics.sysdyn.SysdynResource;\r
-import org.simantics.sysdyn.adapter.ChildVariable;\r
import org.simantics.sysdyn.ui.browser.BrowserSelection;\r
import org.simantics.sysdyn.ui.browser.nodes.ModuleNode;\r
import org.simantics.ui.DoubleClickEvent;\r
StructuralResource2 sr2 = StructuralResource2.getInstance(g);\r
if(g.isInheritedFrom(instanceOf, sr.Module)) {\r
configuration = g.getSingleObject(instanceOf, sr2.IsDefinedBy);\r
- ChildVariable variable = (ChildVariable) bs.getAdapter(Variable.class);\r
- String rvi = variable.getRvi(g);\r
+ Variable variable = (Variable) bs.getAdapter(Variable.class);\r
+ String rvi = Variables.getRVI(g, variable).substring(1);\r
Resource model = Variables.getModel(g, variable);\r
addShowModuleAction(e, getResourceEditorInput(g, model, configuration, rvi));\r
} \r
String rvi;\r
if(moduleNode.getVariable() != null) {\r
model = Variables.getModel(g, moduleNode.getVariable());\r
- ChildVariable var = (ChildVariable)moduleNode.getVariable();\r
- rvi = var.getRvi(g);\r
+ Variable var = moduleNode.getVariable();\r
+ rvi = Variables.getRVI(g, var).substring(1);\r
} else {\r
rvi = (String)g.getRelatedValue(moduleNode.data, Layer0.getInstance(g).HasName);\r
model = g.getSingleObject(moduleNode.data, l0.PartOf);\r
\r
@Override\r
public Object copy(ISynchronizationContext context, WriteGraph graph, Resource source, Resource sourceContainer, Resource targetContainer) throws DatabaseException {\r
- \r
+ \r
BinaryFunction<Boolean, ReadGraph, Statement> tester = new BinaryFunction<Boolean, ReadGraph, Statement>() {\r
\r
@Override\r
\r
import org.simantics.db.ReadGraph;\r
import org.simantics.db.Resource;\r
+import org.simantics.db.common.utils.NameUtils;\r
import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.db.layer0.exception.MissingVariableException;\r
import org.simantics.db.layer0.variable.Variable;\r
import org.simantics.db.layer0.variable.Variables;\r
import org.simantics.diagram.elements.TextNode;\r
import org.simantics.sysdyn.SysdynResource;\r
import org.simantics.sysdyn.adapter.ChildVariable;\r
import org.simantics.sysdyn.adapter.ConfigurationVariable;\r
-import org.simantics.sysdyn.adapter.HistoryVariable;\r
import org.simantics.sysdyn.adapter.RunVariable;\r
import org.simantics.utils.datastructures.hints.IHintContext.Key;\r
\r
}\r
} else {\r
Resource runtime = diagram.getHint((DiagramModelHints.KEY_DIAGRAM_RUNTIME_RESOURCE));\r
+ for(Resource r : graph.getPredicates(runtime)) {\r
+ System.out.println(NameUtils.getSafeName(graph, r) + " " + graph.getPossibleRelatedValue(runtime, r));\r
+ }\r
DiagramResource dr = DiagramResource.getInstance(graph);\r
String variable = (String)graph.getPossibleRelatedValue(runtime, dr.HasVariable);\r
if(variable == null)\r
return;\r
- Variable v = Variables.getVariable(graph, variable);\r
- module = graph.getResource(v.getURI(graph));\r
- if(module != null)\r
- for(Resource dep : graph.getObjects(module, sr.IsHeadOf)) {\r
- Resource reference = graph.getPossibleObject(dep, sr.RefersTo);\r
- if(reference!= null && reference.equals(component)) {\r
- refersTo = graph.getSingleObject(dep, sr.HasTail);\r
- referenceName = (String) graph.getPossibleRelatedValue(refersTo, l0.HasName);\r
- Variable parent = null;\r
- if(v instanceof HistoryVariable)\r
- parent = ((HistoryVariable)v).getParent(graph);\r
- else if(v instanceof ChildVariable)\r
- parent = ((ChildVariable)v).getParent(graph);\r
- if(parent != null && !(parent instanceof RunVariable) && !(parent instanceof ConfigurationVariable)) {\r
- String parentURI = parent.getURI(graph);\r
- moduleName = (String) graph.getPossibleRelatedValue(graph.getResource(parentURI), l0.HasName);\r
- }\r
- break;\r
- }\r
- }\r
+ \r
+ \r
+ try {\r
+ Variable v = Variables.getVariable(graph, variable);\r
+ if(v instanceof ChildVariable) {\r
+ module = ((ChildVariable)v).getRepresents(graph);\r
+ }\r
+ if(module != null)\r
+ for(Resource dep : graph.getObjects(module, sr.IsHeadOf)) {\r
+ Resource reference = graph.getPossibleObject(dep, sr.RefersTo);\r
+ if(reference!= null && reference.equals(component)) {\r
+ refersTo = graph.getSingleObject(dep, sr.HasTail);\r
+ referenceName = (String) graph.getPossibleRelatedValue(refersTo, l0.HasName);\r
+ Variable parent = null;\r
+ if(v instanceof ChildVariable)\r
+ parent = ((ChildVariable)v).getParent(graph);\r
+ if(parent != null && !(parent instanceof RunVariable) && !(parent instanceof ConfigurationVariable)) {\r
+ String parentURI = parent.getURI(graph);\r
+ moduleName = (String) graph.getPossibleRelatedValue(graph.getResource(parentURI), l0.HasName);\r
+ }\r
+ break;\r
+ }\r
+ }\r
+ } catch (MissingVariableException mve) {\r
+ // DO nothing.\r
+ }\r
}\r
\r
String inputReference = null;\r
import org.simantics.modeling.ModelingResources;\r
import org.simantics.structural.stubs.StructuralResource2;\r
import org.simantics.sysdyn.SysdynResource;\r
-import org.simantics.sysdyn.adapter.ChildVariable;\r
-import org.simantics.sysdyn.adapter.HistoryVariable;\r
import org.simantics.sysdyn.ui.editor.DiagramViewer;\r
import org.simantics.ui.SimanticsUI;\r
import org.simantics.ui.utils.ResourceAdaptionUtils;\r
final Resource diagram = ComponentUtils.getPossibleCompositeDiagram(graph, configuration);\r
\r
Variable variable = parent.browsePossible(graph, component);\r
- String rvi = "";\r
- if(variable instanceof HistoryVariable)\r
- rvi = "/" + ((HistoryVariable)variable).getRvi(graph);\r
- else if (variable instanceof ChildVariable)\r
- rvi = "/" + ((ChildVariable)variable).getRvi(graph);\r
- \r
- final String finalRvi = rvi;\r
+ final String finalRvi = Variables.getRVI(graph, variable);\r
\r
PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {\r
\r
@Override\r
public Collection<?> getContribution(ReadGraph graph, Resource input)\r
throws DatabaseException {\r
+ ArrayList<RedeclarationNode> result = new ArrayList<RedeclarationNode>();\r
+ if(input == null)\r
+ return result;\r
+ \r
SysdynResource sr = SysdynResource.getInstance(graph);\r
Layer0 l0 = Layer0.getInstance(graph);\r
StructuralResource2 sr2 = StructuralResource2.getInstance(graph);\r
Resource moduleType = graph.getSingleObject(input, l0.InstanceOf);\r
Resource configuration = graph.getSingleObject(moduleType, sr2.IsDefinedBy);\r
\r
- ArrayList<RedeclarationNode> result = new ArrayList<RedeclarationNode>();\r
- \r
for(Resource r : graph.syncRequest(new ObjectsWithType(configuration, l0.ConsistsOf, sr.Enumeration))) {\r
if(Boolean.TRUE.equals(graph.getRelatedValue(r, sr.IsReplaceable)))\r
result.add(new RedeclarationNode(graph, input, r));\r
import org.simantics.modeling.ModelingUtils;\r
import org.simantics.simulation.ontology.SimulationResource;\r
import org.simantics.sysdyn.SysdynResource;\r
-import org.simantics.sysdyn.adapter.ChildVariable;\r
-import org.simantics.sysdyn.adapter.HistoryVariable;\r
import org.simantics.sysdyn.manager.SysdynDataSet;\r
import org.simantics.sysdyn.manager.SysdynModel;\r
import org.simantics.sysdyn.manager.SysdynModelManager;\r
HashSet<SysdynModel> models = new HashSet<SysdynModel>(); \r
for(Variable variable : variables) {\r
Resource model = Variables.getModel(graph, variable);\r
+ System.out.println("MODEL: " + model);\r
if(model != null) {\r
models.add(getSysdynModel(graph, model));\r
}\r
ArrayList<SysdynDataSet> dataSets = new ArrayList<SysdynDataSet>();\r
HashMap<String, String> rvis = new HashMap<String, String>();\r
\r
- String rvi;\r
- if(variable instanceof ChildVariable) {\r
- ChildVariable var = (ChildVariable)variable;\r
- rvi = var.getRvi(g);\r
- } else if(variable instanceof HistoryVariable) {\r
- HistoryVariable var = (HistoryVariable)variable;\r
- rvi = var.getRvi(g);\r
- } else {\r
- return dataSets;\r
- }\r
- \r
- rvi = rvi.replace("/", ".");\r
+ String rvi = Variables.getRVI(g, variable).substring(1).replace("/", "."); \r
\r
Resource r = variable.getPropertyValue(g, Variables.REPRESENTS);\r
\r
Resource resource = ModelingUtils.getPossibleElementCorrespondendence(g, element);\r
if(resource == null || !g.isInstanceOf(resource, sr.Variable)) return null;\r
String variableURI = g.getPossibleRelatedValue(runtime, dr.HasVariable);\r
- Variable compositeVariable = Variables.getVariable(g, variableURI);\r
try {\r
+ Variable compositeVariable = Variables.getVariable(g, variableURI);\r
return compositeVariable.browsePossible(g, resource);\r
} catch (MissingVariableException e) {\r
return null;\r
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2011 Association for Decentralized Information Management in\r
+ * Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ * VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
package org.simantics.sysdyn.adapter;\r
\r
import java.util.List;\r
import org.simantics.databoard.Datatypes;\r
import org.simantics.databoard.binding.Binding;\r
import org.simantics.databoard.type.Datatype;\r
+import org.simantics.databoard.util.ObjectUtils;\r
import org.simantics.db.ReadGraph;\r
import org.simantics.db.Resource;\r
import org.simantics.db.WriteGraph;\r
import org.simantics.db.common.utils.OrderedSetUtils;\r
import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.db.layer0.variable.StandardGraphChildVariable;\r
+import org.simantics.db.layer0.variable.AbstractChildVariable;\r
import org.simantics.db.layer0.variable.Variable;\r
+import org.simantics.layer0.Layer0;\r
import org.simantics.sysdyn.SysdynResource;\r
\r
-public class ChildVariable extends StandardGraphChildVariable {\r
+public class ChildVariable extends AbstractChildVariable {\r
\r
- final private Variable parent;\r
+ protected Variable parent;\r
+ protected Resource resource;\r
\r
public ChildVariable(Variable parent, Resource resource) {\r
- super(resource);\r
this.parent = parent;\r
- }\r
-\r
- @Override\r
- public Variable getParent(ReadGraph graph) throws DatabaseException {\r
- return parent;\r
+ this.resource = resource;\r
}\r
\r
// FIXME: Support properties! This is just for the system to work like it used to. \r
return super.getInterface(graph, clazz);\r
}\r
\r
- public String getVariableURI(ReadGraph graph) throws DatabaseException {\r
- Variable parent = getParent(graph);\r
- if(parent instanceof ChildVariable) {\r
- ChildVariable p = (ChildVariable)parent;\r
- return p.getVariableURI(graph) + "/" + this.getName(graph);\r
- } else\r
- return parent.getURI(graph) + "/" + this.getName(graph);\r
- }\r
+ /*\r
+ * \r
+ * \r
+ */\r
\r
- public String getRvi(ReadGraph graph) throws DatabaseException {\r
- Variable parent = getParent(graph);\r
- if(parent instanceof ChildVariable) {\r
- ChildVariable p = (ChildVariable)parent;\r
- return p.getRvi(graph) + "/" + this.getName(graph);\r
- } else {\r
- return this.getName(graph);\r
- }\r
+ \r
+ @Override\r
+ public Variable getParent(ReadGraph graph) throws DatabaseException {\r
+ if(parent == null)\r
+ return null; // TODO is this correct thing to do?\r
+ else\r
+ return parent; \r
+ }\r
+ \r
+ @Override\r
+ public Resource getRepresents(ReadGraph graph) throws DatabaseException {\r
+ Layer0 L0 = Layer0.getInstance(graph);\r
+ Resource represents = graph.getPossibleObject(resource, L0.Represents);\r
+ if(represents != null) return represents;\r
+ else return resource;\r
+ }\r
+ \r
+ @Override\r
+ public String getName(ReadGraph graph) throws DatabaseException {\r
+ return graph.getRelatedValue(resource, graph.getService(Layer0.class).HasName, Bindings.STRING);\r
}\r
\r
+ \r
+ @Override\r
+ public String getSerialized(ReadGraph graph) throws DatabaseException {\r
+ return getURI(graph);\r
+ }\r
+ \r
+ @Override\r
+ public String getURI(ReadGraph graph) throws DatabaseException {\r
+ if(parent == null)\r
+ return getName(graph);\r
+ else\r
+ return parent.getURI(graph) + "/" + encodeString(getName(graph));\r
+ }\r
+ \r
+ \r
+ @Override\r
+ public int hashCode() {\r
+ final int prime = 31;\r
+ int result = 1;\r
+ result = prime * result + resource.hashCode();\r
+ result = prime * result + ObjectUtils.hashCode(parent);\r
+ return result;\r
+ }\r
+\r
+ @Override\r
+ public boolean equals(Object obj) {\r
+ if (this == obj)\r
+ return true;\r
+ if (obj == null)\r
+ return false;\r
+ if (getClass() != obj.getClass())\r
+ return false;\r
+ ChildVariable other = (ChildVariable) obj;\r
+ if (!resource.equals(other.resource))\r
+ return false;\r
+ return ObjectUtils.objectEquals(parent, other.parent);\r
+ }\r
+ \r
}\r
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2011 Association for Decentralized Information Management in\r
+ * Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ * VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
package org.simantics.sysdyn.adapter;\r
\r
import org.simantics.db.ReadGraph;\r
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2011 Association for Decentralized Information Management in\r
+ * Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ * VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
package org.simantics.sysdyn.adapter;\r
\r
import java.util.ArrayList;\r
/*******************************************************************************\r
- * Copyright (c) 2010 Association for Decentralized Information Management in\r
+ * Copyright (c) 2007, 2011 Association for Decentralized Information Management in\r
* Industry THTH ry.\r
* All rights reserved. This program and the accompanying materials\r
* are made available under the terms of the Eclipse Public License v1.0\r
import org.simantics.db.common.utils.NameUtils;\r
import org.simantics.db.exception.DatabaseException;\r
import org.simantics.db.layer0.exception.MissingVariableException;\r
-import org.simantics.db.layer0.variable.ResourceVariable;\r
import org.simantics.db.layer0.variable.Variable;\r
import org.simantics.db.layer0.variable.Variables;\r
import org.simantics.layer0.Layer0;\r
import org.simantics.sysdyn.manager.SysdynModelManager;\r
import org.simantics.sysdyn.manager.SysdynResult;\r
\r
-public class HistoryVariable extends ResourceVariable {\r
+public class HistoryVariable extends ChildVariable {\r
\r
- final private Variable parent;\r
- \r
public HistoryVariable(Variable parent, Resource resource) {\r
- super(resource);\r
- this.parent = parent;\r
+ super(parent, resource);\r
}\r
\r
-// @Override\r
-// public <T> T getInterface(ReadGraph graph, Class<T> clazz) throws DatabaseException {\r
-// if(Accessor.class.equals(clazz)) {\r
-//\r
-// SimulationResource SIMU = SimulationResource.getInstance(graph);\r
-// Resource model = Variables.getModel(graph, this);\r
-// Resource configuration = graph.getPossibleObject(model, SIMU.HasConfiguration);\r
-// SysdynModel sm = SysdynModelManager.getInstance(graph.getSession()).getModel(graph, configuration);\r
-// SysdynResult sr = sm.getSysdynResult();\r
-// String rvi = Variables.getRVI(graph, this);\r
-// System.out.println("HistoryVariable rvi='" + rvi + "'");\r
-// rvi = rvi.substring(1).replace("/", ".");\r
-// SysdynDataSet ds = sr.getDataSet(rvi);\r
-// \r
-// try {\r
-// return (T)Accessors.getAccessor(Bindings.getBindingUnchecked(SysdynDataSet.class), ds);\r
-// } catch (RuntimeBindingConstructionException e) {\r
-// e.printStackTrace();\r
-// } catch (AccessorConstructionException e) {\r
-// e.printStackTrace();\r
-// }\r
-// return null;\r
-// \r
-// }\r
-// return super.getInterface(graph, clazz);\r
-// }\r
\r
@SuppressWarnings("unchecked")\r
@Override\r
} else {\r
return super.browseChildren(graph);\r
}\r
- }\r
- \r
- \r
- @Override\r
- public Variable getParent(ReadGraph graph) throws DatabaseException {\r
- return parent;\r
- }\r
- \r
- public String getRvi(ReadGraph graph) throws DatabaseException {\r
- Variable parent = getParent(graph);\r
- if(parent instanceof HistoryVariable) {\r
- HistoryVariable p = (HistoryVariable)parent;\r
- return p.getRvi(graph) + "/" + this.getName(graph);\r
- } else {\r
- return this.getName(graph);\r
- }\r
- }\r
- \r
- final public String getName(ReadGraph graph) throws DatabaseException {\r
- return graph.getRelatedValue(resource, graph.getService(Layer0.class).HasName, Bindings.STRING);\r
- }\r
- \r
+ } \r
}\r
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2011 Association for Decentralized Information Management in\r
+ * Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ * VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
package org.simantics.sysdyn.adapter;\r
\r
import java.util.ArrayList;\r
throw new MissingVariableException("No configuration for " + NameUtils.getSafeName(graph, instanceOf));\r
Map<String, Resource> children = graph.syncRequest(new UnescapedChildMapOfResource(configuration));\r
Resource child = children.get(name);\r
- if(child == null) {\r
- return getPossibleSpecialChild(graph, name);\r
- }\r
- else return graph.adaptContextual(child, this, Variable.class, Variable.class);\r
+ return graph.adaptContextual(child, this, Variable.class, Variable.class);\r
}\r
\r
\r
\r
for(Resource child : graph.syncRequest(new UnescapedChildMapOfResource(configuration)).values())\r
result.add(graph.adaptContextual(child, this, Variable.class, Variable.class));\r
- collectSpecialChildren(graph, result);\r
+ \r
return result;\r
}\r
\r
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2011 Association for Decentralized Information Management in\r
+ * Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ * VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
package org.simantics.sysdyn.adapter;\r
\r
import java.util.ArrayList;\r
\r
import org.simantics.db.ReadGraph;\r
import org.simantics.db.Resource;\r
-import org.simantics.db.common.request.PropertyMapOfResource;\r
import org.simantics.db.common.uri.UnescapedChildMapOfResource;\r
import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.db.layer0.variable.GraphPropertyFactory;\r
import org.simantics.db.layer0.variable.StandardGraphChildVariable;\r
import org.simantics.db.layer0.variable.Variable;\r
import org.simantics.layer0.Layer0;\r