/******************************************************************************* * 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 P3DNode extends Entity implements IP3DNode { public P3DNode(Graph graph, ResourceContainer resourceContainer) { super(graph, resourceContainer.getResource()); } public P3DNode(IEntity entity) { super(entity.getGraph(), entity.getResource()); } public Graph getGraph() { return graph; } public static P3DNode createDefault(Graph graph) { return new P3DNode(graph, InstanceFactory.instantiate(graph, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).P3DNode)); } public static boolean isInstance(IEntity entity) { Graph graph = entity.getGraph(); Resource type = org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).P3DNode; return graph.isInstanceOf(entity.getResource(), type); } @Override public Resource getResource() { return resource; } public org.simantics.proconf.g3d.stubs.G3DNode toG3DNode() { return new org.simantics.proconf.g3d.stubs.G3DNode(graph, resource); } public P3DNode toP3DNode() { return this; } 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()); } }