]> gerrit.simantics Code Review - simantics/3d.git/commitdiff
Convert variable angle turn turn to fixed angle 47/3447/1
authorMarko Luukkainen <marko.luukkainen@semantum.fi>
Mon, 4 Nov 2019 16:38:39 +0000 (18:38 +0200)
committerMarko Luukkainen <marko.luukkainen@semantum.fi>
Mon, 4 Nov 2019 16:38:39 +0000 (18:38 +0200)
When we remove a component next to a variable angle turn, the turn must
be converted to (temporary) fixed angle component.

gitlab #46

Change-Id: I118fad68739531692a4d2e00d4d025e981369837

org.simantics.g3d/.settings/org.eclipse.jdt.core.prefs
org.simantics.g3d/META-INF/MANIFEST.MF
org.simantics.g3d/src/org/simantics/g3d/math/MathTools.java
org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/PipelineComponent.java
org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/controlpoint/PipeControlPoint.java

index 76b52a10078dbea00ffdb4ddf7a35024eb23b953..0c68a61dca867ceb49e79d2402935261ec3e3809 100644 (file)
@@ -1,8 +1,7 @@
-#Mon Dec 12 12:35:07 EET 2011\r
-eclipse.preferences.version=1\r
-org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled\r
-org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6\r
-org.eclipse.jdt.core.compiler.compliance=1.6\r
-org.eclipse.jdt.core.compiler.problem.assertIdentifier=error\r
-org.eclipse.jdt.core.compiler.problem.enumIdentifier=error\r
-org.eclipse.jdt.core.compiler.source=1.6\r
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
+org.eclipse.jdt.core.compiler.compliance=1.8
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.8
index 876933d45cec50ddedd21a3855a662df99e9ccaa..d1a9d0091614aa7af8585a06550d232af5981617 100644 (file)
@@ -20,7 +20,7 @@ Require-Bundle: org.eclipse.core.runtime,
  org.eclipse.nebula.widgets.tablecombo;bundle-version="1.0.0",
  org.simantics.ui;bundle-version="1.0.0",
  org.simantics.scl.osgi;bundle-version="1.0.4"
-Bundle-RequiredExecutionEnvironment: JavaSE-1.6
+Bundle-RequiredExecutionEnvironment: JavaSE-1.8
 Bundle-ActivationPolicy: lazy
 Export-Package: org.simantics.g3d,
  org.simantics.g3d.adapters,
index 0fbd110f3025e96ad7856ef4c17fc5cf40887b15..d761b0ec8350450e8f45829fc8446ffb823bff01 100644 (file)
@@ -147,6 +147,16 @@ public class MathTools {
                return (planeNormal.dot(point) + d);
        }
        
