X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=org.simantics.plant3d%2Fsrc%2Forg%2Fsimantics%2Fplant3d%2Factions%2FTranslateInlineAction.java;h=594c73d3688808109c03d86de18d1a1671007cda;hb=a1e1faa6915445e786f482170576b9c9d0f5d982;hp=c8c862240e76659e1ce0c6a92c2b4d1181796efb;hpb=0602e0f78f22aaf27211ef1de801ddc631e103c0;p=simantics%2F3d.git diff --git a/org.simantics.plant3d/src/org/simantics/plant3d/actions/TranslateInlineAction.java b/org.simantics.plant3d/src/org/simantics/plant3d/actions/TranslateInlineAction.java index c8c86224..594c73d3 100644 --- a/org.simantics.plant3d/src/org/simantics/plant3d/actions/TranslateInlineAction.java +++ b/org.simantics.plant3d/src/org/simantics/plant3d/actions/TranslateInlineAction.java @@ -20,6 +20,8 @@ import org.simantics.plant3d.scenegraph.controlpoint.PipeControlPoint.Direction; public class TranslateInlineAction extends TranslateAction{ + private boolean inline; + private Vector3d s; private Vector3d e; private Vector3d dir; @@ -35,10 +37,15 @@ public class TranslateInlineAction extends TranslateAction{ if (node instanceof InlineComponent) { InlineComponent comp = (InlineComponent)node; if (comp.isVariableLength()) { - setEnabled(false); - } else { + setEnabled(false); + } else if (comp.getNext() == null || comp.getPrevious() == null) { + setEnabled(true); + inline = false; + dir = comp.getControlPoint().getPathLegDirection(Direction.NEXT); + dir.normalize(); + } else { setEnabled(true); - + inline = true; PipelineComponent prev = comp.getPrevious(); PipelineComponent next = comp.getNext(); if (prev == null || next == null) { @@ -46,9 +53,9 @@ public class TranslateInlineAction extends TranslateAction{ setEnabled(false); return; } - if (prev.getControlPoint().isInline() && !prev.getControlPoint().isFixed() && prev.getPrevious() != null) + if (prev.getControlPoint().isInline() && !prev.getControlPoint().isFixedLength() && prev.getPrevious() != null) prev = prev.getPrevious(); - if (next.getControlPoint().isInline() && !next.getControlPoint().isFixed() && next.getNext() != null) { + if (next.getControlPoint().isInline() && !next.getControlPoint().isFixedLength() && next.getNext() != null) { next = next.getNext(); } Point3d ns = new Point3d(); @@ -62,13 +69,13 @@ public class TranslateInlineAction extends TranslateAction{ // We may have offsets in the path leg, hence we have to project the coordinates. Vector3d wp = node.getWorldPosition(); if (prev.getControlPoint().isVariableLength()) - s = MathTools.closestPointOnStraight(ps, wp, dir); + s = MathTools.closestPointOnStraight(ps, wp, dir); else - s = MathTools.closestPointOnStraight(pe, wp, dir); + s = MathTools.closestPointOnStraight(pe, wp, dir); if (next.getControlPoint().isVariableLength()) - e = MathTools.closestPointOnStraight(ne, wp, dir); + e = MathTools.closestPointOnStraight(ne, wp, dir); else - e = MathTools.closestPointOnStraight(ns, wp, dir); + 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); @@ -85,11 +92,15 @@ public class TranslateInlineAction extends TranslateAction{ public boolean keyPressed(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_ESCAPE) panel.useDefaultAction(); - if (valid) - return true; - - update(); - return true; + if (!inline) { + return super.keyPressed(e); + } else { + if (valid) + return true; + + update(); + return true; + } } @Override @@ -99,46 +110,50 @@ public class TranslateInlineAction extends TranslateAction{ @Override 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 true; - //boolean step = ((e.getModifiers() & MouseEvent.CTRL_MASK) > 0); - Vector3d pos = new Vector3d(node.getWorldPosition()); - //pos.add(translate); - pos.set(translate); - //pos = constaints(pos, step); - setWorldPos(pos); - - //mapping.rangeModified(node); - - //nodeMap.modified(node); - update(); + //if ((e.getModifiersEx() & MouseEvent.BUTTON1_DOWN_MASK) > 0 && valid) { + if (e.getButton() == MouseEvent.BUTTON1 && valid) { + if (inline) { + Vector3d translate = getTranslate(e.getX(), e.getY(), prevTranslate); + //System.out.println("translate " + translate); + if (translate == null) + return true; + //boolean step = ((e.getModifiers() & MouseEvent.CTRL_MASK) > 0); + Vector3d pos = new Vector3d(node.getWorldPosition()); + + System.out.println(pos + " " + translate); + //pos.add(translate); + pos.set(translate); + //pos = constaints(pos, step); + setWorldPos(pos); + update(); + } else { + super.mouseDragged(e); + } } else { getDefaultAction().mouseDragged(e); update(); - } + } return true; } - - protected Vector3d getTranslate(double x, double y, Vector3d offset) { Ray ray = vtkUtil.createMouseRay(panel.getRenderer(),x, y); Vector3d p = node.getWorldPosition(); - Vector3d i1 = new Vector3d(); - Vector3d i2 = new Vector3d(); - - double mu[] = new double[2]; - MathTools.intersectStraightStraight( p, dir,ray.pos, ray.dir, i2, i1,mu); - - Vector3d t = MathTools.closestPointOnEdge(i1, s, e); - return t; + if (inline) { + Vector3d i1 = new Vector3d(); + Vector3d i2 = new Vector3d(); + + double mu[] = new double[2]; + MathTools.intersectStraightStraight( p, dir,ray.pos, ray.dir, i2, i1,mu); + + Vector3d t = MathTools.closestPointOnEdge(i1, s, e); + return t; + } else { + return super.getTranslate(x, y, offset); + } }