From: Tuukka Lehtonen Date: Thu, 12 Mar 2020 17:32:40 +0000 (+0200) Subject: Merge branch 'release/1.43.0' X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=c6e13a2972fe12620f00f06a97d8746780cb22b1;hp=57ee576455c42f22303efc600964426474ab6110;p=simantics%2F3d.git Merge branch 'release/1.43.0' --- diff --git a/org.simantics.plant3d/src/org/simantics/plant3d/dialog/ComponentSelectionDialog.java b/org.simantics.plant3d/src/org/simantics/plant3d/dialog/ComponentSelectionDialog.java index da764775..fb506092 100644 --- a/org.simantics.plant3d/src/org/simantics/plant3d/dialog/ComponentSelectionDialog.java +++ b/org.simantics.plant3d/src/org/simantics/plant3d/dialog/ComponentSelectionDialog.java @@ -566,7 +566,7 @@ public class ComponentSelectionDialog extends Dialog implements ISelectionChange rotationAngleText.setEnabled(true); if (angle == null) { ok = false; - if (msg == null) msg = "Please provide a rotation angle"; + if (msg == null) msg = "Please provide a turn angle"; } } else { // this should not happen, since end components should not have variable, or 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 08fa2622..fdb413ee 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 @@ -462,7 +462,7 @@ public class PipeControlPoint extends G3DNode implements IP3DNode { } if (this.rotationAngle != null && Math.abs(this.rotationAngle-rotationAngle) < MathTools.NEAR_ZERO) return; - if (Objects.equals(rotationAngle, rotationAngle)) + if (Objects.equals(this.rotationAngle, rotationAngle)) return; this.rotationAngle = rotationAngle; firePropertyChanged("rotationAngle"); @@ -855,107 +855,70 @@ public class PipeControlPoint extends G3DNode implements IP3DNode { */ public Vector3d getPathLegDirection(Direction direction) { if (direction == Direction.NEXT) { - if (next != null) { - PipeControlPoint pcp = this; - if (pcp.isDualInline()) { - pcp = pcp.getDualSub(); - } - Vector3d v = new Vector3d(); - v.sub(next.getWorldPosition(),pcp.getWorldPosition()); - if (v.lengthSquared() > MathTools.NEAR_ZERO) - v.normalize(); - else - return null; - return v; - } else { - if (previous == null) { - if (!isDirected()) - throw new RuntimeException("Cannot calculate path leg direction for unconnected control point " + this); - return getDirectedControlPointDirection(); + return getPathLegDirectionNext(); + } else { + return getPathLegDirectionPrevious(); + } + } - } else { - if (isVariableAngle() && !asFixedAngle()) - throw new RuntimeException("Cannot calculate path leg direction for unconnected variable angle control point " + this); - if (isInline()) { - PipeControlPoint pcp = this; - if (pcp.isDualSub()) { - pcp = pcp.getParentPoint(); - } - Vector3d v = new Vector3d(); - v.sub(pcp.getWorldPosition(),previous.getWorldPosition()); - if (v.lengthSquared() > MathTools.NEAR_ZERO) - v.normalize(); - else - return null; - return v; - } else if (isDirected()) { - return getDirectedControlPointDirection(); - } else if (isEnd()) { - Vector3d v = new Vector3d(); - v.sub(getWorldPosition(),previous.getWorldPosition()); - if (v.lengthSquared() > MathTools.NEAR_ZERO) - v.normalize(); - else - return null; - return v; - } else if (isTurn() && asFixedAngle() && !_getReversed()) { - return getDirection(Direction.NEXT); - } - throw new RuntimeException("Missing implementation " + this); - } - } + public Vector3d getPathLegDirectionPrevious() { + if (previous != null) { + PipeControlPoint pcp = this; + if (isDualSub()) + pcp = getParentPoint(); + Vector3d v = new Vector3d(); + v.sub(previous.getWorldPosition(),pcp.getWorldPosition()); + if (v.lengthSquared() > MathTools.NEAR_ZERO) + v.normalize(); + else + return null; + return v; + } else if (isDirected()) { + Vector3d v = getDirectedControlPointDirection(); + v.negate(); + return v; + } else if (next == null) { + throw new RuntimeException("Cannot calculate path leg direction for unconnected control point " + this); + } else if (isVariableAngle() && !asFixedAngle()) { + throw new RuntimeException("Cannot calculate path leg direction for unconnected variable angle control point " + this); + } else if (isInline() || isEnd()) { + Vector3d v = getPathLegDirectionNext(); + if (v != null) v.negate(); + return v; + } else if (isTurn() && asFixedAngle() && _getReversed()) { + return getDirection(Direction.PREVIOUS); } else { - if (previous != null) { - PipeControlPoint pcp = this; - if (isDualSub()) - pcp = getParentPoint(); - Vector3d v = new Vector3d(); - v.sub(previous.getWorldPosition(),pcp.getWorldPosition()); - if (v.lengthSquared() > MathTools.NEAR_ZERO) - v.normalize(); - else - return null; - return v; - } else { - if (next == null) { - if (!isDirected()) - throw new RuntimeException("Cannot calculate path leg direction for unconnected control point " + this); - Vector3d v = getDirectedControlPointDirection(); - v.negate(); - return v; - } else { - if (isVariableAngle() && !asFixedAngle()) - throw new RuntimeException("Cannot calculate path leg direction for unconnected variable angle control point " + this); - if (isInline()) { - PipeControlPoint pcp = this; - if (pcp.isDualInline()) { - pcp = pcp.getDualSub(); - } - Vector3d v = new Vector3d(); - v.sub(pcp.getWorldPosition(),next.getWorldPosition()); - if (v.lengthSquared() > MathTools.NEAR_ZERO) - v.normalize(); - else - return null; - return v; - } else if (isDirected()) { - Vector3d v = getDirectedControlPointDirection(); - v.negate(); - return v; - } else if (isEnd()) { - Vector3d v = new Vector3d(); - v.sub(getWorldPosition(),next.getWorldPosition()); - if (v.lengthSquared() > MathTools.NEAR_ZERO) - v.normalize(); - else - return null; - return v; - } else if (isTurn() && asFixedAngle() && _getReversed()) { - return getDirection(Direction.PREVIOUS); - } - throw new RuntimeException("Missing implementation " + this); - } + throw new RuntimeException("Missing implementation " + this); + } + } + + public Vector3d getPathLegDirectionNext() { + if (next != null) { + PipeControlPoint pcp = this; + if (pcp.isDualInline()) { + pcp = pcp.getDualSub(); } + Vector3d v = new Vector3d(); + v.sub(next.getWorldPosition(),pcp.getWorldPosition()); + if (v.lengthSquared() > MathTools.NEAR_ZERO) + v.normalize(); + else + return null; + return v; + } else if (isDirected()) { + return getDirectedControlPointDirection(); + } else if (previous == null) { + throw new RuntimeException("Cannot calculate path leg direction for unconnected control point " + this); + } else if (isVariableAngle() && !asFixedAngle()) { + throw new RuntimeException("Cannot calculate path leg direction for unconnected variable angle control point " + this); + } else if (isInline() || isEnd()) { + Vector3d v = getPathLegDirectionPrevious(); + if (v != null) v.negate(); + return v; + } else if (isTurn() && asFixedAngle() && !_getReversed()) { + return getDirection(Direction.NEXT); + } else { + throw new RuntimeException("Missing implementation " + this); } } @@ -1651,6 +1614,21 @@ public class PipeControlPoint extends G3DNode implements IP3DNode { updateSubPoint(); } + public void orientToDirection(Vector3d dir) { + Double angleO = getRotationAngle(); + double angle = 0.0; + if (angleO != null) + angle = angleO; + boolean reversed = _getReversed(); + Quat4d q = null; + if (dir != null) { + q = getControlPointOrientationQuat(dir, angle, reversed); + } else { + q = getControlPointOrientationQuat(angle, reversed); + } + setWorldOrientation(q); + } + @Override public String toString() { return getClass().getName() + "@" + Integer.toHexString(hashCode()); 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 542534c3..776d38ab 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 @@ -294,7 +294,7 @@ public class PipingRules { scp.setWorldPosition(pos); Vector3d dir = new Vector3d(); dir.sub(pcp2.getWorldPosition(), pcp1.getWorldPosition()); - updateControlPointOrientation(scp, dir); + scp.orientToDirection(dir); scp.setLength(length); validate(scp.getPipeRun()); return scp; @@ -1638,7 +1638,7 @@ public class PipingRules { } else if (u.start.isEnd()) { updateEndComponentControlPoint(u.start, u.dir); } else if (u.start.isInline()) { - updateControlPointOrientation(u.start, u.dir); + u.start.orientToDirection(u.dir); } if (u.end.isTurn()) { //updateTurnControlPointTurn(u.end, u.end.getPrevious(), u.end.getNext()); @@ -1647,7 +1647,7 @@ public class PipingRules { } else if (u.end.isEnd()) { updateEndComponentControlPoint(u.end, u.dir); } else if (u.end.isInline()) { - updateControlPointOrientation(u.end, u.dir); + u.end.orientToDirection(u.dir); } } else { @@ -1776,7 +1776,7 @@ public class PipingRules { System.out.println(" " + newInlinePoint); icp.setWorldPosition(newInlinePoint); - updateControlPointOrientation(icp, dir); + icp.orientToDirection(dir); } /** @@ -1793,7 +1793,7 @@ public class PipingRules { System.out.println("PipingRules.updateEndComponentControlPoint() " + ecp); if (!ecp.isFixed()) // prevent overriding nozzle orientations.. - updateControlPointOrientation(ecp, dir); + ecp.orientToDirection(dir); for (PipeControlPoint pcp : ecp.getChildPoints()) { // TODO update position @@ -1801,21 +1801,6 @@ public class PipingRules { } } - private static void updateControlPointOrientation(PipeControlPoint pcp, Vector3d dir) { - Double angleO = pcp.getRotationAngle(); - double angle = 0.0; - if (angleO != null) - angle = angleO; - boolean reversed = pcp._getReversed(); - Quat4d q = null; - if (dir != null) { - q = pcp.getControlPointOrientationQuat(dir, angle, reversed); - } else { - q = pcp.getControlPointOrientationQuat(angle, reversed); - } - pcp.setWorldOrientation(q); - } - /** * Updates all branches when branch's position has been changed * @@ -1881,7 +1866,7 @@ public class PipingRules { tcp.setTurnAxis(new Vector3d(MathTools.Y_AXIS)); } - updateControlPointOrientation(tcp,prev); + tcp.orientToDirection(prev); if (DEBUG) System.out.println("PipingTools.updateTurnControlPointTurn " + prev + " " + next + " " + turnAngle + " " + turnAxis); diff --git a/org.simantics.plant3d/src/org/simantics/plant3d/utils/ComponentUtils.java b/org.simantics.plant3d/src/org/simantics/plant3d/utils/ComponentUtils.java index 438e0bd6..78f41665 100644 --- a/org.simantics.plant3d/src/org/simantics/plant3d/utils/ComponentUtils.java +++ b/org.simantics.plant3d/src/org/simantics/plant3d/utils/ComponentUtils.java @@ -378,9 +378,6 @@ public class ComponentUtils { public static PipelineComponent addComponent(P3DRootNode root, PipelineComponent component, InsertInstruction inst) throws Exception { PipelineComponent newComponent = ComponentUtils.createComponent(root, inst.typeUri); - if (inst.name != null) - newComponent.setName(inst.name); - PipeControlPoint newPcp = newComponent.getControlPoint(); PipeControlPoint toPcp = component.getControlPoint(); @@ -447,6 +444,8 @@ public class ComponentUtils { } else if (toPcp.isDirected()) { dir = new Vector3d(toPcp.getDirection(Direction.NEXT)); + if (position == PositionType.PREVIOUS) + dir.negate(); pos = new Vector3d(toPcp.getWorldPosition()); } else if (toPcp.isTurn() && toPcp.asFixedAngle()) { dir = new Vector3d(toPcp.getDirection(position == PositionType.NEXT ? Direction.NEXT : Direction.PREVIOUS)); @@ -469,8 +468,12 @@ public class ComponentUtils { } } - String name = component.getPipeRun().getUniqueName(typeName); - newComponent.setName(name); + if (inst.name != null) { + newComponent.setName(inst.name); + } else { + String name = component.getPipeRun().getUniqueName(typeName); + newComponent.setName(name); + } pipeRun.addChild(newComponent); if (newPcp.isSizeChange()) @@ -487,7 +490,7 @@ public class ComponentUtils { } else if (newComponent instanceof TurnComponent) { TurnComponent turnComponent = (TurnComponent)newComponent; if (turnComponent.isVariableAngle()) { - newPcp.setTurnAngle(inst.angle); + newPcp.setTurnAngle(Math.toRadians(inst.angle)); newComponent.setParameter("turnAngle", inst.angle); } if (inst.rotationAngle != null)