+       public static Vector3d projectToPlane(Vector3d v, Vector3d planeNormal) {
+           //v.normalize();
+           //planeNormal.normalize();
+           Vector3d t = new Vector3d();
+           t.cross(v,planeNormal);
+           t.cross(planeNormal, t);
+           return t;
+           
+       }
+       
        public static boolean intersectStraightPlane(Tuple3d linePoint, Vector3d lineDir, Tuple3d planePoint, Vector3d planeNormal, Tuple3d intersectPoint) {
                intersectPoint.set(planePoint);
                intersectPoint.sub(linePoint);
@@ -746,60 +756,97 @@ public class MathTools {
        
        public static boolean createRotation(Vector3d original, Vector3d rotated, AxisAngle4d result) {
                
-                       if (rotated.lengthSquared() > 0.01)
-                               rotated.normalize();
-                       else
-                               return false;
-                       double d = original.dot(rotated);
-                       if (d > 0.9999) {
-                               // original and rotated are parallel, pointing at the same direction
-                               result.angle = 0.0;
-                               result.x = 0.0;
-                               result.y = 1.0;
-                               result.z = 0.0;
-                       } else if (d < -0.9999) {
-                               // original and rotated are parallel, pointing at the opposite direction 
-                               Vector3d a = Z_AXIS;
-                               if (Math.abs(a.dot(original)) > 0.8 )
-                                       a = Y_AXIS;
-                               result.set(a, Math.PI);
-                       } else {
-                               double angle = original.angle(rotated);
-                               Vector3d axis = new Vector3d();
-                               axis.cross(original, rotated);
-                               result.set(axis,angle);
-                       }
-                       return true;
+               if (rotated.lengthSquared() > 0.01)
+                       rotated.normalize();
+               else
+                       return false;
+               double d = original.dot(rotated);
+               if (d > 0.9999) {
+                       // original and rotated are parallel, pointing at the same direction
+                       result.angle = 0.0;
+                       result.x = 0.0;
+                       result.y = 1.0;
+                       result.z = 0.0;
+               } else if (d < -0.9999) {
+                       // original and rotated are parallel, pointing at the opposite direction 
+                       Vector3d a = Z_AXIS;
+                       if (Math.abs(a.dot(original)) > 0.8 )
+                               a = Y_AXIS;
+                       result.set(a, Math.PI);
+               } else {
+                       double angle = original.angle(rotated);
+                       Vector3d axis = new Vector3d();
+                       axis.cross(original, rotated);
+                       result.set(axis,angle);
                }
+               return true;
+       }
        
        public static boolean createRotation(Vector3d original, Vector3d rotated, Quat4d result) {
                
-                       if (rotated.lengthSquared() > 0.01)
-                               rotated.normalize();
-                       else
-                               return false;
-                       double d = original.dot(rotated);
-                       if (d > 0.9999) {
-                               // original and rotated are parallel, pointing at the same direction
-                               result.w = 1.0;
-                               result.x = 0.0;
-                               result.y = 0.0;
-                               result.z = 0.0;
-                       } else if (d < -0.9999) {
-                               // original and rotated are parallel, pointing at the opposite direction 
-                               Vector3d a = Z_AXIS;
-                               if (Math.abs(a.dot(original)) > 0.8 )
-                                       a = Y_AXIS;
-                               getQuat(a, Math.PI, result);
-                               
-                       } else {
-                               double angle = original.angle(rotated);
-                               Vector3d axis = new Vector3d();
-                               axis.cross(original, rotated);
-                               getQuat(axis, angle, result);
-                       }
-                       return true;
+               if (rotated.lengthSquared() > 0.01)
+                       rotated.normalize();
+               else
+                       return false;
+               double d = original.dot(rotated);
+               if (d > 0.9999) {
+                       // original and rotated are parallel, pointing at the same direction
+                       result.w = 1.0;
+                       result.x = 0.0;
+                       result.y = 0.0;
+                       result.z = 0.0;
+               } else if (d < -0.9999) {
+                       // original and rotated are parallel, pointing at the opposite direction 
+                       Vector3d a = Z_AXIS;
+                       if (Math.abs(a.dot(original)) > 0.8 )
+                               a = Y_AXIS;
+                       getQuat(a, Math.PI, result);
+                       
+               } else {
+                       double angle = original.angle(rotated);
+                       Vector3d axis = new Vector3d();
+                       axis.cross(original, rotated);
+                       getQuat(axis, angle, result);
                }
+               return true;
+       }
+       
+       public static boolean createRotation(Vector3d original, Vector3d rotated, Vector3d axis, AxisAngle4d result) {
+        
+        if (rotated.lengthSquared() > 0.01)
+            rotated.normalize();
+        else
+            return false;
+        if (original.lengthSquared() > 0.01)
+            original.normalize();
+        else
+            return false;
+        if (axis.lengthSquared() > 0.01)
+            axis.normalize();
+        else
+            return false;
+        double d = original.dot(rotated);
+        if (d > 0.9999) {
+            // original and rotated are parallel, pointing at the same direction
+            result.angle = 0.0;
+            result.x = axis.x;
+            result.y = axis.y;
+            result.z = axis.z;
+        } else if (d < -0.9999) {
+            // original and rotated are parallel, pointing at the opposite direction 
+            result.angle = Math.PI;
+            result.x = axis.x;
+            result.y = axis.y;
+            result.z = axis.z;
+        } else {
+            Vector3d p1 = projectToPlane(original, axis);
+            Vector3d p2 = projectToPlane(rotated, axis);
+            double angle = p1.angle(p2);
+            result.set(axis,angle);
+            
+        }
+        return true;
+    }
        
        public static void getQuat(Vector3d axis, double angle, Quat4d q)
        {
index c0feb668d183ff090dad98fa81ed844cce02ab0b..735916db6df2b31a0bae9bf7c880ce29c4d95194 100644 (file)
@@ -133,17 +133,20 @@ public abstract class PipelineComponent extends GeometryNode {
        @RelatedSetObj(Plant3D.URIs.HasNext)
        public void setNext(PipelineComponent comp) {
                if (next == comp)
-                       return;
+                   return;
                if (this.next != null)
-                       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();
-               
+                   this.next._removeRef(this);
+        _setNext(comp);
+        this.syncnext = false;
+        if (DEBUG) System.out.println(this + " next " + comp);
+        syncNext();
+        firePropertyChanged(Plant3D.URIs.HasNext);
+        if (comp != null)
+            comp.sync();
+       }
+       
+       protected void _setNext(PipelineComponent comp) {
+           this.next = comp;
        }
        
        
@@ -158,15 +161,19 @@ public abstract class PipelineComponent extends GeometryNode {
                        return;
                if (this.previous != null)
                        this.previous._removeRef(this);
-               this.previous = comp;
+               _setPrevious(comp);
                this.syncprev = false;
                if (DEBUG) System.out.println(this + " prev " + comp);
                syncPrevious();
                firePropertyChanged(Plant3D.URIs.HasPrevious);
                if (comp != null)
                        comp.sync();
-               
        }
+       
+       protected void _setPrevious(PipelineComponent comp) {
+        this.previous = comp;
+    }
+       
        private PipelineComponent branch0;
        
        @RelatedGetObj(Plant3D.URIs.HasBranch0)
@@ -264,13 +271,13 @@ public abstract class PipelineComponent extends GeometryNode {
        // Control point structure is left into illegal state.
        private void _removeRef(PipelineComponent comp) {
                if (next == comp) {
-                       next = null;
+                       _setNext(null);
                        syncnext = false;
                        if (DEBUG) System.out.println(this + " remove next " + comp);
                        firePropertyChanged(Plant3D.URIs.HasNext);
                        syncNext();
                } else if (previous == comp) {
-                       previous = null;
+                       _setPrevious(null);
                        syncprev = false;
                        if (DEBUG) System.out.println(this + " remove prev " + comp);
                        firePropertyChanged(Plant3D.URIs.HasPrevious);
index 8219c1d686d146ba60c982658ab419e07b0d375b..086bdb2b5d408de5fcc8109dba50eae6ea8ca452 100644 (file)
@@ -240,6 +240,9 @@ public class PipeControlPoint extends G3DNode implements IP3DNode {
                if (this.next == next)
                        return;
                if (DEBUG) System.out.println(this + " next " + next);
+               if (next == null && isVariableAngle() && previous != null && !isRemoved()) {
+                   convertVariableAngleToFixed(Direction.NEXT);
+               }
                this.next = next;
                if (component != null) {
                        if (parent == null || isSub)
@@ -248,7 +251,6 @@ public class PipeControlPoint extends G3DNode implements IP3DNode {
                                component.setBranch0(next != null ? next.component : null);
                        updateSubPoint();
                }
-
        }
 
        public void setPrevious(PipeControlPoint previous) {
@@ -259,6 +261,9 @@ public class PipeControlPoint extends G3DNode implements IP3DNode {
                if (this.previous == previous)
                        return;
                if (DEBUG) System.out.println(this + " previous " + previous);
+               if (previous == null && isVariableAngle() && next != null && !isRemoved()) {
+            convertVariableAngleToFixed(Direction.PREVIOUS);
+        }
                this.previous = previous;
                if (component != null) {
                        if (parent == null || isSub)
@@ -267,7 +272,32 @@ public class PipeControlPoint extends G3DNode implements IP3DNode {
                                component.setBranch0(previous != null ? previous.component : null);
                        updateSubPoint();
                }
-
+       }
+       
+       private void convertVariableAngleToFixed(Direction direction) {
+           // We are removing reference, which transforms variable angle to fixed angle.
+        // Since fixed angle is defined differently, we need to calculate fixed angle parameters based on current data
+        // We need to calculate turnAngle and rotationAngle
+           Vector3d dirOut = getPathLegDirection(direction == Direction.NEXT ? Direction.NEXT : Direction.PREVIOUS);
+        Vector3d dir = getPathLegDirection(direction == Direction.NEXT ? Direction.PREVIOUS : Direction.NEXT);
+        dir.negate();
+        dirOut.normalize();
+        dir.normalize();
+        double angle = dir.angle(dirOut);
+        //super._setNext(null);
+        if (direction == Direction.NEXT)
+            next = null;
+        else
+            previous = null;
+        setRotationAngle(0.0);
+        setReversed(direction == Direction.NEXT ? false : true);
+        Vector3d dirOutN = getPathLegDirection(direction == Direction.NEXT ? Direction.NEXT : Direction.PREVIOUS);
+        dirOutN.normalize();
+        AxisAngle4d aa = new AxisAngle4d();
+        if (MathTools.createRotation(dirOutN, dirOut, dir, aa)) {
+            setRotationAngle(aa.angle);
+            setTurnAngle(angle);
+        }
        }
 
        public PipeControlPoint parent;
@@ -324,7 +354,9 @@ public class PipeControlPoint extends G3DNode implements IP3DNode {
 
        @GetPropertyValue(name="Rotation Angle",tabId="Debug",value="rotationAngle")
        public Double getRotationAngle() {
-               return rotationAngle;
+           if (asFixedAngle())
+               return rotationAngle;
+           return null;
        }
 
        @GetPropertyValue(name="Reversed",tabId="Debug",value="reversed")
@@ -996,6 +1028,7 @@ public class PipeControlPoint extends G3DNode implements IP3DNode {
 
                PipeControlPoint additionalRemove = null;
                if (!PipingRules.isEnabled()) {
+                   component = null;
                        setPrevious(null);
                        setNext(null);
                } else {
@@ -1311,6 +1344,10 @@ public class PipeControlPoint extends G3DNode implements IP3DNode {
        private void removeParentPoint() {
                throw new RuntimeException("Child points cannot be removed directly");
        }
+       
+       public boolean isRemoved() {
+           return component == null;
+       }
 
        private void removeComponent() {
                if (component == null)