]> SALOME platform Git repositories - modules/gui.git/commitdiff
Salome HOME
bos #18968 [CEA] Sometimes when clicking to add a face to a group two faces are added
authorvsv <vsv@opencascade.com>
Fri, 10 Apr 2020 17:44:22 +0000 (20:44 +0300)
committervsr <vsr@opencascade.com>
Thu, 16 Apr 2020 11:18:20 +0000 (14:18 +0300)
src/OCCViewer/OCCViewer.cxx
src/OCCViewer/OCCViewer.h
src/OCCViewer/OCCViewer_ViewModel.cxx
src/OCCViewer/OCCViewer_ViewModel.h
src/OCCViewer/OCCViewer_ViewSketcher.cxx
src/OCCViewer/OCCViewer_ViewWindow.cxx

index 7fbf45cc270e583e78cdb98b95e1246a743190a1..ffd136941e6c4eee04281d1e110b850ba11bef31 100644 (file)
@@ -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;
+}
index 173a7a1c8056c269f748bf7c697df1de10a923e6..ff801bea71cb8119b8103f6ab0878bb363d4a068 100644 (file)
 #include <Quantity_Color.hxx>
 
 #include <QColor>
+#include <QRect>
 
 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
index 7a15bb745e8900a2e06efeba635d48b8981dfbed..b12f6b6c62bd861c56af46aa4292a27e23b02a6a 100644 (file)
@@ -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();
 }
 
 /*!
index 4bb4533b5dcda39137ac348b5395e7cbcab1d48b..114ae093e7d8bef2598dddfed6ea01e2acc0b502 100644 (file)
@@ -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
index 195af5a6e6b16f8e968e82309ede10c8d08c267a..bd31ff3b30101cc56b55fbfa6bee7a8dfd73f034 100644 (file)
@@ -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() ) );
index 62eeba51ed3c50af4894d3abebaad4b721a74fa7..4da72e37683333e5a3d7e49e104a100b6eb3fe7b 100644 (file)
@@ -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();
   }
 }