1 /*******************************************************************************
\r
2 * Copyright (c) 2012, 2013 Association for Decentralized Information Management in
\r
4 * All rights reserved. This program and the accompanying materials
\r
5 * are made available under the terms of the Eclipse Public License v1.0
\r
6 * which accompanies this distribution, and is available at
\r
7 * http://www.eclipse.org/legal/epl-v10.html
\r
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.g3d.scenegraph.structural;
\r
14 import java.util.Collection;
\r
16 import javax.vecmath.Quat4d;
\r
17 import javax.vecmath.Vector3d;
\r
19 import org.simantics.g3d.math.MathTools;
\r
20 import org.simantics.g3d.ontology.G3D;
\r
21 import org.simantics.g3d.property.annotations.GetPropertyValue;
\r
22 import org.simantics.g3d.property.annotations.SetPropertyValue;
\r
23 import org.simantics.g3d.scenegraph.IG3DNode;
\r
24 import org.simantics.g3d.scenegraph.base.INode;
\r
25 import org.simantics.g3d.scenegraph.base.NodeException;
\r
26 import org.simantics.g3d.tools.NodeTools;
\r
27 import org.simantics.objmap.graph.annotations.RelatedGetValue;
\r
28 import org.simantics.objmap.graph.annotations.RelatedSetValue;
\r
30 public abstract class G3DStructuralParentNode<T extends IStructuralNode> extends StructuralParentNode<T> implements IG3DNode{
\r
31 private Vector3d position = new Vector3d();
\r
32 private Quat4d orientation = MathTools.getIdentityQuat();
\r
35 @GetPropertyValue(value = G3D.URIs.hasOrientation, tabId = "Transform", name = "Orientation")
\r
36 public Quat4d getOrientation() {
\r
37 if (getParent() == null)
\r
38 return MathTools.getIdentityQuat();
\r
43 @GetPropertyValue(value = G3D.URIs.hasPosition, tabId = "Transform", name = "Position")
\r
44 public Vector3d getPosition() {
\r
45 if (getParent() == null)
\r
46 return MathTools.ORIGIN;
\r
51 @GetPropertyValue(value = G3D.URIs.hasWorldOrientation, tabId = "Transform", name = "World Orientation")
\r
52 public Quat4d getWorldOrientation() {
\r
53 if (getParent() == null)
\r
54 return MathTools.getIdentityQuat();
\r
55 return getWorldOrientation(orientation);
\r
59 @GetPropertyValue(value = G3D.URIs.hasWorldPosition, tabId = "Transform", name = "World Position")
\r
60 public Vector3d getWorldPosition() {
\r
61 IG3DNode parent = (IG3DNode)getParent();
\r
63 return MathTools.ORIGIN;
\r
64 return NodeTools.getWorldPosition(parent, new Vector3d(position));
\r
68 public Quat4d getWorldOrientation(Quat4d localOrientation) {
\r
69 IG3DNode parent = (IG3DNode)getParent();
\r
71 return localOrientation;
\r
72 return NodeTools.getWorldOrientation(parent, localOrientation);
\r
76 public Vector3d getWorldPosition(Vector3d localPosition) {
\r
77 return NodeTools.getWorldPosition(this,localPosition);
\r
81 public Quat4d getLocalOrientation(Quat4d worldOrientation) {
\r
82 IG3DNode parent = (IG3DNode)getParent();
\r
84 return worldOrientation;
\r
85 return NodeTools.getLocalOrientation(parent, new Quat4d(worldOrientation));
\r
89 public Vector3d getLocalPosition(Vector3d worldPosition) {
\r
90 IG3DNode parent = (IG3DNode)getParent();
\r
92 return worldPosition;
\r
93 return NodeTools.getLocalPosition(parent,new Vector3d(worldPosition));
\r
97 @SetPropertyValue(G3D.URIs.hasPosition)
\r
98 public void setPosition(Vector3d position) {
\r
99 this.position = position;
\r
100 firePropertyChanged(G3D.URIs.hasPosition);
\r
104 @SetPropertyValue(G3D.URIs.hasOrientation)
\r
105 public void setOrientation(Quat4d orientation) {
\r
106 this.orientation = orientation;
\r
107 firePropertyChanged(G3D.URIs.hasOrientation);
\r
111 @SetPropertyValue(G3D.URIs.hasWorldOrientation)
\r
112 public void setWorldOrientation(Quat4d orientation) {
\r
113 if (getParent() == null)
\r
114 throw new NodeException("Cannot set root node orientation");
\r
115 Quat4d localOr = getLocalOrientation(orientation);
\r
116 setOrientation(localOr);
\r
120 @SetPropertyValue(G3D.URIs.hasWorldPosition)
\r
121 public void setWorldPosition(Vector3d position) {
\r
122 if (getParent() == null)
\r
123 throw new NodeException("Cannot set root node position");
\r
124 Vector3d localPos = getLocalPosition(position);
\r
125 setPosition(localPos);
\r
130 @RelatedGetValue(G3D.URIs.hasOrientation)
\r
131 public double[] getOrientationArr() {
\r
132 double arr[] = new double[4];
\r
133 orientation.get(arr);
\r
138 @RelatedGetValue(G3D.URIs.hasPosition)
\r
139 public double[] getPositionArr() {
\r
140 double arr[] = new double[3];
\r
145 @RelatedSetValue(G3D.URIs.hasOrientation)
\r
146 public void setOrientation(double[] arr) {
\r
149 setOrientation(new Quat4d(arr));
\r
152 @RelatedSetValue(G3D.URIs.hasPosition)
\r
153 public void setPosition(double[] arr) {
\r
156 setPosition(new Vector3d(arr));
\r
160 protected void _addStrNode(String id, T child) {
\r
161 addNode(id+"/str", child);
\r
164 protected boolean _removeStrNode(String id, T child) {
\r
165 return removeNode(id+"/str", child);
\r
168 protected Collection<T> _getStrNodes(String id) {
\r
169 return getNodes(id+"/str");
\r
172 public Object getAdapter(Class adapter) {
\r
173 if (INode.class == adapter)
\r
175 if (IG3DNode.class == adapter)
\r