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=a8e2da6aed4e09c8f1a336aac903b9a5acee2d53;hp=ba6721043d20f7e38c8f63d227e310ddc7591621;hpb=bdc6f4000e1d4c4cd3c8d4bbf1af16490d019692;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 ba672104..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,9 +6,11 @@ import java.awt.event.MouseWheelEvent; import java.util.HashSet; import java.util.Set; -import javax.vecmath.Vector3d; - +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; import org.simantics.g3d.scenegraph.NodeMap; import org.simantics.g3d.scenegraph.base.INode; import org.simantics.g3d.vtk.swt.InteractiveVtkComposite; @@ -19,16 +21,11 @@ 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; -import org.simantics.plant3d.scenegraph.controlpoint.PipeControlPoint; -import org.simantics.plant3d.scenegraph.controlpoint.PipeControlPoint.Direction; import org.simantics.plant3d.scenegraph.controlpoint.PipeControlPoint.PositionType; -import org.simantics.plant3d.scenegraph.controlpoint.PipingRules; import org.simantics.plant3d.utils.ComponentUtils; -import org.simantics.plant3d.utils.Item; import org.simantics.plant3d.utils.ComponentUtils.InsertInstruction; -import org.simantics.plant3d.utils.Item.Type; +import org.simantics.plant3d.utils.Item; import org.simantics.utils.threads.ThreadUtils; import org.simantics.utils.ui.ExceptionUtils; @@ -39,7 +36,7 @@ public class AddComponentAction extends vtkSwtAction { private P3DRootNode root; private PipelineComponent component; - private NodeMap nodeMap; + private NodeMap nodeMap; private TerminalSelectionGizmo gizmo; @@ -47,21 +44,34 @@ public class AddComponentAction extends vtkSwtAction { private Item toAdd = null; private PositionType insertPosition; + @SuppressWarnings("unused") private boolean insertAdjustable; + @SuppressWarnings("unused") private boolean lengthAdjustable; private String libUri; + private double lengthFactor = 1.0; + private String lengthUnit = "m"; + 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 setLengthUnit(String lengthUnit) { + this.lengthUnit = lengthUnit; + } + public void setComponent(PipelineComponent component) { this.component = component; @@ -71,39 +81,52 @@ 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().isFixed()){ + if (component instanceof InlineComponent && component.getControlPoint().isVariableLength()){ allowed.add(PositionType.SPLIT); } } setEnabled(allowed.size() > 0); } + private String name; + private Double length; private Double angle; + private Double rotationAngle; private Double diameter; + private Double thickness; private Double turnRadius; @Override 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); + dialog.setLengthUnit(lengthUnit); + 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(); this.length = dialog.getLength(); 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); @@ -173,20 +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.angle = angle; + 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();