/******************************************************************************* * Copyright (c) 2007 VTT Technical Research Centre of Finland and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * VTT Technical Research Centre of Finland - initial API and implementation *******************************************************************************/ package org.simantics.processeditor.stubs; import org.simantics.db.Resource; import org.simantics.db.ResourceContainer; import org.simantics.db.Statement; import org.simantics.db.Graph; import org.simantics.db.ResourceContainer; import org.simantics.layer0.utils.ResourceDoesNotSatisfyAssumptionException; import org.simantics.layer0.utils.IEntity; import org.simantics.layer0.utils.internal.Entity; import org.simantics.layer0.utils.instantiation.InstanceFactory; import java.util.Collection; import java.util.ArrayList; public class Reducer extends Entity implements IReducer { public Reducer(Graph graph, ResourceContainer resourceContainer) { super(graph, resourceContainer.getResource()); } public Reducer(IEntity entity) { super(entity.getGraph(), entity.getResource()); } public Graph getGraph() { return graph; } public static Reducer createDefault(Graph graph) { return new Reducer(graph, InstanceFactory.instantiate(graph, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).Reducer)); } public static boolean isInstance(IEntity entity) { Graph graph = entity.getGraph(); Resource type = org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).Reducer; return graph.isInstanceOf(entity.getResource(), type); } @Override public Resource getResource() { return resource; } public org.simantics.processeditor.stubs.CodedComponent toCodedComponent() { return new org.simantics.processeditor.stubs.CodedComponent(graph, resource); } public Reducer toReducer() { return this; } public org.simantics.proconf.g3d.stubs.G3DNode toG3DNode() { return new org.simantics.proconf.g3d.stubs.G3DNode(graph, resource); } public org.simantics.processeditor.stubs.SizeChangeComponent toSizeChangeComponent() { return new org.simantics.processeditor.stubs.SizeChangeComponent(graph, resource); } public org.simantics.processeditor.stubs.PBSNode toPBSNode() { return new org.simantics.processeditor.stubs.PBSNode(graph, resource); } public org.simantics.processeditor.stubs.InlineComponent toInlineComponent() { return new org.simantics.processeditor.stubs.InlineComponent(graph, resource); } public org.simantics.processeditor.stubs.P3DNode toP3DNode() { return new org.simantics.processeditor.stubs.P3DNode(graph, resource); } public org.simantics.processeditor.stubs.DualConnectedComponent toDualConnectedComponent() { return new org.simantics.processeditor.stubs.DualConnectedComponent(graph, resource); } public org.simantics.processeditor.stubs.PipelineComponent toPipelineComponent() { return new org.simantics.processeditor.stubs.PipelineComponent(graph, resource); } public org.simantics.processeditor.stubs.FixedLengthInlineComponent toFixedLengthInlineComponent() { return new org.simantics.processeditor.stubs.FixedLengthInlineComponent(graph, resource); } public org.simantics.processeditor.stubs.LibraryComponent toLibraryComponent() { return new org.simantics.processeditor.stubs.LibraryComponent(graph, resource); } public Collection getChild() { Statement[] statements = graph.getStatements(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasChild); Collection ret = new ArrayList(statements.length); for(Statement s : statements) ret.add(new org.simantics.proconf.g3d.stubs.G3DNode(graph, s.getObject())); return ret; } public void addChild(ResourceContainer v) { graph.addStatement(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasChild, v.getResource()); } public org.simantics.proconf.g3d.stubs.G3DNode getParent() { Statement[] statements = graph.getStatements(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasParent); if(statements.length > 1) throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + statements.length + ") of statements."); if(statements.length == 0) return null; return new org.simantics.proconf.g3d.stubs.G3DNode(graph, statements[0].getObject()); } public void addParent(ResourceContainer v) { graph.addStatement(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasParent, v.getResource()); } public void setParent(ResourceContainer v) { Resource predicate = org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasParent; graph.removeStatements(resource, predicate); graph.addStatement(resource, predicate, v.getResource()); } public org.simantics.proconf.g3d.stubs.Position getLocalPosition() { Statement[] statements = graph.getStatements(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasLocalPosition); if(statements.length > 1) throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + statements.length + ") of statements."); if(statements.length == 0) return null; return new org.simantics.proconf.g3d.stubs.Position(graph, statements[0].getObject()); } public void addLocalPosition(ResourceContainer v) { graph.addStatement(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasLocalPosition, v.getResource()); } public void setLocalPosition(ResourceContainer v) { Resource predicate = org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasLocalPosition; graph.removeStatements(resource, predicate); graph.addStatement(resource, predicate, v.getResource()); } public org.simantics.proconf.g3d.stubs.Position getWorldPosition() { Statement[] statements = graph.getStatements(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasWorldPosition); if(statements.length > 1) throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + statements.length + ") of statements."); if(statements.length == 0) return null; return new org.simantics.proconf.g3d.stubs.Position(graph, statements[0].getObject()); } public void addWorldPosition(ResourceContainer v) { graph.addStatement(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasWorldPosition, v.getResource()); } public void setWorldPosition(ResourceContainer v) { Resource predicate = org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasWorldPosition; graph.removeStatements(resource, predicate); graph.addStatement(resource, predicate, v.getResource()); } public org.simantics.proconf.g3d.stubs.Orientation getLocalOrientation() { Statement[] statements = graph.getStatements(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasLocalOrientation); if(statements.length > 1) throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + statements.length + ") of statements."); if(statements.length == 0) return null; return new org.simantics.proconf.g3d.stubs.Orientation(graph, statements[0].getObject()); } public void addLocalOrientation(ResourceContainer v) { graph.addStatement(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasLocalOrientation, v.getResource()); } public void setLocalOrientation(ResourceContainer v) { Resource predicate = org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasLocalOrientation; graph.removeStatements(resource, predicate); graph.addStatement(resource, predicate, v.getResource()); } public org.simantics.proconf.g3d.stubs.Orientation getWorldOrientation() { Statement[] statements = graph.getStatements(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasWorldOrientation); if(statements.length > 1) throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + statements.length + ") of statements."); if(statements.length == 0) return null; return new org.simantics.proconf.g3d.stubs.Orientation(graph, statements[0].getObject()); } public void addWorldOrientation(ResourceContainer v) { graph.addStatement(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasWorldOrientation, v.getResource()); } public void setWorldOrientation(ResourceContainer v) { Resource predicate = org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasWorldOrientation; graph.removeStatements(resource, predicate); graph.addStatement(resource, predicate, v.getResource()); } public org.simantics.proconf.g3d.stubs.Center getCenter() { Statement[] statements = graph.getStatements(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasCenter); if(statements.length > 1) throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + statements.length + ") of statements."); if(statements.length == 0) return null; return new org.simantics.proconf.g3d.stubs.Center(graph, statements[0].getObject()); } public void addCenter(ResourceContainer v) { graph.addStatement(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasCenter, v.getResource()); } public void setCenter(ResourceContainer v) { Resource predicate = org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasCenter; graph.removeStatements(resource, predicate); graph.addStatement(resource, predicate, v.getResource()); } public org.simantics.processeditor.stubs.PBSNode getParentStructure() { Statement[] statements = graph.getStatements(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasParentStructure); if(statements.length > 1) throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + statements.length + ") of statements."); if(statements.length == 0) return null; return new org.simantics.processeditor.stubs.PBSNode(graph, statements[0].getObject()); } public void addParentStructure(ResourceContainer v) { graph.addStatement(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasParentStructure, v.getResource()); } public void setParentStructure(ResourceContainer v) { Resource predicate = org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasParentStructure; graph.removeStatements(resource, predicate); graph.addStatement(resource, predicate, v.getResource()); } public Collection getChildStructure() { Statement[] statements = graph.getStatements(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasChildStructure); Collection ret = new ArrayList(statements.length); for(Statement s : statements) ret.add(new org.simantics.processeditor.stubs.PBSNode(graph, s.getObject())); return ret; } public void addChildStructure(ResourceContainer v) { graph.addStatement(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasChildStructure, v.getResource()); } public org.simantics.proconf.g3d.stubs.G3DModel getGraphics() { Statement[] statements = graph.getStatements(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasGraphics); if(statements.length > 1) throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + statements.length + ") of statements."); if(statements.length == 0) return null; return new org.simantics.proconf.g3d.stubs.G3DModel(graph, statements[0].getObject()); } public void addGraphics(ResourceContainer v) { graph.addStatement(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasGraphics, v.getResource()); } public void setGraphics(ResourceContainer v) { Resource predicate = org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasGraphics; graph.removeStatements(resource, predicate); graph.addStatement(resource, predicate, v.getResource()); } public double[] getPipeDiameter() { Statement[] statements = graph.getStatements(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasPipeDiameter); if(statements.length != 1) throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + statements.length + ") of statements."); return (double[])graph.getValueAsObject(statements[0].getObject()); } public void setPipeDiameter(Object v) { Resource predicate = org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasPipeDiameter; Collection objects = graph.getObjects(resource, predicate); if(objects.size() == 0) { Resource r = graph.newResource(); Resource valueType = org.simantics.db.Builtins.getInstance(graph).Double; graph.addStatement(r, graph.getBuiltins().InstanceOf, valueType); graph.setValueAsObject(r, v); graph.addStatement(resource, predicate, r); } else if(objects.size() == 1) for(Resource r : objects) graph.setValueAsObject(r, v); else throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + objects.size() + ") of statements."); } public double[] getLength() { Statement[] statements = graph.getStatements(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasLength); if(statements.length != 1) throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + statements.length + ") of statements."); return (double[])graph.getValueAsObject(statements[0].getObject()); } public void setLength(Object v) { Resource predicate = org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasLength; Collection objects = graph.getObjects(resource, predicate); if(objects.size() == 0) { Resource r = graph.newResource(); Resource valueType = org.simantics.db.Builtins.getInstance(graph).Double; graph.addStatement(r, graph.getBuiltins().InstanceOf, valueType); graph.setValueAsObject(r, v); graph.addStatement(resource, predicate, r); } else if(objects.size() == 1) for(Resource r : objects) graph.setValueAsObject(r, v); else throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + objects.size() + ") of statements."); } public org.simantics.processeditor.stubs.PipeControlPoint getControlPoint() { Statement[] statements = graph.getStatements(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasControlPoint); if(statements.length > 1) throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + statements.length + ") of statements."); if(statements.length == 0) return null; return new org.simantics.processeditor.stubs.PipeControlPoint(graph, statements[0].getObject()); } public void addControlPoint(ResourceContainer v) { graph.addStatement(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasControlPoint, v.getResource()); } public void setControlPoint(ResourceContainer v) { Resource predicate = org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasControlPoint; graph.removeStatements(resource, predicate); graph.addStatement(resource, predicate, v.getResource()); } public double[] getRotationAngle() { Statement[] statements = graph.getStatements(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasRotationAngle); if(statements.length != 1) throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + statements.length + ") of statements."); return (double[])graph.getValueAsObject(statements[0].getObject()); } public void setRotationAngle(Object v) { Resource predicate = org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasRotationAngle; Collection objects = graph.getObjects(resource, predicate); if(objects.size() == 0) { Resource r = graph.newResource(); Resource valueType = org.simantics.db.Builtins.getInstance(graph).Double; graph.addStatement(r, graph.getBuiltins().InstanceOf, valueType); graph.setValueAsObject(r, v); graph.addStatement(resource, predicate, r); } else if(objects.size() == 1) for(Resource r : objects) graph.setValueAsObject(r, v); else throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + objects.size() + ") of statements."); } }