Salome HOME
portage V8_5_0
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_Module.cxx
index 36d652a722076189f98e2562b997ffe162475ec6..03a78832368f51deb1616c17644940f9052df243 100644 (file)
@@ -41,7 +41,7 @@
 #include "HYDROGUI_ImportGeomObjectOp.h"
 #include "HYDROGUI_ShowHideOp.h"
 #include "HYDROGUI_Overview.h"
-
+#include <HYDROGUI_ProfileDlg.h>
 #include <HYDROData_Tool.h>
 #include <HYDROData_Image.h>
 #include <HYDROData_Stream.h>
@@ -214,13 +214,19 @@ bool HYDROGUI_Module::activateModule( SUIT_Study* theStudy )
   ViewManagerList anOCCViewManagers;
   anApp->viewManagers( OCCViewer_Viewer::Type(), anOCCViewManagers );
 
-  foreach ( const SUIT_ViewManager* aViewManager, anOCCViewManagers )
+  foreach ( SUIT_ViewManager* aViewManager, anOCCViewManagers )
   {
     connect( aViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ),
              this, SLOT( onMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
     connect( aViewManager, SIGNAL( activated( SUIT_ViewManager* ) ), 
              this, SLOT( onViewActivated( SUIT_ViewManager* ) ) );
 
+    OCCViewer_ViewManager* occ_mgr = dynamic_cast<OCCViewer_ViewManager*>( aViewManager );
+    if( occ_mgr )
+    {
+      occ_mgr->setChainedOperations( true );//TODO: via preferences
+    }
+
     foreach( SUIT_ViewWindow* aViewWindow, aViewManager->getViews() )
     {
       OCCViewer_ViewFrame* aViewFrame = dynamic_cast<OCCViewer_ViewFrame*>( aViewWindow );
@@ -231,6 +237,10 @@ bool HYDROGUI_Module::activateModule( SUIT_Study* theStudy )
     }
   }
 
+  preferencesChanged( "HYDRO", "zoom_shutoff" );
+
+  preferencesChanged( "HYDRO", "chained_panning" );
+
   // Load GEOM data
   SalomeApp_Study* aStudy = 
     dynamic_cast<SalomeApp_Study*>( getApp()->activeStudy() );
@@ -246,6 +256,7 @@ bool HYDROGUI_Module::activateModule( SUIT_Study* theStudy )
     }
   }
 
+
 //  SUIT_DataBrowser* ob = getApp()->objectBrowser();
 //  SUIT_AbstractModel* treeModel = dynamic_cast<SUIT_AbstractModel*>( ob->model() );
 //  treeModel->setAppropriate( SUIT_DataObject::VisibilityId, Qtx::Toggled );
@@ -265,9 +276,17 @@ bool HYDROGUI_Module::deactivateModule( SUIT_Study* theStudy )
 
   ViewManagerList anOCCViewManagers;
   getApp()->viewManagers( OCCViewer_Viewer::Type(), anOCCViewManagers );
