mirror of
https://git.dev.opencascade.org/repos/occt.git
synced 2025-04-06 18:26:22 +03:00
0031518: Samples - update QtWidget samples to use AIS_ViewController
Qt samples IESample and Tutorial have been updated to use AIS_ViewController for view manipulations.
This commit is contained in:
parent
e1c9a10311
commit
0439d1cf44
@ -29,14 +29,46 @@
|
|||||||
#include <OcctWindow.h>
|
#include <OcctWindow.h>
|
||||||
#include <Aspect_DisplayConnection.hxx>
|
#include <Aspect_DisplayConnection.hxx>
|
||||||
|
|
||||||
// the key for multi selection :
|
namespace
|
||||||
#define MULTISELECTIONKEY Qt::ShiftModifier
|
{
|
||||||
|
//! Map Qt buttons bitmask to virtual keys.
|
||||||
|
Aspect_VKeyMouse qtMouseButtons2VKeys (Qt::MouseButtons theButtons)
|
||||||
|
{
|
||||||
|
Aspect_VKeyMouse aButtons = Aspect_VKeyMouse_NONE;
|
||||||
|
if ((theButtons & Qt::LeftButton) != 0)
|
||||||
|
{
|
||||||
|
aButtons |= Aspect_VKeyMouse_LeftButton;
|
||||||
|
}
|
||||||
|
if ((theButtons & Qt::MiddleButton) != 0)
|
||||||
|
{
|
||||||
|
aButtons |= Aspect_VKeyMouse_MiddleButton;
|
||||||
|
}
|
||||||
|
if ((theButtons & Qt::RightButton) != 0)
|
||||||
|
{
|
||||||
|
aButtons |= Aspect_VKeyMouse_RightButton;
|
||||||
|
}
|
||||||
|
return aButtons;
|
||||||
|
}
|
||||||
|
|
||||||
// the key for shortcut ( use to activate dynamic rotation, panning )
|
//! Map Qt mouse modifiers bitmask to virtual keys.
|
||||||
#define CASCADESHORTCUTKEY Qt::ControlModifier
|
Aspect_VKeyFlags qtMouseModifiers2VKeys (Qt::KeyboardModifiers theModifiers)
|
||||||
|
{
|
||||||
// for elastic bean selection
|
Aspect_VKeyFlags aFlags = Aspect_VKeyFlags_NONE;
|
||||||
#define ValZWMin 1
|
if ((theModifiers & Qt::ShiftModifier) != 0)
|
||||||
|
{
|
||||||
|
aFlags |= Aspect_VKeyFlags_SHIFT;
|
||||||
|
}
|
||||||
|
if ((theModifiers & Qt::ControlModifier) != 0)
|
||||||
|
{
|
||||||
|
aFlags |= Aspect_VKeyFlags_CTRL;
|
||||||
|
}
|
||||||
|
if ((theModifiers & Qt::AltModifier) != 0)
|
||||||
|
{
|
||||||
|
aFlags |= Aspect_VKeyFlags_ALT;
|
||||||
|
}
|
||||||
|
return aFlags;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static QCursor* defCursor = NULL;
|
static QCursor* defCursor = NULL;
|
||||||
static QCursor* handCursor = NULL;
|
static QCursor* handCursor = NULL;
|
||||||
@ -60,18 +92,12 @@ View::View( Handle(AIS_InteractiveContext) theContext, QWidget* parent )
|
|||||||
#endif
|
#endif
|
||||||
myContext = theContext;
|
myContext = theContext;
|
||||||
|
|
||||||
myXmin = 0;
|
|
||||||
myYmin = 0;
|
|
||||||
myXmax = 0;
|
|
||||||
myYmax = 0;
|
|
||||||
myCurZoom = 0;
|
myCurZoom = 0;
|
||||||
myRectBand = 0;
|
|
||||||
|
|
||||||
setAttribute(Qt::WA_PaintOnScreen);
|
setAttribute(Qt::WA_PaintOnScreen);
|
||||||
setAttribute(Qt::WA_NoSystemBackground);
|
setAttribute(Qt::WA_NoSystemBackground);
|
||||||
|
|
||||||
|
myDefaultGestures = myMouseGestureMap;
|
||||||
myCurrentMode = CurAction3d_Nothing;
|
myCurrentMode = CurAction3d_Nothing;
|
||||||
myHlrModeIsOn = Standard_False;
|
|
||||||
setMouseTracking( true );
|
setMouseTracking( true );
|
||||||
|
|
||||||
initViewActions();
|
initViewActions();
|
||||||
@ -111,7 +137,8 @@ void View::init()
|
|||||||
void View::paintEvent( QPaintEvent * )
|
void View::paintEvent( QPaintEvent * )
|
||||||
{
|
{
|
||||||
// QApplication::syncX();
|
// QApplication::syncX();
|
||||||
myView->Redraw();
|
myView->InvalidateImmediate();
|
||||||
|
FlushViewEvents (myContext, myView, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void View::resizeEvent( QResizeEvent * )
|
void View::resizeEvent( QResizeEvent * )
|
||||||
@ -123,6 +150,12 @@ void View::resizeEvent( QResizeEvent * )
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void View::OnSelectionChanged (const Handle(AIS_InteractiveContext)& ,
|
||||||
|
const Handle(V3d_View)& )
|
||||||
|
{
|
||||||
|
ApplicationCommonWindow::getApplication()->onSelectionChanged();
|
||||||
|
}
|
||||||
|
|
||||||
void View::fitAll()
|
void View::fitAll()
|
||||||
{
|
{
|
||||||
myView->FitAll();
|
myView->FitAll();
|
||||||
@ -132,22 +165,22 @@ void View::fitAll()
|
|||||||
|
|
||||||
void View::fitArea()
|
void View::fitArea()
|
||||||
{
|
{
|
||||||
myCurrentMode = CurAction3d_WindowZooming;
|
setCurrentAction (CurAction3d_WindowZooming);
|
||||||
}
|
}
|
||||||
|
|
||||||
void View::zoom()
|
void View::zoom()
|
||||||
{
|
{
|
||||||
myCurrentMode = CurAction3d_DynamicZooming;
|
setCurrentAction (CurAction3d_DynamicZooming);
|
||||||
}
|
}
|
||||||
|
|
||||||
void View::pan()
|
void View::pan()
|
||||||
{
|
{
|
||||||
myCurrentMode = CurAction3d_DynamicPanning;
|
setCurrentAction (CurAction3d_DynamicPanning);
|
||||||
}
|
}
|
||||||
|
|
||||||
void View::rotation()
|
void View::rotation()
|
||||||
{
|
{
|
||||||
myCurrentMode = CurAction3d_DynamicRotation;
|
setCurrentAction (CurAction3d_DynamicRotation);
|
||||||
}
|
}
|
||||||
|
|
||||||
void View::globalPan()
|
void View::globalPan()
|
||||||
@ -157,7 +190,7 @@ void View::globalPan()
|
|||||||
// Do a Global Zoom
|
// Do a Global Zoom
|
||||||
myView->FitAll();
|
myView->FitAll();
|
||||||
// Set the mode
|
// Set the mode
|
||||||
myCurrentMode = CurAction3d_GlobalPanning;
|
setCurrentAction (CurAction3d_GlobalPanning);
|
||||||
}
|
}
|
||||||
|
|
||||||
void View::front()
|
void View::front()
|
||||||
@ -203,8 +236,7 @@ void View::reset()
|
|||||||
void View::hlrOff()
|
void View::hlrOff()
|
||||||
{
|
{
|
||||||
QApplication::setOverrideCursor( Qt::WaitCursor );
|
QApplication::setOverrideCursor( Qt::WaitCursor );
|
||||||
myHlrModeIsOn = Standard_False;
|
myView->SetComputedMode (false);
|
||||||
myView->SetComputedMode (myHlrModeIsOn);
|
|
||||||
myView->Redraw();
|
myView->Redraw();
|
||||||
QApplication::restoreOverrideCursor();
|
QApplication::restoreOverrideCursor();
|
||||||
}
|
}
|
||||||
@ -212,8 +244,7 @@ void View::hlrOff()
|
|||||||
void View::hlrOn()
|
void View::hlrOn()
|
||||||
{
|
{
|
||||||
QApplication::setOverrideCursor( Qt::WaitCursor );
|
QApplication::setOverrideCursor( Qt::WaitCursor );
|
||||||
myHlrModeIsOn = Standard_True;
|
myView->SetComputedMode (true);
|
||||||
myView->SetComputedMode (myHlrModeIsOn);
|
|
||||||
myView->Redraw();
|
myView->Redraw();
|
||||||
QApplication::restoreOverrideCursor();
|
QApplication::restoreOverrideCursor();
|
||||||
}
|
}
|
||||||
@ -548,31 +579,6 @@ void View::initRaytraceActions()
|
|||||||
myRaytraceActions->insert( ToolAntialiasingId, a );
|
myRaytraceActions->insert( ToolAntialiasingId, a );
|
||||||
}
|
}
|
||||||
|
|
||||||
void View::mousePressEvent( QMouseEvent* e )
|
|
||||||
{
|
|
||||||
if ( e->button() == Qt::LeftButton )
|
|
||||||
onLButtonDown( ( e->buttons() | e->modifiers() ), e->pos() );
|
|
||||||
else if ( e->button() == Qt::MidButton )
|
|
||||||
onMButtonDown( e->buttons() | e->modifiers(), e->pos() );
|
|
||||||
else if ( e->button() == Qt::RightButton )
|
|
||||||
onRButtonDown( e->buttons() | e->modifiers(), e->pos() );
|
|
||||||
}
|
|
||||||
|
|
||||||
void View::mouseReleaseEvent(QMouseEvent* e)
|
|
||||||
{
|
|
||||||
if ( e->button() == Qt::LeftButton )
|
|
||||||
onLButtonUp( e->buttons(), e->pos() );
|
|
||||||
else if ( e->button() == Qt::MidButton )
|
|
||||||
onMButtonUp( e->buttons(), e->pos() );
|
|
||||||
else if( e->button() == Qt::RightButton )
|
|
||||||
onRButtonUp( e->buttons(), e->pos() );
|
|
||||||
}
|
|
||||||
|
|
||||||
void View::mouseMoveEvent(QMouseEvent* e)
|
|
||||||
{
|
|
||||||
onMouseMove( e->buttons(), e->pos() );
|
|
||||||
}
|
|
||||||
|
|
||||||
void View::activateCursor( const CurrentAction3d mode )
|
void View::activateCursor( const CurrentAction3d mode )
|
||||||
{
|
{
|
||||||
switch( mode )
|
switch( mode )
|
||||||
@ -599,276 +605,124 @@ void View::activateCursor( const CurrentAction3d mode )
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void View::onLButtonDown( const int/*Qt::MouseButtons*/ nFlags, const QPoint point )
|
void View::mousePressEvent (QMouseEvent* theEvent)
|
||||||
{
|
{
|
||||||
// save the current mouse coordinate in min
|
const Graphic3d_Vec2i aPnt (theEvent->pos().x(), theEvent->pos().y());
|
||||||
myXmin = point.x();
|
const Aspect_VKeyFlags aFlags = qtMouseModifiers2VKeys (theEvent->modifiers());
|
||||||
myYmin = point.y();
|
if (!myView.IsNull()
|
||||||
myXmax = point.x();
|
&& UpdateMouseButtons (aPnt,
|
||||||
myYmax = point.y();
|
qtMouseButtons2VKeys (theEvent->buttons()),
|
||||||
|
aFlags,
|
||||||
if ( nFlags & CASCADESHORTCUTKEY )
|
false))
|
||||||
{
|
{
|
||||||
myCurrentMode = CurAction3d_DynamicZooming;
|
updateView();
|
||||||
}
|
}
|
||||||
else
|
myClickPos = aPnt;
|
||||||
|
}
|
||||||
|
|
||||||
|
void View::mouseReleaseEvent (QMouseEvent* theEvent)
|
||||||
|
{
|
||||||
|
const Graphic3d_Vec2i aPnt (theEvent->pos().x(), theEvent->pos().y());
|
||||||
|
const Aspect_VKeyFlags aFlags = qtMouseModifiers2VKeys (theEvent->modifiers());
|
||||||
|
if (!myView.IsNull()
|
||||||
|
&& UpdateMouseButtons (aPnt,
|
||||||
|
qtMouseButtons2VKeys (theEvent->buttons()),
|
||||||
|
aFlags,
|
||||||
|
false))
|
||||||
{
|
{
|
||||||
switch ( myCurrentMode )
|
updateView();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (myCurrentMode == CurAction3d_GlobalPanning)
|
||||||
|
{
|
||||||
|
myView->Place (aPnt.x(), aPnt.y(), myCurZoom);
|
||||||
|
}
|
||||||
|
if (myCurrentMode != CurAction3d_Nothing)
|
||||||
|
{
|
||||||
|
setCurrentAction (CurAction3d_Nothing);
|
||||||
|
}
|
||||||
|
if (theEvent->button() == Qt::RightButton
|
||||||
|
&& (aFlags & Aspect_VKeyFlags_CTRL) == 0
|
||||||
|
&& (myClickPos - aPnt).cwiseAbs().maxComp() <= 4)
|
||||||
|
{
|
||||||
|
Popup (aPnt.x(), aPnt.y());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void View::mouseMoveEvent (QMouseEvent* theEvent)
|
||||||
|
{
|
||||||
|
const Graphic3d_Vec2i aNewPos (theEvent->pos().x(), theEvent->pos().y());
|
||||||
|
if (!myView.IsNull()
|
||||||
|
&& UpdateMousePosition (aNewPos,
|
||||||
|
qtMouseButtons2VKeys (theEvent->buttons()),
|
||||||
|
qtMouseModifiers2VKeys (theEvent->modifiers()),
|
||||||
|
false))
|
||||||
|
{
|
||||||
|
updateView();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//==============================================================================
|
||||||
|
//function : wheelEvent
|
||||||
|
//purpose :
|
||||||
|
//==============================================================================
|
||||||
|
void View::wheelEvent (QWheelEvent* theEvent)
|
||||||
|
{
|
||||||
|
const Graphic3d_Vec2i aPos (theEvent->pos().x(), theEvent->pos().y());
|
||||||
|
if (!myView.IsNull()
|
||||||
|
&& UpdateZoom (Aspect_ScrollDelta (aPos, theEvent->delta() / 8)))
|
||||||
|
{
|
||||||
|
updateView();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// =======================================================================
|
||||||
|
// function : updateView
|
||||||
|
// purpose :
|
||||||
|
// =======================================================================
|
||||||
|
void View::updateView()
|
||||||
|
{
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
|
||||||
|
void View::defineMouseGestures()
|
||||||
|
{
|
||||||
|
myMouseGestureMap.Clear();
|
||||||
|
AIS_MouseGesture aRot = AIS_MouseGesture_RotateOrbit;
|
||||||
|
activateCursor (myCurrentMode);
|
||||||
|
switch (myCurrentMode)
|
||||||
|
{
|
||||||
|
case CurAction3d_Nothing:
|
||||||
{
|
{
|
||||||
case CurAction3d_Nothing:
|
noActiveActions();
|
||||||
if ( nFlags & MULTISELECTIONKEY )
|
myMouseGestureMap = myDefaultGestures;
|
||||||
MultiDragEvent( myXmax, myYmax, -1 );
|
break;
|
||||||
else
|
}
|
||||||
DragEvent( myXmax, myYmax, -1 );
|
case CurAction3d_DynamicZooming:
|
||||||
break;
|
{
|
||||||
case CurAction3d_DynamicZooming:
|
myMouseGestureMap.Bind (Aspect_VKeyMouse_LeftButton, AIS_MouseGesture_Zoom);
|
||||||
break;
|
break;
|
||||||
case CurAction3d_WindowZooming:
|
}
|
||||||
break;
|
case CurAction3d_GlobalPanning:
|
||||||
case CurAction3d_DynamicPanning:
|
{
|
||||||
break;
|
break;
|
||||||
case CurAction3d_GlobalPanning:
|
}
|
||||||
break;
|
case CurAction3d_WindowZooming:
|
||||||
case CurAction3d_DynamicRotation:
|
{
|
||||||
if (myHlrModeIsOn)
|
myMouseGestureMap.Bind (Aspect_VKeyMouse_LeftButton, AIS_MouseGesture_ZoomWindow);
|
||||||
{
|
break;
|
||||||
myView->SetComputedMode (Standard_False);
|
}
|
||||||
}
|
case CurAction3d_DynamicPanning:
|
||||||
myView->StartRotation( point.x(), point.y() );
|
{
|
||||||
break;
|
myMouseGestureMap.Bind (Aspect_VKeyMouse_LeftButton, AIS_MouseGesture_Pan);
|
||||||
default:
|
break;
|
||||||
throw Standard_Failure( "incompatible Current Mode" );
|
}
|
||||||
break;
|
case CurAction3d_DynamicRotation:
|
||||||
|
{
|
||||||
|
myMouseGestureMap.Bind (Aspect_VKeyMouse_LeftButton, aRot);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
activateCursor( myCurrentMode );
|
|
||||||
}
|
|
||||||
|
|
||||||
void View::onMButtonDown( const int/*Qt::MouseButtons*/ nFlags, const QPoint /*point*/ )
|
|
||||||
{
|
|
||||||
if ( nFlags & CASCADESHORTCUTKEY )
|
|
||||||
myCurrentMode = CurAction3d_DynamicPanning;
|
|
||||||
activateCursor( myCurrentMode );
|
|
||||||
}
|
|
||||||
|
|
||||||
void View::onRButtonDown( const int/*Qt::MouseButtons*/ nFlags, const QPoint point )
|
|
||||||
{
|
|
||||||
if ( nFlags & CASCADESHORTCUTKEY )
|
|
||||||
{
|
|
||||||
if (myHlrModeIsOn)
|
|
||||||
{
|
|
||||||
myView->SetComputedMode (Standard_False);
|
|
||||||
}
|
|
||||||
myCurrentMode = CurAction3d_DynamicRotation;
|
|
||||||
myView->StartRotation( point.x(), point.y() );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Popup( point.x(), point.y() );
|
|
||||||
}
|
|
||||||
activateCursor( myCurrentMode );
|
|
||||||
}
|
|
||||||
|
|
||||||
void View::onLButtonUp( Qt::MouseButtons nFlags, const QPoint point )
|
|
||||||
{
|
|
||||||
switch( myCurrentMode )
|
|
||||||
{
|
|
||||||
case CurAction3d_Nothing:
|
|
||||||
if ( point.x() == myXmin && point.y() == myYmin )
|
|
||||||
{
|
|
||||||
// no offset between down and up --> selectEvent
|
|
||||||
myXmax = point.x();
|
|
||||||
myYmax = point.y();
|
|
||||||
if ( nFlags & MULTISELECTIONKEY )
|
|
||||||
MultiInputEvent( point.x(), point.y() );
|
|
||||||
else
|
|
||||||
InputEvent( point.x(), point.y() );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
DrawRectangle( myXmin, myYmin, myXmax, myYmax, Standard_False );
|
|
||||||
myXmax = point.x();
|
|
||||||
myYmax = point.y();
|
|
||||||
if ( nFlags & MULTISELECTIONKEY )
|
|
||||||
MultiDragEvent( point.x(), point.y(), 1 );
|
|
||||||
else
|
|
||||||
DragEvent( point.x(), point.y(), 1 );
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case CurAction3d_DynamicZooming:
|
|
||||||
myCurrentMode = CurAction3d_Nothing;
|
|
||||||
noActiveActions();
|
|
||||||
break;
|
|
||||||
case CurAction3d_WindowZooming:
|
|
||||||
DrawRectangle( myXmin, myYmin, myXmax, myYmax, Standard_False );//,LongDash);
|
|
||||||
myXmax = point.x();
|
|
||||||
myYmax = point.y();
|
|
||||||
if ( (abs( myXmin - myXmax ) > ValZWMin ) ||
|
|
||||||
(abs( myYmin - myYmax ) > ValZWMin ) )
|
|
||||||
myView->WindowFitAll( myXmin, myYmin, myXmax, myYmax );
|
|
||||||
myCurrentMode = CurAction3d_Nothing;
|
|
||||||
noActiveActions();
|
|
||||||
break;
|
|
||||||
case CurAction3d_DynamicPanning:
|
|
||||||
myCurrentMode = CurAction3d_Nothing;
|
|
||||||
noActiveActions();
|
|
||||||
break;
|
|
||||||
case CurAction3d_GlobalPanning :
|
|
||||||
myView->Place( point.x(), point.y(), myCurZoom );
|
|
||||||
myCurrentMode = CurAction3d_Nothing;
|
|
||||||
noActiveActions();
|
|
||||||
break;
|
|
||||||
case CurAction3d_DynamicRotation:
|
|
||||||
myCurrentMode = CurAction3d_Nothing;
|
|
||||||
noActiveActions();
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
throw Standard_Failure(" incompatible Current Mode ");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
activateCursor( myCurrentMode );
|
|
||||||
ApplicationCommonWindow::getApplication()->onSelectionChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
void View::onMButtonUp( Qt::MouseButtons /*nFlags*/, const QPoint /*point*/ )
|
|
||||||
{
|
|
||||||
myCurrentMode = CurAction3d_Nothing;
|
|
||||||
activateCursor( myCurrentMode );
|
|
||||||
}
|
|
||||||
|
|
||||||
void View::onRButtonUp( Qt::MouseButtons /*nFlags*/, const QPoint point )
|
|
||||||
{
|
|
||||||
if ( myCurrentMode == CurAction3d_Nothing )
|
|
||||||
Popup( point.x(), point.y() );
|
|
||||||
else
|
|
||||||
{
|
|
||||||
QApplication::setOverrideCursor( Qt::WaitCursor );
|
|
||||||
// reset tyhe good Degenerated mode according to the strored one
|
|
||||||
// --> dynamic rotation may have change it
|
|
||||||
if (myHlrModeIsOn)
|
|
||||||
{
|
|
||||||
myView->SetComputedMode (myHlrModeIsOn);
|
|
||||||
myView->Redraw();
|
|
||||||
}
|
|
||||||
QApplication::restoreOverrideCursor();
|
|
||||||
myCurrentMode = CurAction3d_Nothing;
|
|
||||||
}
|
|
||||||
activateCursor( myCurrentMode );
|
|
||||||
}
|
|
||||||
|
|
||||||
void View::onMouseMove( Qt::MouseButtons nFlags, const QPoint point )
|
|
||||||
{
|
|
||||||
if ( nFlags & Qt::LeftButton || nFlags & Qt::RightButton || nFlags & Qt::MidButton )
|
|
||||||
{
|
|
||||||
switch ( myCurrentMode )
|
|
||||||
{
|
|
||||||
case CurAction3d_Nothing:
|
|
||||||
myXmax = point.x();
|
|
||||||
myYmax = point.y();
|
|
||||||
DrawRectangle( myXmin, myYmin, myXmax, myYmax, Standard_False );
|
|
||||||
if ( nFlags & MULTISELECTIONKEY )
|
|
||||||
MultiDragEvent( myXmax, myYmax, 0 );
|
|
||||||
else
|
|
||||||
DragEvent( myXmax, myYmax, 0 );
|
|
||||||
DrawRectangle( myXmin, myYmin, myXmax, myYmax, Standard_True );
|
|
||||||
break;
|
|
||||||
case CurAction3d_DynamicZooming:
|
|
||||||
myView->Zoom( myXmax, myYmax, point.x(), point.y() );
|
|
||||||
myXmax = point.x();
|
|
||||||
myYmax = point.y();
|
|
||||||
break;
|
|
||||||
case CurAction3d_WindowZooming:
|
|
||||||
myXmax = point.x();
|
|
||||||
myYmax = point.y();
|
|
||||||
DrawRectangle( myXmin, myYmin, myXmax, myYmax, Standard_False );
|
|
||||||
DrawRectangle( myXmin, myYmin, myXmax, myYmax, Standard_True );
|
|
||||||
break;
|
|
||||||
case CurAction3d_DynamicPanning:
|
|
||||||
myView->Pan( point.x() - myXmax, myYmax - point.y() );
|
|
||||||
myXmax = point.x();
|
|
||||||
myYmax = point.y();
|
|
||||||
break;
|
|
||||||
case CurAction3d_GlobalPanning:
|
|
||||||
break;
|
|
||||||
case CurAction3d_DynamicRotation:
|
|
||||||
myView->Rotation( point.x(), point.y() );
|
|
||||||
myView->Redraw();
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
throw Standard_Failure( "incompatible Current Mode" );
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
myXmax = point.x();
|
|
||||||
myYmax = point.y();
|
|
||||||
if ( nFlags & MULTISELECTIONKEY )
|
|
||||||
MultiMoveEvent( point.x(), point.y() );
|
|
||||||
else
|
|
||||||
MoveEvent( point.x(), point.y() );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void View::DragEvent( const int x, const int y, const int TheState )
|
|
||||||
{
|
|
||||||
// TheState == -1 button down
|
|
||||||
// TheState == 0 move
|
|
||||||
// TheState == 1 button up
|
|
||||||
|
|
||||||
static Standard_Integer theButtonDownX = 0;
|
|
||||||
static Standard_Integer theButtonDownY = 0;
|
|
||||||
|
|
||||||
if ( TheState == -1 )
|
|
||||||
{
|
|
||||||
theButtonDownX = x;
|
|
||||||
theButtonDownY = y;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( TheState == 1 )
|
|
||||||
{
|
|
||||||
myContext->Select( theButtonDownX, theButtonDownY, x, y, myView, Standard_True );
|
|
||||||
emit selectionChanged();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void View::InputEvent( const int /*x*/, const int /*y*/ )
|
|
||||||
{
|
|
||||||
myContext->Select (Standard_True);
|
|
||||||
emit selectionChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
void View::MoveEvent( const int x, const int y )
|
|
||||||
{
|
|
||||||
myContext->MoveTo( x, y, myView, Standard_True );
|
|
||||||
}
|
|
||||||
|
|
||||||
void View::MultiMoveEvent( const int x, const int y )
|
|
||||||
{
|
|
||||||
myContext->MoveTo( x, y, myView, Standard_True );
|
|
||||||
}
|
|
||||||
|
|
||||||
void View::MultiDragEvent( const int x, const int y, const int TheState )
|
|
||||||
{
|
|
||||||
static Standard_Integer theButtonDownX = 0;
|
|
||||||
static Standard_Integer theButtonDownY = 0;
|
|
||||||
|
|
||||||
if ( TheState == -1 )
|
|
||||||
{
|
|
||||||
theButtonDownX = x;
|
|
||||||
theButtonDownY = y;
|
|
||||||
}
|
|
||||||
if ( TheState == 0 )
|
|
||||||
{
|
|
||||||
myContext->ShiftSelect( theButtonDownX, theButtonDownY, x, y, myView, Standard_True );
|
|
||||||
emit selectionChanged();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void View::MultiInputEvent( const int /*x*/, const int /*y*/ )
|
|
||||||
{
|
|
||||||
myContext->ShiftSelect (Standard_True);
|
|
||||||
emit selectionChanged();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void View::Popup( const int /*x*/, const int /*y*/ )
|
void View::Popup( const int /*x*/, const int /*y*/ )
|
||||||
@ -930,49 +784,6 @@ void View::addItemInPopup( QMenu* /*theMenu*/)
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void View::DrawRectangle(const int MinX, const int MinY,
|
|
||||||
const int MaxX, const int MaxY, const bool Draw)
|
|
||||||
{
|
|
||||||
static Standard_Integer StoredMinX, StoredMaxX, StoredMinY, StoredMaxY;
|
|
||||||
static Standard_Boolean m_IsVisible;
|
|
||||||
|
|
||||||
StoredMinX = (MinX < MaxX) ? MinX: MaxX ;
|
|
||||||
StoredMinY = (MinY < MaxY) ? MinY: MaxY ;
|
|
||||||
StoredMaxX = (MinX > MaxX) ? MinX: MaxX ;
|
|
||||||
StoredMaxY = (MinY > MaxY) ? MinY: MaxY ;
|
|
||||||
|
|
||||||
QRect aRect;
|
|
||||||
aRect.setRect( StoredMinX, StoredMinY, abs(StoredMaxX-StoredMinX), abs(StoredMaxY-StoredMinY));
|
|
||||||
|
|
||||||
if ( !myRectBand )
|
|
||||||
{
|
|
||||||
myRectBand = new QRubberBand( QRubberBand::Rectangle, this );
|
|
||||||
myRectBand->setStyle( QStyleFactory::create("windows") );
|
|
||||||
myRectBand->setGeometry( aRect );
|
|
||||||
myRectBand->show();
|
|
||||||
|
|
||||||
/*QPalette palette;
|
|
||||||
palette.setColor(myRectBand->foregroundRole(), Qt::white);
|
|
||||||
myRectBand->setPalette(palette);*/
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( m_IsVisible && !Draw ) // move or up : erase at the old position
|
|
||||||
{
|
|
||||||
myRectBand->hide();
|
|
||||||
delete myRectBand;
|
|
||||||
myRectBand = 0;
|
|
||||||
m_IsVisible = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Draw) // move : draw
|
|
||||||
{
|
|
||||||
//aRect.setRect( StoredMinX, StoredMinY, abs(StoredMaxX-StoredMinX), abs(StoredMaxY-StoredMinY));
|
|
||||||
m_IsVisible = true;
|
|
||||||
myRectBand->setGeometry( aRect );
|
|
||||||
//myRectBand->show();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void View::noActiveActions()
|
void View::noActiveActions()
|
||||||
{
|
{
|
||||||
for ( int i = ViewFitAllId; i < ViewHlrOffId ; i++ )
|
for ( int i = ViewFitAllId; i < ViewHlrOffId ; i++ )
|
||||||
@ -1052,6 +863,3 @@ View::CurrentAction3d View::getCurrentMode()
|
|||||||
{
|
{
|
||||||
return myCurrentMode;
|
return myCurrentMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -8,13 +8,14 @@
|
|||||||
#include <Standard_WarningsRestore.hxx>
|
#include <Standard_WarningsRestore.hxx>
|
||||||
|
|
||||||
#include <AIS_InteractiveContext.hxx>
|
#include <AIS_InteractiveContext.hxx>
|
||||||
|
#include <AIS_ViewController.hxx>
|
||||||
#include <V3d_View.hxx>
|
#include <V3d_View.hxx>
|
||||||
|
|
||||||
class TopoDS_Shape;
|
class TopoDS_Shape;
|
||||||
class QRubberBand;
|
class QRubberBand;
|
||||||
|
|
||||||
//class COMMONSAMPLE_EXPORT View: public QWidget
|
//class COMMONSAMPLE_EXPORT View: public QWidget
|
||||||
class View: public QWidget
|
class View: public QWidget, protected AIS_ViewController
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
protected:
|
protected:
|
||||||
@ -95,6 +96,7 @@ protected:
|
|||||||
virtual void mousePressEvent( QMouseEvent* );
|
virtual void mousePressEvent( QMouseEvent* );
|
||||||
virtual void mouseReleaseEvent(QMouseEvent* );
|
virtual void mouseReleaseEvent(QMouseEvent* );
|
||||||
virtual void mouseMoveEvent( QMouseEvent* );
|
virtual void mouseMoveEvent( QMouseEvent* );
|
||||||
|
virtual void wheelEvent (QWheelEvent* );
|
||||||
|
|
||||||
virtual void addItemInPopup( QMenu* );
|
virtual void addItemInPopup( QMenu* );
|
||||||
|
|
||||||
@ -103,48 +105,41 @@ protected:
|
|||||||
void activateCursor( const CurrentAction3d );
|
void activateCursor( const CurrentAction3d );
|
||||||
void Popup( const int x, const int y );
|
void Popup( const int x, const int y );
|
||||||
CurrentAction3d getCurrentMode();
|
CurrentAction3d getCurrentMode();
|
||||||
|
void updateView();
|
||||||
|
|
||||||
virtual void onLButtonDown( const int nFlags, const QPoint point );
|
//! Setup mouse gestures.
|
||||||
virtual void onMButtonDown( const int nFlags, const QPoint point );
|
void defineMouseGestures();
|
||||||
virtual void onRButtonDown( const int nFlags, const QPoint point );
|
|
||||||
virtual void onLButtonUp( Qt::MouseButtons nFlags, const QPoint point );
|
//! Set current action.
|
||||||
virtual void onMButtonUp( Qt::MouseButtons nFlags, const QPoint point );
|
void setCurrentAction (CurrentAction3d theAction)
|
||||||
virtual void onRButtonUp( Qt::MouseButtons nFlags, const QPoint point );
|
{
|
||||||
virtual void onMouseMove( Qt::MouseButtons nFlags, const QPoint point );
|
myCurrentMode = theAction;
|
||||||
|
defineMouseGestures();
|
||||||
|
}
|
||||||
|
|
||||||
|
//! Handle selection changed event.
|
||||||
|
void OnSelectionChanged (const Handle(AIS_InteractiveContext)& theCtx,
|
||||||
|
const Handle(V3d_View)& theView) Standard_OVERRIDE;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void initCursors();
|
void initCursors();
|
||||||
void initViewActions();
|
void initViewActions();
|
||||||
void initRaytraceActions();
|
void initRaytraceActions();
|
||||||
void DragEvent( const int x, const int y, const int TheState );
|
|
||||||
void InputEvent( const int x, const int y );
|
|
||||||
void MoveEvent( const int x, const int y );
|
|
||||||
void MultiMoveEvent( const int x, const int y );
|
|
||||||
void MultiDragEvent( const int x, const int y, const int TheState );
|
|
||||||
void MultiInputEvent( const int x, const int y );
|
|
||||||
void DrawRectangle( const int MinX, const int MinY,
|
|
||||||
const int MaxX, const int MaxY, const bool Draw );
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool myIsRaytracing;
|
bool myIsRaytracing;
|
||||||
bool myIsShadowsEnabled;
|
bool myIsShadowsEnabled;
|
||||||
bool myIsReflectionsEnabled;
|
bool myIsReflectionsEnabled;
|
||||||
bool myIsAntialiasingEnabled;
|
bool myIsAntialiasingEnabled;
|
||||||
|
|
||||||
bool myDrawRect; // set when a rect is used for selection or magnify
|
|
||||||
Handle(V3d_View) myView;
|
Handle(V3d_View) myView;
|
||||||
Handle(AIS_InteractiveContext) myContext;
|
Handle(AIS_InteractiveContext) myContext;
|
||||||
|
AIS_MouseGestureMap myDefaultGestures;
|
||||||
|
Graphic3d_Vec2i myClickPos;
|
||||||
CurrentAction3d myCurrentMode;
|
CurrentAction3d myCurrentMode;
|
||||||
Standard_Integer myXmin;
|
|
||||||
Standard_Integer myYmin;
|
|
||||||
Standard_Integer myXmax;
|
|
||||||
Standard_Integer myYmax;
|
|
||||||
Standard_Real myCurZoom;
|
Standard_Real myCurZoom;
|
||||||
Standard_Boolean myHlrModeIsOn;
|
|
||||||
QList<QAction*>* myViewActions;
|
QList<QAction*>* myViewActions;
|
||||||
QList<QAction*>* myRaytraceActions;
|
QList<QAction*>* myRaytraceActions;
|
||||||
QMenu* myBackMenu;
|
QMenu* myBackMenu;
|
||||||
QRubberBand* myRectBand; //!< selection rectangle rubber band
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user