]> gerrit.simantics Code Review - simantics/3d.git/commitdiff
Merge branch 'release/1.43.0'
authorTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Fri, 13 Mar 2020 16:58:10 +0000 (18:58 +0200)
committerTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Fri, 13 Mar 2020 16:58:10 +0000 (18:58 +0200)
org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/controlpoint/PipeControlPoint.java
org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/controlpoint/PipingRules.java
org.simantics.plant3d/src/org/simantics/plant3d/utils/ComponentUtils.java

index fdb413ee39316b1cbc0652a4e2360c0ceb105b39..124e54bb15761dc7451c63c5a9a4fd3af70335e5 100644 (file)
@@ -791,9 +791,15 @@ public class PipeControlPoint extends G3DNode implements IP3DNode {
        }
        
        /**
-        * Returns direction vector. 
+        * Returns direction vector pointing towards an adjacent component for
+        * directed control points or turn control points with one open end. 
         * 
-        * For directed control points, always returns outwards pointing vector.
+        * Always returns an outwards pointing vector.
+        * 
+        * For any other type of component, the return value is null.
+        * 
+        * For turn components this only return a non-null value for the unconnected
+        * end of the component. 
         * 
         * @param direction
         * @return normalized vector, or null
@@ -837,6 +843,7 @@ public class PipeControlPoint extends G3DNode implements IP3DNode {
                     Vector3d offset = new Vector3d();
                     MathTools.rotate(q2, v, offset);
                     MathTools.rotate(q, offset, dir);
+                    dir.negate();
                     dir.normalize();
                     return dir;
                 }
index 776d38ab860791abbfb8f488a3271990509c0be8..e930b8d6d07094035a188933141c4519085c5382 100644 (file)
@@ -381,10 +381,43 @@ public class PipingRules {
 
        }
 
+       /**
+        * Calculate offset based on a given fixed component direction.
+        * 
+        * The desired component direction is provided as an input to this method,
+        * unlike the direction vector that is calculated by calculateOffset.
+        * 
+        * The returned offset vector is always perpendicular to the given direction
+        * vector.
+        * 
+        * @param startPoint Start point of leg
+        * @param endPoint   End point of leg
+        * @param start      Starting component of leg
+        * @param list       Inline components between start and end
+        * @param end        Ending component of leg
+        * @param dir        Direction at which the offset is calculated
+        * @param offset     A vector object to receive the offset vector values
+        * @return True if offsets are present
+        */
        public static boolean calculateDirectedOffset(Vector3d startPoint, Vector3d endPoint, PipeControlPoint start, ArrayList<PipeControlPoint> list, PipeControlPoint end, Vector3d dir, Vector3d offset) {
                return calculateOffset(startPoint, endPoint, start, list, end, dir, offset, true);
        }
 
+       /**
+        * Calculate offset and direction vectors for a path leg so that the given chain
+        * of components starts and ends at the given coordinates
+        * 
+        * The returned direction and offset vectors are perpendicular to each other.
+        * 
+        * @param startPoint Start point of the leg
+        * @param endPoint   End point of the leg
+        * @param start      Starting component of the leg
+        * @param list       Inline components between start and end
+        * @param end        Ending component of the leg
+        * @param dir        A vector object to receive the component direction vector
+        * @param offset     A vector object to receive the offset vector
+        * @return True if offsets are present
+        */
        public static boolean calculateOffset(Vector3d startPoint, Vector3d endPoint, PipeControlPoint start, ArrayList<PipeControlPoint> list, PipeControlPoint end, Vector3d dir, Vector3d offset) {
                return calculateOffset(startPoint, endPoint, start, list, end, dir, offset, false);
        }
