Skip to content

Commit

Permalink
Fix add ArchSection w/ multiple Pages
Browse files Browse the repository at this point in the history
  • Loading branch information
WandererFan authored and wwmayer committed Apr 22, 2018
1 parent dc79d41 commit 5d1fa67
Showing 1 changed file with 28 additions and 8 deletions.
36 changes: 28 additions & 8 deletions src/Mod/TechDraw/Gui/Command.cpp
Expand Up @@ -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)
Expand Down Expand Up @@ -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<App::DocumentObject*> objects = getSelection().getObjectsOfType(App::DocumentObject::getClassTypeId());
if (objects.empty()) {
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
Expand All @@ -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
//===========================================================================
Expand Down Expand Up @@ -922,23 +932,33 @@ void CmdTechDrawArchView::activated(int iMsg)
}

std::vector<App::DocumentObject*> 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());
Expand Down

0 comments on commit 5d1fa67

Please sign in to comment.