}
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");
*/
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);
}
}
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());
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;
} 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());
} 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 {
System.out.println(" " + newInlinePoint);
icp.setWorldPosition(newInlinePoint);
- updateControlPointOrientation(icp, dir);
+ icp.orientToDirection(dir);
}
/**
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
}
}
- 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
*
tcp.setTurnAxis(new Vector3d(MathTools.Y_AXIS));
}
- updateControlPointOrientation(tcp,prev);
+ tcp.orientToDirection(prev);
if (DEBUG)
System.out.println("PipingTools.updateTurnControlPointTurn " + prev + " " + next + " " + turnAngle + " " + turnAxis);
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();
} 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));
}
}
- 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())
} 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)