import java.util.Arrays;
import java.util.Collection;
import java.util.List;
+import java.util.Objects;
import javax.vecmath.AxisAngle4d;
import javax.vecmath.Matrix3d;
import org.simantics.g3d.math.MathTools;
import org.simantics.g3d.property.annotations.GetPropertyValue;
import org.simantics.g3d.scenegraph.G3DNode;
+import org.simantics.g3d.scenegraph.base.INode;
import org.simantics.plant3d.scenegraph.IP3DNode;
import org.simantics.plant3d.scenegraph.Nozzle;
import org.simantics.plant3d.scenegraph.P3DRootNode;
}
public void setLength(double l) {
- if (Double.isInfinite(l) || Double.isNaN(l)) {
+ if (this.length == l)
+ return;
+ if (Double.isInfinite(l) || Double.isNaN(l))
return;
- }
if (Math.abs(this.length-l) < MathTools.NEAR_ZERO)
return;
this.length = l;
}
if (this.turnAngle != null && Math.abs(this.turnAngle-turnAngle) < MathTools.NEAR_ZERO)
return;
+ if (Objects.equals(this.turnAngle, turnAngle))
+ return;
this.turnAngle = turnAngle;
firePropertyChanged("turnAngle");
}
}
if (this.offset != null && Math.abs(this.offset-offset) < MathTools.NEAR_ZERO)
return;
+ if (Objects.equals(this.offset, offset))
+ return;
this.offset = offset;
firePropertyChanged("offset");
}
}
if (this.rotationAngle != null && Math.abs(this.rotationAngle-rotationAngle) < MathTools.NEAR_ZERO)
return;
+ if (Objects.equals(rotationAngle, rotationAngle))
+ return;
this.rotationAngle = rotationAngle;
firePropertyChanged("rotationAngle");
}
public void setReversed(Boolean reversed) {
+ if (this.reversed == reversed)
+ return;
this.reversed = reversed;
firePropertyChanged("reversed");
}
return type.name();
}
- public Quat4d getControlPointOrientationQuat(double angle) {
+ public Vector3d getPathLegEndpointVector() {
+ PipeControlPoint a = findPreviousEnd();
+ PipeControlPoint b = findNextEnd();
+
+ if (a == null || b == null) {
+ return getPathLegDirection();
+ }
+
+ Vector3d p1 = a.getWorldPosition();
+ Vector3d p2 = b.getWorldPosition();
+ p2.sub(p1);
+ double l = p2.length();
+ if (l != 0.0) {
+ p2.scale(1.0 / l);
+ return p2;
+ }
+ else {
+ return getPathLegDirection();
+ }
+ }
+ public Vector3d getPathLegDirection() {
if (turnAxis == null) {
- Vector3d dir = getPathLegDirection(Direction.NEXT);
- return getControlPointOrientationQuat(dir, angle);
+ return getPathLegDirection(Direction.NEXT);
} else {
Vector3d dir = getPathLegDirection(Direction.PREVIOUS);
if (dir != null) dir.negate();
+ return dir;
+ }
+ }
+
+ public Quat4d getControlPointOrientationQuat(double angle) {
+ Vector3d dir = getPathLegDirection();
+ if (turnAxis == null) {
+ return getControlPointOrientationQuat(dir, angle);
+ } else {
return getControlPointOrientationQuat(dir, turnAxis, angle);
}
}
}
public Quat4d getControlPointOrientationQuat(double angle, boolean reversed) {
-
- if (turnAxis == null) {
- Vector3d dir = getPathLegDirection(Direction.NEXT);
- return getControlPointOrientationQuat(dir, angle, reversed);
- } else {
- Vector3d dir = getPathLegDirection(Direction.PREVIOUS);
- dir.negate();
- return getControlPointOrientationQuat(dir, angle, reversed);
- }
+ Vector3d dir = getPathLegDirection();
+ return getControlPointOrientationQuat(dir, angle, reversed);
}
-
-
- public static Quat4d getControlPointOrientationQuat(Vector3d dir, double angle) {
+ public Quat4d getControlPointOrientationQuat(Vector3d dir, double angle) {
if (dir == null || dir.lengthSquared() < MathTools.NEAR_ZERO)
return MathTools.getIdentityQuat();
-
- Vector3d up = new Vector3d(0.0, 1.0, 0.0);
- double a = up.angle(dir);
+ final P3DRootNode root = getRoot();
+ Vector3d up = root != null ? new Vector3d(root.getUpVector()) : new Vector3d(0.0, 1.0, 0.0);
+ final Vector3d legDir = getPathLegEndpointVector();
+ double a = up.angle(legDir);
if (a < 0.1 || (Math.PI - a) < 0.1) {
- up.set(1.0, 0.0, 0.0);
+ // Rotate components
+ up.set(up.getY(), up.getZ(), up.getX());
}
-
+
+ // Project up vector into a normal of the leg direction before applying to 'dir'
+ MathTools.mad(up, legDir, -legDir.dot(up)/legDir.lengthSquared());
+ up.normalize();
return getControlPointOrientationQuat(dir, up, angle);
}
+ public P3DRootNode getRoot() {
+ INode n = getParent();
+ while (n != null && !(n instanceof P3DRootNode))
+ n = n.getParent();
+ return (P3DRootNode) n;
+ }
+
public static Quat4d getControlPointOrientationQuat(Vector3d dir, Vector3d up, double angle) {
if (dir == null || dir.lengthSquared() < MathTools.NEAR_ZERO)
return MathTools.getIdentityQuat();
Vector3d right = new Vector3d();
-
+
+ up = new Vector3d(up);
right.cross(dir, up);
up.cross(right, dir);
right.normalize();
if (link) {
if (currentPrev.isDirected() && currentNext.isDirected())
link = false;
- else if (this.isDualInline()) {
- link = false;
- } else if (this.isDualSub()) {
+ else if (this.isDualSub()) {
throw new RuntimeException("_remove() is called for parent point, somehow got to child point. " + this);
}
}
PipeRun previousRun = previous.getPipeRun();
nextPipeRun.setPipeDiameter(previousRun.getPipeDiameter());
+ nextPipeRun.setPipeThickness(previousRun.getPipeThickness());
nextPipeRun.setTurnRadiusArray(previousRun.getTurnRadiusArray());
PipelineComponent n = next.getPipelineComponent();
component._setWorldPosition(getWorldPosition());
updateSubPoint();
}
-
+
private void updateSubPoint() {
if (isOffset()) {
if (next == null && previous == null) {