if(!(target instanceof Resource))\r
return null;\r
final Resource model = (Resource)target;\r
- \r
+\r
return new Runnable() {\r
@Override\r
public void run() {\r
SimanticsUI.getSession().asyncRequest(new WriteRequest() {\r
- \r
+\r
@Override\r
public void perform(WriteGraph g) throws DatabaseException {\r
SysdynResource sr = SysdynResource.getInstance(g);\r
Layer0X L0X = Layer0X.getInstance(g);\r
ModelingResources mr = ModelingResources.getInstance(g);\r
StructuralResource2 sr2 = StructuralResource2.getInstance(g);\r
- \r
+\r
String name = NameUtils.findFreshName(g, "ModuleType", model, l0.ConsistsOf, "%s%d");\r
- \r
+\r
Resource moduleType = g.newResource();\r
g.claimLiteral(moduleType, l0.HasName, name);\r
g.claim(moduleType, l0.Inherits, sr.Module);\r
g.claim(moduleType, l0.PartOf, model);\r
- \r
- \r
- \r
+\r
+\r
+\r
Resource configuration = GraphUtils.create2(g, \r
sr.Configuration,\r
l0.HasName, name + "Configuration",\r
l0.PartOf, moduleType);\r
- \r
+\r
g.claim(moduleType, sr2.IsDefinedBy , configuration);\r
- \r
+\r
Resource diagram = g.newResource();\r
g.adapt(sr.ConfigurationDiagramTemplate, Template.class).apply(g,\r
ArrayMap\r
.keys("", "diagram", "name")\r
.values(configuration, diagram, "Diagrammi")\r
- );\r
- \r
- \r
+ );\r
+\r
+\r
// Remove default mapping and add sysdyn mapping\r
for(Resource trigger : g.getObjects(diagram, L0X.HasTrigger)) {\r
if(g.isInstanceOf(trigger, mr.DiagramToCompositeMapping)) {\r
g.deny(diagram, L0X.HasTrigger, trigger);\r
}\r
}\r
- \r
+\r
GraphUtils.create2(g,\r
sr.Validations_Dependencies_MissingDependencyConnectionsIssueSource,\r
L0X.IsActivatedBy, model,\r
l0.PartOf, moduleType\r
);\r
- \r
+\r
GraphUtils.create2(g,\r
sr.Validations_Dependencies_DependencyConnectionsIssueSource,\r
L0X.IsActivatedBy, model,\r
l0.PartOf, moduleType\r
);\r
- \r
+\r
GraphUtils.create2(g,\r
sr.Validations_Expressions_ExpressionIssueSource,\r
L0X.IsActivatedBy, model,\r
l0.PartOf, moduleType\r
);\r
- \r
+\r
Resource mapping = g.newResource();\r
g.claim(mapping, l0.InstanceOf, null, sr.DiagramToCompositeMapping);\r
g.claim(diagram, L0X.HasTrigger, mapping);\r
- \r
+\r
Resource moduleSymbol = g.newResource();\r
g.claimLiteral(moduleSymbol, l0.HasName, name + " Symbol");\r
g.claimLiteral(moduleSymbol, l0.HasLabel, name + " Symbol");\r
g.claim(moduleSymbol, l0.Inherits, sr.ModuleSymbol);\r
g.claim(moduleSymbol, mr.SymbolToComponentType, moduleType);\r
g.claim(moduleSymbol, l0.PartOf, moduleType);\r
- \r
+\r
Resource terminal = g.newResource();\r
g.claim(terminal, l0.InstanceOf, sr.SysdynTerminal);\r
- DiagramGraphUtil.addConnectionPoint(g, moduleSymbol, terminal, sr.IsHeadOfTerminal); \r
- \r
+ Resource relation = createTerminalRelation(g, moduleSymbol, sr.IsHeadOfTerminal, sr.Variable_isHeadOf);\r
+ DiagramGraphUtil.addConnectionPoint(g, moduleSymbol, terminal, relation); \r
+\r
Resource terminal2 = g.newResource();\r
g.claim(terminal2, l0.InstanceOf, sr.SysdynTerminal);\r
- DiagramGraphUtil.addConnectionPoint(g, moduleSymbol, terminal2, sr.IsTailOfTerminal);\r
- \r
+ relation = createTerminalRelation(g, moduleSymbol, sr.IsTailOfTerminal, sr.Variable_isTailOf);\r
+ DiagramGraphUtil.addConnectionPoint(g, moduleSymbol, terminal2, relation);\r
+\r
g.claim(moduleSymbol, sr2.IsDefinedBy, OrderedSetUtils.create(g, sr2.Composite, terminal, terminal2));\r
- \r
- \r
- \r
+\r
+\r
+\r
}\r
});\r
}\r
};\r
}\r
\r
+ public static Resource createTerminalRelation(WriteGraph graph, Resource symbol, Resource connectionRelation, Resource configurationRelation) throws DatabaseException {\r
+ StructuralResource2 STR = StructuralResource2.getInstance(graph);\r
+ ModelingResources MOD = ModelingResources.getInstance(graph);\r
+ Layer0 L0 = Layer0.getInstance(graph);\r
+\r
+\r
+ Resource terminalRelation = null;\r
+ terminalRelation = GraphUtils.create(graph,\r
+ MOD.DiagramConnectionRelationToConnectionRelation, configurationRelation,\r
+ L0.PartOf, symbol,\r
+ L0.HasName, NameUtils.getSafeName(graph, connectionRelation)\r
+ );\r
+\r
+ graph.claim(terminalRelation, L0.SubrelationOf, null, connectionRelation);\r
+ Resource inverse = GraphUtils.create(graph,\r
+ L0.PartOf, terminalRelation, \r
+ L0.HasName, "Inverse");\r
+\r
+ graph.claim(inverse, L0.SubrelationOf, null, STR.Connects);\r
+ graph.claim(terminalRelation, L0.InverseOf, inverse);\r
+\r
+ return terminalRelation;\r
+ }\r
+\r
}\r
if(element1 != null && term1 != null && element2 != null && term2 != null) {\r
StaticObjectAdapter soa = element1.getElementClass().getSingleItem(StaticObjectAdapter.class);\r
Resource startElementResource = soa.adapt(Resource.class);\r
- soa = element2.getElementClass().getSingleItem(StaticObjectAdapter.class);\r
- Resource endElementResource = soa.adapt(Resource.class);\r
+ Object r = ElementUtils.getObject(element2);\r
+ if(r == null || !(r instanceof Resource))\r
+ return null;\r
+ Resource endElementResource = (Resource) r;\r
\r
DiagramResource dr = DiagramResource.getInstance(g);\r
Resource terminal2 = ((ResourceTerminal) term2).getResource();\r
SysdynResource sr = SysdynResource.getInstance(g);\r
+ \r
+ \r
+ // Chech that end terminal has IsHeadOfTerminal relation\r
+ Resource connectionPoint = g.getPossibleObject(terminal2, dr.HasConnectionPoint);\r
+ if(connectionPoint == null || !g.isSubrelationOf(connectionPoint, sr.IsHeadOfTerminal)) {\r
+ return null;\r
+ }\r
\r
- if(!g.hasStatement(terminal2, dr.HasConnectionPoint, sr.IsHeadOfTerminal)) {\r
- return null;\r
- }\r
\r
+ // If end element is input symbol, allow only one connection and only from a module\r
if(g.isInstanceOf(endElementResource, sr.InputSymbol)) {\r
- if(g.isInheritedFrom(startElementResource, sr.ModuleSymbol)) return null;\r
+ if(!g.isInheritedFrom(startElementResource, sr.ModuleSymbol)) return null;\r
if(g.getObjects(endElementResource, sr.IsHeadOfTerminal).size() > 0) return null;\r
}\r
\r
import org.simantics.db.common.utils.OrderedSetUtils;\r
import org.simantics.db.exception.DatabaseException;\r
import org.simantics.db.layer0.adapter.Template;\r
-import org.simantics.diagram.stubs.DiagramResource;\r
import org.simantics.diagram.synchronization.graph.DiagramGraphUtil;\r
import org.simantics.layer0.Layer0;\r
import org.simantics.layer0.utils.direct.GraphUtils;\r
import org.simantics.operation.Layer0X;\r
import org.simantics.structural.stubs.StructuralResource2;\r
import org.simantics.sysdyn.SysdynResource;\r
+import org.simantics.sysdyn.ui.browser.actions.newActions.NewModuleTypeAction;\r
import org.simantics.sysdyn.ui.browser.nodes.ModulesNode;\r
import org.simantics.ui.SimanticsUI;\r
import org.simantics.ui.utils.AdaptionUtils;\r
Layer0X L0X = Layer0X.getInstance(g);\r
ModelingResources mr = ModelingResources.getInstance(g);\r
StructuralResource2 sr2 = StructuralResource2.getInstance(g);\r
- DiagramResource dr = DiagramResource.getInstance(g);\r
\r
String name = NameUtils.findFreshName(g, "ModuleType", model, l0.ConsistsOf, "%s%d");\r
\r
\r
Resource terminal = g.newResource();\r
g.claim(terminal, l0.InstanceOf, sr.SysdynTerminal);\r
- DiagramGraphUtil.addConnectionPoint(g, moduleSymbol, terminal, sr.IsHeadOfTerminal); \r
+ Resource relation = NewModuleTypeAction.createTerminalRelation(g, moduleSymbol, sr.IsHeadOfTerminal, sr.Variable_isHeadOf);\r
+ DiagramGraphUtil.addConnectionPoint(g, moduleSymbol, terminal, relation); \r
\r
Resource terminal2 = g.newResource();\r
g.claim(terminal2, l0.InstanceOf, sr.SysdynTerminal);\r
- DiagramGraphUtil.addConnectionPoint(g, moduleSymbol, terminal2, sr.IsTailOfTerminal);\r
+ relation = NewModuleTypeAction.createTerminalRelation(g, moduleSymbol, sr.IsTailOfTerminal, sr.Variable_isTailOf);\r
+ DiagramGraphUtil.addConnectionPoint(g, moduleSymbol, terminal2, relation);\r
\r
g.claim(moduleSymbol, sr2.IsDefinedBy, OrderedSetUtils.create(g, sr2.Composite, terminal, terminal2));\r
\r
});\r
return null;\r
}\r
-\r
+ \r
\r
}\r