id="org.simantics.sysdyn.ui.browser.newModule"\r
label="Module"\r
style="push">\r
+ <visibleWhen\r
+ checkEnabled="true">\r
+ <with\r
+ variable="selection">\r
+ <test\r
+ args="org.simantics.sysdyn.ui.browser.nodes.ModulesNode"\r
+ property="org.simantics.sysdyn.ui.nodeClass">\r
+ </test>\r
+ </with>\r
+ </visibleWhen>\r
</command>\r
<command\r
commandId="org.simantics.sysdyn.ui.newExperiment"\r
preference="1.0">\r
</implementation>\r
<implementation\r
- class="org.simantics.sysdyn.ui.browser.contributions.Model"\r
+ class="org.simantics.sysdyn.ui.browser.contributions.Project"\r
preference="1.0">\r
</implementation>\r
<implementation\r
preference="1.0">\r
</implementation>\r
<implementation\r
- class="org.simantics.sysdyn.ui.browser.contributions.ModelChildren"\r
+ class="org.simantics.sysdyn.ui.browser.contributions.Model"\r
preference="2.0">\r
</implementation>\r
<implementation\r
class="org.simantics.sysdyn.ui.browser.contributions.InputLabeler"\r
preference="2.0">\r
</implementation>\r
+ <implementation\r
+ class="org.simantics.sysdyn.ui.browser.contributions.ModuleTypeLabeler"\r
+ preference="2.0">\r
+ </implementation>\r
</binding>\r
</extension>\r
<extension\r
\r
import java.util.ArrayList;\r
import java.util.Collection;\r
-\r
import org.simantics.browsing.ui.graph.contributor.viewpoint.ViewpointContributor;\r
-import org.simantics.db.Builtins;\r
import org.simantics.db.ReadGraph;\r
-import org.simantics.db.Resource;\r
-import org.simantics.db.common.request.ObjectsWithType;\r
import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.sysdyn.SysdynResource;\r
import org.simantics.sysdyn.ui.browser.nodes.AbstractNode;\r
+import org.simantics.sysdyn.ui.browser.nodes.ConfigurationNode;\r
+import org.simantics.sysdyn.ui.browser.nodes.ExperimentsFolder;\r
+import org.simantics.sysdyn.ui.browser.nodes.ModelNode;\r
import org.simantics.sysdyn.ui.browser.nodes.ModulesNode;\r
+import org.simantics.sysdyn.ui.browser.nodes.OperatingInterfacesFolder;\r
\r
-public class Model extends ViewpointContributor<Resource> {\r
+public class Model extends ViewpointContributor<ModelNode> {\r
\r
@Override\r
- public Collection<?> getContribution(ReadGraph graph, Resource project)\r
+ public Collection<?> getContribution(ReadGraph graph, ModelNode model)\r
throws DatabaseException {\r
-\r
ArrayList<AbstractNode> result = new ArrayList<AbstractNode>();\r
- Builtins b = graph.getBuiltins();\r
- SysdynResource sr = SysdynResource.getInstance(graph);\r
- for(Resource r : graph.syncRequest(new ObjectsWithType(project, b.ConsistsOf, sr.SysdynModel))) {\r
- try {\r
- result.add(graph.adapt(r, AbstractNode.class));\r
- } catch(DatabaseException e) {\r
- e.printStackTrace();\r
- }\r
- }\r
- result.add(new ModulesNode(project));\r
+ result.add(new ConfigurationNode(\r
+ graph.getSingleObject(\r
+ model.resource, \r
+ graph.getBuiltins().HasConfiguration))\r
+ );\r
+ result.add(new ExperimentsFolder(model.resource));\r
+ result.add(new OperatingInterfacesFolder(model.resource));\r
+ result.add(new ModulesNode(model.resource));\r
return result;\r
-\r
}\r
\r
@Override\r
public String getViewpointId() {\r
return "Standard";\r
}\r
- \r
}\r
+++ /dev/null
-package org.simantics.sysdyn.ui.browser.contributions;\r
-\r
-import java.util.ArrayList;\r
-import java.util.Collection;\r
-import org.simantics.browsing.ui.graph.contributor.viewpoint.ViewpointContributor;\r
-import org.simantics.db.ReadGraph;\r
-import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.sysdyn.ui.browser.nodes.AbstractNode;\r
-import org.simantics.sysdyn.ui.browser.nodes.ConfigurationNode;\r
-import org.simantics.sysdyn.ui.browser.nodes.ExperimentsFolder;\r
-import org.simantics.sysdyn.ui.browser.nodes.ModelNode;\r
-import org.simantics.sysdyn.ui.browser.nodes.OperatingInterfacesFolder;\r
-\r
-public class ModelChildren extends ViewpointContributor<ModelNode> {\r
-\r
- @Override\r
- public Collection<?> getContribution(ReadGraph graph, ModelNode model)\r
- throws DatabaseException {\r
- ArrayList<AbstractNode> result = new ArrayList<AbstractNode>();\r
- result.add(new ConfigurationNode(\r
- graph.getSingleObject(\r
- model.resource, \r
- graph.getBuiltins().HasConfiguration))\r
- );\r
- result.add(new ExperimentsFolder(model.resource));\r
- result.add(new OperatingInterfacesFolder(model.resource));\r
- return result;\r
- }\r
-\r
- @Override\r
- public String getViewpointId() {\r
- return "Standard";\r
- }\r
-}\r
Builtins b = graph.getBuiltins();\r
Resource resource = module.resource;\r
StringBuilder sb = new StringBuilder();\r
- for(Resource r : graph.getObjects(resource, b.HasLabel))\r
- sb.append(graph.getValue(r));\r
- sb.append(" : ");\r
for(Resource r : graph.getObjects(resource, b.HasName))\r
sb.append(graph.getValue(r));\r
sb.append(" : ");\r
--- /dev/null
+package org.simantics.sysdyn.ui.browser.contributions;\r
+\r
+import org.simantics.browsing.ui.graph.contributor.labeler.LabelerContributor;\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.sysdyn.ui.browser.nodes.ModuleTypeNode;\r
+\r
+public class ModuleTypeLabeler extends LabelerContributor<ModuleTypeNode>{\r
+\r
+ @Override\r
+ public String getLabel(ReadGraph graph, ModuleTypeNode moduleType) throws DatabaseException {\r
+ String label = graph.getPossibleRelatedValue(moduleType.resource, graph.getBuiltins().HasLabel);\r
+ return label == null ? "Model (no name)" : label;\r
+ }\r
+\r
+}\r
public class Modules extends ViewpointContributor<ModulesNode> {\r
\r
@Override\r
- public Collection<?> getContribution(ReadGraph graph, ModulesNode project)\r
+ public Collection<?> getContribution(ReadGraph graph, ModulesNode model)\r
throws DatabaseException {\r
\r
ArrayList<AbstractNode> result = new ArrayList<AbstractNode>();\r
Builtins b = graph.getBuiltins();\r
StructuralResource2 st = StructuralResource2.getInstance(graph);\r
- for(Resource r : graph.syncRequest(new ObjectsWithType(project.resource, b.IsRelatedTo, st.ComponentType))) {\r
+ for(Resource r : graph.syncRequest(new ObjectsWithType(model.resource, b.ConsistsOf, st.ComponentType))) {\r
result.add(new ModuleTypeNode(r));\r
}\r
return result;\r
--- /dev/null
+package org.simantics.sysdyn.ui.browser.contributions;\r
+\r
+import java.util.ArrayList;\r
+import java.util.Collection;\r
+\r
+import org.simantics.browsing.ui.graph.contributor.viewpoint.ViewpointContributor;\r
+import org.simantics.db.Builtins;\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.common.request.ObjectsWithType;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.sysdyn.SysdynResource;\r
+import org.simantics.sysdyn.ui.browser.nodes.AbstractNode;\r
+\r
+public class Project extends ViewpointContributor<Resource> {\r
+\r
+ @Override\r
+ public Collection<?> getContribution(ReadGraph graph, Resource project)\r
+ throws DatabaseException {\r
+\r
+ ArrayList<AbstractNode> result = new ArrayList<AbstractNode>();\r
+ Builtins b = graph.getBuiltins();\r
+ SysdynResource sr = SysdynResource.getInstance(graph);\r
+ for(Resource r : graph.syncRequest(new ObjectsWithType(project, b.ConsistsOf, sr.SysdynModel))) {\r
+ try {\r
+ result.add(graph.adapt(r, AbstractNode.class));\r
+ } catch(DatabaseException e) {\r
+ e.printStackTrace();\r
+ }\r
+ }\r
+ return result;\r
+\r
+ }\r
+\r
+ @Override\r
+ public String getViewpointId() {\r
+ return "Standard";\r
+ }\r
+ \r
+}\r
import org.eclipse.core.commands.AbstractHandler;\r
import org.eclipse.core.commands.ExecutionEvent;\r
import org.eclipse.core.commands.ExecutionException;\r
+import org.eclipse.jface.viewers.ISelection;\r
+import org.eclipse.ui.handlers.HandlerUtil;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.WriteGraph;\r
+import org.simantics.db.common.request.WriteRequest;\r
+import org.simantics.db.common.utils.OrderedSetUtils;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.diagram.DiagramConstants;\r
+import org.simantics.diagram.synchronization.graph.layer.GraphLayer;\r
+import org.simantics.diagram.synchronization.graph.layer.GraphLayerUtil;\r
+import org.simantics.layer0.utils.direct.GraphUtils;\r
+import org.simantics.modeling.ModelingUtils;\r
+import org.simantics.sysdyn.SysdynResource;\r
+import org.simantics.ui.SimanticsUI;\r
+import org.simantics.ui.utils.ResourceAdaptionUtils;\r
\r
public class NewModuleNodeHandler extends AbstractHandler {\r
\r
@Override\r
public Object execute(ExecutionEvent event) throws ExecutionException {\r
- System.out.println("New module!");\r
+ \r
+ ISelection sel = HandlerUtil.getCurrentSelection(event);\r
+ Resource[] resources = ResourceAdaptionUtils.toResources(sel);\r
+ if (resources.length != 1)\r
+ return null;\r
+ \r
+ final Resource model = resources[0];\r
+ \r
+ SimanticsUI.getSession().asyncRequest(new WriteRequest() {\r
+ \r
+ @Override\r
+ public void perform(WriteGraph g) throws DatabaseException {\r
+ // Same as in SysdynProject.java. Should use the same code, not copy.\r
+ SysdynResource sr = SysdynResource.getInstance(g);\r
+ ModelingUtils mu = new ModelingUtils(g);\r
+ \r
+ Resource moduleType = g.newResource();\r
+ g.claimValue(moduleType, mu.b.HasName, "ModuleType");\r
+ g.claimValue(moduleType, mu.b.HasLabel, "ModuleTypeLabel");\r
+ g.claim(moduleType, mu.b.Inherits, sr.Module);\r
+ g.claim(moduleType, mu.b.PartOf, model);\r
+ \r
+ Resource diagram = OrderedSetUtils.create(g, sr.ConfigurationDiagram);\r
+ GraphLayer l = new GraphLayerUtil(g).createLayer(DiagramConstants.DEFAULT_LAYER_NAME, true);\r
+ g.claim(diagram, mu.dr.HasLayer, l.getLayer());\r
+ Resource mapping = g.newResource();\r
+ g.claim(mapping, mu.b.InstanceOf, null, sr.DiagramToCompositeMapping);\r
+ g.claim(diagram, mu.b.HasTrigger, mapping);\r
+\r
+ \r
+ Resource configuration = GraphUtils.create2(g, \r
+ sr.Configuration,\r
+ mu.mr.CompositeToDiagram, diagram);\r
+ \r
+ g.claim(moduleType, mu.sr.IsDefinedBy , configuration);\r
+ \r
+ \r
+ Resource moduleSymbol = g.newResource();\r
+ g.claimValue(moduleSymbol, mu.b.HasName, "ModuuliSymboli");\r
+ g.claimValue(moduleSymbol, mu.b.HasLabel, "ModuuliSymboliLabel");\r
+ g.claim(moduleSymbol, mu.b.Inherits, sr.ModuleSymbol);\r
+ g.claim(moduleSymbol, mu.mr.SymbolToComponentType, moduleType);\r
+ \r
+ Resource terminal = g.newResource();\r
+ g.claim(terminal, mu.b.InstanceOf, sr.SysdynTerminal);\r
+ Resource connectionVariable = g.newResource();\r
+ g.claim(connectionVariable, mu.b.InstanceOf, mu.sr.ConnectionVariable);\r
+ g.claim(connectionVariable, mu.sr.Binds, sr.IsHeadOfTerminal);\r
+ g.claim(connectionVariable, mu.sr.IsParameterOf, sr.ModuleSymbol);\r
+ g.claim(terminal, mu.dr.HasConnectionVariable, connectionVariable);\r
+ \r
+ \r
+ Resource terminal2 = g.newResource();\r
+ g.claim(terminal2, mu.b.InstanceOf, sr.SysdynTerminal);\r
+ Resource connectionVariable2 = g.newResource();\r
+ g.claim(connectionVariable2, mu.b.InstanceOf, mu.sr.ConnectionVariable);\r
+ g.claim(connectionVariable2, mu.sr.Binds, sr.IsTailOfTerminal);\r
+ g.claim(connectionVariable2, mu.sr.IsParameterOf, sr.ModuleSymbol);\r
+ g.claim(terminal2, mu.dr.HasConnectionVariable, connectionVariable2);\r
+ \r
+ g.claim(moduleSymbol, mu.sr.IsDefinedBy, OrderedSetUtils.create(g, mu.sr.Composite, terminal, terminal2));\r
+ \r
+ \r
+ }\r
+ });\r
return null;\r
}\r
\r
} else if (element instanceof Module) {\r
Module m = (Module)element; \r
modules.add(m);\r
- moduleInputs.put(m.getLabel(), new ArrayList<Input>());\r
+ moduleInputs.put(m.getName(), new ArrayList<Input>());\r
for(IElement e : m.getType().getConfiguration().getElements())\r
if(e instanceof Input && !((Input)e).isHeadOfDependency()) {\r
- moduleInputs.get(m.getLabel()).add((Input)e);\r
+ moduleInputs.get(m.getName()).add((Input)e);\r
}\r
} else if (element instanceof Input) {\r
inputs.add((Input)element);\r
if(!modules.isEmpty()) {\r
b.append("// Module definitions\n");\r
for(Module m : modules) {\r
- b.append(" " + m.getType().getName() + " " + m.getLabel() + ";\n");\r
+ b.append(" " + m.getType().getName() + " " + m.getName() + ";\n");\r
}\r
}\r
\r
Input variable = (Input)dependency.getHead();\r
Module module = (Module)dependency.getTail();\r
Variable reference = (Variable)dependency.refersTo();\r
- b.append(" " + variable.getName() + " = " + module.getLabel() + "." + reference.getName() + ";\n");\r
+ b.append(" " + variable.getName() + " = " + module.getName() + "." + reference.getName() + ";\n");\r
}\r
\r
b.append("// Outputs\n");\r
Variable variable = (Variable)dependency.getTail();\r
Module module = (Module)dependency.getHead();\r
Input reference = (Input)dependency.refersTo();\r
- b.append(" " + module.getLabel() + "." + reference.getName() + " = " + variable.getName() + ";\n");\r
- moduleInputs.get(module.getLabel()).remove(reference);\r
+ b.append(" " + module.getName() + "." + reference.getName() + " = " + variable.getName() + ";\n");\r
+ moduleInputs.get(module.getName()).remove(reference);\r
}\r
\r
b.append("// Default values for inputs in modules\n");\r
@RelatedValue("http://www.simantics.org/Layer0-1.0/HasName")\r
private String name;\r
\r
- @RelatedValue("http://www.simantics.org/Layer0-1.0/HasLabel")\r
- private String label;\r
-\r
@RelatedElement("http://www.simantics.org/Layer0-1.0/PartOf")\r
private Configuration parentConfiguration;\r
\r
public String getName() {\r
return name;\r
}\r
-\r
-\r
- public String getLabel() {\r
- return label;\r
- }\r
\r
public ModuleType getType() {\r
return type;\r
_ @ "CustomerModel" : SysdynModel\r
L0.HasLabel "Asiakasmalli" : L0.String\r
L0.PartOf SysdynModuleTestProject\r
- L0.ConsistsOf _ @ "Experiment" : Experiment\r
- L0.HasLabel "Experiment" : L0.String\r
SIMU.HasConfiguration RootConfiguration\r
- L0.ConsistsOf RootConfiguration\r
+ L0.ConsistsOf \r
+ _ @ "Experiment" : Experiment\r
+ L0.HasLabel "Experiment" : L0.String\r
+ CustomerModule\r
+ CapacityModule \r
+ RootConfiguration \r
\r
# Layerit ja connectiontype!\r
\r
_ : DependencyConnection\r
MOD.DiagramConnectionToConnection Dependency36\r
dep(PotentialCustomerConcentrationElement, PotentialCustomersStockElement, "-0.1") \r
- \r
-SysdynModuleTestProject\r
- L0.IsRelatedTo CustomerModule\r
- L0.IsRelatedTo CapacityModule\r
-\r