[TD]Add method to translate View labels

This commit is contained in:
wandererfan
2023-08-16 11:40:42 -04:00
committed by WandererFan
parent ad8177c9fa
commit f4180658dc
4 changed files with 70 additions and 2 deletions

View File

@@ -27,7 +27,6 @@
#include <Mod/TechDraw/App/DrawViewPy.h>
#include <Mod/TechDraw/App/DrawViewPy.cpp>
using namespace TechDraw;
// returns a string which represents the object e.g. when printed in python
@@ -36,6 +35,49 @@ std::string DrawViewPy::representation(void) const
return std::string("<DrawView object>");
}
//! replace the current Label with a translated version
PyObject* DrawViewPy::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
DrawView* dv = getDrawViewPtr();
dv->translateLabel(context, baseName, uniqueName);
Py_Return;
}
PyObject *DrawViewPy::getCustomAttributes(const char* /*attr*/) const
{