From 18243223699d08470ef352772ecdaffb2d970887 Mon Sep 17 00:00:00 2001 From: PaddleStroke Date: Tue, 6 Aug 2024 17:28:30 +0200 Subject: [PATCH] Assembly: Fix bug where double-clicking on a joint would unselect the underlying edge. --- src/Mod/Assembly/Gui/ViewProviderAssembly.cpp | 72 ++++++++++++------- src/Mod/Assembly/Gui/ViewProviderAssembly.h | 1 + 2 files changed, 46 insertions(+), 27 deletions(-) diff --git a/src/Mod/Assembly/Gui/ViewProviderAssembly.cpp b/src/Mod/Assembly/Gui/ViewProviderAssembly.cpp index 9945d05d1a..da04e29f54 100644 --- a/src/Mod/Assembly/Gui/ViewProviderAssembly.cpp +++ b/src/Mod/Assembly/Gui/ViewProviderAssembly.cpp @@ -26,6 +26,7 @@ #ifndef _PreComp_ #include #include +#include #include #include #include @@ -475,9 +476,20 @@ bool ViewProviderAssembly::mouseButtonPressed(int Button, std::chrono::duration_cast(now.time_since_epoch()) .count(); if (nowMillis - lastClickTime < 500) { - // Double-click detected - doubleClickedIn3dView(); - return true; + auto* joint = getSelectedJoint(); + if (joint) { + // Double-click detected + // We start by clearing selection such that the second click selects the joint + // and not the assembly. + Gui::Selection().clearSelection(); + // singleShot timer to make sure this happens after the release of the click. + // Else the release will trigger a removeSelection of what + // doubleClickedIn3dView adds to the selection. + QTimer::singleShot(50, [this]() { + doubleClickedIn3dView(); + }); + return true; + } } // First click detected lastClickTime = nowMillis; @@ -502,31 +514,20 @@ bool ViewProviderAssembly::mouseButtonPressed(int Button, void ViewProviderAssembly::doubleClickedIn3dView() { // Double clicking on a joint should start editing it. - auto sel = Gui::Selection().getSelectionEx("", App::DocumentObject::getClassTypeId()); - if (sel.size() != 1) { - return; // Handle double click only if only one obj selected. + auto* joint = getSelectedJoint(); + + if (joint) { + std::string obj_name = joint->getNameInDocument(); + std::string doc_name = joint->getDocument()->getName(); + + std::string cmd = "import JointObject\n" + "obj = App.getDocument('" + + doc_name + "').getObject('" + obj_name + + "')\n" + "Gui.Control.showDialog(JointObject.TaskAssemblyCreateJoint(0, obj))"; + + Gui::Command::runCommand(Gui::Command::App, cmd.c_str()); } - - App::DocumentObject* obj = sel[0].getObject(); - if (!obj) { - return; - } - - auto* prop = dynamic_cast(obj->getPropertyByName("EnableLengthMin")); - if (!prop) { - return; - } - - std::string obj_name = obj->getNameInDocument(); - std::string doc_name = obj->getDocument()->getName(); - - std::string cmd = "import JointObject\n" - "obj = App.getDocument('" - + doc_name + "').getObject('" + obj_name - + "')\n" - "Gui.Control.showDialog(JointObject.TaskAssemblyCreateJoint(0, obj))"; - - Gui::Command::runCommand(Gui::Command::App, cmd.c_str()); } bool ViewProviderAssembly::canDragObjectIn3d(App::DocumentObject* obj) const @@ -561,6 +562,23 @@ bool ViewProviderAssembly::canDragObjectIn3d(App::DocumentObject* obj) const return true; } +App::DocumentObject* ViewProviderAssembly::getSelectedJoint() +{ + auto sel = Gui::Selection().getSelectionEx("", App::DocumentObject::getClassTypeId()); + + if (sel.size() == 1) { // Handle double click only if only one obj selected. + App::DocumentObject* obj = sel[0].getObject(); + if (obj) { + auto* prop = + dynamic_cast(obj->getPropertyByName("EnableLengthMin")); + if (prop) { + return obj; + } + } + } + return nullptr; +} + bool ViewProviderAssembly::getSelectedObjectsWithinAssembly(bool addPreselection, bool onlySolids) { // check the current selection, and check if any of the selected objects are within this diff --git a/src/Mod/Assembly/Gui/ViewProviderAssembly.h b/src/Mod/Assembly/Gui/ViewProviderAssembly.h index c444b14a9a..c9152583bd 100644 --- a/src/Mod/Assembly/Gui/ViewProviderAssembly.h +++ b/src/Mod/Assembly/Gui/ViewProviderAssembly.h @@ -170,6 +170,7 @@ public: bool canDragObjectIn3d(App::DocumentObject* obj) const; bool getSelectedObjectsWithinAssembly(bool addPreselection = true, bool onlySolids = false); + App::DocumentObject* getSelectedJoint(); /// Get the python wrapper for that ViewProvider PyObject* getPyObject() override;