]> gerrit.simantics Code Review - simantics/3d.git/commitdiff
Simplified free ended variable length component update 04/3104/1
authorMarko Luukkainen <marko.luukkainen@semantum.fi>
Wed, 14 Aug 2019 15:19:00 +0000 (18:19 +0300)
committerMarko Luukkainen <marko.luukkainen@semantum.fi>
Wed, 14 Aug 2019 15:19:00 +0000 (18:19 +0300)
* Previous code was combined with route pipe action, which did not take
account spaced reserved by previous turn component.
* The update code caused undo/redo synchronization issues, since it
altered intended position of the control point

gitlab #24
gitlab #26

Change-Id: I89c7bbc608e7900f0b18b33ce1e390c5469cf0bd

org.simantics.plant3d/src/org/simantics/plant3d/actions/AddComponentAction.java
org.simantics.plant3d/src/org/simantics/plant3d/actions/RoutePipeAction.java
org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/controlpoint/PipeControlPoint.java
org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/controlpoint/PipingRules.java

index 4f35291e88a8a7695171f43ddda2ec1b309e9baa..174d6f1166eac0718aa4aa814bb491b34ae67c66 100644 (file)
@@ -227,10 +227,21 @@ public class AddComponentAction extends vtkSwtAction {
                        } else if (toPcp.isTurn() && toPcp.isFixed()) {
                            dir = new Vector3d(toPcp.getDirection(position == PositionType.NEXT ? Direction.NEXT : Direction.PREVIOUS));
                 pos = new Vector3d(toPcp.getWorldPosition());
-                if (!lengthAdjustable || insertPosition == PositionType.NEXT) {
+                if (!lengthAdjustable) {
                     Vector3d v = new Vector3d(dir);
                     v.scale(toPcp.getInlineLength());
                     pos.add(v);
+                } else {
+                    if (insertPosition == PositionType.NEXT) {
+                        Vector3d v = new Vector3d(dir);
+                        v.scale(toPcp.getInlineLength());
+                        pos.add(v);
+                    } else if (insertPosition == PositionType.SPLIT) {
+                        // scale 0.5*length so that we don't remove the length twice from the new component
+                        Vector3d v = new Vector3d(dir);
+                        v.scale(toPcp.getInlineLength()*0.5);  
+                        pos.add(v);
+                    }
                 }
                        }
                        
index 17455a328b0797cef34dc296d560aff852090ea7..509ab38cce6e9120f94a1e732768b4af0f993e64 100644 (file)
@@ -1061,16 +1061,19 @@ public class RoutePipeAction extends vtkSwtAction {
             * Updates tool graphics for current point 
             */
            private void updateCurrentPoint() {
-//             PipeComponentProvider.createStraightEdges(pipeShapes.get(pipeShapes.size() - 1), controlPoints.get(controlPoints.size() - 1), currentPoint, pipeDiameter*0.5);
                InlineComponent straight = (InlineComponent)added.get(added.size()-1);
-               // FIXME : does not take account space the the previous elbow reserves. 
+               // TODO: the inline length is from previous update step. 
+               double l = straight.getPrevious().getControlPoint().getInlineLength();
                Vector3d v = new Vector3d();
                v.sub(currentPosition, previousPosition);
                double length = v.length();
-               v.scale(0.5);
-               v.add(previousPosition);
-               straight.getControlPoint().setWorldPosition(v);
-               straight.getControlPoint().setLength(length);
+               if (length > MathTools.NEAR_ZERO) {
+               v.scale(1.0/length);
+               v.scale(0.5*(length+l));
+               v.add(previousPosition);
+               straight.getControlPoint().setWorldPosition(v);
+               straight.getControlPoint().setLength(length);
+               }
                try {
                                PipingRules.positionUpdate(straight.getControlPoint(),false);
                        } catch (Exception e) {
index fc78f1b97647efc3cfceb510a6bfd9010240f026..ac76be8b25f373f1e133cb1c2860b52433343548 100644 (file)
@@ -7,6 +7,7 @@ import java.util.List;
 
 import javax.vecmath.AxisAngle4d;
 import javax.vecmath.Matrix3d;
+import javax.vecmath.Point3d;
 import javax.vecmath.Quat4d;
 import javax.vecmath.Tuple3d;
 import javax.vecmath.Vector3d;
@@ -1013,7 +1014,19 @@ public class PipeControlPoint extends G3DNode implements IP3DNode {
                                        if (currentNext.isVariableLength() && currentPrev.isVariableLength()) {
                                                // we have to join them into single variable length component.
                                                additionalRemove = currentPrev;
-                                               //currentPrev.remove();
+                                               // combine lengths and set the location of remaining control point to the center.
+                                               Point3d ps = new Point3d();
+                                           Point3d pe = new Point3d();
+                                           Point3d ns = new Point3d();
+                        Point3d ne = new Point3d();
+                                               currentPrev.getInlineControlPointEnds(ps, pe);
+                                               currentNext.getInlineControlPointEnds(ns, ne);
+                                               double l = currentPrev.getLength() + currentNext.getLength();
+                                               Vector3d cp = new Vector3d();
+                                               cp.add(ps, ne);
+                                               cp.scale(0.5);
+                                               currentNext.setLength(l);
+                                               currentNext.setWorldPosition(cp);
                                        }
                                } else {
                                        // FIXME : pipe run must be split into two parts, since the control point structure is no more continuous. 
index 67c5f35b8755d91c506d87211cd98497000ac9ee..b096266f7af72901d2718812b9dd77d3570d3689 100644 (file)
@@ -708,43 +708,47 @@ public class PipingRules {
        }
        
        private static void updateVariableLengthEnd(PipeControlPoint icp,  PipeControlPoint prev) {
-               double currentLength = icp.getLength();
-               Vector3d currentPos = icp.getWorldPosition();
-               Vector3d prevPos = prev.getWorldPosition();
-               
-               Vector3d dir = new Vector3d();
-               dir.sub(currentPos, prevPos);
-               
-               if (currentLength < MathTools.NEAR_ZERO) {
-                       currentLength = (dir.length() - prev.getInlineLength()) * 2.0;
-               }
-               
-               if (dir.lengthSquared() > MathTools.NEAR_ZERO)
-                       dir.normalize();
-               Point3d endPos = new Point3d(dir);
-               endPos.scale(currentLength * 0.5);
-               endPos.add(currentPos); // this is the free end of the
-                                                               // component
-
-               double offset = prev.getInlineLength();
-               Point3d beginPos = new Point3d(dir);
-               beginPos.scale(offset);
-               beginPos.add(prevPos); // this is the connected end of
-                                                               // the component
-
-               double l = beginPos.distance(endPos);
-               
-               if (Double.isNaN(l))
-                       System.out.println("Length for " + icp + " is NaN");
-
-               dir.scale(l * 0.5);
-               beginPos.add(dir); // center position
-
-               if (DEBUG)
-                       System.out.println("PipingRules.updateInlineControlPoints() setting variable length to " + l);
-               icp.setLength(l);
-
-               icp.setWorldPosition(new Vector3d(beginPos));
+           Vector3d currentPos = icp.getWorldPosition();
+        Vector3d prevPos = prev.getWorldPosition();
+        
+        Vector3d dir = new Vector3d();
+        dir.sub(currentPos, prevPos);
+        
+           boolean simple = true;
+           if (simple) {
+               double currentLength = (dir.length() - prev.getInlineLength()) * 2.0;
+               icp.setLength(currentLength);
+           } else {
+               double currentLength = icp.getLength();
+               if (currentLength < MathTools.NEAR_ZERO) {
+                       currentLength = (dir.length() - prev.getInlineLength()) * 2.0;
+               }
+               
+               if (dir.lengthSquared() > MathTools.NEAR_ZERO)
+                       dir.normalize();
+               Point3d endPos = new Point3d(dir);
+               endPos.scale(currentLength * 0.5);
+               endPos.add(currentPos); // this is the free end of the component
+    
+               double offset = prev.getInlineLength();
+               Point3d beginPos = new Point3d(dir);
+               beginPos.scale(offset);
+               beginPos.add(prevPos); // this is the connected end of the component
+    
+               double l = beginPos.distance(endPos);
+               
+               if (Double.isNaN(l))
+                       System.out.println("Length for " + icp + " is NaN");
+    
+               dir.scale(l * 0.5);
+               beginPos.add(dir); // center position
+    
+               if (DEBUG)
+                       System.out.println("PipingRules.updateInlineControlPoints() setting variable length to " + l);
+               icp.setLength(l);
+    
+               icp.setWorldPosition(new Vector3d(beginPos));
+           }
        }
 
        private static void ppNoOffset(UpdateStruct2 u) throws Exception {
@@ -1291,8 +1295,7 @@ public class PipingRules {
                                        info.getEnd()._remove();
                                }
                        }
-                       // ControlPointTools.removeControlPoint may remove mo0re than one
-                       // CP;
+                       // ControlPointTools.removeControlPoint may remove more than one CP;
                        // we must populate inline CP list again.
                        u.list.clear();
                        u.start.findNextEnd( u.list);
@@ -1725,6 +1728,7 @@ public class PipingRules {
                        return;
                Collection<PipeControlPoint> pcps = pipeRun.getControlPoints();
                int count = 0;
+               //System.out.println("Validate " + pipeRun.getName());
                for (PipeControlPoint pcp : pcps) {
                        if (pcp.getParentPoint() == null || pcp.getParentPoint().getPipeRun() != pipeRun)
                                count++;