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
9 * VTT Technical Research Centre of Finland - initial API and implementation
\r
10 *******************************************************************************/
\r
11 package org.simantics.processeditor.stubs;
\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
25 public class Straight extends Entity implements IStraight {
\r
27 public Straight(Graph graph, ResourceContainer resourceContainer) {
\r
28 super(graph, resourceContainer.getResource());
\r
31 public Straight(IEntity entity) {
\r
32 super(entity.getGraph(), entity.getResource());
\r
35 public Graph getGraph() {
\r
39 public static Straight createDefault(Graph graph) {
\r
40 return new Straight(graph, InstanceFactory.instantiate(graph, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).Straight));
\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).Straight;
\r
46 return graph.isInstanceOf(entity.getResource(), type);
\r
50 public Resource getResource() {
\r
54 public org.simantics.processeditor.stubs.CodedComponent toCodedComponent() {
\r
55 return new org.simantics.processeditor.stubs.CodedComponent(graph, resource);
\r
58 public org.simantics.proconf.g3d.stubs.G3DNode toG3DNode() {
\r
59 return new org.simantics.proconf.g3d.stubs.G3DNode(graph, resource);
\r
62 public org.simantics.processeditor.stubs.InlineComponent toInlineComponent() {
\r
63 return new org.simantics.processeditor.stubs.InlineComponent(graph, resource);
\r
66 public org.simantics.processeditor.stubs.PBSNode toPBSNode() {
\r
67 return new org.simantics.processeditor.stubs.PBSNode(graph, resource);
\r
70 public org.simantics.processeditor.stubs.P3DNode toP3DNode() {
\r
71 return new org.simantics.processeditor.stubs.P3DNode(graph, resource);
\r
74 public org.simantics.processeditor.stubs.DualConnectedComponent toDualConnectedComponent() {
\r
75 return new org.simantics.processeditor.stubs.DualConnectedComponent(graph, resource);
\r
78 public org.simantics.processeditor.stubs.VariableLengthInlineComponent toVariableLengthInlineComponent() {
\r
79 return new org.simantics.processeditor.stubs.VariableLengthInlineComponent(graph, resource);
\r
82 public org.simantics.processeditor.stubs.PipelineComponent toPipelineComponent() {
\r
83 return new org.simantics.processeditor.stubs.PipelineComponent(graph, resource);
\r
86 public org.simantics.processeditor.stubs.LibraryComponent toLibraryComponent() {
\r
87 return new org.simantics.processeditor.stubs.LibraryComponent(graph, resource);
\r
90 public Straight toStraight() {
\r
94 public Collection<org.simantics.proconf.g3d.stubs.G3DNode> getChild() {
\r
95 Statement[] statements = graph.getStatements(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasChild);
\r
96 Collection<org.simantics.proconf.g3d.stubs.G3DNode> ret = new ArrayList<org.simantics.proconf.g3d.stubs.G3DNode>(statements.length);
\r
97 for(Statement s : statements)
\r
98 ret.add(new org.simantics.proconf.g3d.stubs.G3DNode(graph, s.getObject()));
\r
102 public void addChild(ResourceContainer v) {
\r
103 graph.addStatement(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasChild, v.getResource());
\r
106 public org.simantics.proconf.g3d.stubs.G3DNode getParent() {
\r
107 Statement[] statements = graph.getStatements(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasParent);
\r
108 if(statements.length > 1)
\r
109 throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + statements.length + ") of statements.");
\r
110 if(statements.length == 0)
\r
112 return new org.simantics.proconf.g3d.stubs.G3DNode(graph, statements[0].getObject());
\r
115 public void addParent(ResourceContainer v) {
\r
116 graph.addStatement(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasParent, v.getResource());
\r
119 public void setParent(ResourceContainer v) {
\r
120 Resource predicate = org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasParent;
\r
121 graph.removeStatements(resource, predicate);
\r
122 graph.addStatement(resource, predicate, v.getResource());
\r
125 public org.simantics.proconf.g3d.stubs.Position getLocalPosition() {
\r
126 Statement[] statements = graph.getStatements(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasLocalPosition);
\r
127 if(statements.length > 1)
\r
128 throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + statements.length + ") of statements.");
\r
129 if(statements.length == 0)
\r
131 return new org.simantics.proconf.g3d.stubs.Position(graph, statements[0].getObject());
\r
134 public void addLocalPosition(ResourceContainer v) {
\r
135 graph.addStatement(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasLocalPosition, v.getResource());
\r
138 public void setLocalPosition(ResourceContainer v) {
\r
139 Resource predicate = org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasLocalPosition;
\r
140 graph.removeStatements(resource, predicate);
\r
141 graph.addStatement(resource, predicate, v.getResource());
\r
144 public org.simantics.proconf.g3d.stubs.Position getWorldPosition() {
\r
145 Statement[] statements = graph.getStatements(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasWorldPosition);
\r
146 if(statements.length > 1)
\r
147 throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + statements.length + ") of statements.");
\r
148 if(statements.length == 0)
\r
150 return new org.simantics.proconf.g3d.stubs.Position(graph, statements[0].getObject());
\r
153 public void addWorldPosition(ResourceContainer v) {
\r
154 graph.addStatement(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasWorldPosition, v.getResource());
\r
157 public void setWorldPosition(ResourceContainer v) {
\r
158 Resource predicate = org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasWorldPosition;
\r
159 graph.removeStatements(resource, predicate);
\r
160 graph.addStatement(resource, predicate, v.getResource());
\r
163 public org.simantics.proconf.g3d.stubs.Orientation getLocalOrientation() {
\r
164 Statement[] statements = graph.getStatements(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasLocalOrientation);
\r
165 if(statements.length > 1)
\r
166 throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + statements.length + ") of statements.");
\r
167 if(statements.length == 0)
\r
169 return new org.simantics.proconf.g3d.stubs.Orientation(graph, statements[0].getObject());
\r
172 public void addLocalOrientation(ResourceContainer v) {
\r
173 graph.addStatement(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasLocalOrientation, v.getResource());
\r
176 public void setLocalOrientation(ResourceContainer v) {
\r
177 Resource predicate = org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasLocalOrientation;
\r
178 graph.removeStatements(resource, predicate);
\r
179 graph.addStatement(resource, predicate, v.getResource());
\r
182 public org.simantics.proconf.g3d.stubs.Orientation getWorldOrientation() {
\r
183 Statement[] statements = graph.getStatements(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasWorldOrientation);
\r
184 if(statements.length > 1)
\r
185 throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + statements.length + ") of statements.");
\r
186 if(statements.length == 0)
\r
188 return new org.simantics.proconf.g3d.stubs.Orientation(graph, statements[0].getObject());
\r
191 public void addWorldOrientation(ResourceContainer v) {
\r
192 graph.addStatement(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasWorldOrientation, v.getResource());
\r
195 public void setWorldOrientation(ResourceContainer v) {
\r
196 Resource predicate = org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasWorldOrientation;
\r
197 graph.removeStatements(resource, predicate);
\r
198 graph.addStatement(resource, predicate, v.getResource());
\r
201 public org.simantics.proconf.g3d.stubs.Center getCenter() {
\r
202 Statement[] statements = graph.getStatements(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasCenter);
\r
203 if(statements.length > 1)
\r
204 throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + statements.length + ") of statements.");
\r
205 if(statements.length == 0)
\r
207 return new org.simantics.proconf.g3d.stubs.Center(graph, statements[0].getObject());
\r
210 public void addCenter(ResourceContainer v) {
\r
211 graph.addStatement(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasCenter, v.getResource());
\r
214 public void setCenter(ResourceContainer v) {
\r
215 Resource predicate = org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasCenter;
\r
216 graph.removeStatements(resource, predicate);
\r
217 graph.addStatement(resource, predicate, v.getResource());
\r
220 public org.simantics.processeditor.stubs.PBSNode getParentStructure() {
\r
221 Statement[] statements = graph.getStatements(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasParentStructure);
\r
222 if(statements.length > 1)
\r
223 throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + statements.length + ") of statements.");
\r
224 if(statements.length == 0)
\r
226 return new org.simantics.processeditor.stubs.PBSNode(graph, statements[0].getObject());
\r
229 public void addParentStructure(ResourceContainer v) {
\r
230 graph.addStatement(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasParentStructure, v.getResource());
\r
233 public void setParentStructure(ResourceContainer v) {
\r
234 Resource predicate = org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasParentStructure;
\r
235 graph.removeStatements(resource, predicate);
\r
236 graph.addStatement(resource, predicate, v.getResource());
\r
239 public Collection<org.simantics.processeditor.stubs.PBSNode> getChildStructure() {
\r
240 Statement[] statements = graph.getStatements(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasChildStructure);
\r
241 Collection<org.simantics.processeditor.stubs.PBSNode> ret = new ArrayList<org.simantics.processeditor.stubs.PBSNode>(statements.length);
\r
242 for(Statement s : statements)
\r
243 ret.add(new org.simantics.processeditor.stubs.PBSNode(graph, s.getObject()));
\r
247 public void addChildStructure(ResourceContainer v) {
\r
248 graph.addStatement(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasChildStructure, v.getResource());
\r
251 public org.simantics.proconf.g3d.stubs.G3DModel getGraphics() {
\r
252 Statement[] statements = graph.getStatements(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasGraphics);
\r
253 if(statements.length > 1)
\r
254 throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + statements.length + ") of statements.");
\r
255 if(statements.length == 0)
\r
257 return new org.simantics.proconf.g3d.stubs.G3DModel(graph, statements[0].getObject());
\r
260 public void addGraphics(ResourceContainer v) {
\r
261 graph.addStatement(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasGraphics, v.getResource());
\r
264 public void setGraphics(ResourceContainer v) {
\r
265 Resource predicate = org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasGraphics;
\r
266 graph.removeStatements(resource, predicate);
\r
267 graph.addStatement(resource, predicate, v.getResource());
\r
270 public double[] getPipeDiameter() {
\r
271 Statement[] statements = graph.getStatements(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasPipeDiameter);
\r
272 if(statements.length != 1)
\r
273 throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + statements.length + ") of statements.");
\r
274 return (double[])graph.getValueAsObject(statements[0].getObject());
\r
277 public void setPipeDiameter(Object v) {
\r
278 Resource predicate = org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasPipeDiameter;
\r
279 Collection<Resource> objects = graph.getObjects(resource, predicate);
\r
280 if(objects.size() == 0) {
\r
281 Resource r = graph.newResource();
\r
282 Resource valueType = org.simantics.db.Builtins.getInstance(graph).Double;
\r
283 graph.addStatement(r, graph.getBuiltins().InstanceOf, valueType);
\r
284 graph.setValueAsObject(r, v);
\r
285 graph.addStatement(resource, predicate, r);
\r
287 else if(objects.size() == 1)
\r
288 for(Resource r : objects)
\r
289 graph.setValueAsObject(r, v);
\r
291 throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + objects.size() + ") of statements.");
\r
294 public double[] getLength() {
\r
295 Statement[] statements = graph.getStatements(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasLength);
\r
296 if(statements.length != 1)
\r
297 throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + statements.length + ") of statements.");
\r
298 return (double[])graph.getValueAsObject(statements[0].getObject());
\r
301 public void setLength(Object v) {
\r
302 Resource predicate = org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasLength;
\r
303 Collection<Resource> objects = graph.getObjects(resource, predicate);
\r
304 if(objects.size() == 0) {
\r
305 Resource r = graph.newResource();
\r
306 Resource valueType = org.simantics.db.Builtins.getInstance(graph).Double;
\r
307 graph.addStatement(r, graph.getBuiltins().InstanceOf, valueType);
\r
308 graph.setValueAsObject(r, v);
\r
309 graph.addStatement(resource, predicate, r);
\r
311 else if(objects.size() == 1)
\r
312 for(Resource r : objects)
\r
313 graph.setValueAsObject(r, v);
\r
315 throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + objects.size() + ") of statements.");
\r
318 public org.simantics.processeditor.stubs.PipeControlPoint getControlPoint() {
\r
319 Statement[] statements = graph.getStatements(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasControlPoint);
\r
320 if(statements.length > 1)
\r
321 throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + statements.length + ") of statements.");
\r
322 if(statements.length == 0)
\r
324 return new org.simantics.processeditor.stubs.PipeControlPoint(graph, statements[0].getObject());
\r
327 public void addControlPoint(ResourceContainer v) {
\r
328 graph.addStatement(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasControlPoint, v.getResource());
\r
331 public void setControlPoint(ResourceContainer v) {
\r
332 Resource predicate = org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasControlPoint;
\r
333 graph.removeStatements(resource, predicate);
\r
334 graph.addStatement(resource, predicate, v.getResource());
\r