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 BranchEndControlPoint extends Entity implements IBranchEndControlPoint {
\r
27 public BranchEndControlPoint(Graph graph, ResourceContainer resourceContainer) {
\r
28 super(graph, resourceContainer.getResource());
\r
31 public BranchEndControlPoint(IEntity entity) {
\r
32 super(entity.getGraph(), entity.getResource());
\r
35 public Graph getGraph() {
\r
39 public static BranchEndControlPoint createDefault(Graph graph) {
\r
40 return new BranchEndControlPoint(graph, InstanceFactory.instantiate(graph, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).BranchEndControlPoint));
\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).BranchEndControlPoint;
\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 BranchEndControlPoint toBranchEndControlPoint() {
\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 Collection<org.simantics.processeditor.stubs.PipeControlPoint> getSubPoint() {
\r
205 Statement[] statements = graph.getStatements(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasSubPoint);
\r
206 Collection<org.simantics.processeditor.stubs.PipeControlPoint> ret = new ArrayList<org.simantics.processeditor.stubs.PipeControlPoint>(statements.length);
\r
207 for(Statement s : statements)
\r
208 ret.add(new org.simantics.processeditor.stubs.PipeControlPoint(graph, s.getObject()));
\r
212 public void addSubPoint(ResourceContainer v) {
\r
213 graph.addStatement(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasSubPoint, v.getResource());
\r
216 public org.simantics.processeditor.stubs.PipeControlPoint getSubPointOf() {
\r
217 Statement[] statements = graph.getStatements(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).SubPointOf);
\r
218 if(statements.length > 1)
\r
219 throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + statements.length + ") of statements.");
\r
220 if(statements.length == 0)
\r
222 return new org.simantics.processeditor.stubs.PipeControlPoint(graph, statements[0].getObject());
\r
225 public void addSubPointOf(ResourceContainer v) {
\r
226 graph.addStatement(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).SubPointOf, v.getResource());
\r
229 public void setSubPointOf(ResourceContainer v) {
\r
230 Resource predicate = org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).SubPointOf;
\r
231 graph.removeStatements(resource, predicate);
\r
232 graph.addStatement(resource, predicate, v.getResource());
\r
235 // [Nozzle] | [Pipeline Component]
\r
236 public org.simantics.layer0.utils.IEntity getControlPointOf() {
\r
237 Statement[] statements = graph.getStatements(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).ControlPointOf);
\r
238 if(statements.length > 1)
\r
239 throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + statements.length + ") of statements.");
\r
240 if(statements.length == 0)
\r
242 return new Entity(graph, statements[0].getObject());
\r
245 // [Nozzle] | [Pipeline Component]
\r
246 public void addControlPointOf(ResourceContainer v) {
\r
247 graph.addStatement(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).ControlPointOf, v.getResource());
\r
250 // [Nozzle] | [Pipeline Component]
\r
251 public void setControlPointOf(ResourceContainer v) {
\r
252 Resource predicate = org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).ControlPointOf;
\r
253 graph.removeStatements(resource, predicate);
\r
254 graph.addStatement(resource, predicate, v.getResource());
\r
257 public org.simantics.processeditor.stubs.PipeRun getControlPointOfPipeRun() {
\r
258 Statement[] statements = graph.getStatements(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).ControlPointOfPipeRun);
\r
259 if(statements.length > 1)
\r
260 throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + statements.length + ") of statements.");
\r
261 if(statements.length == 0)
\r
263 return new org.simantics.processeditor.stubs.PipeRun(graph, statements[0].getObject());
\r
266 public void addControlPointOfPipeRun(ResourceContainer v) {
\r
267 graph.addStatement(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).ControlPointOfPipeRun, v.getResource());
\r
270 public void setControlPointOfPipeRun(ResourceContainer v) {
\r
271 Resource predicate = org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).ControlPointOfPipeRun;
\r
272 graph.removeStatements(resource, predicate);
\r
273 graph.addStatement(resource, predicate, v.getResource());
\r