1 package org.simantics.plant3d.scenegraph;
3 import java.util.HashSet;
6 import javax.vecmath.Quat4d;
7 import javax.vecmath.Vector3d;
9 import org.simantics.g3d.math.MathTools;
10 import org.simantics.g3d.ontology.G3D;
11 import org.simantics.g3d.property.annotations.GetPropertyValue;
12 import org.simantics.g3d.property.annotations.PropertyContributor;
13 import org.simantics.g3d.property.annotations.SetPropertyValue;
14 import org.simantics.g3d.scenegraph.IG3DNode;
15 import org.simantics.g3d.scenegraph.base.ParentNode;
16 import org.simantics.g3d.tools.NodeTools;
17 import org.simantics.layer0.Layer0;
18 import org.simantics.objmap.graph.annotations.RelatedGetValue;
19 import org.simantics.objmap.graph.annotations.RelatedSetValue;
22 public abstract class P3DParentNode<T extends IP3DNode> extends ParentNode<T> implements IP3DVisualNode {
29 @RelatedGetValue(Layer0.URIs.HasName)
30 @GetPropertyValue(value = Layer0.URIs.HasName, tabId = "Default", name = "Name")
31 public String getName() {
35 @RelatedSetValue(Layer0.URIs.HasName)
36 @SetPropertyValue(Layer0.URIs.HasName)
37 public void setName(String name) {
41 firePropertyChanged(Layer0.URIs.HasName);
45 public String toString() {
49 private Vector3d position = new Vector3d();
50 private Quat4d orientation = MathTools.getIdentityQuat();
53 @GetPropertyValue(value = G3D.URIs.hasOrientation, tabId = "Transform", name = "Orientation")
54 public Quat4d getOrientation() {
58 @RelatedGetValue(G3D.URIs.hasOrientation)
59 public double[] getOrientationArr() {
60 double arr[] = new double[4];
67 @GetPropertyValue(value = G3D.URIs.hasPosition, tabId = "Transform", name = "Position")
68 public Vector3d getPosition() {
72 @RelatedGetValue(G3D.URIs.hasPosition)
73 public double[] getPositionArr() {
74 double arr[] = new double[3];
80 @SetPropertyValue(G3D.URIs.hasOrientation)
81 public void setOrientation(Quat4d orientation) {
82 assert(orientation != null);
83 this.orientation = orientation;
85 firePropertyChanged(G3D.URIs.hasOrientation);
89 @SetPropertyValue(G3D.URIs.hasPosition)
90 public void setPosition(Vector3d position) {
91 assert(position != null);
92 this.position = position;
94 firePropertyChanged(G3D.URIs.hasPosition);
97 @RelatedSetValue(G3D.URIs.hasOrientation)
98 public void setOrientation(double[] arr) {
101 setOrientation(new Quat4d(arr));
104 @RelatedSetValue(G3D.URIs.hasPosition)
105 public void setPosition(double[] arr) {
108 setPosition(new Vector3d(arr));
112 @GetPropertyValue(value = G3D.URIs.hasWorldPosition, tabId = "Transform", name = "World Position")
113 public Vector3d getWorldPosition() {
114 IG3DNode parent = (IG3DNode)getParent();
117 return NodeTools.getWorldPosition(parent, new Vector3d(position));
121 public Vector3d getWorldPosition(Vector3d localPosition) {
122 return NodeTools.getWorldPosition(this,localPosition);
127 @GetPropertyValue(value = G3D.URIs.hasWorldOrientation, tabId = "Transform", name = "World Orientation")
128 public Quat4d getWorldOrientation() {
129 return getWorldOrientation(new Quat4d(orientation));
132 public Quat4d getWorldOrientation(Quat4d localOrientation) {
133 IG3DNode parent = (IG3DNode)getParent();
135 return localOrientation;
136 return NodeTools.getWorldOrientation(parent, localOrientation);
140 public Vector3d getLocalPosition(Vector3d worldPosition) {
141 IG3DNode parent = (IG3DNode)getParent();
143 return worldPosition;
144 return NodeTools.getLocalPosition(parent,new Vector3d(worldPosition));
148 public Quat4d getLocalOrientation(Quat4d worldOrientation) {
149 IG3DNode parent = (IG3DNode)getParent();
151 return worldOrientation;
152 return NodeTools.getLocalOrientation(parent, new Quat4d(worldOrientation));
156 @SetPropertyValue(G3D.URIs.hasWorldPosition)
157 public void setWorldPosition(Vector3d position) {
158 Vector3d localPos = getLocalPosition(position);
159 setPosition(localPos);
163 @SetPropertyValue(G3D.URIs.hasWorldOrientation)
164 public void setWorldOrientation(Quat4d orientation) {
165 Quat4d localOr = getLocalOrientation(orientation);
166 setOrientation(localOr);
170 public Object getAdapter(Class adapter) {
171 if (IG3DNode.class == adapter)
176 public String getUniqueName(String prefix) {
177 Set<String> names = new HashSet<String>();
178 for (IP3DNode node : getNodes()) {
179 if (!(node instanceof IP3DVisualNode))
181 IP3DVisualNode n = (IP3DVisualNode)node;
182 names.add(n.getName());
186 String genName = prefix + "_" + i;
187 if (!names.contains(genName))