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 SingleConnectedComponent extends Entity implements ISingleConnectedComponent {
\r
27 public SingleConnectedComponent(Graph graph, ResourceContainer resourceContainer) {
\r
28 super(graph, resourceContainer.getResource());
\r
31 public SingleConnectedComponent(IEntity entity) {
\r
32 super(entity.getGraph(), entity.getResource());
\r
35 public Graph getGraph() {
\r
39 public static SingleConnectedComponent createDefault(Graph graph) {
\r
40 return new SingleConnectedComponent(graph, InstanceFactory.instantiate(graph, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).SingleConnectedComponent));
\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).SingleConnectedComponent;
\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 SingleConnectedComponent toSingleConnectedComponent() {
\r
70 public org.simantics.processeditor.stubs.PipelineComponent toPipelineComponent() {
\r
71 return new org.simantics.processeditor.stubs.PipelineComponent(graph, resource);
\r
74 public org.simantics.processeditor.stubs.LibraryComponent toLibraryComponent() {
\r
75 return new org.simantics.processeditor.stubs.LibraryComponent(graph, resource);
\r
78 public Collection<org.simantics.proconf.g3d.stubs.G3DNode> getChild() {
\r
79 Statement[] statements = graph.getStatements(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasChild);
\r
80 Collection<org.simantics.proconf.g3d.stubs.G3DNode> ret = new ArrayList<org.simantics.proconf.g3d.stubs.G3DNode>(statements.length);
\r
81 for(Statement s : statements)
\r
82 ret.add(new org.simantics.proconf.g3d.stubs.G3DNode(graph, s.getObject()));
\r
86 public void addChild(ResourceContainer v) {
\r
87 graph.addStatement(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasChild, v.getResource());
\r
90 public org.simantics.proconf.g3d.stubs.G3DNode getParent() {
\r
91 Statement[] statements = graph.getStatements(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasParent);
\r
92 if(statements.length > 1)
\r
93 throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + statements.length + ") of statements.");
\r
94 if(statements.length == 0)
\r
96 return new org.simantics.proconf.g3d.stubs.G3DNode(graph, statements[0].getObject());
\r
99 public void addParent(ResourceContainer v) {
\r
100 graph.addStatement(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasParent, v.getResource());
\r
103 public void setParent(ResourceContainer v) {
\r
104 Resource predicate = org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasParent;
\r
105 graph.removeStatements(resource, predicate);
\r
106 graph.addStatement(resource, predicate, v.getResource());
\r
109 public org.simantics.proconf.g3d.stubs.Position getLocalPosition() {
\r
110 Statement[] statements = graph.getStatements(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasLocalPosition);
\r
111 if(statements.length > 1)
\r
112 throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + statements.length + ") of statements.");
\r
113 if(statements.length == 0)
\r
115 return new org.simantics.proconf.g3d.stubs.Position(graph, statements[0].getObject());
\r
118 public void addLocalPosition(ResourceContainer v) {
\r
119 graph.addStatement(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasLocalPosition, v.getResource());
\r
122 public void setLocalPosition(ResourceContainer v) {
\r
123 Resource predicate = org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasLocalPosition;
\r
124 graph.removeStatements(resource, predicate);
\r
125 graph.addStatement(resource, predicate, v.getResource());
\r
128 public org.simantics.proconf.g3d.stubs.Position getWorldPosition() {
\r
129 Statement[] statements = graph.getStatements(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasWorldPosition);
\r
130 if(statements.length > 1)
\r
131 throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + statements.length + ") of statements.");
\r
132 if(statements.length == 0)
\r
134 return new org.simantics.proconf.g3d.stubs.Position(graph, statements[0].getObject());
\r
137 public void addWorldPosition(ResourceContainer v) {
\r
138 graph.addStatement(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasWorldPosition, v.getResource());
\r
141 public void setWorldPosition(ResourceContainer v) {
\r
142 Resource predicate = org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasWorldPosition;
\r
143 graph.removeStatements(resource, predicate);
\r
144 graph.addStatement(resource, predicate, v.getResource());
\r
147 public org.simantics.proconf.g3d.stubs.Orientation getLocalOrientation() {
\r
148 Statement[] statements = graph.getStatements(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasLocalOrientation);
\r
149 if(statements.length > 1)
\r
150 throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + statements.length + ") of statements.");
\r
151 if(statements.length == 0)
\r
153 return new org.simantics.proconf.g3d.stubs.Orientation(graph, statements[0].getObject());
\r
156 public void addLocalOrientation(ResourceContainer v) {
\r
157 graph.addStatement(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasLocalOrientation, v.getResource());
\r
160 public void setLocalOrientation(ResourceContainer v) {
\r
161 Resource predicate = org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasLocalOrientation;
\r
162 graph.removeStatements(resource, predicate);
\r
163 graph.addStatement(resource, predicate, v.getResource());
\r
166 public org.simantics.proconf.g3d.stubs.Orientation getWorldOrientation() {
\r
167 Statement[] statements = graph.getStatements(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasWorldOrientation);
\r
168 if(statements.length > 1)
\r
169 throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + statements.length + ") of statements.");
\r
170 if(statements.length == 0)
\r
172 return new org.simantics.proconf.g3d.stubs.Orientation(graph, statements[0].getObject());
\r
175 public void addWorldOrientation(ResourceContainer v) {
\r
176 graph.addStatement(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasWorldOrientation, v.getResource());
\r
179 public void setWorldOrientation(ResourceContainer v) {
\r
180 Resource predicate = org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasWorldOrientation;
\r
181 graph.removeStatements(resource, predicate);
\r
182 graph.addStatement(resource, predicate, v.getResource());
\r
185 public org.simantics.proconf.g3d.stubs.Center getCenter() {
\r
186 Statement[] statements = graph.getStatements(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasCenter);
\r
187 if(statements.length > 1)
\r
188 throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + statements.length + ") of statements.");
\r
189 if(statements.length == 0)
\r
191 return new org.simantics.proconf.g3d.stubs.Center(graph, statements[0].getObject());
\r
194 public void addCenter(ResourceContainer v) {
\r
195 graph.addStatement(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasCenter, v.getResource());
\r
198 public void setCenter(ResourceContainer v) {
\r
199 Resource predicate = org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasCenter;
\r
200 graph.removeStatements(resource, predicate);
\r
201 graph.addStatement(resource, predicate, v.getResource());
\r
204 public org.simantics.processeditor.stubs.PBSNode getParentStructure() {
\r
205 Statement[] statements = graph.getStatements(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasParentStructure);
\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.PBSNode(graph, statements[0].getObject());
\r
213 public void addParentStructure(ResourceContainer v) {
\r
214 graph.addStatement(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasParentStructure, v.getResource());
\r
217 public void setParentStructure(ResourceContainer v) {
\r
218 Resource predicate = org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasParentStructure;
\r
219 graph.removeStatements(resource, predicate);
\r
220 graph.addStatement(resource, predicate, v.getResource());
\r
223 public Collection<org.simantics.processeditor.stubs.PBSNode> getChildStructure() {
\r
224 Statement[] statements = graph.getStatements(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasChildStructure);
\r
225 Collection<org.simantics.processeditor.stubs.PBSNode> ret = new ArrayList<org.simantics.processeditor.stubs.PBSNode>(statements.length);
\r
226 for(Statement s : statements)
\r
227 ret.add(new org.simantics.processeditor.stubs.PBSNode(graph, s.getObject()));
\r
231 public void addChildStructure(ResourceContainer v) {
\r
232 graph.addStatement(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasChildStructure, v.getResource());
\r
235 public org.simantics.proconf.g3d.stubs.G3DModel getGraphics() {
\r
236 Statement[] statements = graph.getStatements(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasGraphics);
\r
237 if(statements.length > 1)
\r
238 throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + statements.length + ") of statements.");
\r
239 if(statements.length == 0)
\r
241 return new org.simantics.proconf.g3d.stubs.G3DModel(graph, statements[0].getObject());
\r
244 public void addGraphics(ResourceContainer v) {
\r
245 graph.addStatement(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasGraphics, v.getResource());
\r
248 public void setGraphics(ResourceContainer v) {
\r
249 Resource predicate = org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasGraphics;
\r
250 graph.removeStatements(resource, predicate);
\r
251 graph.addStatement(resource, predicate, v.getResource());
\r
254 public double[] getPipeDiameter() {
\r
255 Statement[] statements = graph.getStatements(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasPipeDiameter);
\r
256 if(statements.length != 1)
\r
257 throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + statements.length + ") of statements.");
\r
258 return (double[])graph.getValueAsObject(statements[0].getObject());
\r
261 public void setPipeDiameter(Object v) {
\r
262 Resource predicate = org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasPipeDiameter;
\r
263 Collection<Resource> objects = graph.getObjects(resource, predicate);
\r
264 if(objects.size() == 0) {
\r
265 Resource r = graph.newResource();
\r
266 Resource valueType = org.simantics.db.Builtins.getInstance(graph).Double;
\r
267 graph.addStatement(r, graph.getBuiltins().InstanceOf, valueType);
\r
268 graph.setValueAsObject(r, v);
\r
269 graph.addStatement(resource, predicate, r);
\r
271 else if(objects.size() == 1)
\r
272 for(Resource r : objects)
\r
273 graph.setValueAsObject(r, v);
\r
275 throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + objects.size() + ") of statements.");
\r
278 public org.simantics.processeditor.stubs.PipeControlPoint getControlPoint() {
\r
279 Statement[] statements = graph.getStatements(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasControlPoint);
\r
280 if(statements.length > 1)
\r
281 throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + statements.length + ") of statements.");
\r
282 if(statements.length == 0)
\r
284 return new org.simantics.processeditor.stubs.PipeControlPoint(graph, statements[0].getObject());
\r
287 public void addControlPoint(ResourceContainer v) {
\r
288 graph.addStatement(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasControlPoint, v.getResource());
\r
291 public void setControlPoint(ResourceContainer v) {
\r
292 Resource predicate = org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasControlPoint;
\r
293 graph.removeStatements(resource, predicate);
\r
294 graph.addStatement(resource, predicate, v.getResource());
\r