Skip to content

Commit

Permalink
[TD]improve selection filtering for ArchSection
Browse files Browse the repository at this point in the history
  • Loading branch information
WandererFan committed Mar 19, 2020
1 parent 55da881 commit 197c0f7
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 41 deletions.
58 changes: 18 additions & 40 deletions src/Mod/TechDraw/Gui/Command.cpp
Expand Up @@ -1157,56 +1157,34 @@ void CmdTechDrawArchView::activated(int iMsg)
TechDraw::DrawPage* page = DrawGuiUtil::findPage(this);
if (!page) {
return;
}
}
std::string PageName = page->getNameInDocument();

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;

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 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) {
if ( archCount > 1 ) {
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
QObject::tr("Selected object is not ArchSection."));
QObject::tr("Please select only 1 Arch Section."));
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) {

if (archObject == nullptr) {
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
QObject::tr("Selected object is not ArchSection."));
QObject::tr("No Arch Sections in selection."));
return;
}

std::string PageName = page->getNameInDocument();

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());
Expand Down
67 changes: 66 additions & 1 deletion src/Mod/TechDraw/Gui/DrawGuiUtil.cpp
Expand Up @@ -96,7 +96,6 @@ void DrawGuiUtil::loadArrowBox(QComboBox* qcb)
}
}


//===========================================================================
// validate helper routines
//===========================================================================
Expand Down Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions src/Mod/TechDraw/Gui/DrawGuiUtil.h
Expand Up @@ -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);
Expand Down

0 comments on commit 197c0f7

Please sign in to comment.