Fix add ArchSection w/ multiple Pages

This commit is contained in:
wandererfan
2018-04-20 11:18:45 -04:00
committed by wmayer
parent dc79d4172d
commit 5d1fa67230

View File

@@ -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<App::DocumentObject*> 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<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());