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 Reducer extends Entity implements IReducer {
\r
27 public Reducer(Graph graph, ResourceContainer resourceContainer) {
\r
28 super(graph, resourceContainer.getResource());
\r
31 public Reducer(IEntity entity) {
\r
32 super(entity.getGraph(), entity.getResource());
\r
35 public Graph getGraph() {
\r
39 public static Reducer createDefault(Graph graph) {
\r
40 return new Reducer(graph, InstanceFactory.instantiate(graph, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).Reducer));
\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).Reducer;
\r
46 return graph.isInstanceOf(entity.getResource(), type);
\r
50 public Resource getResource() {
\r
54 public org.simantics.processeditor.stubs.CodedComponent toCodedComponent() {
\r
55 return new org.simantics.processeditor.stubs.CodedComponent(graph, resource);
\r
58 public Reducer toReducer() {
\r
62 public org.simantics.proconf.g3d.stubs.G3DNode toG3DNode() {
\r
63 return new org.simantics.proconf.g3d.stubs.G3DNode(graph, resource);
\r
66 public org.simantics.processeditor.stubs.SizeChangeComponent toSizeChangeComponent() {
\r
67 return new org.simantics.processeditor.stubs.SizeChangeComponent(graph, resource);
\r
70 public org.simantics.processeditor.stubs.PBSNode toPBSNode() {
\r
71 return new org.simantics.processeditor.stubs.PBSNode(graph, resource);
\r
74 public org.simantics.processeditor.stubs.InlineComponent toInlineComponent() {
\r
75 return new org.simantics.processeditor.stubs.InlineComponent(graph, resource);
\r
78 public org.simantics.processeditor.stubs.P3DNode toP3DNode() {
\r
79 return new org.simantics.processeditor.stubs.P3DNode(graph, resource);
\r
82 public org.simantics.processeditor.stubs.DualConnectedComponent toDualConnectedComponent() {
\r
83 return new org.simantics.processeditor.stubs.DualConnectedComponent(graph, resource);
\r
86 public org.simantics.processeditor.stubs.PipelineComponent toPipelineComponent() {
\r
87 return new org.simantics.processeditor.stubs.PipelineComponent(graph, resource);
\r
90 public org.simantics.processeditor.stubs.FixedLengthInlineComponent toFixedLengthInlineComponent() {
\r
91 return new org.simantics.processeditor.stubs.FixedLengthInlineComponent(graph, resource);
\r
94 public org.simantics.processeditor.stubs.LibraryComponent toLibraryComponent() {
\r
95 return new org.simantics.processeditor.stubs.LibraryComponent(graph, resource);
\r
98 public Collection<org.simantics.proconf.g3d.stubs.G3DNode> getChild() {
\r
99 Statement[] statements = graph.getStatements(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasChild);
\r
100 Collection<org.simantics.proconf.g3d.stubs.G3DNode> ret = new ArrayList<org.simantics.proconf.g3d.stubs.G3DNode>(statements.length);
\r
101 for(Statement s : statements)
\r
102 ret.add(new org.simantics.proconf.g3d.stubs.G3DNode(graph, s.getObject()));
\r
106 public void addChild(ResourceContainer v) {
\r
107 graph.addStatement(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasChild, v.getResource());
\r
110 public org.simantics.proconf.g3d.stubs.G3DNode getParent() {
\r
111 Statement[] statements = graph.getStatements(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasParent);
\r
112 if(statements.length > 1)
\r
113 throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + statements.length + ") of statements.");
\r
114 if(statements.length == 0)
\r
116 return new org.simantics.proconf.g3d.stubs.G3DNode(graph, statements[0].getObject());
\r
119 public void addParent(ResourceContainer v) {
\r
120 graph.addStatement(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasParent, v.getResource());
\r
123 public void setParent(ResourceContainer v) {
\r
124 Resource predicate = org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasParent;
\r
125 graph.removeStatements(resource, predicate);
\r
126 graph.addStatement(resource, predicate, v.getResource());
\r
129 public org.simantics.proconf.g3d.stubs.Position getLocalPosition() {
\r
130 Statement[] statements = graph.getStatements(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasLocalPosition);
\r
131 if(statements.length > 1)
\r
132 throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + statements.length + ") of statements.");
\r
133 if(statements.length == 0)
\r
135 return new org.simantics.proconf.g3d.stubs.Position(graph, statements[0].getObject());
\r
138 public void addLocalPosition(ResourceContainer v) {
\r
139 graph.addStatement(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasLocalPosition, v.getResource());
\r
142 public void setLocalPosition(ResourceContainer v) {
\r
143 Resource predicate = org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasLocalPosition;
\r
144 graph.removeStatements(resource, predicate);
\r
145 graph.addStatement(resource, predicate, v.getResource());
\r
148 public org.simantics.proconf.g3d.stubs.Position getWorldPosition() {
\r
149 Statement[] statements = graph.getStatements(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasWorldPosition);
\r
150 if(statements.length > 1)
\r
151 throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + statements.length + ") of statements.");
\r
152 if(statements.length == 0)
\r
154 return new org.simantics.proconf.g3d.stubs.Position(graph, statements[0].getObject());
\r
157 public void addWorldPosition(ResourceContainer v) {
\r
158 graph.addStatement(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasWorldPosition, v.getResource());
\r
161 public void setWorldPosition(ResourceContainer v) {
\r
162 Resource predicate = org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasWorldPosition;
\r
163 graph.removeStatements(resource, predicate);
\r
164 graph.addStatement(resource, predicate, v.getResource());
\r
167 public org.simantics.proconf.g3d.stubs.Orientation getLocalOrientation() {
\r
168 Statement[] statements = graph.getStatements(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasLocalOrientation);
\r
169 if(statements.length > 1)
\r
170 throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + statements.length + ") of statements.");
\r
171 if(statements.length == 0)
\r
173 return new org.simantics.proconf.g3d.stubs.Orientation(graph, statements[0].getObject());
\r
176 public void addLocalOrientation(ResourceContainer v) {
\r
177 graph.addStatement(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasLocalOrientation, v.getResource());
\r
180 public void setLocalOrientation(ResourceContainer v) {
\r
181 Resource predicate = org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasLocalOrientation;
\r
182 graph.removeStatements(resource, predicate);
\r
183 graph.addStatement(resource, predicate, v.getResource());
\r
186 public org.simantics.proconf.g3d.stubs.Orientation getWorldOrientation() {
\r
187 Statement[] statements = graph.getStatements(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasWorldOrientation);
\r
188 if(statements.length > 1)
\r
189 throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + statements.length + ") of statements.");
\r
190 if(statements.length == 0)
\r
192 return new org.simantics.proconf.g3d.stubs.Orientation(graph, statements[0].getObject());
\r
195 public void addWorldOrientation(ResourceContainer v) {
\r
196 graph.addStatement(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasWorldOrientation, v.getResource());
\r
199 public void setWorldOrientation(ResourceContainer v) {
\r
200 Resource predicate = org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasWorldOrientation;
\r
201 graph.removeStatements(resource, predicate);
\r
202 graph.addStatement(resource, predicate, v.getResource());
\r
205 public org.simantics.proconf.g3d.stubs.Center getCenter() {
\r
206 Statement[] statements = graph.getStatements(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasCenter);
\r
207 if(statements.length > 1)
\r
208 throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + statements.length + ") of statements.");
\r
209 if(statements.length == 0)
\r
211 return new org.simantics.proconf.g3d.stubs.Center(graph, statements[0].getObject());
\r
214 public void addCenter(ResourceContainer v) {
\r
215 graph.addStatement(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasCenter, v.getResource());
\r
218 public void setCenter(ResourceContainer v) {
\r
219 Resource predicate = org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasCenter;
\r
220 graph.removeStatements(resource, predicate);
\r
221 graph.addStatement(resource, predicate, v.getResource());
\r
224 public org.simantics.processeditor.stubs.PBSNode getParentStructure() {
\r
225 Statement[] statements = graph.getStatements(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasParentStructure);
\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 org.simantics.processeditor.stubs.PBSNode(graph, statements[0].getObject());
\r
233 public void addParentStructure(ResourceContainer v) {
\r
234 graph.addStatement(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasParentStructure, v.getResource());
\r
237 public void setParentStructure(ResourceContainer v) {
\r
238 Resource predicate = org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasParentStructure;
\r
239 graph.removeStatements(resource, predicate);
\r
240 graph.addStatement(resource, predicate, v.getResource());
\r
243 public Collection<org.simantics.processeditor.stubs.PBSNode> getChildStructure() {
\r
244 Statement[] statements = graph.getStatements(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasChildStructure);
\r
245 Collection<org.simantics.processeditor.stubs.PBSNode> ret = new ArrayList<org.simantics.processeditor.stubs.PBSNode>(statements.length);
\r
246 for(Statement s : statements)
\r
247 ret.add(new org.simantics.processeditor.stubs.PBSNode(graph, s.getObject()));
\r
251 public void addChildStructure(ResourceContainer v) {
\r
252 graph.addStatement(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasChildStructure, v.getResource());
\r
255 public org.simantics.proconf.g3d.stubs.G3DModel getGraphics() {
\r
256 Statement[] statements = graph.getStatements(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasGraphics);
\r
257 if(statements.length > 1)
\r
258 throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + statements.length + ") of statements.");
\r
259 if(statements.length == 0)
\r
261 return new org.simantics.proconf.g3d.stubs.G3DModel(graph, statements[0].getObject());
\r
264 public void addGraphics(ResourceContainer v) {
\r
265 graph.addStatement(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasGraphics, v.getResource());
\r
268 public void setGraphics(ResourceContainer v) {
\r
269 Resource predicate = org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasGraphics;
\r
270 graph.removeStatements(resource, predicate);
\r
271 graph.addStatement(resource, predicate, v.getResource());
\r
274 public double[] getPipeDiameter() {
\r
275 Statement[] statements = graph.getStatements(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasPipeDiameter);
\r
276 if(statements.length != 1)
\r
277 throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + statements.length + ") of statements.");
\r
278 return (double[])graph.getValueAsObject(statements[0].getObject());
\r
281 public void setPipeDiameter(Object v) {
\r
282 Resource predicate = org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasPipeDiameter;
\r
283 Collection<Resource> objects = graph.getObjects(resource, predicate);
\r
284 if(objects.size() == 0) {
\r
285 Resource r = graph.newResource();
\r
286 Resource valueType = org.simantics.db.Builtins.getInstance(graph).Double;
\r
287 graph.addStatement(r, graph.getBuiltins().InstanceOf, valueType);
\r
288 graph.setValueAsObject(r, v);
\r
289 graph.addStatement(resource, predicate, r);
\r
291 else if(objects.size() == 1)
\r
292 for(Resource r : objects)
\r
293 graph.setValueAsObject(r, v);
\r
295 throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + objects.size() + ") of statements.");
\r
298 public double[] getLength() {
\r
299 Statement[] statements = graph.getStatements(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasLength);
\r
300 if(statements.length != 1)
\r
301 throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + statements.length + ") of statements.");
\r
302 return (double[])graph.getValueAsObject(statements[0].getObject());
\r
305 public void setLength(Object v) {
\r
306 Resource predicate = org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasLength;
\r
307 Collection<Resource> objects = graph.getObjects(resource, predicate);
\r
308 if(objects.size() == 0) {
\r
309 Resource r = graph.newResource();
\r
310 Resource valueType = org.simantics.db.Builtins.getInstance(graph).Double;
\r
311 graph.addStatement(r, graph.getBuiltins().InstanceOf, valueType);
\r
312 graph.setValueAsObject(r, v);
\r
313 graph.addStatement(resource, predicate, r);
\r
315 else if(objects.size() == 1)
\r
316 for(Resource r : objects)
\r
317 graph.setValueAsObject(r, v);
\r
319 throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + objects.size() + ") of statements.");
\r
322 public org.simantics.processeditor.stubs.PipeControlPoint getControlPoint() {
\r
323 Statement[] statements = graph.getStatements(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasControlPoint);
\r
324 if(statements.length > 1)
\r
325 throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + statements.length + ") of statements.");
\r
326 if(statements.length == 0)
\r
328 return new org.simantics.processeditor.stubs.PipeControlPoint(graph, statements[0].getObject());
\r
331 public void addControlPoint(ResourceContainer v) {
\r
332 graph.addStatement(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasControlPoint, v.getResource());
\r
335 public void setControlPoint(ResourceContainer v) {
\r
336 Resource predicate = org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasControlPoint;
\r
337 graph.removeStatements(resource, predicate);
\r
338 graph.addStatement(resource, predicate, v.getResource());
\r
341 public double[] getRotationAngle() {
\r
342 Statement[] statements = graph.getStatements(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasRotationAngle);
\r
343 if(statements.length != 1)
\r
344 throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + statements.length + ") of statements.");
\r
345 return (double[])graph.getValueAsObject(statements[0].getObject());
\r
348 public void setRotationAngle(Object v) {
\r
349 Resource predicate = org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasRotationAngle;
\r
350 Collection<Resource> objects = graph.getObjects(resource, predicate);
\r
351 if(objects.size() == 0) {
\r
352 Resource r = graph.newResource();
\r
353 Resource valueType = org.simantics.db.Builtins.getInstance(graph).Double;
\r
354 graph.addStatement(r, graph.getBuiltins().InstanceOf, valueType);
\r
355 graph.setValueAsObject(r, v);
\r
356 graph.addStatement(resource, predicate, r);
\r
358 else if(objects.size() == 1)
\r
359 for(Resource r : objects)
\r
360 graph.setValueAsObject(r, v);
\r
362 throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + objects.size() + ") of statements.");
\r