[TD]improve selection filtering for ArchSection

This commit is contained in:
wandererfan
2020-03-18 13:20:41 -04:00
committed by WandererFan
parent 75e1ed95d0
commit 71192a9129
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());

View File

@@ -96,7 +96,6 @@ void DrawGuiUtil::loadArrowBox(QComboBox* qcb)
}
}
//===========================================================================
// validate helper routines
//===========================================================================
@@ -182,6 +181,72 @@ bool DrawGuiUtil::isDraftObject(App::DocumentObject* obj)
return result;
}
bool DrawGuiUtil::isArchObject(App::DocumentObject* obj)
{
bool result = false;
App::Property* proxy = obj->getPropertyByName("Proxy");
if (proxy != nullptr) {
//if no proxy, can not be Arch obj
//if has proxy, might be Arch obj
App::PropertyPythonObject* proxyPy = dynamic_cast<App::PropertyPythonObject*>(proxy);
Py::Object proxyObj = proxyPy->getValue();
std::stringstream ss;
if (proxyPy != nullptr) {
Base::PyGILStateLocker lock;
try {
if (proxyObj.hasAttr("__module__")) {
Py::String mod(proxyObj.getAttr("__module__"));
ss << (std::string)mod;
//does this have to be an ArchSection, or can it be any Arch object?
if (ss.str().find("Arch") != std::string::npos) {
result = true;
}
}
}
catch (Py::Exception&) {
Base::PyException e; // extract the Python error text
e.ReportException();
result = false;
}
}
}
return result;
}
bool DrawGuiUtil::isArchSection(App::DocumentObject* obj)
{
bool result = false;
App::Property* proxy = obj->getPropertyByName("Proxy");
if (proxy != nullptr) {
//if no proxy, can not be Arch obj
//if has proxy, might be Arch obj
App::PropertyPythonObject* proxyPy = dynamic_cast<App::PropertyPythonObject*>(proxy);
Py::Object proxyObj = proxyPy->getValue();
std::stringstream ss;
if (proxyPy != nullptr) {
Base::PyGILStateLocker lock;
try {
if (proxyObj.hasAttr("__module__")) {
Py::String mod(proxyObj.getAttr("__module__"));
ss << (std::string)mod;
//does this have to be an ArchSection, or can it be other Arch objects?
if (ss.str().find("ArchSectionPlane") != std::string::npos) {
result = true;
}
}
}
catch (Py::Exception&) {
Base::PyException e; // extract the Python error text
e.ReportException();
result = false;
}
}
}
return result;
}
bool DrawGuiUtil::needPage(Gui::Command* cmd)
{
//need a Document and a Page

View File

@@ -53,7 +53,11 @@ class TechDrawGuiExport DrawGuiUtil {
Q_DECLARE_TR_FUNCTIONS(TechDrawGui::DrawGuiUtil)
public:
static TechDraw::DrawPage* findPage(Gui::Command* cmd);
static bool isDraftObject(App::DocumentObject* obj);
static bool isArchObject(App::DocumentObject* obj);
static bool isArchSection(App::DocumentObject* obj);
static bool needPage(Gui::Command* cmd);
static bool needView(Gui::Command* cmd, bool partOnly = true);
static void dumpRectF(const char* text, const QRectF& r);