diff --git a/src/Mod/TechDraw/App/DrawUtil.cpp b/src/Mod/TechDraw/App/DrawUtil.cpp index a93fef46a5..449311eb17 100644 --- a/src/Mod/TechDraw/App/DrawUtil.cpp +++ b/src/Mod/TechDraw/App/DrawUtil.cpp @@ -174,6 +174,17 @@ double DrawUtil::simpleMinDist(TopoDS_Shape s1, TopoDS_Shape s2) } } +//! returns 2d vector's angle with X axis. result is [0, 2pi]. +double DrawUtil::angleWithX(Base::Vector3d inVec) +{ + double result = atan2(inVec.y, inVec.x); + if (result < 0) { + result += 2.0 * M_PI; + } + + return result; +} + //! assumes 2d on XY //! quick angle for straight edges double DrawUtil::angleWithX(TopoDS_Edge e, bool reverse) @@ -924,6 +935,34 @@ QPointF DrawUtil::invertY(QPointF v) return QPointF(v.x(), -v.y()); } +//! convert a gui point into it's app space equivalent. this requires us to +//! perform the invert, scale, rotate operations in the reverse order from +//! that used to generate the qt point. +//! Note: the centering operation is not considered here +Base::Vector3d DrawUtil::toAppSpace(const DrawViewPart& dvp, const Base::Vector3d &qtPoint) +{ +// Base::Console().Message("DGU::toPaperSpace(%s)\n", formatVector(qtPoint).c_str()); + // From Y+ is down to Y+ is up + Base::Vector3d appPoint = invertY(qtPoint); + + // remove the effect of the Rotation property + double rotDeg = dvp.Rotation.getValue(); + double rotRad = rotDeg * M_PI / 180.0; + if (rotDeg != 0.0) { + // we always rotate around the origin. + appPoint.RotateZ(-rotRad); + } + + // convert to 1:1 scale + appPoint = appPoint / dvp.getScale(); + + return appPoint; +} + +Base::Vector3d DrawUtil::toAppSpace(const DrawViewPart& dvp, const QPointF& qtPoint) +{ + return toAppSpace(dvp, toVector3d(qtPoint)); +} //obs? was used in CSV prototype of Cosmetics std::vector DrawUtil::split(std::string csvLine) diff --git a/src/Mod/TechDraw/App/DrawUtil.h b/src/Mod/TechDraw/App/DrawUtil.h index 805a788fa1..503de91462 100644 --- a/src/Mod/TechDraw/App/DrawUtil.h +++ b/src/Mod/TechDraw/App/DrawUtil.h @@ -71,6 +71,8 @@ namespace TechDraw { +class DrawViewPart; + //used by sort_Edges struct EdgePoints { @@ -92,6 +94,7 @@ public: static double sensibleScale(double working_scale); static double angleWithX(TopoDS_Edge e, bool reverse); static double angleWithX(TopoDS_Edge e, TopoDS_Vertex v, double tolerance = VERTEXTOLERANCE); + static double angleWithX(Base::Vector3d inVec); static double incidenceAngleAtVertex(TopoDS_Edge e, TopoDS_Vertex v, double tolerance); static bool isFirstVert(TopoDS_Edge e, TopoDS_Vertex v, double tolerance = VERTEXTOLERANCE); @@ -259,6 +262,9 @@ public: static bool isCosmeticEdge(App::DocumentObject* owner, std::string element); static bool isCenterLine(App::DocumentObject* owner, std::string element); + static Base::Vector3d toAppSpace(const DrawViewPart& dvp, const Base::Vector3d& inPoint); + static Base::Vector3d toAppSpace(const DrawViewPart& dvp, const QPointF& inPoint); + //debugging routines static void dumpVertexes(const char* text, const TopoDS_Shape& s); static void dumpEdge(const char* label, int i, TopoDS_Edge e);