]> gerrit.simantics Code Review - simantics/3d.git/blobdiff - org.simantics.plant3d/src/org/simantics/plant3d/actions/AddComponentAction.java
Added a length scaling factor for adding components
[simantics/3d.git] / org.simantics.plant3d / src / org / simantics / plant3d / actions / AddComponentAction.java
index d4cf03073d20214baafd5303d8ac06dfdb963a9f..0ee0f6bc2bbcfbf137148357f50f47e70edba792 100644 (file)
@@ -6,8 +6,10 @@ import java.awt.event.MouseWheelEvent;
 import java.util.HashSet;
 import java.util.Set;
 
+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;
@@ -41,21 +43,29 @@ 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;
+       
        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;
                
@@ -71,15 +81,18 @@ public class AddComponentAction extends vtkSwtAction {
                        if (component.getPrevious() == null) {
                                allowed.add(PositionType.PREVIOUS);
                        }
-                       if (component instanceof InlineComponent && !component.getControlPoint().isFixed()){
+                       if (component instanceof InlineComponent && !component.getControlPoint().isFixedLength()){
                                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 turnRadius;
        
@@ -87,16 +100,23 @@ 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();
                this.length = dialog.getLength();
                this.angle = dialog.getAngle();
+               this.rotationAngle = dialog.getRotationAngle();
                this.diameter = dialog.getDiameter();
                this.turnRadius = dialog.getTurnRadius();
                allowed = dialog.filterAllowed();
@@ -169,11 +189,13 @@ public class AddComponentAction extends vtkSwtAction {
                try  {
                        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.length = length;
                        inst.turnRadius = turnRadius;
                        inst.insertPosition = insertPosition;
+                       inst.rotationAngle = rotationAngle;
                        inst.position = position;
                        ComponentUtils.addComponent(root, component, inst);
                } catch (Exception e) {