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);
+ }
}
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]
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 ?
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;
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;
return library;
}
+ public static IModelingRules getModelingRules(ReadGraph graph, Resource diagramResource) throws DatabaseException {
+ return DiagramGraphUtil.getModelingRules(graph, diagramResource, null);
+ }
}