diff --git a/src/Mod/TechDraw/App/AppTechDrawPy.cpp b/src/Mod/TechDraw/App/AppTechDrawPy.cpp index 695744ff43..fea87becfe 100644 --- a/src/Mod/TechDraw/App/AppTechDrawPy.cpp +++ b/src/Mod/TechDraw/App/AppTechDrawPy.cpp @@ -192,6 +192,10 @@ public: add_varargs_method("makeLeader", &Module::makeLeader, "makeLeader(parent - DrawViewPart, points - [Vector], startSymbol - int, endSymbol - int) - Creates a leader line attached to parent. Points are in page coordinates with (0, 0) at lowerleft.s" ); + add_varargs_method("nearestFraction", &Module::nearestFraction, + "nearestFraction(float) - returns the numeration and denominator of the nearest fraction as a tuple." + ); + initialize("This is a module for making drawings"); // register with Python } ~Module() override {} @@ -1348,6 +1352,18 @@ private: return Py::asObject(new DrawLeaderLinePy(newLeader)); } + Py::Object nearestFraction(const Py::Tuple& args) + { + double valueWithDecimals{0.0}; + if (!PyArg_ParseTuple(args.ptr(), "d", &valueWithDecimals)) { + throw Py::TypeError("expected (valueWithDecimals)"); + } + + std::pair numAndDen = DrawUtil::nearestFraction(valueWithDecimals); + PyObject* pyNumAndDen = Py_BuildValue("(ii)", numAndDen.first, numAndDen.second); + return Py::asObject(pyNumAndDen); + } + }; PyObject* initModule()