package org.simantics.plant3d.scenegraph; import java.util.Collection; import java.util.HashSet; import java.util.Set; import javax.vecmath.Quat4d; import javax.vecmath.Vector3d; import org.simantics.db.Resource; import org.simantics.g3d.math.MathTools; import org.simantics.g3d.scenegraph.IG3DNode; import org.simantics.g3d.scenegraph.NodeMap; import org.simantics.g3d.scenegraph.NodeMapProvider; import org.simantics.g3d.scenegraph.base.INode; import org.simantics.g3d.scenegraph.base.NodeException; import org.simantics.g3d.scenegraph.base.ParentNode; import org.simantics.objmap.graph.annotations.GraphType; import org.simantics.objmap.graph.annotations.RelatedElementsAdd; import org.simantics.objmap.graph.annotations.RelatedElementsGet; import org.simantics.objmap.graph.annotations.RelatedElementsRem; import org.simantics.plant3d.editor.P3DNodeMap; import org.simantics.plant3d.ontology.Plant3D; import vtk.vtkProp; @GraphType(Plant3D.URIs.Plant) public class P3DRootNode extends ParentNode implements IG3DNode, NodeMapProvider { @RelatedElementsAdd(Plant3D.URIs.children) public void addChild(INode node) { //public void addChild(IP3DVisualNode node) { addNode(Plant3D.URIs.children,node); } @RelatedElementsGet(Plant3D.URIs.children) public Collection getChild() { return getNodes(Plant3D.URIs.children); } @RelatedElementsRem(Plant3D.URIs.children) public void remChild(INode node) { //public void remChild(IP3DNode node) { removeNode(Plant3D.URIs.children, node); } private P3DNodeMap nodeMap; public void setNodeMap(P3DNodeMap nodeMap) { this.nodeMap = nodeMap; } @Override public NodeMap getNodeMap() { return nodeMap; } @Override public ParentNode getParent() { return null; } @Override public ParentNode getRootNode() { return this; } public javax.vecmath.Quat4d getOrientation() { return MathTools.getIdentityQuat(); }; @Override public Vector3d getPosition() { return new Vector3d(); } @Override public Quat4d getWorldOrientation() { return MathTools.getIdentityQuat(); } @Override public Vector3d getWorldPosition() { return new Vector3d(); } @Override public Quat4d getWorldOrientation(Quat4d localOrientation) { return localOrientation; } @Override public Vector3d getWorldPosition(Vector3d localPosition) { return localPosition; } @Override public Quat4d getLocalOrientation(Quat4d worldOrientation) { return worldOrientation; } @Override public Vector3d getLocalPosition(Vector3d worldPosition) { return worldPosition; } @Override public void setPosition(Vector3d position) { throw new NodeException("Cannot set root node position"); } @Override public void setOrientation(Quat4d orientation) { throw new NodeException("Cannot set root node orientation"); } @Override public void setWorldOrientation(Quat4d orientation) { throw new NodeException("Cannot set root node orientation"); } @Override public void setWorldPosition(Vector3d position) { throw new NodeException("Cannot set root node orientation"); } public String getUniqueName(String prefix) { Set names = new HashSet(); for (INode node : getChild()) { if (!(node instanceof IP3DVisualNode)) continue; IP3DVisualNode n = (IP3DVisualNode)node; names.add(n.getName()); } int i = 1; while (true) { String genName = prefix + "_" + i; if (!names.contains(genName)) return genName; i++; } } @SuppressWarnings("rawtypes") @Override public Object getAdapter(Class adapter) { if (NodeMap.class == adapter) return nodeMap; return null; } public Nozzle createNozzle() { return new Nozzle(); } public Equipment createEquipment() { return new Equipment(); } public InlineComponent createInline() { return new InlineComponent(); } public EndComponent createEnd() { return new EndComponent(); } public TurnComponent createTurn() { return new TurnComponent(); } }