[TD]improve selection filtering for ArchSection

This commit is contained in:
wandererfan
2020-03-18 13:20:41 -04:00
committed by WandererFan
parent 55da881bc9
commit 197c0f799c
3 changed files with 95 additions and 48 deletions

View File

@@ -1157,56 +1157,34 @@ void CmdTechDrawArchView::activated(int iMsg)
TechDraw::DrawPage* page = DrawGuiUtil::findPage(this);
if (!page) {
return;
}
const std::vector<App::DocumentObject*> objects = getSelection().getObjectsOfType(App::DocumentObject::getClassTypeId());
if (objects.size() != 1) {
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
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<App::PropertyPythonObject*>(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();
const std::vector<App::DocumentObject*> objects = getSelection().
getObjectsOfType(App::DocumentObject::getClassTypeId());
App::DocumentObject* archObject = nullptr;
int archCount = 0;
for (auto& obj : objects) {
if (DrawGuiUtil::isArchSection(obj) ) {
archCount++;
archObject = obj;
}
}
if ( archCount > 1 ) {
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
QObject::tr("Please select only 1 Arch Section."));
return;
}
if (archObject == nullptr) {
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
QObject::tr("No Arch Sections in selection."));
return;
}
std::string FeatName = getUniqueObjectName("ArchView");
std::string SourceName = objects.front()->getNameInDocument();
std::string SourceName = archObject->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());