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