From 966a6370e93aa90a8d70d4a970c54df23961e1bc Mon Sep 17 00:00:00 2001 From: vsv Date: Fri, 10 Apr 2020 20:44:22 +0300 Subject: [PATCH] bos #18968 [CEA] Sometimes when clicking to add a face to a group two faces are added --- src/OCCViewer/OCCViewer.cxx | 11 ++++++++ src/OCCViewer/OCCViewer.h | 2 ++ src/OCCViewer/OCCViewer_ViewModel.cxx | 12 +++++---- src/OCCViewer/OCCViewer_ViewModel.h | 4 +++ src/OCCViewer/OCCViewer_ViewSketcher.cxx | 2 +- src/OCCViewer/OCCViewer_ViewWindow.cxx | 34 ++++++++++++++---------- 6 files changed, 45 insertions(+), 20 deletions(-) diff --git a/src/OCCViewer/OCCViewer.cxx b/src/OCCViewer/OCCViewer.cxx index 7fbf45cc2..ffd136941 100644 --- a/src/OCCViewer/OCCViewer.cxx +++ b/src/OCCViewer/OCCViewer.cxx @@ -45,3 +45,14 @@ QColor OCCViewer::color( const Quantity_Color& c ) int( c.Green() * 255 ), int( c.Blue() * 255 ) ); } + +/*! + \brief Check if size of given rectagle exceeds threshold value for mouse events. + \param rect Given rectangle + \return Result of comparison +*/ +bool OCCViewer::overThreshold( const QRect& rect ) +{ + const int threshold = 3; + return qMin( rect.height(), rect.width() ) >= threshold; +} diff --git a/src/OCCViewer/OCCViewer.h b/src/OCCViewer/OCCViewer.h index 173a7a1c8..ff801bea7 100644 --- a/src/OCCViewer/OCCViewer.h +++ b/src/OCCViewer/OCCViewer.h @@ -40,11 +40,13 @@ #include #include +#include namespace OCCViewer { OCCVIEWER_EXPORT Quantity_Color color( const QColor& ); OCCVIEWER_EXPORT QColor color( const Quantity_Color& ); + OCCVIEWER_EXPORT bool overThreshold( const QRect& ); }; #endif //OCCVIEWER_H diff --git a/src/OCCViewer/OCCViewer_ViewModel.cxx b/src/OCCViewer/OCCViewer_ViewModel.cxx index 7a15bb745..b12f6b6c6 100644 --- a/src/OCCViewer/OCCViewer_ViewModel.cxx +++ b/src/OCCViewer/OCCViewer_ViewModel.cxx @@ -21,7 +21,6 @@ // #include "OCCViewer_ViewModel.h" -#include "OCCViewer.h" #include "OCCViewer_ViewFrame.h" #include "OCCViewer_VService.h" #include "OCCViewer_ViewPort3d.h" @@ -131,7 +130,8 @@ OCCViewer_Viewer::OCCViewer_Viewer( bool DisplayTrihedron) myIsUseLocalSelection(false), #endif myClippingDlg (NULL), - myFitter(0) + myFitter(0), + mySelectionDone(false) { // init CasCade viewers myV3dViewer = OCCViewer_VService::CreateViewer( TCollection_ExtendedString("Viewer3d").ToExtString() ); @@ -378,8 +378,8 @@ void OCCViewer_Viewer::onMouseRelease(SUIT_ViewWindow* theWindow, QMouseEvent* t myEndPnt.setX(theEvent->x()); myEndPnt.setY(theEvent->y()); bool aHasShift = (theEvent->modifiers() & Qt::ShiftModifier); - - if (myStartPnt == myEndPnt) + // In case of small tremor of a mouse pointer, consider it as a click + if ( !OCCViewer::overThreshold( QRect( myStartPnt, myEndPnt ) ) && !mySelectionDone) { if (!aHasShift) { myAISContext->ClearCurrents( false ); @@ -396,7 +396,10 @@ void OCCViewer_Viewer::onMouseRelease(SUIT_ViewWindow* theWindow, QMouseEvent* t myAISContext->ShiftSelect( Standard_True ); else myAISContext->Select( Standard_True ); + emit selectionChanged(); } + mySelectionDone = false; + //else //{ // if (aHasShift && myMultiSelectionEnabled) @@ -422,7 +425,6 @@ void OCCViewer_Viewer::onMouseRelease(SUIT_ViewWindow* theWindow, QMouseEvent* t // myAISContext->UpdateCurrentViewer(); //} - emit selectionChanged(); } /*! diff --git a/src/OCCViewer/OCCViewer_ViewModel.h b/src/OCCViewer/OCCViewer_ViewModel.h index 4bb4533b5..114ae093e 100644 --- a/src/OCCViewer/OCCViewer_ViewModel.h +++ b/src/OCCViewer/OCCViewer_ViewModel.h @@ -260,6 +260,9 @@ public: void initView( OCCViewer_ViewWindow* view ); + /// Sets a flag to ignore mouse release for selection. Used for Rectangle/Polygon selection + void doNotSelect() { mySelectionDone = true; } + signals: void selectionChanged(); void deselection(); @@ -326,6 +329,7 @@ protected: #endif OCCViewer_Fitter* myFitter; + bool mySelectionDone; }; #ifdef WIN32 diff --git a/src/OCCViewer/OCCViewer_ViewSketcher.cxx b/src/OCCViewer/OCCViewer_ViewSketcher.cxx index 195af5a6e..bd31ff3b3 100644 --- a/src/OCCViewer/OCCViewer_ViewSketcher.cxx +++ b/src/OCCViewer/OCCViewer_ViewSketcher.cxx @@ -473,7 +473,7 @@ void OCCViewer_PolygonSketcher::onMouse( QMouseEvent* e ) if ( e->type() == QEvent::MouseButtonRelease && ( e->button() & sketchButton() ) ) { - myResult = Reject; + myResult = closed? Accept : Reject; QApplication::postEvent( avp, new QMouseEvent( e->type(), e->pos(), e->globalPos(), e->button(), e->buttons(), e->modifiers() ) ); diff --git a/src/OCCViewer/OCCViewer_ViewWindow.cxx b/src/OCCViewer/OCCViewer_ViewWindow.cxx index 62eeba51e..4da72e376 100644 --- a/src/OCCViewer/OCCViewer_ViewWindow.cxx +++ b/src/OCCViewer/OCCViewer_ViewWindow.cxx @@ -3160,7 +3160,9 @@ void OCCViewer_ViewWindow::onSketchingFinished() case Rect: { QRect* aRect = (QRect*)mypSketcher->data(); - if( aRect ) + // Use rectangle selection only if the rect has a reasonable size + // If it is too small then it is very probably tremor of a mouse pointer + if ( aRect && OCCViewer::overThreshold( *aRect ) ) { int aLeft = aRect->left(); int aRight = aRect->right(); @@ -3180,21 +3182,24 @@ void OCCViewer_ViewWindow::onSketchingFinished() QPolygon* aPolygon = (QPolygon*)mypSketcher->data(); if( aPolygon ) { - int size = aPolygon->size(); - TColgp_Array1OfPnt2d anArray( 1, size ); + QRect aRect = aPolygon->boundingRect(); + if ( OCCViewer::overThreshold( aRect ) ) { + int size = aPolygon->size(); + TColgp_Array1OfPnt2d anArray(1, size); + + QPolygon::Iterator it = aPolygon->begin(); + QPolygon::Iterator itEnd = aPolygon->end(); + for (int index = 1; it != itEnd; ++it, index++) + { + QPoint aPoint = *it; + anArray.SetValue(index, gp_Pnt2d(aPoint.x(), aPoint.y())); + } - QPolygon::Iterator it = aPolygon->begin(); - QPolygon::Iterator itEnd = aPolygon->end(); - for( int index = 1; it != itEnd; ++it, index++ ) - { - QPoint aPoint = *it; - anArray.SetValue( index, gp_Pnt2d( aPoint.x(), aPoint.y() ) ); + if (append) + ic->ShiftSelect(anArray, getViewPort()->getView(), Standard_False); + else + ic->Select(anArray, getViewPort()->getView(), Standard_False); } - - if( append ) - ic->ShiftSelect( anArray, getViewPort()->getView(), Standard_False); - else - ic->Select( anArray, getViewPort()->getView(), Standard_False); } } break; @@ -3204,6 +3209,7 @@ void OCCViewer_ViewWindow::onSketchingFinished() OCCViewer_ViewManager* aViewMgr = ( OCCViewer_ViewManager* )getViewManager(); aViewMgr->getOCCViewer()->performSelectionChanged(); + aViewMgr->getOCCViewer()->doNotSelect(); } } -- 2.39.2