1 /*******************************************************************************
2 * Copyright (c) 2012, 2013 Association for Decentralized Information Management in
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.g3d.csg.scenegraph2;
14 import java.util.Collection;
15 import java.util.HashSet;
17 import java.util.Stack;
19 import javax.vecmath.Quat4d;
20 import javax.vecmath.Vector3d;
22 import org.simantics.g3d.csg.editor.CSGNodeMap;
23 import org.simantics.g3d.csg.ontology.CSG;
24 import org.simantics.g3d.math.MathTools;
25 import org.simantics.g3d.scenegraph.IG3DNode;
26 import org.simantics.g3d.scenegraph.NodeMap;
27 import org.simantics.g3d.scenegraph.NodeMapProvider;
28 import org.simantics.g3d.scenegraph.base.NodeException;
29 import org.simantics.g3d.scenegraph.base.ParentNode;
30 import org.simantics.objmap.graph.annotations.GraphType;
31 import org.simantics.objmap.graph.annotations.RelatedElementsAdd;
32 import org.simantics.objmap.graph.annotations.RelatedElementsGet;
33 import org.simantics.objmap.graph.annotations.RelatedElementsRem;
38 @GraphType(CSG.URIs.Model)
39 public class CSGrootNode extends ParentNode<ICSGnode> implements IG3DNode, NodeMapProvider<vtkProp, ICSGnode> {
42 private CSGNodeMap nodeMap;
44 public void setNodeMap(CSGNodeMap nodeMap) {
45 this.nodeMap = nodeMap;
49 public NodeMap<vtkProp, ICSGnode> getNodeMap() {
54 public ParentNode<?> getParent() {
59 public ParentNode<?> getRootNode() {
63 @RelatedElementsAdd(CSG.URIs.hasChildShape)
64 public void addChild(ICSGnode node) {
65 addNode("child",node);
68 @RelatedElementsGet(CSG.URIs.hasChildShape)
69 public Collection<ICSGnode> getChild() {
70 return getNodes("child");
73 @RelatedElementsRem(CSG.URIs.hasChildShape)
74 public void remChild(ICSGnode node) {
75 removeNode("child", node);
78 public javax.vecmath.Quat4d getOrientation() {
79 return MathTools.getIdentityQuat();
83 public Vector3d getPosition() {
84 return new Vector3d();
88 public Quat4d getWorldOrientation() {
89 return MathTools.getIdentityQuat();
93 public Vector3d getWorldPosition() {
94 return new Vector3d();
98 public Quat4d getWorldOrientation(Quat4d localOrientation) {
99 return localOrientation;
103 public Vector3d getWorldPosition(Vector3d localPosition) {
104 return localPosition;
108 public Quat4d getLocalOrientation(Quat4d worldOrientation) {
109 return worldOrientation;
113 public Vector3d getLocalPosition(Vector3d worldPosition) {
114 return worldPosition;
118 public void setPosition(Vector3d position) {
119 throw new NodeException("Cannot set root node position");
123 public void setOrientation(Quat4d orientation) {
124 throw new NodeException("Cannot set root node orientation");
128 public void setWorldOrientation(Quat4d orientation) {
129 throw new NodeException("Cannot set root node orientation");
133 public void setWorldPosition(Vector3d position) {
134 throw new NodeException("Cannot set root node orientation");
137 public String getUniqueName(String prefix) {
138 Set<String> names = new HashSet<String>();
139 Stack<ICSGnode> nodes = new Stack<ICSGnode>();
140 nodes.addAll(getChild());
141 while (!nodes.isEmpty()) {
142 ICSGnode n = nodes.pop();
143 names.add(((ICSGnode)n).getName());
144 if (n instanceof CSGparentNode) {
145 nodes.addAll(((CSGparentNode)n).getChild());
146 nodes.addAll(((CSGparentNode)n).getPrimaryChild());
147 nodes.addAll(((CSGparentNode)n).getSecondaryChild());
152 String genName = prefix + "_" + i;
153 if (!names.contains(genName))
161 public Object getAdapter(Class adapter) {
162 if (NodeMap.class == adapter)