IConnectionPoint and canBeConnected-checking util to SCL 65/1965/4
authorjsimomaa <jani.simomaa@gmail.com>
Fri, 27 Jul 2018 07:19:12 +0000 (10:19 +0300)
committerJani Simomaa <jani.simomaa@semantum.fi>
Tue, 31 Jul 2018 20:12:48 +0000 (20:12 +0000)
gitlab #67

Change-Id: I7bcb4a3c415dd480cc7b4621ed6b18f1a277d83c

bundles/org.simantics.diagram/src/org/simantics/diagram/query/DiagramRequests.java
bundles/org.simantics.diagram/src/org/simantics/diagram/synchronization/graph/DiagramGraphUtil.java
bundles/org.simantics.modeling/scl/Simantics/RouteGraph.scl
bundles/org.simantics.modeling/src/org/simantics/modeling/ModelingUtils.java
bundles/org.simantics.structural2/src/org/simantics/structural2/modelingRules/CPTerminal.java

index a25fbc39f56ec53fb6604f44a0b43b15b7ed507b..6cd380c4ad3d176b2b3486074d12624f682ca20c 100644 (file)
@@ -108,11 +108,7 @@ public class DiagramRequests {
         return new Read<IModelingRules>() {
             @Override
             public IModelingRules perform(ReadGraph graph) throws DatabaseException {
-                StructuralResource2 sr = StructuralResource2.getInstance(graph);
-                Resource rules = graph.getPossibleObject(diagram, sr.HasModelingRules);
-                if (rules == null)
-                    return defaultValue;
-                return graph.adapt(rules, IModelingRules.class);
+                return DiagramGraphUtil.getModelingRules(graph, diagram, defaultValue);
             }
         };
     }
index 28b78eb541eb6bd1094dfa76cbaead76e86b995f..3a38654e396db46a900b6eb6d1271fba122ec2b8 100644 (file)
@@ -1138,5 +1138,13 @@ public final class DiagramGraphUtil {
        public static void defaultSymbolDropHandler(WriteGraph graph, List<WorkbenchSelectionElement> drop) throws DatabaseException {
                System.err.println("dropped " + drop);
        }
+
+    public static IModelingRules getModelingRules(ReadGraph graph, Resource diagram, IModelingRules defaultValue) throws DatabaseException {
+        StructuralResource2 sr = StructuralResource2.getInstance(graph);
+        Resource rules = graph.getPossibleObject(diagram, sr.HasModelingRules);
+        if (rules == null)
+            return defaultValue;
+        return graph.adapt(rules, IModelingRules.class);
+    }
     
 }
index fff5de896f86e59ea495456d70d2c3b44d78eee2..cacec102b700763288fcf09a132d21b22c859f77 100644 (file)
@@ -6,6 +6,8 @@ import "http://www.simantics.org/Structural-1.2" as STR
 import "http://www.simantics.org/Diagram-2.2" as DIA
 import "http://www.simantics.org/Modeling-1.2" as MOD
 
+import "Logging" as LOGGER
+
 importJava "org.simantics.modeling.scl.RouteGraphMatching" where
     matchRouteGraph :: [Resource] -> Integer -> [Integer] -> <ReadGraph> Maybe [Resource]
 
@@ -140,4 +142,44 @@ modifyRouteGraph structure modis =
             ra = ArrayList.fromList nodes
             for modis (executeAtomicModification connection ra)
             ArrayList.freeze ra
-        Nothing -> fail "Couldn't resolve route graph structure."
\ No newline at end of file
+        Nothing -> fail "Couldn't resolve route graph structure."
+
+// Connection and terminal judgements
+importJava "org.simantics.structural2.modelingRules.CPTerminal" where
+    makeIConnectionPoint :: Resource -> Resource -> <Proc> IConnectionPoint
+
+importJava "org.simantics.structural2.modelingRules.ConnectionJudgementType" where
+    data ConnectionJudgementType
+    LEGAL :: ConnectionJudgementType
+    ILLEGAL :: ConnectionJudgementType
+    CANBEMADELEGAL :: ConnectionJudgementType
+
+importJava "org.simantics.structural2.modelingRules.ConnectionJudgement" where
+    data ConnectionJudgement
+    @private
+    @JavaName "type" 
+    getConnectionJudgementType :: ConnectionJudgement -> ConnectionJudgementType
+
+importJava "org.simantics.structural2.modelingRules.IConnectionPoint" where
+    data IConnectionPoint
+
+
+importJava "org.simantics.modeling.ModelingUtils" where
+    getModelingRules :: Resource -> <ReadGraph, Proc> Maybe IModelingRules
+
+importJava "org.simantics.structural2.modelingRules.IModelingRules" where
+    data IModelingRules
+
+    judgeConnection :: IModelingRules -> [IConnectionPoint] -> <ReadGraph, Proc> ConnectionJudgement
+
+canTerminalBeConnected :: Resource -> Resource -> Resource -> <ReadGraph, Proc> Boolean
+canTerminalBeConnected diagram component terminal = match getModelingRules diagram with
+    Just modelingRules -> do
+        cpTerminal = makeIConnectionPoint component terminal
+        connectionJudgement = judgeConnection modelingRules [cpTerminal]
+        canBeConnected = getConnectionJudgementType connectionJudgement == LEGAL
+        LOGGER.info $ "canBeConnected : \(canBeConnected)"
+        canBeConnected
+    Nothing -> do
+        LOGGER.warn $ "No modeling rules available for diagram \(diagram) to resolve connection judgement"
+        False // true or false when no modeling rules available ?
index b10ad9da009065604f184ed0c9311799ff08d74d..017d1cf4bc6ab01c5593025a022435746dc37c36 100644 (file)
@@ -130,6 +130,7 @@ import org.simantics.db.service.VirtualGraphSupport;
 import org.simantics.diagram.stubs.DiagramResource;
 import org.simantics.diagram.stubs.G2DResource;
 import org.simantics.diagram.synchronization.graph.AddElement;
+import org.simantics.diagram.synchronization.graph.DiagramGraphUtil;
 import org.simantics.graph.db.IImportAdvisor2;
 import org.simantics.graph.db.ImportAdvisors;
 import org.simantics.graph.db.MissingDependencyException;
@@ -155,6 +156,7 @@ import org.simantics.scl.runtime.function.Function1;
 import org.simantics.scl.runtime.tuple.Tuple;
 import org.simantics.simulation.ontology.SimulationResource;
 import org.simantics.structural.stubs.StructuralResource2;
+import org.simantics.structural2.modelingRules.IModelingRules;
 import org.simantics.structural2.scl.StructuralComponent;
 import org.simantics.structural2.utils.StructuralUtils;
 import org.simantics.utils.ObjectUtils;
@@ -2444,5 +2446,8 @@ public class ModelingUtils {
         return library;
     }
 
+    public static IModelingRules getModelingRules(ReadGraph graph, Resource diagramResource) throws DatabaseException {
+        return DiagramGraphUtil.getModelingRules(graph, diagramResource, null);
+    }
 
 }
index 68eec97358d0d1872de51b59674e49c379ace14b..9692b57870b53e8f6dc40bf319076034901c0de1 100644 (file)
@@ -56,4 +56,14 @@ public class CPTerminal implements IConnectionPoint {
         return (component == null ? other.component == null : component.equals(other.component)) && relation.equals(other.relation);
     }
 
+    /**
+     * Convenience method for SCL
+     * 
+     * @param component
+     * @param relation
+     * @return
+     */
+    public static IConnectionPoint makeIConnectionPoint(Resource component, Resource relation) {
+        return new CPTerminal(component, relation);
+    }
 }