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 VariableLengthControlPoint extends Entity implements IVariableLengthControlPoint {
\r
27 public VariableLengthControlPoint(Graph graph, ResourceContainer resourceContainer) {
\r
28 super(graph, resourceContainer.getResource());
\r
31 public VariableLengthControlPoint(IEntity entity) {
\r
32 super(entity.getGraph(), entity.getResource());
\r
35 public Graph getGraph() {
\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
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
50 public Resource getResource() {
\r
54 public VariableLengthControlPoint toVariableLengthControlPoint() {
\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 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
228 public void addSubPoint(ResourceContainer v) {
\r
229 graph.addStatement(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasSubPoint, v.getResource());
\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
238 return new org.simantics.processeditor.stubs.PipeControlPoint(graph, statements[0].getObject());
\r
241 public void addSubPointOf(ResourceContainer v) {
\r
242 graph.addStatement(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).SubPointOf, v.getResource());
\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
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
258 return new Entity(graph, statements[0].getObject());
\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
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
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
279 return new org.simantics.processeditor.stubs.PipeRun(graph, statements[0].getObject());
\r
282 public void addControlPointOfPipeRun(ResourceContainer v) {
\r
283 graph.addStatement(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).ControlPointOfPipeRun, v.getResource());
\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