From e9d988d43cbeec22d0cc52c60c2e5781b58db8fa Mon Sep 17 00:00:00 2001 From: wandererfan Date: Wed, 19 Oct 2022 14:39:21 -0400 Subject: [PATCH] [TD]expose DVP projectPoint to Python --- src/Mod/TechDraw/App/DrawViewPartPy.xml | 10 +++++++++- src/Mod/TechDraw/App/DrawViewPartPyImp.cpp | 14 ++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/Mod/TechDraw/App/DrawViewPartPy.xml b/src/Mod/TechDraw/App/DrawViewPartPy.xml index 52645d1ad9..e0fd128a37 100644 --- a/src/Mod/TechDraw/App/DrawViewPartPy.xml +++ b/src/Mod/TechDraw/App/DrawViewPartPy.xml @@ -148,7 +148,15 @@ getVertexBySelection(vertexName). Returns Part.TopoShape. - + + + projectPoint(vector3d point, [bool invert]). Returns the projection of point in the + projection coordinate system of this DrawViewPart. Optionally inverts the Y coordinate of the + result. + + + + requestPaint(). Redraw the graphic for this View. diff --git a/src/Mod/TechDraw/App/DrawViewPartPyImp.cpp b/src/Mod/TechDraw/App/DrawViewPartPyImp.cpp index cb9c9977fd..30d4469810 100644 --- a/src/Mod/TechDraw/App/DrawViewPartPyImp.cpp +++ b/src/Mod/TechDraw/App/DrawViewPartPyImp.cpp @@ -709,6 +709,20 @@ PyObject* DrawViewPartPy::getVertexBySelection(PyObject *args) return new Part::TopoShapeVertexPy(new Part::TopoShape(outVertex)); } +PyObject* DrawViewPartPy::projectPoint(PyObject *args) +{ + PyObject* pPoint = nullptr; + PyObject* pInvert = Py_False; + if (!PyArg_ParseTuple(args, "O!|O!", &(Base::VectorPy::Type), &pPoint, &PyBool_Type, &pInvert)) { + throw Py::TypeError("expected (vector)"); + } + + bool invert = Base::asBoolean(pInvert); + + DrawViewPart* dvp = getDrawViewPartPtr(); + Base::Vector3d projection = dvp->projectPoint(static_cast(pPoint)->value(), invert); + return new Base::VectorPy(new Base::Vector3d(projection)); +} //============================================================================== PyObject *DrawViewPartPy::getCustomAttributes(const char* /*attr*/) const