]> gerrit.simantics Code Review - simantics/3d.git/blob - org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/P3DRootNode.java
Compiler warning elimination
[simantics/3d.git] / org.simantics.plant3d / src / org / simantics / plant3d / scenegraph / P3DRootNode.java
1 package org.simantics.plant3d.scenegraph;
2
3 import java.util.Collection;
4 import java.util.HashSet;
5 import java.util.Set;
6
7 import javax.vecmath.Quat4d;
8 import javax.vecmath.Vector3d;
9
10 import org.simantics.db.Resource;
11 import org.simantics.g3d.math.MathTools;
12 import org.simantics.g3d.scenegraph.IG3DNode;
13 import org.simantics.g3d.scenegraph.NodeMap;
14 import org.simantics.g3d.scenegraph.NodeMapProvider;
15 import org.simantics.g3d.scenegraph.base.INode;
16 import org.simantics.g3d.scenegraph.base.NodeException;
17 import org.simantics.g3d.scenegraph.base.ParentNode;
18 import org.simantics.objmap.graph.IMapping;
19 import org.simantics.objmap.graph.annotations.GraphType;
20 import org.simantics.objmap.graph.annotations.RelatedElementsAdd;
21 import org.simantics.objmap.graph.annotations.RelatedElementsGet;
22 import org.simantics.objmap.graph.annotations.RelatedElementsRem;
23 import org.simantics.plant3d.ontology.Plant3D;
24
25 import vtk.vtkProp;
26
27 @GraphType(Plant3D.URIs.Plant)
28 public class P3DRootNode extends ParentNode<INode> implements IG3DNode, NodeMapProvider<Resource, vtkProp, INode> {
29         
30         
31         @RelatedElementsAdd(Plant3D.URIs.children)
32         public void addChild(INode node) {
33         //public void addChild(IP3DVisualNode node) {
34                 addNode(Plant3D.URIs.children,node);
35         }
36         
37         @RelatedElementsGet(Plant3D.URIs.children)
38         public Collection<INode> getChild() {
39                 return getNodes(Plant3D.URIs.children);
40         }
41         
42         @RelatedElementsRem(Plant3D.URIs.children)
43         public void remChild(INode node) {
44         //public void remChild(IP3DNode node) {
45                 removeNode(Plant3D.URIs.children, node);
46         }
47         
48         private NodeMap<Resource, vtkProp, INode> nodeMap;
49         private IMapping<Resource, INode> mapping;
50         
51         public void setNodeMap(NodeMap<Resource, vtkProp, INode> nodeMap) {
52                 this.nodeMap = nodeMap;
53                 this.mapping = nodeMap.getMapping();
54         }
55         
56         public void setMapping(IMapping<Resource, INode> mapping) {
57                 this.mapping = mapping;
58         }
59         
60         @Override
61         public NodeMap<Resource, vtkProp, INode> getNodeMap() {
62                 return nodeMap;
63         }
64         
65         public Resource getNodeResource(INode node) {
66                 return mapping.inverseGet(node);
67         }
68         
69         public INode getResourceNode(Resource r) {
70                 return mapping.get(r);
71         }
72         
73         @Override
74         public ParentNode<?> getParent() {
75                 return null;
76         }
77         
78         @Override
79         public ParentNode<?> getRootNode() {
80                 return this;
81         }
82         
83         public javax.vecmath.Quat4d getOrientation() {
84                 return MathTools.getIdentityQuat();
85         };
86         
87         @Override
88         public Vector3d getPosition() {
89                 return new Vector3d();
90         }
91         
92         @Override
93         public Quat4d getWorldOrientation() {
94                 return MathTools.getIdentityQuat();
95         }
96         
97         @Override
98         public Vector3d getWorldPosition() {
99                 return new Vector3d();
100         }
101         
102         @Override
103         public Quat4d getWorldOrientation(Quat4d localOrientation) {
104                 return localOrientation;
105         }
106         
107         @Override
108         public Vector3d getWorldPosition(Vector3d localPosition) {
109                 return localPosition;
110         }
111         
112         @Override
113         public Quat4d getLocalOrientation(Quat4d worldOrientation) {
114                 return worldOrientation;
115         }
116         
117         @Override
118         public Vector3d getLocalPosition(Vector3d worldPosition) {
119                 return worldPosition;
120         }
121         
122         @Override
123         public void setPosition(Vector3d position) {
124                 throw new NodeException("Cannot set root node position");
125         }
126         
127         @Override
128         public void setOrientation(Quat4d orientation) {
129                 throw new NodeException("Cannot set root node orientation");
130         }
131         
132         @Override
133         public void setWorldOrientation(Quat4d orientation) {
134                 throw new NodeException("Cannot set root node orientation");
135         }
136         
137         @Override
138         public void setWorldPosition(Vector3d position) {
139                 throw new NodeException("Cannot set root node orientation");
140         }
141         
142         public String getUniqueName(String prefix) {
143                 Set<String> names = new HashSet<String>();
144                 for (INode node : getChild()) {
145                         if (!(node instanceof IP3DVisualNode))
146                                 continue;
147                         IP3DVisualNode n = (IP3DVisualNode)node;
148                         names.add(n.getName());
149                 }
150                 int i = 1;
151                 while (true) {
152                         String genName = prefix + "_" + i;
153                         if (!names.contains(genName))
154                                 return genName;
155                         i++;
156                 }
157         }
158
159         
160         @Override
161         public <T> T getAdapter(Class<T> adapter) {
162                 if (adapter.isAssignableFrom(NodeMap.class))
163                         return adapter.cast(nodeMap);
164                 return null;
165         }
166         
167         public Nozzle createNozzle() {
168                 return new Nozzle();
169         }
170         
171         public Equipment createEquipment() {
172                 return new Equipment();
173         }
174         
175         public InlineComponent createInline() {
176                 return new InlineComponent();
177         }
178         
179         public EndComponent createEnd() {
180                 return new EndComponent();
181         }
182         
183         public TurnComponent createTurn() {
184                 return new TurnComponent();
185         }
186 }