X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=org.simantics.plant3d%2Fsrc%2Forg%2Fsimantics%2Fplant3d%2Factions%2FAddComponentAction.java;h=f87e63f70aa216639bc947d8e3dc9f5bf3f53f09;hb=refs%2Fchanges%2F87%2F4287%2F1;hp=0ee0f6bc2bbcfbf137148357f50f47e70edba792;hpb=9029e681fb0c47e9041c5527b966a247b23029b3;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 0ee0f6bc..f87e63f7 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; @@ -51,6 +52,7 @@ public class AddComponentAction extends vtkSwtAction { private String libUri; private double lengthFactor = 1.0; + private String lengthUnit = "m"; public AddComponentAction(InteractiveVtkComposite panel, P3DRootNode root, String libUri) { super(panel); @@ -66,6 +68,10 @@ public class AddComponentAction extends vtkSwtAction { this.lengthFactor = lengthFactor; } + public void setLengthUnit(String lengthUnit) { + this.lengthUnit = lengthUnit; + } + public void setComponent(PipelineComponent component) { this.component = component; @@ -75,13 +81,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); } } @@ -94,6 +100,7 @@ public class AddComponentAction extends vtkSwtAction { private Double angle; private Double rotationAngle; private Double diameter; + private Double thickness; private Double turnRadius; @Override @@ -104,6 +111,7 @@ public class AddComponentAction extends vtkSwtAction { // Set list of already reserved component names dialog.addUsedNames(ComponentUtils.getPipelineComponentNames(root)); dialog.setLengthFactor(lengthFactor); + dialog.setLengthUnit(lengthUnit); if (dialog.open() == ComponentSelectionDialog.CANCEL) return; @@ -118,6 +126,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); @@ -187,22 +196,39 @@ 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; inst.rotationAngle = rotationAngle; inst.position = position; - ComponentUtils.addComponent(root, component, inst); + PipelineComponent newComponent = ComponentUtils.addComponent(root, component, inst); + componentAdded(newComponent); } catch (Exception e) { ExceptionUtils.logAndShowError("Cannot add component", e); } } + /** + * This method does nothing, but can be overridden by a subclass to do additional + * post-processing for a newly added component. + * + * @param newComponent A newly added pipeline component + */ + protected void componentAdded(PipelineComponent newComponent) { + // Nothing to do here + } + public boolean mouseClicked(MouseEvent e) { if (e.getClickCount() == 1 && e.getButton() == MouseEvent.BUTTON1) { int type = panel.getPickType();