From 707ef236f3da6c1f57cee0b470e3296a10439e87 Mon Sep 17 00:00:00 2001 From: WandererFan Date: Thu, 28 Jan 2016 12:43:51 -0500 Subject: [PATCH] Add Python functionality for DrawHatch --- src/Mod/TechDraw/App/CMakeLists.txt | 4 ++- src/Mod/TechDraw/App/DrawHatch.cpp | 11 ++++++++ src/Mod/TechDraw/App/DrawHatch.h | 5 ++-- src/Mod/TechDraw/App/DrawHatchPy.xml | 18 +++++++++++++ src/Mod/TechDraw/App/DrawHatchPyImp.cpp | 32 ++++++++++++++++++++++++ src/Mod/TechDraw/App/DrawPage.cpp | 4 +-- src/Mod/TechDraw/Gui/CommandDecorate.cpp | 15 ++++++----- 7 files changed, 77 insertions(+), 12 deletions(-) create mode 100644 src/Mod/TechDraw/App/DrawHatchPy.xml create mode 100644 src/Mod/TechDraw/App/DrawHatchPyImp.cpp diff --git a/src/Mod/TechDraw/App/CMakeLists.txt b/src/Mod/TechDraw/App/CMakeLists.txt index 28ef1079e..7ebb8bd97 100644 --- a/src/Mod/TechDraw/App/CMakeLists.txt +++ b/src/Mod/TechDraw/App/CMakeLists.txt @@ -35,6 +35,7 @@ generate_from_xml(DrawSVGTemplatePy) generate_from_xml(DrawViewSymbolPy) generate_from_xml(DrawViewClipPy) generate_from_xml(DrawViewDimensionPy) +generate_from_xml(DrawHatchPy) SET(Draw_SRCS DrawPage.cpp @@ -104,7 +105,8 @@ SET(Python_SRCS DrawViewClipPyImp.cpp DrawViewDimensionPy.xml DrawViewDimensionPyImp.cpp -) + DrawHatchPy.xml + DrawHatchPyImp.cpp) SOURCE_GROUP("Mod" FILES ${TechDraw_SRCS}) SOURCE_GROUP("Features" FILES ${Draw_SRCS}) diff --git a/src/Mod/TechDraw/App/DrawHatch.cpp b/src/Mod/TechDraw/App/DrawHatch.cpp index 7a62b18a2..f6411efa9 100644 --- a/src/Mod/TechDraw/App/DrawHatch.cpp +++ b/src/Mod/TechDraw/App/DrawHatch.cpp @@ -37,6 +37,8 @@ #include "DrawHatch.h" +#include "DrawHatchPy.h" // generated from DrawHatchPy.xml + using namespace TechDraw; using namespace std; @@ -97,6 +99,15 @@ App::DocumentObjectExecReturn *DrawHatch::execute(void) return App::DocumentObject::StdReturn; } +PyObject *DrawHatch::getPyObject(void) +{ + if (PythonObject.is(Py::_None())) { + // ref counter is set to 1 + PythonObject = Py::Object(new DrawHatchPy(this),true); + } + return Py::new_reference_to(PythonObject); +} + // Python Drawing feature --------------------------------------------------------- namespace App { diff --git a/src/Mod/TechDraw/App/DrawHatch.h b/src/Mod/TechDraw/App/DrawHatch.h index 4fb6f576f..5adef7bfb 100644 --- a/src/Mod/TechDraw/App/DrawHatch.h +++ b/src/Mod/TechDraw/App/DrawHatch.h @@ -55,9 +55,8 @@ public: virtual const char* getViewProviderName(void) const { return "TechDrawGui::ViewProviderHatch"; } - - //DrawViewPart* getViewPart() const; - + //return PyObject as DrawHatchPy + virtual PyObject *getPyObject(void); protected: void onChanged(const App::Property* prop); diff --git a/src/Mod/TechDraw/App/DrawHatchPy.xml b/src/Mod/TechDraw/App/DrawHatchPy.xml new file mode 100644 index 000000000..bce289344 --- /dev/null +++ b/src/Mod/TechDraw/App/DrawHatchPy.xml @@ -0,0 +1,18 @@ + + + + + + Feature for creating and manipulating Technical Drawing Hatch areas + + + + diff --git a/src/Mod/TechDraw/App/DrawHatchPyImp.cpp b/src/Mod/TechDraw/App/DrawHatchPyImp.cpp new file mode 100644 index 000000000..3ff2e1ac6 --- /dev/null +++ b/src/Mod/TechDraw/App/DrawHatchPyImp.cpp @@ -0,0 +1,32 @@ + +#include "PreCompiled.h" + +#include "Mod/TechDraw/App/DrawHatch.h" + +// inclusion of the generated files (generated out of DrawHatchPy.xml) +#include "DrawHatchPy.h" +#include "DrawHatchPy.cpp" + +using namespace TechDraw; + +// returns a string which represents the object e.g. when printed in python +std::string DrawHatchPy::representation(void) const +{ + return std::string(""); +} + + + + + + + +PyObject *DrawHatchPy::getCustomAttributes(const char* /*attr*/) const +{ + return 0; +} + +int DrawHatchPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/) +{ + return 0; +} diff --git a/src/Mod/TechDraw/App/DrawPage.cpp b/src/Mod/TechDraw/App/DrawPage.cpp index 942d3db81..ac134b025 100644 --- a/src/Mod/TechDraw/App/DrawPage.cpp +++ b/src/Mod/TechDraw/App/DrawPage.cpp @@ -72,6 +72,7 @@ DrawPage::DrawPage(void) ProjectionType.setEnums(ProjectionTypeEnums); ADD_PROPERTY(ProjectionType, ((long)0)); ADD_PROPERTY_TYPE(Scale ,(1.0), group, App::Prop_None, "Scale factor for this Page"); + //TODO: Page should create itself with default Template instead of Cmd figuring it out? } DrawPage::~DrawPage() @@ -156,7 +157,7 @@ PyObject *DrawPage::getPyObject(void) PythonObject = Py::Object(new DrawPagePy(this),true); } - return Py::new_reference_to(PythonObject); + return Py::new_reference_to(PythonObject); } bool DrawPage::hasValidTemplate() const @@ -272,4 +273,3 @@ void DrawPage::onDocumentRestored() recompute(); App::DocumentObject::onDocumentRestored(); } - diff --git a/src/Mod/TechDraw/Gui/CommandDecorate.cpp b/src/Mod/TechDraw/Gui/CommandDecorate.cpp index 3ad8b1c53..b7a728601 100644 --- a/src/Mod/TechDraw/Gui/CommandDecorate.cpp +++ b/src/Mod/TechDraw/Gui/CommandDecorate.cpp @@ -98,19 +98,22 @@ void CmdTechDrawNewHatch::activated(int iMsg) subs.push_back((*itSub)); } + //TODO: this should be the active page or a selected page? not first page + std::vector pages = getDocument()->getObjectsOfType(TechDraw::DrawPage::getClassTypeId()); + TechDraw::DrawPage *page = dynamic_cast(pages.front()); + std::string PageName = page->getNameInDocument(); + openCommand("Create Hatch"); doCommand(Doc,"App.activeDocument().addObject('TechDraw::DrawHatch','%s')",FeatName.c_str()); doCommand(Doc,"App.activeDocument().%s.PartView = App.activeDocument().%s",FeatName.c_str(),objFeat->getNameInDocument()); - commitCommand(); hatch = dynamic_cast(getDocument()->getObject(FeatName.c_str())); hatch->Edges.setValues(objs, subs); + //should this be: doCommand(Doc,"App..Feat..Edges = [(App...%s,%s),(App..%s,%s),...]",objs[0]->getNameInDocument(),subs[0],...); + //seems very unwieldy - hatch->execute(); - - std::vector pages = getDocument()->getObjectsOfType(TechDraw::DrawPage::getClassTypeId()); - TechDraw::DrawPage *page = dynamic_cast(pages.front()); - page->addView(page->getDocument()->getObject(FeatName.c_str())); + doCommand(Doc,"App.activeDocument().%s.addView(App.activeDocument().%s)",PageName.c_str(),FeatName.c_str()); + commitCommand(); //Horrible hack to force Tree update ??still required?? double x = objFeat->X.getValue();