]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
Changed the way terminal relations are created for new module types. The old way...
authorlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Tue, 28 Aug 2012 08:12:14 +0000 (08:12 +0000)
committerlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Tue, 28 Aug 2012 08:12:14 +0000 (08:12 +0000)
git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@25526 ac1ea38d-2e2b-0410-8846-a27921b304fc

org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/actions/newActions/NewModuleTypeAction.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/SysdynConnectionAdvisor.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewModuleNodeHandler.java

index 8b400bdeb4603eaa1a523b150de82aa470743f54..0bc575095aee9c58f57ed5a95da7b69b6a2da0d8 100644 (file)
@@ -41,12 +41,12 @@ public class NewModuleTypeAction implements ActionFactory{
         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
@@ -54,83 +54,109 @@ public class NewModuleTypeAction implements ActionFactory{
                         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
index 81e70e1f50129c888fa05603e3e27b011bf130a4..ffcfd38ee6f988ac485aadbbdc8cca6fee3fee9e 100644 (file)
@@ -79,19 +79,26 @@ public class SysdynConnectionAdvisor  implements IConnectionAdvisor {
                                        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
index 4c16319ba83f1f044a6c35e5bbb984c1cca78741..6bfc3767f2c9d135d7027e8b9658874efac03d54 100644 (file)
@@ -23,7 +23,6 @@ import org.simantics.db.common.utils.NameUtils;
 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
@@ -31,6 +30,7 @@ import org.simantics.modeling.ModelingResources;
 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
@@ -67,7 +67,6 @@ public class NewModuleNodeHandler extends AbstractHandler {
                 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
@@ -131,11 +130,13 @@ public class NewModuleNodeHandler extends AbstractHandler {
                 \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
@@ -144,6 +145,6 @@ public class NewModuleNodeHandler extends AbstractHandler {
         });\r
         return null;\r
     }\r
-\r
+    \r
 \r
 }\r