/******************************************************************************* * 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 DirectedControlPoint extends Entity implements IDirectedControlPoint { public DirectedControlPoint(Graph graph, ResourceContainer resourceContainer) { super(graph, resourceContainer.getResource()); } public DirectedControlPoint(IEntity entity) { super(entity.getGraph(), entity.getResource()); } public Graph getGraph() { return graph; } public static DirectedControlPoint createDefault(Graph graph) { return new DirectedControlPoint(graph, InstanceFactory.instantiate(graph, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).DirectedControlPoint)); } public static boolean isInstance(IEntity entity) { Graph graph = entity.getGraph(); Resource type = org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).DirectedControlPoint; return graph.isInstanceOf(entity.getResource(), type); } @Override public Resource getResource() { return resource; } public org.simantics.processeditor.stubs.PathLegEndControlPoint toPathLegEndControlPoint() { return new org.simantics.processeditor.stubs.PathLegEndControlPoint(graph, resource); } public DirectedControlPoint toDirectedControlPoint() { return this; } public org.simantics.processeditor.stubs.RunEndControlPoint toRunEndControlPoint() { return new org.simantics.processeditor.stubs.RunEndControlPoint(graph, resource); } public org.simantics.processeditor.stubs.PipeControlPoint toPipeControlPoint() { return new org.simantics.processeditor.stubs.PipeControlPoint(graph, resource); } 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."); 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."); 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."); 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."); 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.processeditor.stubs.PipeControlPoint getNext() { Statement[] statements = graph.getStatements(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasNext); 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 addNext(ResourceContainer v) { graph.addStatement(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasNext, v.getResource()); } public void setNext(ResourceContainer v) { Resource predicate = org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasNext; graph.removeStatements(resource, predicate); graph.addStatement(resource, predicate, v.getResource()); } public org.simantics.processeditor.stubs.PipeControlPoint getPrevious() { Statement[] statements = graph.getStatements(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasPrevious); 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 addPrevious(ResourceContainer v) { graph.addStatement(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasPrevious, v.getResource()); } public void setPrevious(ResourceContainer v) { Resource predicate = org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasPrevious; 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 Collection getSubPoint() { Statement[] statements = graph.getStatements(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasSubPoint); Collection ret = new ArrayList(statements.length); for(Statement s : statements) ret.add(new org.simantics.processeditor.stubs.PipeControlPoint(graph, s.getObject())); return ret; } public void addSubPoint(ResourceContainer v) { graph.addStatement(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasSubPoint, v.getResource()); } public org.simantics.processeditor.stubs.PipeControlPoint getSubPointOf() { Statement[] statements = graph.getStatements(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).SubPointOf); 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 addSubPointOf(ResourceContainer v) { graph.addStatement(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).SubPointOf, v.getResource()); } public void setSubPointOf(ResourceContainer v) { Resource predicate = org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).SubPointOf; graph.removeStatements(resource, predicate); graph.addStatement(resource, predicate, v.getResource()); } // [Nozzle] | [Pipeline Component] public org.simantics.layer0.utils.IEntity getControlPointOf() { Statement[] statements = graph.getStatements(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).ControlPointOf); if(statements.length > 1) throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + statements.length + ") of statements."); if(statements.length == 0) return null; return new Entity(graph, statements[0].getObject()); } // [Nozzle] | [Pipeline Component] public void addControlPointOf(ResourceContainer v) { graph.addStatement(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).ControlPointOf, v.getResource()); } // [Nozzle] | [Pipeline Component] public void setControlPointOf(ResourceContainer v) { Resource predicate = org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).ControlPointOf; graph.removeStatements(resource, predicate); graph.addStatement(resource, predicate, v.getResource()); } public org.simantics.processeditor.stubs.PipeRun getControlPointOfPipeRun() { Statement[] statements = graph.getStatements(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).ControlPointOfPipeRun); 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.PipeRun(graph, statements[0].getObject()); } public void addControlPointOfPipeRun(ResourceContainer v) { graph.addStatement(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).ControlPointOfPipeRun, v.getResource()); } public void setControlPointOfPipeRun(ResourceContainer v) { Resource predicate = org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).ControlPointOfPipeRun; graph.removeStatements(resource, predicate); graph.addStatement(resource, predicate, v.getResource()); } }