From: Marko Luukkainen Date: Wed, 30 Oct 2019 14:16:14 +0000 (+0200) Subject: Allow Pipe Routing to be created without branch support X-Git-Tag: v1.43.0~159^2 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=064a7d0401dba71baae82737271620ca7bcb6bfa;p=simantics%2F3d.git Allow Pipe Routing to be created without branch support Additionally, re-using pipe routing for translating free ends. gitlab #36 Change-Id: Ife8fc5ca4e5bae505bb95c488c3e2d263a29a188 --- diff --git a/org.simantics.g3d.vtk/src/org/simantics/g3d/vtk/swt/TranslateAction.java b/org.simantics.g3d.vtk/src/org/simantics/g3d/vtk/swt/TranslateAction.java index 47a3ea3b..b30573c5 100644 --- a/org.simantics.g3d.vtk/src/org/simantics/g3d/vtk/swt/TranslateAction.java +++ b/org.simantics.g3d.vtk/src/org/simantics/g3d/vtk/swt/TranslateAction.java @@ -303,7 +303,8 @@ public class TranslateAction extends vtkSwtAction{ @Override public boolean mouseDragged(MouseEvent e) { - if ((e.getModifiersEx() & MouseEvent.BUTTON1_DOWN_MASK) > 0 && valid) { + //if ((e.getModifiersEx() & MouseEvent.BUTTON1_DOWN_MASK) > 0 && valid) { + if (e.getButton() == MouseEvent.BUTTON1 && valid) { Vector3d translate = getTranslate(e.getX(), e.getY(), prevTranslate); //System.out.println("translate " + translate); diff --git a/org.simantics.plant3d/src/org/simantics/plant3d/actions/RoutePipeAction.java b/org.simantics.plant3d/src/org/simantics/plant3d/actions/RoutePipeAction.java index a4c04b3e..0f82184b 100644 --- a/org.simantics.plant3d/src/org/simantics/plant3d/actions/RoutePipeAction.java +++ b/org.simantics.plant3d/src/org/simantics/plant3d/actions/RoutePipeAction.java @@ -58,24 +58,25 @@ public class RoutePipeAction extends vtkSwtAction { private int decimals = 2; private P3DRootNode root; - private PipelineComponent startComponent; - private PipeRun pipeRun; + protected PipelineComponent startComponent; + protected PipeRun pipeRun; + private boolean allowBranches; - private TranslateAxisGizmo translateAxisGizmo = new TranslateAxisGizmo(); + protected TranslateAxisGizmo translateAxisGizmo = new TranslateAxisGizmo(); private SplitPointSelectionGizmo splitPointSelectionGizmo; private ConstraintPointGizmo constraintPointGizmo; private TerminalSelectionGizmo terminalSelectionGizmo; private NodeMap nodeMap; - private enum ToolState{NOT_ACTIVE, INITIALIZING, SELECTING_POSITION, SELECTING_SPLIT, ROUTING}; - private ToolState state = ToolState.NOT_ACTIVE; + protected enum ToolState{NOT_ACTIVE, INITIALIZING, SELECTING_POSITION, SELECTING_SPLIT, ROUTING}; + protected ToolState state = ToolState.NOT_ACTIVE; private ConstraintDetector detector;// = new DummyConstraintDetector(); - private boolean useDefault = false; - private Vector3d direction = null; - private Vector3d previousPosition = null; - private Vector3d currentPosition = null; + protected boolean useDefault = false; + protected Vector3d direction = null; + protected Vector3d previousPosition = null; + protected Vector3d currentPosition = null; boolean step = false; @@ -87,10 +88,14 @@ public class RoutePipeAction extends vtkSwtAction { private Set allowed = new HashSet(); - public RoutePipeAction(InteractiveVtkComposite panel, P3DRootNode root) { + this(panel,root, true); + } + + public RoutePipeAction(InteractiveVtkComposite panel, P3DRootNode root, boolean allowBranches) { super(panel); this.root = root; + this.allowBranches = allowBranches; setText("Route Pipe"); setImageDescriptor(Activator.imageDescriptorFromPlugin(Activator.PLUGIN_ID, "icons/Straight.png")); nodeMap = root.getNodeMap(); @@ -107,7 +112,7 @@ public class RoutePipeAction extends vtkSwtAction { allowed.add(PositionType.NEXT); if (this.startComponent.getPrevious() == null && !(this.startComponent instanceof Nozzle)) allowed.add(PositionType.PREVIOUS); - if (this.startComponent instanceof InlineComponent && !this.startComponent.getControlPoint().isFixed()) + if (allowBranches && this.startComponent instanceof InlineComponent && !this.startComponent.getControlPoint().isFixed()) allowed.add(PositionType.SPLIT); setEnabled(allowed.size() > 0); } @@ -165,7 +170,7 @@ public class RoutePipeAction extends vtkSwtAction { panel.unlock(); } - private List added = new ArrayList(); + protected List added = new ArrayList(); @Override public boolean keyPressed(KeyEvent e) { @@ -256,7 +261,7 @@ public class RoutePipeAction extends vtkSwtAction { boolean startRemovable = false; - private void activate() throws Exception { + protected void activate() throws Exception { state = ToolState.INITIALIZING; added.clear(); @@ -292,7 +297,7 @@ public class RoutePipeAction extends vtkSwtAction { - private void activateNextPrev(PipeControlPoint start) throws Exception{ + protected void activateNextPrev(PipeControlPoint start) throws Exception{ if (!reversed && start.isDualInline()) start = start.getSubPoint().get(0); else if (reversed && start.isDualSub()) @@ -368,7 +373,7 @@ public class RoutePipeAction extends vtkSwtAction { updateCurrentPoint(); } - private void setPreviousPosition(Vector3d v) { + protected void setPreviousPosition(Vector3d v) { previousPosition = new Vector3d(v); if (translateAxisGizmo.isAttached()) translateAxisGizmo.setPosition(previousPosition); @@ -536,7 +541,7 @@ public class RoutePipeAction extends vtkSwtAction { addPoint(); } } else { - throw new RuntimeException("kjf"); + throw new RuntimeException("RoutePipeAction initlialization has been failed, no added components found"); // // user was selecting position of branch // lastPoint.set(startPoint); // controlPoints.add(new Point3d(startPoint)); @@ -678,16 +683,7 @@ public class RoutePipeAction extends vtkSwtAction { INode hoverObject = null; - private void updateRouting(double x, double y) { -// if(input.keyPressed(KeyEvent.VK_ESCAPE)) { -// controlPoints.clear(); -// end(); -// return; -// } -// if (input.keyPressed(KeyEvent.VK_C)) { -// useCamera = !useCamera; -// cameraAction.setChecked(useCamera); -// } + protected void updateRouting(double x, double y) { if (useDefault) { //panel.getDefaultAction().update(); return; @@ -769,7 +765,7 @@ public class RoutePipeAction extends vtkSwtAction { panel.refresh(); } - private boolean updateCurrentPoint(Vector3d o, Vector3d d) { + protected boolean updateCurrentPoint(Vector3d o, Vector3d d) { Vector3d point = new Vector3d(this.previousPosition); @@ -841,7 +837,7 @@ public class RoutePipeAction extends vtkSwtAction { return null; } - private void updateRoute(Vector3d o, Vector3d d) { + protected void updateRoute(Vector3d o, Vector3d d) { detector.clearConstraintHighlights(); Point3d previousPipePoint = new Point3d(previousPosition); String s = ""; @@ -928,6 +924,10 @@ public class RoutePipeAction extends vtkSwtAction { } private PositionType endingToStraight(INode straightNode, double mu[], Vector3d o, Vector3d d) { + if (!allowBranches) { + updateCurrentPoint(); + return null; + } InlineComponent s = (InlineComponent)straightNode; String info = ""; Point3d sStart = new Point3d(); @@ -1047,6 +1047,10 @@ public class RoutePipeAction extends vtkSwtAction { } private PositionType endingLockToStraight(INode straightNode, double mu[]) { + if (!allowBranches) { + updateCurrentPoint(); + return null; + } InlineComponent s = (InlineComponent)straightNode; Point3d sStart = new Point3d(); Point3d sEnd = new Point3d(); @@ -1101,7 +1105,7 @@ public class RoutePipeAction extends vtkSwtAction { return null; } - private void addPoint() throws Exception { + protected void addPoint() throws Exception { InlineComponent previous = (InlineComponent)getLast(); PipeControlPoint previousCP = previous.getControlPoint(); TurnComponent turn = ComponentUtils.createTurn(root); @@ -1145,7 +1149,7 @@ public class RoutePipeAction extends vtkSwtAction { /** * Updates tool graphics for current point */ - private void updateCurrentPoint() { + protected void updateCurrentPoint() { InlineComponent straight = (InlineComponent)added.get(added.size()-1); // TODO: the inline length is from previous update step. double l; @@ -1198,7 +1202,7 @@ public class RoutePipeAction extends vtkSwtAction { } - private void endPiping() throws Exception { + protected void endPiping() throws Exception { state = ToolState.NOT_ACTIVE; if (endTo != null) { diff --git a/org.simantics.plant3d/src/org/simantics/plant3d/actions/TranslateFreeVariableLengthAction.java b/org.simantics.plant3d/src/org/simantics/plant3d/actions/TranslateFreeVariableLengthAction.java new file mode 100644 index 00000000..e693f1fb --- /dev/null +++ b/org.simantics.plant3d/src/org/simantics/plant3d/actions/TranslateFreeVariableLengthAction.java @@ -0,0 +1,183 @@ +package org.simantics.plant3d.actions; + +import java.util.ArrayList; +import java.util.List; + +import javax.vecmath.Vector3d; + +import org.simantics.g3d.math.Ray; +import org.simantics.g3d.scenegraph.IG3DNode; +import org.simantics.g3d.vtk.swt.InteractiveVtkComposite; +import org.simantics.g3d.vtk.utils.vtkUtil; +import org.simantics.plant3d.Activator; +import org.simantics.plant3d.actions.RoutePipeAction.LockType; +import org.simantics.plant3d.actions.RoutePipeAction.ToolState; +import org.simantics.plant3d.scenegraph.EndComponent; +import org.simantics.plant3d.scenegraph.InlineComponent; +import org.simantics.plant3d.scenegraph.Nozzle; +import org.simantics.plant3d.scenegraph.P3DRootNode; +import org.simantics.plant3d.scenegraph.PipelineComponent; +import org.simantics.plant3d.scenegraph.TurnComponent; +import org.simantics.plant3d.scenegraph.controlpoint.PipeControlPoint; +import org.simantics.plant3d.scenegraph.controlpoint.PipingRules; +import org.simantics.plant3d.scenegraph.controlpoint.PipeControlPoint.Direction; +import org.simantics.plant3d.utils.ComponentUtils; + +public class TranslateFreeVariableLengthAction extends RoutePipeAction{ + + private InlineComponent component; + + public TranslateFreeVariableLengthAction(InteractiveVtkComposite panel, P3DRootNode root) { + super(panel, root, false); + setText("Translate"); + setImageDescriptor(Activator.imageDescriptorFromPlugin("com.famfamfam.silk", "icons/arrow_refresh.png")); + } + + + public void setNode(IG3DNode node) { + if (node instanceof InlineComponent) { + component = (InlineComponent)node; + if (component.isVariableLength() && (component.getNext() == null || component.getPrevious() == null)) { + PipelineComponent pathLegStart; + if (component.getNext() == null) { + pathLegStart = component.getControlPoint().findPreviousEnd().getPipelineComponent(); + } else { + pathLegStart = component.getControlPoint().findNextEnd().getPipelineComponent(); + } + setComponent(pathLegStart); + + setEnabled(true); + } else { + setEnabled(false); + } + } else { + component = null; + setEnabled(false); + } + } + + @Override + protected void activate() throws Exception { + state = ToolState.INITIALIZING; + added.clear(); + pipeRun = startComponent.getPipeRun(); + PipeControlPoint start = startComponent.getControlPoint(); + activateNextPrev(start); + } + + @Override + protected void activateNextPrev(PipeControlPoint start) throws Exception { + if (!reversed && start.isDualInline()) + start = start.getSubPoint().get(0); + else if (reversed && start.isDualSub()) + start = start.parent; + + pipeRun = component.getPipeRun(); + + List cps = new ArrayList(); + PipeControlPoint s = null; + if (component.getNext() == null) { + s = component.getControlPoint().findPreviousEnd(cps); + } else { + s = component.getControlPoint().findNextEnd(cps); + } + if (s.getPipelineComponent() != startComponent) { + throw new Exception("Path leg start mismatch"); + } + + + + setPreviousPosition(start.getWorldPosition()); + currentPosition = component.getPosition(); + + if (startComponent instanceof Nozzle) { + direction = startComponent.getControlPoint().getDirectedControlPointDirection(); + lock = LockType.CUSTOM; + } else if (startComponent instanceof PipelineComponent){ + if (startComponent instanceof InlineComponent) { + direction = startComponent.getControlPoint().getPathLegDirection(reversed ? Direction.PREVIOUS : Direction.NEXT); + lock = LockType.CUSTOM; + if (((InlineComponent) startComponent).isVariableLength()) { + direction = null; + lock = LockType.NONE; + } + Vector3d v = new Vector3d(); + if (!reversed) { + start.getControlPointEnds(v, previousPosition); + } else { + start.getControlPointEnds(previousPosition,v); + } + } else if (startComponent instanceof TurnComponent) { + if (start.isFixed()) { + direction = startComponent.getControlPoint().getPathLegDirection(reversed ? Direction.PREVIOUS : Direction.NEXT); + lock = LockType.CUSTOM; + } else { + direction = null; + lock = LockType.NONE; + } + } else if (startComponent instanceof EndComponent) { + throw new Exception("Not supported"); + } + + } else { + throw new Exception("Not supported"); + } + currentPosition = new Vector3d(previousPosition); + state = ToolState.ROUTING; + if (direction != null) { + direction.normalize(); + + } + startRemovable = start.isDeletable(); + start.setDeletable(false); + for (PipeControlPoint pcp : cps) { + added.add(pcp.getPipelineComponent()); + pcp.setDeletable(false); + } + added.add(component); + + + translateAxisGizmo.attach(panel); + setPreviousPosition(previousPosition); + updateCurrentPoint(); + } + + @Override + public void deactivate() { + // TODO Auto-generated method stub + super.deactivate(); + } + + protected void addPoint() throws Exception { + // Translate action is not supposed to add points + return; + } + + @Override + protected void endPiping() throws Exception { + state = ToolState.NOT_ACTIVE; + panel.useDefaultAction(); + } + + protected void updateRouting(double x, double y) { + if (useDefault) { + //panel.getDefaultAction().update(); + return; + } + + endTo = null; + endType = null; + endPort = null; + + Ray ray = vtkUtil.createMouseRay(panel.getRenderer(),x, y); + Vector3d o = new Vector3d(ray.pos); + Vector3d d = ray.dir; + + + updateCurrentPoint(o, d); + updateRoute(o,d); + panel.refresh(); + } + + +} 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..92a88b53 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) { @@ -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); + } } diff --git a/org.simantics.plant3d/src/org/simantics/plant3d/editor/Plant3DEditor.java b/org.simantics.plant3d/src/org/simantics/plant3d/editor/Plant3DEditor.java index d3f3c5e4..2dc90bdd 100644 --- a/org.simantics.plant3d/src/org/simantics/plant3d/editor/Plant3DEditor.java +++ b/org.simantics.plant3d/src/org/simantics/plant3d/editor/Plant3DEditor.java @@ -45,6 +45,7 @@ import org.simantics.plant3d.actions.AddEquipmentAction; import org.simantics.plant3d.actions.AddNozzleAction; import org.simantics.plant3d.actions.RemoveAndSplitAction; import org.simantics.plant3d.actions.RoutePipeAction; +import org.simantics.plant3d.actions.TranslateFreeVariableLengthAction; import org.simantics.plant3d.actions.TranslateInlineAction; import org.simantics.plant3d.ontology.Plant3D; import org.simantics.plant3d.scenegraph.EndComponent; @@ -90,14 +91,15 @@ public class Plant3DEditor extends ResourceEditorPart { private NodeSelectionProvider2 selectionProvider; - private vtkCameraAndSelectorAction cameraAction; - private TranslateAction translateAction; - private TranslateInlineAction translateInlineAction; - private RotateAction rotateAction; - private RemoveAction removeAction; - private RemoveAndSplitAction removeSplitAction; - private RoutePipeAction routePipeAction; - private AddComponentAction addComponentAction; + protected vtkCameraAndSelectorAction cameraAction; + protected TranslateAction translateAction; + protected TranslateInlineAction translateInlineAction; + protected TranslateFreeVariableLengthAction translateFreeVariableLengthAction; + protected RotateAction rotateAction; + protected RemoveAction removeAction; + protected RemoveAndSplitAction removeSplitAction; + protected RoutePipeAction routePipeAction; + protected AddComponentAction addComponentAction; private P3DNodeMap nodeMap; @@ -129,8 +131,6 @@ public class Plant3DEditor extends ResourceEditorPart { hookContextMenu(); createScene(); - - //component.syncPopulate(); new ContextMenuListener(panel, contextMenu); @@ -160,9 +160,7 @@ public class Plant3DEditor extends ResourceEditorPart { rootNode = (P3DRootNode)mapping.map(graph, input); // update control points. // TODO : this should be optimized. - - - + try { P3DUtil.finalizeDBLoad(rootNode); nodeMap = createNodeMap(getSession(), mapping, panel,rootNode); @@ -239,6 +237,7 @@ public class Plant3DEditor extends ResourceEditorPart { protected void createActions() { translateAction = new TranslateAction(panel,nodeMap); translateInlineAction = new TranslateInlineAction(panel, nodeMap); + translateFreeVariableLengthAction = new TranslateFreeVariableLengthAction(panel, getRootNode()); rotateAction = new RotateAction(panel,nodeMap); removeAction = new RemoveAction(nodeMap) { public void setNode(IG3DNode node) { @@ -406,7 +405,10 @@ public class Plant3DEditor extends ResourceEditorPart { } else if (node instanceof InlineComponent) { //m.add(translateInlineAction); InlineComponent component = (InlineComponent)node; - m.add(translateInlineAction); + if (component.isVariableLength()) + m.add(translateFreeVariableLengthAction); + else + m.add(translateInlineAction); m.add(routePipeAction); routePipeAction.setComponent(component); m.add(addComponentAction); @@ -421,6 +423,7 @@ public class Plant3DEditor extends ResourceEditorPart { translateAction.setNode(node); translateInlineAction.setNode(node); + translateFreeVariableLengthAction.setNode(node); rotateAction.setNode(node); removeAction.setNode(node);