]> gerrit.simantics Code Review - simantics/sysdyn.git/blob
240874fe5f0fe5aab1a9afb3afbd760c33dfea80
[simantics/sysdyn.git] /
1 /*******************************************************************************\r
2  * Copyright (c) 2010 Association for Decentralized Information Management in\r
3  * Industry THTH ry.\r
4  * All rights reserved. This program and the accompanying materials\r
5  * are made available under the terms of the Eclipse Public License v1.0\r
6  * which accompanies this distribution, and is available at\r
7  * http://www.eclipse.org/legal/epl-v10.html\r
8  *\r
9  * Contributors:\r
10  *     VTT Technical Research Centre of Finland - initial API and implementation\r
11  *******************************************************************************/\r
12 package org.simantics.sysdyn.ui.editor;\r
13 \r
14 import org.simantics.db.ReadGraph;\r
15 import org.simantics.db.Resource;\r
16 import org.simantics.db.exception.DatabaseException;\r
17 import org.simantics.layer0.utils.binaryPredicates.InversePredicate;\r
18 import org.simantics.layer0.utils.binaryPredicates.OrderedSetElementsPredicate;\r
19 import org.simantics.mapping.constraint.instructions.IInstruction;\r
20 import org.simantics.mapping.constraint.instructions.TypedBracketInstruction.CreationInstruction;\r
21 import org.simantics.mapping.rule.instructions.IRuleInstruction;\r
22 import org.simantics.sysdyn.SysdynResource;\r
23 \r
24 public class DiagramToCompositeMapping3 extends org.simantics.modeling.mapping.DiagramToCompositeMapping3 {\r
25 \r
26     private SysdynResource sdr;\r
27 \r
28     public DiagramToCompositeMapping3(ReadGraph g, Resource mapping)\r
29     throws DatabaseException {\r
30         super(g, mapping);\r
31     }\r
32 \r
33     @Override\r
34     protected void setup(ReadGraph graph) {\r
35         sdr = SysdynResource.getInstance(graph);\r
36     }\r
37 \r
38     @Override\r
39     protected Resource getConfigurationConnectionType() {\r
40         return sdr.DependencyConnection;\r
41     }\r
42 \r
43     @Override\r
44     public CreationInstruction componentCreationInstruction(int component, int componentType, int configuration) {\r
45         return new SysdynCreationInstruction(project, configurationRoot, component, componentType, configuration);\r
46     }\r
47 \r
48     @Override\r
49     protected IRuleInstruction additiveRule() {\r
50         return \r
51         \r
52         if_(bf(OrderedSetElementsPredicate.INSTANCE, Diagram, Element),\r
53                 query(\r
54                     if_(and(bf(L0.InstanceOf, Element, ElementType),\r
55                                bf(MOD.SymbolToComponentType, ElementType, ComponentType)\r
56                         ),\r
57                         // If element type of the element has a corresponding component type\r
58                         createComponentRule(),\r
59                     \r
60                         if_(and(b(DIA.Connection, Element), bf(L0.InstanceOf, Element, ElementType), bf(MOD.DiagramConnectionTypeToConnectionType, ElementType, ComponentType)),\r
61                                 createNormalConnectionRule(),\r
62 \r
63                                 if_(b(DIA.Flag, Element),\r
64                                         createFlagRule()\r
65                                 )\r
66                         )\r
67                     )\r
68                 )\r
69             );\r
70     }\r
71 \r
72     @Override\r
73     protected IRuleInstruction destructiveRule() {\r
74         return\r
75         if_(and(bf(L0.ConsistsOf, Configuration, Component),\r
76                 b(mapped, Component) // handle only mapped components\r
77         ),\r
78         query(\r
79                 if_(and(bf(MOD.ComponentToElement, Component, Element),\r
80                         bf(new InversePredicate(OrderedSetElementsPredicate.INSTANCE), Element, Diagram)\r
81                 ),\r
82                 // If component has a corresponding element in the diagram\r
83                 if_(and(statement_bff(Component, ConnectionRelation, Connection, STR.IsConnectedTo),\r
84                         b(mapped, Connection)\r
85                 ),\r
86                 // If component has a mapped connection\r
87                 unless(\r
88                         bf(MOD.ConnectionToDiagramConnection, Connection, DiagramConnectionRelation),\r
89                         // If the configuration connection does not have a correspondence in the diagram remove it\r
90                         and(deny(exists(Connection)))\r
91                 )\r
92                 ),\r
93 \r
94                 unless(\r
95                         bf(MOD.ConnectionToDiagramConnection, Component, Element),\r
96                         // If the configuration connection does not have a correspondence in the diagram remove it\r
97                         and(deny(exists(Component)))\r
98                 )\r
99 \r
100                 )\r
101         )\r
102         );\r
103     }\r
104 \r
105     @Override\r
106     protected IInstruction claimBasicConnection() {\r
107         return and(exists(\r
108                 bf(MOD.DiagramConnectionToConnection, Element, Connection),\r
109                 Connection\r
110         ),\r
111         bb(L0.InstanceOf, Connection, ComponentType),\r
112         bb(L0.PartOf, Connection, Configuration),\r
113         b(mapped, Connection)\r
114 \r
115         );\r
116     }\r
117     \r
118 //    @Override\r
119 //    protected IInstruction claimBasicConnection() {\r
120 //        return and(exists(\r
121 //                bf(MOD.DiagramConnectionToConnection, Element, Connection),\r
122 //                Connection\r
123 //        ),\r
124 //        bb(L0.InstanceOf, Connection, ComponentType),\r
125 //        b(mapped, Connection),\r
126 //        bb(L0.PartOf, Connection, Configuration)\r
127 //        );\r
128 //    }\r
129 }\r