]> gerrit.simantics Code Review - simantics/3d.git/commitdiff
Handle fixed turn components when pipe run is reversed. 35/3135/1
authorMarko Luukkainen <marko.luukkainen@semantum.fi>
Wed, 21 Aug 2019 10:21:51 +0000 (13:21 +0300)
committerMarko Luukkainen <marko.luukkainen@semantum.fi>
Wed, 21 Aug 2019 10:21:51 +0000 (13:21 +0300)
Handle unconnected variable length component, when it is the firs
component of a path leg.

gitlab #23

Change-Id: Iccc027fca87a4e4e89fae88f58e53f245eb5025c

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

index be82d85e3cd808eadd93be549d79724ac32cb94b..3c320434cd6af985911e24c0d3b49eccfd0eceee 100644 (file)
@@ -1077,8 +1077,12 @@ public class RoutePipeAction extends vtkSwtAction {
             */
            private void updateCurrentPoint() {
                InlineComponent straight = (InlineComponent)added.get(added.size()-1);
-               // TODO: the inline length is from previous update step. 
-               double l = straight.getPrevious().getControlPoint().getInlineLength();
+               // TODO: the inline length is from previous update step.
+               double l;
+               if (!reversed)
+                   l = straight.getPrevious().getControlPoint().getInlineLength();
+               else
+                   l = straight.getNext().getControlPoint().getInlineLength();
                Vector3d v = new Vector3d();
                v.sub(currentPosition, previousPosition);
                double length = v.length();
index 1fd83da110d3f36bf8739db214d325444d8e74e9..fe30c29c3e2a7d82aca29bead0289ecac8ec9597 100644 (file)
@@ -91,9 +91,7 @@ public class InlineComponent extends PipelineComponent {
        public Boolean isReversed() {
                if (!controlPoint.isReverse())
                        return null;
-               Boolean d = controlPoint.getReversed();
-               if (d == null)
-                       return false;
+               Boolean d = controlPoint._getReversed();
                return d;
        }
        @RelatedSetValue(Plant3D.URIs.IsReversed)
index e8779985ae6b44622b62dd166fb260d61200a376..0205f5a318f9778531a36160414ad99ab5d4f497 100644 (file)
@@ -132,6 +132,32 @@ public class TurnComponent extends PipelineComponent {
             e.printStackTrace();
         }   
     }
+    
+    @RelatedGetValue(Plant3D.URIs.IsReversed)
+    @GetPropertyValue(name="Reverse", value=Plant3D.URIs.IsReversed, tabId = "Default")
+    public Boolean isReversed() {
+        if (!controlPoint.isFixed())
+            return null;
+        Boolean d = controlPoint._getReversed();
+        return d;
+    }
+    @RelatedSetValue(Plant3D.URIs.IsReversed)
+    //@SetPropertyValue(value=Plant3D.URIs.IsReversed)
+    public void setReversed(Boolean reverse) {
+        if (!controlPoint.isFixed())
+            return;
+        
+        if (reverse == null) {
+            return;
+        }
+        controlPoint.setReversed(reverse);
+        try {
+            PipingRules.requestUpdate(getControlPoint());
+        } catch (Exception e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        }   
+    }
        
        @Override
        protected double[] getColor() {
index 660558652c47c03c1897b7aa1a53761e6795a206..53a612e201179eca765af679c424c04a4c8ef601 100644 (file)
@@ -404,7 +404,7 @@ public class PipeControlPoint extends G3DNode implements IP3DNode {
                                 dir.normalize();
                         Quat4d q =  getControlPointOrientationQuat(dir, angle);
                         if (reversed) {
-                                Quat4d q2 = new Quat4d();
+                               Quat4d q2 = new Quat4d();
                                q2.set(new AxisAngle4d(MathTools.Y_AXIS, Math.PI));
                                q.mulInverse(q2);
                         }
index b096266f7af72901d2718812b9dd77d3570d3689..fd50bf7b4b1c26ed9e8757855f547d818464ec4d 100644 (file)
@@ -527,15 +527,15 @@ public class PipingRules {
                        pathLegPoints.add(u.end);
 
                        // TODO : values can be cached in the loop
-                       for (int i = 1; i < pathLegPoints.size(); i++) {
+                       for (int i = 0; i < pathLegPoints.size(); i++) {
                                PipeControlPoint icp = pathLegPoints.get(i);
 
-                               PipeControlPoint prev = pathLegPoints.get(i - 1);
-                               
+                               PipeControlPoint prev = i > 0 ? pathLegPoints.get(i - 1) : null;
+                               PipeControlPoint next = i < pathLegPoints.size() - 1 ? pathLegPoints.get(i + 1) : null;
 
                                if (icp.isVariableLength()) {
-                                       if (i != pathLegPoints.size() - 1) {
-                                               PipeControlPoint next = pathLegPoints.get(i + 1);
+                                       if (prev != null && next != null) {
+                                               
                                                recalcline = recalcline | updateVariableLength(icp,  prev, next);
 
                                        } else {
@@ -544,11 +544,11 @@ public class PipingRules {
                                                // the problem is that we want to keep unconnected end
                                                // of the component in the same
                                                // place, but center of the component must be moved.
-                                               updateVariableLengthEnd(icp, prev);
+                                               updateVariableLengthEnd(icp, prev != null ? prev : next);
                                        }
 
 
-                               } else if (!prev.isVariableLength()) {
+                               } else if (prev != null && !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.
@@ -587,18 +587,18 @@ public class PipingRules {
                        ep = new Vector3d(u.endPoint);
                        ep.sub(u.offset);
                        
-                       for (int i = 1; i < pathLegPoints.size(); i++) {
+                       for (int i = 0; i < pathLegPoints.size(); i++) {
                                PipeControlPoint icp = pathLegPoints.get(i);
 
-                               PipeControlPoint prev = pathLegPoints.get(i - 1);
-                               if (prev.isDualInline())
+                               PipeControlPoint prev = i > 0 ? pathLegPoints.get(i - 1) : null;
+                PipeControlPoint next = i < pathLegPoints.size() - 1 ? pathLegPoints.get(i + 1) : null;
+                
+                               if (prev != null && prev.isDualInline())
                                        prev = prev.getSubPoint().get(0);
                                
 
                                if (icp.isVariableLength()) {
-                                       if (i != pathLegPoints.size() - 1) {
-                                               PipeControlPoint next;
-                                               next = pathLegPoints.get(i + 1);
+                                       if (prev != null && next != null) {
                                                recalcline = recalcline | updateVariableLength(icp,  prev, next);
 
                                        } else {
@@ -607,9 +607,9 @@ public class PipingRules {
                                                // the problem is that we want to keep unconnected end
                                                // of the component in the same
                                                // place, but center of the component must be moved.
-                                               updateVariableLengthEnd(icp, prev);
+                                               updateVariableLengthEnd(icp, prev != null ? prev : next);
                                        }
-                               } else if (!prev.isVariableLength()) {
+                               } else if (prev != null && !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.
@@ -828,6 +828,13 @@ public class PipingRules {
                }
 
                Vector3d directedDirection = direction(dcp, dcpStart ? Direction.NEXT : Direction.PREVIOUS);
+               if (directedDirection == null) {
+                   updateTurnControlPointTurn(dcp, dcp.getPrevious(), dcp.getNext());
+                   directedDirection = direction(dcp, dcpStart ? Direction.NEXT : Direction.PREVIOUS);
+                   if (directedDirection == null) {
+                       return;
+                   }
+               }
                Point3d directedEndPoint = new Point3d(u.endPoint);
                if (u.hasOffsets)
                        directedEndPoint.add(u.offset);
@@ -1540,12 +1547,25 @@ public class PipingRules {
                
                if (!tcp.isFixed()) {
                    if (next == null || prev == null)
-                   return Math.PI; // FIXME : argh
+                   return tcp.getTurnAngle();
                Vector3d middlePoint = tcp.getWorldPosition();
                Vector3d nextPoint = next.getWorldPosition();
                Vector3d prevPoint = prev.getWorldPosition();
                return updateTurnControlPointTurn(tcp, middlePoint, prevPoint, nextPoint);
                } else {
+                   // Verify that fixed turn is properly defined.
+                   // TODO : when reversed flag is changed, rotation angle should be recalculated, otherwise the orientation will change.
+                   // TODO : should reverse flag toggle to be done already when we are removing defining side?
+                   if (prev != null && next != null) {
+                       // Nothing to do
+                   } else if (prev == null) {
+                       if (!tcp._getReversed())
+                           tcp.setReversed(true);
+                   } else if (next == null) {
+                       if (tcp._getReversed())
+                           tcp.setReversed(false);
+                   }
+                   
                    Vector3d dir;
                    if (!tcp._getReversed()) {
                    if (prev == null)
@@ -1563,7 +1583,7 @@ public class PipingRules {
                 Vector3d middlePoint = tcp.getWorldPosition();
                 Vector3d nextPoint = next.getWorldPosition();
                 dir = new Vector3d();
-                dir.sub(nextPoint,middlePoint);
+                dir.sub(middlePoint, nextPoint);
                    }
                    dir.normalize();
             
@@ -1695,6 +1715,12 @@ public class PipingRules {
                                }
                                
                        }
+                       if (current.isTurn() && current.isFixed()) {
+                           current.setReversed(!current._getReversed());
+                       }
+                       if (current.isInline() && current.isReverse()) {
+                           current.setReversed(!current._getReversed());
+                       }   
                }
        }