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 PipeRun extends Entity implements IPipeRun {
\r
27 public PipeRun(Graph graph, ResourceContainer resourceContainer) {
\r
28 super(graph, resourceContainer.getResource());
\r
31 public PipeRun(IEntity entity) {
\r
32 super(entity.getGraph(), entity.getResource());
\r
35 public Graph getGraph() {
\r
39 public static PipeRun createDefault(Graph graph) {
\r
40 return new PipeRun(graph, InstanceFactory.instantiate(graph, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).PipeRun));
\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).PipeRun;
\r
46 return graph.isInstanceOf(entity.getResource(), type);
\r
50 public Resource getResource() {
\r
54 public org.simantics.proconf.g3d.stubs.G3DNode toG3DNode() {
\r
55 return new org.simantics.proconf.g3d.stubs.G3DNode(graph, resource);
\r
58 public PipeRun toPipeRun() {
\r
62 public org.simantics.processeditor.stubs.P3DNode toP3DNode() {
\r
63 return new org.simantics.processeditor.stubs.P3DNode(graph, resource);
\r
66 public Collection<org.simantics.proconf.g3d.stubs.G3DNode> getChild() {
\r
67 Statement[] statements = graph.getStatements(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasChild);
\r
68 Collection<org.simantics.proconf.g3d.stubs.G3DNode> ret = new ArrayList<org.simantics.proconf.g3d.stubs.G3DNode>(statements.length);
\r
69 for(Statement s : statements)
\r
70 ret.add(new org.simantics.proconf.g3d.stubs.G3DNode(graph, s.getObject()));
\r
74 public void addChild(ResourceContainer v) {
\r
75 graph.addStatement(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasChild, v.getResource());
\r
78 public org.simantics.proconf.g3d.stubs.G3DNode getParent() {
\r
79 Statement[] statements = graph.getStatements(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasParent);
\r
80 if(statements.length > 1)
\r
81 throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + statements.length + ") of statements.");
\r
82 if(statements.length == 0)
\r
84 return new org.simantics.proconf.g3d.stubs.G3DNode(graph, statements[0].getObject());
\r
87 public void addParent(ResourceContainer v) {
\r
88 graph.addStatement(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasParent, v.getResource());
\r
91 public void setParent(ResourceContainer v) {
\r
92 Resource predicate = org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasParent;
\r
93 graph.removeStatements(resource, predicate);
\r
94 graph.addStatement(resource, predicate, v.getResource());
\r
97 public org.simantics.proconf.g3d.stubs.Position getLocalPosition() {
\r
98 Statement[] statements = graph.getStatements(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasLocalPosition);
\r
99 if(statements.length > 1)
\r
100 throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + statements.length + ") of statements.");
\r
101 if(statements.length == 0)
\r
103 return new org.simantics.proconf.g3d.stubs.Position(graph, statements[0].getObject());
\r
106 public void addLocalPosition(ResourceContainer v) {
\r
107 graph.addStatement(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasLocalPosition, v.getResource());
\r
110 public void setLocalPosition(ResourceContainer v) {
\r
111 Resource predicate = org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasLocalPosition;
\r
112 graph.removeStatements(resource, predicate);
\r
113 graph.addStatement(resource, predicate, v.getResource());
\r
116 public org.simantics.proconf.g3d.stubs.Position getWorldPosition() {
\r
117 Statement[] statements = graph.getStatements(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasWorldPosition);
\r
118 if(statements.length > 1)
\r
119 throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + statements.length + ") of statements.");
\r
120 if(statements.length == 0)
\r
122 return new org.simantics.proconf.g3d.stubs.Position(graph, statements[0].getObject());
\r
125 public void addWorldPosition(ResourceContainer v) {
\r
126 graph.addStatement(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasWorldPosition, v.getResource());
\r
129 public void setWorldPosition(ResourceContainer v) {
\r
130 Resource predicate = org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasWorldPosition;
\r
131 graph.removeStatements(resource, predicate);
\r
132 graph.addStatement(resource, predicate, v.getResource());
\r
135 public org.simantics.proconf.g3d.stubs.Orientation getLocalOrientation() {
\r
136 Statement[] statements = graph.getStatements(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasLocalOrientation);
\r
137 if(statements.length > 1)
\r
138 throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + statements.length + ") of statements.");
\r
139 if(statements.length == 0)
\r
141 return new org.simantics.proconf.g3d.stubs.Orientation(graph, statements[0].getObject());
\r
144 public void addLocalOrientation(ResourceContainer v) {
\r
145 graph.addStatement(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasLocalOrientation, v.getResource());
\r
148 public void setLocalOrientation(ResourceContainer v) {
\r
149 Resource predicate = org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasLocalOrientation;
\r
150 graph.removeStatements(resource, predicate);
\r
151 graph.addStatement(resource, predicate, v.getResource());
\r
154 public org.simantics.proconf.g3d.stubs.Orientation getWorldOrientation() {
\r
155 Statement[] statements = graph.getStatements(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasWorldOrientation);
\r
156 if(statements.length > 1)
\r
157 throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + statements.length + ") of statements.");
\r
158 if(statements.length == 0)
\r
160 return new org.simantics.proconf.g3d.stubs.Orientation(graph, statements[0].getObject());
\r
163 public void addWorldOrientation(ResourceContainer v) {
\r
164 graph.addStatement(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasWorldOrientation, v.getResource());
\r
167 public void setWorldOrientation(ResourceContainer v) {
\r
168 Resource predicate = org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasWorldOrientation;
\r
169 graph.removeStatements(resource, predicate);
\r
170 graph.addStatement(resource, predicate, v.getResource());
\r
173 public org.simantics.proconf.g3d.stubs.Center getCenter() {
\r
174 Statement[] statements = graph.getStatements(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasCenter);
\r
175 if(statements.length > 1)
\r
176 throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + statements.length + ") of statements.");
\r
177 if(statements.length == 0)
\r
179 return new org.simantics.proconf.g3d.stubs.Center(graph, statements[0].getObject());
\r
182 public void addCenter(ResourceContainer v) {
\r
183 graph.addStatement(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasCenter, v.getResource());
\r
186 public void setCenter(ResourceContainer v) {
\r
187 Resource predicate = org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasCenter;
\r
188 graph.removeStatements(resource, predicate);
\r
189 graph.addStatement(resource, predicate, v.getResource());
\r
192 public double[] getPipeDiameter() {
\r
193 Statement[] statements = graph.getStatements(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasPipeDiameter);
\r
194 if(statements.length != 1)
\r
195 throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + statements.length + ") of statements.");
\r
196 return (double[])graph.getValueAsObject(statements[0].getObject());
\r
199 public void setPipeDiameter(Object v) {
\r
200 Resource predicate = org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasPipeDiameter;
\r
201 Collection<Resource> objects = graph.getObjects(resource, predicate);
\r
202 if(objects.size() == 0) {
\r
203 Resource r = graph.newResource();
\r
204 Resource valueType = org.simantics.db.Builtins.getInstance(graph).Double;
\r
205 graph.addStatement(r, graph.getBuiltins().InstanceOf, valueType);
\r
206 graph.setValueAsObject(r, v);
\r
207 graph.addStatement(resource, predicate, r);
\r
209 else if(objects.size() == 1)
\r
210 for(Resource r : objects)
\r
211 graph.setValueAsObject(r, v);
\r
213 throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + objects.size() + ") of statements.");
\r
216 public double[] getTurnRadius() {
\r
217 Statement[] statements = graph.getStatements(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasTurnRadius);
\r
218 if(statements.length != 1)
\r
219 throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + statements.length + ") of statements.");
\r
220 return (double[])graph.getValueAsObject(statements[0].getObject());
\r
223 public void setTurnRadius(Object v) {
\r
224 Resource predicate = org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasTurnRadius;
\r
225 Collection<Resource> objects = graph.getObjects(resource, predicate);
\r
226 if(objects.size() == 0) {
\r
227 Resource r = graph.newResource();
\r
228 Resource valueType = org.simantics.db.Builtins.getInstance(graph).Double;
\r
229 graph.addStatement(r, graph.getBuiltins().InstanceOf, valueType);
\r
230 graph.setValueAsObject(r, v);
\r
231 graph.addStatement(resource, predicate, r);
\r
233 else if(objects.size() == 1)
\r
234 for(Resource r : objects)
\r
235 graph.setValueAsObject(r, v);
\r
237 throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + objects.size() + ") of statements.");
\r
240 public Collection<org.simantics.processeditor.stubs.PipeControlPoint> getControlPoints() {
\r
241 Statement[] statements = graph.getStatements(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasControlPoints);
\r
242 Collection<org.simantics.processeditor.stubs.PipeControlPoint> ret = new ArrayList<org.simantics.processeditor.stubs.PipeControlPoint>(statements.length);
\r
243 for(Statement s : statements)
\r
244 ret.add(new org.simantics.processeditor.stubs.PipeControlPoint(graph, s.getObject()));
\r
248 public void addControlPoints(ResourceContainer v) {
\r
249 graph.addStatement(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasControlPoints, v.getResource());
\r