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