Salome HOME
Fix for the bug #45: check and warning when the same image is used in 2 arguments.
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_Module.cxx
index 604ed597512ab270758189fc867e779fdf846210..19d2e20757c0f91b3f4d75e5eb7b0e5a6a8f72c9 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();
@@ -227,7 +253,7 @@ void HYDROGUI_Module::contextMenuPopup( const QString& theClient,
   bool anIsFusedImage = false;
   bool anIsCutImage = false;
   bool anIsSplittedImage = false;
-  bool anIsMustBeUpdatedImage = false;
+  bool anIsMustobjectBeUpdated = false;
   bool anIsPolyline = false;
   bool anIsPolyline3D = false;
   bool anIsProfile = false;
@@ -241,6 +267,7 @@ void HYDROGUI_Module::contextMenuPopup( const QString& theClient,
   bool anIsZone = false;
   bool anIsObstacle = false;
   bool anIsStream = false;
+  bool anIsChannel = false;
   bool anIsGeomObject = false;
 
   // check the selected GEOM objects
@@ -263,6 +290,11 @@ void HYDROGUI_Module::contextMenuPopup( const QString& theClient,
       anIsVisibleInSelection |= aVisibility;
       anIsHiddenInSelection |= !aVisibility;
 
+      if ( anObject->IsMustBeUpdated() )
+      {
+        anIsMustobjectBeUpdated = true;
+      }
+
       ObjectKind anObjectKind = anObject->GetKind();
       if( anObjectKind == KIND_IMAGE )
       {
@@ -285,10 +317,6 @@ void HYDROGUI_Module::contextMenuPopup( const QString& theClient,
                 anIsSplittedImage = true;
             }
           }
-          if ( anImage->IsMustBeUpdated() )
-          {
-            anIsMustBeUpdatedImage = true;
-          }
         }
       }
       else if( anObjectKind == KIND_POLYLINEXY )
@@ -322,6 +350,8 @@ void HYDROGUI_Module::contextMenuPopup( const QString& theClient,
         anIsObstacle = true;
       else if( anObjectKind == KIND_STREAM )
         anIsStream = true;
+      else if( anObjectKind == KIND_CHANNEL )
+        anIsChannel = true;
     }
 
     anIsGeomObject = HYDROData_Tool::IsGeometryObject( anObject );
@@ -342,6 +372,24 @@ void HYDROGUI_Module::contextMenuPopup( const QString& theClient,
         case KIND_IMAGE:
           theMenu->addAction( action( ImportImageId ) );
           break;
+        case KIND_BATHYMETRY:
+          theMenu->addAction( action( ImportBathymetryId ) );
+          break;
+        case KIND_ARTIFICIAL_OBJECT:
+          theMenu->addAction( action( CreateChannelId ) );
+          break;
+        case KIND_NATURAL_OBJECT:
+          theMenu->addAction( action( CreateImmersibleZoneId ) );
+          theMenu->addAction( action( CreateStreamId ) );
+          break;
+        case KIND_OBSTACLE:
+          theMenu->addAction( action( ImportObstacleFromFileId ) );
+          theMenu->addAction( action( CreateBoxId ) );
+          theMenu->addAction( action( CreateCylinderId ) );
+          break;
+        case KIND_CALCULATION:
+          theMenu->addAction( action( CreateCalculationId ) );
+          break;
         case KIND_POLYLINEXY:
           theMenu->addAction( action( CreatePolylineId ) );
           break;
@@ -356,20 +404,6 @@ void HYDROGUI_Module::contextMenuPopup( const QString& theClient,
         case KIND_VISUAL_STATE:
           theMenu->addAction( action( SaveVisualStateId ) );
           break;
-        case KIND_BATHYMETRY:
-          theMenu->addAction( action( ImportBathymetryId ) );
-          break;
-        case KIND_CALCULATION:
-          theMenu->addAction( action( CreateCalculationId ) );
-          break;
-        case KIND_IMMERSIBLE_ZONE:
-          theMenu->addAction( action( CreateImmersibleZoneId ) );
-          break;
-        case KIND_OBSTACLE:
-          theMenu->addAction( action( ImportObstacleFromFileId ) );
-          theMenu->addAction( action( CreateBoxId ) );
-          theMenu->addAction( action( CreateCylinderId ) );
-          break;
       }
       theMenu->addSeparator();
     }
@@ -377,9 +411,9 @@ void HYDROGUI_Module::contextMenuPopup( const QString& theClient,
 
   if( anIsSelectedDataObjects )
   {
-    if ( anIsMustBeUpdatedImage )
+    if ( anIsMustobjectBeUpdated )
     {
-      theMenu->addAction( action( UpdateImageId ) );
+      theMenu->addAction( action( UpdateObjectId ) );
       theMenu->addSeparator();
     }
 
@@ -399,7 +433,7 @@ void HYDROGUI_Module::contextMenuPopup( const QString& theClient,
             theMenu->addAction( action( EditSplittedImageId ) );
         }
 
-        theMenu->addAction( action( ObserveImageId ) );
+        //RKV: BUG#98: theMenu->addAction( action( ObserveImageId ) );
         theMenu->addAction( action( ExportImageId ) );
         theMenu->addSeparator();
 
@@ -414,6 +448,11 @@ void HYDROGUI_Module::contextMenuPopup( const QString& theClient,
         theMenu->addAction( action( SplitImageId ) );
         theMenu->addSeparator();
       }
+      else if( anIsBathymetry )
+      {
+        theMenu->addAction( action( EditImportedBathymetryId ) );
+        theMenu->addSeparator();
+      }
       else if( anIsPolyline )
       {
         theMenu->addAction( action( EditPolylineId ) );
@@ -446,6 +485,11 @@ void HYDROGUI_Module::contextMenuPopup( const QString& theClient,
         theMenu->addAction( action( EditStreamId ) );
         theMenu->addSeparator();
       }
+      else if( anIsChannel )
+      {
+        theMenu->addAction( action( EditChannelId ) );
+        theMenu->addSeparator();
+      }
       else if( anIsVisualState && anIsObjectBrowser )
       {
         theMenu->addAction( action( SaveVisualStateId ) );
@@ -467,8 +511,10 @@ void HYDROGUI_Module::contextMenuPopup( const QString& theClient,
     theMenu->addAction( action( DeleteId ) );
     theMenu->addSeparator();
 
-    if( anIsImage || anIsPolyline || anIsPolyline3D || anIsImmersibleZone || anIsZone || 
-        anIsRegion || anIsBathymetry || anIsObstacle || anIsStream || anIsValidProfile )
+    if( anIsImage || anIsPolyline || anIsPolyline3D || 
+        anIsImmersibleZone || anIsZone || anIsRegion ||
+        anIsBathymetry || anIsObstacle || anIsStream ||
+        anIsChannel || anIsValidProfile )
     {
       if( anIsHiddenInSelection )
         theMenu->addAction( action( ShowId ) );
@@ -944,6 +990,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 );
 }
 
@@ -960,6 +1017,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
@@ -1021,6 +1080,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 );
+      }
     }
   }
 }
@@ -1185,3 +1249,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