]> SALOME platform Git repositories - modules/hydro.git/commitdiff
Salome HOME
Feature #102: show coordinates in status bar for OCC viewer.
authormzn <mzn@opencascade.com>
Mon, 2 Dec 2013 14:13:12 +0000 (14:13 +0000)
committermzn <mzn@opencascade.com>
Mon, 2 Dec 2013 14:13:12 +0000 (14:13 +0000)
src/HYDROGUI/HYDROGUI_Module.cxx
src/HYDROGUI/HYDROGUI_Module.h
src/HYDROGUI/HYDROGUI_Tool.cxx
src/HYDROGUI/HYDROGUI_Tool.h
src/HYDROGUI/resources/HYDROGUI_msg_en.ts

index f3bba4b99093547a808d3d6458f681d06b54e0a2..cad9dc666008bdef9ea84852fb0e13ffd325ce31 100644 (file)
 #include <SVTK_ViewModel.h>
 #include <SVTK_Selector.h>
 
+#include <OCCViewer_ViewPort3d.h>
+
+#include <GEOMUtils.hxx>
+
 #include <QAction>
 #include <QApplication>
 #include <QGraphicsSceneMouseEvent>
 #include <QMenu>
+#include <QMouseEvent>
+#include <QStatusBar>
 
 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<OCCViewer_ViewFrame*>( 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<OCCViewer_ViewWindow*>(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
index a0a117a92bfaed27cab0e28ac4751a540f290622..3b09238fa18238279c59bc3058b903541c9b24ed 100644 (file)
@@ -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, 
index bd764fe83267f6dc89dfff8f0e6b2e145163e9d1..2189ebd1006427e3469ff5adb970195a3630d26a 100644 (file)
@@ -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
index ec6f207528ff16b7837708f1a2f9335c718a172f..18a3d587e4df9c2034c03cffbc23543d192cf73b 100644 (file)
@@ -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
index 4b13e041be928bdfee475d5f847c9750a8c3c03f..7ffb7cdecbfb6f48ee0baeecf2efce2c05598e07 100644 (file)
@@ -1016,6 +1016,10 @@ file cannot be correctly imported for a Bathymetry definition.</translation>
       <source>STB_COLOR</source>
       <translation>Set object color</translation>
     </message>
+    <message>
+      <source>COORDINATES_INFO</source>
+      <translation>X: %1, Y: %2</translation>
+    </message>
   </context>
   
   <context>