]> gerrit.simantics Code Review - simantics/3d.git/blobdiff - org.simantics.g3d.vtk/src/org/simantics/g3d/vtk/swt/TranslateAction.java
Editor internal toolbar for Plant3D editor
[simantics/3d.git] / org.simantics.g3d.vtk / src / org / simantics / g3d / vtk / swt / TranslateAction.java
index 32b97c1bda3abf576796e52f063327c2ca133a4f..682112cfefdbd12ba1dc6abac8752b01bd1d8a39 100644 (file)
@@ -22,13 +22,19 @@ 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.MathTools;
 import org.simantics.g3d.math.Ray;
 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.TranslateAxisGizmo;
@@ -57,6 +63,9 @@ public class TranslateAction extends vtkSwtAction{
        private Cursor activeCursor;// = Cursor.getPredefinedCursor(Cursor.HAND_CURSOR);
        private Cursor dragCursor;// = Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR);
        
+       protected ToolComposite toolComposite;
+       protected Combo axisCombo;
+       
        public void setNode(IG3DNode node) {
                this.node = node;
                if ((node instanceof IStructuralNode) && ((IStructuralNode)node).isPartOfInstantiatedModel() && !((IStructuralNode)node).isInstantiatedModelRoot()) {
@@ -70,7 +79,7 @@ public class TranslateAction extends vtkSwtAction{
                return node;
        }
        
-       public TranslateAction(InteractiveVtkComposite panel, VTKNodeMap<?, ? extends INode> nodeMap) {
+       public TranslateAction(InteractiveVtkComposite panel, VTKNodeMap<?, ? extends INode> nodeMap, ToolComposite toolComposite) {
                super(panel);
                setImageDescriptor(Activator.imageDescriptorFromPlugin("com.famfamfam.silk", "icons/arrow_out.png"));
                setText("Translate");
@@ -78,11 +87,46 @@ public class TranslateAction extends vtkSwtAction{
                
                activeCursor = Display.getCurrent().getSystemCursor(SWT.CURSOR_HAND);
                dragCursor = Display.getCurrent().getSystemCursor(SWT.CURSOR_SIZEALL);
+               this.toolComposite = toolComposite;
+       }
+       
+       protected void createTools(ToolComposite toolComposite) {
+           Label label = new Label(toolComposite, SWT.READ_ONLY);
+           label.setText("Translate direction:");
+           axisCombo = new Combo(toolComposite, SWT.READ_ONLY);
+        axisCombo.add("X");
+        axisCombo.add("Y");
+        axisCombo.add("Z");
+        axisCombo.add("XY");
+        axisCombo.add("XZ");
+        axisCombo.add("YZ");
+        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() {
@@ -91,12 +135,13 @@ public class TranslateAction extends vtkSwtAction{
                                update();
                        }
                });
-               
-               
-               
        }
        
        public void deattach() {
+           if (toolComposite != null) {
+               toolComposite.clear();
+               axisCombo = null;
+           }
                
                node = null;
                nodeMap.commit("Translate");
@@ -142,13 +187,19 @@ public class TranslateAction extends vtkSwtAction{
                if (e.getKeyCode() == KeyEvent.VK_G) {
                        worldCoord = !worldCoord;
                }
-               gizmo.setType(index);
                
+               updateLock();
                update();
                //panel.repaint();
                return true;
        }
        
+       private void updateLock() {
+           gizmo.setType(index);
+           if (axisCombo != null)
+               axisCombo.select(index);
+           panel.refresh();
+       }
 
        
        @Override
@@ -422,65 +473,65 @@ public class TranslateAction extends vtkSwtAction{
                                translate.x = s[0];
                                
                                break;
-                       case Y :
-                               dir = new Vector3d(0.0,1.0,0.0);
-                               if(!worldCoord)
-                                       MathTools.rotate(q, dir, dir);
-                               i1 = new Vector3d();
-                               i2 = new Vector3d();
-                               s = new double[2];
-                               MathTools.intersectStraightStraight( p, dir,ray.pos, ray.dir, i2, i1,s);
-                               translate.y = s[0];
-                               break;
-                       case Z :
-                               dir = new Vector3d(0.0,0.0,1.0);
-                               if(!worldCoord)
-                                       MathTools.rotate(q, dir, dir);
-                               i1 = new Vector3d();
-                               i2 = new Vector3d();
-                               s = new double[2];
-                               MathTools.intersectStraightStraight( p, dir,ray.pos, ray.dir, i2, i1,s);
-                               translate.z = s[0];
-                               break;
-                       case XY :
-                               normal = new Vector3d(0.0,0.0,1.0);
-                               if(!worldCoord)
-                                       MathTools.rotate(q, normal, normal);
-                               r = new Vector3d();
-                               if (MathTools.intersectStraightPlane(ray.pos, ray.dir, p, normal, r)) {
-                                       r.sub(p);
-                                       translate.x = r.x;
-                                       translate.y = r.y;
-                               }
-                               break;
-                       case XZ :
-                               normal = new Vector3d(0.0,1.0,0.0);
-                               if(!worldCoord)
-                                       MathTools.rotate(q, normal, normal);
-                               r = new Vector3d();
-                               if (MathTools.intersectStraightPlane(ray.pos, ray.dir, p, normal, r)) {
-                                       r.sub(p);
-                                       translate.x = r.x;
-                                       translate.z = r.z;
-                               }
-                               break;
-                       case YZ :
-                               normal = new Vector3d(1.0,0.0,0.0);
-                               if(!worldCoord)
-                                       MathTools.rotate(q, normal, normal);
-                               r = new Vector3d();
-                               if (MathTools.intersectStraightPlane(ray.pos, ray.dir, p, normal, r)) {
-                                       r.sub(p);
-                                       translate.y = r.y;
-                                       translate.z = r.z;
-                               }
-                               break;
-                       default :
-                               
-                               return null;
+               case Y :
+                       dir = new Vector3d(0.0,1.0,0.0);
+                       if(!worldCoord)
+                               MathTools.rotate(q, dir, dir);
+                       i1 = new Vector3d();
+                       i2 = new Vector3d();
+                       s = new double[2];
+                       MathTools.intersectStraightStraight( p, dir,ray.pos, ray.dir, i2, i1,s);
+                       translate.y = s[0];
+                       break;
+               case Z :
+                       dir = new Vector3d(0.0,0.0,1.0);
+                       if(!worldCoord)
+                               MathTools.rotate(q, dir, dir);
+                       i1 = new Vector3d();
+                       i2 = new Vector3d();
+                       s = new double[2];
+                       MathTools.intersectStraightStraight( p, dir,ray.pos, ray.dir, i2, i1,s);
+                       translate.z = s[0];
+                       break;
+               case XY :
+                       normal = new Vector3d(0.0,0.0,1.0);
+                       if(!worldCoord)
+                               MathTools.rotate(q, normal, normal);
+                       r = new Vector3d();
+                       if (MathTools.intersectStraightPlane(ray.pos, ray.dir, p, normal, r)) {
+                               r.sub(p);
+                               translate.x = r.x;
+                               translate.y = r.y;
+                       }
+                       break;
+               case XZ :
+                       normal = new Vector3d(0.0,1.0,0.0);
+                       if(!worldCoord)
+                               MathTools.rotate(q, normal, normal);
+                       r = new Vector3d();
+                       if (MathTools.intersectStraightPlane(ray.pos, ray.dir, p, normal, r)) {
+                               r.sub(p);
+                               translate.x = r.x;
+                               translate.z = r.z;
+                       }
+                       break;
+               case YZ :
+                       normal = new Vector3d(1.0,0.0,0.0);
+                       if(!worldCoord)
+                               MathTools.rotate(q, normal, normal);
+                       r = new Vector3d();
+                       if (MathTools.intersectStraightPlane(ray.pos, ray.dir, p, normal, r)) {
+                               r.sub(p);
+                               translate.y = r.y;
+                               translate.z = r.z;
                        }
-                       translate.sub(offset);
-                       return translate;
+                       break;
+               default :
+                       
+                       return null;
+               }
+               translate.sub(offset);
+               return translate;
        }
        
 }