]> gerrit.simantics Code Review - simantics/3d.git/commitdiff
Removing straight next to branch point did not properly remove branch 67/3367/1
authorMarko Luukkainen <marko.luukkainen@semantum.fi>
Fri, 18 Oct 2019 10:28:28 +0000 (13:28 +0300)
committerMarko Luukkainen <marko.luukkainen@semantum.fi>
Fri, 18 Oct 2019 10:28:28 +0000 (13:28 +0300)
gitlab #35

Change-Id: I7d5be95dc81bda7b1d7d72f1c26c298eb368c02e

org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/PipelineComponent.java
org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/controlpoint/PipeControlPoint.java

index fd085db11bb530f4007fbd1fabda812166a9c24b..28e4ad71f12951eb9237ef2b2514ae3c12047413 100644 (file)
@@ -32,6 +32,8 @@ import org.simantics.plant3d.scenegraph.controlpoint.PipingRules;
  */
 @PropertyContributor
 public abstract class PipelineComponent extends GeometryNode {
+    
+    private static boolean DEBUG = false;
 
        
        private PipeRun pipeRun;
@@ -135,11 +137,12 @@ public abstract class PipelineComponent extends GeometryNode {
                        this.next._removeRef(this);
                this.next = comp;
                this.syncnext = false;
+               if (DEBUG) System.out.println(this + " next " + comp);
                syncNext();
                firePropertyChanged(Plant3D.URIs.HasNext);
                if (comp != null)
                        comp.sync();
-//             System.out.println(this + " next " + comp);
+               
        }
        
        
@@ -156,11 +159,12 @@ public abstract class PipelineComponent extends GeometryNode {
                        this.previous._removeRef(this);
                this.previous = comp;
                this.syncprev = false;
+               if (DEBUG) System.out.println(this + " prev " + comp);
                syncPrevious();
                firePropertyChanged(Plant3D.URIs.HasPrevious);
                if (comp != null)
                        comp.sync();
-//             System.out.println(this + " prev " + comp);
+               
        }
        private PipelineComponent branch0;
        
@@ -177,11 +181,11 @@ public abstract class PipelineComponent extends GeometryNode {
                        this.branch0._removeRef(this);
                this.branch0 = comp;
                this.syncbr0 = false;
+               if (DEBUG) System.out.println(this + " br0 " + comp);
                syncBranch0();
                firePropertyChanged(Plant3D.URIs.HasBranch0);
                if (comp != null)
                        comp.sync();
-//             System.out.println(this + " next " + comp);
        }
 
        @GetPropertyValue(name="Previous",tabId="Debug",value=Plant3D.URIs.HasPrevious)
@@ -384,8 +388,8 @@ public abstract class PipelineComponent extends GeometryNode {
                                }
                                
                        } else if (getControlPoint().getSubPoint().size() > 0) { // TODO : this may cause problems? (Removes branch point, before branch has been set?)
-                               getControlPoint().getSubPoint().get(0).remove();
-                               getControlPoint().children.clear();
+                               //getControlPoint().getSubPoint().get(0).remove();
+                               //getControlPoint().children.clear();
                                return true;
                        }
                } else {
@@ -418,6 +422,7 @@ public abstract class PipelineComponent extends GeometryNode {
        
        @Override
        public void remove() {
+           if (DEBUG) System.out.println(this + " remove");
                PipeControlPoint pcp = getControlPoint();
                // Second check is needed, when remove process is initiated from control point.
                if (pcp != null && pcp.getPipelineComponent() != null) {
index daab2d111b234d2da42a16f78671a543a9f23607..b3bc2e1e09b757499e2adaccb819f2f3a0b5c006 100644 (file)
@@ -683,12 +683,12 @@ public class PipeControlPoint extends G3DNode implements IP3DNode {
                        } else {
                                if (previous == null) {
                                        if (!isDirected())
-                                               throw new RuntimeException("Cannot calculate path leg direction for unconnected control point");
+                                               throw new RuntimeException("Cannot calculate path leg direction for unconnected control point " + this);
                                        return getDirectedControlPointDirection();
 
                                } else {
                                        if (isVariableAngle())
-                                               throw new RuntimeException("Cannot calculate path leg direction for unconnected variable angle control point");
+                                               throw new RuntimeException("Cannot calculate path leg direction for unconnected variable angle control point " + this);
                                        if (isInline()) {
                                                PipeControlPoint pcp = this;
                                                if (pcp.isDualSub()) {
@@ -706,7 +706,7 @@ public class PipeControlPoint extends G3DNode implements IP3DNode {
                                        } else if (isTurn() && isFixed() && !_getReversed()) {
                                                return getDirection(Direction.NEXT);
                                        }
-                                       throw new RuntimeException("Missing implementation");
+                                       throw new RuntimeException("Missing implementation " + this);
                                }
                        }
                } else {
@@ -720,13 +720,13 @@ public class PipeControlPoint extends G3DNode implements IP3DNode {
                        } else {
                                if (next == null)  {
                                        if (!isDirected())
-                                               throw new RuntimeException("Cannot calculate path leg direction for unconnected control point");
+                                               throw new RuntimeException("Cannot calculate path leg direction for unconnected control point " + this);
                                        Vector3d v = getDirectedControlPointDirection();
                                        v.negate();
                                        return v;
                                } else {
                                        if (isVariableAngle())
-                                               throw new RuntimeException("Cannot calculate path leg direction for unconnected variable angle control point");
+                                               throw new RuntimeException("Cannot calculate path leg direction for unconnected variable angle control point " + this);
                                        if (isInline()) {
                                                PipeControlPoint pcp = this;
                                                if (pcp.isDualInline()) {
@@ -746,7 +746,7 @@ public class PipeControlPoint extends G3DNode implements IP3DNode {
                                        } else if (isTurn() && isFixed() && _getReversed()) {
                                                return getDirection(Direction.PREVIOUS);
                                        }
-                                       throw new RuntimeException("Missing implementation");
+                                       throw new RuntimeException("Missing implementation " + this);
                                }
                        }
                }
@@ -948,10 +948,14 @@ public class PipeControlPoint extends G3DNode implements IP3DNode {
        public void _remove(boolean renconnect) {
                if (component == null && next == null && previous == null)
                        return;
+               if (DEBUG) System.out.println(this + " Remove " + renconnect);
                if (isDualInline() || isDualSub()) {
                        removeDualPoint();
                        return;
                }
+               if (getParentPoint() != null) {
+                   getParentPoint()._remove(renconnect);
+               }
                PipeRun pipeRun = getPipeRun();
                if (pipeRun == null)
                        return;
@@ -1118,20 +1122,32 @@ public class PipeControlPoint extends G3DNode implements IP3DNode {
                        additionalRemove.remove();
        }
 
+       /**
+        * Removes control point and attempts to reconnect next/prev
+        * 
+        * If this point is size change (PipeRuns are different on both sides), then reconnection cannot be made.
+        */
        public void remove() {
                PipeControlPoint currentPrev = previous;
                PipeControlPoint currentNext = next;
                _remove();
                try {
                        if (currentNext != null)
-                               PipingRules.requestUpdate(currentNext);
+                           if (!currentNext.checkRemove())
+                               PipingRules.requestUpdate(currentNext);
                        if (currentPrev != null)
-                               PipingRules.requestUpdate(currentPrev);
+                           if (!currentPrev.checkRemove())
+                               PipingRules.requestUpdate(currentPrev);
                } catch (Exception e) {
                        e.printStackTrace();
                }
        }
        
+       
+       /**
+        * Removes control point without attempting to reconnect next/prev.
+        * This usually leads to creation of another PipeRun for the control points after this point. 
+        */
        public void removeAndSplit() {
         PipeControlPoint currentPrev = previous;
         PipeControlPoint currentNext = next;
@@ -1159,13 +1175,39 @@ public class PipeControlPoint extends G3DNode implements IP3DNode {
         _remove(false);
         try {
             if (currentNext != null)
-                PipingRules.requestUpdate(currentNext);
+                if (!currentNext.checkRemove())
+                    PipingRules.requestUpdate(currentNext);
             if (currentPrev != null)
-                PipingRules.requestUpdate(currentPrev);
+                if (!currentPrev.checkRemove())
+                    PipingRules.requestUpdate(currentPrev);
         } catch (Exception e) {
             e.printStackTrace();
         }
     }
+       
+       /**
+        * This is called when adjacent control point is removed.
+        * 
+        * This call should remove the give point, if the point cannot exist alone. 
+        * At the moment there is one such case: branch.
+        * 
+        * @return
+        */
+       protected boolean checkRemove() {
+           if (getParentPoint() != null) {
+               return getParentPoint().checkRemove();
+           } else {
+               if (getPipelineComponent() == null)
+                   return true; // already removed
+           if (getPipelineComponent().getType().equals("Plant3D.URIs.Builtin_BranchSplitComponent")) {
+               if (getSubPoint().get(0).getNext() == null && getSubPoint().get(0).getPrevious() == null) {
+                       remove();
+                       return true;
+               }
+           }
+            return false;
+           }
+    }
 
        private void checkRemove(PipeRun pipeRun) {
                Collection<PipeControlPoint> points = pipeRun.getControlPoints();