X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=org.simantics.plant3d%2Fsrc%2Forg%2Fsimantics%2Fplant3d%2Factions%2FTranslateInlineAction.java;h=352f7fd53f38f47ac7627947f0ee835424cdbb12;hb=refs%2Fchanges%2F87%2F4287%2F1;hp=1bb2874c5b0031feb6ab8d77efd312f2370efdf2;hpb=53d55c24c779745f188bdb18d32f71d20acb61b2;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 1bb2874c..352f7fd5 100644 --- a/org.simantics.plant3d/src/org/simantics/plant3d/actions/TranslateInlineAction.java +++ b/org.simantics.plant3d/src/org/simantics/plant3d/actions/TranslateInlineAction.java @@ -9,6 +9,8 @@ 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.scenegraph.base.INode; +import org.simantics.g3d.toolbar.ToolComposite; import org.simantics.g3d.vtk.common.VTKNodeMap; import org.simantics.g3d.vtk.swt.InteractiveVtkComposite; import org.simantics.g3d.vtk.swt.TranslateAction; @@ -16,39 +18,49 @@ import org.simantics.g3d.vtk.utils.vtkUtil; import org.simantics.plant3d.Activator; import org.simantics.plant3d.scenegraph.InlineComponent; import org.simantics.plant3d.scenegraph.PipelineComponent; -import org.simantics.plant3d.scenegraph.controlpoint.PipeControlPoint.Direction; -public class TranslateInlineAction extends TranslateAction{ - +public class TranslateInlineAction extends TranslateAction { + + private boolean inline; + private Vector3d s; private Vector3d e; private Vector3d dir; - public TranslateInlineAction(InteractiveVtkComposite panel, VTKNodeMap nodeMap) { - super(panel, nodeMap); + public TranslateInlineAction(InteractiveVtkComposite panel, VTKNodeMap nodeMap, + ToolComposite toolComposite) { + super(panel, nodeMap, toolComposite); setImageDescriptor(Activator.imageDescriptorFromPlugin("com.famfamfam.silk", "icons/arrow_refresh.png")); } - + @Override public void setNode(IG3DNode node) { super.setNode(node); if (node instanceof InlineComponent) { - InlineComponent comp = (InlineComponent)node; + InlineComponent comp = (InlineComponent) node; if (comp.isVariableLength()) { setEnabled(false); + } else if (comp.getNext() == null || comp.getPrevious() == null) { + setEnabled(true); + inline = false; + dir = comp.getControlPoint().getInlineDir(); + dir.normalize(); } else { setEnabled(true); - + inline = true; 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). + // 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.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(); @@ -57,9 +69,9 @@ public class TranslateInlineAction extends TranslateAction{ Point3d pe = new Point3d(); 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. + dir = comp.getControlPoint().getInlineDir(); + // 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); @@ -80,67 +92,79 @@ public class TranslateInlineAction extends TranslateAction{ setEnabled(false); } } - + + @Override + protected void createAxisSelection(ToolComposite toolComposite) { + // No axis selection for inline components + } + @Override public boolean keyPressed(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_ESCAPE) panel.useDefaultAction(); - if (valid) + if (!inline) { + return super.keyPressed(e); + } else { + if (valid) + return true; + + update(); return true; - - update(); - return true; + } } - + @Override public void setWorldCoord(boolean b) { - + } - + @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); - + + 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); + } + + } }