]> gerrit.simantics Code Review - simantics/3d.git/blob - org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/P3DRootNode.java
Use generics type variable for mapping db object.
[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.annotations.GraphType;
19 import org.simantics.objmap.graph.annotations.RelatedElementsAdd;
20 import org.simantics.objmap.graph.annotations.RelatedElementsGet;
21 import org.simantics.objmap.graph.annotations.RelatedElementsRem;
22 import org.simantics.plant3d.editor.P3DNodeMap;
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 P3DNodeMap nodeMap;
49         
50         public void setNodeMap(P3DNodeMap nodeMap) {
51                 this.nodeMap = nodeMap;
52         }
53         
54         @Override
55         public NodeMap<Resource,vtkProp, INode> getNodeMap() {
56                 return nodeMap;
57         }
58         
59         @Override
60         public ParentNode<?> getParent() {
61                 return null;
62         }
63         
64         @Override
65         public ParentNode<?> getRootNode() {
66                 return this;
67         }
68         
69         public javax.vecmath.Quat4d getOrientation() {
70                 return MathTools.getIdentityQuat();
71         };
72         
73         @Override
74         public Vector3d getPosition() {
75                 return new Vector3d();
76         }
77         
78         @Override
79         public Quat4d getWorldOrientation() {
80                 return MathTools.getIdentityQuat();
81         }
82         
83         @Override
84         public Vector3d getWorldPosition() {
85                 return new Vector3d();
86         }
87         
88         @Override
89         public Quat4d getWorldOrientation(Quat4d localOrientation) {
90                 return localOrientation;
91         }
92         
93         @Override
94         public Vector3d getWorldPosition(Vector3d localPosition) {
95                 return localPosition;
96         }
97         
98         @Override
99         public Quat4d getLocalOrientation(Quat4d worldOrientation) {
100                 return worldOrientation;
101         }
102         
103         @Override
104         public Vector3d getLocalPosition(Vector3d worldPosition) {
105                 return worldPosition;
106         }
107         
108         @Override
109         public void setPosition(Vector3d position) {
110                 throw new NodeException("Cannot set root node position");
111         }
112         
113         @Override
114         public void setOrientation(Quat4d orientation) {
115                 throw new NodeException("Cannot set root node orientation");
116         }
117         
118         @Override
119         public void setWorldOrientation(Quat4d orientation) {
120                 throw new NodeException("Cannot set root node orientation");
121         }
122         
123         @Override
124         public void setWorldPosition(Vector3d position) {
125                 throw new NodeException("Cannot set root node orientation");
126         }
127         
128         public String getUniqueName(String prefix) {
129                 Set<String> names = new HashSet<String>();
130                 for (INode node : getChild()) {
131                         if (!(node instanceof IP3DVisualNode))
132                                 continue;
133                         IP3DVisualNode n = (IP3DVisualNode)node;
134                         names.add(n.getName());
135                 }
136                 int i = 1;
137                 while (true) {
138                         String genName = prefix + "_" + i;
139                         if (!names.contains(genName))
140                                 return genName;
141                         i++;
142                 }
143         }
144
145         
146         @SuppressWarnings("rawtypes")
147         @Override
148         public Object getAdapter(Class adapter) {
149                 if (NodeMap.class == adapter)
150                         return nodeMap;
151                 return null;
152         }
153         
154         public Nozzle createNozzle() {
155                 return new Nozzle();
156         }
157         
158         public Equipment createEquipment() {
159                 return new Equipment();
160         }
161         
162         public InlineComponent createInline() {
163                 return new InlineComponent();
164         }
165         
166         public EndComponent createEnd() {
167                 return new EndComponent();
168         }
169         
170         public TurnComponent createTurn() {
171                 return new TurnComponent();
172         }
173 }