Assembly: Fix context menu 'Activate object' not working and causing crash (#17092)
* Assembly: Add setupContextMenu to ViewProviderAssembly.h * Assembly: Fix right click 'activate object' menu not setting edit * add QMenu header * Add NOLINT * Add one more space before //NOLINT or clang cries... * Fix isInEditMode * add isInEditMode to ViewProviderAssemblyPy.xml * add isInEditMode to ViewProviderAssemblyPyImp.cpp * update activeAssembly() in Utils to make sure isInEditMode
This commit is contained in:
@@ -27,6 +27,7 @@
|
||||
#include <boost/core/ignore_unused.hpp>
|
||||
#include <QMessageBox>
|
||||
#include <QTimer>
|
||||
#include <QMenu>
|
||||
#include <vector>
|
||||
#include <sstream>
|
||||
#include <iostream>
|
||||
@@ -48,6 +49,7 @@
|
||||
|
||||
#include <Base/Tools.h>
|
||||
|
||||
#include <Gui/ActionFunction.h>
|
||||
#include <Gui/Application.h>
|
||||
#include <Gui/BitmapFactory.h>
|
||||
#include <Gui/CommandT.h>
|
||||
@@ -112,6 +114,20 @@ QIcon ViewProviderAssembly::getIcon() const
|
||||
return Gui::BitmapFactory().pixmap("Geoassembly.svg");
|
||||
}
|
||||
|
||||
void ViewProviderAssembly::setupContextMenu(QMenu* menu, QObject* receiver, const char* member)
|
||||
{
|
||||
auto func = new Gui::ActionFunction(menu);
|
||||
|
||||
QAction* act = menu->addAction(QObject::tr("Active object"));
|
||||
act->setCheckable(true);
|
||||
act->setChecked(isActivePart());
|
||||
func->trigger(act, [this]() {
|
||||
this->doubleClicked();
|
||||
});
|
||||
|
||||
ViewProviderDragger::setupContextMenu(menu, receiver, member); // NOLINT
|
||||
}
|
||||
|
||||
bool ViewProviderAssembly::doubleClicked()
|
||||
{
|
||||
if (isInEditMode()) {
|
||||
@@ -292,12 +308,7 @@ void ViewProviderAssembly::setEditViewer(Gui::View3DInventorViewer* viewer, int
|
||||
|
||||
bool ViewProviderAssembly::isInEditMode() const
|
||||
{
|
||||
App::DocumentObject* activePart = getActivePart();
|
||||
if (!activePart) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return activePart == this->getObject();
|
||||
return asmDragger != nullptr;
|
||||
}
|
||||
|
||||
App::DocumentObject* ViewProviderAssembly::getActivePart() const
|
||||
|
||||
@@ -103,6 +103,7 @@ public:
|
||||
QIcon getIcon() const override;
|
||||
|
||||
bool doubleClicked() override;
|
||||
void setupContextMenu(QMenu* menu, QObject* receiver, const char* member) override;
|
||||
bool onDelete(const std::vector<std::string>& subNames) override;
|
||||
bool canDelete(App::DocumentObject* obj) const override;
|
||||
|
||||
|
||||
@@ -14,6 +14,15 @@
|
||||
<UserDocu>This is the ViewProviderAssembly class</UserDocu>
|
||||
</Documentation>
|
||||
|
||||
<Methode Name="isInEditMode">
|
||||
<Documentation>
|
||||
<UserDocu>
|
||||
Return true if the assembly object is currently in edit mode.
|
||||
|
||||
isInEditMode() -> bool
|
||||
</UserDocu>
|
||||
</Documentation>
|
||||
</Methode>
|
||||
<Methode Name="getDragger">
|
||||
<Documentation>
|
||||
<UserDocu>
|
||||
|
||||
@@ -42,6 +42,16 @@ std::string ViewProviderAssemblyPy::representation() const
|
||||
return str.str();
|
||||
}
|
||||
|
||||
PyObject* ViewProviderAssemblyPy::isInEditMode(PyObject* args)
|
||||
{
|
||||
if (!PyArg_ParseTuple(args, "")) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Py::Boolean val(getViewProviderAssemblyPtr()->isInEditMode());
|
||||
return Py::new_reference_to(val);
|
||||
}
|
||||
|
||||
Py::Boolean ViewProviderAssemblyPy::getEnableMovement() const
|
||||
{
|
||||
return {getViewProviderAssemblyPtr()->getEnableMovement()};
|
||||
|
||||
@@ -52,7 +52,8 @@ def activePartOrAssembly():
|
||||
def activeAssembly():
|
||||
active_assembly = activePartOrAssembly()
|
||||
if active_assembly is not None and active_assembly.isDerivedFrom("Assembly::AssemblyObject"):
|
||||
return active_assembly
|
||||
if active_assembly.ViewObject.isInEditMode():
|
||||
return active_assembly
|
||||
|
||||
return None
|
||||
|
||||
|
||||
Reference in New Issue
Block a user