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