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 VerticalVessel extends Entity implements IVerticalVessel {
\r
27 public VerticalVessel(Graph graph, ResourceContainer resourceContainer) {
\r
28 super(graph, resourceContainer.getResource());
\r
31 public VerticalVessel(IEntity entity) {
\r
32 super(entity.getGraph(), entity.getResource());
\r
35 public Graph getGraph() {
\r
39 public static VerticalVessel createDefault(Graph graph) {
\r
40 return new VerticalVessel(graph, InstanceFactory.instantiate(graph, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).VerticalVessel));
\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).VerticalVessel;
\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 org.simantics.processeditor.stubs.PBSNode toPBSNode() {
\r
59 return new org.simantics.processeditor.stubs.PBSNode(graph, resource);
\r
62 public org.simantics.processeditor.stubs.P3DNode toP3DNode() {
\r
63 return new org.simantics.processeditor.stubs.P3DNode(graph, resource);
\r
66 public VerticalVessel toVerticalVessel() {
\r
70 public org.simantics.processeditor.stubs.Vessel toVessel() {
\r
71 return new org.simantics.processeditor.stubs.Vessel(graph, resource);
\r
74 public org.simantics.processeditor.stubs.Equipment toEquipment() {
\r
75 return new org.simantics.processeditor.stubs.Equipment(graph, resource);
\r
78 public org.simantics.processeditor.stubs.LibraryComponent toLibraryComponent() {
\r
79 return new org.simantics.processeditor.stubs.LibraryComponent(graph, resource);
\r
82 public Collection<org.simantics.proconf.g3d.stubs.G3DNode> getChild() {
\r
83 Statement[] statements = graph.getStatements(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasChild);
\r
84 Collection<org.simantics.proconf.g3d.stubs.G3DNode> ret = new ArrayList<org.simantics.proconf.g3d.stubs.G3DNode>(statements.length);
\r
85 for(Statement s : statements)
\r
86 ret.add(new org.simantics.proconf.g3d.stubs.G3DNode(graph, s.getObject()));
\r
90 public void addChild(ResourceContainer v) {
\r
91 graph.addStatement(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasChild, v.getResource());
\r
94 public org.simantics.proconf.g3d.stubs.G3DNode getParent() {
\r
95 Statement[] statements = graph.getStatements(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasParent);
\r
96 if(statements.length > 1)
\r
97 throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + statements.length + ") of statements.");
\r
98 if(statements.length == 0)
\r
100 return new org.simantics.proconf.g3d.stubs.G3DNode(graph, statements[0].getObject());
\r
103 public void addParent(ResourceContainer v) {
\r
104 graph.addStatement(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasParent, v.getResource());
\r
107 public void setParent(ResourceContainer v) {
\r
108 Resource predicate = org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasParent;
\r
109 graph.removeStatements(resource, predicate);
\r
110 graph.addStatement(resource, predicate, v.getResource());
\r
113 public org.simantics.proconf.g3d.stubs.Position getLocalPosition() {
\r
114 Statement[] statements = graph.getStatements(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasLocalPosition);
\r
115 if(statements.length > 1)
\r
116 throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + statements.length + ") of statements.");
\r
117 if(statements.length == 0)
\r
119 return new org.simantics.proconf.g3d.stubs.Position(graph, statements[0].getObject());
\r
122 public void addLocalPosition(ResourceContainer v) {
\r
123 graph.addStatement(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasLocalPosition, v.getResource());
\r
126 public void setLocalPosition(ResourceContainer v) {
\r
127 Resource predicate = org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasLocalPosition;
\r
128 graph.removeStatements(resource, predicate);
\r
129 graph.addStatement(resource, predicate, v.getResource());
\r
132 public org.simantics.proconf.g3d.stubs.Position getWorldPosition() {
\r
133 Statement[] statements = graph.getStatements(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasWorldPosition);
\r
134 if(statements.length > 1)
\r
135 throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + statements.length + ") of statements.");
\r
136 if(statements.length == 0)
\r
138 return new org.simantics.proconf.g3d.stubs.Position(graph, statements[0].getObject());
\r
141 public void addWorldPosition(ResourceContainer v) {
\r
142 graph.addStatement(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasWorldPosition, v.getResource());
\r
145 public void setWorldPosition(ResourceContainer v) {
\r
146 Resource predicate = org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasWorldPosition;
\r
147 graph.removeStatements(resource, predicate);
\r
148 graph.addStatement(resource, predicate, v.getResource());
\r
151 public org.simantics.proconf.g3d.stubs.Orientation getLocalOrientation() {
\r
152 Statement[] statements = graph.getStatements(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasLocalOrientation);
\r
153 if(statements.length > 1)
\r
154 throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + statements.length + ") of statements.");
\r
155 if(statements.length == 0)
\r
157 return new org.simantics.proconf.g3d.stubs.Orientation(graph, statements[0].getObject());
\r
160 public void addLocalOrientation(ResourceContainer v) {
\r
161 graph.addStatement(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasLocalOrientation, v.getResource());
\r
164 public void setLocalOrientation(ResourceContainer v) {
\r
165 Resource predicate = org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasLocalOrientation;
\r
166 graph.removeStatements(resource, predicate);
\r
167 graph.addStatement(resource, predicate, v.getResource());
\r
170 public org.simantics.proconf.g3d.stubs.Orientation getWorldOrientation() {
\r
171 Statement[] statements = graph.getStatements(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasWorldOrientation);
\r
172 if(statements.length > 1)
\r
173 throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + statements.length + ") of statements.");
\r
174 if(statements.length == 0)
\r
176 return new org.simantics.proconf.g3d.stubs.Orientation(graph, statements[0].getObject());
\r
179 public void addWorldOrientation(ResourceContainer v) {
\r
180 graph.addStatement(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasWorldOrientation, v.getResource());
\r
183 public void setWorldOrientation(ResourceContainer v) {
\r
184 Resource predicate = org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasWorldOrientation;
\r
185 graph.removeStatements(resource, predicate);
\r
186 graph.addStatement(resource, predicate, v.getResource());
\r
189 public org.simantics.proconf.g3d.stubs.Center getCenter() {
\r
190 Statement[] statements = graph.getStatements(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasCenter);
\r
191 if(statements.length > 1)
\r
192 throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + statements.length + ") of statements.");
\r
193 if(statements.length == 0)
\r
195 return new org.simantics.proconf.g3d.stubs.Center(graph, statements[0].getObject());
\r
198 public void addCenter(ResourceContainer v) {
\r
199 graph.addStatement(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasCenter, v.getResource());
\r
202 public void setCenter(ResourceContainer v) {
\r
203 Resource predicate = org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasCenter;
\r
204 graph.removeStatements(resource, predicate);
\r
205 graph.addStatement(resource, predicate, v.getResource());
\r
208 public org.simantics.processeditor.stubs.PBSNode getParentStructure() {
\r
209 Statement[] statements = graph.getStatements(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasParentStructure);
\r
210 if(statements.length > 1)
\r
211 throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + statements.length + ") of statements.");
\r
212 if(statements.length == 0)
\r
214 return new org.simantics.processeditor.stubs.PBSNode(graph, statements[0].getObject());
\r
217 public void addParentStructure(ResourceContainer v) {
\r
218 graph.addStatement(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasParentStructure, v.getResource());
\r
221 public void setParentStructure(ResourceContainer v) {
\r
222 Resource predicate = org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasParentStructure;
\r
223 graph.removeStatements(resource, predicate);
\r
224 graph.addStatement(resource, predicate, v.getResource());
\r
227 public Collection<org.simantics.processeditor.stubs.PBSNode> getChildStructure() {
\r
228 Statement[] statements = graph.getStatements(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasChildStructure);
\r
229 Collection<org.simantics.processeditor.stubs.PBSNode> ret = new ArrayList<org.simantics.processeditor.stubs.PBSNode>(statements.length);
\r
230 for(Statement s : statements)
\r
231 ret.add(new org.simantics.processeditor.stubs.PBSNode(graph, s.getObject()));
\r
235 public void addChildStructure(ResourceContainer v) {
\r
236 graph.addStatement(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasChildStructure, v.getResource());
\r
239 public org.simantics.proconf.g3d.stubs.G3DModel getGraphics() {
\r
240 Statement[] statements = graph.getStatements(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasGraphics);
\r
241 if(statements.length > 1)
\r
242 throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + statements.length + ") of statements.");
\r
243 if(statements.length == 0)
\r
245 return new org.simantics.proconf.g3d.stubs.G3DModel(graph, statements[0].getObject());
\r
248 public void addGraphics(ResourceContainer v) {
\r
249 graph.addStatement(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasGraphics, v.getResource());
\r
252 public void setGraphics(ResourceContainer v) {
\r
253 Resource predicate = org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasGraphics;
\r
254 graph.removeStatements(resource, predicate);
\r
255 graph.addStatement(resource, predicate, v.getResource());
\r
258 public org.simantics.processeditor.stubs.Nozzle getNozzle() {
\r
259 Statement[] statements = graph.getStatements(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasNozzle);
\r
260 if(statements.length > 1)
\r
261 throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + statements.length + ") of statements.");
\r
262 if(statements.length == 0)
\r
264 return new org.simantics.processeditor.stubs.Nozzle(graph, statements[0].getObject());
\r
267 public void addNozzle(ResourceContainer v) {
\r
268 graph.addStatement(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasNozzle, v.getResource());
\r
271 public void setNozzle(ResourceContainer v) {
\r
272 Resource predicate = org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasNozzle;
\r
273 graph.removeStatements(resource, predicate);
\r
274 graph.addStatement(resource, predicate, v.getResource());
\r
277 // [Nozzle]&[Property]
\r
278 public Collection<org.simantics.layer0.utils.IEntity> getNozzleDefinition() {
\r
279 Statement[] statements = graph.getStatements(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasNozzleDefinition);
\r
280 Collection<org.simantics.layer0.utils.IEntity> ret = new ArrayList<org.simantics.layer0.utils.IEntity>(statements.length);
\r
281 for(Statement s : statements)
\r
282 ret.add(new Entity(graph, s.getObject()));
\r
286 // [Nozzle]&[Property]
\r
287 public void addNozzleDefinition(ResourceContainer v) {
\r
288 graph.addStatement(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasNozzleDefinition, v.getResource());
\r
291 public String[] getNozzleRestriction() {
\r
292 Statement[] statements = graph.getStatements(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasNozzleRestriction);
\r
293 if(statements.length > 1)
\r
294 throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + statements.length + ") of statements.");
\r
295 if(statements.length == 0)
\r
297 return (String[])graph.getValueAsObject(statements[0].getObject());
\r
300 public void setNozzleRestriction(Object v) {
\r
301 Resource predicate = org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasNozzleRestriction;
\r
302 Collection<Resource> objects = graph.getObjects(resource, predicate);
\r
303 if(objects.size() == 0) {
\r
304 Resource r = graph.newResource();
\r
305 Resource valueType = org.simantics.db.Builtins.getInstance(graph).IntegerRangeUnion;
\r
306 graph.addStatement(r, graph.getBuiltins().InstanceOf, valueType);
\r
307 graph.setValueAsObject(r, v);
\r
308 graph.addStatement(resource, predicate, r);
\r
310 else if(objects.size() == 1)
\r
311 for(Resource r : objects)
\r
312 graph.setValueAsObject(r, v);
\r
314 throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + objects.size() + ") of statements.");
\r
317 public double[] getHeight() {
\r
318 Statement[] statements = graph.getStatements(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasHeight);
\r
319 if(statements.length != 1)
\r
320 throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + statements.length + ") of statements.");
\r
321 return (double[])graph.getValueAsObject(statements[0].getObject());
\r
324 public void setHeight(Object v) {
\r
325 Resource predicate = org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasHeight;
\r
326 Collection<Resource> objects = graph.getObjects(resource, predicate);
\r
327 if(objects.size() == 0) {
\r
328 Resource r = graph.newResource();
\r
329 Resource valueType = org.simantics.db.Builtins.getInstance(graph).Double;
\r
330 graph.addStatement(r, graph.getBuiltins().InstanceOf, valueType);
\r
331 graph.setValueAsObject(r, v);
\r
332 graph.addStatement(resource, predicate, r);
\r
334 else if(objects.size() == 1)
\r
335 for(Resource r : objects)
\r
336 graph.setValueAsObject(r, v);
\r
338 throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + objects.size() + ") of statements.");
\r