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.property;
\r
14 import javax.vecmath.AxisAngle4d;
\r
15 import javax.vecmath.Quat4d;
\r
16 import javax.vecmath.Vector3d;
\r
18 import org.simantics.g3d.Activator;
\r
19 import org.simantics.g3d.math.EulerTools;
\r
20 import org.simantics.g3d.math.EulerTools.Order;
\r
21 import org.simantics.g3d.math.MathTools;
\r
22 import org.simantics.g3d.preferences.PreferenceConstants;
\r
24 public class QuatPropertyManipulator implements PropertyManipulator {
\r
26 ValueProvider provider;
\r
27 protected Object input;
\r
29 enum EditType {QUATERNION,AXIS_ANGLE,EULER};
\r
31 EditType type = EditType.QUATERNION;
\r
35 Object editValue = null;
\r
37 public QuatPropertyManipulator(ValueProvider provider, Object input) {
\r
38 this.provider = provider;
\r
41 String set = Activator.getDefault().getPreferenceStore().getString(PreferenceConstants.ORIENTATION_PRESENTATION);
\r
42 if ("quat".equals(set)) {
\r
43 type = EditType.QUATERNION;
\r
44 } else if ("aa".equals(set)) {
\r
45 type = EditType.AXIS_ANGLE;
\r
46 } else if ("euler".equals(set)) {
\r
47 type = EditType.EULER;
\r
48 String eulerOrder = Activator.getDefault().getPreferenceStore().getString(PreferenceConstants.EULER_ANGLE_ORDER);
\r
49 order = Order.valueOf(eulerOrder);
\r
56 public String getDescription(int i) {
\r
81 return order.toString().substring(i, i+1);
\r
89 public int getValueCount() {
\r
104 public String getValue(int i) {
\r
106 Quat4d q = (Quat4d) provider.getValue(input);
\r
111 q = (Quat4d)editValue;
\r
128 aa = (AxisAngle4d)editValue;
\r
130 aa = new AxisAngle4d();
\r
140 d = MathTools.radToDeg(aa.angle);
\r
146 aa = (Vector3d)editValue;
\r
148 aa = EulerTools.getEulerFromQuat(order, q);//MathTools.getEuler(q);
\r
155 d = MathTools.radToDeg(d);
\r
161 return Double.toString(d);
\r
162 } catch (Exception e) {
\r
170 public String setValue(String value, int i) {
\r
172 Double d = Double.parseDouble(value);
\r
173 Quat4d q = (Quat4d) provider.getValue(input);
\r
177 q = (Quat4d)editValue;
\r
193 aa = (AxisAngle4d) editValue;
\r
195 aa = new AxisAngle4d();
\r
205 aa.angle = MathTools.degToRad(d);
\r
207 MathTools.getQuat(aa,q);
\r
213 e = (Vector3d)editValue;
\r
215 e = EulerTools.getEulerFromQuat(order, q);//MathTools.getEuler(q);
\r
216 d = MathTools.degToRad(d);
\r
223 q = EulerTools.getQuatFromEuler(order, e);//MathTools.getQuat(e);
\r
230 } catch (Exception e) {
\r
231 return e.getMessage();
\r
236 protected void setValue(Quat4d q) throws Exception {
\r
237 provider.setValue(input, q);
\r
240 private void storeEditValue() {
\r
242 Quat4d q = (Quat4d) provider.getValue(input);
\r
248 AxisAngle4d aa = new AxisAngle4d();
\r
253 Vector3d e = EulerTools.getEulerFromQuat(order, q);
\r
257 } catch (Exception e) {
\r
263 public boolean getEditMode() {
\r
268 public void setEditMode(boolean b) {
\r