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 FixedLengthControlPoint extends Entity implements IFixedLengthControlPoint {
\r
27 public FixedLengthControlPoint(Graph graph, ResourceContainer resourceContainer) {
\r
28 super(graph, resourceContainer.getResource());
\r
31 public FixedLengthControlPoint(IEntity entity) {
\r
32 super(entity.getGraph(), entity.getResource());
\r
35 public Graph getGraph() {
\r
39 public static FixedLengthControlPoint createDefault(Graph graph) {
\r
40 return new FixedLengthControlPoint(graph, InstanceFactory.instantiate(graph, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).FixedLengthControlPoint));
\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).FixedLengthControlPoint;
\r
46 return graph.isInstanceOf(entity.getResource(), type);
\r
50 public Resource getResource() {
\r
54 public FixedLengthControlPoint toFixedLengthControlPoint() {
\r
58 public org.simantics.processeditor.stubs.InlineControlPoint toInlineControlPoint() {
\r
59 return new org.simantics.processeditor.stubs.InlineControlPoint(graph, resource);
\r
62 public org.simantics.processeditor.stubs.PipeControlPoint toPipeControlPoint() {
\r
63 return new org.simantics.processeditor.stubs.PipeControlPoint(graph, resource);
\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
73 public void addLocalPosition(ResourceContainer v) {
\r
74 graph.addStatement(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasLocalPosition, v.getResource());
\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
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
90 public void addWorldPosition(ResourceContainer v) {
\r
91 graph.addStatement(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasWorldPosition, v.getResource());
\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
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
107 public void addLocalOrientation(ResourceContainer v) {
\r
108 graph.addStatement(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasLocalOrientation, v.getResource());
\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
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
124 public void addWorldOrientation(ResourceContainer v) {
\r
125 graph.addStatement(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasWorldOrientation, v.getResource());
\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
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
140 return new org.simantics.processeditor.stubs.PipeControlPoint(graph, statements[0].getObject());
\r
143 public void addNext(ResourceContainer v) {
\r
144 graph.addStatement(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasNext, v.getResource());
\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
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
159 return new org.simantics.processeditor.stubs.PipeControlPoint(graph, statements[0].getObject());
\r
162 public void addPrevious(ResourceContainer v) {
\r
163 graph.addStatement(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasPrevious, v.getResource());
\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
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
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
189 else if(objects.size() == 1)
\r
190 for(Resource r : objects)
\r
191 graph.setValueAsObject(r, v);
\r
193 throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + objects.size() + ") of statements.");
\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
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
213 else if(objects.size() == 1)
\r
214 for(Resource r : objects)
\r
215 graph.setValueAsObject(r, v);
\r
217 throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + objects.size() + ") of statements.");
\r
220 public double[] getRotationAngle() {
\r
221 Statement[] statements = graph.getStatements(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasRotationAngle);
\r
222 if(statements.length != 1)
\r
223 throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + statements.length + ") of statements.");
\r
224 return (double[])graph.getValueAsObject(statements[0].getObject());
\r
227 public void setRotationAngle(Object v) {
\r
228 Resource predicate = org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasRotationAngle;
\r
229 Collection<Resource> objects = graph.getObjects(resource, predicate);
\r
230 if(objects.size() == 0) {
\r
231 Resource r = graph.newResource();
\r
232 Resource valueType = org.simantics.db.Builtins.getInstance(graph).Double;
\r
233 graph.addStatement(r, graph.getBuiltins().InstanceOf, valueType);
\r
234 graph.setValueAsObject(r, v);
\r
235 graph.addStatement(resource, predicate, r);
\r
237 else if(objects.size() == 1)
\r
238 for(Resource r : objects)
\r
239 graph.setValueAsObject(r, v);
\r
241 throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + objects.size() + ") of statements.");
\r
244 public Collection<org.simantics.processeditor.stubs.PipeControlPoint> getSubPoint() {
\r
245 Statement[] statements = graph.getStatements(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasSubPoint);
\r
246 Collection<org.simantics.processeditor.stubs.PipeControlPoint> ret = new ArrayList<org.simantics.processeditor.stubs.PipeControlPoint>(statements.length);
\r
247 for(Statement s : statements)
\r
248 ret.add(new org.simantics.processeditor.stubs.PipeControlPoint(graph, s.getObject()));
\r
252 public void addSubPoint(ResourceContainer v) {
\r
253 graph.addStatement(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasSubPoint, v.getResource());
\r
256 public org.simantics.processeditor.stubs.PipeControlPoint getSubPointOf() {
\r
257 Statement[] statements = graph.getStatements(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).SubPointOf);
\r
258 if(statements.length > 1)
\r
259 throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + statements.length + ") of statements.");
\r
260 if(statements.length == 0)
\r
262 return new org.simantics.processeditor.stubs.PipeControlPoint(graph, statements[0].getObject());
\r
265 public void addSubPointOf(ResourceContainer v) {
\r
266 graph.addStatement(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).SubPointOf, v.getResource());
\r
269 public void setSubPointOf(ResourceContainer v) {
\r
270 Resource predicate = org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).SubPointOf;
\r
271 graph.removeStatements(resource, predicate);
\r
272 graph.addStatement(resource, predicate, v.getResource());
\r
275 // [Nozzle] | [Pipeline Component]
\r
276 public org.simantics.layer0.utils.IEntity getControlPointOf() {
\r
277 Statement[] statements = graph.getStatements(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).ControlPointOf);
\r
278 if(statements.length > 1)
\r
279 throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + statements.length + ") of statements.");
\r
280 if(statements.length == 0)
\r
282 return new Entity(graph, statements[0].getObject());
\r
285 // [Nozzle] | [Pipeline Component]
\r
286 public void addControlPointOf(ResourceContainer v) {
\r
287 graph.addStatement(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).ControlPointOf, v.getResource());
\r
290 // [Nozzle] | [Pipeline Component]
\r
291 public void setControlPointOf(ResourceContainer v) {
\r
292 Resource predicate = org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).ControlPointOf;
\r
293 graph.removeStatements(resource, predicate);
\r
294 graph.addStatement(resource, predicate, v.getResource());
\r
297 public org.simantics.processeditor.stubs.PipeRun getControlPointOfPipeRun() {
\r
298 Statement[] statements = graph.getStatements(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).ControlPointOfPipeRun);
\r
299 if(statements.length > 1)
\r
300 throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + statements.length + ") of statements.");
\r
301 if(statements.length == 0)
\r
303 return new org.simantics.processeditor.stubs.PipeRun(graph, statements[0].getObject());
\r
306 public void addControlPointOfPipeRun(ResourceContainer v) {
\r
307 graph.addStatement(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).ControlPointOfPipeRun, v.getResource());
\r
310 public void setControlPointOfPipeRun(ResourceContainer v) {
\r
311 Resource predicate = org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).ControlPointOfPipeRun;
\r
312 graph.removeStatements(resource, predicate);
\r
313 graph.addStatement(resource, predicate, v.getResource());
\r