-  foreach ( const SUIT_ViewManager* aViewManager, anOCCViewManagers ) {
+  foreach ( SUIT_ViewManager* aViewManager, anOCCViewManagers )
+  {
     disconnect( aViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ),
                 this, SLOT( onMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
+
+    OCCViewer_ViewManager* occ_mgr = dynamic_cast<OCCViewer_ViewManager*>( aViewManager );
+    if( occ_mgr )
+    {
+      occ_mgr->setChainedOperations( false );
+      setAutoZoom( occ_mgr, true );
+    }
   }
 
   /* Issues ## 68, 88.
@@ -293,6 +312,9 @@ bool HYDROGUI_Module::deactivateModule( SUIT_Study* theStudy )
   HYDROGUI_Tool::setOCCActionShown( this, OCCViewer_ViewWindow::MaximizedId, true );
 
   myActiveOperationMap.clear();
+
+  myViewManagerMap.clear();
+
   return LightApp_Module::deactivateModule( theStudy );
 }
 
@@ -495,7 +517,7 @@ void HYDROGUI_Module::contextMenuPopup( const QString& theClient,
         Handle(HYDROData_Stream) aStream = 
           Handle(HYDROData_Stream)::DownCast( anObject );
         if ( !aStream.IsNull() )
-            isStreamHasBottom = !aStream->GetBottomPolyline().IsNull();
+          isStreamHasBottom = !aStream->GetBottomPolyline().IsNull();
       }
       else if( anObjectKind == KIND_CHANNEL )
         anIsChannel = true;
@@ -513,7 +535,7 @@ void HYDROGUI_Module::contextMenuPopup( const QString& theClient,
 
   // Check if all selected objects are profiles
   anAllAreProfiles = ( aNbOfSelectedProfiles > 0 ) &&
-                     ( aNbOfSelectedProfiles == aSeq.Length() );
+    ( aNbOfSelectedProfiles == aSeq.Length() );
 
   // check the selected partitions
   if( !anIsSelectedDataObjects && anIsObjectBrowser )
@@ -523,53 +545,61 @@ void HYDROGUI_Module::contextMenuPopup( const QString& theClient,
     {
       switch( aSelectedPartition )
       {
-        case KIND_IMAGE:
-          theMenu->addAction( action( ImportImageId ) );
-          break;
-        case KIND_BATHYMETRY:
-          theMenu->addAction( action( ImportBathymetryId ) );
-          break;
-        case KIND_ARTIFICIAL_OBJECT:
-          theMenu->addAction( action( CreateChannelId ) );
-          theMenu->addAction( action( CreateDigueId ) );
-          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_STRICKLER_TABLE:
-          theMenu->addAction( action( ImportStricklerTableFromFileId ) );          
-          break;
-        case KIND_LAND_COVER_MAP:
-          theMenu->addAction( action( CreateLandCoverMapId ) ); 
-          theMenu->addAction( action( ImportLandCoverMapId ) ); 
-          break;
-        case KIND_CALCULATION:
-          theMenu->addAction( action( CreateCalculationId ) );
-          break;
-        case KIND_POLYLINEXY:
-          theMenu->addAction( action( ImportPolylineId ) );
-          theMenu->addAction( action( CreatePolylineId ) );
-          break;
-        case KIND_POLYLINE:
-          theMenu->addAction( action( CreatePolyline3DId ) );
-          break;
-        case KIND_PROFILE:
-          theMenu->addAction( action( CreateProfileId ) );
-          theMenu->addAction( action( ImportProfilesId ) );
-          theMenu->addAction( action( AllGeoreferencementId ) );
-          break;
-        case KIND_VISUAL_STATE:
-          theMenu->addAction( action( SaveVisualStateId ) );
-          break;
+      case KIND_IMAGE:
+        theMenu->addAction( action( ImportImageId ) );
+        break;
+      case KIND_BATHYMETRY:
+        theMenu->addAction( action( ImportBathymetryId ) );
+        break;
+      case KIND_ARTIFICIAL_OBJECT:
+        theMenu->addAction( action( CreateChannelId ) );
+        theMenu->addAction( action( CreateDigueId ) );
+        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_STRICKLER_TABLE:
+        theMenu->addAction( action( ImportStricklerTableFromFileId ) );          
+        break;
+      case KIND_LAND_COVER_MAP:
+        theMenu->addAction( action( CreateLandCoverMapId ) ); 
+        theMenu->addAction( action( ImportLandCoverMapId ) ); 
+        break;
+      case KIND_CALCULATION:
+        theMenu->addAction( action( CreateCalculationId ) );
+        break;
+      case KIND_POLYLINEXY:
+        theMenu->addAction( action( ImportPolylineId ) );
+        theMenu->addAction( action( CreatePolylineId ) );
+        break;
+      case KIND_POLYLINE:
+        theMenu->addAction( action( CreatePolyline3DId ) );
+        break;
+      case KIND_PROFILE:
+        theMenu->addAction( action( CreateProfileId ) );
+        theMenu->addAction( action( ImportProfilesId ) );
+        theMenu->addAction( action( AllGeoreferencementId ) );
+        break;
+      case KIND_VISUAL_STATE:
+        theMenu->addAction( action( SaveVisualStateId ) );
+        break;
       }
       theMenu->addSeparator();
     }
+    else
+    {
+      Handle(HYDROData_CalculationCase) aCalcCase;
+      QString outStr;
+      HYDROGUI_Tool::IsSelectedPartOfCalcCase(this, aCalcCase, outStr);
+      if (outStr == HYDROGUI_DataModel::partitionName( KIND_REGION ))
+        theMenu->addAction( action( RegenerateRegionColorsId ) );
+    }
   }
 
   if( anIsSelectedDataObjects )
@@ -660,8 +690,8 @@ void HYDROGUI_Module::contextMenuPopup( const QString& theClient,
         theMenu->addAction( action( EditStreamId ) );
         if ( action( RiverBottomContextId ) )
         {
-            theMenu->addAction( action( RiverBottomContextId ) );
-            action( RiverBottomContextId )->setEnabled( !isStreamHasBottom );
+          theMenu->addAction( action( RiverBottomContextId ) );
+          action( RiverBottomContextId )->setEnabled( !isStreamHasBottom );
         }
         theMenu->addAction( action( ProfileInterpolateId ) );
         theMenu->addSeparator();
@@ -718,6 +748,8 @@ void HYDROGUI_Module::contextMenuPopup( const QString& theClient,
         theMenu->addAction( action( LoadVisualStateId ) );
         theMenu->addSeparator();
       }
+      else if (anIsZone)
+        theMenu->addAction( action( ZoneSetColorId ) );
 
       if ( anIsStream || anIsChannel || anIsDigue || anIsObstacle )
       {
@@ -738,7 +770,10 @@ void HYDROGUI_Module::contextMenuPopup( const QString& theClient,
         theMenu->addAction( action( SetTransparencyId ) );
         theMenu->addSeparator();
       }
-    } else if ( anAllAreProfiles ) {
+    } 
+    else if ( anAllAreProfiles )
+    {
+      theMenu->addAction( action( EditProfileId ) );
       theMenu->addAction( action( SelectedGeoreferencementId ) );
       theMenu->addSeparator();
     }
@@ -761,10 +796,10 @@ void HYDROGUI_Module::contextMenuPopup( const QString& theClient,
     theMenu->addSeparator();
 
     if( anIsImage || anIsPolyline || anIsPolyline3D || 
-        anIsImmersibleZone || anIsZone || anIsRegion ||
-        anIsBathymetry || anIsObstacle || anIsStream ||
-        anIsChannel || anIsDigue || anIsDummyObject3D ||
-        anIsValidProfile || anIsGroup || anIsLandCoverMap )
+      anIsImmersibleZone || anIsZone || anIsRegion ||
+      anIsBathymetry || anIsObstacle || anIsStream ||
+      anIsChannel || anIsDigue || anIsDummyObject3D ||
+      anIsValidProfile || anIsGroup || anIsLandCoverMap )
     {
       if( anIsHiddenInSelection )
         theMenu->addAction( action( ShowId ) );
@@ -798,7 +833,7 @@ void HYDROGUI_Module::contextMenuPopup( const QString& theClient,
     theMenu->addAction( action( HideAllId ) );
     theMenu->addSeparator();
   }
-  
+
   if ( anIsOCCView || anIsVTKView )
   {
     theMenu->addSeparator();
@@ -875,6 +910,10 @@ void HYDROGUI_Module::createPreferences()
   addPreference( tr( "PREF_VIEWER_AUTO_FITALL" ), viewerGroup,
                  LightApp_Preferences::Bool, "HYDRO", "auto_fit_all" );
 
+  addPreference( tr( "PREF_VIEWER_ZOOM_SHUTOFF" ), viewerGroup, LightApp_Preferences::Bool, "HYDRO", "zoom_shutoff" );
+
+  addPreference( tr( "PREF_VIEWER_CHAINED_PANNING" ), viewerGroup, LightApp_Preferences::Bool, "HYDRO", "chained_panning" );
+
   int StricklerTableGroup = addPreference( tr( "PREF_GROUP_STRICKLER_TABLE" ), genTab );
   int defaultStricklerCoef = addPreference( tr( "PREF_DEFAULT_STRICKLER_COEFFICIENT" ), StricklerTableGroup,
                                             LightApp_Preferences::DblSpin, "preferences", "default_strickler_coefficient" );
@@ -933,8 +972,34 @@ void HYDROGUI_Module::preferencesChanged( const QString& theSection, const QStri
           getOCCDisplayer()->UpdatePolylines( aViewerId, aType, aSize );
       }
     }
+    else if (theSection == "HYDRO" && thePref == "zoom_shutoff")
+    {
+      bool aZoomShutoff = resMgr->booleanValue( "HYDRO", "zoom_shutoff" );
+      setAutoZoomToAllViewManagers(!aZoomShutoff);
+    }
+    else if (theSection == "HYDRO" && thePref == "chained_panning")
+    {
+      bool aChainedPan = resMgr->booleanValue( "HYDRO", "chained_panning" );
+      if (!aChainedPan)
+        resetViewState();
+      ViewManagerList aViewManagers = getApp()->viewManagers();
+      foreach (SUIT_ViewManager* aVMgr, aViewManagers)
+      {
+        OCCViewer_ViewManager* anOCCViewMgr = dynamic_cast<OCCViewer_ViewManager*>( aVMgr );
+        if (anOCCViewMgr)
+          anOCCViewMgr->setChainedOperations( aChainedPan );
+      }
+      
+      QList<QDockWidget*> docW = getApp()->desktop()->findChildren<QDockWidget*>();
+      foreach (QDockWidget* qw, docW)
+      {
+        HYDROGUI_ProfileDlg* pdlg = dynamic_cast<HYDROGUI_ProfileDlg*>(qw);
+        if (pdlg)
+          pdlg->viewManager()->setChainedOperations(aChainedPan);
+      }
+    }
     else
-        LightApp_Module::preferencesChanged( theSection, thePref );
+      LightApp_Module::preferencesChanged( theSection, thePref );
 }
 
 QCursor HYDROGUI_Module::getPrefEditCursor() const
@@ -1009,6 +1074,10 @@ void HYDROGUI_Module::update( const int flags )
 
   setUpdateEnabled( true );
 
+  preferencesChanged( "HYDRO", "zoom_shutoff" );
+
+  preferencesChanged( "HYDRO", "chained_panning" );
+
   QApplication::restoreOverrideCursor();
 }
 
@@ -1570,7 +1639,7 @@ void HYDROGUI_Module::onViewManagerAdded( SUIT_ViewManager* theViewManager )
   else if( theViewManager->getType() == OCCViewer_Viewer::Type() )
   {
     OCCViewer_ViewManager* mgr = dynamic_cast<OCCViewer_ViewManager*>( theViewManager );
-    mgr->setChainedOperations( true );//TODO: via preferences
+    //mgr->setChainedOperations( true );
 
     connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
              this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
@@ -1650,7 +1719,6 @@ 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 );
@@ -1737,6 +1805,7 @@ void HYDROGUI_Module::updateViewer( HYDROGUI_AbstractDisplayer* theDisplayer,
   while( anIdIter.hasNext() )
   {
     theDisplayer->UpdateAll( anIdIter.next(), theIsInit, theIsForced, theDoFitAll );
+    myOverview->setTopView();
   }
 }
 
@@ -1982,3 +2051,38 @@ void HYDROGUI_Module::onViewActivated( SUIT_ViewManager* theMgr )
 
   myOverview->setMainView( occwnd );
 }
+
+void HYDROGUI_Module::setAutoZoomToAllViewManagers(bool bAutoZoom)
+{
+  ViewManagerList aViewManagers = getApp()->viewManagers();
+  foreach (SUIT_ViewManager* aVMgr, aViewManagers)
+    setAutoZoom(aVMgr, bAutoZoom);
+}
+
+void HYDROGUI_Module::setAutoZoom(SUIT_ViewManager* aVMgr, bool bAutoZoom)
+{
+  if (!aVMgr)
+    return;
+  QVector<SUIT_ViewWindow*> aViews = aVMgr->getViews();
+  foreach (SUIT_ViewWindow* aView, aViews)
+  {
+    if (aView)
+    {
+      OCCViewer_ViewFrame* anOCCViewFrame = dynamic_cast<OCCViewer_ViewFrame*>( aView );
+      if (anOCCViewFrame)
+      {
+        anOCCViewFrame->setAutomaticZoom(bAutoZoom);
+        for (int i = OCCViewer_ViewFrame::MAIN_VIEW; i<=OCCViewer_ViewFrame::TOP_RIGHT; i++)
+        {
+          OCCViewer_ViewWindow* aV = anOCCViewFrame->getView(i);
+          if (aV)
+            aV->setAutomaticZoom(bAutoZoom);
+        }
+      }
+      OCCViewer_ViewWindow* anOCCViewWindow = dynamic_cast<OCCViewer_ViewWindow*>( aView );
+      if (anOCCViewWindow)
+        anOCCViewWindow->setAutomaticZoom(bAutoZoom);
+    }
+  }
+}
+