]> gerrit.simantics Code Review - simantics/3d.git/blobdiff - org.simantics.plant3d/src/org/simantics/plant3d/actions/RoutePipeAction.java
Editor internal toolbar for Plant3D editor
[simantics/3d.git] / org.simantics.plant3d / src / org / simantics / plant3d / actions / RoutePipeAction.java
index 9f523c956be2b8ac7c08cb2f15740e45dc67c380..389f3be5de60484f4370dbf3aafe3a14cc9fa746 100644 (file)
@@ -13,11 +13,18 @@ import javax.vecmath.Point3d;
 import javax.vecmath.Tuple3d;
 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.widgets.Button;
+import org.eclipse.swt.widgets.Combo;
+import org.eclipse.swt.widgets.Label;
 import org.simantics.db.Resource;
 import org.simantics.g3d.math.MathTools;
 import org.simantics.g3d.math.Ray;
 import org.simantics.g3d.scenegraph.NodeMap;
 import org.simantics.g3d.scenegraph.base.INode;
+import org.simantics.g3d.toolbar.ToolComposite;
 import org.simantics.g3d.tools.ConstraintDetector;
 import org.simantics.g3d.vtk.gizmo.TranslateAxisGizmo;
 import org.simantics.g3d.vtk.swt.InteractiveVtkComposite;
@@ -47,7 +54,7 @@ import vtk.vtkTextActor;
 
 public class RoutePipeAction extends vtkSwtAction {
        enum LockType {
-               X, Y, Z, XY, YZ, XZ, NONE, CUSTOM
+               X, Y, Z, XY, XZ, YZ, NONE, CUSTOM
        };
 
        LockType lock = LockType.NONE;
@@ -91,11 +98,15 @@ public class RoutePipeAction extends vtkSwtAction {
        
        private Set<PositionType> allowed = new HashSet<PositionType>();
        
-       public RoutePipeAction(InteractiveVtkComposite panel, P3DRootNode root) {
-           this(panel,root, true);
+       protected ToolComposite toolComposite;
+    protected Combo axisCombo;
+    protected Button cameraButton;
+       
+       public RoutePipeAction(InteractiveVtkComposite panel, P3DRootNode root, ToolComposite toolComposite) {
+           this(panel,root, toolComposite, true);
        }
        
-       public RoutePipeAction(InteractiveVtkComposite panel, P3DRootNode root, boolean allowBranches) {
+       public RoutePipeAction(InteractiveVtkComposite panel, P3DRootNode root, ToolComposite toolComposite, boolean allowBranches) {
                super(panel);
                this.root = root;
                this.allowBranches = allowBranches;
@@ -106,6 +117,7 @@ public class RoutePipeAction extends vtkSwtAction {
                terminalSelectionGizmo = new TerminalSelectionGizmo(panel);
                constraintPointGizmo = new ConstraintPointGizmo(panel);
                detector = new org.simantics.g3d.vtk.swt.ConstraintDetector(panel);
+               this.toolComposite = toolComposite;
        }
        
        public void setComponent(PipelineComponent component) {
@@ -120,19 +132,69 @@ public class RoutePipeAction extends vtkSwtAction {
                setEnabled(allowed.size() > 0);
        }
        
-       public void deattach() {
-               deactivate();
-               startComponent = null;
-               
-               deattachUI();
-               super.deattach();
-               panel.refresh();
-       }
+       protected void createTools(ToolComposite toolComposite) {
+        Label label = new Label(toolComposite, SWT.READ_ONLY);
+        label.setText("Route 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("None");
+        axisCombo.add("Custom");
+        axisCombo.addSelectionListener(new SelectionAdapter() {
+            @Override
+            public void widgetSelected(SelectionEvent e) {
+                Combo c = (Combo)e.getSource();
+                setLockType(LockType.values()[c.getSelectionIndex()],false);
+                panel.getComponent().setFocus();
+                
+            }
+        });
+        axisCombo.select(lock.ordinal());
+        cameraButton = new Button(toolComposite, SWT.TOGGLE);
+        cameraButton.setText("Camera");
+        cameraButton.setSelection(useDefault);
+        cameraButton.addSelectionListener(new SelectionAdapter() {
+            @Override
+            public void widgetSelected(SelectionEvent e) {
+                setUseDefault(((Button)e.getSource()).getSelection());
+                panel.getComponent().setFocus();
+            }
+        });
+        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 deattach() {
+        deactivate();
+        if (toolComposite != null) {
+            toolComposite.clear();
+            axisCombo = null;
+            cameraButton = null;
+        }
+
+        startComponent = null;
+
+        deattachUI();
+        super.deattach();
+        panel.refresh();
+    }
        
        public void attach() {
                if (startComponent == null)
                        return;
-               
+               if (toolComposite != null) {
+                  createTools(toolComposite); 
+           }
                super.attach();
                ThreadUtils.asyncExec(panel.getThreadQueue(), new Runnable() {
                        public void run() {
@@ -236,19 +298,21 @@ public class RoutePipeAction extends vtkSwtAction {
                        }
                }
                if (e.getKeyCode() == KeyEvent.VK_C) {
-                       useDefault = !useDefault;
-                       if (useDefault)
-                           setInfoText("Rotating camera");
-                       System.out.println("UseDefault " + useDefault);
+                       setUseDefault(!useDefault);
                }
                
-               
-               
-               
                update();
                return true;
        }
        
+       private void setUseDefault(boolean b) {
+           useDefault = b;
+           if (useDefault)
+            setInfoText("Rotating camera");
+        if (cameraButton != null)
+            cameraButton.setSelection(useDefault);
+       }
+       
        
        private void update() {
                panel.refresh();
@@ -387,6 +451,7 @@ public class RoutePipeAction extends vtkSwtAction {
                translateAxisGizmo.attach(panel);
                setPreviousPosition(previousPosition);
                updateCurrentPoint();
+               updateWidget();
        }
        
        protected void setPreviousPosition(Vector3d v) {
@@ -433,6 +498,7 @@ public class RoutePipeAction extends vtkSwtAction {
                translateAxisGizmo.attach(panel);
                setPreviousPosition(previousPosition);
                updateCurrentPoint();
+               updateWidget();
        }
        
        private void activateSplit(PipeControlPoint start) throws Exception{
@@ -482,7 +548,10 @@ public class RoutePipeAction extends vtkSwtAction {
        }
        
        private void setLockType(LockType type, boolean force) {
-               if (force || (lock != LockType.CUSTOM || !lockForced) ) {
+           if (type == LockType.CUSTOM && (direction == null || added.size() > 0)) {
+               // nothing to do..
+           } else if (force || (lock != LockType.CUSTOM || !lockForced || added.size() > 0) ) {
+                   
                        lock = type;
                        
                        switch (lock) {
@@ -510,7 +579,16 @@ public class RoutePipeAction extends vtkSwtAction {
                                break;
                                
                        }
+                       
                }
+               updateWidget();
+       }
+       
+       private void updateWidget() {
+           if (axisCombo != null) {
+            axisCombo.select(lock.ordinal());
+            axisCombo.setEnabled(!lockForced || lock != LockType.CUSTOM);
+           }
        }
        
        @Override
@@ -557,7 +635,7 @@ public class RoutePipeAction extends vtkSwtAction {
                                                                addPoint();
                                                        }
                                                } else {
-                                                       throw new RuntimeException("RoutePipeAction initlialization has been failed, no added components found");
+                                                       throw new RuntimeException("RoutePipeAction initialization has failed, no added components found");
                //                      // user was selecting position of branch
                //                    lastPoint.set(startPoint);
                //                    controlPoints.add(new Point3d(startPoint));