From 012b508ac3ce401e2c3d6fb22325c587b51e5d50 Mon Sep 17 00:00:00 2001 From: vsr Date: Wed, 29 Dec 2004 05:56:20 +0000 Subject: [PATCH] Implement PAL7620 improvement: provide key-bindings for viewer operations, like zooming, panning, rotating. --- src/OCCViewer/OCCViewer_ViewFrame.cxx | 91 ++++++++++++++ src/OCCViewer/OCCViewer_ViewFrame.h | 11 ++ src/OCCViewer/OCCViewer_ViewPort.h | 7 +- src/OCCViewer/OCCViewer_ViewPort3d.cxx | 33 ++++- src/OCCViewer/OCCViewer_ViewPort3d.h | 4 + src/Plot2d/Plot2d_ViewFrame.cxx | 115 ++++++++++++++---- src/Plot2d/Plot2d_ViewFrame.h | 10 ++ .../VTKViewer_InteractorStyleSALOME.cxx | 14 +++ .../VTKViewer_InteractorStyleSALOME.h | 3 + src/VTKViewer/VTKViewer_ViewFrame.cxx | 91 ++++++++++++++ src/VTKViewer/VTKViewer_ViewFrame.h | 11 ++ 11 files changed, 367 insertions(+), 23 deletions(-) diff --git a/src/OCCViewer/OCCViewer_ViewFrame.cxx b/src/OCCViewer/OCCViewer_ViewFrame.cxx index caa2d2f27..90645fdb2 100644 --- a/src/OCCViewer/OCCViewer_ViewFrame.cxx +++ b/src/OCCViewer/OCCViewer_ViewFrame.cxx @@ -1135,3 +1135,94 @@ void OCCViewer_ViewFrame::AfterDisplay( SALOME_Displayer* d ) d->AfterDisplay( this, SALOME_OCCViewType() ); } +#define INCREMENT_FOR_OP 10 + +//======================================================================= +// name : onPanLeft +// Purpose : Performs incremental panning to the left +//======================================================================= +void OCCViewer_ViewFrame::onPanLeft() +{ + myViewPort->incrementalPan( -INCREMENT_FOR_OP, 0 ); +} + +//======================================================================= +// name : onPanRight +// Purpose : Performs incremental panning to the right +//======================================================================= +void OCCViewer_ViewFrame::onPanRight() +{ + myViewPort->incrementalPan( INCREMENT_FOR_OP, 0 ); +} + +//======================================================================= +// name : onPanUp +// Purpose : Performs incremental panning to the top +//======================================================================= +void OCCViewer_ViewFrame::onPanUp() +{ + myViewPort->incrementalPan( 0, INCREMENT_FOR_OP ); +} + +//======================================================================= +// name : onPanDown +// Purpose : Performs incremental panning to the bottom +//======================================================================= +void OCCViewer_ViewFrame::onPanDown() +{ + myViewPort->incrementalPan( 0, -INCREMENT_FOR_OP ); +} + +//======================================================================= +// name : onZoomIn +// Purpose : Performs incremental zooming in +//======================================================================= +void OCCViewer_ViewFrame::onZoomIn() +{ + myViewPort->incrementalZoom( INCREMENT_FOR_OP ); +} + +//======================================================================= +// name : onZoomOut +// Purpose : Performs incremental zooming out +//======================================================================= +void OCCViewer_ViewFrame::onZoomOut() +{ + myViewPort->incrementalZoom( -INCREMENT_FOR_OP ); +} + +//======================================================================= +// name : onRotateLeft +// Purpose : Performs incremental rotating to the left +//======================================================================= +void OCCViewer_ViewFrame::onRotateLeft() +{ + myViewPort->incrementalRotate( -INCREMENT_FOR_OP, 0 ); +} + +//======================================================================= +// name : onRotateRight +// Purpose : Performs incremental rotating to the right +//======================================================================= +void OCCViewer_ViewFrame::onRotateRight() +{ + myViewPort->incrementalRotate( INCREMENT_FOR_OP, 0 ); +} + +//======================================================================= +// name : onRotateUp +// Purpose : Performs incremental rotating to the top +//======================================================================= +void OCCViewer_ViewFrame::onRotateUp() +{ + myViewPort->incrementalRotate( 0, -INCREMENT_FOR_OP ); +} + +//======================================================================= +// name : onRotateDown +// Purpose : Performs incremental rotating to the bottom +//======================================================================= +void OCCViewer_ViewFrame::onRotateDown() +{ + myViewPort->incrementalRotate( 0, INCREMENT_FOR_OP ); +} diff --git a/src/OCCViewer/OCCViewer_ViewFrame.h b/src/OCCViewer/OCCViewer_ViewFrame.h index 42b3c0685..9f6b4a55d 100644 --- a/src/OCCViewer/OCCViewer_ViewFrame.h +++ b/src/OCCViewer/OCCViewer_ViewFrame.h @@ -153,6 +153,17 @@ public slots: void onViewTrihedron(); void onAdjustTrihedron(); + void onPanLeft(); + void onPanRight(); + void onPanUp(); + void onPanDown(); + void onZoomIn(); + void onZoomOut(); + void onRotateLeft(); + void onRotateRight(); + void onRotateUp(); + void onRotateDown(); + protected: void initViewPort(); diff --git a/src/OCCViewer/OCCViewer_ViewPort.h b/src/OCCViewer/OCCViewer_ViewPort.h index 7b7a6552c..6f80c7816 100644 --- a/src/OCCViewer/OCCViewer_ViewPort.h +++ b/src/OCCViewer/OCCViewer_ViewPort.h @@ -129,7 +129,12 @@ public: virtual void fitAll( bool withZ = true ) = 0; virtual void reset() = 0; - + + virtual void incrementalPan ( const int incrX, const int incrY ) = 0; + virtual void incrementalZoom ( const int incr ) = 0; + virtual void incrementalRotate( const int incrX, const int incrY ) = 0; + + /* background color */ virtual QColor backgroundColor() const; virtual void setBackgroundColor( const QColor& color) = 0; diff --git a/src/OCCViewer/OCCViewer_ViewPort3d.cxx b/src/OCCViewer/OCCViewer_ViewPort3d.cxx index 68a73d4a5..0ace89025 100644 --- a/src/OCCViewer/OCCViewer_ViewPort3d.cxx +++ b/src/OCCViewer/OCCViewer_ViewPort3d.cxx @@ -84,7 +84,6 @@ void OCCViewer_ViewPort3d::onCreatePopup() { if ( myPopup ) { QAD_Desktop* Desktop = (QAD_Desktop*) QAD_Application::getDesktop(); - QAD_Study* myActiveStudy = Desktop->getActiveStudy(); QString theContext; QString theParent("Viewer"); @@ -385,3 +384,35 @@ void OCCViewer_ViewPort3d::reset() myActiveView->Reset(); } } + +/*! + Incremental panning +*/ +void OCCViewer_ViewPort3d::incrementalPan( const int incrX, const int incrY ) +{ + this->pan( incrX, incrY ); +} + +/*! + Incremental zooming +*/ +void OCCViewer_ViewPort3d::incrementalZoom( const int incr ) +{ + int cx = width() / 2; + int cy = height() / 2; + this->zoom( cx, cy, cx + incr, cy + incr ); +} + +/*! + Incremental rotating +*/ +void OCCViewer_ViewPort3d::incrementalRotate( const int incrX, const int incrY ) +{ + int cx = width() / 2; + int cy = height() / 2; + this->startRotation( cx, cy ); + this->rotate( cx + incrX, cy + incrY ); + this->endRotation(); +} + + diff --git a/src/OCCViewer/OCCViewer_ViewPort3d.h b/src/OCCViewer/OCCViewer_ViewPort3d.h index 446cb65ca..e36ca9de2 100644 --- a/src/OCCViewer/OCCViewer_ViewPort3d.h +++ b/src/OCCViewer/OCCViewer_ViewPort3d.h @@ -71,6 +71,10 @@ class QAD_EXPORT OCCViewer_ViewPort3d: public OCCViewer_ViewPort void fitAll( bool withZ = true ); void reset(); + void incrementalPan ( const int incrX, const int incrY ); + void incrementalZoom ( const int incr ); + void incrementalRotate( const int incrX, const int incrY ); + /* background */ void setBackgroundColor( const QColor& color); QColor backgroundColor() const; diff --git a/src/Plot2d/Plot2d_ViewFrame.cxx b/src/Plot2d/Plot2d_ViewFrame.cxx index ae6234cb8..cde7a3961 100644 --- a/src/Plot2d/Plot2d_ViewFrame.cxx +++ b/src/Plot2d/Plot2d_ViewFrame.cxx @@ -412,7 +412,7 @@ void Plot2d_ViewFrame::DisplayAll() getCurves( clist ); for ( int i = 0; i < clist.count(); i++ ) { updateCurve( clist.at( i ), false ); - } + } myPlot->replot(); } /*! @@ -1447,29 +1447,11 @@ void Plot2d_ViewFrame::plotMouseMoved( const QMouseEvent& me ) if ( myOperation != NoOpId) { if ( myOperation == ZoomId ) { - QwtDiMap xMap = myPlot->canvasMap( QwtPlot::xBottom ); - QwtDiMap yMap = myPlot->canvasMap( QwtPlot::yLeft ); - - myPlot->setAxisScale( QwtPlot::yLeft, - myPlot->invTransform( QwtPlot::yLeft, yMap.i1() ), - myPlot->invTransform( QwtPlot::yLeft, yMap.i2() + dy ) ); - myPlot->setAxisScale( QwtPlot::xBottom, - myPlot->invTransform( QwtPlot::xBottom, xMap.i1() ), - myPlot->invTransform( QwtPlot::xBottom, xMap.i2() - dx ) ); - myPlot->replot(); + this->incrementalZoom( dx, dy ); myPnt = me.pos(); } else if ( myOperation == PanId ) { - QwtDiMap xMap = myPlot->canvasMap( QwtPlot::xBottom ); - QwtDiMap yMap = myPlot->canvasMap( QwtPlot::yLeft ); - - myPlot->setAxisScale( QwtPlot::yLeft, - myPlot->invTransform( QwtPlot::yLeft, yMap.i1()-dy ), - myPlot->invTransform( QwtPlot::yLeft, yMap.i2()-dy ) ); - myPlot->setAxisScale( QwtPlot::xBottom, - myPlot->invTransform( QwtPlot::xBottom, xMap.i1()-dx ), - myPlot->invTransform( QwtPlot::xBottom, xMap.i2()-dx ) ); - myPlot->replot(); + this->incrementalPan( dx, dy ); myPnt = me.pos(); } } @@ -1810,3 +1792,94 @@ void Plot2d_ViewFrame::AfterDisplay( SALOME_Displayer* d ) { d->AfterDisplay( this, SALOME_Plot2dViewType() ); } + +#define INCREMENT_FOR_OP 10 + +//======================================================================= +// Plot2d_ViewFrame::onPanLeft +// Performs incremental panning to the left +//======================================================================= +void Plot2d_ViewFrame::onPanLeft() +{ + this->incrementalPan( -INCREMENT_FOR_OP, 0 ); +} + +//======================================================================= +// Plot2d_ViewFrame::onPanRight +// Performs incremental panning to the right +//======================================================================= +void Plot2d_ViewFrame::onPanRight() +{ + this->incrementalPan( INCREMENT_FOR_OP, 0 ); +} + +//======================================================================= +// Plot2d_ViewFrame::onPanUp +// Performs incremental panning to the top +//======================================================================= +void Plot2d_ViewFrame::onPanUp() +{ + this->incrementalPan( 0, -INCREMENT_FOR_OP ); +} + +//======================================================================= +// Plot2d_ViewFrame::onPanDown +// Performs incremental panning to the bottom +//======================================================================= +void Plot2d_ViewFrame::onPanDown() +{ + this->incrementalPan( 0, INCREMENT_FOR_OP ); +} + +//======================================================================= +// Plot2d_ViewFrame::onZoomIn +// Performs incremental zooming in +//======================================================================= +void Plot2d_ViewFrame::onZoomIn() +{ + this->incrementalZoom( INCREMENT_FOR_OP, INCREMENT_FOR_OP ); +} + +//======================================================================= +// Plot2d_ViewFrame::onZoomOut +// Performs incremental zooming out +//======================================================================= +void Plot2d_ViewFrame::onZoomOut() +{ + this->incrementalZoom( -INCREMENT_FOR_OP, -INCREMENT_FOR_OP ); +} + +//======================================================================= +// Plot2d_ViewFrame::incrementalPan +// Incremental zooming operation +//======================================================================= +void Plot2d_ViewFrame::incrementalPan( const int incrX, const int incrY ) { + QwtDiMap xMap = myPlot->canvasMap( QwtPlot::xBottom ); + QwtDiMap yMap = myPlot->canvasMap( QwtPlot::yLeft ); + + myPlot->setAxisScale( QwtPlot::yLeft, + myPlot->invTransform( QwtPlot::yLeft, yMap.i1()-incrY ), + myPlot->invTransform( QwtPlot::yLeft, yMap.i2()-incrY ) ); + myPlot->setAxisScale( QwtPlot::xBottom, + myPlot->invTransform( QwtPlot::xBottom, xMap.i1()-incrX ), + myPlot->invTransform( QwtPlot::xBottom, xMap.i2()-incrX ) ); + myPlot->replot(); +} + +//======================================================================= +// Plot2d_ViewFrame::incrementalZoom +// Incremental panning operation +//======================================================================= +void Plot2d_ViewFrame::incrementalZoom( const int incrX, const int incrY ) { + QwtDiMap xMap = myPlot->canvasMap( QwtPlot::xBottom ); + QwtDiMap yMap = myPlot->canvasMap( QwtPlot::yLeft ); + + myPlot->setAxisScale( QwtPlot::yLeft, + myPlot->invTransform( QwtPlot::yLeft, yMap.i1() ), + myPlot->invTransform( QwtPlot::yLeft, yMap.i2() + incrY ) ); + myPlot->setAxisScale( QwtPlot::xBottom, + myPlot->invTransform( QwtPlot::xBottom, xMap.i1() ), + myPlot->invTransform( QwtPlot::xBottom, xMap.i2() - incrX ) ); + myPlot->replot(); +} + diff --git a/src/Plot2d/Plot2d_ViewFrame.h b/src/Plot2d/Plot2d_ViewFrame.h index 04c87155c..275c432fb 100644 --- a/src/Plot2d/Plot2d_ViewFrame.h +++ b/src/Plot2d/Plot2d_ViewFrame.h @@ -124,6 +124,9 @@ public: void setVerScaleMode( const int mode, bool update = true ); int getVerScaleMode() const { return myYMode; } + void incrementalPan ( const int incrX, const int incrY ); + void incrementalZoom( const int incrX, const int incrY ); + protected: void createActions(); int testOperation( const QMouseEvent& ); @@ -155,6 +158,13 @@ public slots: void onFitData(); void onChangeBackground(); + void onPanLeft(); + void onPanRight(); + void onPanUp(); + void onPanDown(); + void onZoomIn(); + void onZoomOut(); + protected slots: void onLegendClicked( long key ); void plotMousePressed( const QMouseEvent& ); diff --git a/src/VTKViewer/VTKViewer_InteractorStyleSALOME.cxx b/src/VTKViewer/VTKViewer_InteractorStyleSALOME.cxx index 276a5bc6d..0fd4d7c52 100644 --- a/src/VTKViewer/VTKViewer_InteractorStyleSALOME.cxx +++ b/src/VTKViewer/VTKViewer_InteractorStyleSALOME.cxx @@ -1474,6 +1474,20 @@ Handle(VTKViewer_Filter) VTKViewer_InteractorStyleSALOME::GetFilter( const int t return IsFilterPresent( theId ) ? myFilters[ theId ] : Handle(VTKViewer_Filter)(); } +void VTKViewer_InteractorStyleSALOME::IncrementalPan( const int incrX, const int incrY ) +{ + this->PanXY( incrX, incrY, 0, 0 ); +} + +void VTKViewer_InteractorStyleSALOME::IncrementalZoom( const int incr ) +{ + this->DollyXY( incr, incr ); +} + +void VTKViewer_InteractorStyleSALOME::IncrementalRotate( const int incrX, const int incrY ) +{ + this->RotateXY( incrX, -incrY ); +} diff --git a/src/VTKViewer/VTKViewer_InteractorStyleSALOME.h b/src/VTKViewer/VTKViewer_InteractorStyleSALOME.h index 851aeafdf..2952537a3 100644 --- a/src/VTKViewer/VTKViewer_InteractorStyleSALOME.h +++ b/src/VTKViewer/VTKViewer_InteractorStyleSALOME.h @@ -93,6 +93,9 @@ class VTKViewer_InteractorStyleSALOME : public QObject, public vtkInteractorStyl const int theId, const bool theIsNode = false ); + void IncrementalPan ( const int incrX, const int incrY ); + void IncrementalZoom ( const int incr ); + void IncrementalRotate( const int incrX, const int incrY ); protected: VTKViewer_InteractorStyleSALOME(); diff --git a/src/VTKViewer/VTKViewer_ViewFrame.cxx b/src/VTKViewer/VTKViewer_ViewFrame.cxx index 1dc5b8db4..067cc6aee 100644 --- a/src/VTKViewer/VTKViewer_ViewFrame.cxx +++ b/src/VTKViewer/VTKViewer_ViewFrame.cxx @@ -841,6 +841,97 @@ void VTKViewer_ViewFrame::redisplayAll( QAD_Study* theQADStudy, const bool theTo Repaint(); } +#define INCREMENT_FOR_OP 10 + +//======================================================================= +// name : onPanLeft +// Purpose : Performs incremental panning to the left +//======================================================================= +void VTKViewer_ViewFrame::onPanLeft() +{ + m_RWInteractor->GetInteractorStyleSALOME()->IncrementalPan( -INCREMENT_FOR_OP, 0 ); +} + +//======================================================================= +// name : onPanRight +// Purpose : Performs incremental panning to the right +//======================================================================= +void VTKViewer_ViewFrame::onPanRight() +{ + m_RWInteractor->GetInteractorStyleSALOME()->IncrementalPan( INCREMENT_FOR_OP, 0 ); +} + +//======================================================================= +// name : onPanUp +// Purpose : Performs incremental panning to the top +//======================================================================= +void VTKViewer_ViewFrame::onPanUp() +{ + m_RWInteractor->GetInteractorStyleSALOME()->IncrementalPan( 0, INCREMENT_FOR_OP ); +} + +//======================================================================= +// name : onPanDown +// Purpose : Performs incremental panning to the bottom +//======================================================================= +void VTKViewer_ViewFrame::onPanDown() +{ + m_RWInteractor->GetInteractorStyleSALOME()->IncrementalPan( 0, -INCREMENT_FOR_OP ); +} + +//======================================================================= +// name : onZoomIn +// Purpose : Performs incremental zooming in +//======================================================================= +void VTKViewer_ViewFrame::onZoomIn() +{ + m_RWInteractor->GetInteractorStyleSALOME()->IncrementalZoom( INCREMENT_FOR_OP ); +} + +//======================================================================= +// name : onZoomOut +// Purpose : Performs incremental zooming out +//======================================================================= +void VTKViewer_ViewFrame::onZoomOut() +{ + m_RWInteractor->GetInteractorStyleSALOME()->IncrementalZoom( -INCREMENT_FOR_OP ); +} + +//======================================================================= +// name : onRotateLeft +// Purpose : Performs incremental rotating to the left +//======================================================================= +void VTKViewer_ViewFrame::onRotateLeft() +{ + m_RWInteractor->GetInteractorStyleSALOME()->IncrementalRotate( -INCREMENT_FOR_OP, 0 ); +} + +//======================================================================= +// name : onRotateRight +// Purpose : Performs incremental rotating to the right +//======================================================================= +void VTKViewer_ViewFrame::onRotateRight() +{ + m_RWInteractor->GetInteractorStyleSALOME()->IncrementalRotate( INCREMENT_FOR_OP, 0 ); +} + +//======================================================================= +// name : onRotateUp +// Purpose : Performs incremental rotating to the top +//======================================================================= +void VTKViewer_ViewFrame::onRotateUp() +{ + m_RWInteractor->GetInteractorStyleSALOME()->IncrementalRotate( 0, -INCREMENT_FOR_OP ); +} + +//======================================================================= +// name : onRotateDown +// Purpose : Performs incremental rotating to the bottom +//======================================================================= +void VTKViewer_ViewFrame::onRotateDown() +{ + m_RWInteractor->GetInteractorStyleSALOME()->IncrementalRotate( 0, INCREMENT_FOR_OP ); +} diff --git a/src/VTKViewer/VTKViewer_ViewFrame.h b/src/VTKViewer/VTKViewer_ViewFrame.h index 6a8d79b25..cef0aaa5f 100644 --- a/src/VTKViewer/VTKViewer_ViewFrame.h +++ b/src/VTKViewer/VTKViewer_ViewFrame.h @@ -128,6 +128,17 @@ public slots: void onViewTrihedron(); void onAdjustTrihedron(); + void onPanLeft(); + void onPanRight(); + void onPanUp(); + void onPanDown(); + void onZoomIn(); + void onZoomOut(); + void onRotateLeft(); + void onRotateRight(); + void onRotateUp(); + void onRotateDown(); + private: void InitialSetup(); void redisplayAll( QAD_Study*, const bool = true ); -- 2.39.2