Add dumpSymbol method to DrawViewSymbol based classes

- this is mainly for debugging output from Arch/Draft
This commit is contained in:
WandererFan
2017-08-27 20:43:09 -04:00
committed by wmayer
parent 31535e9b53
commit 481008629b
4 changed files with 48 additions and 1 deletions

View File

@@ -38,6 +38,8 @@
#include "DrawPage.h"
#include "DrawViewSymbol.h"
#include <Mod/TechDraw/App/DrawViewSymbolPy.h> // generated from DrawViewSymbolPy.xml
using namespace TechDraw;
using namespace std;
@@ -158,7 +160,14 @@ bool DrawViewSymbol::checkFit(TechDraw::DrawPage* p) const
return result;
}
PyObject *DrawViewSymbol::getPyObject(void)
{
if (PythonObject.is(Py::_None())) {
// ref counter is set to 1
PythonObject = Py::Object(new DrawViewSymbolPy(this),true);
}
return Py::new_reference_to(PythonObject);
}
// Python Drawing feature ---------------------------------------------------------

View File

@@ -60,6 +60,9 @@ public:
virtual QRectF getRect() const override;
virtual bool checkFit(TechDraw::DrawPage* p) const override;
//return PyObject as DrawViewSymbolPy
virtual PyObject *getPyObject(void);
protected:
virtual void onChanged(const App::Property* prop) override;

View File

@@ -13,6 +13,11 @@
<Author Licence="LGPL" Name="WandererFan" EMail="wandererfan@gmail.com" />
<UserDocu>Feature for creating and manipulating Drawing SVG Symbol Views</UserDocu>
</Documentation>
<Methode Name="dumpSymbol">
<Documentation>
<UserDocu>dumpSymbol(fileSpec) - dump the contents of Symbol to a file</UserDocu>
</Documentation>
</Methode>
<CustomAttributes />
</PythonExport>
</GenerateModel>

View File

@@ -1,6 +1,10 @@
#include "PreCompiled.h"
#include <Base/Console.h>
#include <Base/FileInfo.h>
#include <Base/Stream.h>
#include "DrawViewSymbol.h"
#include "DrawView.h"
@@ -17,6 +21,32 @@ std::string DrawViewSymbolPy::representation(void) const
return std::string("<DrawViewSymbol object>");
}
PyObject* DrawViewSymbolPy::dumpSymbol(PyObject *args)
{
const char* fileSpec;
if (!PyArg_ParseTuple(args, "s", &fileSpec)) {
throw Py::TypeError("** dumpSymbol bad args.");
}
auto dvs = getDrawViewSymbolPtr();
std::string symbolRepr;
if (dvs != nullptr) {
symbolRepr = dvs->Symbol.getValue();
}
Base::FileInfo fi(fileSpec);
std::ofstream outfile;
outfile.open(fi.filePath());
outfile.write (symbolRepr.c_str(),symbolRepr.size());
outfile.close();
if (outfile.good()) {
outfile.close();
} else {
std::string error = std::string("Can't write ");
error += fileSpec;
throw Py::Exception(error);
}
Py_Return;
}
PyObject *DrawViewSymbolPy::getCustomAttributes(const char* /*attr*/) const
{