From 61120da875875baa4cc62f327ef3503a142c116a Mon Sep 17 00:00:00 2001 From: "Zheng, Lei" Date: Mon, 4 Jul 2022 14:27:49 +0800 Subject: [PATCH] Part: expose "Attachment" context menu through ViewProviderPartExt Fixes #472 @kevenwyld --- src/Mod/Part/Gui/Command.cpp | 8 +++++--- .../Part/Gui/ViewProviderAttachExtension.cpp | 5 +++++ src/Mod/Part/Gui/ViewProviderExt.cpp | 20 +++++++++++++++++++ .../Part/Gui/ViewProviderSubShapeBinder.cpp | 6 ++---- src/Mod/Sketcher/Gui/ViewProviderSketch.cpp | 12 +---------- 5 files changed, 33 insertions(+), 18 deletions(-) diff --git a/src/Mod/Part/Gui/Command.cpp b/src/Mod/Part/Gui/Command.cpp index f4b0f79588ff..b51a439fe7d5 100644 --- a/src/Mod/Part/Gui/Command.cpp +++ b/src/Mod/Part/Gui/Command.cpp @@ -2837,11 +2837,13 @@ bool CmdPartEditAttachment::isActive(void) auto sels = Gui::Selection().getSelection("", 1, true); if (sels.empty()) return false; + auto obj = sels[0].pObject; if (auto prop = Base::freecad_dynamic_cast( - sels[0].pObject->getPropertyByName("Placement"))) + obj->getPropertyByName("Placement"))) { - return !prop->testStatus(App::Property::Hidden) - && !prop->testStatus(App::Property::ReadOnly); + return obj->getExtensionByType(true) + || (!prop->testStatus(App::Property::Hidden) + && !prop->testStatus(App::Property::ReadOnly)); } return false; } diff --git a/src/Mod/Part/Gui/ViewProviderAttachExtension.cpp b/src/Mod/Part/Gui/ViewProviderAttachExtension.cpp index ebde88b6d366..579f3d1fae03 100644 --- a/src/Mod/Part/Gui/ViewProviderAttachExtension.cpp +++ b/src/Mod/Part/Gui/ViewProviderAttachExtension.cpp @@ -112,12 +112,17 @@ void ViewProviderAttachExtension::extensionUpdateData(const App::Property* prop) void ViewProviderAttachExtension::extensionSetupContextMenu(QMenu* menu, QObject*, const char*) { + // The "Attachment" menu is now exposed by PartGui::ViewProviderExt +#if 0 // toggle command to display components Gui::ActionFunction* func = new Gui::ActionFunction(menu); QAction* act = menu->addAction(QObject::tr("Attachment editor")); if (Gui::Control().activeDialog()) act->setDisabled(true); func->trigger(act, boost::bind(&ViewProviderAttachExtension::showAttachmentEditor, this)); +#else + (void)menu; +#endif } void ViewProviderAttachExtension::showAttachmentEditor() diff --git a/src/Mod/Part/Gui/ViewProviderExt.cpp b/src/Mod/Part/Gui/ViewProviderExt.cpp index c35d5dd76e6d..2c04960c7b98 100644 --- a/src/Mod/Part/Gui/ViewProviderExt.cpp +++ b/src/Mod/Part/Gui/ViewProviderExt.cpp @@ -115,6 +115,8 @@ #include #include +#include +#include #include #include #include @@ -1656,6 +1658,24 @@ void ViewProviderPartExt::updateData(const App::Property* prop) void ViewProviderPartExt::setupContextMenu(QMenu* menu, QObject* receiver, const char* member) { + if (!getObject()) + return; + if (auto propPlacement = Base::freecad_dynamic_cast( + getObject()->getPropertyByName("Placement"))) + { + if (getObject()->getExtensionByType(true) + || (!propPlacement->testStatus(App::Property::Hidden) + && !propPlacement->testStatus(App::Property::ReadOnly))) { + if (auto cmd = Gui::Application::Instance->commandManager().getCommandByName("Part_EditAttachment")) + { + cmd->initAction(); + if (auto action = cmd->getAction()) { + if (auto act = action->action()) + menu->addAction(act); + } + } + } + } Gui::ViewProviderGeometryObject::setupContextMenu(menu, receiver, member); QAction* act = menu->addAction(QObject::tr("Set colors..."), receiver, member); act->setData(QVariant((int)ViewProvider::Color)); diff --git a/src/Mod/Part/Gui/ViewProviderSubShapeBinder.cpp b/src/Mod/Part/Gui/ViewProviderSubShapeBinder.cpp index 532c869cc754..5c32a50be471 100644 --- a/src/Mod/Part/Gui/ViewProviderSubShapeBinder.cpp +++ b/src/Mod/Part/Gui/ViewProviderSubShapeBinder.cpp @@ -240,10 +240,6 @@ void ViewProviderSubShapeBinder::setupContextMenu(QMenu* menu, QObject* receiver if (!self) return; - Gui::MenuItem menuItem; - menuItem << "Part_EditAttachment"; - Gui::MenuManager::getInstance()->setupContextMenu(&menuItem, *menu); - Gui::ActionFunction* func = new Gui::ActionFunction(menu); QAction* act; act = menu->addAction(QObject::tr("Synchronize"), receiver, member); @@ -315,6 +311,8 @@ void ViewProviderSubShapeBinder::setupContextMenu(QMenu* menu, QObject* receiver auto act = menu->addAction(QObject::tr("Toggle export"), receiver, member); act->setData(QVariant((int)Gui::ViewProvider::ExportInGroup)); } + + ViewProviderPart::setupContextMenu(menu,receiver,member); } bool ViewProviderSubShapeBinder::setEdit(int ModNum) { diff --git a/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp b/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp index 4f6cbca5f975..08bbf0032b00 100755 --- a/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp +++ b/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp @@ -6951,17 +6951,7 @@ void ViewProviderSketch::setupContextMenu(QMenu *menu, QObject *receiver, const QAction *act = menu->addAction(tr("Edit sketch"), receiver, member); func->trigger(act, boost::bind(&ViewProviderSketch::doubleClicked, this)); - auto sketch = static_cast(getObject()); - if (sketch->MapMode.getValue() == Attacher::mmDeactivated || !sketch->Support.getValue()) { - QAction* act = menu->addAction(QObject::tr("Transform"), receiver, member); - act->setToolTip(QObject::tr("Transform at the origin of the placement")); - act->setData(QVariant((int)ViewProvider::Transform)); - act = menu->addAction(QObject::tr("Transform at"), receiver, member); - act->setToolTip(QObject::tr("Transform at the center of the shape")); - act->setData(QVariant((int)ViewProvider::TransformAt)); - } - - PartGui::ViewProviderAttachExtension::extensionSetupContextMenu(menu, receiver, member); + PartGui::ViewProvider2DObjectGrid::setupContextMenu(menu, receiver, member); } bool ViewProviderSketch::setEdit(int ModNum)