]> gerrit.simantics Code Review - simantics/3d.git/blobdiff - org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/PipelineComponent.java
Remove listener calls when property values not updated.
[simantics/3d.git] / org.simantics.plant3d / src / org / simantics / plant3d / scenegraph / PipelineComponent.java
index 61e48585336fb7749ba30c021fd42f549f40a027..f0621fdd2ce7f76dad1490963b62ba73583065a1 100644 (file)
@@ -4,6 +4,7 @@ import java.util.Collections;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.Map.Entry;
+import java.util.Objects;
 
 import javax.vecmath.Quat4d;
 import javax.vecmath.Tuple3d;
@@ -145,8 +146,10 @@ public abstract class PipelineComponent extends GeometryNode {
        
        @RelatedSetObj(Plant3D.URIs.HasNext)
        public void setNext(PipelineComponent comp) {
-               if (next == comp)
+               if (next == comp) {
+                   syncNext();
                    return;
+               }
                if (this.next != null)
                    this.next._removeRef(this);
         _setNext(comp);
@@ -170,8 +173,10 @@ public abstract class PipelineComponent extends GeometryNode {
        
        @RelatedSetObj(Plant3D.URIs.HasPrevious)
        public void setPrevious(PipelineComponent comp) {
-               if (previous == comp)
+               if (previous == comp) {
+                   syncPrevious();
                        return;
+               }
                if (this.previous != null)
                        this.previous._removeRef(this);
                _setPrevious(comp);
@@ -196,8 +201,10 @@ public abstract class PipelineComponent extends GeometryNode {
        
        @RelatedSetObj(Plant3D.URIs.HasBranch0)
        public void setBranch0(PipelineComponent comp) {
-               if (branch0 == comp)
+               if (branch0 == comp) {
+                   syncBranch0();
                        return;
+               }
                if (this.branch0 != null)
                        this.branch0._removeRef(this);
                this.branch0 = comp;
@@ -305,7 +312,7 @@ public abstract class PipelineComponent extends GeometryNode {
        }
        
        boolean syncnext = false;
-       private void syncNext() {
+       protected void syncNext() {
                if (syncnext)
                        return;
                syncnext = _syncNext();
@@ -344,7 +351,7 @@ public abstract class PipelineComponent extends GeometryNode {
        }
        
        boolean syncprev = false;
-       private void syncPrevious() {
+       protected void syncPrevious() {
                if (syncprev)
                        return;
                syncprev = _syncPrevious();
@@ -381,7 +388,7 @@ public abstract class PipelineComponent extends GeometryNode {
        }
        
        boolean syncbr0 = false;
-       private void syncBranch0() {
+       protected void syncBranch0() {
                if (syncbr0)
                        return;
                syncbr0 = _syncBranch0();
@@ -453,10 +460,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();
@@ -464,6 +505,7 @@ public abstract class PipelineComponent extends GeometryNode {
         if (pcp != null && pcp.getPipelineComponent() != null) {
             pcp.removeAndSplit();
         }
+        setPipeRun(null);
         super.remove();
        }
 
@@ -667,4 +709,29 @@ public abstract class PipelineComponent extends GeometryNode {
                        throw new IllegalStateException("No centroid defined");
                }
        }
+       
+       
+       private String error;
+       
+       /**
+        * Returns possible pipe modelling error, or null;
+        * @return
+        */
+       @GetPropertyValue(name="Error", value="error", tabId = "Default")
+       public String getError() {
+           return error;
+       }
+       
+       /**
+        * Sets pipe modelling error. 
+        * 
+        * Error is usually set by PipingRules.
+        * @param error
+        */
+       public void setError(String error) {
+           if (Objects.equals(this.error,  error))
+               return;
+           this.error = error;
+           firePropertyChanged("error");
+       }
 }