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