1 package org.simantics.plant3d.scenegraph;
3 import java.util.Collection;
4 import java.util.HashSet;
7 import javax.vecmath.Quat4d;
8 import javax.vecmath.Vector3d;
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;
27 @GraphType(Plant3D.URIs.Plant)
28 public class P3DRootNode extends ParentNode<INode> implements IG3DNode, NodeMapProvider<Resource, vtkProp, INode> {
30 // Vertical direction that determines the interpretation of rotation angle origin
31 protected Vector3d upVector = new Vector3d(0.0, 1.0, 0.0);
33 @RelatedElementsAdd(Plant3D.URIs.children)
34 public void addChild(INode node) {
35 //public void addChild(IP3DVisualNode node) {
36 addNode(Plant3D.URIs.children,node);
39 @RelatedElementsGet(Plant3D.URIs.children)
40 public Collection<INode> getChild() {
41 return getNodes(Plant3D.URIs.children);
44 @RelatedElementsRem(Plant3D.URIs.children)
45 public void remChild(INode node) {
46 //public void remChild(IP3DNode node) {
47 removeNode(Plant3D.URIs.children, node);
50 private NodeMap<Resource, vtkProp, INode> nodeMap;
51 private IMapping<Resource, INode> mapping;
53 public void setNodeMap(NodeMap<Resource, vtkProp, INode> nodeMap) {
54 this.nodeMap = nodeMap;
55 this.mapping = nodeMap.getMapping();
58 public void setMapping(IMapping<Resource, INode> mapping) {
59 this.mapping = mapping;
63 public NodeMap<Resource, vtkProp, INode> getNodeMap() {
67 public Resource getNodeResource(INode node) {
68 return mapping.inverseGet(node);
71 public INode getResourceNode(Resource r) {
72 return mapping.get(r);
76 public ParentNode<?> getParent() {
81 public ParentNode<?> getRootNode() {
85 public javax.vecmath.Quat4d getOrientation() {
86 return MathTools.getIdentityQuat();
90 public Vector3d getPosition() {
91 return new Vector3d();
95 public Quat4d getWorldOrientation() {
96 return MathTools.getIdentityQuat();
100 public Vector3d getWorldPosition() {
101 return new Vector3d();
105 public Quat4d getWorldOrientation(Quat4d localOrientation) {
106 return localOrientation;
110 public Vector3d getWorldPosition(Vector3d localPosition) {
111 return localPosition;
115 public Quat4d getLocalOrientation(Quat4d worldOrientation) {
116 return worldOrientation;
120 public Vector3d getLocalPosition(Vector3d worldPosition) {
121 return worldPosition;
125 public void setPosition(Vector3d position) {
126 throw new NodeException("Cannot set root node position");
130 public void setOrientation(Quat4d orientation) {
131 throw new NodeException("Cannot set root node orientation");
135 public void setWorldOrientation(Quat4d orientation) {
136 throw new NodeException("Cannot set root node orientation");
140 public void setWorldPosition(Vector3d position) {
141 throw new NodeException("Cannot set root node orientation");
144 public String getUniqueName(String prefix) {
145 Set<String> names = new HashSet<String>();
146 for (INode node : getChild()) {
147 if (!(node instanceof IP3DVisualNode))
149 IP3DVisualNode n = (IP3DVisualNode)node;
150 names.add(n.getName());
154 String genName = prefix + "_" + i;
155 if (!names.contains(genName))
163 public <T> T getAdapter(Class<T> adapter) {
164 if (adapter.isAssignableFrom(NodeMap.class))
165 return adapter.cast(nodeMap);
169 public Nozzle createNozzle() {
173 public Equipment createEquipment() {
174 return new Equipment();
177 public InlineComponent createInline() {
178 return new InlineComponent();
181 public EndComponent createEnd() {
182 return new EndComponent();
185 public TurnComponent createTurn() {
186 return new TurnComponent();
189 public Vector3d getUpVector() {