]> gerrit.simantics Code Review - simantics/sysdyn.git/blob
00119d31315758467109bfe0dab6b99a6a87c205
[simantics/sysdyn.git] /
1 package org.simantics.sysdyn.modelImport.model.element;\r
2 \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
15 \r
16 public abstract class Connection implements IWriteableObject {\r
17 \r
18         protected Element head;\r
19         protected Element tail;\r
20 \r
21         public Connection(Element head, Element tail) {\r
22                 this.head = head;\r
23                 this.tail = tail;\r
24         }\r
25 \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
31 \r
32                 Resource connection = GraphUtils.create2(graph, type,\r
33                                 sr.Variable_HasHead, head.getResource(),\r
34                                 sr.Variable_HasTail, tail.getResource(),\r
35                                 l0.PartOf, parent);\r
36                 graph.claim(connection, mr.Mapped, connection);\r
37                 \r
38                 return connection;\r
39         }\r
40         \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
48                 \r
49                 Resource diagram = graph.getSingleObject(parent, mr.CompositeToDiagram);\r
50                 \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
54 \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
59 \r
60                 Resource diagramConnection = GraphUtils.create2(graph, type,\r
61                                 l0.HasName, context.getNextObject(),\r
62                                 l0.PartOf, diagram,\r
63                                 sr2.HasConnectionType, sr.SysdynConnectionType,\r
64                                 mr.DiagramConnectionToConnection, connection,\r
65                                 dr.HasArrowConnector, headConnector,\r
66                                 dr.HasPlainConnector, tailConnector);\r
67 \r
68                 OrderedSetUtils.add(graph, diagram, diagramConnection);\r
69                 \r
70                 return diagramConnection;\r
71         }\r
72 \r
73 }\r