diff --git a/src/Gui/Navigation/BlenderNavigationStyle.cpp b/src/Gui/Navigation/BlenderNavigationStyle.cpp index d18513f8f1..e6086dbc6f 100644 --- a/src/Gui/Navigation/BlenderNavigationStyle.cpp +++ b/src/Gui/Navigation/BlenderNavigationStyle.cpp @@ -295,10 +295,19 @@ 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; } + // 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..1544650abb 100644 --- a/src/Gui/Navigation/RevitNavigationStyle.cpp +++ b/src/Gui/Navigation/RevitNavigationStyle.cpp @@ -292,10 +292,19 @@ 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; } + // 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); } diff --git a/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp b/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp index 2441e8c8f3..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); @@ -1141,6 +1142,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 +1164,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: { @@ -1181,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; } @@ -3714,6 +3729,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 +3744,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 +4384,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