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 FixedAngleTurnComponent extends Entity implements IFixedAngleTurnComponent {
\r
27 public FixedAngleTurnComponent(Graph graph, ResourceContainer resourceContainer) {
\r
28 super(graph, resourceContainer.getResource());
\r
31 public FixedAngleTurnComponent(IEntity entity) {
\r
32 super(entity.getGraph(), entity.getResource());
\r
35 public Graph getGraph() {
\r
39 public static FixedAngleTurnComponent createDefault(Graph graph) {
\r
40 return new FixedAngleTurnComponent(graph, InstanceFactory.instantiate(graph, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).FixedAngleTurnComponent));
\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).FixedAngleTurnComponent;
\r
46 return graph.isInstanceOf(entity.getResource(), type);
\r
50 public Resource getResource() {
\r
54 public org.simantics.proconf.g3d.stubs.G3DNode toG3DNode() {
\r
55 return new org.simantics.proconf.g3d.stubs.G3DNode(graph, resource);
\r
58 public org.simantics.processeditor.stubs.PBSNode toPBSNode() {
\r
59 return new org.simantics.processeditor.stubs.PBSNode(graph, resource);
\r
62 public org.simantics.processeditor.stubs.P3DNode toP3DNode() {
\r
63 return new org.simantics.processeditor.stubs.P3DNode(graph, resource);
\r
66 public FixedAngleTurnComponent toFixedAngleTurnComponent() {
\r
70 public org.simantics.processeditor.stubs.PipelineComponent toPipelineComponent() {
\r
71 return new org.simantics.processeditor.stubs.PipelineComponent(graph, resource);
\r
74 public org.simantics.processeditor.stubs.LibraryComponent toLibraryComponent() {
\r
75 return new org.simantics.processeditor.stubs.LibraryComponent(graph, resource);
\r
78 public org.simantics.processeditor.stubs.TurnComponent toTurnComponent() {
\r
79 return new org.simantics.processeditor.stubs.TurnComponent(graph, resource);
\r
82 public Collection<org.simantics.proconf.g3d.stubs.G3DNode> getChild() {
\r
83 Statement[] statements = graph.getStatements(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasChild);
\r
84 Collection<org.simantics.proconf.g3d.stubs.G3DNode> ret = new ArrayList<org.simantics.proconf.g3d.stubs.G3DNode>(statements.length);
\r
85 for(Statement s : statements)
\r
86 ret.add(new org.simantics.proconf.g3d.stubs.G3DNode(graph, s.getObject()));
\r
90 public void addChild(ResourceContainer v) {
\r
91 graph.addStatement(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasChild, v.getResource());
\r
94 public org.simantics.proconf.g3d.stubs.G3DNode getParent() {
\r
95 Statement[] statements = graph.getStatements(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasParent);
\r
96 if(statements.length > 1)
\r
97 throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + statements.length + ") of statements.");
\r
98 if(statements.length == 0)
\r
100 return new org.simantics.proconf.g3d.stubs.G3DNode(graph, statements[0].getObject());
\r
103 public void addParent(ResourceContainer v) {
\r
104 graph.addStatement(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasParent, v.getResource());
\r
107 public void setParent(ResourceContainer v) {
\r
108 Resource predicate = org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasParent;
\r
109 graph.removeStatements(resource, predicate);
\r
110 graph.addStatement(resource, predicate, v.getResource());
\r
113 public org.simantics.proconf.g3d.stubs.Position getLocalPosition() {
\r
114 Statement[] statements = graph.getStatements(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasLocalPosition);
\r
115 if(statements.length > 1)
\r
116 throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + statements.length + ") of statements.");
\r
117 if(statements.length == 0)
\r
119 return new org.simantics.proconf.g3d.stubs.Position(graph, statements[0].getObject());
\r
122 public void addLocalPosition(ResourceContainer v) {
\r
123 graph.addStatement(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasLocalPosition, v.getResource());
\r
126 public void setLocalPosition(ResourceContainer v) {
\r
127 Resource predicate = org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasLocalPosition;
\r
128 graph.removeStatements(resource, predicate);
\r
129 graph.addStatement(resource, predicate, v.getResource());
\r
132 public org.simantics.proconf.g3d.stubs.Position getWorldPosition() {
\r
133 Statement[] statements = graph.getStatements(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasWorldPosition);
\r
134 if(statements.length > 1)
\r
135 throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + statements.length + ") of statements.");
\r
136 if(statements.length == 0)
\r
138 return new org.simantics.proconf.g3d.stubs.Position(graph, statements[0].getObject());
\r
141 public void addWorldPosition(ResourceContainer v) {
\r
142 graph.addStatement(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasWorldPosition, v.getResource());
\r
145 public void setWorldPosition(ResourceContainer v) {
\r
146 Resource predicate = org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasWorldPosition;
\r
147 graph.removeStatements(resource, predicate);
\r
148 graph.addStatement(resource, predicate, v.getResource());
\r
151 public org.simantics.proconf.g3d.stubs.Orientation getLocalOrientation() {
\r
152 Statement[] statements = graph.getStatements(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasLocalOrientation);
\r
153 if(statements.length > 1)
\r
154 throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + statements.length + ") of statements.");
\r
155 if(statements.length == 0)
\r
157 return new org.simantics.proconf.g3d.stubs.Orientation(graph, statements[0].getObject());
\r
160 public void addLocalOrientation(ResourceContainer v) {
\r
161 graph.addStatement(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasLocalOrientation, v.getResource());
\r
164 public void setLocalOrientation(ResourceContainer v) {
\r
165 Resource predicate = org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasLocalOrientation;
\r
166 graph.removeStatements(resource, predicate);
\r
167 graph.addStatement(resource, predicate, v.getResource());
\r
170 public org.simantics.proconf.g3d.stubs.Orientation getWorldOrientation() {
\r
171 Statement[] statements = graph.getStatements(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasWorldOrientation);
\r
172 if(statements.length > 1)
\r
173 throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + statements.length + ") of statements.");
\r
174 if(statements.length == 0)
\r
176 return new org.simantics.proconf.g3d.stubs.Orientation(graph, statements[0].getObject());
\r
179 public void addWorldOrientation(ResourceContainer v) {
\r
180 graph.addStatement(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasWorldOrientation, v.getResource());
\r
183 public void setWorldOrientation(ResourceContainer v) {
\r
184 Resource predicate = org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasWorldOrientation;
\r
185 graph.removeStatements(resource, predicate);
\r
186 graph.addStatement(resource, predicate, v.getResource());
\r
189 public org.simantics.proconf.g3d.stubs.Center getCenter() {
\r
190 Statement[] statements = graph.getStatements(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasCenter);
\r
191 if(statements.length > 1)
\r
192 throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + statements.length + ") of statements.");
\r
193 if(statements.length == 0)
\r
195 return new org.simantics.proconf.g3d.stubs.Center(graph, statements[0].getObject());
\r
198 public void addCenter(ResourceContainer v) {
\r
199 graph.addStatement(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasCenter, v.getResource());
\r
202 public void setCenter(ResourceContainer v) {
\r
203 Resource predicate = org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasCenter;
\r
204 graph.removeStatements(resource, predicate);
\r
205 graph.addStatement(resource, predicate, v.getResource());
\r
208 public org.simantics.processeditor.stubs.PBSNode getParentStructure() {
\r
209 Statement[] statements = graph.getStatements(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasParentStructure);
\r
210 if(statements.length > 1)
\r
211 throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + statements.length + ") of statements.");
\r
212 if(statements.length == 0)
\r
214 return new org.simantics.processeditor.stubs.PBSNode(graph, statements[0].getObject());
\r
217 public void addParentStructure(ResourceContainer v) {
\r
218 graph.addStatement(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasParentStructure, v.getResource());
\r
221 public void setParentStructure(ResourceContainer v) {
\r
222 Resource predicate = org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasParentStructure;
\r
223 graph.removeStatements(resource, predicate);
\r
224 graph.addStatement(resource, predicate, v.getResource());
\r
227 public Collection<org.simantics.processeditor.stubs.PBSNode> getChildStructure() {
\r
228 Statement[] statements = graph.getStatements(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasChildStructure);
\r
229 Collection<org.simantics.processeditor.stubs.PBSNode> ret = new ArrayList<org.simantics.processeditor.stubs.PBSNode>(statements.length);
\r
230 for(Statement s : statements)
\r
231 ret.add(new org.simantics.processeditor.stubs.PBSNode(graph, s.getObject()));
\r
235 public void addChildStructure(ResourceContainer v) {
\r
236 graph.addStatement(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasChildStructure, v.getResource());
\r
239 public org.simantics.proconf.g3d.stubs.G3DModel getGraphics() {
\r
240 Statement[] statements = graph.getStatements(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasGraphics);
\r
241 if(statements.length > 1)
\r
242 throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + statements.length + ") of statements.");
\r
243 if(statements.length == 0)
\r
245 return new org.simantics.proconf.g3d.stubs.G3DModel(graph, statements[0].getObject());
\r
248 public void addGraphics(ResourceContainer v) {
\r
249 graph.addStatement(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasGraphics, v.getResource());
\r
252 public void setGraphics(ResourceContainer v) {
\r
253 Resource predicate = org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasGraphics;
\r
254 graph.removeStatements(resource, predicate);
\r
255 graph.addStatement(resource, predicate, v.getResource());
\r
258 public double[] getPipeDiameter() {
\r
259 Statement[] statements = graph.getStatements(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasPipeDiameter);
\r
260 if(statements.length != 1)
\r
261 throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + statements.length + ") of statements.");
\r
262 return (double[])graph.getValueAsObject(statements[0].getObject());
\r
265 public void setPipeDiameter(Object v) {
\r
266 Resource predicate = org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasPipeDiameter;
\r
267 Collection<Resource> objects = graph.getObjects(resource, predicate);
\r
268 if(objects.size() == 0) {
\r
269 Resource r = graph.newResource();
\r
270 Resource valueType = org.simantics.db.Builtins.getInstance(graph).Double;
\r
271 graph.addStatement(r, graph.getBuiltins().InstanceOf, valueType);
\r
272 graph.setValueAsObject(r, v);
\r
273 graph.addStatement(resource, predicate, r);
\r
275 else if(objects.size() == 1)
\r
276 for(Resource r : objects)
\r
277 graph.setValueAsObject(r, v);
\r
279 throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + objects.size() + ") of statements.");
\r
282 public org.simantics.processeditor.stubs.PipeControlPoint getControlPoint() {
\r
283 Statement[] statements = graph.getStatements(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasControlPoint);
\r
284 if(statements.length > 1)
\r
285 throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + statements.length + ") of statements.");
\r
286 if(statements.length == 0)
\r
288 return new org.simantics.processeditor.stubs.PipeControlPoint(graph, statements[0].getObject());
\r
291 public void addControlPoint(ResourceContainer v) {
\r
292 graph.addStatement(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasControlPoint, v.getResource());
\r
295 public void setControlPoint(ResourceContainer v) {
\r
296 Resource predicate = org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasControlPoint;
\r
297 graph.removeStatements(resource, predicate);
\r
298 graph.addStatement(resource, predicate, v.getResource());
\r
301 public double[] getTurnAngle() {
\r
302 Statement[] statements = graph.getStatements(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasTurnAngle);
\r
303 if(statements.length != 1)
\r
304 throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + statements.length + ") of statements.");
\r
305 return (double[])graph.getValueAsObject(statements[0].getObject());
\r
308 public void setTurnAngle(Object v) {
\r
309 Resource predicate = org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasTurnAngle;
\r
310 Collection<Resource> objects = graph.getObjects(resource, predicate);
\r
311 if(objects.size() == 0) {
\r
312 Resource r = graph.newResource();
\r
313 Resource valueType = org.simantics.db.Builtins.getInstance(graph).Double;
\r
314 graph.addStatement(r, graph.getBuiltins().InstanceOf, valueType);
\r
315 graph.setValueAsObject(r, v);
\r
316 graph.addStatement(resource, predicate, r);
\r
318 else if(objects.size() == 1)
\r
319 for(Resource r : objects)
\r
320 graph.setValueAsObject(r, v);
\r
322 throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + objects.size() + ") of statements.");
\r
325 public double[] getRotationAngle() {
\r
326 Statement[] statements = graph.getStatements(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasRotationAngle);
\r
327 if(statements.length != 1)
\r
328 throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + statements.length + ") of statements.");
\r
329 return (double[])graph.getValueAsObject(statements[0].getObject());
\r
332 public void setRotationAngle(Object v) {
\r
333 Resource predicate = org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasRotationAngle;
\r
334 Collection<Resource> objects = graph.getObjects(resource, predicate);
\r
335 if(objects.size() == 0) {
\r
336 Resource r = graph.newResource();
\r
337 Resource valueType = org.simantics.db.Builtins.getInstance(graph).Double;
\r
338 graph.addStatement(r, graph.getBuiltins().InstanceOf, valueType);
\r
339 graph.setValueAsObject(r, v);
\r
340 graph.addStatement(resource, predicate, r);
\r
342 else if(objects.size() == 1)
\r
343 for(Resource r : objects)
\r
344 graph.setValueAsObject(r, v);
\r
346 throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + objects.size() + ") of statements.");
\r