X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=org.simantics.plant3d%2Fsrc%2Forg%2Fsimantics%2Fplant3d%2Factions%2FAddComponentAction.java;h=174d6f1166eac0718aa4aa814bb491b34ae67c66;hb=0ad74f024bc769b126a2e46d0015fe0deb30b34c;hp=a4398a5455b582fab3c3192800593c9f921e5c7d;hpb=8b06e290cf681e2157824428395988063686e7b3;p=simantics%2F3d.git diff --git a/org.simantics.plant3d/src/org/simantics/plant3d/actions/AddComponentAction.java b/org.simantics.plant3d/src/org/simantics/plant3d/actions/AddComponentAction.java index a4398a54..174d6f11 100644 --- a/org.simantics.plant3d/src/org/simantics/plant3d/actions/AddComponentAction.java +++ b/org.simantics.plant3d/src/org/simantics/plant3d/actions/AddComponentAction.java @@ -17,6 +17,7 @@ import org.simantics.plant3d.Activator; import org.simantics.plant3d.dialog.ComponentSelectionDialog; import org.simantics.plant3d.gizmo.TerminalSelectionGizmo; import org.simantics.plant3d.scenegraph.InlineComponent; +import org.simantics.plant3d.scenegraph.Nozzle; import org.simantics.plant3d.scenegraph.P3DRootNode; import org.simantics.plant3d.scenegraph.PipeRun; import org.simantics.plant3d.scenegraph.PipelineComponent; @@ -44,6 +45,9 @@ public class AddComponentAction extends vtkSwtAction { private Set allowed = new HashSet(); private Item toAdd = null; + private PositionType insertPosition; + private boolean insertAdjustable; + private boolean lengthAdjustable; public AddComponentAction(InteractiveVtkComposite panel, P3DRootNode root) { super(panel); @@ -58,14 +62,20 @@ public class AddComponentAction extends vtkSwtAction { this.component = component; allowed.clear(); - if (component.getNext() == null) { - allowed.add(PositionType.NEXT); - } - if (component.getPrevious() == null) { - allowed.add(PositionType.PREVIOUS); - } - if (component instanceof InlineComponent && !component.getControlPoint().isFixed()){ - allowed.add(PositionType.SPLIT); + if (component instanceof Nozzle) { + if (component.getNext() == null && component.getPrevious() == null) { + allowed.add(PositionType.NEXT); + } + } else { + if (component.getNext() == null) { + allowed.add(PositionType.NEXT); + } + if (component.getPrevious() == null) { + allowed.add(PositionType.PREVIOUS); + } + if (component instanceof InlineComponent && !component.getControlPoint().isFixed()){ + allowed.add(PositionType.SPLIT); + } } setEnabled(allowed.size() > 0); } @@ -77,12 +87,16 @@ public class AddComponentAction extends vtkSwtAction { @Override public void run() { - ComponentSelectionDialog dialog = new ComponentSelectionDialog(Display.getCurrent().getActiveShell(), allowed); + + ComponentSelectionDialog dialog = new ComponentSelectionDialog(Display.getCurrent().getActiveShell(), allowed, component); if (dialog.open() == ComponentSelectionDialog.CANCEL) return; toAdd = dialog.getSelected(); if (toAdd == null) return; + this.insertPosition = dialog.getInsertPosition(); + this.insertAdjustable = dialog.isInsertAdjustable(); + this.lengthAdjustable = dialog.isLenghtAdjustable(); this.length = dialog.getLength(); this.angle = dialog.getAngle(); this.diameter = dialog.getDiameter(); @@ -117,7 +131,7 @@ public class AddComponentAction extends vtkSwtAction { public void deattach() { // deactivate(); component = null; - nodeMap.commit(); + nodeMap.commit("Add component"); deattachUI(); super.deattach(); panel.refresh(); @@ -181,16 +195,31 @@ public class AddComponentAction extends vtkSwtAction { dir = new Vector3d(); toPcp.getInlineControlPointEnds(start, end, dir); dir.normalize(); - switch (position) { - case NEXT: - pos = new Vector3d(end); - break; - case PREVIOUS: - pos = new Vector3d(start); - break; - case SPLIT: - break; - } + if (!insertAdjustable || insertPosition == PositionType.NEXT) { + switch (position) { + case NEXT: + pos = new Vector3d(end); + break; + case PREVIOUS: + pos = new Vector3d(start); + break; + case SPLIT: + break; + } + } else if (insertPosition == PositionType.SPLIT) { + pos = new Vector3d(toPcp.getWorldPosition()); + } else { + switch (position) { + case NEXT: + pos = new Vector3d(start); + break; + case PREVIOUS: + pos = new Vector3d(end); + break; + case SPLIT: + break; + } + } } else if (toPcp.isDirected()) { dir = new Vector3d(toPcp.getDirection(Direction.NEXT)); @@ -198,9 +227,22 @@ public class AddComponentAction extends vtkSwtAction { } else if (toPcp.isTurn() && toPcp.isFixed()) { dir = new Vector3d(toPcp.getDirection(position == PositionType.NEXT ? Direction.NEXT : Direction.PREVIOUS)); pos = new Vector3d(toPcp.getWorldPosition()); - Vector3d v = new Vector3d(dir); - v.scale(toPcp.getInlineLength()); - pos.add(v); + if (!lengthAdjustable) { + Vector3d v = new Vector3d(dir); + v.scale(toPcp.getInlineLength()); + pos.add(v); + } else { + if (insertPosition == PositionType.NEXT) { + Vector3d v = new Vector3d(dir); + v.scale(toPcp.getInlineLength()); + pos.add(v); + } else if (insertPosition == PositionType.SPLIT) { + // scale 0.5*length so that we don't remove the length twice from the new component + Vector3d v = new Vector3d(dir); + v.scale(toPcp.getInlineLength()*0.5); + pos.add(v); + } + } } @@ -222,7 +264,16 @@ public class AddComponentAction extends vtkSwtAction { newComponent.updateParameters(); Vector3d v = new Vector3d(dir); - v.scale(newComponent.getControlPoint().getInlineLength()); + if (insertAdjustable) { + if (insertPosition == PositionType.NEXT) + v.scale(newComponent.getControlPoint().getInlineLength()); + else if (insertPosition == PositionType.SPLIT) + v.set(0, 0, 0); + else if (insertPosition == PositionType.PREVIOUS) + v.scale(-newComponent.getControlPoint().getInlineLength()); + } else { + v.scale(newComponent.getControlPoint().getInlineLength()); + } switch (position) { case NEXT: pos.add(v);