]> gerrit.simantics Code Review - simantics/3d.git/blobdiff - org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/PipelineComponent.java
Allow multiple radii for turns.
[simantics/3d.git] / org.simantics.plant3d / src / org / simantics / plant3d / scenegraph / PipelineComponent.java
index d66869ea2069219be8c6dae03e2ec378d235f40d..c0feb668d183ff090dad98fa81ed844cce02ab0b 100644 (file)
@@ -1,15 +1,21 @@
 package org.simantics.plant3d.scenegraph;
 
 import java.util.Collections;
+import java.util.HashMap;
 import java.util.Map;
+import java.util.Map.Entry;
 
 import javax.vecmath.Quat4d;
 import javax.vecmath.Tuple3d;
 import javax.vecmath.Vector3d;
 
 import org.simantics.g3d.math.MathTools;
+import org.simantics.g3d.property.annotations.CompoundGetPropertyValue;
+import org.simantics.g3d.property.annotations.CompoundSetPropertyValue;
 import org.simantics.g3d.property.annotations.GetPropertyValue;
 import org.simantics.g3d.property.annotations.PropertyContributor;
+import org.simantics.objmap.graph.annotations.CompoundRelatedGetValue;
+import org.simantics.objmap.graph.annotations.CompoundRelatedSetValue;
 import org.simantics.objmap.graph.annotations.RelatedGetObj;
 import org.simantics.objmap.graph.annotations.RelatedSetObj;
 import org.simantics.plant3d.ontology.Plant3D;
@@ -26,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;
@@ -83,6 +91,38 @@ public abstract class PipelineComponent extends GeometryNode {
                super.updateParameters();
        }
        
+       @Override
+    @CompoundRelatedGetValue(objRelation=Plant3D.URIs.hasParameter,objType=Plant3D.URIs.Parameter,valRelation=Plant3D.URIs.hasParameterValue)
+    public Map<String, Object> getParameterMap() {
+        return super.getParameterMap();
+    }
+       
+    @Override
+    @CompoundRelatedSetValue(Plant3D.URIs.hasParameter)
+    public void setParameterMap(Map<String, Object> parameters) {
+        super.setParameterMap(parameters);
+    }
+    
+    @CompoundGetPropertyValue(name="Parameters",tabId="Parameters",value="parameters")
+    public Map<String,Object> getParameterMapUI() {
+        // TODO : how to filter parameters that are calculated by geometry provider?
+        Map<String,Object> map = new HashMap<String, Object>(getParameterMap());
+        map.remove("radius");
+        map.remove("radius2");
+        map.remove("offset");
+        return map;
+    }
+    
+    @CompoundSetPropertyValue(value="parameters")
+    public void setParameterMapUI(Map<String, Object> parameters) { 
+        Map<String, Object> curr = getParameterMap();
+        for (Entry<String, Object> entry : curr.entrySet()) {
+            if (!parameters.containsKey(entry.getKey()))
+                parameters.put(entry.getKey(), entry.getValue());
+        }
+        setParameterMap(parameters);
+    }
+       
        public abstract void setType(String typeURI) throws Exception;
        
        @RelatedGetObj(Plant3D.URIs.HasNext)
@@ -98,11 +138,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);
+               
        }
        
        
@@ -119,11 +160,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;
        
@@ -140,11 +182,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)
@@ -224,14 +266,20 @@ public abstract class PipelineComponent extends GeometryNode {
                if (next == comp) {
                        next = null;
                        syncnext = false;
+                       if (DEBUG) System.out.println(this + " remove next " + comp);
+                       firePropertyChanged(Plant3D.URIs.HasNext);
                        syncNext();
                } else if (previous == comp) {
                        previous = null;
                        syncprev = false;
+                       if (DEBUG) System.out.println(this + " remove prev " + comp);
+                       firePropertyChanged(Plant3D.URIs.HasPrevious);
                        syncPrevious();
                } else if (branch0 == comp) {
                        branch0 = null;
                        syncbr0 = false;
+                       if (DEBUG) System.out.println(this + " remove br0 " + comp);
+                       firePropertyChanged(Plant3D.URIs.HasBranch0);
                        syncBranch0();
                }
        }
