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=60f95215250409cfb382c42474e1926f857fd417;hpb=ed38e7de95ae9c274a25269afa7d5b4369b20f1c;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 60f95215..174d6f11 100644 --- a/org.simantics.plant3d/src/org/simantics/plant3d/actions/AddComponentAction.java +++ b/org.simantics.plant3d/src/org/simantics/plant3d/actions/AddComponentAction.java @@ -45,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); @@ -84,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(); @@ -188,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)); @@ -205,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); + } + } } @@ -229,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);