Skip to content

Commit

Permalink
Part: expose "Attachment" context menu through ViewProviderPartExt
Browse files Browse the repository at this point in the history
  • Loading branch information
realthunder committed Jul 4, 2022
1 parent 629a87a commit 61120da
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 18 deletions.
8 changes: 5 additions & 3 deletions src/Mod/Part/Gui/Command.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<App::PropertyPlacement>(
sels[0].pObject->getPropertyByName("Placement")))
obj->getPropertyByName("Placement")))
{
return !prop->testStatus(App::Property::Hidden)
&& !prop->testStatus(App::Property::ReadOnly);
return obj->getExtensionByType<Part::AttachExtension>(true)
|| (!prop->testStatus(App::Property::Hidden)
&& !prop->testStatus(App::Property::ReadOnly));
}
return false;
}
Expand Down
5 changes: 5 additions & 0 deletions src/Mod/Part/Gui/ViewProviderAttachExtension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
20 changes: 20 additions & 0 deletions src/Mod/Part/Gui/ViewProviderExt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@
#include <App/MappedElement.h>

#include <Gui/Application.h>
#include <Gui/Command.h>
#include <Gui/Action.h>
#include <Gui/SoFCUnifiedSelection.h>
#include <Gui/SoFCSelectionAction.h>
#include <Gui/Selection.h>
Expand Down Expand Up @@ -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<App::PropertyPlacement>(
getObject()->getPropertyByName("Placement")))
{
if (getObject()->getExtensionByType<Part::AttachExtension>(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));
Expand Down
6 changes: 2 additions & 4 deletions src/Mod/Part/Gui/ViewProviderSubShapeBinder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down
12 changes: 1 addition & 11 deletions src/Mod/Sketcher/Gui/ViewProviderSketch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Sketcher::SketchObject*>(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)
Expand Down

0 comments on commit 61120da

Please sign in to comment.