@@ -347,8 +395,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 {
@@ -381,6 +429,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) {
@@ -388,6 +437,15 @@ public abstract class PipelineComponent extends GeometryNode {
                }
                super.remove();
        }
+       
+       public void removeAndSplit() {
+           PipeControlPoint pcp = getControlPoint();
+        // Second check is needed, when remove process is initiated from control point.
+        if (pcp != null && pcp.getPipelineComponent() != null) {
+            pcp.removeAndSplit();
+        }
+        super.remove();
+       }
 
        @Override
        protected double[] getColor() {
@@ -409,12 +467,7 @@ public abstract class PipelineComponent extends GeometryNode {
                super.setOrientation(orientation);
                if (getControlPoint() != null) {
                        getControlPoint()._setWorldOrientation(getWorldOrientation());
-                       try {
-                               PipingRules.requestUpdate(getControlPoint());
-                       } catch (Exception e) {
-                               // TODO Auto-generated catch block
-                               e.printStackTrace();
-                       }       
+                       PipingRules.requestUpdate(getControlPoint());
                }
        }
        
@@ -425,12 +478,7 @@ public abstract class PipelineComponent extends GeometryNode {
                super.setPosition(position);
                if (getControlPoint() != null) {
                        getControlPoint()._setWorldPosition(getWorldPosition());
-                       try {
-                               PipingRules.requestUpdate(getControlPoint());
-                       } catch (Exception e) {
-                               // TODO Auto-generated catch block
-                               e.printStackTrace();
-                       }
+                       PipingRules.requestUpdate(getControlPoint());
                }
        }
        
@@ -456,7 +504,7 @@ public abstract class PipelineComponent extends GeometryNode {
                        case END:
                                return null;
                        case TURN: {
-                               double r = getPipeRun().getTurnRadius();
+                               double r = ((TurnComponent)this).getTurnRadius();
                                double a = pcp.getTurnAngle();
                                return a*r;
                        }
@@ -465,6 +513,24 @@ public abstract class PipelineComponent extends GeometryNode {
                }
        }
        
+       /**
+        * Returns diameter of the pipe
+        * @return
+        */
+       public Double getDiameter() {
+           return getPipeRun().getPipeDiameter();
+       }
+       
+       /**
+        * Returns secondary diameter of the pipe for size change components
+        * @return
+        */
+       public Double getDiameter2() {
+           if (getAlternativePipeRun() == null)
+               return null;
+           return getAlternativePipeRun().getPipeDiameter();
+       }
+       
        public void getEnds(Tuple3d p1, Tuple3d p2) {
                getControlPoint().getControlPointEnds(p1, p2);
        }
@@ -516,7 +582,7 @@ public abstract class PipelineComponent extends GeometryNode {
                case TURN: {
                        Vector3d loc = pcp.getRealPosition(PositionType.PREVIOUS);
                        
-                       double r = getPipeRun().getTurnRadius();
+                       double r = ((TurnComponent)this).getTurnRadius();
                        double a = pcp.getTurnAngle();
                        double pipeRadius = pcp.getPipeRun().getPipeDiameter() / 2;
                        
@@ -573,7 +639,7 @@ public abstract class PipelineComponent extends GeometryNode {
                        double r2 = getAlternativePipeRun().getPipeDiameter() / 2;
                        return pcp.getLength() * Math.PI * (r1*r1 + r1*r2 + r2*r2) / 4;
                case TURN: {
-                       double r = getPipeRun().getTurnRadius();
+                       double r = ((TurnComponent)this).getTurnRadius();
                        double a = pcp.getTurnAngle();
                        return r * a * Math.PI * pipeRadius * pipeRadius;
                }