]> gerrit.simantics Code Review - simantics/3d.git/blobdiff - org.simantics.plant3d/src/org/simantics/plant3d/actions/RoutePipeAction.java
Fixed variable angle turns when they are not connected
[simantics/3d.git] / org.simantics.plant3d / src / org / simantics / plant3d / actions / RoutePipeAction.java
index 5c787037daed939790c0d8030942b9e1e5ea3aa9..dac9d2c11b004c428a5103116db1fd8c88eed920 100644 (file)
@@ -13,6 +13,7 @@ import javax.vecmath.Point3d;
 import javax.vecmath.Tuple3d;
 import javax.vecmath.Vector3d;
 
+import org.simantics.db.Resource;
 import org.simantics.g3d.math.MathTools;
 import org.simantics.g3d.math.Ray;
 import org.simantics.g3d.scenegraph.NodeMap;
@@ -57,24 +58,25 @@ public class RoutePipeAction extends vtkSwtAction {
        private int decimals = 2;
 
        private P3DRootNode root;
-       private PipelineComponent startComponent;
-       private PipeRun pipeRun;
+       protected PipelineComponent startComponent;
+       protected PipeRun pipeRun;
+       private boolean allowBranches;
 
-       private TranslateAxisGizmo translateAxisGizmo = new TranslateAxisGizmo();
+       protected TranslateAxisGizmo translateAxisGizmo = new TranslateAxisGizmo();
        private SplitPointSelectionGizmo splitPointSelectionGizmo;
        private ConstraintPointGizmo constraintPointGizmo;
        private TerminalSelectionGizmo terminalSelectionGizmo;
-       private NodeMap<vtkProp,INode> nodeMap;
+       private NodeMap<Resource,vtkProp,INode> nodeMap;
        
-       private enum ToolState{NOT_ACTIVE, INITIALIZING, SELECTING_POSITION, SELECTING_SPLIT, ROUTING};
-       private ToolState state = ToolState.NOT_ACTIVE;
+       protected enum ToolState{NOT_ACTIVE, INITIALIZING, SELECTING_POSITION, SELECTING_SPLIT, ROUTING};
+       protected ToolState state = ToolState.NOT_ACTIVE;
        
        private ConstraintDetector detector;// = new DummyConstraintDetector();
        
-       private boolean useDefault = false;
-       private Vector3d direction = null;
-       private Vector3d previousPosition = null;
-       private Vector3d currentPosition = null;
+       protected boolean useDefault = false;
+       protected Vector3d direction = null;
+       protected Vector3d previousPosition = null;
+       protected Vector3d currentPosition = null;
        
        boolean step = false;
        
@@ -86,10 +88,14 @@ public class RoutePipeAction extends vtkSwtAction {
        
        private Set<PositionType> allowed = new HashSet<PositionType>();
        
-       
        public RoutePipeAction(InteractiveVtkComposite panel, P3DRootNode root) {
+           this(panel,root, true);
+       }
+       
+       public RoutePipeAction(InteractiveVtkComposite panel, P3DRootNode root, boolean allowBranches) {
                super(panel);
                this.root = root;
+               this.allowBranches = allowBranches;
                setText("Route Pipe");
                setImageDescriptor(Activator.imageDescriptorFromPlugin(Activator.PLUGIN_ID, "icons/Straight.png"));
                nodeMap = root.getNodeMap();
@@ -106,7 +112,7 @@ public class RoutePipeAction extends vtkSwtAction {
                        allowed.add(PositionType.NEXT);
                if (this.startComponent.getPrevious() == null && !(this.startComponent instanceof Nozzle))
                        allowed.add(PositionType.PREVIOUS);
-               if (this.startComponent instanceof InlineComponent && !this.startComponent.getControlPoint().isFixed())
+               if (allowBranches && this.startComponent instanceof InlineComponent && !this.startComponent.getControlPoint().isFixedLength())
                        allowed.add(PositionType.SPLIT);
                setEnabled(allowed.size() > 0);
        }
@@ -114,7 +120,7 @@ public class RoutePipeAction extends vtkSwtAction {
        public void deattach() {
                deactivate();
                startComponent = null;
-               nodeMap.commit("Route pipe");
+               
                deattachUI();
                super.deattach();
                panel.refresh();
@@ -164,7 +170,7 @@ public class RoutePipeAction extends vtkSwtAction {
                panel.unlock();
        }
        
-       private List<PipelineComponent> added = new ArrayList<PipelineComponent>();
+       protected List<PipelineComponent> added = new ArrayList<PipelineComponent>();
        
        @Override
        public boolean keyPressed(KeyEvent e) {
@@ -255,7 +261,7 @@ public class RoutePipeAction extends vtkSwtAction {
        
        boolean startRemovable = false;
        
-       private void activate() throws Exception {
+       protected void activate() throws Exception {
                state = ToolState.INITIALIZING;
                added.clear();
                
@@ -291,7 +297,7 @@ public class RoutePipeAction extends vtkSwtAction {
        
        
        
-       private void activateNextPrev(PipeControlPoint start) throws Exception{
+       protected void activateNextPrev(PipeControlPoint start) throws Exception{
                if (!reversed && start.isDualInline())
                        start = start.getSubPoint().get(0);
                else if (reversed && start.isDualSub())
@@ -320,7 +326,7 @@ public class RoutePipeAction extends vtkSwtAction {
                                        start.getControlPointEnds(previousPosition,v);
                                }
                        } else if (startComponent instanceof TurnComponent) {
-                               if (start.isFixed()) {
+                               if (start.asFixedAngle()) {
                                        direction = startComponent.getControlPoint().getPathLegDirection(reversed ? Direction.PREVIOUS : Direction.NEXT);
                                        lock = LockType.CUSTOM;
                                } else {
@@ -367,7 +373,7 @@ public class RoutePipeAction extends vtkSwtAction {
                updateCurrentPoint();
        }
        
-       private void setPreviousPosition(Vector3d v) {
+       protected void setPreviousPosition(Vector3d v) {
                previousPosition = new Vector3d(v);
                if (translateAxisGizmo.isAttached())
                        translateAxisGizmo.setPosition(previousPosition);
@@ -422,11 +428,23 @@ public class RoutePipeAction extends vtkSwtAction {
                state = ToolState.SELECTING_SPLIT;
        }
        public void deactivate() {
-               for (PipelineComponent component : added) {
-                       component.getControlPoint().setDeletable(true);
-               }
+           if (added.size() > 0) {
+           for (PipelineComponent component : added) {
+                       component.getControlPoint().setDeletable(true);
+               }
+               
+            for (PipelineComponent comp : added) {
+                PipingRules.requestUpdate(comp.getControlPoint());
+            }
+            try {
+                PipingRules.update();
+                nodeMap.commit("Route pipe");
+            } catch (Exception e) {
+                ExceptionUtils.logAndShowError(e);
+            }
+            added.clear();        
+        }
                
-               added.clear();
                startComponent.getControlPoint().setDeletable(startRemovable);
 
                direction = null;
@@ -523,7 +541,7 @@ public class RoutePipeAction extends vtkSwtAction {
                                                                addPoint();
                                                        }
                                                } else {
-                                                       throw new RuntimeException("kjf");
+                                                       throw new RuntimeException("RoutePipeAction initlialization has been failed, no added components found");
                //                      // user was selecting position of branch
                //                    lastPoint.set(startPoint);
                //                    controlPoints.add(new Point3d(startPoint));
@@ -665,16 +683,7 @@ public class RoutePipeAction extends vtkSwtAction {
        
        INode hoverObject = null;
 
-       private void updateRouting(double x, double y) {
-//             if(input.keyPressed(KeyEvent.VK_ESCAPE)) {
-//                     controlPoints.clear();
-//                     end();
-//                     return;
-//             }
-//             if (input.keyPressed(KeyEvent.VK_C)) {
-//                     useCamera = !useCamera;
-//                     cameraAction.setChecked(useCamera);
-//             }
+       protected void updateRouting(double x, double y) {
                if (useDefault) {
                        //panel.getDefaultAction().update();
                        return;
@@ -756,7 +765,7 @@ public class RoutePipeAction extends vtkSwtAction {
                panel.refresh();
        }
        
-       private boolean updateCurrentPoint(Vector3d o, Vector3d d) {
+       protected boolean updateCurrentPoint(Vector3d o, Vector3d d) {
 
                Vector3d point = new Vector3d(this.previousPosition);
                
@@ -828,7 +837,7 @@ public class RoutePipeAction extends vtkSwtAction {
                return null;
        }
        
-       private void updateRoute(Vector3d o, Vector3d d) {
+       protected void updateRoute(Vector3d o, Vector3d d) {
                detector.clearConstraintHighlights();
                Point3d previousPipePoint = new Point3d(previousPosition);
                String s = "";
@@ -915,6 +924,10 @@ public class RoutePipeAction extends vtkSwtAction {
        }
        
        private PositionType endingToStraight(INode straightNode, double mu[], Vector3d o, Vector3d d) {
+           if (!allowBranches) {
+               updateCurrentPoint();
+            return null;
+           }
                InlineComponent s = (InlineComponent)straightNode;
                String info = "";
                Point3d sStart = new Point3d();
@@ -1034,6 +1047,10 @@ public class RoutePipeAction extends vtkSwtAction {
        }
        
        private PositionType endingLockToStraight(INode straightNode, double mu[]) {
+           if (!allowBranches) {
+            updateCurrentPoint();
+            return null;
+        }
                InlineComponent s = (InlineComponent)straightNode;
                Point3d sStart = new Point3d();
                Point3d sEnd = new Point3d(); 
@@ -1088,7 +1105,7 @@ public class RoutePipeAction extends vtkSwtAction {
                return null;
        }
        
-       private void addPoint() throws Exception {
+       protected void addPoint() throws Exception {
                InlineComponent previous = (InlineComponent)getLast();
                PipeControlPoint previousCP = previous.getControlPoint();
                TurnComponent turn = ComponentUtils.createTurn(root);
@@ -1132,7 +1149,7 @@ public class RoutePipeAction extends vtkSwtAction {
        /**
         * Updates tool graphics for current point 
         */
-       private void updateCurrentPoint() {
+       protected void updateCurrentPoint() {
                InlineComponent straight = (InlineComponent)added.get(added.size()-1);
                // TODO: the inline length is from previous update step.
                double l;
@@ -1185,7 +1202,7 @@ public class RoutePipeAction extends vtkSwtAction {
                
        }
        
-       private void endPiping() throws Exception {
+       protected void endPiping() throws Exception {
                state = ToolState.NOT_ACTIVE;
                
                if (endTo != null) {