1 package org.simantics.sysdyn.modelImport.model.element;
\r
3 import org.simantics.db.Resource;
\r
4 import org.simantics.db.WriteGraph;
\r
5 import org.simantics.db.common.utils.OrderedSetUtils;
\r
6 import org.simantics.db.exception.DatabaseException;
\r
7 import org.simantics.diagram.stubs.DiagramResource;
\r
8 import org.simantics.layer0.Layer0;
\r
9 import org.simantics.layer0.utils.direct.GraphUtils;
\r
10 import org.simantics.modeling.ModelingResources;
\r
11 import org.simantics.structural.stubs.StructuralResource2;
\r
12 import org.simantics.sysdyn.SysdynResource;
\r
13 import org.simantics.sysdyn.modelImport.model.IWriteableObject;
\r
14 import org.simantics.sysdyn.modelImport.model.WriteContext;
\r
16 public abstract class Connection implements IWriteableObject {
\r
18 protected Element head;
\r
19 protected Element tail;
\r
21 public Connection(Element head, Element tail) {
\r
26 protected Resource createConnection(WriteGraph graph, Resource type, Resource parent, WriteContext context)
\r
27 throws DatabaseException {
\r
28 Layer0 l0 = Layer0.getInstance(graph);
\r
29 ModelingResources mr = ModelingResources.getInstance(graph);
\r
30 SysdynResource sr = SysdynResource.getInstance(graph);
\r
32 Resource connection = GraphUtils.create2(graph, type,
\r
33 sr.Variable_HasHead, head.getResource(),
\r
34 sr.Variable_HasTail, tail.getResource(),
\r
36 graph.claim(connection, mr.Mapped, connection);
\r
41 protected Resource createSymbol(WriteGraph graph, Resource type, Resource connection, Resource parent, WriteContext context)
\r
42 throws DatabaseException {
\r
43 DiagramResource dr = DiagramResource.getInstance(graph);
\r
44 Layer0 l0 = Layer0.getInstance(graph);
\r
45 ModelingResources mr = ModelingResources.getInstance(graph);
\r
46 StructuralResource2 sr2 = StructuralResource2.getInstance(graph);
\r
47 SysdynResource sr = SysdynResource.getInstance(graph);
\r
49 Resource diagram = graph.getSingleObject(parent, mr.CompositeToDiagram);
\r
51 Resource diagramTail = graph.getPossibleObject(tail.getResource(), mr.ComponentToElement);
\r
52 Resource tailConnector = GraphUtils.create2(graph, dr.Connector,
\r
53 sr.HasTailTerminal, diagramTail);
\r
55 Resource diagramHead = graph.getPossibleObject(head.getResource(), mr.ComponentToElement);
\r
56 Resource headConnector = GraphUtils.create2(graph, dr.Connector,
\r
57 sr.HasHeadTerminal, diagramHead,
\r
58 dr.AreConnected, tailConnector);
\r
60 Resource diagramConnection = GraphUtils.create2(graph, type,
\r
61 l0.HasName, context.getNextObject(),
\r
63 sr2.HasConnectionType, sr.SysdynConnectionType,
\r
64 mr.DiagramConnectionToConnection, connection,
\r
65 dr.HasArrowConnector, headConnector,
\r
66 dr.HasPlainConnector, tailConnector);
\r
68 OrderedSetUtils.add(graph, diagram, diagramConnection);
\r
70 return diagramConnection;
\r