]> gerrit.simantics Code Review - simantics/3d.git/blobdiff - org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/controlpoint/PipeControlPoint.java
Remove/Split action removes pipeline components without reconnecting
[simantics/3d.git] / org.simantics.plant3d / src / org / simantics / plant3d / scenegraph / controlpoint / PipeControlPoint.java
index 93186779e60d580aa31d23a95585ce4886ff9f7b..daab2d111b234d2da42a16f78671a543a9f23607 100644 (file)
@@ -16,6 +16,8 @@ import org.simantics.g3d.math.MathTools;
 import org.simantics.g3d.property.annotations.GetPropertyValue;
 import org.simantics.g3d.scenegraph.G3DNode;
 import org.simantics.plant3d.scenegraph.IP3DNode;
+import org.simantics.plant3d.scenegraph.Nozzle;
+import org.simantics.plant3d.scenegraph.P3DRootNode;
 import org.simantics.plant3d.scenegraph.PipeRun;
 import org.simantics.plant3d.scenegraph.PipelineComponent;
 
@@ -938,8 +940,12 @@ public class PipeControlPoint extends G3DNode implements IP3DNode {
                        }
                }
        }
-
+       
        public void _remove() {
+           _remove(true);
+       }
+
+       public void _remove(boolean renconnect) {
                if (component == null && next == null && previous == null)
                        return;
                if (isDualInline() || isDualSub()) {
@@ -964,7 +970,7 @@ public class PipeControlPoint extends G3DNode implements IP3DNode {
                                return;
                        }
                        if (currentNext != null && currentPrev != null) {
-                               boolean link = true;
+                               boolean link = renconnect;
                                if (currentNext.isBranchEnd()) {
                                        link = false;
                                        //                                      currentNext.setPrevious(null);
@@ -1125,6 +1131,41 @@ public class PipeControlPoint extends G3DNode implements IP3DNode {
                        e.printStackTrace();
                }
        }
+       
+       public void removeAndSplit() {
+        PipeControlPoint currentPrev = previous;
+        PipeControlPoint currentNext = next;
+        
+        if (next != null && previous != null) {
+            P3DRootNode root = (P3DRootNode)getPipelineComponent().getRootNode();
+            PipeRun nextPipeRun = new PipeRun();
+            nextPipeRun.setName(root.getUniqueName("PipeRun"));
+            root.addChild(nextPipeRun);
+            
+            PipeRun previousRun = previous.getPipeRun();
+            nextPipeRun.setPipeDiameter(previousRun.getPipeDiameter());
+            nextPipeRun.setTurnRadius(previousRun.getTurnRadius());
+            
+            PipelineComponent n = next.getPipelineComponent();
+            while (n != null) {
+                if (! (n instanceof Nozzle)) {
+                    n.deattach();
+                    nextPipeRun.addChild(n);
+                } else
+                    n.setPipeRun(nextPipeRun);
+                n = n.getNext();
+            }
+        }
+        _remove(false);
+        try {
+            if (currentNext != null)
+                PipingRules.requestUpdate(currentNext);
+            if (currentPrev != null)
+                PipingRules.requestUpdate(currentPrev);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
 
        private void checkRemove(PipeRun pipeRun) {
                Collection<PipeControlPoint> points = pipeRun.getControlPoints();