diff --git a/src/Mod/TechDraw/App/DrawGeomHatch.cpp b/src/Mod/TechDraw/App/DrawGeomHatch.cpp index f524d8f1d3..8713999a9d 100644 --- a/src/Mod/TechDraw/App/DrawGeomHatch.cpp +++ b/src/Mod/TechDraw/App/DrawGeomHatch.cpp @@ -64,6 +64,7 @@ using namespace TechDraw; +using DU = DrawUtil; App::PropertyFloatConstraint::Constraints DrawGeomHatch::scaleRange = { Precision::Confusion(), std::numeric_limits::max(), (0.1)}; // increment by 0.1 @@ -577,6 +578,13 @@ TopoDS_Face DrawGeomHatch::extractFace(DrawViewPart* source, int iface ) return TopoDS::Face(temp); } +//! get a translated label string from the context (ex TaskActiveView), the base name (ex ActiveView) and +//! the unique name within the document (ex ActiveView001), and use it to update the Label property. +void DrawGeomHatch::translateLabel(std::string context, std::string baseName, std::string uniqueName) +{ + Label.setValue(DU::translateArbitrary(context, baseName, uniqueName)); +} + //-------------------------------------------------------------------------------------------------- PyObject *DrawGeomHatch::getPyObject() diff --git a/src/Mod/TechDraw/App/DrawGeomHatch.h b/src/Mod/TechDraw/App/DrawGeomHatch.h index 55e8c0fc7d..165696e68b 100644 --- a/src/Mod/TechDraw/App/DrawGeomHatch.h +++ b/src/Mod/TechDraw/App/DrawGeomHatch.h @@ -103,6 +103,8 @@ public: static App::Color prefGeomHatchColor(); static std::vector makeLineSets(std::string fileSpec, std::string myPattern); + void translateLabel(std::string context, std::string baseName, std::string uniqueName); + protected: void replacePatIncluded(std::string newHatchFileName); diff --git a/src/Mod/TechDraw/App/DrawGeomHatchPy.xml b/src/Mod/TechDraw/App/DrawGeomHatchPy.xml index 8cedf84241..c061dd0812 100644 --- a/src/Mod/TechDraw/App/DrawGeomHatchPy.xml +++ b/src/Mod/TechDraw/App/DrawGeomHatchPy.xml @@ -13,6 +13,13 @@ Feature for creating and manipulating Technical Drawing GeomHatch areas + + + translateLabel(translationContext, objectBaseName, objectUniqueName). + No return value. Replace the current label with a translated version where possible. + + + diff --git a/src/Mod/TechDraw/App/DrawGeomHatchPyImp.cpp b/src/Mod/TechDraw/App/DrawGeomHatchPyImp.cpp index 61c460393e..fc434573f7 100644 --- a/src/Mod/TechDraw/App/DrawGeomHatchPyImp.cpp +++ b/src/Mod/TechDraw/App/DrawGeomHatchPyImp.cpp @@ -34,10 +34,48 @@ std::string DrawGeomHatchPy::representation() const return std::string(""); } +//! replace the current Label with a translated version +PyObject* DrawGeomHatchPy::translateLabel(PyObject *args) +{ + PyObject* pyContext; + PyObject* pyBaseName; + PyObject* pyUniqueName; + std::string context; + std::string baseName; + std::string uniqueName; + if (!PyArg_ParseTuple(args, "OOO", &pyContext, &pyBaseName, &pyUniqueName)) { + throw Py::TypeError("Could not translate label - bad parameters."); + } + Py_ssize_t size = 0; + const char* cContext = PyUnicode_AsUTF8AndSize(pyContext, &size); + if (cContext) { + context = std::string(cContext, size); + } else { + throw Py::TypeError("Could not translate label - context not available."); + } + const char* cBaseName = PyUnicode_AsUTF8AndSize(pyBaseName, &size); + if (cBaseName) { + baseName = std::string(cBaseName, size); + } else { + throw Py::TypeError("Could not translate label - base name not available."); + } + const char* cUniqueName = PyUnicode_AsUTF8AndSize(pyUniqueName, &size); + if (cUniqueName) { + uniqueName = std::string(cUniqueName, size); + } else { + throw Py::TypeError("Could not translate label - unique name not available."); + } + + // we have the 3 parameters we need for DrawView::translateLabel + DrawGeomHatch* dgh = getDrawGeomHatchPtr(); + dgh->translateLabel(context, baseName, uniqueName); + + Py_Return; +} PyObject *DrawGeomHatchPy::getCustomAttributes(const char* /*attr*/) const diff --git a/src/Mod/TechDraw/App/DrawHatch.cpp b/src/Mod/TechDraw/App/DrawHatch.cpp index 162988decb..3a7528e224 100644 --- a/src/Mod/TechDraw/App/DrawHatch.cpp +++ b/src/Mod/TechDraw/App/DrawHatch.cpp @@ -41,6 +41,7 @@ using namespace TechDraw; +using DU = DrawUtil; PROPERTY_SOURCE(TechDraw::DrawHatch, App::DocumentObject) @@ -201,6 +202,13 @@ bool DrawHatch::isBitmapHatch(void) const return fi.hasExtension({"bmp", "png", "jpg", "jpeg"}); } +//! get a translated label string from the context (ex TaskActiveView), the base name (ex ActiveView) and +//! the unique name within the document (ex ActiveView001), and use it to update the Label property. +void DrawHatch::translateLabel(std::string context, std::string baseName, std::string uniqueName) +{ + Label.setValue(DU::translateArbitrary(context, baseName, uniqueName)); +} + //standard preference getters std::string DrawHatch::prefSvgHatch(void) { diff --git a/src/Mod/TechDraw/App/DrawHatch.h b/src/Mod/TechDraw/App/DrawHatch.h index 9bf97a4a4b..b856da157d 100644 --- a/src/Mod/TechDraw/App/DrawHatch.h +++ b/src/Mod/TechDraw/App/DrawHatch.h @@ -72,6 +72,8 @@ public: bool isSvgHatch() const; bool isBitmapHatch() const; + void translateLabel(std::string context, std::string baseName, std::string uniqueName); + protected: void onChanged(const App::Property* prop) override; void replaceFileIncluded(std::string newSvgFile); diff --git a/src/Mod/TechDraw/App/DrawHatchPy.xml b/src/Mod/TechDraw/App/DrawHatchPy.xml index 46df058060..835b6acbdc 100644 --- a/src/Mod/TechDraw/App/DrawHatchPy.xml +++ b/src/Mod/TechDraw/App/DrawHatchPy.xml @@ -13,6 +13,13 @@ Feature for creating and manipulating Technical Drawing Hatch areas + + + translateLabel(translationContext, objectBaseName, objectUniqueName). + No return value. Replace the current label with a translated version where possible. + + + diff --git a/src/Mod/TechDraw/App/DrawHatchPyImp.cpp b/src/Mod/TechDraw/App/DrawHatchPyImp.cpp index 14e8a90366..c80f570659 100644 --- a/src/Mod/TechDraw/App/DrawHatchPyImp.cpp +++ b/src/Mod/TechDraw/App/DrawHatchPyImp.cpp @@ -35,6 +35,48 @@ std::string DrawHatchPy::representation() const { return std::string(""); } +//! replace the current Label with a translated version +PyObject* DrawHatchPy::translateLabel(PyObject *args) +{ + PyObject* pyContext; + PyObject* pyBaseName; + PyObject* pyUniqueName; + std::string context; + std::string baseName; + std::string uniqueName; + + if (!PyArg_ParseTuple(args, "OOO", &pyContext, &pyBaseName, &pyUniqueName)) { + throw Py::TypeError("Could not translate label - bad parameters."); + } + + Py_ssize_t size = 0; + const char* cContext = PyUnicode_AsUTF8AndSize(pyContext, &size); + if (cContext) { + context = std::string(cContext, size); + } else { + throw Py::TypeError("Could not translate label - context not available."); + } + + const char* cBaseName = PyUnicode_AsUTF8AndSize(pyBaseName, &size); + if (cBaseName) { + baseName = std::string(cBaseName, size); + } else { + throw Py::TypeError("Could not translate label - base name not available."); + } + + const char* cUniqueName = PyUnicode_AsUTF8AndSize(pyUniqueName, &size); + if (cUniqueName) { + uniqueName = std::string(cUniqueName, size); + } else { + throw Py::TypeError("Could not translate label - unique name not available."); + } + + // we have the 3 parameters we need for DrawView::translateLabel + DrawHatch* dh = getDrawHatchPtr(); + dh->translateLabel(context, baseName, uniqueName); + + Py_Return; +} PyObject *DrawHatchPy::getCustomAttributes(const char* /*attr*/) const {