Merge pull request #22998 from Rexbas/prevent-showing-context-menu

Navigation: Prevent showing context menu after panning or rubber band selection
This commit is contained in:
Chris Hennes
2025-08-31 22:41:05 -05:00
committed by GitHub
12 changed files with 100 additions and 8 deletions

View File

@@ -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);
}

View File

@@ -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);
}

View File

@@ -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);
}

View File

@@ -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

View File

@@ -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);
}

View File

@@ -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);
}

View File

@@ -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);
}

View File

@@ -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);
}

View File

@@ -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);
}

View File

@@ -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);
}

View File

@@ -543,6 +543,7 @@ ViewProviderSketch::ViewProviderSketch()
, pObserver(std::make_unique<ViewProviderSketch::ParameterObserver>(*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<Gui::View3DInventorViewer*>(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;

View File

@@ -991,6 +991,8 @@ private:
SoNodeSensor cameraSensor;
int viewOrientationFactor; // stores if sketch viewed from front or back
bool blockContextMenu;
};
} // namespace SketcherGui