]> gerrit.simantics Code Review - simantics/3d.git/blobdiff - org.simantics.plant3d/src/org/simantics/plant3d/actions/AddComponentAction.java
Simplified free ended variable length component update
[simantics/3d.git] / org.simantics.plant3d / src / org / simantics / plant3d / actions / AddComponentAction.java
index 60f95215250409cfb382c42474e1926f857fd417..174d6f1166eac0718aa4aa814bb491b34ae67c66 100644 (file)
@@ -45,6 +45,9 @@ public class AddComponentAction extends vtkSwtAction {
        private Set<PositionType> allowed = new HashSet<PositionType>();
        
        private Item toAdd = null;
+       private PositionType insertPosition;
+       private boolean insertAdjustable;
+       private boolean lengthAdjustable;
        
        public AddComponentAction(InteractiveVtkComposite panel, P3DRootNode root) {
                super(panel);
@@ -84,12 +87,16 @@ public class AddComponentAction extends vtkSwtAction {
        
        @Override
        public void run() {
-               ComponentSelectionDialog dialog = new ComponentSelectionDialog(Display.getCurrent().getActiveShell(), allowed);
+           
+               ComponentSelectionDialog dialog = new ComponentSelectionDialog(Display.getCurrent().getActiveShell(), allowed, component);
                if (dialog.open() == ComponentSelectionDialog.CANCEL)
                        return;
                toAdd = dialog.getSelected();
                if (toAdd == null)
                        return;
+               this.insertPosition = dialog.getInsertPosition();
+               this.insertAdjustable = dialog.isInsertAdjustable();
+               this.lengthAdjustable = dialog.isLenghtAdjustable();
                this.length = dialog.getLength();
                this.angle = dialog.getAngle();
                this.diameter = dialog.getDiameter();
@@ -188,16 +195,31 @@ public class AddComponentAction extends vtkSwtAction {
                    dir = new Vector3d();
                    toPcp.getInlineControlPointEnds(start, end, dir);
                    dir.normalize();
-                   switch (position) {
-                case NEXT:
-                    pos = new Vector3d(end);
-                    break;
-                case PREVIOUS:
-                    pos = new Vector3d(start);
-                    break;
-                case SPLIT:
-                    break;
-                }
+                   if (!insertAdjustable || insertPosition == PositionType.NEXT) {
+                   switch (position) {
+                    case NEXT:
+                        pos = new Vector3d(end);
+                        break;
+                    case PREVIOUS:
+                        pos = new Vector3d(start);
+                        break;
+                    case SPLIT:
+                        break;
+                    }
+                   } else if (insertPosition == PositionType.SPLIT) {
+                       pos = new Vector3d(toPcp.getWorldPosition());
+                   } else {
+                       switch (position) {
+                    case NEXT:
+                        pos = new Vector3d(start);
+                        break;
+                    case PREVIOUS:
+                        pos = new Vector3d(end);
+                        break;
+                    case SPLIT:
+                        break;
+                    }
+                   }
                   
                        } else if (toPcp.isDirected()) {
                            dir = new Vector3d(toPcp.getDirection(Direction.NEXT));
@@ -205,9 +227,22 @@ public class AddComponentAction extends vtkSwtAction {
                        } else if (toPcp.isTurn() && toPcp.isFixed()) {
                            dir = new Vector3d(toPcp.getDirection(position == PositionType.NEXT ? Direction.NEXT : Direction.PREVIOUS));
                 pos = new Vector3d(toPcp.getWorldPosition());
-                Vector3d v = new Vector3d(dir);
-                v.scale(toPcp.getInlineLength());
-                pos.add(v);
+                if (!lengthAdjustable) {
+                    Vector3d v = new Vector3d(dir);
+                    v.scale(toPcp.getInlineLength());
+                    pos.add(v);
+                } else {
+                    if (insertPosition == PositionType.NEXT) {
+                        Vector3d v = new Vector3d(dir);
+                        v.scale(toPcp.getInlineLength());
+                        pos.add(v);
+                    } else if (insertPosition == PositionType.SPLIT) {
+                        // scale 0.5*length so that we don't remove the length twice from the new component
+                        Vector3d v = new Vector3d(dir);
+                        v.scale(toPcp.getInlineLength()*0.5);  
+                        pos.add(v);
+                    }
+                }
                        }
                        
                        
@@ -229,7 +264,16 @@ public class AddComponentAction extends vtkSwtAction {
                                newComponent.updateParameters();
                                
                            Vector3d v = new Vector3d(dir);
-                v.scale(newComponent.getControlPoint().getInlineLength());
+                           if (insertAdjustable) {
+                           if (insertPosition == PositionType.NEXT)
+                               v.scale(newComponent.getControlPoint().getInlineLength());
+                           else if (insertPosition == PositionType.SPLIT)
+                               v.set(0, 0, 0);
+                           else if (insertPosition == PositionType.PREVIOUS)
+                               v.scale(-newComponent.getControlPoint().getInlineLength());
+                           } else {
+                               v.scale(newComponent.getControlPoint().getInlineLength());
+                           }
                 switch (position) {
                 case NEXT:
                     pos.add(v);