X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=org.simantics.plant3d%2Fsrc%2Forg%2Fsimantics%2Fplant3d%2Fscenegraph%2FTurnComponent.java;h=cd490a5d38aa9b7965e6f9b2daf3a9cf5d5f2bc3;hb=e92fe8961f1de7bc132e64814bba4c5f92f67ba6;hp=0e307a471eba496fbe1c93d5727b56cee1b5d4e8;hpb=7a6193c2806c1755ad127eb479e871b2008df856;p=simantics%2F3d.git 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 0e307a47..cd490a5d 100644 --- a/org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/TurnComponent.java +++ b/org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/TurnComponent.java @@ -9,6 +9,7 @@ import org.simantics.g3d.math.MathTools; import org.simantics.g3d.property.annotations.GetPropertyValue; import org.simantics.g3d.property.annotations.SetPropertyValue; import org.simantics.g3d.scenegraph.base.ParentNode; +import org.simantics.g3d.tools.NodeTools; import org.simantics.objmap.graph.annotations.DynamicGraphType; import org.simantics.objmap.graph.annotations.GetType; import org.simantics.objmap.graph.annotations.RelatedGetValue; @@ -70,7 +71,7 @@ public class TurnComponent extends PipelineComponent { @Override public void updateParameters() { super.updateParameters(); - if (!isVariableAngle()) { + if (controlPoint.asFixedAngle()) { Map calculated = getCalculatedParameters(); if (calculated.containsKey("length")) { controlPoint.setLength((Double)calculated.get("length")); @@ -79,14 +80,20 @@ public class TurnComponent extends PipelineComponent { } } - @RelatedGetValue(Plant3D.URIs.HasTurnAngle) public Double getTurnAngle() { + return getControlPoint().getTurnAngle(); + } + + @RelatedGetValue(Plant3D.URIs.HasTurnAngle) + public Double _getTurnAngle() { + if (!getControlPoint().asFixedAngle()) + return null; return getControlPoint().getTurnAngle(); } @RelatedSetValue(Plant3D.URIs.HasTurnAngle) public void setTurnAngle(Double a) { - if (!getControlPoint().isFixed()) + if (!getControlPoint().asFixedAngle()) return; getControlPoint().setTurnAngle(a); } @@ -140,7 +147,7 @@ public class TurnComponent extends PipelineComponent { @RelatedGetValue(Plant3D.URIs.HasRotationAngle) @GetPropertyValue(name="Rotation Angle", value=Plant3D.URIs.HasRotationAngle, tabId = "Default") public Double getRotationAngle() { - if (!controlPoint.isFixed()) + if (!controlPoint.asFixedAngle()) return null; Double d = controlPoint.getRotationAngle(); if (d == null) @@ -150,7 +157,7 @@ public class TurnComponent extends PipelineComponent { @RelatedSetValue(Plant3D.URIs.HasRotationAngle) @SetPropertyValue(value=Plant3D.URIs.HasRotationAngle) public void setRotationAngle(Double angle) { - if (!controlPoint.isFixed()) + if (!controlPoint.asFixedAngle()) return; if (angle == null || Double.isInfinite(angle) || Double.isNaN(angle)) { @@ -166,14 +173,14 @@ public class TurnComponent extends PipelineComponent { @RelatedGetValue(Plant3D.URIs.IsReversed) @GetPropertyValue(name="Reverse", value=Plant3D.URIs.IsReversed, tabId = "Default") public Boolean isReversed() { - if (!controlPoint.isFixed()) + if (!controlPoint.asFixedAngle()) return null; Boolean d = controlPoint._getReversed(); return d; } @RelatedSetValue(Plant3D.URIs.IsReversed) public void setReversed(Boolean reverse) { - if (!controlPoint.isFixed()) + if (!controlPoint.asFixedAngle()) return; if (reverse == null) { @@ -190,4 +197,38 @@ public class TurnComponent extends PipelineComponent { else return new double[]{1.0,0.0,0.0}; } + + /** + * Turn is a section of a circle; this method returns center of that circle. + * @return + */ + public Vector3d getCenterPosition() { + // getPosition() is control point position, located outside of turn + // we need to calculate position in the middle of the turn + double t = Math.tan((Math.PI - getControlPoint().getTurnAngle()) * 0.5); + double tr = getTurnRadius(); + double R = 0.0; + if (t > MathTools.NEAR_ZERO) + R = tr / t; + Vector3d localC = new Vector3d(-R, 0.0, -tr); + // worldC is center of a circle + Vector3d worldC = NodeTools.getWorldPosition(this,localC); + return worldC; + } + + /** + * Returns position in the middle of turn component + * @return + */ + public Vector3d getMiddlePosition() { + Vector3d pos = getWorldPosition(); + Vector3d worldC = getCenterPosition(); + + // calculate vector from center to edge, which is middle of the turn + pos.sub(worldC); + pos.normalize(); + pos.scale(getTurnRadius()); + pos.add(worldC); + return pos; + } }