Salome HOME
Merge branch 'BR_v14_rc' of ssh://git.salome-platform.org/modules/hydro into BR_v14_rc
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_ShowHideOp.cxx
index d06c59f26ce4c267f84d89fd05db87ba0c3d6e84..066d0190f2bb90ba836c3c300cc40785c31fce2f 100644 (file)
@@ -1,12 +1,8 @@
-// Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
-//
-// Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
-// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
-//
+// Copyright (C) 2014-2015  EDF-R&D
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
 // License as published by the Free Software Foundation; either
-// version 2.1 of the License.
+// version 2.1 of the License, or (at your option) any later version.
 //
 // This library is distributed in the hope that it will be useful,
 // but WITHOUT ANY WARRANTY; without even the implied warranty of
 #include <HYDROData_Region.h>
 
 #include <LightApp_Application.h>
+#include <LightApp_Displayer.h>
 
 #include <OCCViewer_ViewModel.h>
+#include <OCCViewer_ViewManager.h>
+
 #include <SVTK_ViewModel.h>
 
 #include <SUIT_ViewManager.h>
@@ -65,7 +64,32 @@ void HYDROGUI_ShowHideOp::startOperation()
 {
   HYDROGUI_Operation::startOperation();
 
-  size_t aViewId = HYDROGUI_Tool::GetActiveViewId( module() );
+  HYDROGUI_Module* aModule = module();
+
+  size_t aViewId = HYDROGUI_Tool::GetActiveViewId( aModule );
+
+  int anUpdateFlags = 0;
+
+  SUIT_ViewManager* aVTKMgr           = NULL;
+  OCCViewer_ViewManager* anOCCManager = NULL;
+
+  SUIT_ViewManager* aViewMgr = aModule->getApp()->activeViewManager();
+  if ( aViewMgr )
+  {
+    if ( aViewMgr->getType() == GraphicsView_Viewer::Type() )
+    {
+      anUpdateFlags |= UF_Viewer;
+    }
+    else if ( aViewMgr->getType() == OCCViewer_Viewer::Type() )
+    {
+      anUpdateFlags |= UF_OCCViewer;
+      anOCCManager = ::qobject_cast<OCCViewer_ViewManager*>( aViewMgr );
+    }
+    else if ( aViewMgr->getType() == SVTK_Viewer::Type() )
+    {
+      anUpdateFlags |= UF_VTKViewer;
+    }
+  }
 
   // for all objects
   if( myId == ShowOnlyId || myId == ShowAllId || myId == HideAllId )
@@ -76,26 +100,31 @@ void HYDROGUI_ShowHideOp::startOperation()
     {
       Handle(HYDROData_Entity) anObject = anIterator.Current();
       if( !anObject.IsNull() )
-        module()->setObjectVisible( aViewId, anObject, aVisibility );
+        aModule->setObjectVisible( aViewId, anObject, aVisibility );
     }
-  }
 
-  int anUpdateFlags = 0;
-  SUIT_ViewManager* aVTKMgr = 0;
+    // For occ viewer we do the additional step to hide objects from other modules
+    if ( anOCCManager != NULL && !aVisibility )
+      LightApp_Displayer().EraseAll( true );
+  }
 
+  bool isFoundImage = false;
   // for selected objects
   if( myId == ShowId || myId == ShowOnlyId || myId == HideId )
   {
-    HYDROData_SequenceOfObjects aSeq = HYDROGUI_Tool::GetSelectedObjects( module() );
+    HYDROData_SequenceOfObjects aSeq = HYDROGUI_Tool::GetSelectedObjects( aModule );
   
-    bool aVisibility = myId == ShowId || myId == ShowOnlyId;
+    bool aVisibility = myId == ShowId || myId == ShowOnlyId || myId == ShowAllId;
     Handle( HYDROData_Entity ) anObject;
     for( Standard_Integer anIndex = 1, aLength = aSeq.Length(); anIndex <= aLength; anIndex++ )
     {
       anObject = aSeq.Value( anIndex );
       if( !anObject.IsNull() )
       {
-        module()->setObjectVisible( aViewId, anObject, aVisibility );
+        if ( anObject->GetKind() == KIND_IMAGE )
+          isFoundImage = true;
+
+        aModule->setObjectVisible( aViewId, anObject, aVisibility );
         if ( anObject->GetKind() == KIND_REGION )
         {
           Handle( HYDROData_Region ) aRegion = Handle( HYDROData_Region )::DownCast( anObject );
@@ -107,22 +136,29 @@ void HYDROGUI_ShowHideOp::startOperation()
               anObject = aZonesSeq.Value( aZoneIdx );
               if( !anObject.IsNull() )
               {
-                module()->setObjectVisible( aViewId, anObject, aVisibility );
+                aModule->setObjectVisible( aViewId, anObject, aVisibility );
               }
             }
           }
         }
         else if ( anObject->GetKind() == KIND_BATHYMETRY && aVisibility )
         {
-          // Activate VTK viewer if show a bathymetry
-          aVTKMgr = module()->getApp()->viewManager( SVTK_Viewer::Type() );
-          if ( !aVTKMgr )
+          if ( anUpdateFlags & UF_OCCViewer )
           {
-            aVTKMgr = module()->getApp()->createViewManager( SVTK_Viewer::Type() );
+            aModule->setObjectVisible( aViewId, anObject, aVisibility );
           }
-          if ( aVTKMgr )
+          else if ( !(anUpdateFlags & UF_VTKViewer) )
           {
-            module()->setObjectVisible( (size_t)aVTKMgr->getViewModel(), anObject, aVisibility );
+            // Activate VTK viewer if show a bathymetry
+            aVTKMgr = aModule->getApp()->viewManager( SVTK_Viewer::Type() );
+            if ( !aVTKMgr )
+            {
+              aVTKMgr = aModule->getApp()->createViewManager( SVTK_Viewer::Type() );
+            }
+            if ( aVTKMgr )
+            {
+              aModule->setObjectVisible( (size_t)aVTKMgr->getViewModel(), anObject, aVisibility );
+            }
           }
         }
       }
@@ -131,7 +167,8 @@ void HYDROGUI_ShowHideOp::startOperation()
 
   if ( myId == ShowOnlyId || myId == ShowId || myId == ShowAllId )
   {
-    anUpdateFlags |= UF_FitAll;
+    if( isFoundImage || myId == ShowAllId )
+      anUpdateFlags |= UF_FitAll;
   }
 
   // Set VTK viewer active if show a bathymetry
@@ -140,23 +177,7 @@ void HYDROGUI_ShowHideOp::startOperation()
     anUpdateFlags |= UF_VTKViewer;
     aVTKMgr->setShown( true );
   }
-  SUIT_ViewManager* aViewMgr = module()->getApp()->activeViewManager();
-  if ( aViewMgr )
-  {
-    if ( aViewMgr->getType() == GraphicsView_Viewer::Type() )
-    {
-      anUpdateFlags |= UF_Viewer;
-    }
-    else if ( aViewMgr->getType() == OCCViewer_Viewer::Type() )
-    {
-      anUpdateFlags |= UF_OCCViewer;
-    }
-    else if ( aViewMgr->getType() == SVTK_Viewer::Type() )
-    {
-      anUpdateFlags |= UF_VTKViewer;
-    }
-  }
 
-  module()->update( anUpdateFlags );
+  aModule->update( anUpdateFlags );
   commit();
 }