]> gerrit.simantics Code Review - simantics/3d.git/blobdiff - org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/controlpoint/PipeControlPoint.java
Support for reversible in-line components
[simantics/3d.git] / org.simantics.plant3d / src / org / simantics / plant3d / scenegraph / controlpoint / PipeControlPoint.java
index 21f2564d781e87b44fc1713264cf0640e002a618..ecaeb7ae7c41d2b70017d4de433dfac968270ecc 100644 (file)
@@ -1,6 +1,7 @@
 package org.simantics.plant3d.scenegraph.controlpoint;
 
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Collection;
 import java.util.List;
 
@@ -30,6 +31,8 @@ public class PipeControlPoint extends G3DNode implements IP3DNode {
        
        private Type type;
        private boolean fixed = true;
+       private boolean rotate = false;
+       private boolean reverse = false;
        private boolean deletable = true;
        private boolean sub = false;
        
@@ -81,6 +84,24 @@ public class PipeControlPoint extends G3DNode implements IP3DNode {
                this.fixed = fixed;
        }
        
+       @GetPropertyValue(name="Rotate",tabId="Debug",value="rotate")
+       public boolean isRotate() {
+               return rotate;
+       }
+       
+       public void setRotate(boolean rotate) {
+               this.rotate = rotate;
+       }
+       
+       @GetPropertyValue(name="Reverse",tabId="Debug",value="reverse")
+       public boolean isReverse() {
+               return reverse;
+       }
+       
+       public void setReverse(boolean reverse) {
+               this.reverse = reverse;
+       }
+       
        public void setSub(boolean sub) {
                this.sub = sub;
        }
@@ -218,6 +239,7 @@ public class PipeControlPoint extends G3DNode implements IP3DNode {
 
        private Double offset;
        private Double rotationAngle;
+       private Boolean reversed;
        
        @GetPropertyValue(name="Length",tabId="Debug",value="length")
        public double getLength() {
@@ -256,6 +278,11 @@ public class PipeControlPoint extends G3DNode implements IP3DNode {
                return rotationAngle;
        }
        
+       @GetPropertyValue(name="Reversed",tabId="Debug",value="reversed")
+       public Boolean getReversed() {
+               return reversed;
+       }
+       
        public void setTurnAngle(Double turnAngle) {
                if (Double.isInfinite(turnAngle) || Double.isNaN(turnAngle)) {
                        return;
@@ -291,10 +318,17 @@ public class PipeControlPoint extends G3DNode implements IP3DNode {
                firePropertyChanged("rotationAngle");
        }
        
+       public void setReversed(Boolean reversed) {
+               this.reversed = reversed;
+               firePropertyChanged("rotationAngle");
+       }
+       
        public Vector3d getSizeChangeOffsetVector(Vector3d dir) {
+               Quat4d q;
                if (rotationAngle == null)
-                       rotationAngle = 0.0;
-               Quat4d q = getControlPointOrientationQuat(dir, rotationAngle);
+                       q = getControlPointOrientationQuat(dir, 0.0);
+               else
+                       q = getControlPointOrientationQuat(dir, rotationAngle);
                Vector3d v = new Vector3d(0.0,offset,0.0);
        Vector3d offset = new Vector3d();
        MathTools.rotate(q, v, offset);
@@ -302,9 +336,11 @@ public class PipeControlPoint extends G3DNode implements IP3DNode {
        }
        
        public Vector3d getSizeChangeOffsetVector() {
+               Quat4d q;
                if (rotationAngle == null)
-                       rotationAngle = 0.0;
-               Quat4d q = getControlPointOrientationQuat(rotationAngle);
+                       q = getControlPointOrientationQuat(0.0);
+               else
+                       q = getControlPointOrientationQuat(rotationAngle);
                Vector3d v = new Vector3d(0.0,offset,0.0);
        Vector3d offset = new Vector3d();
        MathTools.rotate(q, v, offset);
@@ -325,7 +361,19 @@ public class PipeControlPoint extends G3DNode implements IP3DNode {
                return previous.toString();
        }
        
-        public Quat4d getControlPointOrientationQuat(double angle) {
+       @GetPropertyValue(name="Sub",tabId="Debug",value="sub")
+       private String getSubString() {
+               if (children.size() == 0)
+                       return "";
+               return Arrays.toString(children.toArray());
+       }
+       
+       @GetPropertyValue(name="Type",tabId="Debug",value="type")
+       public String getTypeString() {
+               return type.name();
+       }
+       
+       public Quat4d getControlPointOrientationQuat(double angle) {
                 
                 if (turnAxis == null) {
                         Vector3d dir = getPathLegDirection(Direction.NEXT);
@@ -339,11 +387,33 @@ public class PipeControlPoint extends G3DNode implements IP3DNode {
                                 dir.normalize();
                         return getControlPointOrientationQuat(dir, turnAxis, angle);
                 }
-        }
+       }
+        
+    public Quat4d getControlPointOrientationQuat(double angle, boolean reversed) {
+                
+                if (turnAxis == null) {
+                        Vector3d dir = getPathLegDirection(Direction.NEXT);
+                        if (dir.lengthSquared() > MathTools.NEAR_ZERO)
+                                dir.normalize();
+                        Quat4d q =  getControlPointOrientationQuat(dir, angle);
+                        if (reversed) {
+                                Quat4d q2 = new Quat4d();
+                               q2.set(new AxisAngle4d(MathTools.Y_AXIS, Math.PI));
+                               q.mulInverse(q2);
+                        }
+                        return q;
+                } else {
+                        Vector3d dir = getPathLegDirection(Direction.PREVIOUS);
+                        dir.negate();
+                        if (dir.lengthSquared() > MathTools.NEAR_ZERO)
+                                dir.normalize();
+                        return getControlPointOrientationQuat(dir, turnAxis, angle);
+                }
+       }
         
        
        
-        public static Quat4d getControlPointOrientationQuat(Vector3d dir, double angle) {
+       public static Quat4d getControlPointOrientationQuat(Vector3d dir, double angle) {
                        if (dir.lengthSquared() < MathTools.NEAR_ZERO)
                                return MathTools.getIdentityQuat();
                
@@ -1003,6 +1073,15 @@ public class PipeControlPoint extends G3DNode implements IP3DNode {
                p1.remChild(ocp);
                p2.remChild(sccp);
                
+               // TODO : now we assume that this is size change, and we do
+               if (ocp.next != null)
+                       ocp.next.setPrevious(null);
+               if (ocp.previous != null)
+                       ocp.previous.setNext(null);
+               if (sccp.next != null)
+                       sccp.next.setPrevious(null);
+               if (sccp.previous != null)
+                       sccp.previous.setNext(null);
                ocp.setNext(null);
                ocp.setPrevious(null);
                sccp.setNext(null);
@@ -1044,6 +1123,7 @@ public class PipeControlPoint extends G3DNode implements IP3DNode {
                }
                PipelineComponent comp = component;
                component = null;
+               
                comp.remove();
        }
        
@@ -1061,11 +1141,11 @@ public class PipeControlPoint extends G3DNode implements IP3DNode {
        public void setPosition(Vector3d position) {
                if (MathTools.equals(position, getPosition()))
                        return;
+               if (Double.isNaN(position.x) || Double.isNaN(position.y) || Double.isNaN(position.z))
+                       throw new IllegalArgumentException("NaN is not supported");
                super.setPosition(position);
                if (getParentPoint() == null && component != null)
                        component._setWorldPosition(getWorldPosition());
-               if (isDualSub())
-                       System.out.println();
                updateSubPoint();
        }