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