-// Copyright (C) 2007-2019 CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2022 CEA/DEN, EDF R&D, OPEN CASCADE
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
delete (QRect*)mypData;
mypData = 0;
mypRectRB->clearGeometry();
+ mypRectRB->hide();
}
bool OCCViewer_RectSketcher::onKey( QKeyEvent* e )
else
avp->setCursor( Qt::ForbiddenCursor );
- if ( e->type() == QEvent::MouseButtonRelease && e->button() == sketchButton() )
+ if ( e->type() == QEvent::MouseButtonRelease && (int)e->button() == sketchButton() ) // todo Qt::MouseButton is unsigned int: comparison of int with uint
{
myResult = Accept;
QApplication::postEvent( avp, new QMouseEvent( e->type(), e->pos(),
myDelButton ( 0 ),
myMode ( Poligone )
{
- mySketchButton = Qt::RightButton;
+ mySketchButton = Qt::LeftButton;
if ( vw )
{
OCCViewer_ViewPort3d* avp = mypViewWindow->getViewPort();
void OCCViewer_PolygonSketcher::onDeactivate()
{
- if ( mypPolyRB )
- mypPolyRB->clearGeometry();
- if (mypCircleRB)
+ if (mypPolyRB) {
+ mypPolyRB->clearGeometry();
+ mypPolyRB->hide();
+ }
+ if (mypCircleRB) {
mypCircleRB->clearGeometry();
+ mypCircleRB->hide();
+ }
((QPolygon*)mypData)->clear();
}
-bool OCCViewer_PolygonSketcher::onKey( QKeyEvent* e )
+bool OCCViewer_PolygonSketcher::onKey(QKeyEvent* e)
{
- if ( e->key() == Qt::Key_Escape )
+ int aKey = e->key();
+ if (aKey == Qt::Key_Escape)
{
myResult = Reject;
return true;
}
- else if ( e->key() == Qt::Key_Enter || e->key() == Qt::Key_Return )
+ else if (aKey == Qt::Key_Enter || aKey == Qt::Key_Return)
{
QPolygon* points = (QPolygon*)data();
- if ( points->count() )
+ if (points->count())
{
- QPoint last = points->point( points->count() - 1 );
- if ( last != myCurr )
+ QPoint last = points->point(points->count() - 1);
+ if (last != myCurr)
{
- points->resize( points->count() + 1 );
- points->setPoint( points->count() - 1, myCurr );
+ points->resize(points->count() + 1);
+ points->setPoint(points->count() - 1, myCurr);
}
}
myResult = Accept;
return true;
}
- else if ( e->key() == Qt::Key_Backspace && e->type() == QEvent::KeyRelease )
+ else if (aKey == Qt::Key_Backspace && e->type() == QEvent::KeyRelease)
{
QPolygon* points = (QPolygon*)data();
- if ( points->count() > 1 )
- points->resize( points->count() - 1 );
- onMouse( 0 );
+ if (points->count() > 1)
+ points->resize(points->count() - 1);
+ onMouse(0);
return true;
}
+ else if (aKey == Qt::Key_Space && e->type() == QEvent::KeyRelease)
+ {
+ OCCViewer_ViewPort3d* avp = mypViewWindow->getViewPort();
+ bool closed = false;
+ QPolygon* points = (QPolygon*)data();
+ bool valid = avp->rect().contains(myCurr);
+ if (!myStart.isNull())
+ {
+ QRect aRect(myStart.x() - myToler.width(), myStart.y() - myToler.height(),
+ 2 * myToler.width(), 2 * myToler.height());
+ closed = aRect.contains(myCurr);
+ }
+ valid = valid && isValid(points, myCurr);
+ if (closed && !valid)
+ closed = false;
+ if (closed)
+ myResult = Accept;
+ else
+ {
+ if (myStart.isNull())
+ myStart = myCurr;
+ else
+ {
+ QPoint last = points->point(points->count() - 1);
+ if (last != myCurr && valid)
+ {
+ points->resize(points->count() + 1);
+ points->setPoint(points->count() - 1, myCurr);
+ }
+ if (valid && myDbl)
+ myResult = Accept;
+ }
+ }
+ }
return true;
}
if ( e->type() == QEvent::MouseButtonRelease && ( e->button() & sketchButton() ) )
{
- myResult = Reject;
+ myResult = (closed && (points->count() > 2)) ? Accept : Reject;
QApplication::postEvent( avp, new QMouseEvent( e->type(), e->pos(),
e->globalPos(), e->button(),
e->buttons(), e->modifiers() ) );
}
- else if ( e->type() == QEvent::MouseButtonRelease && ( e->button() & myAddButton ) )
- {
- if ( closed )
- myResult = Accept;
- else
- {
- if ( myStart.isNull() )
- myStart = myCurr;
- else
- {
- QPoint last = points->point( points->count() - 1 );
- if ( last != myCurr && valid )
- {
- points->resize( points->count() + 1 );
- points->setPoint( points->count() - 1, myCurr );
- }
- if ( valid && myDbl )
- myResult = Accept;
- }
- }
- }
else if ( ( e->type() == QEvent::MouseButtonRelease && ( e->button() & myDelButton ) ) ||
( e->type() == QEvent::MouseButtonDblClick && ( e->button() & myDelButton ) ) )
{
return true;
bool res = true;
- for ( uint i = 0; i < aPoints->count() - 1 && res; i++ )
+ for ( int i = 0; i < aPoints->count() - 1 && res; i++ )
{
const QPoint& aStart = aPoints->point( i );
const QPoint& anEnd = aPoints->point( i + 1 );