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