X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=org.simantics.plant3d%2Fsrc%2Forg%2Fsimantics%2Fplant3d%2Factions%2FAddComponentAction.java;h=9b3d90835e14a3961f5c9af0c48fd7ead86417dc;hb=refs%2Fchanges%2F60%2F3960%2F1;hp=ea25230ab57c745bbe8e229e648d5604c293d4a7;hpb=8792531e8f0967aee36cdd405ec0cd3a34f9ab06;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 ea25230a..9b3d9083 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,8 @@ 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; import org.simantics.g3d.math.MathTools; @@ -49,16 +51,22 @@ 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; setText("Add Component"); - setImageDescriptor(Activator.imageDescriptorFromPlugin(Activator.PLUGIN_ID, "icons/Component.png")); + setImageDescriptor(ResourceLocator.imageDescriptorFromBundle(Activator.PLUGIN_ID, "icons/Component.png").get()); nodeMap = root.getNodeMap(); gizmo = new TerminalSelectionGizmo(panel); this.libUri = libUri; } + public void setLengthFactor(double lengthFactor) { + this.lengthFactor = lengthFactor; + } + public void setComponent(PipelineComponent component) { this.component = component; @@ -81,6 +89,8 @@ public class AddComponentAction extends vtkSwtAction { setEnabled(allowed.size() > 0); } + private String name; + private Double length; private Double angle; private Double rotationAngle; @@ -91,11 +101,17 @@ public class AddComponentAction extends vtkSwtAction { public void run() { ComponentSelectionDialog dialog = new ComponentSelectionDialog(Display.getCurrent().getActiveShell(), allowed, component, libUri); + + // Set list of already reserved component names + dialog.addUsedNames(ComponentUtils.getPipelineComponentNames(root)); + dialog.setLengthFactor(lengthFactor); + if (dialog.open() == ComponentSelectionDialog.CANCEL) return; toAdd = dialog.getSelected(); if (toAdd == null) return; + this.name = dialog.getName(); this.insertPosition = dialog.getInsertPosition(); this.insertAdjustable = dialog.isInsertAdjustable(); this.lengthAdjustable = dialog.isLenghtAdjustable(); @@ -172,8 +188,14 @@ 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.length = length;