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.db.Resource;
23 import org.simantics.g3d.csg.editor.CSGNodeMap;
24 import org.simantics.g3d.csg.ontology.CSG;
25 import org.simantics.g3d.math.MathTools;
26 import org.simantics.g3d.scenegraph.IG3DNode;
27 import org.simantics.g3d.scenegraph.NodeMap;
28 import org.simantics.g3d.scenegraph.NodeMapProvider;
29 import org.simantics.g3d.scenegraph.base.NodeException;
30 import org.simantics.g3d.scenegraph.base.ParentNode;
31 import org.simantics.objmap.graph.annotations.GraphType;
32 import org.simantics.objmap.graph.annotations.RelatedElementsAdd;
33 import org.simantics.objmap.graph.annotations.RelatedElementsGet;
34 import org.simantics.objmap.graph.annotations.RelatedElementsRem;
39 @GraphType(CSG.URIs.Model)
40 public class CSGrootNode extends ParentNode<ICSGnode> implements IG3DNode, NodeMapProvider<Resource,vtkProp, ICSGnode> {
43 private CSGNodeMap nodeMap;
45 public void setNodeMap(CSGNodeMap nodeMap) {
46 this.nodeMap = nodeMap;
50 public NodeMap<Resource,vtkProp, ICSGnode> getNodeMap() {
55 public ParentNode<?> getParent() {
60 public ParentNode<?> getRootNode() {
64 @RelatedElementsAdd(CSG.URIs.hasChildShape)
65 public void addChild(ICSGnode node) {
66 addNode("child",node);
69 @RelatedElementsGet(CSG.URIs.hasChildShape)
70 public Collection<ICSGnode> getChild() {
71 return getNodes("child");
74 @RelatedElementsRem(CSG.URIs.hasChildShape)
75 public void remChild(ICSGnode node) {
76 removeNode("child", node);
79 public javax.vecmath.Quat4d getOrientation() {
80 return MathTools.getIdentityQuat();
84 public Vector3d getPosition() {
85 return new Vector3d();
89 public Quat4d getWorldOrientation() {
90 return MathTools.getIdentityQuat();
94 public Vector3d getWorldPosition() {
95 return new Vector3d();
99 public Quat4d getWorldOrientation(Quat4d localOrientation) {
100 return localOrientation;
104 public Vector3d getWorldPosition(Vector3d localPosition) {
105 return localPosition;
109 public Quat4d getLocalOrientation(Quat4d worldOrientation) {
110 return worldOrientation;
114 public Vector3d getLocalPosition(Vector3d worldPosition) {
115 return worldPosition;
119 public void setPosition(Vector3d position) {
120 throw new NodeException("Cannot set root node position");
124 public void setOrientation(Quat4d orientation) {
125 throw new NodeException("Cannot set root node orientation");
129 public void setWorldOrientation(Quat4d orientation) {
130 throw new NodeException("Cannot set root node orientation");
134 public void setWorldPosition(Vector3d position) {
135 throw new NodeException("Cannot set root node orientation");
138 public String getUniqueName(String prefix) {
139 Set<String> names = new HashSet<String>();
140 Stack<ICSGnode> nodes = new Stack<ICSGnode>();
141 nodes.addAll(getChild());
142 while (!nodes.isEmpty()) {
143 ICSGnode n = nodes.pop();
144 names.add(((ICSGnode)n).getName());
145 if (n instanceof CSGparentNode) {
146 nodes.addAll(((CSGparentNode)n).getChild());
147 nodes.addAll(((CSGparentNode)n).getPrimaryChild());
148 nodes.addAll(((CSGparentNode)n).getSecondaryChild());
153 String genName = prefix + "_" + i;
154 if (!names.contains(genName))
162 public <C> C getAdapter(Class<C> adapter) {
163 if (adapter.isAssignableFrom(NodeMap.class))
164 return adapter.cast(nodeMap);