]> gerrit.simantics Code Review - simantics/3d.git/blob - org.simantics.g3d/src/org/simantics/g3d/scenegraph/G3DNode.java
Reversing pipe runs was never implemented properly
[simantics/3d.git] / org.simantics.g3d / src / org / simantics / g3d / scenegraph / G3DNode.java
1 /*******************************************************************************\r
2  * Copyright (c) 2012, 2013 Association for Decentralized Information Management in\r
3  * Industry THTH ry.\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
8  *\r
9  * Contributors:\r
10  *     VTT Technical Research Centre of Finland - initial API and implementation\r
11  *******************************************************************************/\r
12 package org.simantics.g3d.scenegraph;\r
13 \r
14 import javax.vecmath.Quat4d;\r
15 import javax.vecmath.Vector3d;\r
16 \r
17 import org.simantics.g3d.ontology.G3D;\r
18 import org.simantics.g3d.property.annotations.GetPropertyValue;\r
19 import org.simantics.g3d.property.annotations.PropertyContributor;\r
20 import org.simantics.g3d.property.annotations.SetPropertyValue;\r
21 import org.simantics.g3d.scenegraph.base.INode;\r
22 import org.simantics.g3d.scenegraph.base.Node;\r
23 import org.simantics.g3d.tools.NodeTools;\r
24 import org.simantics.objmap.graph.annotations.RelatedGetValue;\r
25 import org.simantics.objmap.graph.annotations.RelatedSetValue;\r
26 \r
27 \r
28 @PropertyContributor\r
29 public class G3DNode extends Node implements IG3DNode {\r
30         \r
31         private Vector3d position = new Vector3d();\r
32         private Quat4d orientation = new Quat4d(0,0,0,1);\r
33         \r
34         @Override\r
35         @GetPropertyValue(value = G3D.URIs.hasOrientation, tabId = "Transform", name = "Orientation")\r
36         public Quat4d getOrientation() {\r
37                 return orientation;\r
38         }\r
39         \r
40         @RelatedGetValue(G3D.URIs.hasOrientation)\r
41         public double[] getOrientationArr() {\r
42                 double arr[] = new double[4];\r
43                 orientation.get(arr);\r
44                 return arr;\r
45                 \r
46         }\r
47         \r
48         @Override\r
49         @GetPropertyValue(value = G3D.URIs.hasPosition, tabId = "Transform", name = "Position")\r
50         public Vector3d getPosition() {\r
51                 return position;\r
52         }\r
53         \r
54         @RelatedGetValue(G3D.URIs.hasPosition)\r
55         public double[] getPositionArr() {\r
56                 double arr[] = new double[3];\r
57                 position.get(arr);\r
58                 return arr;\r
59         }\r
60         \r
61         @Override\r
62         @SetPropertyValue(G3D.URIs.hasOrientation)\r
63         public void setOrientation(Quat4d orientation) {\r
64                 assert(orientation != null);\r
65                 this.orientation = orientation;\r
66                 \r
67                 firePropertyChanged(G3D.URIs.hasOrientation);\r
68         }\r
69         \r
70         @RelatedSetValue(G3D.URIs.hasOrientation)\r
71         public void setOrientation(double[] arr) {\r
72                 if (arr == null)\r
73                         return;\r
74                 setOrientation(new Quat4d(arr));\r
75         }\r
76         \r
77         @Override\r
78         @SetPropertyValue(G3D.URIs.hasPosition)\r
79         public void setPosition(Vector3d position) {\r
80                 assert(position != null);\r
81                 this.position = position;\r
82                 \r
83                 firePropertyChanged(G3D.URIs.hasPosition);\r
84         }\r
85         \r
86         @RelatedSetValue(G3D.URIs.hasPosition)\r
87         public void setPosition(double[] arr) {\r
88                 if (arr == null)\r
89                         return;\r
90                 setPosition(new Vector3d(arr));\r
91         }\r
92         \r
93         @Override\r
94         @GetPropertyValue(value = G3D.URIs.hasWorldPosition, tabId = "Transform", name = "World Position")\r
95         public Vector3d getWorldPosition() {\r
96                 IG3DNode parent = (IG3DNode)getParent();\r
97                 if (parent == null)\r
98                         return position;\r
99                 return NodeTools.getWorldPosition(parent, new Vector3d(position));\r
100         }\r
101         \r
102         \r
103         public Vector3d getWorldPosition(Vector3d localPosition) {\r
104                 return NodeTools.getWorldPosition(this,localPosition);\r
105         }\r
106 \r
107         \r
108         @Override\r
109         @GetPropertyValue(value = G3D.URIs.hasWorldOrientation, tabId = "Transform", name = "World Orientation")\r
110         public Quat4d getWorldOrientation() {\r
111                 return getWorldOrientation(new Quat4d(orientation));\r
112         }\r
113         \r
114         public Quat4d getWorldOrientation(Quat4d localOrientation) {\r
115                 IG3DNode parent = (IG3DNode)getParent();\r
116                 if (parent == null)\r
117                         return localOrientation;\r
118                 return NodeTools.getWorldOrientation(parent, localOrientation);\r
119         }\r
120         \r
121         @Override\r
122         public Vector3d getLocalPosition(Vector3d worldPosition) {\r
123                 IG3DNode parent = (IG3DNode)getParent();\r
124                 if (parent == null)\r
125                         return worldPosition;\r
126                 return NodeTools.getLocalPosition(parent,new Vector3d(worldPosition));\r
127         }\r
128         \r
129         @Override\r
130         public Quat4d getLocalOrientation(Quat4d worldOrientation) {\r
131                 IG3DNode parent = (IG3DNode)getParent();\r
132                 if (parent == null)\r
133                         return worldOrientation;\r
134                 return NodeTools.getLocalOrientation(parent, new Quat4d(worldOrientation));\r
135         }\r
136         \r
137         @Override\r
138         @SetPropertyValue(G3D.URIs.hasWorldPosition)\r
139         public void setWorldPosition(Vector3d position) {\r
140                 Vector3d localPos = getLocalPosition(position);\r
141                 setPosition(localPos);\r
142         }\r
143         \r
144         @Override\r
145         @SetPropertyValue(G3D.URIs.hasWorldOrientation)\r
146         public void setWorldOrientation(Quat4d orientation) {\r
147                 Quat4d localOr = getLocalOrientation(orientation);\r
148                 setOrientation(localOr);\r
149         }\r
150         \r
151         @Override\r
152         public Object getAdapter(Class adapter) {\r
153                 if (INode.class == adapter)\r
154                         return this;\r
155                 if (IG3DNode.class == adapter)\r
156                         return this;\r
157                 return null;\r
158         }\r
159 \r
160 }\r