]> gerrit.simantics Code Review - simantics/3d.git/blobdiff - org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/PipelineComponent.java
Allow unsplitting removal of reducers by joining pipe runs
[simantics/3d.git] / org.simantics.plant3d / src / org / simantics / plant3d / scenegraph / PipelineComponent.java
index e1a24f10369024c61a29a1b3d1e8e525039cac3f..d3ded1efe7b0fe1217fd706844555ea219b4a8ea 100644 (file)
@@ -459,11 +459,44 @@ public abstract class PipelineComponent extends GeometryNode {
                PipeControlPoint pcp = getControlPoint();
                // Second check is needed, when remove process is initiated from control point.
                if (pcp != null && pcp.getPipelineComponent() != null) {
+                       if (pcp.isSizeChange()) {
+                               mergeWithAlternative();
+                       }
+                       
                        pcp.remove();
                }
+               
                setPipeRun(null);
                super.remove();
        }
+
+       private void mergeWithAlternative() {
+               PipeRun run = getPipeRun();
+               PipeRun alternative = getAlternativePipeRun();
+               if (alternative != null) {
+                       // Move components from alternative pipe run to main run
+                       PipelineComponent p = getNext();
+                       while (p != null && p.getPipeRun() == alternative) {
+                               if (p.getParent() == alternative) {
+                                       p.deattach(); // For components
+                                       run.addChild(p);
+                               }
+                               else {
+                                       p.setPipeRun(run); // For nozzles
+                               }
+
+                               p.updateParameters();
+                               PipingRules.requestUpdate(p.getControlPoint());
+                               
+                               p = p.getNext();
+                       }
+                       
+                       setAlternativePipeRun(run);
+                       
+                       if (alternative.getChild().isEmpty())
+                               alternative.remove();
+               }
+       }
        
        public void removeAndSplit() {
            PipeControlPoint pcp = getControlPoint();