From c92f0ce42986722e8b68444a7eb837a8bd882e1a Mon Sep 17 00:00:00 2001 From: Marko Luukkainen Date: Mon, 5 Aug 2019 16:18:09 +0300 Subject: [PATCH] Disable in-line translate for variable length components gitlab #17 Change-Id: I587c5f1af80db32e237adf628bf70d446d432781 --- .../actions/TranslateInlineAction.java | 61 +++++++++++-------- 1 file changed, 35 insertions(+), 26 deletions(-) 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 2c10845f..4ac0a0e7 100644 --- a/org.simantics.plant3d/src/org/simantics/plant3d/actions/TranslateInlineAction.java +++ b/org.simantics.plant3d/src/org/simantics/plant3d/actions/TranslateInlineAction.java @@ -33,34 +33,43 @@ public class TranslateInlineAction extends TranslateAction{ public void setNode(IG3DNode node) { super.setNode(node); if (node instanceof InlineComponent) { - setEnabled(true); InlineComponent comp = (InlineComponent)node; + if (comp.isVariableLength()) { + setEnabled(false); + } else { + setEnabled(true); - PipelineComponent prev = comp.getPrevious(); - PipelineComponent next = comp.getNext(); - if (prev.getControlPoint().isInline() && !prev.getControlPoint().isFixed()) - prev = prev.getPrevious(); - if (next.getControlPoint().isInline() && !next.getControlPoint().isFixed()) { - next = next.getNext(); + PipelineComponent prev = comp.getPrevious(); + PipelineComponent next = comp.getNext(); + if (prev == null || next == null) { + // TODO : we should support open ended translation (when translated component is the first or last of the run). + setEnabled(false); + return; + } + if (prev.getControlPoint().isInline() && !prev.getControlPoint().isFixed()) + prev = prev.getPrevious(); + if (next.getControlPoint().isInline() && !next.getControlPoint().isFixed()) { + 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); + 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); + // Remove component's own space from end points to get actual movement range + double l = comp.getControlPoint().getInlineLength(); + Vector3d ld = new Vector3d(dir); + ld.scale(l); + s.add(ld); + e.sub(ld); } - Point3d ns = new Point3d(); - Point3d ne = new Point3d(); - Point3d ps = new Point3d(); - Point3d pe = new Point3d(); - next.getControlPointEnds(ns, ne); - prev.getControlPointEnds(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); - // Remove component's own space from end points to get actual movement range - double l = comp.getControlPoint().getInlineLength(); - Vector3d ld = new Vector3d(dir); - ld.scale(l); - s.add(ld); - e.sub(ld); } else { setEnabled(false); } @@ -89,7 +98,7 @@ public class TranslateInlineAction extends TranslateAction{ //System.out.println("translate " + translate); if (translate == null) return; - boolean step = ((e.getModifiers() & MouseEvent.CTRL_MASK) > 0); + //boolean step = ((e.getModifiers() & MouseEvent.CTRL_MASK) > 0); Vector3d pos = new Vector3d(node.getWorldPosition()); //pos.add(translate); pos.set(translate); -- 2.45.2