]> 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 7726b203005611c05b89a739b634617018f79295..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;
@@ -459,11 +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();
@@ -675,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");
+       }
 }