From: lempinen Date: Tue, 28 Aug 2012 08:12:14 +0000 (+0000) Subject: Changed the way terminal relations are created for new module types. The old way... X-Git-Tag: simantics-1.7~4^2~16 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=263567ced86e8d3cfeb16d2b9f0c739164a44309;p=simantics%2Fsysdyn.git Changed the way terminal relations are created for new module types. The old way was to modify existing terminal relations, but now they are immutable, so new subrelations need to be created. (refs #3530) git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@25526 ac1ea38d-2e2b-0410-8846-a27921b304fc --- diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/actions/newActions/NewModuleTypeAction.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/actions/newActions/NewModuleTypeAction.java index 8b400bde..0bc57509 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/actions/newActions/NewModuleTypeAction.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/actions/newActions/NewModuleTypeAction.java @@ -41,12 +41,12 @@ public class NewModuleTypeAction implements ActionFactory{ if(!(target instanceof Resource)) return null; final Resource model = (Resource)target; - + return new Runnable() { @Override public void run() { SimanticsUI.getSession().asyncRequest(new WriteRequest() { - + @Override public void perform(WriteGraph g) throws DatabaseException { SysdynResource sr = SysdynResource.getInstance(g); @@ -54,83 +54,109 @@ public class NewModuleTypeAction implements ActionFactory{ Layer0X L0X = Layer0X.getInstance(g); ModelingResources mr = ModelingResources.getInstance(g); StructuralResource2 sr2 = StructuralResource2.getInstance(g); - + String name = NameUtils.findFreshName(g, "ModuleType", model, l0.ConsistsOf, "%s%d"); - + Resource moduleType = g.newResource(); g.claimLiteral(moduleType, l0.HasName, name); g.claim(moduleType, l0.Inherits, sr.Module); g.claim(moduleType, l0.PartOf, model); - - - + + + Resource configuration = GraphUtils.create2(g, sr.Configuration, l0.HasName, name + "Configuration", l0.PartOf, moduleType); - + g.claim(moduleType, sr2.IsDefinedBy , configuration); - + Resource diagram = g.newResource(); g.adapt(sr.ConfigurationDiagramTemplate, Template.class).apply(g, ArrayMap .keys("", "diagram", "name") .values(configuration, diagram, "Diagrammi") - ); - - + ); + + // Remove default mapping and add sysdyn mapping for(Resource trigger : g.getObjects(diagram, L0X.HasTrigger)) { if(g.isInstanceOf(trigger, mr.DiagramToCompositeMapping)) { g.deny(diagram, L0X.HasTrigger, trigger); } } - + GraphUtils.create2(g, sr.Validations_Dependencies_MissingDependencyConnectionsIssueSource, L0X.IsActivatedBy, model, l0.PartOf, moduleType ); - + GraphUtils.create2(g, sr.Validations_Dependencies_DependencyConnectionsIssueSource, L0X.IsActivatedBy, model, l0.PartOf, moduleType ); - + GraphUtils.create2(g, sr.Validations_Expressions_ExpressionIssueSource, L0X.IsActivatedBy, model, l0.PartOf, moduleType ); - + Resource mapping = g.newResource(); g.claim(mapping, l0.InstanceOf, null, sr.DiagramToCompositeMapping); g.claim(diagram, L0X.HasTrigger, mapping); - + Resource moduleSymbol = g.newResource(); g.claimLiteral(moduleSymbol, l0.HasName, name + " Symbol"); g.claimLiteral(moduleSymbol, l0.HasLabel, name + " Symbol"); g.claim(moduleSymbol, l0.Inherits, sr.ModuleSymbol); g.claim(moduleSymbol, mr.SymbolToComponentType, moduleType); g.claim(moduleSymbol, l0.PartOf, moduleType); - + Resource terminal = g.newResource(); g.claim(terminal, l0.InstanceOf, sr.SysdynTerminal); - DiagramGraphUtil.addConnectionPoint(g, moduleSymbol, terminal, sr.IsHeadOfTerminal); - + Resource relation = createTerminalRelation(g, moduleSymbol, sr.IsHeadOfTerminal, sr.Variable_isHeadOf); + DiagramGraphUtil.addConnectionPoint(g, moduleSymbol, terminal, relation); + Resource terminal2 = g.newResource(); g.claim(terminal2, l0.InstanceOf, sr.SysdynTerminal); - DiagramGraphUtil.addConnectionPoint(g, moduleSymbol, terminal2, sr.IsTailOfTerminal); - + relation = createTerminalRelation(g, moduleSymbol, sr.IsTailOfTerminal, sr.Variable_isTailOf); + DiagramGraphUtil.addConnectionPoint(g, moduleSymbol, terminal2, relation); + g.claim(moduleSymbol, sr2.IsDefinedBy, OrderedSetUtils.create(g, sr2.Composite, terminal, terminal2)); - - - + + + } }); } }; } + public static Resource createTerminalRelation(WriteGraph graph, Resource symbol, Resource connectionRelation, Resource configurationRelation) throws DatabaseException { + StructuralResource2 STR = StructuralResource2.getInstance(graph); + ModelingResources MOD = ModelingResources.getInstance(graph); + Layer0 L0 = Layer0.getInstance(graph); + + + Resource terminalRelation = null; + terminalRelation = GraphUtils.create(graph, + MOD.DiagramConnectionRelationToConnectionRelation, configurationRelation, + L0.PartOf, symbol, + L0.HasName, NameUtils.getSafeName(graph, connectionRelation) + ); + + graph.claim(terminalRelation, L0.SubrelationOf, null, connectionRelation); + Resource inverse = GraphUtils.create(graph, + L0.PartOf, terminalRelation, + L0.HasName, "Inverse"); + + graph.claim(inverse, L0.SubrelationOf, null, STR.Connects); + graph.claim(terminalRelation, L0.InverseOf, inverse); + + return terminalRelation; + } + } diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/SysdynConnectionAdvisor.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/SysdynConnectionAdvisor.java index 81e70e1f..ffcfd38e 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/SysdynConnectionAdvisor.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/SysdynConnectionAdvisor.java @@ -79,19 +79,26 @@ public class SysdynConnectionAdvisor implements IConnectionAdvisor { if(element1 != null && term1 != null && element2 != null && term2 != null) { StaticObjectAdapter soa = element1.getElementClass().getSingleItem(StaticObjectAdapter.class); Resource startElementResource = soa.adapt(Resource.class); - soa = element2.getElementClass().getSingleItem(StaticObjectAdapter.class); - Resource endElementResource = soa.adapt(Resource.class); + Object r = ElementUtils.getObject(element2); + if(r == null || !(r instanceof Resource)) + return null; + Resource endElementResource = (Resource) r; DiagramResource dr = DiagramResource.getInstance(g); Resource terminal2 = ((ResourceTerminal) term2).getResource(); SysdynResource sr = SysdynResource.getInstance(g); + + + // Chech that end terminal has IsHeadOfTerminal relation + Resource connectionPoint = g.getPossibleObject(terminal2, dr.HasConnectionPoint); + if(connectionPoint == null || !g.isSubrelationOf(connectionPoint, sr.IsHeadOfTerminal)) { + return null; + } - if(!g.hasStatement(terminal2, dr.HasConnectionPoint, sr.IsHeadOfTerminal)) { - return null; - } + // If end element is input symbol, allow only one connection and only from a module if(g.isInstanceOf(endElementResource, sr.InputSymbol)) { - if(g.isInheritedFrom(startElementResource, sr.ModuleSymbol)) return null; + if(!g.isInheritedFrom(startElementResource, sr.ModuleSymbol)) return null; if(g.getObjects(endElementResource, sr.IsHeadOfTerminal).size() > 0) return null; } diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewModuleNodeHandler.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewModuleNodeHandler.java index 4c16319b..6bfc3767 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewModuleNodeHandler.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewModuleNodeHandler.java @@ -23,7 +23,6 @@ import org.simantics.db.common.utils.NameUtils; import org.simantics.db.common.utils.OrderedSetUtils; import org.simantics.db.exception.DatabaseException; import org.simantics.db.layer0.adapter.Template; -import org.simantics.diagram.stubs.DiagramResource; import org.simantics.diagram.synchronization.graph.DiagramGraphUtil; import org.simantics.layer0.Layer0; import org.simantics.layer0.utils.direct.GraphUtils; @@ -31,6 +30,7 @@ import org.simantics.modeling.ModelingResources; import org.simantics.operation.Layer0X; import org.simantics.structural.stubs.StructuralResource2; import org.simantics.sysdyn.SysdynResource; +import org.simantics.sysdyn.ui.browser.actions.newActions.NewModuleTypeAction; import org.simantics.sysdyn.ui.browser.nodes.ModulesNode; import org.simantics.ui.SimanticsUI; import org.simantics.ui.utils.AdaptionUtils; @@ -67,7 +67,6 @@ public class NewModuleNodeHandler extends AbstractHandler { Layer0X L0X = Layer0X.getInstance(g); ModelingResources mr = ModelingResources.getInstance(g); StructuralResource2 sr2 = StructuralResource2.getInstance(g); - DiagramResource dr = DiagramResource.getInstance(g); String name = NameUtils.findFreshName(g, "ModuleType", model, l0.ConsistsOf, "%s%d"); @@ -131,11 +130,13 @@ public class NewModuleNodeHandler extends AbstractHandler { Resource terminal = g.newResource(); g.claim(terminal, l0.InstanceOf, sr.SysdynTerminal); - DiagramGraphUtil.addConnectionPoint(g, moduleSymbol, terminal, sr.IsHeadOfTerminal); + Resource relation = NewModuleTypeAction.createTerminalRelation(g, moduleSymbol, sr.IsHeadOfTerminal, sr.Variable_isHeadOf); + DiagramGraphUtil.addConnectionPoint(g, moduleSymbol, terminal, relation); Resource terminal2 = g.newResource(); g.claim(terminal2, l0.InstanceOf, sr.SysdynTerminal); - DiagramGraphUtil.addConnectionPoint(g, moduleSymbol, terminal2, sr.IsTailOfTerminal); + relation = NewModuleTypeAction.createTerminalRelation(g, moduleSymbol, sr.IsTailOfTerminal, sr.Variable_isTailOf); + DiagramGraphUtil.addConnectionPoint(g, moduleSymbol, terminal2, relation); g.claim(moduleSymbol, sr2.IsDefinedBy, OrderedSetUtils.create(g, sr2.Composite, terminal, terminal2)); @@ -144,6 +145,6 @@ public class NewModuleNodeHandler extends AbstractHandler { }); return null; } - + }