]> gerrit.simantics Code Review - simantics/3d.git/blob
47ded7e2ea85d6d82633fdce9778ed2452328d31
[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 BranchEndControlPoint extends Entity implements IBranchEndControlPoint {\r
26     \r
27     public BranchEndControlPoint(Graph graph, ResourceContainer resourceContainer) {\r
28         super(graph, resourceContainer.getResource());\r
29     }\r
30     \r
31     public BranchEndControlPoint(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 BranchEndControlPoint createDefault(Graph graph) {\r
40         return new BranchEndControlPoint(graph, InstanceFactory.instantiate(graph, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).BranchEndControlPoint));\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).BranchEndControlPoint;\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 BranchEndControlPoint toBranchEndControlPoint() {\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 Collection<org.simantics.processeditor.stubs.PipeControlPoint> getSubPoint() {\r
205         Statement[] statements = graph.getStatements(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasSubPoint);\r
206         Collection<org.simantics.processeditor.stubs.PipeControlPoint> ret = new ArrayList<org.simantics.processeditor.stubs.PipeControlPoint>(statements.length);\r
207         for(Statement s : statements)\r
208             ret.add(new org.simantics.processeditor.stubs.PipeControlPoint(graph, s.getObject()));\r
209         return ret;\r
210     }\r
211     \r
212     public void addSubPoint(ResourceContainer v) {\r
213         graph.addStatement(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasSubPoint, v.getResource());\r
214     }\r
215     \r
216     public org.simantics.processeditor.stubs.PipeControlPoint getSubPointOf() {\r
217         Statement[] statements = graph.getStatements(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).SubPointOf);\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.PipeControlPoint(graph, statements[0].getObject());\r
223     }\r
224     \r
225     public void addSubPointOf(ResourceContainer v) {\r
226         graph.addStatement(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).SubPointOf, v.getResource());\r
227     }\r
228     \r
229     public void setSubPointOf(ResourceContainer v) {\r
230         Resource predicate = org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).SubPointOf;\r
231         graph.removeStatements(resource, predicate);\r
232         graph.addStatement(resource, predicate, v.getResource());\r
233     }\r
234     \r
235     // [Nozzle] | [Pipeline Component]\r
236     public org.simantics.layer0.utils.IEntity getControlPointOf() {\r
237         Statement[] statements = graph.getStatements(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).ControlPointOf);\r
238         if(statements.length > 1)\r
239             throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + statements.length + ") of statements.");\r
240         if(statements.length == 0)\r
241             return null;\r
242         return new Entity(graph, statements[0].getObject());\r
243     }\r
244     \r
245     // [Nozzle] | [Pipeline Component]\r
246     public void addControlPointOf(ResourceContainer v) {\r
247         graph.addStatement(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).ControlPointOf, v.getResource());\r
248     }\r
249     \r
250     // [Nozzle] | [Pipeline Component]\r
251     public void setControlPointOf(ResourceContainer v) {\r
252         Resource predicate = org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).ControlPointOf;\r
253         graph.removeStatements(resource, predicate);\r
254         graph.addStatement(resource, predicate, v.getResource());\r
255     }\r
256     \r
257     public org.simantics.processeditor.stubs.PipeRun getControlPointOfPipeRun() {\r
258         Statement[] statements = graph.getStatements(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).ControlPointOfPipeRun);\r
259         if(statements.length > 1)\r
260             throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + statements.length + ") of statements.");\r
261         if(statements.length == 0)\r
262             return null;\r
263         return new org.simantics.processeditor.stubs.PipeRun(graph, statements[0].getObject());\r
264     }\r
265     \r
266     public void addControlPointOfPipeRun(ResourceContainer v) {\r
267         graph.addStatement(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).ControlPointOfPipeRun, v.getResource());\r
268     }\r
269     \r
270     public void setControlPointOfPipeRun(ResourceContainer v) {\r
271         Resource predicate = org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).ControlPointOfPipeRun;\r
272         graph.removeStatements(resource, predicate);\r
273         graph.addStatement(resource, predicate, v.getResource());\r
274     }\r
275     \r
276 }\r
277 \r