Salome HOME
Disabling message_progress
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_Module.cxx
index dc41e3e12e3c1ca7921d68d7b585000379b19538..f93e0cef65fbf1955a0f5b072067ce7ca890970f 100755 (executable)
@@ -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"
 //#define _DEVDEBUG_
 #include "HYDRO_trace.hxx"
 
-static int ViewManagerId = 0;
+static size_t ViewManagerId = 1;
 
 extern "C" HYDRO_EXPORT CAM_Module* createModule()
 {
@@ -164,8 +167,8 @@ void HYDROGUI_Module::initialize( CAM_Application* theApp )
   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() ) );
+  //HYDROData_Tool::SetSIProgress( new HYDROGUI_SIProgressIndicator( theApp->desktop() ) );
+  //HYDROData_Tool::SetZIProgress( new HYDROGUI_ZIProgressIndicator( theApp->desktop() ) );
 }
 
 bool HYDROGUI_Module::activateModule( SUIT_Study* theStudy )
@@ -181,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 );
@@ -231,7 +252,7 @@ bool HYDROGUI_Module::activateModule( SUIT_Study* theStudy )
   {
     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 );
@@ -255,7 +276,7 @@ bool HYDROGUI_Module::activateModule( SUIT_Study* theStudy )
   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::getStudyServant();
@@ -294,7 +315,7 @@ bool HYDROGUI_Module::deactivateModule( SUIT_Study* theStudy )
   {
     disconnect( aViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ),
                 this, SLOT( onMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
-    disconnect( aViewManager, SIGNAL( activated( SUIT_ViewManager* ) ), 
+    disconnect( aViewManager, SIGNAL( activated( SUIT_ViewManager* ) ),
                 this, SLOT( onViewActivated( SUIT_ViewManager* ) ) );
 
     OCCViewer_ViewManager* occ_mgr = dynamic_cast<OCCViewer_ViewManager*>( aViewManager );
@@ -332,14 +353,16 @@ bool HYDROGUI_Module::deactivateModule( SUIT_Study* theStudy )
   myViewManagerMap.clear();
 
   bool ret = LightApp_Module::deactivateModule( theStudy );
-  HYDROGUI_DataModel* aModel = getDataModel();
-  if (aModel->isAboutToClose())
-  {
+  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();
-  }
-  return ret;
 }
 
 void HYDROGUI_Module::windows( QMap<int, int>& theMap ) const
@@ -361,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 );
@@ -438,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
@@ -514,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;
@@ -543,7 +566,7 @@ void HYDROGUI_Module::contextMenuPopup( const QString& theClient,
       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();
@@ -594,11 +617,11 @@ void HYDROGUI_Module::contextMenuPopup( const QString& theClient,
         theMenu->addAction( action( CreateCylinderId ) );
         break;
       case KIND_STRICKLER_TABLE:
-        theMenu->addAction( action( ImportStricklerTableFromFileId ) );          
+        theMenu->addAction( action( ImportStricklerTableFromFileId ) );
         break;
       case KIND_LAND_COVER_MAP:
-        theMenu->addAction( action( CreateLandCoverMapId ) ); 
-        theMenu->addAction( action( ImportLandCoverMapId ) ); 
+        theMenu->addAction( action( CreateLandCoverMapId ) );
+        theMenu->addAction( action( ImportLandCoverMapId ) );
         break;
       case KIND_CALCULATION:
         theMenu->addAction( action( CreateCalculationId ) );
@@ -754,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 );
 
@@ -777,7 +800,7 @@ void HYDROGUI_Module::contextMenuPopup( const QString& theClient,
         //
         theMenu->addAction( action( ExportToShapeFileID ) );
         theMenu->addSeparator();
-      }      
+      }
       else if( anIsVisualState && anIsObjectBrowser )
       {
         theMenu->addAction( action( SaveVisualStateId ) );
@@ -808,7 +831,7 @@ void HYDROGUI_Module::contextMenuPopup( const QString& theClient,
         theMenu->addAction( action( SetTransparencyId ) );
         theMenu->addSeparator();
       }
-    } 
+    }
     else if ( anAllAreProfiles )
     {
       theMenu->addAction( action( EditProfileId ) );
@@ -833,7 +856,7 @@ void HYDROGUI_Module::contextMenuPopup( const QString& theClient,
 
     theMenu->addSeparator();
 
-    if( anIsImage || anIsPolyline || anIsPolyline3D || 
+    if( anIsImage || anIsPolyline || anIsPolyline3D ||
       anIsImmersibleZone || anIsZone || anIsRegion ||
       anIsBathymetry || anIsObstacle || anIsStream ||
       anIsChannel || anIsDigue || anIsDummyObject3D ||
@@ -989,7 +1012,7 @@ void HYDROGUI_Module::preferencesChanged( const QString& theSection, const QStri
     SUIT_ResourceMgr* resMgr = application()->resourceMgr();
     if ( theSection == "preferences" && thePref == "default_strickler_coefficient" )
     {
-        
+
         Handle(HYDROData_Document) aDoc = HYDROData_Document::Document();
         if ( resMgr && !aDoc.IsNull() )
             aDoc->SetDefaultStricklerCoefficient( resMgr->doubleValue( theSection, thePref, 0 ) );
@@ -1007,7 +1030,7 @@ 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 );
@@ -1030,7 +1053,7 @@ void HYDROGUI_Module::preferencesChanged( const QString& theSection, const QStri
         if (anOCCViewMgr)
           anOCCViewMgr->setChainedOperations( aChainedPan );
       }
-      
+
       QList<QDockWidget*> docW = getApp()->desktop()->findChildren<QDockWidget*>();
       foreach (QDockWidget* qw, docW)
       {
@@ -1075,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() )
   {
@@ -1096,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
     }
   }
 
@@ -1136,6 +1159,7 @@ void HYDROGUI_Module::updateCommandsStatus()
 
 void HYDROGUI_Module::selectionChanged()
 {
+  DEBTRACE("HYDROGUI_Module::selectionChanged");
   LightApp_Module::selectionChanged();
   updateCommandsStatus();
 }
@@ -1164,9 +1188,9 @@ HYDROGUI_VTKPrsDisplayer* HYDROGUI_Module::getVTKDisplayer() const
   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");
+  DEBTRACE("HYDROGUI_Module::getViewManager " << theId);
   if( myViewManagerMap.contains( theId ) )
   {
     return myViewManagerMap[ theId ].first;
@@ -1174,9 +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");
+  DEBTRACE("HYDROGUI_Module::getViewer " << theId);
   if( myViewManagerMap.contains( theId ) )
   {
     ViewManagerInfo anInfo = myViewManagerMap[ theId ];
@@ -1188,9 +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");
+  DEBTRACE("HYDROGUI_Module::getOCCViewer " << theId);
   if( myViewManagerMap.contains( theId ) )
   {
     ViewManagerInfo anInfo = myViewManagerMap[ theId ];
@@ -1202,9 +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");
+  DEBTRACE("HYDROGUI_Module::getVTKViewer "  << theId);
   if( myViewManagerMap.contains( theId ) )
   {
     ViewManagerInfo anInfo = myViewManagerMap[ theId ];
@@ -1216,25 +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 )
 {
   DEBTRACE("HYDROGUI_Module::getViewManagerRole");
-  int anId = getViewManagerId( theViewManager );
-  if( anId != -1 )
+  size_t anId = getViewManagerId( theViewManager );
+  if( anId == 0 )
   {
     const ViewManagerInfo& anInfo = myViewManagerMap[ anId ];
     return anInfo.second;
@@ -1246,24 +1270,24 @@ void HYDROGUI_Module::setViewManagerRole( SUIT_ViewManager* theViewManager,
                                           const ViewManagerRole theRole )
 {
   DEBTRACE("HYDROGUI_Module::setViewManagerRole");
-  int anId = getViewManagerId( theViewManager );
-  if( anId != -1 )
+  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;
@@ -1287,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 );
         }
@@ -1358,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;
@@ -1375,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;
@@ -1398,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 )
 {
@@ -1409,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 ) )
@@ -1423,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;
@@ -1432,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;
@@ -1450,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;
@@ -1473,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 )
 {
@@ -1507,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 ) )
@@ -1536,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 ) )
@@ -1563,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;
@@ -1579,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 ) )
   {
@@ -1690,7 +1729,7 @@ void HYDROGUI_Module::onViewManagerAdded( SUIT_ViewManager* theViewManager )
   LightApp_Module::onViewManagerAdded( theViewManager );
 
   if( theViewManager->getType() == GraphicsView_Viewer::Type() )
-  { 
+  {
     connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
              this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
   }
@@ -1703,7 +1742,7 @@ void HYDROGUI_Module::onViewManagerAdded( SUIT_ViewManager* theViewManager )
              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() )
@@ -1720,23 +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)
 {
-  DEBTRACE("HYDROGUI_Module::onViewManagerRemoved");
-  LightApp_Module::onViewManagerRemoved( theViewManager );
-
-  createSelector( theViewManager ); // replace the default selector
+  DEBTRACE("removeViewManager")
 
-  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 );
       }
