From 718dd707fa24716bbfbb8e508eb5231b12edea73 Mon Sep 17 00:00:00 2001 From: wandererfan Date: Fri, 15 May 2020 16:34:21 -0400 Subject: [PATCH] [TD]Getters/Setters for CosmeticVertex attribs --- src/Mod/TechDraw/App/CosmeticVertexPy.xml | 19 +++++- src/Mod/TechDraw/App/CosmeticVertexPyImp.cpp | 65 ++++++++++++++++++++ 2 files changed, 83 insertions(+), 1 deletion(-) diff --git a/src/Mod/TechDraw/App/CosmeticVertexPy.xml b/src/Mod/TechDraw/App/CosmeticVertexPy.xml index bccca58862..038ebbcd40 100644 --- a/src/Mod/TechDraw/App/CosmeticVertexPy.xml +++ b/src/Mod/TechDraw/App/CosmeticVertexPy.xml @@ -43,6 +43,23 @@ - + + + set/return the vertex's colour using a tuple (rgba). + + + + + + set/return the vertex's radius in mm. + + + + + + set/return the vertex's style as integer. + + + diff --git a/src/Mod/TechDraw/App/CosmeticVertexPyImp.cpp b/src/Mod/TechDraw/App/CosmeticVertexPyImp.cpp index 3fbb9444f3..f5e55a6137 100644 --- a/src/Mod/TechDraw/App/CosmeticVertexPyImp.cpp +++ b/src/Mod/TechDraw/App/CosmeticVertexPyImp.cpp @@ -168,6 +168,71 @@ void CosmeticVertexPy::setShow(Py::Boolean arg) } } +Py::Object CosmeticVertexPy::getColor(void) const +{ + App::Color color = getCosmeticVertexPtr()->color; + PyObject* pyColor = DrawUtil::colorToPyTuple(color); + return Py::asObject(pyColor); +} + +void CosmeticVertexPy::setColor(Py::Object arg) +{ + PyObject* pTuple = arg.ptr(); + double red = 0.0, green = 0.0, blue = 0.0, alpha = 0.0; + App::Color c(red, green, blue, alpha); + if (PyTuple_Check(pTuple)) { + c = DrawUtil::pyTupleToColor(pTuple); + CosmeticVertex* cv = getCosmeticVertexPtr(); + cv->color = c; + } else { + Base::Console().Error("CEPI::setColor - not a tuple!\n"); + std::string error = std::string("type must be 'tuple', not "); + error += pTuple->ob_type->tp_name; + throw Py::TypeError(error); + } +} + +Py::Object CosmeticVertexPy::getSize(void) const +{ + CosmeticVertex* cv = getCosmeticVertexPtr(); + double size = cv->size; + PyObject* pSize = PyFloat_FromDouble(size); + return Py::asObject(pSize); +} + +void CosmeticVertexPy::setSize(Py::Object arg) +{ + double size = 1.0; + PyObject* p = arg.ptr(); + if (PyFloat_Check(p)) { + size = PyFloat_AsDouble(p); + } else { + throw Py::TypeError("expected (float)"); + } + CosmeticVertex* cv = getCosmeticVertexPtr(); + cv->size = size; +} + +Py::Object CosmeticVertexPy::getStyle(void) const +{ + CosmeticVertex* cv = getCosmeticVertexPtr(); + double style = cv->style; + PyObject* pStyle = PyLong_FromLong((long) style); + return Py::asObject(pStyle); +} + +void CosmeticVertexPy::setStyle(Py::Object arg) +{ + int style = 1; + PyObject* p = arg.ptr(); + if (PyLong_Check(p)) { + style = (int) PyLong_AsLong(p); + } else { + throw Py::TypeError("expected (float)"); + } + CosmeticVertex* cv = getCosmeticVertexPtr(); + cv->style = style; +} PyObject *CosmeticVertexPy::getCustomAttributes(const char* /*attr*/) const {