@@ -397,8 +430,11 @@ public class PipingRules {
                } else {
                        Vector3d sp = new Vector3d(startPoint);
                        Point3d ep = new Point3d(endPoint);
-                       dir.set(ep);
-                       dir.sub(sp);
+                       if (!directed) {
+                               dir.set(ep);
+                               dir.sub(sp);
+                       }
+                       
                        double l = dir.lengthSquared(); 
                        if (l > MathTools.NEAR_ZERO)
                                dir.scale(1.0/Math.sqrt(l));
@@ -1080,15 +1116,19 @@ public class PipingRules {
                
                Point3d otherPosition = new Point3d(dcpStart ? u.endPoint : u.startPoint);
                if (u.hasOffsets) {
-                       Vector3d dir = new Vector3d(), offset = new Vector3d();
+                       Vector3d dir = dcp.getDirection(dcpStart ? Direction.NEXT : Direction.PREVIOUS);
+                       if (!dcpStart)
+                               dir.negate();
+                       
+                       Vector3d offset = new Vector3d();
                        calculateDirectedOffset(u.startPoint, u.endPoint, u.start, u.list, u.end, dir, offset);
                        u.dir = dir;
                        u.offset = offset;
                        
                        if (dcpStart)
-                               otherPosition.add(offset);
-                       else
                                otherPosition.sub(offset);
+                       else
+                               otherPosition.add(offset);
                }
 
                double mu[] = new double[2];
@@ -1236,7 +1276,7 @@ public class PipingRules {
                Point3d position1 = new Point3d(u.startPoint);
                Point3d position2 = new Point3d(u.endPoint);
                
-               Vector3d dir = new Vector3d(), offset = new Vector3d();
+               Vector3d dir = u.start.getDirection(Direction.NEXT), offset = new Vector3d();
                calculateDirectedOffset(new Vector3d(position1), new Vector3d(position2), u.start, u.list, u.end, dir, offset);
                
                Point3d position1offset = new Point3d(position1);
index 78f4166547b8740367cc3c18eaccb5523d0a3148..913fceb9178276045828d04d9546000e39b62dd2 100644 (file)
@@ -405,6 +405,8 @@ public class ComponentUtils {
                        sizeChange = ((InlineComponent)newComponent).isSizeChange();
                }
                
+               // Calculate component position and direction vectors
+               // 'dir' is a unit vector that represents the direction from 'component' to 'newComponent'
                if (toPcp.isInline()) {
                        switch (position) {
                        case NEXT: 
@@ -434,6 +436,7 @@ public class ComponentUtils {
                                break;
                        case PREVIOUS:
                                pos = new Vector3d(start);
+                               dir.negate();
                                break;
                        case SPLIT:
                                pos = new Vector3d(toPcp.getWorldPosition());
@@ -441,11 +444,9 @@ public class ComponentUtils {
                        default:
                                break;
                        }
-
                } else if (toPcp.isDirected()) {
-                       dir = new Vector3d(toPcp.getDirection(Direction.NEXT));
-                       if (position == PositionType.PREVIOUS)
-                               dir.negate();
+                       // 'dir' always points out of a nozzle regardless of insertion direction
+                       dir = new Vector3d(toPcp.getDirectedControlPointDirection());
                        pos = new Vector3d(toPcp.getWorldPosition());
                } else if (toPcp.isTurn() && toPcp.asFixedAngle()) {
                        dir = new Vector3d(toPcp.getDirection(position == PositionType.NEXT ? Direction.NEXT : Direction.PREVIOUS));
@@ -497,7 +498,6 @@ public class ComponentUtils {
                 ((TurnComponent) newComponent).setRotationAngle(inst.rotationAngle);
                }
                
-               
                newComponent.updateParameters();
                
                Vector3d v = new Vector3d(dir);
@@ -516,12 +516,11 @@ public class ComponentUtils {
                } else {
                        v.scale(newComponent.getControlPoint().getInlineLength());
                }
+               
                switch (position) {
                case NEXT:
-                       pos.add(v);
-                       break;
                case PREVIOUS:
-                       pos.sub(v);
+                       pos.add(v);
                        break;
                case SPLIT:
                        break;