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