From b63b50f907c318cd999ff8cdc0ca3f1bf93dc6fe Mon Sep 17 00:00:00 2001 From: Marko Luukkainen Date: Wed, 21 Aug 2019 13:21:51 +0300 Subject: [PATCH] Handle fixed turn components when pipe run is reversed. Handle unconnected variable length component, when it is the firs component of a path leg. gitlab #23 Change-Id: Iccc027fca87a4e4e89fae88f58e53f245eb5025c --- .../plant3d/actions/RoutePipeAction.java | 8 ++- .../plant3d/scenegraph/InlineComponent.java | 4 +- .../plant3d/scenegraph/TurnComponent.java | 26 ++++++++ .../controlpoint/PipeControlPoint.java | 2 +- .../scenegraph/controlpoint/PipingRules.java | 60 +++++++++++++------ 5 files changed, 77 insertions(+), 23 deletions(-) diff --git a/org.simantics.plant3d/src/org/simantics/plant3d/actions/RoutePipeAction.java b/org.simantics.plant3d/src/org/simantics/plant3d/actions/RoutePipeAction.java index be82d85e..3c320434 100644 --- a/org.simantics.plant3d/src/org/simantics/plant3d/actions/RoutePipeAction.java +++ b/org.simantics.plant3d/src/org/simantics/plant3d/actions/RoutePipeAction.java @@ -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(); diff --git a/org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/InlineComponent.java b/org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/InlineComponent.java index 1fd83da1..fe30c29c 100644 --- a/org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/InlineComponent.java +++ b/org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/InlineComponent.java @@ -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) diff --git a/org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/TurnComponent.java b/org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/TurnComponent.java index e8779985..0205f5a3 100644 --- a/org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/TurnComponent.java +++ b/org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/TurnComponent.java @@ -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() { diff --git a/org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/controlpoint/PipeControlPoint.java b/org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/controlpoint/PipeControlPoint.java index 66055865..53a612e2 100644 --- a/org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/controlpoint/PipeControlPoint.java +++ b/org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/controlpoint/PipeControlPoint.java @@ -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); } diff --git a/org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/controlpoint/PipingRules.java b/org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/controlpoint/PipingRules.java index b096266f..fd50bf7b 100644 --- a/org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/controlpoint/PipingRules.java +++ b/org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/controlpoint/PipingRules.java @@ -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()); + } } } -- 2.47.1