]> gerrit.simantics Code Review - simantics/3d.git/blob - org.simantics.g3d.csg/src/org/simantics/g3d/csg/scenegraph2/CSGrootNode.java
Compiler warning elimination
[simantics/3d.git] / org.simantics.g3d.csg / src / org / simantics / g3d / csg / scenegraph2 / CSGrootNode.java
1 /*******************************************************************************
2  * Copyright (c) 2012, 2013 Association for Decentralized Information Management in
3  * Industry THTH ry.
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
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.g3d.csg.scenegraph2;
13
14 import java.util.Collection;
15 import java.util.HashSet;
16 import java.util.Set;
17 import java.util.Stack;
18
19 import javax.vecmath.Quat4d;
20 import javax.vecmath.Vector3d;
21
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;
35
36 import vtk.vtkProp;
37
38
39 @GraphType(CSG.URIs.Model)
40 public class CSGrootNode extends ParentNode<ICSGnode> implements IG3DNode, NodeMapProvider<Resource,vtkProp, ICSGnode> {
41         
42         
43         private CSGNodeMap nodeMap;
44         
45         public void setNodeMap(CSGNodeMap nodeMap) {
46                 this.nodeMap = nodeMap;
47         }
48         
49         @Override
50         public NodeMap<Resource,vtkProp, ICSGnode> getNodeMap() {
51                 return nodeMap;
52         }
53         
54         @Override
55         public ParentNode<?> getParent() {
56                 return null;
57         }
58         
59         @Override
60         public ParentNode<?> getRootNode() {
61                 return this;
62         }
63         
64         @RelatedElementsAdd(CSG.URIs.hasChildShape)
65         public void addChild(ICSGnode node) {
66                 addNode("child",node);
67         }
68         
69         @RelatedElementsGet(CSG.URIs.hasChildShape)
70         public Collection<ICSGnode> getChild() {
71                 return getNodes("child");
72         }
73         
74         @RelatedElementsRem(CSG.URIs.hasChildShape)
75         public void remChild(ICSGnode node) {
76                 removeNode("child", node);
77         }
78         
79         public javax.vecmath.Quat4d getOrientation() {
80                 return MathTools.getIdentityQuat();
81         };
82         
83         @Override
84         public Vector3d getPosition() {
85                 return new Vector3d();
86         }
87         
88         @Override
89         public Quat4d getWorldOrientation() {
90                 return MathTools.getIdentityQuat();
91         }
92         
93         @Override
94         public Vector3d getWorldPosition() {
95                 return new Vector3d();
96         }
97         
98         @Override
99         public Quat4d getWorldOrientation(Quat4d localOrientation) {
100                 return localOrientation;
101         }
102         
103         @Override
104         public Vector3d getWorldPosition(Vector3d localPosition) {
105                 return localPosition;
106         }
107         
108         @Override
109         public Quat4d getLocalOrientation(Quat4d worldOrientation) {
110                 return worldOrientation;
111         }
112         
113         @Override
114         public Vector3d getLocalPosition(Vector3d worldPosition) {
115                 return worldPosition;
116         }
117         
118         @Override
119         public void setPosition(Vector3d position) {
120                 throw new NodeException("Cannot set root node position");
121         }
122         
123         @Override
124         public void setOrientation(Quat4d orientation) {
125                 throw new NodeException("Cannot set root node orientation");
126         }
127         
128         @Override
129         public void setWorldOrientation(Quat4d orientation) {
130                 throw new NodeException("Cannot set root node orientation");
131         }
132         
133         @Override
134         public void setWorldPosition(Vector3d position) {
135                 throw new NodeException("Cannot set root node orientation");
136         }
137         
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());
149                         }
150                 }
151                 int i = 1;
152                 while (true) {
153                         String genName = prefix + "_" + i;
154                         if (!names.contains(genName))
155                                 return genName;
156                         i++;
157                 }
158         }
159         
160
161         @Override
162         public <C> C getAdapter(Class<C> adapter) {
163                 if (adapter.isAssignableFrom(NodeMap.class))
164                         return adapter.cast(nodeMap);
165                 return null;
166         }
167         
168
169 }