From: jsimomaa Date: Fri, 27 Jul 2018 07:19:12 +0000 (+0300) Subject: IConnectionPoint and canBeConnected-checking util to SCL X-Git-Tag: v1.43.0~136^2~423 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F65%2F1965%2F4;p=simantics%2Fplatform.git IConnectionPoint and canBeConnected-checking util to SCL gitlab #67 Change-Id: I7bcb4a3c415dd480cc7b4621ed6b18f1a277d83c --- diff --git a/bundles/org.simantics.diagram/src/org/simantics/diagram/query/DiagramRequests.java b/bundles/org.simantics.diagram/src/org/simantics/diagram/query/DiagramRequests.java index a25fbc39f..6cd380c4a 100644 --- a/bundles/org.simantics.diagram/src/org/simantics/diagram/query/DiagramRequests.java +++ b/bundles/org.simantics.diagram/src/org/simantics/diagram/query/DiagramRequests.java @@ -108,11 +108,7 @@ public class DiagramRequests { return new Read() { @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); } }; } diff --git a/bundles/org.simantics.diagram/src/org/simantics/diagram/synchronization/graph/DiagramGraphUtil.java b/bundles/org.simantics.diagram/src/org/simantics/diagram/synchronization/graph/DiagramGraphUtil.java index 28b78eb54..3a38654e3 100644 --- a/bundles/org.simantics.diagram/src/org/simantics/diagram/synchronization/graph/DiagramGraphUtil.java +++ b/bundles/org.simantics.diagram/src/org/simantics/diagram/synchronization/graph/DiagramGraphUtil.java @@ -1138,5 +1138,13 @@ public final class DiagramGraphUtil { public static void defaultSymbolDropHandler(WriteGraph graph, List 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); + } } diff --git a/bundles/org.simantics.modeling/scl/Simantics/RouteGraph.scl b/bundles/org.simantics.modeling/scl/Simantics/RouteGraph.scl index fff5de896..cacec102b 100644 --- a/bundles/org.simantics.modeling/scl/Simantics/RouteGraph.scl +++ b/bundles/org.simantics.modeling/scl/Simantics/RouteGraph.scl @@ -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] -> 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 -> 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 -> Maybe IModelingRules + +importJava "org.simantics.structural2.modelingRules.IModelingRules" where + data IModelingRules + + judgeConnection :: IModelingRules -> [IConnectionPoint] -> ConnectionJudgement + +canTerminalBeConnected :: Resource -> Resource -> Resource -> 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 ? diff --git a/bundles/org.simantics.modeling/src/org/simantics/modeling/ModelingUtils.java b/bundles/org.simantics.modeling/src/org/simantics/modeling/ModelingUtils.java index b10ad9da0..017d1cf4b 100644 --- a/bundles/org.simantics.modeling/src/org/simantics/modeling/ModelingUtils.java +++ b/bundles/org.simantics.modeling/src/org/simantics/modeling/ModelingUtils.java @@ -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); + } } diff --git a/bundles/org.simantics.structural2/src/org/simantics/structural2/modelingRules/CPTerminal.java b/bundles/org.simantics.structural2/src/org/simantics/structural2/modelingRules/CPTerminal.java index 68eec9735..9692b5787 100644 --- a/bundles/org.simantics.structural2/src/org/simantics/structural2/modelingRules/CPTerminal.java +++ b/bundles/org.simantics.structural2/src/org/simantics/structural2/modelingRules/CPTerminal.java @@ -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); + } }