From 24da86c9133854b6cfccfa4294c171eaad7be6ce Mon Sep 17 00:00:00 2001 From: wandererfan Date: Tue, 4 Feb 2020 19:03:21 -0500 Subject: [PATCH] [TD]trap wrong selection for ArchSection --- src/Mod/TechDraw/App/DrawViewArch.cpp | 8 ++++++ src/Mod/TechDraw/Gui/Command.cpp | 39 +++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/src/Mod/TechDraw/App/DrawViewArch.cpp b/src/Mod/TechDraw/App/DrawViewArch.cpp index 8fd53be71a..ef471ac7f2 100644 --- a/src/Mod/TechDraw/App/DrawViewArch.cpp +++ b/src/Mod/TechDraw/App/DrawViewArch.cpp @@ -103,6 +103,14 @@ App::DocumentObjectExecReturn *DrawViewArch::execute(void) } App::DocumentObject* sourceObj = Source.getValue(); + //if (sourceObj is not ArchSection) return + App::Property* proxy = sourceObj->getPropertyByName("Proxy"); + if (proxy == nullptr) { + Base::Console().Error("DVA::execute - %s is not an ArchSection\n", sourceObj->Label.getValue()); + //this is definitely not an ArchSection + return DrawView::execute(); + } + if (sourceObj) { std::string svgFrag; std::string svgHead = getSVGHead(); diff --git a/src/Mod/TechDraw/Gui/Command.cpp b/src/Mod/TechDraw/Gui/Command.cpp index ec5c57d3a4..6434468041 100644 --- a/src/Mod/TechDraw/Gui/Command.cpp +++ b/src/Mod/TechDraw/Gui/Command.cpp @@ -30,7 +30,9 @@ #include +#include #include +#include #include #include #include @@ -1153,6 +1155,43 @@ void CmdTechDrawArchView::activated(int iMsg) QObject::tr("Select exactly one object.")); return; } + //if the docObj doesn't have a Proxy property, it definitely isn't an ArchSection + App::DocumentObject* frontObj = objects.front(); + App::Property* proxy = frontObj->getPropertyByName("Proxy"); + if (proxy == nullptr) { + QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), + QObject::tr("Selected object is not ArchSection.")); + return; + } + App::PropertyPythonObject* proxyPy = dynamic_cast(proxy); + Py::Object proxyObj = proxyPy->getValue(); + std::stringstream ss; + bool proceed = false; + if (proxyPy != nullptr) { + Base::PyGILStateLocker lock; + try { + if (proxyObj.hasAttr("__module__")) { + Py::String mod(proxyObj.getAttr("__module__")); + ss << (std::string)mod; + } + if (ss.str() == "ArchSectionPlane") { + proceed = true; + } + } + catch (Py::Exception&) { + Base::PyException e; // extract the Python error text + e.ReportException(); + proceed = false; + } + } else { + proceed = false; + } + + if (!proceed) { + QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), + QObject::tr("Selected object is not ArchSection.")); + return; + } std::string PageName = page->getNameInDocument();