From ac3b441cba9570279d0d67fd6ac4354e393d4c83 Mon Sep 17 00:00:00 2001 From: Bas Ruigrok Date: Sat, 9 Aug 2025 18:54:51 +0200 Subject: [PATCH 1/4] Gui: Reset navigation flags when the new mode is not IDLE or when the mouse buttons are released --- src/Gui/Navigation/BlenderNavigationStyle.cpp | 7 +++++++ src/Gui/Navigation/CADNavigationStyle.cpp | 7 +++++++ src/Gui/Navigation/InventorNavigationStyle.cpp | 7 +++++++ src/Gui/Navigation/NavigationStyle.cpp | 14 ++++++++------ src/Gui/Navigation/OpenCascadeNavigationStyle.cpp | 7 +++++++ src/Gui/Navigation/OpenSCADNavigationStyle.cpp | 7 +++++++ src/Gui/Navigation/RevitNavigationStyle.cpp | 7 +++++++ src/Gui/Navigation/SolidWorksNavigationStyle.cpp | 7 +++++++ src/Gui/Navigation/TinkerCADNavigationStyle.cpp | 7 +++++++ src/Gui/Navigation/TouchpadNavigationStyle.cpp | 7 +++++++ 10 files changed, 71 insertions(+), 6 deletions(-) diff --git a/src/Gui/Navigation/BlenderNavigationStyle.cpp b/src/Gui/Navigation/BlenderNavigationStyle.cpp index d18513f8f1..e44b79f738 100644 --- a/src/Gui/Navigation/BlenderNavigationStyle.cpp +++ b/src/Gui/Navigation/BlenderNavigationStyle.cpp @@ -299,6 +299,13 @@ SbBool BlenderNavigationStyle::processSoEvent(const SoEvent * const ev) processed = false; } + // Reset flags when newmode is IDLE and the buttons are released + if (newmode == IDLE && !button1down && !button2down && !button3down) { + hasPanned = false; + hasDragged = false; + hasZoomed = false; + } + if (newmode != curmode) { this->setViewingMode(newmode); } diff --git a/src/Gui/Navigation/CADNavigationStyle.cpp b/src/Gui/Navigation/CADNavigationStyle.cpp index 2c242436f0..09c519a25e 100644 --- a/src/Gui/Navigation/CADNavigationStyle.cpp +++ b/src/Gui/Navigation/CADNavigationStyle.cpp @@ -315,6 +315,13 @@ SbBool CADNavigationStyle::processSoEvent(const SoEvent * const ev) processed = false; } + // Reset flags when newmode is IDLE and the buttons are released + if (newmode == IDLE && !button1down && !button2down && !button3down) { + hasPanned = false; + hasDragged = false; + hasZoomed = false; + } + if (newmode != curmode) { this->setViewingMode(newmode); } diff --git a/src/Gui/Navigation/InventorNavigationStyle.cpp b/src/Gui/Navigation/InventorNavigationStyle.cpp index 2f09ead1f6..b8d4ceb91a 100644 --- a/src/Gui/Navigation/InventorNavigationStyle.cpp +++ b/src/Gui/Navigation/InventorNavigationStyle.cpp @@ -297,6 +297,13 @@ SbBool InventorNavigationStyle::processSoEvent(const SoEvent * const ev) processed = false; } + // Reset flags when newmode is IDLE and the buttons are released + if (newmode == IDLE && !button1down && !button2down && !button3down) { + hasPanned = false; + hasDragged = false; + hasZoomed = false; + } + if (newmode != curmode) { this->setViewingMode(newmode); } diff --git a/src/Gui/Navigation/NavigationStyle.cpp b/src/Gui/Navigation/NavigationStyle.cpp index ba02def974..9a5761bb82 100644 --- a/src/Gui/Navigation/NavigationStyle.cpp +++ b/src/Gui/Navigation/NavigationStyle.cpp @@ -1591,6 +1591,14 @@ void NavigationStyle::syncModifierKeys(const SoEvent * const ev) void NavigationStyle::setViewingMode(const ViewerMode newmode) { const ViewerMode oldmode = this->currentmode; + + // Reset flags when changing from IDLE to another mode or if the mode is IDLE and the buttons are released + if ((oldmode == IDLE && newmode != IDLE) || (newmode == IDLE && !button1down && !button2down && !button3down)) { + hasPanned = false; + hasDragged = false; + hasZoomed = false; + } + if (newmode == oldmode) { // The rotation center could have been changed even if the mode has not changed @@ -1601,12 +1609,6 @@ void NavigationStyle::setViewingMode(const ViewerMode newmode) return; } - if (newmode == NavigationStyle::IDLE) { - hasPanned = false; - hasDragged = false; - hasZoomed = false; - } - switch (newmode) { case DRAGGING: // Set up initial projection point for the projector object when diff --git a/src/Gui/Navigation/OpenCascadeNavigationStyle.cpp b/src/Gui/Navigation/OpenCascadeNavigationStyle.cpp index 7af1705f5a..f6d8b1bad3 100644 --- a/src/Gui/Navigation/OpenCascadeNavigationStyle.cpp +++ b/src/Gui/Navigation/OpenCascadeNavigationStyle.cpp @@ -273,6 +273,13 @@ SbBool OpenCascadeNavigationStyle::processSoEvent(const SoEvent * const ev) processed = false; } + // Reset flags when newmode is IDLE and the buttons are released + if (newmode == IDLE && !button1down && !button2down && !button3down) { + hasPanned = false; + hasDragged = false; + hasZoomed = false; + } + if (newmode != curmode) { this->setViewingMode(newmode); } diff --git a/src/Gui/Navigation/OpenSCADNavigationStyle.cpp b/src/Gui/Navigation/OpenSCADNavigationStyle.cpp index 3603df95a6..68eec6efc5 100644 --- a/src/Gui/Navigation/OpenSCADNavigationStyle.cpp +++ b/src/Gui/Navigation/OpenSCADNavigationStyle.cpp @@ -268,6 +268,13 @@ SbBool OpenSCADNavigationStyle::processSoEvent(const SoEvent * const ev) processed = false; } + // Reset flags when newmode is IDLE and the buttons are released + if (newmode == IDLE && !button1down && !button2down && !button3down) { + hasPanned = false; + hasDragged = false; + hasZoomed = false; + } + if (newmode != curmode) { this->setViewingMode(newmode); } diff --git a/src/Gui/Navigation/RevitNavigationStyle.cpp b/src/Gui/Navigation/RevitNavigationStyle.cpp index e22d0b4119..b5c4c570e6 100644 --- a/src/Gui/Navigation/RevitNavigationStyle.cpp +++ b/src/Gui/Navigation/RevitNavigationStyle.cpp @@ -296,6 +296,13 @@ SbBool RevitNavigationStyle::processSoEvent(const SoEvent * const ev) processed = false; } + // Reset flags when newmode is IDLE and the buttons are released + if (newmode == IDLE && !button1down && !button2down && !button3down) { + hasPanned = false; + hasDragged = false; + hasZoomed = false; + } + if (newmode != curmode) { this->setViewingMode(newmode); } diff --git a/src/Gui/Navigation/SolidWorksNavigationStyle.cpp b/src/Gui/Navigation/SolidWorksNavigationStyle.cpp index 50ba26e1ac..f8c4db5a45 100644 --- a/src/Gui/Navigation/SolidWorksNavigationStyle.cpp +++ b/src/Gui/Navigation/SolidWorksNavigationStyle.cpp @@ -295,6 +295,13 @@ SbBool SolidWorksNavigationStyle::processSoEvent(const SoEvent * const ev) processed = false; } + // Reset flags when newmode is IDLE and the buttons are released + if (newmode == IDLE && !button1down && !button2down && !button3down) { + hasPanned = false; + hasDragged = false; + hasZoomed = false; + } + if (newmode != curmode) { this->setViewingMode(newmode); } diff --git a/src/Gui/Navigation/TinkerCADNavigationStyle.cpp b/src/Gui/Navigation/TinkerCADNavigationStyle.cpp index 0a4c3516a1..1874f46878 100644 --- a/src/Gui/Navigation/TinkerCADNavigationStyle.cpp +++ b/src/Gui/Navigation/TinkerCADNavigationStyle.cpp @@ -245,6 +245,13 @@ SbBool TinkerCADNavigationStyle::processSoEvent(const SoEvent * const ev) processed = false; } + // Reset flags when newmode is IDLE and the buttons are released + if (newmode == IDLE && !button1down && !button2down && !button3down) { + hasPanned = false; + hasDragged = false; + hasZoomed = false; + } + if (newmode != curmode) { this->setViewingMode(newmode); } diff --git a/src/Gui/Navigation/TouchpadNavigationStyle.cpp b/src/Gui/Navigation/TouchpadNavigationStyle.cpp index 1f8837511f..957652e8a0 100644 --- a/src/Gui/Navigation/TouchpadNavigationStyle.cpp +++ b/src/Gui/Navigation/TouchpadNavigationStyle.cpp @@ -272,6 +272,13 @@ SbBool TouchpadNavigationStyle::processSoEvent(const SoEvent * const ev) processed = false; } + // Reset flags when newmode is IDLE and the buttons are released + if (newmode == IDLE && !button1down && !button2down && !button3down) { + hasPanned = false; + hasDragged = false; + hasZoomed = false; + } + if (newmode != curmode) { this->setViewingMode(newmode); } From 39329e547fec7490d2dbeaf9575cce47b60d1ca7 Mon Sep 17 00:00:00 2001 From: Bas Ruigrok Date: Sat, 9 Aug 2025 18:56:49 +0200 Subject: [PATCH 2/4] Sketcher: Don't show the context menu after rubber band selection --- src/Mod/Sketcher/Gui/ViewProviderSketch.cpp | 11 +++++++++++ src/Mod/Sketcher/Gui/ViewProviderSketch.h | 2 ++ 2 files changed, 13 insertions(+) diff --git a/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp b/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp index 2441e8c8f3..f265937d06 100644 --- a/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp +++ b/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp @@ -644,6 +644,8 @@ ViewProviderSketch::ViewProviderSketch() updateColorPropertiesVisibility(); pcSketchFacesToggle->addChild(pcSketchFaces); + + blockContextMenu = false; } ViewProviderSketch::~ViewProviderSketch() @@ -1141,6 +1143,7 @@ bool ViewProviderSketch::mouseButtonPressed(int Button, bool pressed, const SbVe case STATUS_SKETCH_UseRubberBand: doBoxSelection(DoubleClick::prvCursorPos, cursorPos, viewer); rubberband->setWorking(false); + blockContextMenu = true; // use draw(false, false) to avoid solver geometry with outdated construction flags draw(false, false); @@ -1162,6 +1165,8 @@ bool ViewProviderSketch::mouseButtonPressed(int Button, bool pressed, const SbVe // Right mouse button **************************************************** else if (Button == 2) { if (pressed) { + blockContextMenu = false; + // Do things depending on the mode of the user interaction switch (Mode) { case STATUS_NONE: { @@ -3714,6 +3719,8 @@ void ViewProviderSketch::setEditViewer(Gui::View3DInventorViewer* viewer, int Mo cameraSensor.setData(camSensorData); cameraSensor.setDeleteCallback(&ViewProviderSketch::camSensDeleteCB, camSensorData); cameraSensor.attach(viewer->getCamera()); + + blockContextMenu = false; } void ViewProviderSketch::unsetEditViewer(Gui::View3DInventorViewer* viewer) @@ -3727,6 +3734,8 @@ void ViewProviderSketch::unsetEditViewer(Gui::View3DInventorViewer* viewer) viewer->removeGraphicsItem(rubberband.get()); viewer->setEditing(false); viewer->setSelectionEnabled(true); + + blockContextMenu = false; } void ViewProviderSketch::camSensDeleteCB(void* data, SoSensor *s) @@ -4365,6 +4374,8 @@ bool ViewProviderSketch::isInEditMode() const } void ViewProviderSketch::generateContextMenu() { + if (blockContextMenu) return; + int selectedEdges = 0; int selectedLines = 0; int selectedConics = 0; diff --git a/src/Mod/Sketcher/Gui/ViewProviderSketch.h b/src/Mod/Sketcher/Gui/ViewProviderSketch.h index 4bfaf0a590..69be10135e 100644 --- a/src/Mod/Sketcher/Gui/ViewProviderSketch.h +++ b/src/Mod/Sketcher/Gui/ViewProviderSketch.h @@ -991,6 +991,8 @@ private: SoNodeSensor cameraSensor; int viewOrientationFactor; // stores if sketch viewed from front or back + + bool blockContextMenu; }; } // namespace SketcherGui From e469eb5ccb21f5271a2ed67571949fc9d2893f2f Mon Sep 17 00:00:00 2001 From: Bas Ruigrok Date: Sat, 23 Aug 2025 13:54:33 +0200 Subject: [PATCH 3/4] Sketcher: Cancel rubber band selection with RMB Cleanup --- src/Mod/Sketcher/Gui/ViewProviderSketch.cpp | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp b/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp index f265937d06..2e1108e35e 100644 --- a/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp +++ b/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp @@ -543,6 +543,7 @@ ViewProviderSketch::ViewProviderSketch() , pObserver(std::make_unique(*this)) , sketchHandler(nullptr) , viewOrientationFactor(1) + , blockContextMenu(false) { PartGui::ViewProviderAttachExtension::initExtension(this); PartGui::ViewProviderGridExtension::initExtension(this); @@ -644,8 +645,6 @@ ViewProviderSketch::ViewProviderSketch() updateColorPropertiesVisibility(); pcSketchFacesToggle->addChild(pcSketchFaces); - - blockContextMenu = false; } ViewProviderSketch::~ViewProviderSketch() @@ -1166,7 +1165,7 @@ bool ViewProviderSketch::mouseButtonPressed(int Button, bool pressed, const SbVe else if (Button == 2) { if (pressed) { blockContextMenu = false; - + // Do things depending on the mode of the user interaction switch (Mode) { case STATUS_NONE: { @@ -1186,7 +1185,18 @@ bool ViewProviderSketch::mouseButtonPressed(int Button, bool pressed, const SbVe // Base::Console().log("start dragging, point:%d\n",this->DragPoint); setSketchMode(STATUS_SELECT_Constraint); } + break; } + case STATUS_SKETCH_UseRubberBand: + // Cancel rubberband + rubberband->setWorking(false); + blockContextMenu = true; + + // a redraw is required in order to clear the rubberband + draw(true, false); + const_cast(viewer)->redraw(); + setSketchMode(STATUS_NONE); + return true; default: break; } @@ -4375,7 +4385,7 @@ bool ViewProviderSketch::isInEditMode() const void ViewProviderSketch::generateContextMenu() { if (blockContextMenu) return; - + int selectedEdges = 0; int selectedLines = 0; int selectedConics = 0; From cc930ae145b0321c10627aae67a3404953158c32 Mon Sep 17 00:00:00 2001 From: Bas Ruigrok Date: Sat, 23 Aug 2025 14:01:19 +0200 Subject: [PATCH 4/4] Gui: Allow switch to panning after canceling sketcher rubber band selection --- src/Gui/Navigation/BlenderNavigationStyle.cpp | 4 +++- src/Gui/Navigation/RevitNavigationStyle.cpp | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Gui/Navigation/BlenderNavigationStyle.cpp b/src/Gui/Navigation/BlenderNavigationStyle.cpp index e44b79f738..e6086dbc6f 100644 --- a/src/Gui/Navigation/BlenderNavigationStyle.cpp +++ b/src/Gui/Navigation/BlenderNavigationStyle.cpp @@ -295,7 +295,9 @@ SbBool BlenderNavigationStyle::processSoEvent(const SoEvent * const ev) // Prevent interrupting rubber-band selection in sketcher if (viewer->isEditing() && curmode == NavigationStyle::SELECTION && newmode != NavigationStyle::IDLE) { - newmode = NavigationStyle::SELECTION; + if (!button1down || !button2down) { // Allow canceling rubber-band in sketcher if both button 1 and button 2 are pressed + newmode = NavigationStyle::SELECTION; + } processed = false; } diff --git a/src/Gui/Navigation/RevitNavigationStyle.cpp b/src/Gui/Navigation/RevitNavigationStyle.cpp index b5c4c570e6..1544650abb 100644 --- a/src/Gui/Navigation/RevitNavigationStyle.cpp +++ b/src/Gui/Navigation/RevitNavigationStyle.cpp @@ -292,7 +292,9 @@ SbBool RevitNavigationStyle::processSoEvent(const SoEvent * const ev) // Prevent interrupting rubber-band selection in sketcher if (viewer->isEditing() && curmode == NavigationStyle::SELECTION && newmode != NavigationStyle::IDLE) { - newmode = NavigationStyle::SELECTION; + if (!button1down || !button2down) { // Allow canceling rubber-band in sketcher if both button 1 and button 2 are pressed + newmode = NavigationStyle::SELECTION; + } processed = false; }