From 5d1fa6723061efdab389d004ceb5c5508aaec20d Mon Sep 17 00:00:00 2001 From: wandererfan Date: Fri, 20 Apr 2018 11:18:45 -0400 Subject: [PATCH] Fix add ArchSection w/ multiple Pages --- src/Mod/TechDraw/Gui/Command.cpp | 36 +++++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/src/Mod/TechDraw/Gui/Command.cpp b/src/Mod/TechDraw/Gui/Command.cpp index f673b76984..fd2e2a9617 100644 --- a/src/Mod/TechDraw/Gui/Command.cpp +++ b/src/Mod/TechDraw/Gui/Command.cpp @@ -78,6 +78,16 @@ using namespace TechDrawGui; using namespace std; +bool isArchSection(App::DocumentObject* obj) +{ + bool result = true; + App::Property* prop1 = obj->getPropertyByName("Objects"); + App::Property* prop2 = obj->getPropertyByName("OnlySolids"); + if ( (!prop1) || (!prop2) ) { + result = false; + } + return result; +} //=========================================================================== // TechDraw_NewPageDef (default template) @@ -869,6 +879,7 @@ void CmdTechDrawDraftView::activated(int iMsg) } //TODO: shouldn't this be checking for a Draft object only? +// there is no obvious way of check for a Draft object. Could be App::FeaturePython, Part::Part2DObject, ??? std::vector objects = getSelection().getObjectsOfType(App::DocumentObject::getClassTypeId()); if (objects.empty()) { QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), @@ -894,7 +905,6 @@ bool CmdTechDrawDraftView::isActive(void) return DrawGuiUtil::needPage(this); } -//TODO: shouldn't this be checking for an Arch object only? //=========================================================================== // TechDraw_ArchView //=========================================================================== @@ -922,23 +932,33 @@ void CmdTechDrawArchView::activated(int iMsg) } std::vector objects = getSelection().getObjectsOfType(App::DocumentObject::getClassTypeId()); - if (objects.size() != 1) { + if (objects.empty()) { QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), - QObject::tr("Select exactly one Arch Section Plane object.")); + QObject::tr("Select at least one object.")); return; } - App::Property* prop1 = objects[0]->getPropertyByName("Objects"); - App::Property* prop2 = objects[0]->getPropertyByName("OnlySolids"); - if ( (!prop1) || (!prop2) ) { + int ifound = 0; + bool found = false; + for (auto& obj: objects) { + if (isArchSection(obj)) { + found = true; + break; + } + ifound++; + } + App::DocumentObject* archObj; + if (found) { + archObj = objects[ifound]; + } else { QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), - QObject::tr("The selected object is not an Arch Section Plane.")); + QObject::tr("There is no Arch Section Plane in selection.")); return; } std::string PageName = page->getNameInDocument(); std::string FeatName = getUniqueObjectName("ArchView"); - std::string SourceName = objects[0]->getNameInDocument(); + std::string SourceName = archObj->getNameInDocument(); openCommand("Create ArchView"); doCommand(Doc,"App.activeDocument().addObject('TechDraw::DrawViewArch','%s')",FeatName.c_str()); doCommand(Doc,"App.activeDocument().%s.Source = App.activeDocument().%s",FeatName.c_str(),SourceName.c_str());