]> gerrit.simantics Code Review - simantics/3d.git/blob
bc07e75f98dbbf955cd1761ba5b0de449b8a885e
[simantics/3d.git] /
1 /*******************************************************************************\r
2  * Copyright (c) 2007 VTT Technical Research Centre of Finland and others.\r
3  * All rights reserved. This program and the accompanying materials\r
4  * are made available under the terms of the Eclipse Public License v1.0\r
5  * which accompanies this distribution, and is available at\r
6  * http://www.eclipse.org/legal/epl-v10.html\r
7  *\r
8  * Contributors:\r
9  *     VTT Technical Research Centre of Finland - initial API and implementation\r
10  *******************************************************************************/\r
11 package org.simantics.processeditor.stubs;\r
12 \r
13 import org.simantics.db.Resource;\r
14 import org.simantics.db.ResourceContainer;\r
15 import org.simantics.db.Statement;\r
16 import org.simantics.db.Graph;\r
17 import org.simantics.db.ResourceContainer;\r
18 import org.simantics.layer0.utils.ResourceDoesNotSatisfyAssumptionException;\r
19 import org.simantics.layer0.utils.IEntity;\r
20 import org.simantics.layer0.utils.internal.Entity;\r
21 import org.simantics.layer0.utils.instantiation.InstanceFactory;\r
22 import java.util.Collection;\r
23 import java.util.ArrayList;\r
24 \r
25 public class DualConnectedComponent extends Entity implements IDualConnectedComponent {\r
26     \r
27     public DualConnectedComponent(Graph graph, ResourceContainer resourceContainer) {\r
28         super(graph, resourceContainer.getResource());\r
29     }\r
30     \r
31     public DualConnectedComponent(IEntity entity) {\r
32         super(entity.getGraph(), entity.getResource());\r
33     }\r
34     \r
35     public Graph getGraph() {\r
36         return graph;\r
37     }\r
38     \r
39     public static DualConnectedComponent createDefault(Graph graph) {\r
40         return new DualConnectedComponent(graph, InstanceFactory.instantiate(graph, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).DualConnectedComponent));\r
41     }\r
42     \r
43     public static boolean isInstance(IEntity entity) {\r
44         Graph graph = entity.getGraph();\r
45         Resource type = org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).DualConnectedComponent;\r
46         return graph.isInstanceOf(entity.getResource(), type);\r
47     }\r
48     \r
49     @Override\r
50     public Resource getResource() {\r
51         return resource;\r
52     }\r
53     \r
54     public org.simantics.proconf.g3d.stubs.G3DNode toG3DNode() {\r
55         return new org.simantics.proconf.g3d.stubs.G3DNode(graph, resource);\r
56     }\r
57     \r
58     public org.simantics.processeditor.stubs.PBSNode toPBSNode() {\r
59         return new org.simantics.processeditor.stubs.PBSNode(graph, resource);\r
60     }\r
61     \r
62     public org.simantics.processeditor.stubs.P3DNode toP3DNode() {\r
63         return new org.simantics.processeditor.stubs.P3DNode(graph, resource);\r
64     }\r
65     \r
66     public DualConnectedComponent toDualConnectedComponent() {\r
67         return this;\r
68     }\r
69     \r
70     public org.simantics.processeditor.stubs.PipelineComponent toPipelineComponent() {\r
71         return new org.simantics.processeditor.stubs.PipelineComponent(graph, resource);\r
72     }\r
73     \r
74     public org.simantics.processeditor.stubs.LibraryComponent toLibraryComponent() {\r
75         return new org.simantics.processeditor.stubs.LibraryComponent(graph, resource);\r
76     }\r
77     \r
78     public Collection<org.simantics.proconf.g3d.stubs.G3DNode> getChild() {\r
79         Statement[] statements = graph.getStatements(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasChild);\r
80         Collection<org.simantics.proconf.g3d.stubs.G3DNode> ret = new ArrayList<org.simantics.proconf.g3d.stubs.G3DNode>(statements.length);\r
81         for(Statement s : statements)\r
82             ret.add(new org.simantics.proconf.g3d.stubs.G3DNode(graph, s.getObject()));\r
83         return ret;\r
84     }\r
85     \r
86     public void addChild(ResourceContainer v) {\r
87         graph.addStatement(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasChild, v.getResource());\r
88     }\r
89     \r
90     public org.simantics.proconf.g3d.stubs.G3DNode getParent() {\r
91         Statement[] statements = graph.getStatements(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasParent);\r
92         if(statements.length > 1)\r
93             throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + statements.length + ") of statements.");\r
94         if(statements.length == 0)\r
95             return null;\r
96         return new org.simantics.proconf.g3d.stubs.G3DNode(graph, statements[0].getObject());\r
97     }\r
98     \r
99     public void addParent(ResourceContainer v) {\r
100         graph.addStatement(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasParent, v.getResource());\r
101     }\r
102     \r
103     public void setParent(ResourceContainer v) {\r
104         Resource predicate = org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasParent;\r
105         graph.removeStatements(resource, predicate);\r
106         graph.addStatement(resource, predicate, v.getResource());\r
107     }\r
108     \r
109     public org.simantics.proconf.g3d.stubs.Position getLocalPosition() {\r
110         Statement[] statements = graph.getStatements(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasLocalPosition);\r
111         if(statements.length > 1)\r
112             throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + statements.length + ") of statements.");\r
113         if(statements.length == 0)\r
114             return null;\r
115         return new org.simantics.proconf.g3d.stubs.Position(graph, statements[0].getObject());\r
116     }\r
117     \r
118     public void addLocalPosition(ResourceContainer v) {\r
119         graph.addStatement(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasLocalPosition, v.getResource());\r
120     }\r
121     \r
122     public void setLocalPosition(ResourceContainer v) {\r
123         Resource predicate = org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasLocalPosition;\r
124         graph.removeStatements(resource, predicate);\r
125         graph.addStatement(resource, predicate, v.getResource());\r
126     }\r
127     \r
128     public org.simantics.proconf.g3d.stubs.Position getWorldPosition() {\r
129         Statement[] statements = graph.getStatements(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasWorldPosition);\r
130         if(statements.length > 1)\r
131             throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + statements.length + ") of statements.");\r
132         if(statements.length == 0)\r
133             return null;\r
134         return new org.simantics.proconf.g3d.stubs.Position(graph, statements[0].getObject());\r
135     }\r
136     \r
137     public void addWorldPosition(ResourceContainer v) {\r
138         graph.addStatement(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasWorldPosition, v.getResource());\r
139     }\r
140     \r
141     public void setWorldPosition(ResourceContainer v) {\r
142         Resource predicate = org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasWorldPosition;\r
143         graph.removeStatements(resource, predicate);\r
144         graph.addStatement(resource, predicate, v.getResource());\r
145     }\r
146     \r
147     public org.simantics.proconf.g3d.stubs.Orientation getLocalOrientation() {\r
148         Statement[] statements = graph.getStatements(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasLocalOrientation);\r
149         if(statements.length > 1)\r
150             throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + statements.length + ") of statements.");\r
151         if(statements.length == 0)\r
152             return null;\r
153         return new org.simantics.proconf.g3d.stubs.Orientation(graph, statements[0].getObject());\r
154     }\r
155     \r
156     public void addLocalOrientation(ResourceContainer v) {\r
157         graph.addStatement(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasLocalOrientation, v.getResource());\r
158     }\r
159     \r
160     public void setLocalOrientation(ResourceContainer v) {\r
161         Resource predicate = org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasLocalOrientation;\r
162         graph.removeStatements(resource, predicate);\r
163         graph.addStatement(resource, predicate, v.getResource());\r
164     }\r
165     \r
166     public org.simantics.proconf.g3d.stubs.Orientation getWorldOrientation() {\r
167         Statement[] statements = graph.getStatements(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasWorldOrientation);\r
168         if(statements.length > 1)\r
169             throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + statements.length + ") of statements.");\r
170         if(statements.length == 0)\r
171             return null;\r
172         return new org.simantics.proconf.g3d.stubs.Orientation(graph, statements[0].getObject());\r
173     }\r
174     \r
175     public void addWorldOrientation(ResourceContainer v) {\r
176         graph.addStatement(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasWorldOrientation, v.getResource());\r
177     }\r
178     \r
179     public void setWorldOrientation(ResourceContainer v) {\r
180         Resource predicate = org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasWorldOrientation;\r
181         graph.removeStatements(resource, predicate);\r
182         graph.addStatement(resource, predicate, v.getResource());\r
183     }\r
184     \r
185     public org.simantics.proconf.g3d.stubs.Center getCenter() {\r
186         Statement[] statements = graph.getStatements(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasCenter);\r
187         if(statements.length > 1)\r
188             throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + statements.length + ") of statements.");\r
189         if(statements.length == 0)\r
190             return null;\r
191         return new org.simantics.proconf.g3d.stubs.Center(graph, statements[0].getObject());\r
192     }\r
193     \r
194     public void addCenter(ResourceContainer v) {\r
195         graph.addStatement(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasCenter, v.getResource());\r
196     }\r
197     \r
198     public void setCenter(ResourceContainer v) {\r
199         Resource predicate = org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasCenter;\r
200         graph.removeStatements(resource, predicate);\r
201         graph.addStatement(resource, predicate, v.getResource());\r
202     }\r
203     \r
204     public org.simantics.processeditor.stubs.PBSNode getParentStructure() {\r
205         Statement[] statements = graph.getStatements(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasParentStructure);\r
206         if(statements.length > 1)\r
207             throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + statements.length + ") of statements.");\r
208         if(statements.length == 0)\r
209             return null;\r
210         return new org.simantics.processeditor.stubs.PBSNode(graph, statements[0].getObject());\r
211     }\r
212     \r
213     public void addParentStructure(ResourceContainer v) {\r
214         graph.addStatement(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasParentStructure, v.getResource());\r
215     }\r
216     \r
217     public void setParentStructure(ResourceContainer v) {\r
218         Resource predicate = org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasParentStructure;\r
219         graph.removeStatements(resource, predicate);\r
220         graph.addStatement(resource, predicate, v.getResource());\r
221     }\r
222     \r
223     public Collection<org.simantics.processeditor.stubs.PBSNode> getChildStructure() {\r
224         Statement[] statements = graph.getStatements(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasChildStructure);\r
225         Collection<org.simantics.processeditor.stubs.PBSNode> ret = new ArrayList<org.simantics.processeditor.stubs.PBSNode>(statements.length);\r
226         for(Statement s : statements)\r
227             ret.add(new org.simantics.processeditor.stubs.PBSNode(graph, s.getObject()));\r
228         return ret;\r
229     }\r
230     \r
231     public void addChildStructure(ResourceContainer v) {\r
232         graph.addStatement(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasChildStructure, v.getResource());\r
233     }\r
234     \r
235     public org.simantics.proconf.g3d.stubs.G3DModel getGraphics() {\r
236         Statement[] statements = graph.getStatements(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasGraphics);\r
237         if(statements.length > 1)\r
238             throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + statements.length + ") of statements.");\r
239         if(statements.length == 0)\r
240             return null;\r
241         return new org.simantics.proconf.g3d.stubs.G3DModel(graph, statements[0].getObject());\r
242     }\r
243     \r
244     public void addGraphics(ResourceContainer v) {\r
245         graph.addStatement(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasGraphics, v.getResource());\r
246     }\r
247     \r
248     public void setGraphics(ResourceContainer v) {\r
249         Resource predicate = org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasGraphics;\r
250         graph.removeStatements(resource, predicate);\r
251         graph.addStatement(resource, predicate, v.getResource());\r
252     }\r
253     \r
254     public double[] getPipeDiameter() {\r
255         Statement[] statements = graph.getStatements(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasPipeDiameter);\r
256         if(statements.length != 1)\r
257             throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + statements.length + ") of statements.");\r
258         return (double[])graph.getValueAsObject(statements[0].getObject());\r
259     }\r
260     \r
261     public void setPipeDiameter(Object v) {\r
262         Resource predicate = org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasPipeDiameter;\r
263         Collection<Resource> objects = graph.getObjects(resource, predicate);\r
264         if(objects.size() == 0) {\r
265             Resource r = graph.newResource();\r
266         Resource valueType = org.simantics.db.Builtins.getInstance(graph).Double;\r
267             graph.addStatement(r, graph.getBuiltins().InstanceOf, valueType);\r
268             graph.setValueAsObject(r, v);\r
269             graph.addStatement(resource, predicate, r);\r
270         }\r
271         else if(objects.size() == 1)\r
272             for(Resource r : objects)\r
273                 graph.setValueAsObject(r, v);\r
274         else\r
275             throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + objects.size() + ") of statements.");\r
276     }\r
277     \r
278     public org.simantics.processeditor.stubs.PipeControlPoint getControlPoint() {\r
279         Statement[] statements = graph.getStatements(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasControlPoint);\r
280         if(statements.length > 1)\r
281             throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + statements.length + ") of statements.");\r
282         if(statements.length == 0)\r
283             return null;\r
284         return new org.simantics.processeditor.stubs.PipeControlPoint(graph, statements[0].getObject());\r
285     }\r
286     \r
287     public void addControlPoint(ResourceContainer v) {\r
288         graph.addStatement(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasControlPoint, v.getResource());\r
289     }\r
290     \r
291     public void setControlPoint(ResourceContainer v) {\r
292         Resource predicate = org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasControlPoint;\r
293         graph.removeStatements(resource, predicate);\r
294         graph.addStatement(resource, predicate, v.getResource());\r
295     }\r
296     \r
297 }\r
298 \r