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 EndComponentControlPoint extends Entity implements IEndComponentControlPoint {
\r
27 public EndComponentControlPoint(Graph graph, ResourceContainer resourceContainer) {
\r
28 super(graph, resourceContainer.getResource());
\r
31 public EndComponentControlPoint(IEntity entity) {
\r
32 super(entity.getGraph(), entity.getResource());
\r
35 public Graph getGraph() {
\r
39 public static EndComponentControlPoint createDefault(Graph graph) {
\r
40 return new EndComponentControlPoint(graph, InstanceFactory.instantiate(graph, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).EndComponentControlPoint));
\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).EndComponentControlPoint;
\r
46 return graph.isInstanceOf(entity.getResource(), type);
\r
50 public Resource getResource() {
\r
54 public org.simantics.processeditor.stubs.PathLegEndControlPoint toPathLegEndControlPoint() {
\r
55 return new org.simantics.processeditor.stubs.PathLegEndControlPoint(graph, resource);
\r
58 public org.simantics.processeditor.stubs.RunEndControlPoint toRunEndControlPoint() {
\r
59 return new org.simantics.processeditor.stubs.RunEndControlPoint(graph, resource);
\r
62 public EndComponentControlPoint toEndComponentControlPoint() {
\r
66 public org.simantics.processeditor.stubs.UndirectedControlPoint toUndirectedControlPoint() {
\r
67 return new org.simantics.processeditor.stubs.UndirectedControlPoint(graph, resource);
\r
70 public org.simantics.processeditor.stubs.PipeControlPoint toPipeControlPoint() {
\r
71 return new org.simantics.processeditor.stubs.PipeControlPoint(graph, resource);
\r
74 public org.simantics.proconf.g3d.stubs.Position getLocalPosition() {
\r
75 Statement[] statements = graph.getStatements(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasLocalPosition);
\r
76 if(statements.length != 1)
\r
77 throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + statements.length + ") of statements.");
\r
78 return new org.simantics.proconf.g3d.stubs.Position(graph, statements[0].getObject());
\r
81 public void addLocalPosition(ResourceContainer v) {
\r
82 graph.addStatement(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasLocalPosition, v.getResource());
\r
85 public void setLocalPosition(ResourceContainer v) {
\r
86 Resource predicate = org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasLocalPosition;
\r
87 graph.removeStatements(resource, predicate);
\r
88 graph.addStatement(resource, predicate, v.getResource());
\r
91 public org.simantics.proconf.g3d.stubs.Position getWorldPosition() {
\r
92 Statement[] statements = graph.getStatements(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasWorldPosition);
\r
93 if(statements.length != 1)
\r
94 throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + statements.length + ") of statements.");
\r
95 return new org.simantics.proconf.g3d.stubs.Position(graph, statements[0].getObject());
\r
98 public void addWorldPosition(ResourceContainer v) {
\r
99 graph.addStatement(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasWorldPosition, v.getResource());
\r
102 public void setWorldPosition(ResourceContainer v) {
\r
103 Resource predicate = org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasWorldPosition;
\r
104 graph.removeStatements(resource, predicate);
\r
105 graph.addStatement(resource, predicate, v.getResource());
\r
108 public org.simantics.proconf.g3d.stubs.Orientation getLocalOrientation() {
\r
109 Statement[] statements = graph.getStatements(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasLocalOrientation);
\r
110 if(statements.length != 1)
\r
111 throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + statements.length + ") of statements.");
\r
112 return new org.simantics.proconf.g3d.stubs.Orientation(graph, statements[0].getObject());
\r
115 public void addLocalOrientation(ResourceContainer v) {
\r
116 graph.addStatement(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasLocalOrientation, v.getResource());
\r
119 public void setLocalOrientation(ResourceContainer v) {
\r
120 Resource predicate = org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasLocalOrientation;
\r
121 graph.removeStatements(resource, predicate);
\r
122 graph.addStatement(resource, predicate, v.getResource());
\r
125 public org.simantics.proconf.g3d.stubs.Orientation getWorldOrientation() {
\r
126 Statement[] statements = graph.getStatements(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasWorldOrientation);
\r
127 if(statements.length != 1)
\r
128 throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + statements.length + ") of statements.");
\r
129 return new org.simantics.proconf.g3d.stubs.Orientation(graph, statements[0].getObject());
\r
132 public void addWorldOrientation(ResourceContainer v) {
\r
133 graph.addStatement(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasWorldOrientation, v.getResource());
\r
136 public void setWorldOrientation(ResourceContainer v) {
\r
137 Resource predicate = org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasWorldOrientation;
\r
138 graph.removeStatements(resource, predicate);
\r
139 graph.addStatement(resource, predicate, v.getResource());
\r
142 public org.simantics.processeditor.stubs.PipeControlPoint getNext() {
\r
143 Statement[] statements = graph.getStatements(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasNext);
\r
144 if(statements.length > 1)
\r
145 throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + statements.length + ") of statements.");
\r
146 if(statements.length == 0)
\r
148 return new org.simantics.processeditor.stubs.PipeControlPoint(graph, statements[0].getObject());
\r
151 public void addNext(ResourceContainer v) {
\r
152 graph.addStatement(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasNext, v.getResource());
\r
155 public void setNext(ResourceContainer v) {
\r
156 Resource predicate = org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasNext;
\r
157 graph.removeStatements(resource, predicate);
\r
158 graph.addStatement(resource, predicate, v.getResource());
\r
161 public org.simantics.processeditor.stubs.PipeControlPoint getPrevious() {
\r
162 Statement[] statements = graph.getStatements(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasPrevious);
\r
163 if(statements.length > 1)
\r
164 throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + statements.length + ") of statements.");
\r
165 if(statements.length == 0)
\r
167 return new org.simantics.processeditor.stubs.PipeControlPoint(graph, statements[0].getObject());
\r
170 public void addPrevious(ResourceContainer v) {
\r
171 graph.addStatement(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasPrevious, v.getResource());
\r
174 public void setPrevious(ResourceContainer v) {
\r
175 Resource predicate = org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasPrevious;
\r
176 graph.removeStatements(resource, predicate);
\r
177 graph.addStatement(resource, predicate, v.getResource());
\r
180 public double[] getPipeDiameter() {
\r
181 Statement[] statements = graph.getStatements(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasPipeDiameter);
\r
182 if(statements.length != 1)
\r
183 throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + statements.length + ") of statements.");
\r
184 return (double[])graph.getValueAsObject(statements[0].getObject());
\r
187 public void setPipeDiameter(Object v) {
\r
188 Resource predicate = org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasPipeDiameter;
\r
189 Collection<Resource> objects = graph.getObjects(resource, predicate);
\r
190 if(objects.size() == 0) {
\r
191 Resource r = graph.newResource();
\r
192 Resource valueType = org.simantics.db.Builtins.getInstance(graph).Double;
\r
193 graph.addStatement(r, graph.getBuiltins().InstanceOf, valueType);
\r
194 graph.setValueAsObject(r, v);
\r
195 graph.addStatement(resource, predicate, r);
\r
197 else if(objects.size() == 1)
\r
198 for(Resource r : objects)
\r
199 graph.setValueAsObject(r, v);
\r
201 throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + objects.size() + ") of statements.");
\r
204 public double[] getRotationAngle() {
\r
205 Statement[] statements = graph.getStatements(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasRotationAngle);
\r
206 if(statements.length != 1)
\r
207 throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + statements.length + ") of statements.");
\r
208 return (double[])graph.getValueAsObject(statements[0].getObject());
\r
211 public void setRotationAngle(Object v) {
\r
212 Resource predicate = org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasRotationAngle;
\r
213 Collection<Resource> objects = graph.getObjects(resource, predicate);
\r
214 if(objects.size() == 0) {
\r
215 Resource r = graph.newResource();
\r
216 Resource valueType = org.simantics.db.Builtins.getInstance(graph).Double;
\r
217 graph.addStatement(r, graph.getBuiltins().InstanceOf, valueType);
\r
218 graph.setValueAsObject(r, v);
\r
219 graph.addStatement(resource, predicate, r);
\r
221 else if(objects.size() == 1)
\r
222 for(Resource r : objects)
\r
223 graph.setValueAsObject(r, v);
\r
225 throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + objects.size() + ") of statements.");
\r
228 public Collection<org.simantics.processeditor.stubs.PipeControlPoint> getSubPoint() {
\r
229 Statement[] statements = graph.getStatements(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasSubPoint);
\r
230 Collection<org.simantics.processeditor.stubs.PipeControlPoint> ret = new ArrayList<org.simantics.processeditor.stubs.PipeControlPoint>(statements.length);
\r
231 for(Statement s : statements)
\r
232 ret.add(new org.simantics.processeditor.stubs.PipeControlPoint(graph, s.getObject()));
\r
236 public void addSubPoint(ResourceContainer v) {
\r
237 graph.addStatement(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasSubPoint, v.getResource());
\r
240 public org.simantics.processeditor.stubs.PipeControlPoint getSubPointOf() {
\r
241 Statement[] statements = graph.getStatements(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).SubPointOf);
\r
242 if(statements.length > 1)
\r
243 throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + statements.length + ") of statements.");
\r
244 if(statements.length == 0)
\r
246 return new org.simantics.processeditor.stubs.PipeControlPoint(graph, statements[0].getObject());
\r
249 public void addSubPointOf(ResourceContainer v) {
\r
250 graph.addStatement(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).SubPointOf, v.getResource());
\r
253 public void setSubPointOf(ResourceContainer v) {
\r
254 Resource predicate = org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).SubPointOf;
\r
255 graph.removeStatements(resource, predicate);
\r
256 graph.addStatement(resource, predicate, v.getResource());
\r
259 // [Nozzle] | [Pipeline Component]
\r
260 public org.simantics.layer0.utils.IEntity getControlPointOf() {
\r
261 Statement[] statements = graph.getStatements(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).ControlPointOf);
\r
262 if(statements.length > 1)
\r
263 throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + statements.length + ") of statements.");
\r
264 if(statements.length == 0)
\r
266 return new Entity(graph, statements[0].getObject());
\r
269 // [Nozzle] | [Pipeline Component]
\r
270 public void addControlPointOf(ResourceContainer v) {
\r
271 graph.addStatement(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).ControlPointOf, v.getResource());
\r
274 // [Nozzle] | [Pipeline Component]
\r
275 public void setControlPointOf(ResourceContainer v) {
\r
276 Resource predicate = org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).ControlPointOf;
\r
277 graph.removeStatements(resource, predicate);
\r
278 graph.addStatement(resource, predicate, v.getResource());
\r
281 public org.simantics.processeditor.stubs.PipeRun getControlPointOfPipeRun() {
\r
282 Statement[] statements = graph.getStatements(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).ControlPointOfPipeRun);
\r
283 if(statements.length > 1)
\r
284 throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + statements.length + ") of statements.");
\r
285 if(statements.length == 0)
\r
287 return new org.simantics.processeditor.stubs.PipeRun(graph, statements[0].getObject());
\r
290 public void addControlPointOfPipeRun(ResourceContainer v) {
\r
291 graph.addStatement(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).ControlPointOfPipeRun, v.getResource());
\r
294 public void setControlPointOfPipeRun(ResourceContainer v) {
\r
295 Resource predicate = org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).ControlPointOfPipeRun;
\r
296 graph.removeStatements(resource, predicate);
\r
297 graph.addStatement(resource, predicate, v.getResource());
\r