From 550e8f952b9fd5bc2c8fc7f9dc5429d37afcee4e Mon Sep 17 00:00:00 2001 From: ouv Date: Thu, 4 Aug 2016 13:48:12 +0300 Subject: [PATCH] 0003998: External 20809 Coordinates plot surfaces --- src/Plot3d/Plot3d_ViewWindow.cxx | 83 ++++++++++++++++++++++++ src/Plot3d/Plot3d_ViewWindow.h | 8 +++ src/Plot3d/resources/Plot3d_msg_en.ts | 4 ++ src/SVTK/SVTK_InteractorStyle.cxx | 13 +++- src/SVTK/SVTK_InteractorStyle.h | 4 ++ src/SVTK/SVTK_RenderWindowInteractor.cxx | 2 +- 6 files changed, 111 insertions(+), 3 deletions(-) diff --git a/src/Plot3d/Plot3d_ViewWindow.cxx b/src/Plot3d/Plot3d_ViewWindow.cxx index c318478e3..412dd8977 100644 --- a/src/Plot3d/Plot3d_ViewWindow.cxx +++ b/src/Plot3d/Plot3d_ViewWindow.cxx @@ -27,6 +27,7 @@ #include #include +#include #include #include @@ -36,16 +37,21 @@ #include #include #include +#include #include #include +#include +#include #include #include #include +#include #include #include +#include #include #include #include @@ -120,6 +126,10 @@ Plot3d_ViewWindow::Plot3d_ViewWindow( SUIT_Desktop* theDesktop ): myFitDataBounds[3] = -1; myFitDataBounds[4] = 0; myFitDataBounds[5] = -1; + + // Cell picker (required to display mapped coordinates in the status bar) + myCellPicker = vtkCellPicker::New(); + myCellPicker->Delete(); } /*! @@ -158,6 +168,14 @@ void Plot3d_ViewWindow::Initialize( SVTK_ViewModelBase* theModel ) } } + SVTK_RenderWindowInteractor* anInteractor = GetInteractor(); + connect( anInteractor, SIGNAL( MouseMove( QMouseEvent* ) ), this, SLOT( onMouseMove( QMouseEvent* ) ) ); + connect( anInteractor, SIGNAL( MouseButtonPressed( QMouseEvent* ) ), this, SLOT( onMouseButtonPressed( QMouseEvent* ) ) ); + connect( anInteractor, SIGNAL( MouseButtonReleased( QMouseEvent* ) ), this, SLOT( onMouseButtonReleased( QMouseEvent* ) ) ); + + myStandardInteractorStyle->SetIsSelectionEnabled( false ); + myKeyFreeInteractorStyle->SetIsSelectionEnabled( false ); + if( vtkRenderer* aRenderer = getRenderer() ) aRenderer->AddActor( myScalarBarActor.GetPointer() ); } @@ -618,6 +636,61 @@ void Plot3d_ViewWindow::onFitData() } } +/*! + Slot called when the mouse is moved. + \param theEvent mouse event +*/ +void Plot3d_ViewWindow::onMouseMove( QMouseEvent* theEvent ) +{ + QString aMsg; + if( theEvent->buttons() & Qt::LeftButton && !( theEvent->modifiers() & Qt::ControlModifier ) ) + { + double aXPos = (double)theEvent->x(); + double aYPos = (double)theEvent->y(); + + aYPos = getInteractor()->GetSize()[1] - aYPos - 1.0; // see SVTK_InteractorStyle.cxx, inline function GetEventPosition() + + myCellPicker->Pick( aXPos, aYPos, 0, getRenderer() ); + vtkPoints* aPoints = myCellPicker->GetPickedPositions(); + if( aPoints && aPoints->GetNumberOfPoints() > 0 ) + { + double* aPoint = aPoints->GetPoint( 0 ); + + double aScale[3]; + GetScale( aScale ); // take into account the current scale + + double aXCoord = fabs( aScale[0] ) > DBL_EPSILON ? aPoint[0] / aScale[0] : aPoint[0]; + double aYCoord = fabs( aScale[1] ) > DBL_EPSILON ? aPoint[1] / aScale[1] : aPoint[1]; + double aZCoord = fabs( aScale[2] ) > DBL_EPSILON ? aPoint[2] / aScale[2] : aPoint[2]; + + QString aXStr = QString().sprintf( "%g", aXCoord ); + QString aYStr = QString().sprintf( "%g", aYCoord ); + QString aZStr = QString().sprintf( "%g", aZCoord ); + + aMsg = tr( "INF_COORDINATES_XYZ" ).arg( aXStr, aYStr, aZStr ); + } + } + putInfo( aMsg ); +} + +/*! + Slot called when the mouse button is pressed. + \param theEvent mouse event +*/ +void Plot3d_ViewWindow::onMouseButtonPressed( QMouseEvent* theEvent ) +{ + onMouseMove( theEvent ); +} + +/*! + Slot called when the mouse button is released. + \param theEvent mouse event +*/ +void Plot3d_ViewWindow::onMouseButtonReleased( QMouseEvent* theEvent ) +{ + putInfo( QString() ); +} + /*! Store 2D/3D view state \param theViewState - view state to be stored @@ -671,6 +744,16 @@ void Plot3d_ViewWindow::clearViewState( const bool theIs2D ) myStored3DViewState.IsInitialized = false; } +/*! + \brief Put message to the status bar. + \param theMsg message text +*/ +void Plot3d_ViewWindow::putInfo( const QString& theMsg ) +{ + QStatusBar* aStatusBar = myDesktop->statusBar(); + aStatusBar->showMessage( theMsg ); +} + /*! Get actor of the global scalar bar \return actor of the global scalar bar diff --git a/src/Plot3d/Plot3d_ViewWindow.h b/src/Plot3d/Plot3d_ViewWindow.h index 18ce20042..48e49e1c4 100644 --- a/src/Plot3d/Plot3d_ViewWindow.h +++ b/src/Plot3d/Plot3d_ViewWindow.h @@ -23,6 +23,7 @@ #include +class vtkCellPicker; class vtkLookupTable; class vtkScalarBarActor; class vtkScalarBarWidget; @@ -54,6 +55,8 @@ public: void clearViewState( const bool theIs2D ); + void putInfo( const QString& theMsg ); + vtkSmartPointer GetScalarBarActor() const; void UpdateScalarBar( const bool theIsRepaint = true ); @@ -66,6 +69,9 @@ public slots: void onSurfacesSettings(); void onMergeScalarBars( bool theOn ); void onFitData(); + void onMouseMove( QMouseEvent* theEvent ); + void onMouseButtonPressed( QMouseEvent* theEvent ); + void onMouseButtonReleased( QMouseEvent* theEvent ); protected: struct ViewState @@ -107,6 +113,8 @@ protected: bool myIsFitDataInitialized; bool myIsFitDataEnabled; double myFitDataBounds[6]; + + vtkSmartPointer myCellPicker; }; #endif diff --git a/src/Plot3d/resources/Plot3d_msg_en.ts b/src/Plot3d/resources/Plot3d_msg_en.ts index 35e941a55..0e5df8b5f 100644 --- a/src/Plot3d/resources/Plot3d_msg_en.ts +++ b/src/Plot3d/resources/Plot3d_msg_en.ts @@ -18,6 +18,10 @@ The scale has been switched to linear. minimum value of the range is less or equal zero. Correct the range or switch to linear scale? + + INF_COORDINATES_XYZ + Coordinates: X : %1, Y : %2, Z: %3 + NO_OBJECTS_TO_FIT No objects to fit diff --git a/src/SVTK/SVTK_InteractorStyle.cxx b/src/SVTK/SVTK_InteractorStyle.cxx index 0e61dc1f2..05cae30d0 100644 --- a/src/SVTK/SVTK_InteractorStyle.cxx +++ b/src/SVTK/SVTK_InteractorStyle.cxx @@ -94,7 +94,8 @@ SVTK_InteractorStyle::SVTK_InteractorStyle(): myControllerOnKeyDown(SVTK_ControllerOnKeyDown::New()), myHighlightSelectionPointActor(SVTK_Actor::New()), myRectBand(0), - myIsRotationEnabled( true ) + myIsRotationEnabled( true ), + myIsSelectionEnabled( true ) { myPointPicker->Delete(); @@ -522,7 +523,7 @@ void SVTK_InteractorStyle::OnLeftButtonDown(int ctrl, int shift, GetRenderWidget()->setCursor(myDefCursor); } - else + else if( myIsSelectionEnabled ) startOperation(VTK_INTERACTOR_STYLE_CAMERA_SELECT); } @@ -1724,6 +1725,14 @@ void SVTK_InteractorStyle::SetIsRotationEnabled( const bool theState ) myIsRotationEnabled = theState; } +/*! + Enable/disable selection +*/ +void SVTK_InteractorStyle::SetIsSelectionEnabled( const bool theState ) +{ + myIsSelectionEnabled = theState; +} + /*! To get current increment controller */ diff --git a/src/SVTK/SVTK_InteractorStyle.h b/src/SVTK/SVTK_InteractorStyle.h index 15d329e93..b4a9616db 100644 --- a/src/SVTK/SVTK_InteractorStyle.h +++ b/src/SVTK/SVTK_InteractorStyle.h @@ -231,6 +231,9 @@ class SVTK_EXPORT SVTK_InteractorStyle: public vtkInteractorStyle //! Enable/disable rotation void SetIsRotationEnabled( const bool theState ); + //! Enable/disable selection + void SetIsSelectionEnabled( const bool theState ); + protected: SVTK_InteractorStyle(); ~SVTK_InteractorStyle(); @@ -355,6 +358,7 @@ class SVTK_EXPORT SVTK_InteractorStyle: public vtkInteractorStyle QRubberBand* myRectBand; //!< selection rectangle rubber band bool myIsRotationEnabled; + bool myIsSelectionEnabled; }; #ifdef WIN32 diff --git a/src/SVTK/SVTK_RenderWindowInteractor.cxx b/src/SVTK/SVTK_RenderWindowInteractor.cxx index 6f96493b5..55a696b6d 100644 --- a/src/SVTK/SVTK_RenderWindowInteractor.cxx +++ b/src/SVTK/SVTK_RenderWindowInteractor.cxx @@ -59,7 +59,7 @@ using namespace std; -static bool GENERATE_SUIT_EVENTS = false; +static bool GENERATE_SUIT_EVENTS = true; static bool FOCUS_UNDER_MOUSE = false; -- 2.39.2