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