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 PathLegEndControlPoint extends Entity implements IPathLegEndControlPoint {
\r
27 public PathLegEndControlPoint(Graph graph, ResourceContainer resourceContainer) {
\r
28 super(graph, resourceContainer.getResource());
\r
31 public PathLegEndControlPoint(IEntity entity) {
\r
32 super(entity.getGraph(), entity.getResource());
\r
35 public Graph getGraph() {
\r
39 public static PathLegEndControlPoint createDefault(Graph graph) {
\r
40 return new PathLegEndControlPoint(graph, InstanceFactory.instantiate(graph, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).PathLegEndControlPoint));
\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).PathLegEndControlPoint;
\r
46 return graph.isInstanceOf(entity.getResource(), type);
\r
50 public Resource getResource() {
\r
54 public PathLegEndControlPoint toPathLegEndControlPoint() {
\r
58 public org.simantics.processeditor.stubs.PipeControlPoint toPipeControlPoint() {
\r
59 return new org.simantics.processeditor.stubs.PipeControlPoint(graph, resource);
\r
62 public org.simantics.proconf.g3d.stubs.Position getLocalPosition() {
\r
63 Statement[] statements = graph.getStatements(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasLocalPosition);
\r
64 if(statements.length != 1)
\r
65 throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + statements.length + ") of statements.");
\r
66 return new org.simantics.proconf.g3d.stubs.Position(graph, statements[0].getObject());
\r
69 public void addLocalPosition(ResourceContainer v) {
\r
70 graph.addStatement(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasLocalPosition, v.getResource());
\r
73 public void setLocalPosition(ResourceContainer v) {
\r
74 Resource predicate = org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasLocalPosition;
\r
75 graph.removeStatements(resource, predicate);
\r
76 graph.addStatement(resource, predicate, v.getResource());
\r
79 public org.simantics.proconf.g3d.stubs.Position getWorldPosition() {
\r
80 Statement[] statements = graph.getStatements(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasWorldPosition);
\r
81 if(statements.length != 1)
\r
82 throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + statements.length + ") of statements.");
\r
83 return new org.simantics.proconf.g3d.stubs.Position(graph, statements[0].getObject());
\r
86 public void addWorldPosition(ResourceContainer v) {
\r
87 graph.addStatement(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasWorldPosition, v.getResource());
\r
90 public void setWorldPosition(ResourceContainer v) {
\r
91 Resource predicate = org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasWorldPosition;
\r
92 graph.removeStatements(resource, predicate);
\r
93 graph.addStatement(resource, predicate, v.getResource());
\r
96 public org.simantics.proconf.g3d.stubs.Orientation getLocalOrientation() {
\r
97 Statement[] statements = graph.getStatements(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasLocalOrientation);
\r
98 if(statements.length != 1)
\r
99 throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + statements.length + ") of statements.");
\r
100 return new org.simantics.proconf.g3d.stubs.Orientation(graph, statements[0].getObject());
\r
103 public void addLocalOrientation(ResourceContainer v) {
\r
104 graph.addStatement(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasLocalOrientation, v.getResource());
\r
107 public void setLocalOrientation(ResourceContainer v) {
\r
108 Resource predicate = org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasLocalOrientation;
\r
109 graph.removeStatements(resource, predicate);
\r
110 graph.addStatement(resource, predicate, v.getResource());
\r
113 public org.simantics.proconf.g3d.stubs.Orientation getWorldOrientation() {
\r
114 Statement[] statements = graph.getStatements(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasWorldOrientation);
\r
115 if(statements.length != 1)
\r
116 throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + statements.length + ") of statements.");
\r
117 return new org.simantics.proconf.g3d.stubs.Orientation(graph, statements[0].getObject());
\r
120 public void addWorldOrientation(ResourceContainer v) {
\r
121 graph.addStatement(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasWorldOrientation, v.getResource());
\r
124 public void setWorldOrientation(ResourceContainer v) {
\r
125 Resource predicate = org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasWorldOrientation;
\r
126 graph.removeStatements(resource, predicate);
\r
127 graph.addStatement(resource, predicate, v.getResource());
\r
130 public org.simantics.processeditor.stubs.PipeControlPoint getNext() {
\r
131 Statement[] statements = graph.getStatements(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasNext);
\r
132 if(statements.length > 1)
\r
133 throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + statements.length + ") of statements.");
\r
134 if(statements.length == 0)
\r
136 return new org.simantics.processeditor.stubs.PipeControlPoint(graph, statements[0].getObject());
\r
139 public void addNext(ResourceContainer v) {
\r
140 graph.addStatement(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasNext, v.getResource());
\r
143 public void setNext(ResourceContainer v) {
\r
144 Resource predicate = org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasNext;
\r
145 graph.removeStatements(resource, predicate);
\r
146 graph.addStatement(resource, predicate, v.getResource());
\r
149 public org.simantics.processeditor.stubs.PipeControlPoint getPrevious() {
\r
150 Statement[] statements = graph.getStatements(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasPrevious);
\r
151 if(statements.length > 1)
\r
152 throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + statements.length + ") of statements.");
\r
153 if(statements.length == 0)
\r
155 return new org.simantics.processeditor.stubs.PipeControlPoint(graph, statements[0].getObject());
\r
158 public void addPrevious(ResourceContainer v) {
\r
159 graph.addStatement(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasPrevious, v.getResource());
\r
162 public void setPrevious(ResourceContainer v) {
\r
163 Resource predicate = org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasPrevious;
\r
164 graph.removeStatements(resource, predicate);
\r
165 graph.addStatement(resource, predicate, v.getResource());
\r
168 public double[] getPipeDiameter() {
\r
169 Statement[] statements = graph.getStatements(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasPipeDiameter);
\r
170 if(statements.length != 1)
\r
171 throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + statements.length + ") of statements.");
\r
172 return (double[])graph.getValueAsObject(statements[0].getObject());
\r
175 public void setPipeDiameter(Object v) {
\r
176 Resource predicate = org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasPipeDiameter;
\r
177 Collection<Resource> objects = graph.getObjects(resource, predicate);
\r
178 if(objects.size() == 0) {
\r
179 Resource r = graph.newResource();
\r
180 Resource valueType = org.simantics.db.Builtins.getInstance(graph).Double;
\r
181 graph.addStatement(r, graph.getBuiltins().InstanceOf, valueType);
\r
182 graph.setValueAsObject(r, v);
\r
183 graph.addStatement(resource, predicate, r);
\r
185 else if(objects.size() == 1)
\r
186 for(Resource r : objects)
\r
187 graph.setValueAsObject(r, v);
\r
189 throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + objects.size() + ") of statements.");
\r
192 public Collection<org.simantics.processeditor.stubs.PipeControlPoint> getSubPoint() {
\r
193 Statement[] statements = graph.getStatements(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasSubPoint);
\r
194 Collection<org.simantics.processeditor.stubs.PipeControlPoint> ret = new ArrayList<org.simantics.processeditor.stubs.PipeControlPoint>(statements.length);
\r
195 for(Statement s : statements)
\r
196 ret.add(new org.simantics.processeditor.stubs.PipeControlPoint(graph, s.getObject()));
\r
200 public void addSubPoint(ResourceContainer v) {
\r
201 graph.addStatement(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasSubPoint, v.getResource());
\r
204 public org.simantics.processeditor.stubs.PipeControlPoint getSubPointOf() {
\r
205 Statement[] statements = graph.getStatements(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).SubPointOf);
\r
206 if(statements.length > 1)
\r
207 throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + statements.length + ") of statements.");
\r
208 if(statements.length == 0)
\r
210 return new org.simantics.processeditor.stubs.PipeControlPoint(graph, statements[0].getObject());
\r
213 public void addSubPointOf(ResourceContainer v) {
\r
214 graph.addStatement(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).SubPointOf, v.getResource());
\r
217 public void setSubPointOf(ResourceContainer v) {
\r
218 Resource predicate = org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).SubPointOf;
\r
219 graph.removeStatements(resource, predicate);
\r
220 graph.addStatement(resource, predicate, v.getResource());
\r
223 // [Nozzle] | [Pipeline Component]
\r
224 public org.simantics.layer0.utils.IEntity getControlPointOf() {
\r
225 Statement[] statements = graph.getStatements(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).ControlPointOf);
\r
226 if(statements.length > 1)
\r
227 throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + statements.length + ") of statements.");
\r
228 if(statements.length == 0)
\r
230 return new Entity(graph, statements[0].getObject());
\r
233 // [Nozzle] | [Pipeline Component]
\r
234 public void addControlPointOf(ResourceContainer v) {
\r
235 graph.addStatement(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).ControlPointOf, v.getResource());
\r
238 // [Nozzle] | [Pipeline Component]
\r
239 public void setControlPointOf(ResourceContainer v) {
\r
240 Resource predicate = org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).ControlPointOf;
\r
241 graph.removeStatements(resource, predicate);
\r
242 graph.addStatement(resource, predicate, v.getResource());
\r
245 public org.simantics.processeditor.stubs.PipeRun getControlPointOfPipeRun() {
\r
246 Statement[] statements = graph.getStatements(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).ControlPointOfPipeRun);
\r
247 if(statements.length > 1)
\r
248 throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + statements.length + ") of statements.");
\r
249 if(statements.length == 0)
\r
251 return new org.simantics.processeditor.stubs.PipeRun(graph, statements[0].getObject());
\r
254 public void addControlPointOfPipeRun(ResourceContainer v) {
\r
255 graph.addStatement(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).ControlPointOfPipeRun, v.getResource());
\r
258 public void setControlPointOfPipeRun(ResourceContainer v) {
\r
259 Resource predicate = org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).ControlPointOfPipeRun;
\r
260 graph.removeStatements(resource, predicate);
\r
261 graph.addStatement(resource, predicate, v.getResource());
\r