]> gerrit.simantics Code Review - simantics/3d.git/commitdiff
Handle variable length components on offset path leg 29/3029/1
authorMarko Luukkainen <marko.luukkainen@semantum.fi>
Thu, 18 Jul 2019 13:14:09 +0000 (16:14 +0300)
committerMarko Luukkainen <marko.luukkainen@semantum.fi>
Thu, 18 Jul 2019 13:14:09 +0000 (16:14 +0300)
* Offset path leg update may now insert a straight, if there is
available space
* Inline component update could add and remove control points without
updating update struct.
* Removing pipe control point had cyclic dependency to itself (through
component)

gitlab #12

Change-Id: I27e9385cda3077dd1f3e16f7bfbd0015352d98fd

org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/PipelineComponent.java
org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/controlpoint/ControlPointFactory.java
org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/controlpoint/PipeControlPoint.java
org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/controlpoint/PipingRules.java

index 03caa9815dfcf08dcc16394332b89d13719b0a70..26a3239700657c78aa7085c14332dc1ecac7ac61 100644 (file)
@@ -299,12 +299,13 @@ public abstract class PipelineComponent extends GeometryNode {
        @Override
        public void remove() {
                PipeControlPoint pcp = getControlPoint();
-               if (pcp != null) {
+               // Second check is needed, when remove process is initiated from control point.
+               if (pcp != null && pcp.getPipelineComponent() != null) {
                        pcp.remove();
                }
                super.remove();
        }
-       
+
        @Override
        protected double[] getColor() {
                if (getControlPoint() == null || !getControlPoint().isFixed())
index 824f74d6741e9e07643fdc197b10b63b9d03e190..0967f38b77981bc12b618ad9309b8827f1715ddb 100644 (file)
@@ -59,7 +59,6 @@ public class ControlPointFactory {
                                sub.setFixed(inst.fixed);
                                sub.setSub(true);
                                sub.setDeletable(false);
-//                             pcp.setOffset(0.0);
                                if (inst.isOffset)
                                        pcp.setOffset(0.0);
                        }
index 555a662089a41240b3ac17861b6130a657d68997..b14b298bcf26d0060ea91ec09521f740fc596b45 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;
 
@@ -340,6 +341,18 @@ public class PipeControlPoint extends G3DNode implements IP3DNode {
                return previous.toString();
        }
        
+       @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) {
@@ -1068,6 +1081,7 @@ public class PipeControlPoint extends G3DNode implements IP3DNode {
                }
                PipelineComponent comp = component;
                component = null;
+               
                comp.remove();
        }
        
index 5ec468e27993ab8531290f18537d245225773178..e1d9ae2d3971a57548a8821f9c118acb4c4934ff 100644 (file)
@@ -475,6 +475,7 @@ public class PipingRules {
                if (DEBUG)
                        System.out.println("PipingRules.updateInlineControlPoints() " + u);
 
+               boolean recalcline = false;
                if (!u.hasOffsets) {
                        
                        Vector3d start = new Vector3d(u.startPoint);
@@ -514,7 +515,7 @@ public class PipingRules {
                                if (icp.isVariableLength()) {
                                        if (i != pathLegPoints.size() - 1) {
                                                PipeControlPoint next = pathLegPoints.get(i + 1);
-                                               updateVariableLength(icp,  prev, next);
+                                               recalcline = recalcline | updateVariableLength(icp,  prev, next);
 
                                        } else {
                                                // this is variable length component at the end of the
@@ -532,30 +533,7 @@ public class PipingRules {
                                        // space between them.
                                        // I there is, we'll have to create new variable length
                                        // component between them.
-                                       Vector3d currentPos = icp.getWorldPosition();
-                                       Vector3d prevPos = prev.getWorldPosition();
-                                       Vector3d dir = new Vector3d(currentPos);
-                                       dir.sub(prevPos);
-                                       double l = dir.lengthSquared();
-                                       double l2prev = prev.getInlineLength();
-                                       double l2next = icp.getInlineLength();
-                                       double l2 = l2prev + l2next;
-                                       double l2s = l2 * l2;
-                                       if (l > l2s) {
-                                               if (allowInsertRemove) {
-                                                       dir.normalize();
-                                                       double length = Math.sqrt(l) - l2; // true length of the
-                                                                                                                               // variable length
-                                                                                                                               // component
-                                                       dir.scale(length * 0.5 + l2prev); // calculate center
-                                                                                                                               // position of the
-                                                                                                                               // component
-                                                       dir.add(prevPos);
-                                                       PipeControlPoint scp = insertStraight(prev, icp, dir, length);
-                                               } else {
-                                                       triedIR = true;
-                                               }
-                                       }
+                                       recalcline = recalcline | possibleVaribleLengthInsert(icp, prev);
                                }
                        }
                } else { // with offset
@@ -581,6 +559,9 @@ public class PipingRules {
                        }
                        pathLegPoints.add(u.end);
                        
+                       if (!checkSizes)
+                               return; 
+                       
                        sp = new Vector3d(u.startPoint);
                        ep = new Vector3d(u.endPoint);
                        ep.sub(u.offset);
@@ -597,7 +578,7 @@ public class PipingRules {
                                        if (i != pathLegPoints.size() - 1) {
                                                PipeControlPoint next;
                                                next = pathLegPoints.get(i + 1);
-                                               updateVariableLength(icp,  prev, next);
+                                               recalcline = recalcline | updateVariableLength(icp,  prev, next);
 
                                        } else {
                                                // this is variable length component at the end of the
@@ -607,7 +588,15 @@ public class PipingRules {
                                                // place, but center of the component must be moved.
                                                updateVariableLengthEnd(icp, prev);
                                        }
-                               } else if (icp.isOffset()) {
+                               } else if (!prev.isVariableLength()) {
+                                       // If this and previous control point are not variable
+                                       // length pcps, we'll have to check if there is no empty
+                                       // space between them.
+                                       // I there is, we'll have to create new variable length
+                                       // component between them.
+                                       recalcline = recalcline | possibleVaribleLengthInsert(icp, prev);
+                               }
+                               if (icp.isOffset()) {
                                        // TODO : offset vector is already calculated and should be
                                        // cached
                                        Vector3d  offset = icp.getSizeChangeOffsetVector(u.dir);
@@ -616,9 +605,13 @@ public class PipingRules {
                                }
                        }
                }
+               if (recalcline) {
+                       u.list.clear();
+                       u.start.findNextEnd(u.list);
+               }
        }
        
-       private static void updateVariableLength(PipeControlPoint icp, PipeControlPoint prev,  PipeControlPoint next) {
+       private static boolean updateVariableLength(PipeControlPoint icp, PipeControlPoint prev,  PipeControlPoint next) {
                Vector3d prevPos = prev.getWorldPosition();
                Vector3d nextPos = next.getWorldPosition();
                
@@ -649,6 +642,7 @@ public class PipingRules {
                        dir.add(prevPos);
                        icp.setWorldPosition(dir);
                        icp.setLength(length);
+                       return false;
                } else {
                        // components leave no space to the component and it
                        // must be removed
@@ -657,8 +651,39 @@ public class PipingRules {
                                if (DEBUG)
                                        System.out.println("PipingRules.updateVariableLength removing " + icp);
                                icp._remove();
+                               return true;
+                       }
+                       return false;
+               }
+       }
+       
+       private static boolean possibleVaribleLengthInsert(PipeControlPoint icp, PipeControlPoint prev) throws Exception{
+               Vector3d currentPos = icp.getWorldPosition();
+               Vector3d prevPos = prev.getWorldPosition();
+               Vector3d dir = new Vector3d(currentPos);
+               dir.sub(prevPos);
+               double l = dir.lengthSquared();
+               double l2prev = prev.getInlineLength();
+               double l2next = icp.getInlineLength();
+               double l2 = l2prev + l2next;
+               double l2s = l2 * l2;
+               if (l > l2s) {
+                       if (allowInsertRemove) {
+                               dir.normalize();
+                               double length = Math.sqrt(l) - l2; // true length of the
+                                                                                                       // variable length
+                                                                                                       // component
+                               dir.scale(length * 0.5 + l2prev); // calculate center
+                                                                                                       // position of the
+                                                                                                       // component
+                               dir.add(prevPos);
+                               PipeControlPoint scp = insertStraight(prev, icp, dir, length);
+                               return true;
+                       } else {
+                               triedIR = true;
                        }
                }
+               return false;
        }
        
        private static void updateVariableLengthEnd(PipeControlPoint icp,  PipeControlPoint prev) {
@@ -1652,9 +1677,8 @@ public class PipingRules {
                        System.out.println("Run is not connected");
                }
                for (PipeControlPoint pcp : pcps) {
-                       if (!pcp.isDirected())
-                               if (pcp.getNext() == null && pcp.getPrevious() == null)
-                                       System.out.println("Orphan " + pcp);
+                       if (!pcp.isDirected() && pcp.getNext() == null && pcp.getPrevious() == null)
+                               System.out.println("Orphan undirected " + pcp);
                }
                for (PipeControlPoint pcp : pcps) {
                        if (pcp.getParentPoint() == null) {