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