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