From 20c995635bc4476073e5431c116a7d99aba97cb2 Mon Sep 17 00:00:00 2001 From: mzn Date: Mon, 2 Dec 2013 14:13:12 +0000 Subject: [PATCH] Feature #102: show coordinates in status bar for OCC viewer. --- src/HYDROGUI/HYDROGUI_Module.cxx | 70 +++++++++++++++++++++++ src/HYDROGUI/HYDROGUI_Module.h | 2 + src/HYDROGUI/HYDROGUI_Tool.cxx | 5 ++ src/HYDROGUI/HYDROGUI_Tool.h | 7 +++ src/HYDROGUI/resources/HYDROGUI_msg_en.ts | 4 ++ 5 files changed, 88 insertions(+) diff --git a/src/HYDROGUI/HYDROGUI_Module.cxx b/src/HYDROGUI/HYDROGUI_Module.cxx index f3bba4b9..cad9dc66 100644 --- a/src/HYDROGUI/HYDROGUI_Module.cxx +++ b/src/HYDROGUI/HYDROGUI_Module.cxx @@ -77,10 +77,16 @@ #include #include +#include + +#include + #include #include #include #include +#include +#include static int ViewManagerId = 0; @@ -156,6 +162,19 @@ bool HYDROGUI_Module::activateModule( SUIT_Study* theStudy ) HYDROGUI_Tool::setOCCActionShown( this, OCCViewer_ViewWindow::MaximizedId, false ); + ViewManagerList anOCCViewManagers; + anApp->viewManagers( OCCViewer_Viewer::Type(), anOCCViewManagers ); + foreach ( const SUIT_ViewManager* aViewManager, anOCCViewManagers ) { + connect( aViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ), + this, SLOT( onMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) ); + foreach( SUIT_ViewWindow* aViewWindow, aViewManager->getViews() ) { + OCCViewer_ViewFrame* aViewFrame = dynamic_cast( aViewWindow ); + if ( aViewFrame && aViewFrame->getViewPort() ) { + aViewFrame->getViewPort()->installEventFilter( this ); + } + } + } + return aRes; } @@ -167,6 +186,13 @@ bool HYDROGUI_Module::deactivateModule( SUIT_Study* theStudy ) getApp()->removeViewManager( aViewManager ); myViewManagerMap.clear(); + ViewManagerList anOCCViewManagers; + getApp()->viewManagers( OCCViewer_Viewer::Type(), anOCCViewManagers ); + foreach ( const SUIT_ViewManager* aViewManager, anOCCViewManagers ) { + disconnect( aViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ), + this, SLOT( onMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) ); + } + myObjectStateMap.clear(); myShapesMap.clear(); myVTKPrsMap.clear(); @@ -947,6 +973,17 @@ bool HYDROGUI_Module::eventFilter( QObject* theObj, QEvent* theEvent ) theObj->removeEventFilter( this ); } } + else if ( theObj->inherits( "OCCViewer_ViewPort" ) ) + { + if( aType == QEvent::Leave ) + { + SUIT_Desktop* aDesktop = getApp()->desktop(); + if ( aDesktop && aDesktop->statusBar() ) { + aDesktop->statusBar()->clearMessage(); + } + } + } + return LightApp_Module::eventFilter( theObj, theEvent ); } @@ -963,6 +1000,8 @@ void HYDROGUI_Module::onViewManagerAdded( SUIT_ViewManager* theViewManager ) { connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ), this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) ); + connect( theViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ), + this, SLOT( onMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) ); } createSelector( theViewManager ); // replace the default selector @@ -1024,6 +1063,11 @@ void HYDROGUI_Module::onViewCreated( SUIT_ViewWindow* theViewWindow ) aViewFrame->onTopView(); HYDROGUI_Tool::setOCCActionShown( aViewFrame, OCCViewer_ViewWindow::MaximizedId, false ); + + OCCViewer_ViewPort3d* aViewPort = aViewFrame->getViewPort(); + if ( aViewPort ) { + aViewPort->installEventFilter( this ); + } } } } @@ -1188,3 +1232,29 @@ void HYDROGUI_Module::restoreSelection( const QStringList& theEntryList ) aSelectionMgr->setSelected( aList ); } } + +void HYDROGUI_Module::onMouseMove( SUIT_ViewWindow* theViewWindow, QMouseEvent* theEvent ) +{ + OCCViewer_ViewWindow* anOCCViewWindow = + dynamic_cast(theViewWindow); + if ( !anOCCViewWindow ) { + return; + } + + // Get the selected point coordinates + OCCViewer_ViewPort3d* aViewPort = anOCCViewWindow->getViewPort(); + if ( !aViewPort ) { + return; + } + + gp_Pnt aPnt = GEOMUtils::ConvertClickToPoint( theEvent->x(), theEvent->y(), + aViewPort->getView() ); + + // Show the coordinates in the status bar + SUIT_Desktop* aDesktop = getApp()->desktop(); + if ( aDesktop && aDesktop->statusBar() ) { + QString aX = HYDROGUI_Tool::GetCoordinateString( aPnt.X() ); + QString anY = HYDROGUI_Tool::GetCoordinateString( aPnt.Y() ); + aDesktop->statusBar()->showMessage( tr("COORDINATES_INFO").arg( aX ).arg( anY ) ); + } +} \ No newline at end of file diff --git a/src/HYDROGUI/HYDROGUI_Module.h b/src/HYDROGUI/HYDROGUI_Module.h index a0a117a9..3b09238f 100644 --- a/src/HYDROGUI/HYDROGUI_Module.h +++ b/src/HYDROGUI/HYDROGUI_Module.h @@ -181,6 +181,8 @@ protected slots: void onExternalOperationFinished( const QString&, const QString&, const QStringList& ); + void onMouseMove( SUIT_ViewWindow*, QMouseEvent* ); + private: void updateViewer( HYDROGUI_AbstractDisplayer* theDisplayer, const bool theIsInit = false, diff --git a/src/HYDROGUI/HYDROGUI_Tool.cxx b/src/HYDROGUI/HYDROGUI_Tool.cxx index bd764fe8..2189ebd1 100644 --- a/src/HYDROGUI/HYDROGUI_Tool.cxx +++ b/src/HYDROGUI/HYDROGUI_Tool.cxx @@ -630,3 +630,8 @@ QStringList HYDROGUI_Tool::FindExistingObjectsNames( const Handle(HYDROData_Docu return aNames; } + +QString HYDROGUI_Tool::GetCoordinateString( const double theNumber ) +{ + return QString::number( theNumber, 'f', 2 ); +} \ No newline at end of file diff --git a/src/HYDROGUI/HYDROGUI_Tool.h b/src/HYDROGUI/HYDROGUI_Tool.h index ec6f2075..18a3d587 100644 --- a/src/HYDROGUI/HYDROGUI_Tool.h +++ b/src/HYDROGUI/HYDROGUI_Tool.h @@ -316,6 +316,13 @@ public: */ static QStringList FindExistingObjectsNames( const Handle(HYDROData_Document)& theDoc, const ObjectKind theObjectKind ); + + /** + * \brief Converts coordinate value to string. + * \param theNumber coordinate as a number + * \return coordinate as a string + */ + static QString GetCoordinateString( const double theNumber ); }; #endif diff --git a/src/HYDROGUI/resources/HYDROGUI_msg_en.ts b/src/HYDROGUI/resources/HYDROGUI_msg_en.ts index 4b13e041..7ffb7cde 100644 --- a/src/HYDROGUI/resources/HYDROGUI_msg_en.ts +++ b/src/HYDROGUI/resources/HYDROGUI_msg_en.ts @@ -1016,6 +1016,10 @@ file cannot be correctly imported for a Bathymetry definition. STB_COLOR Set object color + + COORDINATES_INFO + X: %1, Y: %2 + -- 2.39.2