Salome HOME
Issues ##68, 88: Swith between GEOM and HYDRO.
authormzn <mzn@opencascade.com>
Tue, 10 Dec 2013 09:43:35 +0000 (09:43 +0000)
committermzn <mzn@opencascade.com>
Tue, 10 Dec 2013 09:43:35 +0000 (09:43 +0000)
src/HYDROGUI/HYDROGUI_Module.cxx

index 3c7a5e59c80ae0277796063223112a8d04281735..7244bab70c5448c06576aef30aa561bff201f1ef 100644 (file)
@@ -153,6 +153,38 @@ bool HYDROGUI_Module::activateModule( SUIT_Study* theStudy )
                               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;
+  ViewManagerList anAllViewManagers = anApp->viewManagers();
+  ViewManagerList aHydroViewManagers; // view managers created inside the HYDRO module
+  ViewManagerMapIterator anIter( myViewManagerMap );
+  while( anIter.hasNext() ) {
+    int anId = anIter.next().key();
+    const ViewManagerInfo& anInfo = anIter.value();
+  
+    aHydroViewManagers << anInfo.first;
+
+    if ( !anAllViewManagers.contains( anInfo.first ) ) {
+      anObsoleteIds << anId;
+    }
+  }
+  foreach ( const int anId, anObsoleteIds ) {
+    myViewManagerMap.remove( anId );
+    myObjectStateMap.remove( anId );
+    myShapesMap.remove( anId );
+    myVTKPrsMap.remove( anId );
+  }
+  // Replace the default selector for all view managers.
+  // Add view managers created outside of HYDRO module to the map.
+  foreach ( SUIT_ViewManager* aViewManager, anAllViewManagers ) {
+    createSelector( aViewManager ); // replace the default selector
+    if ( !aHydroViewManagers.contains( aViewManager ) ) {
+      ViewManagerInfo anInfo( aViewManager, VMR_General );
+      myViewManagerMap.insert( ViewManagerId++, anInfo );
+    }
+  }
+
   update( UF_All );
 
   updateCommandsStatus();
@@ -180,11 +212,13 @@ bool HYDROGUI_Module::activateModule( SUIT_Study* theStudy )
 
 bool HYDROGUI_Module::deactivateModule( SUIT_Study* theStudy )
 {
+  /* Issues ## 68, 88.
   ViewManagerMapIterator anIter( myViewManagerMap );
   while( anIter.hasNext() )
     if( SUIT_ViewManager* aViewManager = anIter.next().value().first )
       getApp()->removeViewManager( aViewManager );
   myViewManagerMap.clear();
+  */
 
   ViewManagerList anOCCViewManagers;
   getApp()->viewManagers( OCCViewer_Viewer::Type(), anOCCViewManagers );
@@ -193,9 +227,11 @@ bool HYDROGUI_Module::deactivateModule( SUIT_Study* theStudy )
                 this, SLOT( onMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
   }
 
+  /* Issues ## 68, 88.
   myObjectStateMap.clear();
   myShapesMap.clear();
   myVTKPrsMap.clear();
+  */
 
   // clear the data model's list of copying objects
   HYDROGUI_DataModel::changeCopyingObjects( HYDROData_SequenceOfObjects() );
@@ -225,7 +261,7 @@ void HYDROGUI_Module::windows( QMap<int, int>& theMap ) const
 
 void HYDROGUI_Module::viewManagers( QStringList& theTypesList ) const
 {
-  theTypesList << OCCViewer_Viewer::Type() << GraphicsView_Viewer::Type();
+  theTypesList << GraphicsView_Viewer::Type() << OCCViewer_Viewer::Type();
 }
 
 void HYDROGUI_Module::contextMenuPopup( const QString& theClient,
@@ -272,7 +308,7 @@ void HYDROGUI_Module::contextMenuPopup( const QString& theClient,
   bool anIsGeomObject = false;
 
   // check the selected GEOM objects
-  if ( !HYDROGUI_Tool::GetSelectedGeomObjects( this ).isEmpty() ) {
+  if ( anIsObjectBrowser && !HYDROGUI_Tool::GetSelectedGeomObjects( this ).isEmpty() ) {
     theMenu->addAction( action( ImportGeomObjectId ) );
     theMenu->addSeparator();
   }