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;
+}
#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
//
#include "OCCViewer_ViewModel.h"
-#include "OCCViewer.h"
#include "OCCViewer_ViewFrame.h"
#include "OCCViewer_VService.h"
#include "OCCViewer_ViewPort3d.h"
myIsUseLocalSelection(false),
#endif
myClippingDlg (NULL),
- myFitter(0)
+ myFitter(0),
+ mySelectionDone(false)
{
// init CasCade viewers
myV3dViewer = OCCViewer_VService::CreateViewer( TCollection_ExtendedString("Viewer3d").ToExtString() );
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 );
myAISContext->ShiftSelect( Standard_True );
else
myAISContext->Select( Standard_True );
+ emit selectionChanged();
}
+ mySelectionDone = false;
+
//else
//{
// if (aHasShift && myMultiSelectionEnabled)
// myAISContext->UpdateCurrentViewer();
//}
- emit selectionChanged();
}
/*!
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();
#endif
OCCViewer_Fitter* myFitter;
+ bool mySelectionDone;
};
#ifdef WIN32
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() ) );
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();
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;
OCCViewer_ViewManager* aViewMgr = ( OCCViewer_ViewManager* )getViewManager();
aViewMgr->getOCCViewer()->performSelectionChanged();
+ aViewMgr->getOCCViewer()->doNotSelect();
}
}