]> gerrit.simantics Code Review - simantics/3d.git/blobdiff - org.simantics.plant3d/src/org/simantics/plant3d/actions/TranslateInlineAction.java
SCL bindings to some G3D and Plant3D Java classes
[simantics/3d.git] / org.simantics.plant3d / src / org / simantics / plant3d / actions / TranslateInlineAction.java
index 4ac0a0e72c1c8976ad48ab4603c25c8f541146b7..c8c862240e76659e1ce0c6a92c2b4d1181796efb 100644 (file)
@@ -9,9 +9,9 @@ import javax.vecmath.Vector3d;
 import org.simantics.g3d.math.MathTools;
 import org.simantics.g3d.math.Ray;
 import org.simantics.g3d.scenegraph.IG3DNode;
-import org.simantics.g3d.vtk.action.TranslateAction;
-import org.simantics.g3d.vtk.common.InteractiveVtkPanel;
 import org.simantics.g3d.vtk.common.VTKNodeMap;
+import org.simantics.g3d.vtk.swt.InteractiveVtkComposite;
+import org.simantics.g3d.vtk.swt.TranslateAction;
 import org.simantics.g3d.vtk.utils.vtkUtil;
 import org.simantics.plant3d.Activator;
 import org.simantics.plant3d.scenegraph.InlineComponent;
@@ -24,7 +24,7 @@ public class TranslateInlineAction extends TranslateAction{
        private Vector3d e;
        private Vector3d dir;
 
-       public TranslateInlineAction(InteractiveVtkPanel panel, VTKNodeMap nodeMap) {
+       public TranslateInlineAction(InteractiveVtkComposite panel, VTKNodeMap nodeMap) {
                super(panel, nodeMap);
                setImageDescriptor(Activator.imageDescriptorFromPlugin("com.famfamfam.silk", "icons/arrow_refresh.png"));
        }
@@ -46,23 +46,29 @@ public class TranslateInlineAction extends TranslateAction{
                                        setEnabled(false);
                                        return;
                                }
-                               if (prev.getControlPoint().isInline() && !prev.getControlPoint().isFixed())
+                               if (prev.getControlPoint().isInline() && !prev.getControlPoint().isFixed() && prev.getPrevious() != null)
                                        prev = prev.getPrevious();
-                               if (next.getControlPoint().isInline() && !next.getControlPoint().isFixed()) {
+                               if (next.getControlPoint().isInline() && !next.getControlPoint().isFixed() && next.getNext() != null) {
                                        next = next.getNext();
                                }
                                Point3d ns = new Point3d();
                                Point3d ne = new Point3d();
                                Point3d ps = new Point3d();
                                Point3d pe = new Point3d();
-                               next.getControlPointEnds(ns, ne);
-                               prev.getControlPointEnds(ps, pe);
+                               next.getEnds(ns, ne);
+                               prev.getEnds(ps, pe);
                                dir = comp.getControlPoint().getPathLegDirection(Direction.NEXT);
                                dir.normalize();
                                // We may have offsets in the path leg, hence we have to project the coordinates.
                                Vector3d wp = node.getWorldPosition();
-                               s = MathTools.closestPointOnStraight(pe, wp, dir);
-                               e = MathTools.closestPointOnStraight(ns, wp, dir);
+                               if (prev.getControlPoint().isVariableLength())
+                                   s = MathTools.closestPointOnStraight(ps, wp, dir);
+                               else
+                                   s = MathTools.closestPointOnStraight(pe, wp, dir);
+                               if (next.getControlPoint().isVariableLength())
+                                   e = MathTools.closestPointOnStraight(ne, wp, dir);
+                               else
+                                   e = MathTools.closestPointOnStraight(ns, wp, dir);
                                // Remove component's own space from end points to get actual movement range
                                double l = comp.getControlPoint().getInlineLength();
                                Vector3d ld = new Vector3d(dir);
@@ -76,13 +82,14 @@ public class TranslateInlineAction extends TranslateAction{
        }
        
        @Override
-       public void keyPressed(KeyEvent e) {
+       public boolean keyPressed(KeyEvent e) {
                if (e.getKeyCode() == KeyEvent.VK_ESCAPE)
                        panel.useDefaultAction();
                if (valid)
-                       return;
+                       return true;
                
                update();
+               return true;
        }
        
        @Override
@@ -91,13 +98,13 @@ public class TranslateInlineAction extends TranslateAction{
        }
        
        @Override
-       public void mouseDragged(MouseEvent e) {
+       public boolean mouseDragged(MouseEvent e) {
                if ((e.getModifiersEx() & MouseEvent.BUTTON1_DOWN_MASK) > 0 && valid) { 
                        
                        Vector3d translate = getTranslate(e.getX(), e.getY(), prevTranslate);
                        //System.out.println("translate " + translate);
                        if (translate == null)
-                               return;
+                               return true;
                        //boolean step = ((e.getModifiers() & MouseEvent.CTRL_MASK) > 0);
                        Vector3d pos = new Vector3d(node.getWorldPosition());
                        //pos.add(translate);
@@ -110,16 +117,17 @@ public class TranslateInlineAction extends TranslateAction{
                        //nodeMap.modified(node);
                        update();
                } else {
-                       panel.getDefaultAction().mouseDragged(e);
+                       getDefaultAction().mouseDragged(e);
                        update();
                }
+               return true;
        }
        
        
        
        protected Vector3d getTranslate(double x, double y, Vector3d offset) {
                
-               Ray ray = vtkUtil.createMouseRay(panel.GetRenderer(),x, y);
+               Ray ray = vtkUtil.createMouseRay(panel.getRenderer(),x, y);
                
                Vector3d p = node.getWorldPosition();