]> gerrit.simantics Code Review - simantics/3d.git/blobdiff - org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/InlineComponent.java
Handle fixed turn components when pipe run is reversed.
[simantics/3d.git] / org.simantics.plant3d / src / org / simantics / plant3d / scenegraph / InlineComponent.java
index 88b1fab3a29a6f8d5214d30fe4b46533914d1a64..fe30c29c3e2a7d82aca29bead0289ecac8ec9597 100644 (file)
@@ -3,19 +3,26 @@ package org.simantics.plant3d.scenegraph;
 import java.util.HashMap;
 import java.util.Map;
 
+import org.simantics.g3d.math.MathTools;
+import org.simantics.g3d.property.annotations.GetPropertyValue;
+import org.simantics.g3d.property.annotations.SetPropertyValue;
 import org.simantics.g3d.scenegraph.base.ParentNode;
 import org.simantics.objmap.graph.annotations.DynamicGraphType;
 import org.simantics.objmap.graph.annotations.GetType;
+import org.simantics.objmap.graph.annotations.RelatedGetValue;
+import org.simantics.objmap.graph.annotations.RelatedSetValue;
 import org.simantics.objmap.graph.annotations.SetType;
 import org.simantics.plant3d.ontology.Plant3D;
 import org.simantics.plant3d.scenegraph.controlpoint.ControlPointFactory;
 import org.simantics.plant3d.scenegraph.controlpoint.PipeControlPoint;
+import org.simantics.plant3d.scenegraph.controlpoint.PipingRules;
 
 @DynamicGraphType(Plant3D.URIs.InlineComponent)
 public class InlineComponent extends PipelineComponent {
 
        private String type;
        private PipeControlPoint controlPoint;
+       private boolean componentCalculatedOffset = false;
        
        @GetType(Plant3D.URIs.InlineComponent)
        public String getType() {
@@ -44,6 +51,67 @@ public class InlineComponent extends PipelineComponent {
                return !controlPoint.isFixed();
        }
        
+       public boolean isSizeChange() {
+           return controlPoint.isSizeChange();
+       }
+       
+       @RelatedGetValue(Plant3D.URIs.HasRotationAngle)
+       @GetPropertyValue(name="Rotation Angle", value=Plant3D.URIs.HasRotationAngle, tabId = "Default")
+       public Double getRotationAngle() {
+               if (!controlPoint.isRotate())
+                       return null;
+               Double d = controlPoint.getRotationAngle();
+               if (d == null)
+                       return 0.0;
+               return MathTools.radToDeg(d);
+       }
+       @RelatedSetValue(Plant3D.URIs.HasRotationAngle)
+       @SetPropertyValue(value=Plant3D.URIs.HasRotationAngle)
+       public void setRotationAngle(Double angle) {
+               if (!controlPoint.isRotate())
+                       return;
+               
+               if (angle == null || Double.isInfinite(angle) || Double.isNaN(angle)) {
+                       return;
+               }
+               angle = MathTools.degToRad(angle);
+               if (controlPoint.getRotationAngle() != null && Math.abs(controlPoint.getRotationAngle()-angle) < MathTools.NEAR_ZERO)
+                       return;
+               controlPoint.setRotationAngle(angle);
+               try {
+                       PipingRules.requestUpdate(getControlPoint());
+               } catch (Exception e) {
+                       // TODO Auto-generated catch block
+                       e.printStackTrace();
+               }       
+       }
+       
+       @RelatedGetValue(Plant3D.URIs.IsReversed)
+       @GetPropertyValue(name="Reverse", value=Plant3D.URIs.IsReversed, tabId = "Default")
+       public Boolean isReversed() {
+               if (!controlPoint.isReverse())
+                       return null;
+               Boolean d = controlPoint._getReversed();
+               return d;
+       }
+       @RelatedSetValue(Plant3D.URIs.IsReversed)
+       @SetPropertyValue(value=Plant3D.URIs.IsReversed)
+       public void setReversed(Boolean reverse) {
+               if (!controlPoint.isReverse())
+                       return;
+               
+               if (reverse == null) {
+                       return;
+               }
+               controlPoint.setReversed(reverse);
+               try {
+                       PipingRules.requestUpdate(getControlPoint());
+               } catch (Exception e) {
+                       // TODO Auto-generated catch block
+                       e.printStackTrace();
+               }       
+       }
+       
        @Override
        public void updateParameters() {
                super.updateParameters();
@@ -52,9 +120,39 @@ public class InlineComponent extends PipelineComponent {
                        if (calculated.containsKey("length")) {
                                controlPoint.setLength((Double)calculated.get("length"));
                        }
+                       if (calculated.containsKey("offset")) {
+                               controlPoint.setOffset((Double)calculated.get("offset"));
+                               componentCalculatedOffset = true;
+                       } else {
+                               componentCalculatedOffset = false;
+                       }
                }
        }
        
+       @Override
+       public void setPipeRun(PipeRun pipeRun) {
+               // TODO Auto-generated method stub
+               super.setPipeRun(pipeRun);
+               if (getPipeRun() != null && getAlternativePipeRun() != null) {
+                       updateOffset();
+               }
+       }
+       
+       @Override
+       public void setAlternativePipeRun(PipeRun pipeRun) {
+               // TODO Auto-generated method stub
+               super.setAlternativePipeRun(pipeRun);
+               if (getPipeRun() != null && getAlternativePipeRun() != null) {
+                       updateOffset();
+               }
+       }
+       
+       private void updateOffset() {
+               if (!componentCalculatedOffset && getControlPoint().isOffset()) {
+                       getControlPoint().setOffset(getPipeRun().getPipeDiameter()*0.5 - getAlternativePipeRun().getPipeDiameter()*0.5);
+               }
+       }
+
        @Override
        public Map<String, Object> updateParameterMap() {
                Map<String,Object> map = new HashMap<String, Object>();
@@ -63,9 +161,12 @@ public class InlineComponent extends PipelineComponent {
                                map.put("length", controlPoint.getLength());
                        if (controlPoint.isDualInline()) {
                                PipeControlPoint sub = controlPoint.getSubPoint().get(0);
-                               PipeRun pipeRun = sub.getPipeRun();
-                               if (pipeRun != null) {
-                                       map.put("radius2", pipeRun.getPipeDiameter() * 0.5);
+                               PipeRun pipeRun2 = sub.getPipeRun();
+                               if (pipeRun2 != null) {
+                                       map.put("radius2", pipeRun2.getPipeDiameter() * 0.5);
+                               }
+                               if (controlPoint.isOffset() && !componentCalculatedOffset) {
+                                       map.put("offset", controlPoint.getOffset());
                                }
                        }
                }