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> {
31 @RelatedElementsAdd(Plant3D.URIs.children)
32 public void addChild(INode node) {
33 //public void addChild(IP3DVisualNode node) {
34 addNode(Plant3D.URIs.children,node);
37 @RelatedElementsGet(Plant3D.URIs.children)
38 public Collection<INode> getChild() {
39 return getNodes(Plant3D.URIs.children);
42 @RelatedElementsRem(Plant3D.URIs.children)
43 public void remChild(INode node) {
44 //public void remChild(IP3DNode node) {
45 removeNode(Plant3D.URIs.children, node);
48 private NodeMap<Resource, vtkProp, INode> nodeMap;
49 private IMapping<Resource, INode> mapping;
51 public void setNodeMap(NodeMap<Resource, vtkProp, INode> nodeMap) {
52 this.nodeMap = nodeMap;
53 this.mapping = nodeMap.getMapping();
56 public void setMapping(IMapping<Resource, INode> mapping) {
57 this.mapping = mapping;
61 public NodeMap<Resource, vtkProp, INode> getNodeMap() {
65 public Resource getNodeResource(INode node) {
66 return mapping.inverseGet(node);
69 public INode getResourceNode(Resource r) {
70 return mapping.get(r);
74 public ParentNode<?> getParent() {
79 public ParentNode<?> getRootNode() {
83 public javax.vecmath.Quat4d getOrientation() {
84 return MathTools.getIdentityQuat();
88 public Vector3d getPosition() {
89 return new Vector3d();
93 public Quat4d getWorldOrientation() {
94 return MathTools.getIdentityQuat();
98 public Vector3d getWorldPosition() {
99 return new Vector3d();
103 public Quat4d getWorldOrientation(Quat4d localOrientation) {
104 return localOrientation;
108 public Vector3d getWorldPosition(Vector3d localPosition) {
109 return localPosition;
113 public Quat4d getLocalOrientation(Quat4d worldOrientation) {
114 return worldOrientation;
118 public Vector3d getLocalPosition(Vector3d worldPosition) {
119 return worldPosition;
123 public void setPosition(Vector3d position) {
124 throw new NodeException("Cannot set root node position");
128 public void setOrientation(Quat4d orientation) {
129 throw new NodeException("Cannot set root node orientation");
133 public void setWorldOrientation(Quat4d orientation) {
134 throw new NodeException("Cannot set root node orientation");
138 public void setWorldPosition(Vector3d position) {
139 throw new NodeException("Cannot set root node orientation");
142 public String getUniqueName(String prefix) {
143 Set<String> names = new HashSet<String>();
144 for (INode node : getChild()) {
145 if (!(node instanceof IP3DVisualNode))
147 IP3DVisualNode n = (IP3DVisualNode)node;
148 names.add(n.getName());
152 String genName = prefix + "_" + i;
153 if (!names.contains(genName))
161 public <T> T getAdapter(Class<T> adapter) {
162 if (adapter.isAssignableFrom(NodeMap.class))
163 return adapter.cast(nodeMap);
167 public Nozzle createNozzle() {
171 public Equipment createEquipment() {
172 return new Equipment();
175 public InlineComponent createInline() {
176 return new InlineComponent();
179 public EndComponent createEnd() {
180 return new EndComponent();
183 public TurnComponent createTurn() {
184 return new TurnComponent();