[TD]fix hatch fail due to missing translate method
This commit is contained in:
@@ -64,6 +64,7 @@
|
||||
|
||||
|
||||
using namespace TechDraw;
|
||||
using DU = DrawUtil;
|
||||
|
||||
App::PropertyFloatConstraint::Constraints DrawGeomHatch::scaleRange = {
|
||||
Precision::Confusion(), std::numeric_limits<double>::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()
|
||||
|
||||
@@ -103,6 +103,8 @@ public:
|
||||
static App::Color prefGeomHatchColor();
|
||||
static std::vector<LineSet> makeLineSets(std::string fileSpec, std::string myPattern);
|
||||
|
||||
void translateLabel(std::string context, std::string baseName, std::string uniqueName);
|
||||
|
||||
protected:
|
||||
void replacePatIncluded(std::string newHatchFileName);
|
||||
|
||||
|
||||
@@ -13,6 +13,13 @@
|
||||
<Author Licence="LGPL" Name="WandererFan" EMail="wandererfan@gmail.com" />
|
||||
<UserDocu>Feature for creating and manipulating Technical Drawing GeomHatch areas</UserDocu>
|
||||
</Documentation>
|
||||
<Methode Name="translateLabel">
|
||||
<Documentation>
|
||||
<UserDocu>translateLabel(translationContext, objectBaseName, objectUniqueName).
|
||||
No return value. Replace the current label with a translated version where possible.
|
||||
</UserDocu>
|
||||
</Documentation>
|
||||
</Methode>
|
||||
<CustomAttributes />
|
||||
</PythonExport>
|
||||
</GenerateModel>
|
||||
|
||||
@@ -34,10 +34,48 @@ std::string DrawGeomHatchPy::representation() const
|
||||
return std::string("<DrawGeomHatch object>");
|
||||
}
|
||||
|
||||
//! 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
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -13,6 +13,13 @@
|
||||
<Author Licence="LGPL" Name="WandererFan" EMail="wandererfan@gmail.com" />
|
||||
<UserDocu>Feature for creating and manipulating Technical Drawing Hatch areas</UserDocu>
|
||||
</Documentation>
|
||||
<Methode Name="translateLabel">
|
||||
<Documentation>
|
||||
<UserDocu>translateLabel(translationContext, objectBaseName, objectUniqueName).
|
||||
No return value. Replace the current label with a translated version where possible.
|
||||
</UserDocu>
|
||||
</Documentation>
|
||||
</Methode>
|
||||
<CustomAttributes />
|
||||
</PythonExport>
|
||||
</GenerateModel>
|
||||
|
||||
@@ -35,6 +35,48 @@ std::string DrawHatchPy::representation() const
|
||||
{
|
||||
return std::string("<DrawHatch object>");
|
||||
}
|
||||
//! 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
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user