Salome HOME
Disabling message_progress
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_Module.cxx
old mode 100644 (file)
new mode 100755 (executable)
index 046a19a..f93e0ce
@@ -16,6 +16,8 @@
 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
 
+#include <Python.h>
+
 #include "HYDROGUI_Module.h"
 
 #include "HYDROGUI.h"
@@ -28,6 +30,7 @@
 #include "HYDROGUI_OCCDisplayer.h"
 #include "HYDROGUI_OCCSelector.h"
 #include "HYDROGUI_Operations.h"
+#include "HYDROGUI_Operation.h"
 #include "HYDROGUI_PrsImage.h"
 #include "HYDROGUI_Tool.h"
 #include "HYDROGUI_Tool2.h"
@@ -41,7 +44,9 @@
 #include "HYDROGUI_ImportGeomObjectOp.h"
 #include "HYDROGUI_ShowHideOp.h"
 #include "HYDROGUI_Overview.h"
-
+#include <HYDROGUI_ProfileDlg.h>
+#include <HYDROGUI_SIProgressIndicator.h>
+#include <HYDROGUI_ZIProgressIndicator.h>
 #include <HYDROData_Tool.h>
 #include <HYDROData_Image.h>
 #include <HYDROData_Stream.h>
 #include <QStatusBar>
 #include <QCursor>
 
