X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;ds=sidebyside;f=org.simantics.g3d.vtk%2Fsrc%2Forg%2Fsimantics%2Fg3d%2Fvtk%2Fswt%2FRotateAction.java;h=f9ea1877b154b13653963026501138a7b1a712be;hb=96b67feb92c117c72fb823b6fff5f89afa7ee631;hp=9cf39effb808ed8dc139f8bdafe77d2a5479d693;hpb=3d51c0d674afdad4413a16ac104ee111c7031dfc;p=simantics%2F3d.git diff --git a/org.simantics.g3d.vtk/src/org/simantics/g3d/vtk/swt/RotateAction.java b/org.simantics.g3d.vtk/src/org/simantics/g3d/vtk/swt/RotateAction.java index 9cf39eff..f9ea1877 100644 --- a/org.simantics.g3d.vtk/src/org/simantics/g3d/vtk/swt/RotateAction.java +++ b/org.simantics.g3d.vtk/src/org/simantics/g3d/vtk/swt/RotateAction.java @@ -21,8 +21,13 @@ import javax.vecmath.Quat4d; import javax.vecmath.Vector3d; import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.graphics.Cursor; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Combo; import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Label; import org.simantics.g3d.math.EulerTools; import org.simantics.g3d.math.EulerTools.Order; import org.simantics.g3d.math.MathTools; @@ -31,6 +36,7 @@ import org.simantics.g3d.preferences.PreferenceConstants; import org.simantics.g3d.scenegraph.IG3DNode; import org.simantics.g3d.scenegraph.base.INode; import org.simantics.g3d.scenegraph.structural.IStructuralNode; +import org.simantics.g3d.toolbar.ToolComposite; import org.simantics.g3d.vtk.Activator; import org.simantics.g3d.vtk.common.VTKNodeMap; import org.simantics.g3d.vtk.gizmo.RotateAxisGizmo; @@ -77,6 +83,9 @@ public class RotateAction extends vtkSwtAction{ //AxisAngle4d rotation = new AxisAngle4d(); Quat4d worldOrientation = new Quat4d(); + protected ToolComposite toolComposite; + protected Combo axisCombo; + public void setNode(IG3DNode node) { this.node = node; if ((node instanceof IStructuralNode) && ((IStructuralNode)node).isPartOfInstantiatedModel() && !((IStructuralNode)node).isInstantiatedModelRoot()) { @@ -105,12 +114,12 @@ public class RotateAction extends vtkSwtAction{ return node; } - public RotateAction(InteractiveVtkComposite panel, VTKNodeMap nodeMap) { + public RotateAction(InteractiveVtkComposite panel, VTKNodeMap nodeMap, ToolComposite toolComposite) { super(panel); setImageDescriptor(Activator.imageDescriptorFromPlugin("com.famfamfam.silk", "icons/arrow_rotate_clockwise.png")); setText("Rotate"); this.nodeMap = nodeMap; - + this.toolComposite = toolComposite; steps = 36; angles = new double[steps+1]; @@ -122,10 +131,41 @@ public class RotateAction extends vtkSwtAction{ dragCursor = Display.getCurrent().getSystemCursor(SWT.CURSOR_CROSS); } + protected void createTools(ToolComposite toolComposite) { + Label label = new Label(toolComposite, SWT.READ_ONLY); + label.setText("Rotate axis:"); + axisCombo = new Combo(toolComposite, SWT.READ_ONLY); + axisCombo.add("X"); + axisCombo.add("Y"); + axisCombo.add("Z"); + axisCombo.add("Camera"); + axisCombo.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + Combo c = (Combo)e.getSource(); + index = c.getSelectionIndex(); + updateLock(); + panel.getComponent().setFocus(); + } + }); + axisCombo.select(index); + + Button close = new Button(toolComposite, SWT.PUSH); + close.setText("Close"); + close.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + panel.useDefaultAction(); + }; + }); + toolComposite.relayout(); + } + public void attach() { if (node == null) return; - + if (toolComposite != null) { + createTools(toolComposite); + } super.attach(); ThreadUtils.asyncExec(panel.getThreadQueue(), new Runnable() { public void run() { @@ -139,7 +179,10 @@ public class RotateAction extends vtkSwtAction{ } public void deattach() { - + if (toolComposite != null) { + toolComposite.clear(); + axisCombo = null; + } node = null; nodeMap.commit("Rotate"); deattachUI(); @@ -184,11 +227,19 @@ public class RotateAction extends vtkSwtAction{ if (e.getKeyCode() == KeyEvent.VK_G) { worldCoord = !worldCoord; } - gizmo.setType(index); - panel.refresh(); + + updateLock(); + return true; } + private void updateLock() { + gizmo.setType(index); + if (axisCombo != null) + axisCombo.select(index); + panel.refresh(); + } + @Override public boolean keyReleased(KeyEvent e) { return false; @@ -227,7 +278,7 @@ public class RotateAction extends vtkSwtAction{ private void update() { Vector3d nodePos = node.getWorldPosition(); - System.out.println(nodePos); +// System.out.println(nodePos); gizmo.setPosition(nodePos); if (worldCoord) { gizmo.setRotation(new AxisAngle4d()); @@ -408,7 +459,7 @@ public class RotateAction extends vtkSwtAction{ // intersection point j.set(i2); i.cross(j, axis); - System.out.println("I,J " + i + " " + j); +// System.out.println("I,J " + i + " " + j); double angleI = i2.angle(i); double angleJ = i2.angle(j); prevAngle = Math.atan2(Math.cos(angleJ), Math.cos(angleI)); @@ -436,7 +487,7 @@ public class RotateAction extends vtkSwtAction{ taxis = new Vector3d(axis); MathTools.rotate(parentWorldOrientation, axis, axis); } - System.out.println(inputType); +// System.out.println(inputType); if (inputType == InputType.INTERSECT) { double s[] = new double[2]; @@ -446,7 +497,7 @@ public class RotateAction extends vtkSwtAction{ double angleI = i2.angle(i); double angleJ = i2.angle(j); double angle = Math.atan2(Math.cos(angleJ), Math.cos(angleI)); - System.out.println("Angle " + angle + " i " + angleI + " j " + angleJ + " prev " + prevAngle); +// System.out.println("Angle " + angle + " i " + angleI + " j " + angleJ + " prev " + prevAngle); if(!worldCoord) axis = taxis; if (useStep) { @@ -475,7 +526,7 @@ public class RotateAction extends vtkSwtAction{ //Quat4d q = MathTools.getQuat(euler); Quat4d q = EulerTools.getQuatFromEuler(order, euler); setOrientation(q); - System.out.println(" (" + MathTools.radToDeg(euler.x) + " " + MathTools.radToDeg(euler.y) + " " + MathTools.radToDeg(euler.z) + ") " + qrot + " "+ q); +// System.out.println(" (" + MathTools.radToDeg(euler.x) + " " + MathTools.radToDeg(euler.y) + " " + MathTools.radToDeg(euler.z) + ") " + qrot + " "+ q); } else { setOrientation(qrot); } @@ -530,7 +581,7 @@ public class RotateAction extends vtkSwtAction{ //Quat4d q = MathTools.getQuat(euler); Quat4d q = EulerTools.getQuatFromEuler(order, euler); setOrientation(q); - System.out.println(" (" + MathTools.radToDeg(euler.x) + " " + MathTools.radToDeg(euler.y) + " " + MathTools.radToDeg(euler.z) + ") " + qrot + " "+ q); +// System.out.println(" (" + MathTools.radToDeg(euler.x) + " " + MathTools.radToDeg(euler.y) + " " + MathTools.radToDeg(euler.z) + ") " + qrot + " "+ q); } else { setOrientation(qrot); } @@ -614,8 +665,7 @@ public class RotateAction extends vtkSwtAction{ case Z: return new Vector3d(0.0, 0.0, 1.0); case P: - Vector3d axis = new Vector3d(panel.getRenderer().GetActiveCamera() - .GetDirectionOfProjection()); + Vector3d axis = new Vector3d(panel.getRenderer().GetActiveCamera().GetDirectionOfProjection()); axis.normalize(); return axis; default: