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