1 package org.simantics.sysdyn.modelImport.model.element;
\r
3 import org.simantics.db.ReadGraph;
\r
4 import org.simantics.db.Resource;
\r
5 import org.simantics.db.WriteGraph;
\r
6 import org.simantics.db.common.utils.OrderedSetUtils;
\r
7 import org.simantics.db.exception.DatabaseException;
\r
8 import org.simantics.diagram.stubs.DiagramResource;
\r
9 import org.simantics.layer0.Layer0;
\r
10 import org.simantics.layer0.utils.direct.GraphUtils;
\r
11 import org.simantics.modeling.ModelingResources;
\r
12 import org.simantics.structural.stubs.StructuralResource2;
\r
13 import org.simantics.sysdyn.SysdynResource;
\r
14 import org.simantics.sysdyn.modelImport.model.IWriteableObject;
\r
15 import org.simantics.sysdyn.modelImport.model.WriteContext;
\r
17 public abstract class Connection implements IWriteableObject {
\r
19 protected Symbol head;
\r
20 protected Symbol tail;
\r
22 private Resource connection;
\r
23 private Resource diagramConnection;
\r
25 public Connection(Symbol tail, Symbol head) {
\r
31 public Resource write(WriteGraph graph, Resource parent, WriteContext context) throws DatabaseException {
\r
32 DiagramResource dr = DiagramResource.getInstance(graph);
\r
33 Layer0 l0 = Layer0.getInstance(graph);
\r
34 ModelingResources mr = ModelingResources.getInstance(graph);
\r
35 StructuralResource2 sr2 = StructuralResource2.getInstance(graph);
\r
36 SysdynResource sr = SysdynResource.getInstance(graph);
\r
38 connection = GraphUtils.create2(graph, getConnectionType(graph),
\r
39 sr.Variable_HasHead, head.getResource(),
\r
40 sr.Variable_HasTail, tail.getResource(),
\r
42 graph.claim(connection, mr.Mapped, connection);
\r
44 Resource diagram = graph.getSingleObject(parent, mr.CompositeToDiagram);
\r
46 Resource tailConnector = GraphUtils.create2(graph, dr.Connector,
\r
47 sr.HasTailTerminal, tail.getDiagramResource());
\r
49 Resource headConnector = GraphUtils.create2(graph, dr.Connector,
\r
50 sr.HasHeadTerminal, head.getDiagramResource(),
\r
51 dr.AreConnected, tailConnector);
\r
53 diagramConnection = GraphUtils.create2(graph, getDiagramConnectionType(graph),
\r
54 l0.HasName, context.getNextObject(),
\r
56 sr2.HasConnectionType, sr.SysdynConnectionType,
\r
57 mr.DiagramConnectionToConnection, connection,
\r
58 dr.HasArrowConnector, headConnector,
\r
59 dr.HasPlainConnector, tailConnector);
\r
61 OrderedSetUtils.add(graph, diagram, diagramConnection);
\r
66 public abstract Resource getConnectionType(ReadGraph graph);
\r
67 public abstract Resource getDiagramConnectionType(ReadGraph graph);
\r
70 public Resource getResource() {
\r
74 public Resource getDiagramResource() {
\r
75 return diagramConnection;
\r