From 363d1489c3f27bcaa765326096a157fd244f024c Mon Sep 17 00:00:00 2001 From: PaddleStroke Date: Thu, 25 Jul 2024 01:44:36 +0200 Subject: [PATCH] Assembly: define joint double click on 3dview (#15572) * Assembly: define joint double click on 3dview * Update string --- src/Mod/Assembly/Gui/ViewProviderAssembly.cpp | 46 +++++++++++++++++++ src/Mod/Assembly/Gui/ViewProviderAssembly.h | 6 +++ 2 files changed, 52 insertions(+) diff --git a/src/Mod/Assembly/Gui/ViewProviderAssembly.cpp b/src/Mod/Assembly/Gui/ViewProviderAssembly.cpp index 88079688a6..37cf6f69ee 100644 --- a/src/Mod/Assembly/Gui/ViewProviderAssembly.cpp +++ b/src/Mod/Assembly/Gui/ViewProviderAssembly.cpp @@ -38,6 +38,8 @@ #include #endif +#include + #include #include #include @@ -96,6 +98,7 @@ ViewProviderAssembly::ViewProviderAssembly() , moveInCommand(true) , jointVisibilityBackup(false) , ctrlPressed(false) + , lastClickTime(0) , docsToMove({}) {} @@ -466,6 +469,19 @@ bool ViewProviderAssembly::mouseButtonPressed(int Button, // Left Mouse button **************************************************** if (Button == 1) { if (pressed && !getDraggerVisibility()) { + // Check for double-click + auto now = std::chrono::steady_clock::now(); + long nowMillis = + std::chrono::duration_cast(now.time_since_epoch()) + .count(); + if (nowMillis - lastClickTime < 500) { + // Double-click detected + doubleClickedIn3dView(); + return true; + } + // First click detected + lastClickTime = nowMillis; + canStartDragging = true; } else { // Button 1 released @@ -483,6 +499,36 @@ bool ViewProviderAssembly::mouseButtonPressed(int Button, return false; } +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. + } + + 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 { if (!obj) { diff --git a/src/Mod/Assembly/Gui/ViewProviderAssembly.h b/src/Mod/Assembly/Gui/ViewProviderAssembly.h index 15417f8a14..f72f73347f 100644 --- a/src/Mod/Assembly/Gui/ViewProviderAssembly.h +++ b/src/Mod/Assembly/Gui/ViewProviderAssembly.h @@ -103,6 +103,9 @@ public: bool pressed, const SbVec2s& cursorPos, const Gui::View3DInventorViewer* viewer) override; + // Function to handle double click event + void doubleClickedIn3dView(); + /// Finds what drag mode should be used based on the user selection. DragMode findDragMode(); @@ -172,6 +175,9 @@ public: bool moveInCommand; bool jointVisibilityBackup; bool ctrlPressed; + + long lastClickTime; // Store last click time as milliseconds + int numberOfSel; Base::Vector3d prevPosition; Base::Vector3d initialPosition;