@@ -1756,13 +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();
@@ -1774,8 +1823,10 @@ 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 );
@@ -1787,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 );
     }
   }
@@ -1841,18 +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 )
 {
   DEBTRACE("HYDROGUI_Module::updateViewer");
-  QList<int> aViewManagerIdList;
+  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 ) )
@@ -1862,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 );
@@ -1870,9 +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");
+  DEBTRACE("HYDROGUI_Module::createSelector " << isDisableGV);
   if( !theViewManager )
     return;
 
@@ -1881,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;
@@ -1889,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() )
@@ -1904,14 +1988,22 @@ 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 );
+    }
   }
 }
 
@@ -1940,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() );
@@ -2070,16 +2162,16 @@ void HYDROGUI_Module::dropObjects( const DataObjectList& what, SUIT_DataObject*
                                    const int row, Qt::DropAction action )
 {
   if ( action != Qt::CopyAction && action != Qt::MoveAction )
-    return; 
+    return;
 
   if (row == -1)
     return;
 
   if (where->level() < 2 )
-    return;  
+    return;
 
   DataObjectList::ConstIterator it = what.constBegin();
-  for (;it != what.constEnd();++it) 
+  for (;it != what.constEnd();++it)
   {
     if ((*it)->parent() != where)
       return;
@@ -2088,7 +2180,7 @@ void HYDROGUI_Module::dropObjects( const DataObjectList& what, SUIT_DataObject*
   it = what.constBegin();
 
   int i=0;
-  for (;it != what.constEnd();++it) 
+  for (;it != what.constEnd();++it)
   {
     SUIT_DataObject* objWhat = *it;
 
@@ -2109,14 +2201,14 @@ void HYDROGUI_Module::dropObjects( const DataObjectList& what, SUIT_DataObject*
         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 int theViewId ) const
+Handle(HYDROData_StricklerTable) HYDROGUI_Module::getLandCoverColoringTable( const size_t theViewId ) const
 {
   Handle(HYDROData_StricklerTable) aTable;
 
@@ -2127,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 );
 }
@@ -2152,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();
       }