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 UndirectedControlPoint extends Entity implements IUndirectedControlPoint {
\r
27 public UndirectedControlPoint(Graph graph, ResourceContainer resourceContainer) {
\r
28 super(graph, resourceContainer.getResource());
\r
31 public UndirectedControlPoint(IEntity entity) {
\r
32 super(entity.getGraph(), entity.getResource());
\r
35 public Graph getGraph() {
\r
39 public static UndirectedControlPoint createDefault(Graph graph) {
\r
40 return new UndirectedControlPoint(graph, InstanceFactory.instantiate(graph, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).UndirectedControlPoint));
\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).UndirectedControlPoint;
\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 UndirectedControlPoint toUndirectedControlPoint() {
\r
66 public org.simantics.processeditor.stubs.PipeControlPoint toPipeControlPoint() {
\r
67 return new org.simantics.processeditor.stubs.PipeControlPoint(graph, resource);
\r
70 public org.simantics.proconf.g3d.stubs.Position getLocalPosition() {
\r
71 Statement[] statements = graph.getStatements(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasLocalPosition);
\r
72 if(statements.length != 1)
\r
73 throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + statements.length + ") of statements.");
\r
74 return new org.simantics.proconf.g3d.stubs.Position(graph, statements[0].getObject());
\r
77 public void addLocalPosition(ResourceContainer v) {
\r
78 graph.addStatement(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasLocalPosition, v.getResource());
\r
81 public void setLocalPosition(ResourceContainer v) {
\r
82 Resource predicate = org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasLocalPosition;
\r
83 graph.removeStatements(resource, predicate);
\r
84 graph.addStatement(resource, predicate, v.getResource());
\r
87 public org.simantics.proconf.g3d.stubs.Position getWorldPosition() {
\r
88 Statement[] statements = graph.getStatements(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasWorldPosition);
\r
89 if(statements.length != 1)
\r
90 throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + statements.length + ") of statements.");
\r
91 return new org.simantics.proconf.g3d.stubs.Position(graph, statements[0].getObject());
\r
94 public void addWorldPosition(ResourceContainer v) {
\r
95 graph.addStatement(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasWorldPosition, v.getResource());
\r
98 public void setWorldPosition(ResourceContainer v) {
\r
99 Resource predicate = org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasWorldPosition;
\r
100 graph.removeStatements(resource, predicate);
\r
101 graph.addStatement(resource, predicate, v.getResource());
\r
104 public org.simantics.proconf.g3d.stubs.Orientation getLocalOrientation() {
\r
105 Statement[] statements = graph.getStatements(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasLocalOrientation);
\r
106 if(statements.length != 1)
\r
107 throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + statements.length + ") of statements.");
\r
108 return new org.simantics.proconf.g3d.stubs.Orientation(graph, statements[0].getObject());
\r
111 public void addLocalOrientation(ResourceContainer v) {
\r
112 graph.addStatement(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasLocalOrientation, v.getResource());
\r
115 public void setLocalOrientation(ResourceContainer v) {
\r
116 Resource predicate = org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasLocalOrientation;
\r
117 graph.removeStatements(resource, predicate);
\r
118 graph.addStatement(resource, predicate, v.getResource());
\r
121 public org.simantics.proconf.g3d.stubs.Orientation getWorldOrientation() {
\r
122 Statement[] statements = graph.getStatements(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasWorldOrientation);
\r
123 if(statements.length != 1)
\r
124 throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + statements.length + ") of statements.");
\r
125 return new org.simantics.proconf.g3d.stubs.Orientation(graph, statements[0].getObject());
\r
128 public void addWorldOrientation(ResourceContainer v) {
\r
129 graph.addStatement(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasWorldOrientation, v.getResource());
\r
132 public void setWorldOrientation(ResourceContainer v) {
\r
133 Resource predicate = org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasWorldOrientation;
\r
134 graph.removeStatements(resource, predicate);
\r
135 graph.addStatement(resource, predicate, v.getResource());
\r
138 public org.simantics.processeditor.stubs.PipeControlPoint getNext() {
\r
139 Statement[] statements = graph.getStatements(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasNext);
\r
140 if(statements.length > 1)
\r
141 throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + statements.length + ") of statements.");
\r
142 if(statements.length == 0)
\r
144 return new org.simantics.processeditor.stubs.PipeControlPoint(graph, statements[0].getObject());
\r
147 public void addNext(ResourceContainer v) {
\r
148 graph.addStatement(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasNext, v.getResource());
\r
151 public void setNext(ResourceContainer v) {
\r
152 Resource predicate = org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasNext;
\r
153 graph.removeStatements(resource, predicate);
\r
154 graph.addStatement(resource, predicate, v.getResource());
\r
157 public org.simantics.processeditor.stubs.PipeControlPoint getPrevious() {
\r
158 Statement[] statements = graph.getStatements(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasPrevious);
\r
159 if(statements.length > 1)
\r
160 throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + statements.length + ") of statements.");
\r
161 if(statements.length == 0)
\r
163 return new org.simantics.processeditor.stubs.PipeControlPoint(graph, statements[0].getObject());
\r
166 public void addPrevious(ResourceContainer v) {
\r
167 graph.addStatement(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasPrevious, v.getResource());
\r
170 public void setPrevious(ResourceContainer v) {
\r
171 Resource predicate = org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasPrevious;
\r
172 graph.removeStatements(resource, predicate);
\r
173 graph.addStatement(resource, predicate, v.getResource());
\r
176 public double[] getPipeDiameter() {
\r
177 Statement[] statements = graph.getStatements(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasPipeDiameter);
\r
178 if(statements.length != 1)
\r
179 throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + statements.length + ") of statements.");
\r
180 return (double[])graph.getValueAsObject(statements[0].getObject());
\r
183 public void setPipeDiameter(Object v) {
\r
184 Resource predicate = org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasPipeDiameter;
\r
185 Collection<Resource> objects = graph.getObjects(resource, predicate);
\r
186 if(objects.size() == 0) {
\r
187 Resource r = graph.newResource();
\r
188 Resource valueType = org.simantics.db.Builtins.getInstance(graph).Double;
\r
189 graph.addStatement(r, graph.getBuiltins().InstanceOf, valueType);
\r
190 graph.setValueAsObject(r, v);
\r
191 graph.addStatement(resource, predicate, r);
\r
193 else if(objects.size() == 1)
\r
194 for(Resource r : objects)
\r
195 graph.setValueAsObject(r, v);
\r
197 throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + objects.size() + ") of statements.");
\r
200 public Collection<org.simantics.processeditor.stubs.PipeControlPoint> getSubPoint() {
\r
201 Statement[] statements = graph.getStatements(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasSubPoint);
\r
202 Collection<org.simantics.processeditor.stubs.PipeControlPoint> ret = new ArrayList<org.simantics.processeditor.stubs.PipeControlPoint>(statements.length);
\r
203 for(Statement s : statements)
\r
204 ret.add(new org.simantics.processeditor.stubs.PipeControlPoint(graph, s.getObject()));
\r
208 public void addSubPoint(ResourceContainer v) {
\r
209 graph.addStatement(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasSubPoint, v.getResource());
\r
212 public org.simantics.processeditor.stubs.PipeControlPoint getSubPointOf() {
\r
213 Statement[] statements = graph.getStatements(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).SubPointOf);
\r
214 if(statements.length > 1)
\r
215 throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + statements.length + ") of statements.");
\r
216 if(statements.length == 0)
\r
218 return new org.simantics.processeditor.stubs.PipeControlPoint(graph, statements[0].getObject());
\r
221 public void addSubPointOf(ResourceContainer v) {
\r
222 graph.addStatement(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).SubPointOf, v.getResource());
\r
225 public void setSubPointOf(ResourceContainer v) {
\r
226 Resource predicate = org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).SubPointOf;
\r
227 graph.removeStatements(resource, predicate);
\r
228 graph.addStatement(resource, predicate, v.getResource());
\r
231 // [Nozzle] | [Pipeline Component]
\r
232 public org.simantics.layer0.utils.IEntity getControlPointOf() {
\r
233 Statement[] statements = graph.getStatements(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).ControlPointOf);
\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 Entity(graph, statements[0].getObject());
\r
241 // [Nozzle] | [Pipeline Component]
\r
242 public void addControlPointOf(ResourceContainer v) {
\r
243 graph.addStatement(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).ControlPointOf, v.getResource());
\r
246 // [Nozzle] | [Pipeline Component]
\r
247 public void setControlPointOf(ResourceContainer v) {
\r
248 Resource predicate = org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).ControlPointOf;
\r
249 graph.removeStatements(resource, predicate);
\r
250 graph.addStatement(resource, predicate, v.getResource());
\r
253 public org.simantics.processeditor.stubs.PipeRun getControlPointOfPipeRun() {
\r
254 Statement[] statements = graph.getStatements(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).ControlPointOfPipeRun);
\r
255 if(statements.length > 1)
\r
256 throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + statements.length + ") of statements.");
\r
257 if(statements.length == 0)
\r
259 return new org.simantics.processeditor.stubs.PipeRun(graph, statements[0].getObject());
\r
262 public void addControlPointOfPipeRun(ResourceContainer v) {
\r
263 graph.addStatement(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).ControlPointOfPipeRun, v.getResource());
\r
266 public void setControlPointOfPipeRun(ResourceContainer v) {
\r
267 Resource predicate = org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).ControlPointOfPipeRun;
\r
268 graph.removeStatements(resource, predicate);
\r
269 graph.addStatement(resource, predicate, v.getResource());
\r