/******************************************************************************* * Copyright (c) 2012, 2013 Association for Decentralized Information Management in * Industry THTH ry. * 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.g3d.csg.scenegraph2; import java.util.Collection; import java.util.HashSet; import java.util.Set; import java.util.Stack; import javax.vecmath.Quat4d; import javax.vecmath.Vector3d; import org.simantics.db.Resource; import org.simantics.g3d.csg.editor.CSGNodeMap; import org.simantics.g3d.csg.ontology.CSG; 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.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 vtk.vtkProp; @GraphType(CSG.URIs.Model) public class CSGrootNode extends ParentNode implements IG3DNode, NodeMapProvider { private CSGNodeMap nodeMap; public void setNodeMap(CSGNodeMap nodeMap) { this.nodeMap = nodeMap; } @Override public NodeMap getNodeMap() { return nodeMap; } @Override public ParentNode getParent() { return null; } @Override public ParentNode getRootNode() { return this; } @RelatedElementsAdd(CSG.URIs.hasChildShape) public void addChild(ICSGnode node) { addNode("child",node); } @RelatedElementsGet(CSG.URIs.hasChildShape) public Collection getChild() { return getNodes("child"); } @RelatedElementsRem(CSG.URIs.hasChildShape) public void remChild(ICSGnode node) { removeNode("child", node); } 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(); Stack nodes = new Stack(); nodes.addAll(getChild()); while (!nodes.isEmpty()) { ICSGnode n = nodes.pop(); names.add(((ICSGnode)n).getName()); if (n instanceof CSGparentNode) { nodes.addAll(((CSGparentNode)n).getChild()); nodes.addAll(((CSGparentNode)n).getPrimaryChild()); nodes.addAll(((CSGparentNode)n).getSecondaryChild()); } } int i = 1; while (true) { String genName = prefix + "_" + i; if (!names.contains(genName)) return genName; i++; } } @Override public C getAdapter(Class adapter) { if (adapter.isAssignableFrom(NodeMap.class)) return adapter.cast(nodeMap); return null; } }