-static int ViewManagerId = 0;
+//#define _DEVDEBUG_
+#include "HYDRO_trace.hxx"
+
+static size_t ViewManagerId = 1;
 
 extern "C" HYDRO_EXPORT CAM_Module* createModule()
 {
@@ -126,20 +134,24 @@ HYDROGUI_Module::HYDROGUI_Module()
   myIsUpdateEnabled( true ),
   myOverview( 0 )
 {
+  DEBTRACE("HYDROGUI_Module::HYDROGUI_Module()");
 }
 
 HYDROGUI_Module::~HYDROGUI_Module()
 {
+  DEBTRACE("HYDROGUI_Module::~HYDROGUI_Module()");
 }
 
 int HYDROGUI_Module::getStudyId() const
 {
+  DEBTRACE("HYDROGUI_Module::getStudyId()");
   LightApp_Application* anApp = getApp();
   return anApp ? anApp->activeStudy()->id() : 0;
 }
 
 void HYDROGUI_Module::initialize( CAM_Application* theApp )
 {
+  DEBTRACE("HYDROGUI_Module::initialize");
   LightApp_Module::initialize( theApp );
 
   createActions();
@@ -154,10 +166,14 @@ void HYDROGUI_Module::initialize( CAM_Application* theApp )
   myDisplayer = new HYDROGUI_Displayer( this );
   myOCCDisplayer = new HYDROGUI_OCCDisplayer( this );
   myVTKDisplayer = new HYDROGUI_VTKPrsDisplayer( this );
+
+  //HYDROData_Tool::SetSIProgress( new HYDROGUI_SIProgressIndicator( theApp->desktop() ) );
+  //HYDROData_Tool::SetZIProgress( new HYDROGUI_ZIProgressIndicator( theApp->desktop() ) );
 }
 
 bool HYDROGUI_Module::activateModule( SUIT_Study* theStudy )
 {
+  DEBTRACE("HYDROGUI_Module::activateModule");
   bool aRes = LightApp_Module::activateModule( theStudy );
 
   LightApp_Application* anApp = getApp();
@@ -168,28 +184,46 @@ bool HYDROGUI_Module::activateModule( SUIT_Study* theStudy )
   setMenuShown( true );
   setToolShown( true );
 
+  // import Python module that manages HYDRO plugins (need to be here because SalomePyQt API uses active module)
+  PyGILState_STATE gstate = PyGILState_Ensure();
+  PyObject* pluginsmanager = PyImport_ImportModuleNoBlock((char*)"salome_pluginsmanager");
+  if ( !pluginsmanager ) {
+    PyErr_Print();
+  }
+  else {
+    PyObject* result =
+      PyObject_CallMethod(pluginsmanager, (char*)"initialize", (char*)"isss", 1, "hydro",
+                          tr("MEN_DESK_HYDRO").toUtf8().data(),
+                          tr("Python plugins").toUtf8().data());
+    if ( !result )
+      PyErr_Print();
+    Py_XDECREF(result);
+  }
+  PyGILState_Release(gstate);
+  // end of GEOM plugins loading
+
 #ifndef DISABLE_PYCONSOLE
-  aDesktop->tabifyDockWidget( HYDROGUI_Tool::WindowDock( anApp->getWindow( LightApp_Application::WT_PyConsole ) ), 
+  aDesktop->tabifyDockWidget( HYDROGUI_Tool::WindowDock( anApp->getWindow( LightApp_Application::WT_PyConsole ) ),
                               HYDROGUI_Tool::WindowDock( anApp->getWindow( LightApp_Application::WT_LogWindow ) ) );
 #endif
 
   // Remove defunct view managers from the map.
   // It's essential to do this before "update( UF_All )" call!
-  QList<int> anObsoleteIds;
+  QList<size_t> anObsoleteIds;
   ViewManagerList anAllViewManagers = anApp->viewManagers();
   ViewManagerList aHydroViewManagers; // view managers created inside the HYDRO module
   ViewManagerMapIterator anIter( myViewManagerMap );
   while( anIter.hasNext() ) {
-    int anId = anIter.next().key();
+    size_t anId = anIter.next().key();
     const ViewManagerInfo& anInfo = anIter.value();
-  
+
     aHydroViewManagers << anInfo.first;
 
     if ( !anAllViewManagers.contains( anInfo.first ) ) {
       anObsoleteIds << anId;
     }
   }
-  foreach ( const int anId, anObsoleteIds ) {
+  foreach ( const size_t anId, anObsoleteIds ) {
     myViewManagerMap.remove( anId );
     myObjectStateMap.remove( anId );
     myShapesMap.remove( anId );
@@ -214,13 +248,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* ) ), 
+    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,11 +271,15 @@ bool HYDROGUI_Module::activateModule( SUIT_Study* theStudy )
     }
   }
 
+  preferencesChanged( "HYDRO", "zoom_shutoff" );
+
+  preferencesChanged( "HYDRO", "chained_panning" );
+
   // Load GEOM data
-  SalomeApp_Study* aStudy = 
+  SalomeApp_Study* aStudy =
     dynamic_cast<SalomeApp_Study*>( getApp()->activeStudy() );
   if ( aStudy ) {
-    SALOMEDS::Study_var aDSStudy = GeometryGUI::ClientStudyToStudy( aStudy->studyDS() );
+    SALOMEDS::Study_var aDSStudy = GeometryGUI::getStudyServant();
     GEOM::GEOM_Gen_var aGeomEngine = GeometryGUI::GetGeomGen();
     if ( !aGeomEngine->_is_nil() && !aGeomEngine->_is_nil() ) {
       SALOMEDS::StudyBuilder_var aStudyBuilder = aDSStudy->NewBuilder();
@@ -246,6 +290,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 );
@@ -255,6 +300,7 @@ bool HYDROGUI_Module::activateModule( SUIT_Study* theStudy )
 
 bool HYDROGUI_Module::deactivateModule( SUIT_Study* theStudy )
 {
+  DEBTRACE("HYDROGUI_Module::deactivateModule");
   /* Issues ## 68, 88.
   ViewManagerMapIterator anIter( myViewManagerMap );
   while( anIter.hasNext() )
@@ -265,9 +311,19 @@ 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* ) ) );
+    disconnect( 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( false );
+      setAutoZoom( occ_mgr, true );
+    }
   }
 
   /* Issues ## 68, 88.
@@ -293,11 +349,25 @@ bool HYDROGUI_Module::deactivateModule( SUIT_Study* theStudy )
   HYDROGUI_Tool::setOCCActionShown( this, OCCViewer_ViewWindow::MaximizedId, true );
 
   myActiveOperationMap.clear();
-  return LightApp_Module::deactivateModule( theStudy );
+
+  myViewManagerMap.clear();
+
+  bool ret = LightApp_Module::deactivateModule( theStudy );
+  return ret;
+}
+
+void HYDROGUI_Module::studyClosed(SUIT_Study* theStudy)
+{
+    DEBTRACE("HYDROGUI_Module::studyClosed");
+    HYDROGUI_Operation::myIsClear = false; // force clear of Zlayers on next study
+    Handle(HYDROData_Document) aDoc = HYDROData_Document::Document();
+    if (!aDoc.IsNull())
+      aDoc->Close();
 }
 
 void HYDROGUI_Module::windows( QMap<int, int>& theMap ) const
 {
+  DEBTRACE("HYDROGUI_Module::windows");
   static bool inWindows = false;
   if( inWindows )
     return;
@@ -314,7 +384,7 @@ void HYDROGUI_Module::windows( QMap<int, int>& theMap ) const
   LightApp_Application* app = getApp();
   if( app && app->getWindow( OverviewWindow )==0 )
   {
-    const_cast<HYDROGUI_Module*>( this )->myOverview = 
+    const_cast<HYDROGUI_Module*>( this )->myOverview =
       new HYDROGUI_Overview( tr( "OVERVIEW" ), 0, app->desktop() );
     app->insertDockWindow( OverviewWindow, myOverview );
     app->placeDockWindow( OverviewWindow, Qt::LeftDockWidgetArea );
@@ -324,6 +394,7 @@ void HYDROGUI_Module::windows( QMap<int, int>& theMap ) const
 
 void HYDROGUI_Module::viewManagers( QStringList& theTypesList ) const
 {
+  DEBTRACE("HYDROGUI_Module::viewManagers");
   theTypesList << GraphicsView_Viewer::Type() << OCCViewer_Viewer::Type();
 }
 
@@ -375,6 +446,7 @@ void HYDROGUI_Module::contextMenuPopup( const QString& theClient,
   bool anIsObjectCanBeColored = false;
   bool isRoot = false;
   bool isStreamHasBottom = false;
+  bool anIsBCPolygon = false;
 
   SUIT_SelectionMgr* aSelectionMgr = getApp()->selectionMgr();
   SUIT_DataOwnerPtrList anOwners;
@@ -389,14 +461,14 @@ void HYDROGUI_Module::contextMenuPopup( const QString& theClient,
 
   // Check the selected GEOM objects (take into account the Object Browser only)
   if ( anIsObjectBrowser ) {
-    QList<GEOM::shape_type> anObstacleTypes = 
+    QList<GEOM::shape_type> anObstacleTypes =
       HYDROGUI_ImportGeomObjectOp::getObstacleTypes();
-    QList<GEOM::shape_type> aPolylineTypes = 
+    QList<GEOM::shape_type> aPolylineTypes =
       HYDROGUI_ImportGeomObjectOp::getPolylineTypes();
 
-    bool isCanBeImportedAsObstacle = 
+    bool isCanBeImportedAsObstacle =
       !HYDROGUI_Tool::GetSelectedGeomObjects( this, anObstacleTypes ).isEmpty();
-    bool isCanBeImportedAsPolyline = 
+    bool isCanBeImportedAsPolyline =
       !HYDROGUI_Tool::GetSelectedGeomObjects( this, aPolylineTypes ).isEmpty();
 
     // Add import as obstacle action
@@ -465,7 +537,7 @@ void HYDROGUI_Module::contextMenuPopup( const QString& theClient,
         anIsProfile = true;
         aNbOfSelectedProfiles++;
 
-        Handle(HYDROData_Profile) aProfile = 
+        Handle(HYDROData_Profile) aProfile =
           Handle(HYDROData_Profile)::DownCast( anObject );
         if( !aProfile.IsNull() && aProfile->IsValid() ) {
           anIsValidProfile = true;
@@ -489,13 +561,15 @@ void HYDROGUI_Module::contextMenuPopup( const QString& theClient,
         anIsStricklerTable = true;
       else if( anObjectKind == KIND_LAND_COVER_MAP )
         anIsLandCoverMap = true;
+      else if (anObjectKind == KIND_BC_POLYGON)
+        anIsBCPolygon = true;
       else if( anObjectKind == KIND_STREAM )
       {
         anIsStream = true;
-        Handle(HYDROData_Stream) aStream = 
+        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 +587,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,50 +597,54 @@ 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 ) );
+        theMenu->addAction( action( ImportPolylineId ) );
+        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_BC_POLYGON:
+        theMenu->addAction( action( ImportBCPolygonId ) );
+        break;
       }
       theMenu->addSeparator();
     }
@@ -640,6 +718,8 @@ void HYDROGUI_Module::contextMenuPopup( const QString& theClient,
         theMenu->addAction( action( SplitPolylinesId ) );
         theMenu->addAction( action( MergePolylinesId ) );
         theMenu->addSeparator();
+        theMenu->addAction( action( ShowAttrPolylinesId ) );
+        theMenu->addSeparator();
       }
       else if( anIsPolyline3D )
       {
@@ -656,6 +736,7 @@ void HYDROGUI_Module::contextMenuPopup( const QString& theClient,
       {
         theMenu->addAction( action( EditCalculationId ) );
         theMenu->addAction( action( ExportCalculationId ) );
+        theMenu->addAction( action( CompleteCalculationId ) );
         theMenu->addSeparator();
       }
       else if( anIsImmersibleZone )
@@ -668,8 +749,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();
@@ -696,9 +777,9 @@ void HYDROGUI_Module::contextMenuPopup( const QString& theClient,
         theMenu->addAction( action( DuplicateStricklerTableId ) );
         theMenu->addSeparator();
 
-        Handle(HYDROData_StricklerTable) aTable = 
+        Handle(HYDROData_StricklerTable) aTable =
           Handle(HYDROData_StricklerTable)::DownCast( aSeq.First() );
-        QString aCurrentTable = 
+        QString aCurrentTable =
           HYDROGUI_DataObject::dataObjectEntry( getLandCoverColoringTable( anActiveViewId ) );
         bool isUsed = aCurrentTable == HYDROGUI_DataObject::dataObjectEntry( aTable );
 
@@ -719,13 +800,17 @@ void HYDROGUI_Module::contextMenuPopup( const QString& theClient,
         //
         theMenu->addAction( action( ExportToShapeFileID ) );
         theMenu->addSeparator();
-      }      
+      }
       else if( anIsVisualState && anIsObjectBrowser )
       {
         theMenu->addAction( action( SaveVisualStateId ) );
         theMenu->addAction( action( LoadVisualStateId ) );
         theMenu->addSeparator();
       }
+      else if (anIsZone)
+        theMenu->addAction( action( ZoneSetColorId ) );
+      else if (anIsBCPolygon)
+        theMenu->addAction( action( SetBoundaryTypePolygonId ) );
 
       if ( anIsStream || anIsChannel || anIsDigue || anIsObstacle )
       {
@@ -746,7 +831,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();
     }
@@ -768,11 +856,12 @@ 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 )
+    if( anIsImage || anIsPolyline || anIsPolyline3D ||
+      anIsImmersibleZone || anIsZone || anIsRegion ||
+      anIsBathymetry || anIsObstacle || anIsStream ||
+      anIsChannel || anIsDigue || anIsDummyObject3D ||
+      anIsValidProfile || anIsGroup || anIsLandCoverMap ||
+      anIsBCPolygon)
     {
       if( anIsHiddenInSelection )
         theMenu->addAction( action( ShowId ) );
@@ -806,7 +895,7 @@ void HYDROGUI_Module::contextMenuPopup( const QString& theClient,
     theMenu->addAction( action( HideAllId ) );
     theMenu->addSeparator();
   }
-  
+
   if ( anIsOCCView || anIsVTKView )
   {
     theMenu->addSeparator();
@@ -858,6 +947,7 @@ void HYDROGUI_Module::contextMenuPopup( const QString& theClient,
 
 void HYDROGUI_Module::createPreferences()
 {
+  DEBTRACE("HYDROGUI_Module::createPreferences");
   int genTab = addPreference( tr( "PREF_TAB_GENERAL" ) );
   int CursorGroup = addPreference( tr( "PREF_GROUP_CURSOR" ), genTab );
 
@@ -883,7 +973,9 @@ void HYDROGUI_Module::createPreferences()
   addPreference( tr( "PREF_VIEWER_AUTO_FITALL" ), viewerGroup,
                  LightApp_Preferences::Bool, "HYDRO", "auto_fit_all" );
 
-  addPreference( tr( "PREF_VIEWER_AUTOMATIC_ZOOM" ), viewerGroup, LightApp_Preferences::Bool, "HYDRO", "automatic_zoom" );
+  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,
@@ -916,11 +1008,12 @@ void HYDROGUI_Module::createPreferences()
 
 void HYDROGUI_Module::preferencesChanged( const QString& theSection, const QString& thePref )
 {
+    DEBTRACE("HYDROGUI_Module::preferencesChanged");
     SUIT_ResourceMgr* resMgr = application()->resourceMgr();
     if ( theSection == "preferences" && thePref == "default_strickler_coefficient" )
     {
-        
-        Handle(HYDROData_Document) aDoc = HYDROData_Document::Document( application()->activeStudy()->id() );
+
+        Handle(HYDROData_Document) aDoc = HYDROData_Document::Document();
         if ( resMgr && !aDoc.IsNull() )
             aDoc->SetDefaultStricklerCoefficient( resMgr->doubleValue( theSection, thePref, 0 ) );
     }
@@ -937,46 +1030,40 @@ void HYDROGUI_Module::preferencesChanged( const QString& theSection, const QStri
       ViewManagerMap::const_iterator it = myViewManagerMap.begin(), last = myViewManagerMap.end();
       for( ; it!=last; it++ )
       {
-        int aViewerId = it.key();
+        size_t aViewerId = it.key();
         OCCViewer_ViewManager* aMgr = dynamic_cast<OCCViewer_ViewManager*>( it.value().first );
         if( aMgr )
           getOCCDisplayer()->UpdatePolylines( aViewerId, aType, aSize );
       }
     }
-    else if (theSection == "HYDRO" && thePref == "automatic_zoom")
+    else if (theSection == "HYDRO" && thePref == "zoom_shutoff")
     {
-      bool anAutoZoom = resMgr->booleanValue( "HYDRO", "automatic_zoom" );
+      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)
       {
-        if (aVMgr)
-        {
-          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(anAutoZoom);
-                for (int i = OCCViewer_ViewFrame::MAIN_VIEW; i<=OCCViewer_ViewFrame::TOP_RIGHT; i++)
-                {
-                  OCCViewer_ViewWindow* aV = anOCCViewFrame->getView(i);
-                  if (aV)
-                    aV->setAutomaticZoom(anAutoZoom);
-                }
-              }
-              OCCViewer_ViewWindow* anOCCViewWindow = dynamic_cast<OCCViewer_ViewWindow*>( aView );
-              if (anOCCViewWindow)
-                anOCCViewWindow->setAutomaticZoom(true);
-            }
-          }
-        }
+        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
@@ -990,6 +1077,7 @@ QCursor HYDROGUI_Module::getPrefEditCursor() const
 
 void HYDROGUI_Module::update( const int flags )
 {
+  DEBTRACE("HYDROGUI_Module::update");
   if ( !isUpdateEnabled() )
     return;
 
@@ -1010,13 +1098,13 @@ void HYDROGUI_Module::update( const int flags )
   }
 
   if( ( flags & UF_Viewer ) )
-    updateViewer( getDisplayer(), flags & UF_GV_Init, flags & UF_GV_Forced, aDoFitAll ); 
+    updateViewer( getDisplayer(), flags & UF_GV_Init, flags & UF_GV_Forced, aDoFitAll );
 
   if( ( flags & UF_OCCViewer ) )
-    updateViewer( getOCCDisplayer(), flags & UF_OCC_Init, flags & UF_OCC_Forced, aDoFitAll ); 
+    updateViewer( getOCCDisplayer(), flags & UF_OCC_Init, flags & UF_OCC_Forced, aDoFitAll );
 
   if( ( flags & UF_VTKViewer ) )
-    updateViewer( getVTKDisplayer(), flags & UF_VTK_Init, flags & UF_VTK_Forced, aDoFitAll ); 
+    updateViewer( getVTKDisplayer(), flags & UF_VTK_Init, flags & UF_VTK_Forced, aDoFitAll );
 
   if( ( flags & UF_Model ) && getDataModel() && getApp() )
   {
@@ -1031,11 +1119,11 @@ void HYDROGUI_Module::update( const int flags )
     bool isResizeOnExpandItem = aResMgr->booleanValue( "ObjectBrowser", "resize_on_expand_item", false );
     SUIT_DataBrowser* anObjectBrowser = getApp()->objectBrowser();
     if ( isResizeOnExpandItem && anObjectBrowser ) {
-      anObjectBrowser->setResizeOnExpandItem( false ); // MZN: ISSUE #280 
+      anObjectBrowser->setResizeOnExpandItem( false ); // MZN: ISSUE #280
     }
     getApp()->updateObjectBrowser( true );
     if ( isResizeOnExpandItem && anObjectBrowser ) {
-      anObjectBrowser->setResizeOnExpandItem( true ); // MZN: ISSUE #280 
+      anObjectBrowser->setResizeOnExpandItem( true ); // MZN: ISSUE #280
     }
   }
 
@@ -1051,11 +1139,16 @@ void HYDROGUI_Module::update( const int flags )
 
   setUpdateEnabled( true );
 
+  preferencesChanged( "HYDRO", "zoom_shutoff" );
+
+  preferencesChanged( "HYDRO", "chained_panning" );
+
   QApplication::restoreOverrideCursor();
 }
 
 void HYDROGUI_Module::updateCommandsStatus()
 {
+  DEBTRACE("HYDROGUI_Module::updateCommandsStatus");
   LightApp_Module::updateCommandsStatus();
 
   updateUndoRedoControls();
@@ -1066,32 +1159,38 @@ void HYDROGUI_Module::updateCommandsStatus()
 
 void HYDROGUI_Module::selectionChanged()
 {
+  DEBTRACE("HYDROGUI_Module::selectionChanged");
   LightApp_Module::selectionChanged();
   updateCommandsStatus();
 }
 
 HYDROGUI_DataModel* HYDROGUI_Module::getDataModel() const
 {
+  //DEBTRACE("HYDROGUI_Module::getDataModel()");
   return (HYDROGUI_DataModel*)dataModel();
 }
 
 HYDROGUI_Displayer* HYDROGUI_Module::getDisplayer() const
 {
+  //DEBTRACE("HYDROGUI_Module::getDisplayer()");
   return myDisplayer;
 }
 
 HYDROGUI_OCCDisplayer* HYDROGUI_Module::getOCCDisplayer() const
 {
+  DEBTRACE("HYDROGUI_Module::getOCCDisplayer");
   return myOCCDisplayer;
 }
 
 HYDROGUI_VTKPrsDisplayer* HYDROGUI_Module::getVTKDisplayer() const
 {
+  DEBTRACE("HYDROGUI_Module::getVTKDisplayer");
   return myVTKDisplayer;
 }
 
-SUIT_ViewManager* HYDROGUI_Module::getViewManager( const int theId ) const
+SUIT_ViewManager* HYDROGUI_Module::getViewManager( const size_t theId ) const
 {
+  DEBTRACE("HYDROGUI_Module::getViewManager " << theId);
   if( myViewManagerMap.contains( theId ) )
   {
     return myViewManagerMap[ theId ].first;
@@ -1099,8 +1198,9 @@ SUIT_ViewManager* HYDROGUI_Module::getViewManager( const int theId ) const
   return NULL;
 }
 
-GraphicsView_Viewer* HYDROGUI_Module::getViewer( const int theId ) const
+GraphicsView_Viewer* HYDROGUI_Module::getViewer( const size_t theId ) const
 {
+  DEBTRACE("HYDROGUI_Module::getViewer " << theId);
   if( myViewManagerMap.contains( theId ) )
   {
     ViewManagerInfo anInfo = myViewManagerMap[ theId ];
@@ -1112,8 +1212,9 @@ GraphicsView_Viewer* HYDROGUI_Module::getViewer( const int theId ) const
   return NULL;
 }
 
-OCCViewer_Viewer* HYDROGUI_Module::getOCCViewer( const int theId ) const
+OCCViewer_Viewer* HYDROGUI_Module::getOCCViewer( const size_t theId ) const
 {
+  DEBTRACE("HYDROGUI_Module::getOCCViewer " << theId);
   if( myViewManagerMap.contains( theId ) )
   {
     ViewManagerInfo anInfo = myViewManagerMap[ theId ];
@@ -1125,8 +1226,9 @@ OCCViewer_Viewer* HYDROGUI_Module::getOCCViewer( const int theId ) const
   return NULL;
 }
 
-SVTK_Viewer* HYDROGUI_Module::getVTKViewer( const int theId ) const
+SVTK_Viewer* HYDROGUI_Module::getVTKViewer( const size_t theId ) const
 {
+  DEBTRACE("HYDROGUI_Module::getVTKViewer "  << theId);
   if( myViewManagerMap.contains( theId ) )
   {
     ViewManagerInfo anInfo = myViewManagerMap[ theId ];
@@ -1138,23 +1240,25 @@ SVTK_Viewer* HYDROGUI_Module::getVTKViewer( const int theId ) const
   return NULL;
 }
 
-int HYDROGUI_Module::getViewManagerId( SUIT_ViewManager* theViewManager )
+size_t HYDROGUI_Module::getViewManagerId( SUIT_ViewManager* theViewManager )
 {
+  DEBTRACE("HYDROGUI_Module::getViewManagerId");
   ViewManagerMapIterator anIter( myViewManagerMap );
   while( anIter.hasNext() )
   {
-    int anId = anIter.next().key();
+    size_t anId = anIter.next().key();
     const ViewManagerInfo& anInfo = anIter.value();
     if( anInfo.first == theViewManager )
       return anId;
   }
-  return -1;
+  return 0;
 }
 
 HYDROGUI_Module::ViewManagerRole HYDROGUI_Module::getViewManagerRole( SUIT_ViewManager* theViewManager )
 {
-  int anId = getViewManagerId( theViewManager );
-  if( anId != -1 )
+  DEBTRACE("HYDROGUI_Module::getViewManagerRole");
+  size_t anId = getViewManagerId( theViewManager );
+  if( anId == 0 )
   {
     const ViewManagerInfo& anInfo = myViewManagerMap[ anId ];
     return anInfo.second;
@@ -1165,24 +1269,25 @@ HYDROGUI_Module::ViewManagerRole HYDROGUI_Module::getViewManagerRole( SUIT_ViewM
 void HYDROGUI_Module::setViewManagerRole( SUIT_ViewManager* theViewManager,
                                           const ViewManagerRole theRole )
 {
-  int anId = getViewManagerId( theViewManager );
-  if( anId != -1 )
+  DEBTRACE("HYDROGUI_Module::setViewManagerRole");
+  size_t anId = getViewManagerId( theViewManager );
+  if( anId != 0 )
   {
     ViewManagerInfo& anInfo = myViewManagerMap[ anId ];
     anInfo.second = theRole;
   }
 }
 
-bool HYDROGUI_Module::isObjectVisible( const int theViewId,
+bool HYDROGUI_Module::isObjectVisible( const size_t theViewId,
                                        const Handle(HYDROData_Entity)& theObject ) const
 {
   if( theObject.IsNull() )
     return false;
 
-  if( theViewId < 0 )
+  if( theViewId == 0 )
   {
     //search in all
-    foreach( int aViewId, myObjectStateMap.keys() )
+    foreach( size_t aViewId, myObjectStateMap.keys() )
     {
       if( isObjectVisible( aViewId, theObject ) )
         return true;
@@ -1206,26 +1311,40 @@ bool HYDROGUI_Module::isObjectVisible( const int theViewId,
   return false;
 }
 
-void HYDROGUI_Module::setObjectVisible( const int theViewId,
+void HYDROGUI_Module::setObjectVisible( const size_t theViewId,
                                         const Handle(HYDROData_Entity)& theObject,
                                         const bool theState )
 {
+  DEBTRACE("setObjectVisible, theViewId: " << theViewId << " " << theState);
   if( !theObject.IsNull() )
   {
-    Entry2ObjectStateMap& aEntry2ObjectStateMap = myObjectStateMap[ theViewId ];
-    QString anEntry = HYDROGUI_DataObject::dataObjectEntry( theObject );
+       DEBTRACE("myObjectStateMap.size: " << myObjectStateMap.size());
+       QString anEntry = HYDROGUI_DataObject::dataObjectEntry( theObject );
+       DEBTRACE("anEntry: " << anEntry.toStdString());
+       if (myObjectStateMap.find(theViewId) == myObjectStateMap.end())
+       {
+               DEBTRACE("theViewId is not a valid key for myObjectStateMap");
+       }
+    if (theViewId)
+    {
+        Entry2ObjectStateMap& aEntry2ObjectStateMap = myObjectStateMap[ theViewId ]; // created OK if it does not exist
+        DEBTRACE("myObjectStateMap key created");
 
-    ObjectState& anObjectState = aEntry2ObjectStateMap[ anEntry ];
-    anObjectState.Visibility = theState;
+        ObjectState& anObjectState = aEntry2ObjectStateMap[ anEntry ];
+        anObjectState.Visibility = theState;
+    }
 
     HYDROGUI_DataObject* hydroObject = getDataModel()->getDataObject( theObject );
     if ( hydroObject )
     {
+        DEBTRACE("hydroObject " << hydroObject);
         SUIT_AbstractModel* treeModel = dynamic_cast<SUIT_AbstractModel*>( getApp()->objectBrowser()->model() );
         if ( treeModel )
         {
+          DEBTRACE("treeModel " << treeModel);
           QString id = hydroObject->text( hydroObject->customData( Qtx::IdType ).toInt() );
           Qtx::VisibilityState visState = treeModel->visibilityState( id );
+          DEBTRACE("id " << id << " visState "<< visState);
           if ( visState != Qtx::UnpresentableState )
             treeModel->setVisibilityState( id, theState ? Qtx::ShownState : Qtx::HiddenState );
         }
@@ -1242,6 +1361,7 @@ void HYDROGUI_Module::setObjectVisible( const int theViewId,
 void HYDROGUI_Module::setIsToUpdate( const Handle(HYDROData_Entity)& theObject,
                                      const bool theState )
 {
+  DEBTRACE("HYDROGUI_Module::setIsToUpdate");
   if( !theObject.IsNull() )
   {
     // Process OCC shapes
@@ -1276,7 +1396,7 @@ void HYDROGUI_Module::setIsToUpdate( const Handle(HYDROData_Entity)& theObject,
 }
 
 /////////////////// OCC SHAPES PROCESSING
-QList<HYDROGUI_Shape*> HYDROGUI_Module::getObjectShapes( const int  theViewId,
+QList<HYDROGUI_Shape*> HYDROGUI_Module::getObjectShapes( const size_t  theViewId,
                                                          ObjectKind theKind ) const
 {
   QList<HYDROGUI_Shape*> aResult;
@@ -1293,7 +1413,7 @@ QList<HYDROGUI_Shape*> HYDROGUI_Module::getObjectShapes( const int  theViewId,
   return aResult;
 }
 
-HYDROGUI_Shape* HYDROGUI_Module::getObjectShape( const int                       theViewId,
+HYDROGUI_Shape* HYDROGUI_Module::getObjectShape( const size_t                    theViewId,
                                                  const Handle(HYDROData_Entity)& theObject ) const
 {
   HYDROGUI_Shape* aResShape = NULL;
@@ -1316,7 +1436,7 @@ HYDROGUI_Shape* HYDROGUI_Module::getObjectShape( const int
   return aResShape;
 }
 
-void HYDROGUI_Module::setObjectShape( const int                       theViewId,
+void HYDROGUI_Module::setObjectShape( const size_t                    theViewId,
                                       const Handle(HYDROData_Entity)& theObject,
                                       HYDROGUI_Shape*                 theShape )
 {
@@ -1327,7 +1447,7 @@ void HYDROGUI_Module::setObjectShape( const int                       theViewId,
   aViewShapes.append( theShape );
 }
 
-void HYDROGUI_Module::removeObjectShape( const int                       theViewId,
+void HYDROGUI_Module::removeObjectShape( const size_t                    theViewId,
                                          const Handle(HYDROData_Entity)& theObject )
 {
   if ( !myShapesMap.contains( theViewId ) )
@@ -1341,6 +1461,7 @@ void HYDROGUI_Module::removeObjectShape( const int                       theView
     anObject = aShape->getObject();
     if ( aShape && (!anObject.IsNull()) && IsEqual( anObject, theObject ) )
     {
+      DEBTRACE("delete shape :" << aShape->getObject()->GetName().toStdString());
       delete aShape;
       aViewShapes.removeAt( i );
       continue;
@@ -1350,7 +1471,7 @@ void HYDROGUI_Module::removeObjectShape( const int                       theView
   }
 }
 
-void HYDROGUI_Module::removeViewShapes( const int theViewId )
+void HYDROGUI_Module::removeViewShapes( const size_t theViewId )
 {
   if ( !myShapesMap.contains( theViewId ) )
     return;
@@ -1368,7 +1489,7 @@ void HYDROGUI_Module::removeViewShapes( const int theViewId )
 /////////////////// END OF OCC SHAPES PROCESSING
 
 /////////////////// VTKPrs PROCESSING
-HYDROGUI_VTKPrs* HYDROGUI_Module::getObjectVTKPrs( const int                       theViewId,
+HYDROGUI_VTKPrs* HYDROGUI_Module::getObjectVTKPrs( const size_t                  theViewId,
                                                  const Handle(HYDROData_Entity)& theObject ) const
 {
   HYDROGUI_VTKPrs* aResShape = NULL;
@@ -1391,7 +1512,7 @@ HYDROGUI_VTKPrs* HYDROGUI_Module::getObjectVTKPrs( const int
   return aResShape;
 }
 
-void HYDROGUI_Module::setObjectVTKPrs( const int                       theViewId,
+void HYDROGUI_Module::setObjectVTKPrs( const size_t                    theViewId,
                                        const Handle(HYDROData_Entity)& theObject,
                                        HYDROGUI_VTKPrs*                 theShape )
 {
@@ -1425,7 +1546,7 @@ void HYDROGUI_Module::setObjectVTKPrs( const int                       theViewId
   aViewShapes.append( theShape );
 }
 
-void HYDROGUI_Module::removeObjectVTKPrs( const int      theViewId,
+void HYDROGUI_Module::removeObjectVTKPrs( const size_t   theViewId,
                                           const QString& theEntry )
 {
   if ( !myVTKPrsMap.contains( theViewId ) )
@@ -1454,7 +1575,7 @@ void HYDROGUI_Module::removeObjectVTKPrs( const int      theViewId,
   getVTKDisplayer()->SetZRange( theViewId, anInvalidRange );
 }
 
-void HYDROGUI_Module::removeObjectVTKPrs( const int                       theViewId,
+void HYDROGUI_Module::removeObjectVTKPrs( const size_t                    theViewId,
                                           const Handle(HYDROData_Entity)& theObject )
 {
   if ( !myVTKPrsMap.contains( theViewId ) )
@@ -1481,7 +1602,7 @@ void HYDROGUI_Module::removeObjectVTKPrs( const int                       theVie
   getVTKDisplayer()->SetZRange( theViewId, anInvalidRange );
 }
 
-void HYDROGUI_Module::removeViewVTKPrs( const int theViewId )
+void HYDROGUI_Module::removeViewVTKPrs( const size_t theViewId )
 {
   if ( !myVTKPrsMap.contains( theViewId ) )
     return;
@@ -1497,7 +1618,7 @@ void HYDROGUI_Module::removeViewVTKPrs( const int theViewId )
   myVTKPrsMap.remove( theViewId );
 }
 
-void HYDROGUI_Module::updateVTKZRange( const int theViewId, double theRange[] )
+void HYDROGUI_Module::updateVTKZRange( const size_t theViewId, double theRange[] )
 {
   if ( myVTKPrsMap.contains( theViewId ) )
   {
@@ -1520,11 +1641,13 @@ void HYDROGUI_Module::updateVTKZRange( const int theViewId, double theRange[] )
 
 void HYDROGUI_Module::clearCache()
 {
+    DEBTRACE("HYDROGUI_Module::clearCache");
     myObjectStateMap.clear();
 }
 
 CAM_DataModel* HYDROGUI_Module::createDataModel()
 {
+  DEBTRACE("HYDROGUI_Module::createDataModel");
   return new HYDROGUI_DataModel( this );
 }
 
@@ -1602,23 +1725,24 @@ bool HYDROGUI_Module::eventFilter( QObject* theObj, QEvent* theEvent )
 
 void HYDROGUI_Module::onViewManagerAdded( SUIT_ViewManager* theViewManager )
 {
+  DEBTRACE("HYDROGUI_Module::onViewManagerAdded");
   LightApp_Module::onViewManagerAdded( theViewManager );
 
   if( theViewManager->getType() == GraphicsView_Viewer::Type() )
-  { 
+  {
     connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
              this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
   }
   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* ) ) );
     connect( theViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ),
              this, SLOT( onMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
-    connect( theViewManager, SIGNAL( activated( SUIT_ViewManager* ) ), 
+    connect( theViewManager, SIGNAL( activated( SUIT_ViewManager* ) ),
              this, SLOT( onViewActivated( SUIT_ViewManager* ) ) );
   }
   else if( theViewManager->getType() == SVTK_Viewer::Type() )
@@ -1635,22 +1759,23 @@ void HYDROGUI_Module::onViewManagerAdded( SUIT_ViewManager* theViewManager )
   myViewManagerMap.insert( ViewManagerId++, anInfo );
 }
 
-void HYDROGUI_Module::onViewManagerRemoved( SUIT_ViewManager* theViewManager )
+void HYDROGUI_Module::removeViewManager( SUIT_ViewManager* theViewManager)
 {
-  LightApp_Module::onViewManagerRemoved( theViewManager );
+  DEBTRACE("removeViewManager")
 
-  createSelector( theViewManager ); // replace the default selector
-
-  int anId = getViewManagerId( theViewManager );
-  if( anId != -1 )
+  size_t anId = getViewManagerId( theViewManager );
+  if( anId != 0 )
   {
+    bool isDisableGVSelector = theViewManager->getType() == GraphicsView_Viewer::Type();
+    createSelector( theViewManager, isDisableGVSelector ); // replace the default selector
+
     OCCViewer_ViewManager* anOCCViewManager =
       ::qobject_cast<OCCViewer_ViewManager*>( myViewManagerMap[ anId ].first );
     if ( anOCCViewManager )
     {
       OCCViewer_Viewer* anOCCViewer = anOCCViewManager->getOCCViewer();
       if ( anOCCViewer ) {
-        int aViewerId = (size_t)anOCCViewer;
+        size_t aViewerId = (size_t)anOCCViewer;
         removeViewShapes( aViewerId );
         setLandCoversScalarMapModeOff( aViewerId );
       }
@@ -1670,12 +1795,23 @@ void HYDROGUI_Module::onViewManagerRemoved( SUIT_ViewManager* theViewManager )
   }
 }
 
+void HYDROGUI_Module::onViewManagerRemoved( SUIT_ViewManager* theViewManager )
+{
+  DEBTRACE("HYDROGUI_Module::onViewManagerRemoved");
+  removeViewManager(theViewManager);
+  LightApp_Module::onViewManagerRemoved( theViewManager );
+
+}
+
 void HYDROGUI_Module::onViewCreated( SUIT_ViewWindow* theViewWindow )
 {
+  DEBTRACE("HYDROGUI_Module::onViewCreated");
   if( theViewWindow && theViewWindow->inherits( "GraphicsView_ViewFrame" ) )
   {
+       DEBTRACE("theViewWindow->inherits( 'GraphicsView_ViewFrame' )");
     if( GraphicsView_ViewFrame* aViewFrame = dynamic_cast<GraphicsView_ViewFrame*>( theViewWindow ) )
     {
+      DEBTRACE("---");
       aViewFrame->installEventFilter( this );
 
       GraphicsView_ViewPort* aViewPort = aViewFrame->getViewPort();
@@ -1687,12 +1823,13 @@ void HYDROGUI_Module::onViewCreated( SUIT_ViewWindow* theViewWindow )
   }
   else if( theViewWindow && theViewWindow->inherits( "OCCViewer_ViewFrame" ) )
   {
+       DEBTRACE("theViewWindow->inherits( 'OCCViewer_ViewFrame' )");
     if( OCCViewer_ViewFrame* aViewFrame = dynamic_cast<OCCViewer_ViewFrame*>( theViewWindow ) )
     {
+      DEBTRACE("---");
       aViewFrame->onTopView();
 
       HYDROGUI_Tool::setOCCActionShown( aViewFrame, OCCViewer_ViewWindow::MaximizedId, false );
-
       OCCViewer_ViewPort3d* aViewPort = aViewFrame->getViewPort();
       if ( aViewPort ) {
         aViewPort->installEventFilter( this );
@@ -1701,8 +1838,10 @@ void HYDROGUI_Module::onViewCreated( SUIT_ViewWindow* theViewWindow )
   }
   else if( theViewWindow && theViewWindow->inherits( "SVTK_ViewWindow" ) )
   {
+       DEBTRACE("theViewWindow->inherits( 'SVTK_ViewWindow' )");
     if( SVTK_ViewWindow* aViewFrame = dynamic_cast<SVTK_ViewWindow*>( theViewWindow ) )
     {
+      DEBTRACE("---");
       aViewFrame->installEventFilter( this );
     }
   }
@@ -1755,17 +1894,18 @@ void HYDROGUI_Module::onViewPortMouseEvent( QGraphicsSceneMouseEvent* theEvent )
   */
 }
 
-void HYDROGUI_Module::updateViewer( HYDROGUI_AbstractDisplayer* theDisplayer, 
-                                    const bool theIsInit, 
-                                    const bool theIsForced, 
+void HYDROGUI_Module::updateViewer( HYDROGUI_AbstractDisplayer* theDisplayer,
+                                    const bool theIsInit,
+                                    const bool theIsForced,
                                     const bool theDoFitAll )
 {
-  QList<int> aViewManagerIdList;
+  DEBTRACE("HYDROGUI_Module::updateViewer");
+  QList<size_t> aViewManagerIdList;
 
   // currently, all views are updated
   ViewManagerMapIterator anIter( myViewManagerMap );
   while( anIter.hasNext() )
-  { 
+  {
     SUIT_ViewManager* aViewManager = anIter.next().value().first;
 
     if ( theDisplayer->IsApplicable( aViewManager ) )
@@ -1775,7 +1915,7 @@ void HYDROGUI_Module::updateViewer( HYDROGUI_AbstractDisplayer* theDisplayer,
     }
   }
 
-  QListIterator<int> anIdIter( aViewManagerIdList );
+  QListIterator<size_t> anIdIter( aViewManagerIdList );
   while( anIdIter.hasNext() )
   {
     theDisplayer->UpdateAll( anIdIter.next(), theIsInit, theIsForced, theDoFitAll );
@@ -1783,8 +1923,9 @@ void HYDROGUI_Module::updateViewer( HYDROGUI_AbstractDisplayer* theDisplayer,
   }
 }
 
-void HYDROGUI_Module::createSelector( SUIT_ViewManager* theViewManager )
+void HYDROGUI_Module::createSelector( SUIT_ViewManager* theViewManager, bool isDisableGV )
 {
+  DEBTRACE("HYDROGUI_Module::createSelector " << isDisableGV);
   if( !theViewManager )
     return;
 
@@ -1793,6 +1934,7 @@ void HYDROGUI_Module::createSelector( SUIT_ViewManager* theViewManager )
     return;
 
   QString aViewType = theViewManager->getType();
+  DEBTRACE("aViewType " << aViewType.toStdString());
   if( aViewType != GraphicsView_Viewer::Type() &&
       aViewType != OCCViewer_Viewer::Type())
     return;
@@ -1801,14 +1943,44 @@ void HYDROGUI_Module::createSelector( SUIT_ViewManager* theViewManager )
   aSelectionMgr->selectors( aViewType, aSelectorList );
 
   // disable all alien selectors
+  bool isGV = false;
+  bool isOCC = false;
   QList<SUIT_Selector*>::iterator anIter, anIterEnd = aSelectorList.end();
   for( anIter = aSelectorList.begin(); anIter != anIterEnd; anIter++ )
   {
     SUIT_Selector* aSelector = *anIter;
-    if( aSelector && ( !dynamic_cast<HYDROGUI_GVSelector*>( aSelector ) &&
-                       !dynamic_cast<SVTK_Selector*>( aSelector ) &&
-                       !dynamic_cast<HYDROGUI_OCCSelector*>( aSelector ) ) )
-      aSelector->setEnabled( false );
+    bool isOk = false;
+    if (aSelector)
+    {
+       DEBTRACE("Selector " << aSelector->type().toStdString());
+       if (dynamic_cast<HYDROGUI_GVSelector*>( aSelector ))
+       {
+               isOk = !isDisableGV;
+               isGV = true;
+               DEBTRACE("HYDROGUI_GVSelector " << isOk);
+       }
+       else if (dynamic_cast<SVTK_Selector*>( aSelector ))
+       {
+               isOk = true;
+               DEBTRACE("SVTK_Selector");
+       }
+       else if (dynamic_cast<HYDROGUI_OCCSelector*>( aSelector ))
+       {
+               isOk = true;
+               isOCC = true;
+               DEBTRACE("HYDROGUI_OCCSelector");
+       }
+       if (isOk)
+               {
+                 DEBTRACE("Selector enabled " << aSelector->type().toStdString());
+                 aSelector->setEnabled( true );
+               }
+       else
+               {
+                 DEBTRACE("Selector disabled " << aSelector->type().toStdString());
+                 aSelector->setEnabled( false );
+               }
+    }
   }
 
   if ( aViewType == GraphicsView_Viewer::Type() )
@@ -1816,19 +1988,28 @@ void HYDROGUI_Module::createSelector( SUIT_ViewManager* theViewManager )
     GraphicsView_ViewManager* aViewManager =
       ::qobject_cast<GraphicsView_ViewManager*>( theViewManager );
     if( aViewManager )
-      new HYDROGUI_GVSelector( this, aViewManager->getViewer(), aSelectionMgr );
+    {
+      HYDROGUI_GVSelector* sel = new HYDROGUI_GVSelector( this, aViewManager->getViewer(), aSelectionMgr );
+      DEBTRACE("new HYDROGUI_GVSelector " << sel << " " << sel->type().toStdString());
+      sel->setEnabled( true );
+    }
   }
   else if ( aViewType == OCCViewer_Viewer::Type() )
   {
     OCCViewer_ViewManager* aViewManager =
       ::qobject_cast<OCCViewer_ViewManager*>( theViewManager );
     if( aViewManager )
-      new HYDROGUI_OCCSelector( this, aViewManager->getOCCViewer(), aSelectionMgr );
+    {
+      HYDROGUI_OCCSelector* sel =  new HYDROGUI_OCCSelector( this, aViewManager->getOCCViewer(), aSelectionMgr );
+      DEBTRACE("new HYDROGUI_OCCSelector " << sel << " " << sel->type().toStdString());
+      sel->setEnabled( true );
+    }
   }
 }
 
 bool HYDROGUI_Module::setUpdateEnabled( const bool theState )
 {
+  DEBTRACE("HYDROGUI_Module::setUpdateEnabled");
   bool aPrevState = myIsUpdateEnabled;
   myIsUpdateEnabled = theState;
   return aPrevState;
@@ -1841,6 +2022,7 @@ bool HYDROGUI_Module::isUpdateEnabled() const
 
 QStringList HYDROGUI_Module::storeSelection() const
 {
+  DEBTRACE("HYDROGUI_Module::storeSelection");
   QStringList anEntryList;
   if( LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr() )
   {
@@ -1850,7 +2032,7 @@ QStringList HYDROGUI_Module::storeSelection() const
     SUIT_DataOwnerPtrList::iterator anIter;
     for( anIter = aList.begin(); anIter != aList.end(); anIter++ )
     {
-      const LightApp_DataOwner* anOwner = 
+      const LightApp_DataOwner* anOwner =
         dynamic_cast<const LightApp_DataOwner*>( (*anIter).operator->() );
       if( anOwner )
         anEntryList.append( anOwner->entry() );
@@ -1861,6 +2043,7 @@ QStringList HYDROGUI_Module::storeSelection() const
 
 void HYDROGUI_Module::restoreSelection( const QStringList& theEntryList )
 {
+  DEBTRACE("HYDROGUI_Module::restoreSelection");
   if( LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr() )
   {
     SUIT_DataOwnerPtrList aList( true );
@@ -1886,8 +2069,7 @@ void HYDROGUI_Module::onMouseMove( SUIT_ViewWindow* theViewWindow, QMouseEvent*
     if ( aDesktop && aDesktop->statusBar() )
     {
       gp_Pnt aWPnt( X, Y, Z );
-      int aStudyId = application()->activeStudy()->id();
-      HYDROData_Document::Document( aStudyId )->Transform( aWPnt, false );
+      HYDROData_Document::Document()->Transform( aWPnt, false );
       double WX = aWPnt.X(), WY = aWPnt.Y();
 
       QString aXStr = HYDROGUI_Tool::GetCoordinateString( X, true );
@@ -1906,6 +2088,7 @@ void HYDROGUI_Module::onMouseMove( SUIT_ViewWindow* theViewWindow, QMouseEvent*
  */
 QStack<HYDROGUI_Operation*>& HYDROGUI_Module::getActiveOperations()
 {
+  DEBTRACE("HYDROGUI_Module::getActiveOperations");
   return myActiveOperationMap;
 }
 
@@ -1964,7 +2147,68 @@ void HYDROGUI_Module::onObjectClicked( SUIT_DataObject* theObject, int theColumn
   update( UF_OCCViewer | UF_VTKViewer | ( visState == Qtx::ShownState ? UF_FitAll : 0 ) );
 }
 
-Handle(HYDROData_StricklerTable) HYDROGUI_Module::getLandCoverColoringTable( const int theViewId ) const
+bool HYDROGUI_Module::isDraggable( const SUIT_DataObject* what ) const
+{
+  return true;
+}
+
+bool HYDROGUI_Module::isDropAccepted( const SUIT_DataObject* where ) const
+{
+
+  return true;
+}
+
+void HYDROGUI_Module::dropObjects( const DataObjectList& what, SUIT_DataObject* where,
+                                   const int row, Qt::DropAction action )
+{
+  if ( action != Qt::CopyAction && action != Qt::MoveAction )
+    return;
+
+  if (row == -1)
+    return;
+
+  if (where->level() < 2 )
+    return;
+
+  DataObjectList::ConstIterator it = what.constBegin();
+  for (;it != what.constEnd();++it)
+  {
+    if ((*it)->parent() != where)
+      return;
+  }
+
+  it = what.constBegin();
+
+  int i=0;
+  for (;it != what.constEnd();++it)
+  {
+    SUIT_DataObject* objWhat = *it;
+
+    DataObjectList objInSect = where->children();
+
+    //std::list<SUIT_DataObject*> t1 = where->children().toStdList(); //debug
+    int ind = objInSect.indexOf(objWhat);
+    if (ind != -1)
+    {
+      HYDROGUI_DataModel* aModel = getDataModel();
+      int pos = -1;
+      if (ind >= row)
+      {
+        pos = row + i;
+        i++;
+      }
+      else
+        pos = row - 1;
+      where->moveChildPos(objWhat, pos);
+      //std::list<SUIT_DataObject*> t2 = where->children().toStdList(); //debug
+    }
+  }
+
+  getApp()->updateObjectBrowser(true);
+
+}
+
+Handle(HYDROData_StricklerTable) HYDROGUI_Module::getLandCoverColoringTable( const size_t theViewId ) const
 {
   Handle(HYDROData_StricklerTable) aTable;
 
@@ -1975,20 +2219,20 @@ Handle(HYDROData_StricklerTable) HYDROGUI_Module::getLandCoverColoringTable( con
   return aTable;
 }
 
-void HYDROGUI_Module::setLandCoverColoringTable( const int theViewId,
+void HYDROGUI_Module::setLandCoverColoringTable( const size_t theViewId,
                                                  const Handle(HYDROData_StricklerTable)& theTable )
 {
-  if ( !theTable.IsNull() ) {
+  if ( !theTable.IsNull() && theViewId ) {
     myLandCoverColoringMap.insert( theViewId, theTable );
   }
 }
 
-void HYDROGUI_Module::setLandCoversScalarMapModeOff( const int theViewId )
+void HYDROGUI_Module::setLandCoversScalarMapModeOff( const size_t theViewId )
 {
   myLandCoverColoringMap.remove( theViewId );
 }
 
-bool HYDROGUI_Module::isLandCoversScalarMapModeOn( const int theViewId ) const
+bool HYDROGUI_Module::isLandCoversScalarMapModeOn( const size_t theViewId ) const
 {
   return myLandCoverColoringMap.contains( theViewId );
 }
@@ -2000,12 +2244,11 @@ void HYDROGUI_Module::setObjectRemoved( const Handle(HYDROData_Entity)& theObjec
   }
 
   if ( theObject->GetKind() == KIND_STRICKLER_TABLE ) {
-    Handle(HYDROData_StricklerTable) aTable = 
+    Handle(HYDROData_StricklerTable) aTable =
       Handle(HYDROData_StricklerTable)::DownCast( theObject );
-    QList<int> aViewIds;
-    QMutableMapIterator<int, Handle(HYDROData_StricklerTable)> anIter( myLandCoverColoringMap );
+    QMutableMapIterator<size_t, Handle(HYDROData_StricklerTable)> anIter( myLandCoverColoringMap );
     while ( anIter.hasNext() ) {
-      if ( HYDROGUI_DataObject::dataObjectEntry( anIter.next().value() ) == 
+      if ( HYDROGUI_DataObject::dataObjectEntry( anIter.next().value() ) ==
            HYDROGUI_DataObject::dataObjectEntry( aTable ) ) {
         anIter.remove();
       }
@@ -2015,6 +2258,7 @@ void HYDROGUI_Module::setObjectRemoved( const Handle(HYDROData_Entity)& theObjec
 
 void HYDROGUI_Module::onViewActivated( SUIT_ViewManager* theMgr )
 {
+  DEBTRACE("HYDROGUI_Module::onViewActivated");
   if( !theMgr )
     return;
 
@@ -2025,3 +2269,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);
+    }
+  }
+}
+