X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=org.simantics.plant3d%2Fsrc%2Forg%2Fsimantics%2Fplant3d%2Factions%2FAddComponentAction.java;h=dae8c629b4335a7bfacb88503086d7d34285311b;hb=57ee576455c42f22303efc600964426474ab6110;hp=d9ee9d70849188f7f50e7ba0bc2b58513609c3ac;hpb=b464f638f47c449c3ddad850a2466773c3453999;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 d9ee9d70..dae8c629 100644 --- a/org.simantics.plant3d/src/org/simantics/plant3d/actions/AddComponentAction.java +++ b/org.simantics.plant3d/src/org/simantics/plant3d/actions/AddComponentAction.java @@ -6,6 +6,7 @@ import java.awt.event.MouseWheelEvent; import java.util.HashSet; import java.util.Set; +import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.resource.ResourceLocator; import org.eclipse.swt.widgets.Display; import org.simantics.db.Resource; @@ -50,6 +51,8 @@ public class AddComponentAction extends vtkSwtAction { private String libUri; + private double lengthFactor = 1.0; + public AddComponentAction(InteractiveVtkComposite panel, P3DRootNode root, String libUri) { super(panel); this.root = root; @@ -60,6 +63,10 @@ public class AddComponentAction extends vtkSwtAction { this.libUri = libUri; } + public void setLengthFactor(double lengthFactor) { + this.lengthFactor = lengthFactor; + } + public void setComponent(PipelineComponent component) { this.component = component; @@ -69,13 +76,13 @@ public class AddComponentAction extends vtkSwtAction { allowed.add(PositionType.NEXT); } } else { - if (component.getNext() == null) { + if (component.getNext() == null || component.getControlPoint().isVariableLength()) { allowed.add(PositionType.NEXT); } - if (component.getPrevious() == null) { + if (component.getPrevious() == null || component.getControlPoint().isVariableLength()) { allowed.add(PositionType.PREVIOUS); } - if (component instanceof InlineComponent && !component.getControlPoint().isFixedLength()){ + if (component instanceof InlineComponent && component.getControlPoint().isVariableLength()){ allowed.add(PositionType.SPLIT); } } @@ -88,6 +95,7 @@ public class AddComponentAction extends vtkSwtAction { private Double angle; private Double rotationAngle; private Double diameter; + private Double thickness; private Double turnRadius; @Override @@ -97,6 +105,7 @@ public class AddComponentAction extends vtkSwtAction { // Set list of already reserved component names dialog.addUsedNames(ComponentUtils.getPipelineComponentNames(root)); + dialog.setLengthFactor(lengthFactor); if (dialog.open() == ComponentSelectionDialog.CANCEL) return; @@ -111,6 +120,7 @@ public class AddComponentAction extends vtkSwtAction { this.angle = dialog.getAngle(); this.rotationAngle = dialog.getRotationAngle(); this.diameter = dialog.getDiameter(); + this.thickness = dialog.getThickness(); this.turnRadius = dialog.getTurnRadius(); allowed = dialog.filterAllowed(); gizmo.setComponent(component, allowed); @@ -180,11 +190,17 @@ public class AddComponentAction extends vtkSwtAction { public void doInsert(PositionType position) { try { + if (position == PositionType.SPLIT && length != null && length > component.getControlPoint().getLength()) { + MessageDialog.openError(panel.getComponent().getShell(), "Error", "There is no room for a component of length " + length * lengthFactor + " units"); + return; + } + InsertInstruction inst = new InsertInstruction(); inst.typeUri = toAdd.getUri(); inst.name = name; inst.angle = angle != null ? MathTools.degToRad(angle) : null; inst.diameter = diameter; + inst.thickness = thickness; inst.length = length; inst.turnRadius = turnRadius; inst.insertPosition = insertPosition;