]> gerrit.simantics Code Review - simantics/3d.git/blob - org.simantics.proconf.processeditor/src/org/simantics/processeditor/stubs/Elbow.java
git-svn-id: https://www.simantics.org/svn/simantics/3d/branches/dev@7344 ac1ea38d...
[simantics/3d.git] / org.simantics.proconf.processeditor / src / org / simantics / processeditor / stubs / Elbow.java
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 Elbow extends Entity implements IElbow {\r
26     \r
27     public Elbow(Graph graph, ResourceContainer resourceContainer) {\r
28         super(graph, resourceContainer.getResource());\r
29     }\r
30     \r
31     public Elbow(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 Elbow createDefault(Graph graph) {\r
40         return new Elbow(graph, InstanceFactory.instantiate(graph, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).Elbow));\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).Elbow;\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.processeditor.stubs.CodedComponent toCodedComponent() {\r
55         return new org.simantics.processeditor.stubs.CodedComponent(graph, resource);\r
56     }\r
57     \r
58     public org.simantics.proconf.g3d.stubs.G3DNode toG3DNode() {\r
59         return new org.simantics.proconf.g3d.stubs.G3DNode(graph, resource);\r
60     }\r
61     \r
62     public org.simantics.processeditor.stubs.PBSNode toPBSNode() {\r
63         return new org.simantics.processeditor.stubs.PBSNode(graph, resource);\r
64     }\r
65     \r
66     public org.simantics.processeditor.stubs.VariableAngleTurnComponent toVariableAngleTurnComponent() {\r
67         return new org.simantics.processeditor.stubs.VariableAngleTurnComponent(graph, resource);\r
68     }\r
69     \r
70     public org.simantics.processeditor.stubs.P3DNode toP3DNode() {\r
71         return new org.simantics.processeditor.stubs.P3DNode(graph, resource);\r
72     }\r
73     \r
74     public org.simantics.processeditor.stubs.DualConnectedComponent toDualConnectedComponent() {\r
75         return new org.simantics.processeditor.stubs.DualConnectedComponent(graph, resource);\r
76     }\r
77     \r
78     public Elbow toElbow() {\r
79         return this;\r
80     }\r
81     \r
82     public org.simantics.processeditor.stubs.PipelineComponent toPipelineComponent() {\r
83         return new org.simantics.processeditor.stubs.PipelineComponent(graph, resource);\r
84     }\r
85     \r
86     public org.simantics.processeditor.stubs.LibraryComponent toLibraryComponent() {\r
87         return new org.simantics.processeditor.stubs.LibraryComponent(graph, resource);\r
88     }\r
89     \r
90     public org.simantics.processeditor.stubs.TurnComponent toTurnComponent() {\r
91         return new org.simantics.processeditor.stubs.TurnComponent(graph, resource);\r
92     }\r
93     \r
94     public Collection<org.simantics.proconf.g3d.stubs.G3DNode> getChild() {\r
95         Statement[] statements = graph.getStatements(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasChild);\r
96         Collection<org.simantics.proconf.g3d.stubs.G3DNode> ret = new ArrayList<org.simantics.proconf.g3d.stubs.G3DNode>(statements.length);\r
97         for(Statement s : statements)\r
98             ret.add(new org.simantics.proconf.g3d.stubs.G3DNode(graph, s.getObject()));\r
99         return ret;\r
100     }\r
101     \r
102     public void addChild(ResourceContainer v) {\r
103         graph.addStatement(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasChild, v.getResource());\r
104     }\r
105     \r
106     public org.simantics.proconf.g3d.stubs.G3DNode getParent() {\r
107         Statement[] statements = graph.getStatements(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasParent);\r
108         if(statements.length > 1)\r
109             throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + statements.length + ") of statements.");\r
110         if(statements.length == 0)\r
111             return null;\r
112         return new org.simantics.proconf.g3d.stubs.G3DNode(graph, statements[0].getObject());\r
113     }\r
114     \r
115     public void addParent(ResourceContainer v) {\r
116         graph.addStatement(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasParent, v.getResource());\r
117     }\r
118     \r
119     public void setParent(ResourceContainer v) {\r
120         Resource predicate = org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasParent;\r
121         graph.removeStatements(resource, predicate);\r
122         graph.addStatement(resource, predicate, v.getResource());\r
123     }\r
124     \r
125     public org.simantics.proconf.g3d.stubs.Position getLocalPosition() {\r
126         Statement[] statements = graph.getStatements(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasLocalPosition);\r
127         if(statements.length > 1)\r
128             throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + statements.length + ") of statements.");\r
129         if(statements.length == 0)\r
130             return null;\r
131         return new org.simantics.proconf.g3d.stubs.Position(graph, statements[0].getObject());\r
132     }\r
133     \r
134     public void addLocalPosition(ResourceContainer v) {\r
135         graph.addStatement(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasLocalPosition, v.getResource());\r
136     }\r
137     \r
138     public void setLocalPosition(ResourceContainer v) {\r
139         Resource predicate = org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasLocalPosition;\r
140         graph.removeStatements(resource, predicate);\r
141         graph.addStatement(resource, predicate, v.getResource());\r
142     }\r
143     \r
144     public org.simantics.proconf.g3d.stubs.Position getWorldPosition() {\r
145         Statement[] statements = graph.getStatements(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasWorldPosition);\r
146         if(statements.length > 1)\r
147             throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + statements.length + ") of statements.");\r
148         if(statements.length == 0)\r
149             return null;\r
150         return new org.simantics.proconf.g3d.stubs.Position(graph, statements[0].getObject());\r
151     }\r
152     \r
153     public void addWorldPosition(ResourceContainer v) {\r
154         graph.addStatement(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasWorldPosition, v.getResource());\r
155     }\r
156     \r
157     public void setWorldPosition(ResourceContainer v) {\r
158         Resource predicate = org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasWorldPosition;\r
159         graph.removeStatements(resource, predicate);\r
160         graph.addStatement(resource, predicate, v.getResource());\r
161     }\r
162     \r
163     public org.simantics.proconf.g3d.stubs.Orientation getLocalOrientation() {\r
164         Statement[] statements = graph.getStatements(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasLocalOrientation);\r
165         if(statements.length > 1)\r
166             throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + statements.length + ") of statements.");\r
167         if(statements.length == 0)\r
168             return null;\r
169         return new org.simantics.proconf.g3d.stubs.Orientation(graph, statements[0].getObject());\r
170     }\r
171     \r
172     public void addLocalOrientation(ResourceContainer v) {\r
173         graph.addStatement(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasLocalOrientation, v.getResource());\r
174     }\r
175     \r
176     public void setLocalOrientation(ResourceContainer v) {\r
177         Resource predicate = org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasLocalOrientation;\r
178         graph.removeStatements(resource, predicate);\r
179         graph.addStatement(resource, predicate, v.getResource());\r
180     }\r
181     \r
182     public org.simantics.proconf.g3d.stubs.Orientation getWorldOrientation() {\r
183         Statement[] statements = graph.getStatements(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasWorldOrientation);\r
184         if(statements.length > 1)\r
185             throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + statements.length + ") of statements.");\r
186         if(statements.length == 0)\r
187             return null;\r
188         return new org.simantics.proconf.g3d.stubs.Orientation(graph, statements[0].getObject());\r
189     }\r
190     \r
191     public void addWorldOrientation(ResourceContainer v) {\r
192         graph.addStatement(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasWorldOrientation, v.getResource());\r
193     }\r
194     \r
195     public void setWorldOrientation(ResourceContainer v) {\r
196         Resource predicate = org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasWorldOrientation;\r
197         graph.removeStatements(resource, predicate);\r
198         graph.addStatement(resource, predicate, v.getResource());\r
199     }\r
200     \r
201     public org.simantics.proconf.g3d.stubs.Center getCenter() {\r
202         Statement[] statements = graph.getStatements(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasCenter);\r
203         if(statements.length > 1)\r
204             throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + statements.length + ") of statements.");\r
205         if(statements.length == 0)\r
206             return null;\r
207         return new org.simantics.proconf.g3d.stubs.Center(graph, statements[0].getObject());\r
208     }\r
209     \r
210     public void addCenter(ResourceContainer v) {\r
211         graph.addStatement(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasCenter, v.getResource());\r
212     }\r
213     \r
214     public void setCenter(ResourceContainer v) {\r
215         Resource predicate = org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasCenter;\r
216         graph.removeStatements(resource, predicate);\r
217         graph.addStatement(resource, predicate, v.getResource());\r
218     }\r
219     \r
220     public org.simantics.processeditor.stubs.PBSNode getParentStructure() {\r
221         Statement[] statements = graph.getStatements(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasParentStructure);\r
222         if(statements.length > 1)\r
223             throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + statements.length + ") of statements.");\r
224         if(statements.length == 0)\r
225             return null;\r
226         return new org.simantics.processeditor.stubs.PBSNode(graph, statements[0].getObject());\r
227     }\r
228     \r
229     public void addParentStructure(ResourceContainer v) {\r
230         graph.addStatement(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasParentStructure, v.getResource());\r
231     }\r
232     \r
233     public void setParentStructure(ResourceContainer v) {\r
234         Resource predicate = org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasParentStructure;\r
235         graph.removeStatements(resource, predicate);\r
236         graph.addStatement(resource, predicate, v.getResource());\r
237     }\r
238     \r
239     public Collection<org.simantics.processeditor.stubs.PBSNode> getChildStructure() {\r
240         Statement[] statements = graph.getStatements(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasChildStructure);\r
241         Collection<org.simantics.processeditor.stubs.PBSNode> ret = new ArrayList<org.simantics.processeditor.stubs.PBSNode>(statements.length);\r
242         for(Statement s : statements)\r
243             ret.add(new org.simantics.processeditor.stubs.PBSNode(graph, s.getObject()));\r
244         return ret;\r
245     }\r
246     \r
247     public void addChildStructure(ResourceContainer v) {\r
248         graph.addStatement(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasChildStructure, v.getResource());\r
249     }\r
250     \r
251     public org.simantics.proconf.g3d.stubs.G3DModel getGraphics() {\r
252         Statement[] statements = graph.getStatements(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasGraphics);\r
253         if(statements.length > 1)\r
254             throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + statements.length + ") of statements.");\r
255         if(statements.length == 0)\r
256             return null;\r
257         return new org.simantics.proconf.g3d.stubs.G3DModel(graph, statements[0].getObject());\r
258     }\r
259     \r
260     public void addGraphics(ResourceContainer v) {\r
261         graph.addStatement(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasGraphics, v.getResource());\r
262     }\r
263     \r
264     public void setGraphics(ResourceContainer v) {\r
265         Resource predicate = org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasGraphics;\r
266         graph.removeStatements(resource, predicate);\r
267         graph.addStatement(resource, predicate, v.getResource());\r
268     }\r
269     \r
270     public double[] getPipeDiameter() {\r
271         Statement[] statements = graph.getStatements(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasPipeDiameter);\r
272         if(statements.length != 1)\r
273             throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + statements.length + ") of statements.");\r
274         return (double[])graph.getValueAsObject(statements[0].getObject());\r
275     }\r
276     \r
277     public void setPipeDiameter(Object v) {\r
278         Resource predicate = org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasPipeDiameter;\r
279         Collection<Resource> objects = graph.getObjects(resource, predicate);\r
280         if(objects.size() == 0) {\r
281             Resource r = graph.newResource();\r
282         Resource valueType = org.simantics.db.Builtins.getInstance(graph).Double;\r
283             graph.addStatement(r, graph.getBuiltins().InstanceOf, valueType);\r
284             graph.setValueAsObject(r, v);\r
285             graph.addStatement(resource, predicate, r);\r
286         }\r
287         else if(objects.size() == 1)\r
288             for(Resource r : objects)\r
289                 graph.setValueAsObject(r, v);\r
290         else\r
291             throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + objects.size() + ") of statements.");\r
292     }\r
293     \r
294     public double[] getTurnRadius() {\r
295         Statement[] statements = graph.getStatements(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasTurnRadius);\r
296         if(statements.length != 1)\r
297             throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + statements.length + ") of statements.");\r
298         return (double[])graph.getValueAsObject(statements[0].getObject());\r
299     }\r
300     \r
301     public void setTurnRadius(Object v) {\r
302         Resource predicate = org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasTurnRadius;\r
303         Collection<Resource> objects = graph.getObjects(resource, predicate);\r
304         if(objects.size() == 0) {\r
305             Resource r = graph.newResource();\r
306         Resource valueType = org.simantics.db.Builtins.getInstance(graph).Double;\r
307             graph.addStatement(r, graph.getBuiltins().InstanceOf, valueType);\r
308             graph.setValueAsObject(r, v);\r
309             graph.addStatement(resource, predicate, r);\r
310         }\r
311         else if(objects.size() == 1)\r
312             for(Resource r : objects)\r
313                 graph.setValueAsObject(r, v);\r
314         else\r
315             throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + objects.size() + ") of statements.");\r
316     }\r
317     \r
318     public org.simantics.processeditor.stubs.PipeControlPoint getControlPoint() {\r
319         Statement[] statements = graph.getStatements(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasControlPoint);\r
320         if(statements.length > 1)\r
321             throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + statements.length + ") of statements.");\r
322         if(statements.length == 0)\r
323             return null;\r
324         return new org.simantics.processeditor.stubs.PipeControlPoint(graph, statements[0].getObject());\r
325     }\r
326     \r
327     public void addControlPoint(ResourceContainer v) {\r
328         graph.addStatement(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasControlPoint, v.getResource());\r
329     }\r
330     \r
331     public void setControlPoint(ResourceContainer v) {\r
332         Resource predicate = org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasControlPoint;\r
333         graph.removeStatements(resource, predicate);\r
334         graph.addStatement(resource, predicate, v.getResource());\r
335     }\r
336     \r
337     public double[] getTurnAngle() {\r
338         Statement[] statements = graph.getStatements(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasTurnAngle);\r
339         if(statements.length != 1)\r
340             throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + statements.length + ") of statements.");\r
341         return (double[])graph.getValueAsObject(statements[0].getObject());\r
342     }\r
343     \r
344     public void setTurnAngle(Object v) {\r
345         Resource predicate = org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasTurnAngle;\r
346         Collection<Resource> objects = graph.getObjects(resource, predicate);\r
347         if(objects.size() == 0) {\r
348             Resource r = graph.newResource();\r
349         Resource valueType = org.simantics.db.Builtins.getInstance(graph).Double;\r
350             graph.addStatement(r, graph.getBuiltins().InstanceOf, valueType);\r
351             graph.setValueAsObject(r, v);\r
352             graph.addStatement(resource, predicate, r);\r
353         }\r
354         else if(objects.size() == 1)\r
355             for(Resource r : objects)\r
356                 graph.setValueAsObject(r, v);\r
357         else\r
358             throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + objects.size() + ") of statements.");\r
359     }\r
360     \r
361 }\r
362 \r