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