Salome HOME
Update copyright
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_VTKUtils.cxx
index 903aceb65f60b63517316873a4bafb866e2bd336..11b6204b02eec865b8a3a60a9345275510420978 100644 (file)
@@ -1,23 +1,23 @@
-//  Copyright (C) 2007-2010  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2011  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) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
 //
-//  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.
+// 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.
 //
-//  This library is distributed in the hope that it will be useful,
-//  but WITHOUT ANY WARRANTY; without even the implied warranty of
-//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-//  Lesser General Public License for more details.
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
 //
-//  You should have received a copy of the GNU Lesser General Public
-//  License along with this library; if not, write to the Free Software
-//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 //
-//  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
 
 // SMESH SMESHGUI : GUI for SMESH component
@@ -103,21 +103,41 @@ namespace SMESH
    */
   //================================================================================
 
-  void RemoveVisualObjectWithActors( const char* theEntry )
+  void RemoveVisualObjectWithActors( const char* theEntry, bool fromAllViews )
   {
-    SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>
-      ( SUIT_Session::session()->activeApplication() );
-    SUIT_ViewManager* aViewManager =
-      app ? app->getViewManager(SVTK_Viewer::Type(), true) : 0;
-    if ( aViewManager ) {
+    SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>(SUIT_Session::session()->activeApplication());
+    if(!app)
+      return;
+    SalomeApp_Study* aStudy  = dynamic_cast<SalomeApp_Study*>(app->activeStudy());
+    if(!aStudy)
+      return;
+    ViewManagerList aList;
+
+    if(fromAllViews) {
+      app->viewManagers(SVTK_Viewer::Type() , aList);
+    } else {
+      SUIT_ViewManager* aVM = app->getViewManager(SVTK_Viewer::Type(), true);
+      if(aVM)
+        aList.append(aVM);
+    }    
+    bool actorRemoved = false;
+    ViewManagerList::ConstIterator it = aList.begin();
+    SUIT_ViewManager* aViewManager = 0;
+    for( ; it!=aList.end();it++) {
+      aViewManager = *it;
       QVector<SUIT_ViewWindow*> views = aViewManager->getViews();
       for ( int iV = 0; iV < views.count(); ++iV ) {
         if ( SMESH_Actor* actor = FindActorByEntry( views[iV], theEntry)) {
-          if(SVTK_ViewWindow* vtkWnd = GetVtkViewWindow(views[iV]))
+          if(SVTK_ViewWindow* vtkWnd = GetVtkViewWindow(views[iV])) {
             vtkWnd->RemoveActor(actor);
+            actorRemoved = true;
+          }
           actor->Delete();
         }
       }
+    }
+    
+    if (aViewManager ) {
       int aStudyId = aViewManager->study()->id();
       TVisualObjCont::key_type aKey(aStudyId,theEntry);
       TVisualObjCont::iterator anIter = VISUAL_OBJ_CONT.find(aKey);
@@ -128,6 +148,9 @@ namespace SMESH
       }
       VISUAL_OBJ_CONT.erase(aKey);
     }
+
+    if(actorRemoved)
+      aStudy->setVisibilityState(theEntry, Qtx::HiddenState);
   }
   //================================================================================
   /*!
@@ -350,34 +373,31 @@ namespace SMESH
 
     if ( objModified ) {
       // PAL16631. Mesurements showed that to show aVisualObj in SHADING(default) mode,
-      // ~10 times more memory is used than it occupies.
+      // ~5 times more memory is used than it occupies.
       // Warn the user if there is less free memory than 30 sizes of a grid
       // TODO: estimate memory usage in other modes and take current mode into account
       int freeMB = SMDS_Mesh::CheckMemory(true);
       int usedMB = aVisualObj->GetUnstructuredGrid()->GetActualMemorySize() / 1024;
-      if ( freeMB > 0 && usedMB * 30 > freeMB ) {
-#ifdef _DEBUG_
-        MESSAGE ( "SMESHGUI_VTKUtils::GetVisualObj(), freeMB=" << freeMB
-               << ", usedMB=" << usedMB );
-#endif
-//        bool continu = false;
-//        if ( usedMB * 10 > freeMB )
-//          // even dont try to show
-//          SUIT_MessageBox::warning(SMESHGUI::desktop(), QObject::tr("SMESH_WRN_WARNING"),
-//                                   QObject::tr("SMESH_NO_MESH_VISUALIZATION"));
-//        else
-//          // there is a chance to succeed
-//          continu = SUIT_MessageBox::warning
-//            (SMESHGUI::desktop(),
-//             QObject::tr("SMESH_WRN_WARNING"),
-//             QObject::tr("SMESH_CONTINUE_MESH_VISUALIZATION"),
-//             SUIT_MessageBox::Yes | SUIT_MessageBox::No,
-//             SUIT_MessageBox::Yes ) == SUIT_MessageBox::Yes;
-//        if ( !continu ) {
-//          // remove the corresponding actors from all views
-//          RemoveVisualObjectWithActors( theEntry );
-//          aVisualObj.reset();
-//        }
+      MESSAGE("SMESHGUI_VTKUtils::GetVisualObj(), freeMB=" << freeMB << ", usedMB=" <<usedMB);
+      if ( freeMB > 0 && usedMB * 5 > freeMB ) {
+       bool continu = false;
+       if ( usedMB * 3 > freeMB )
+         // even dont try to show
+         SUIT_MessageBox::warning(SMESHGUI::desktop(), QObject::tr("SMESH_WRN_WARNING"),
+                                  QObject::tr("SMESH_NO_MESH_VISUALIZATION"));
+       else
+         // there is a chance to succeed
+         continu = SUIT_MessageBox::warning
+           (SMESHGUI::desktop(),
+            QObject::tr("SMESH_WRN_WARNING"),
+            QObject::tr("SMESH_CONTINUE_MESH_VISUALIZATION"),
+            SUIT_MessageBox::Yes | SUIT_MessageBox::No,
+            SUIT_MessageBox::Yes ) == SUIT_MessageBox::Yes;
+       if ( !continu ) {
+         // remove the corresponding actors from all views
+         RemoveVisualObjectWithActors( theEntry );
+         aVisualObj.reset();
+       }
       }
     }
 
@@ -588,7 +608,7 @@ namespace SMESH
         }
 
         SMESH::SMESH_GroupBase_var aGroup = SMESH::SMESH_GroupBase::_narrow( SMESH::SObjectToObject( aSObj ));
-        if(!CORBA::is_nil(aGroup))
+        if(!CORBA::is_nil(aGroup) && anActor)
         {
           SALOMEDS::Color aColor = aGroup->GetColor();
           if( !( aColor.R > 0 || aColor.G > 0 || aColor.B > 0 ) )
@@ -686,6 +706,15 @@ namespace SMESH
     if (!aViewWnd)
       return OK;
 
+    SVTK_ViewWindow* vtkWnd = GetVtkViewWindow(theWnd);
+    if (!vtkWnd)
+      return OK;
+
+    SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( vtkWnd->getViewManager()->study() );
+    
+    if (!aStudy)
+      return OK;
+
     {
       OK = true;
       vtkRenderer *aRenderer = aViewWnd->getRenderer();
@@ -699,6 +728,13 @@ namespace SMESH
           if (SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(anAct)) {
                 MESSAGE("--- display " << anActor);
             anActor->SetVisibility(true);
+
+            if(anActor->hasIO()){
+              Handle(SALOME_InteractiveObject) anIO = anActor->getIO();
+              if(anIO->hasEntry()){
+                aStudy->setVisibilityState(anIO->getEntry(), Qtx::ShownState);
+              }
+            }
           }
         }
         break;
@@ -712,6 +748,7 @@ namespace SMESH
             anActor->SetVisibility(false);
           }
         }
+        aStudy->setVisibilityStateForAll(Qtx::HiddenState);
       }
       default: {
         if (SMESH_Actor *anActor = FindActorByEntry(theWnd,theEntry)) {
@@ -719,12 +756,15 @@ namespace SMESH
             case eDisplay:
             case eDisplayOnly:
                 //MESSAGE("--- display " << anActor);
+              anActor->Update();
               anActor->SetVisibility(true);
               if (theAction == eDisplayOnly) aRenderer->ResetCameraClippingRange();
+              aStudy->setVisibilityState(theEntry, Qtx::ShownState);
               break;
             case eErase:
                 //MESSAGE("--- erase " << anActor);
               anActor->SetVisibility(false);
+              aStudy->setVisibilityState(theEntry, Qtx::HiddenState);
               break;
           }
         } else {
@@ -743,6 +783,7 @@ namespace SMESH
                 if ((anActor = CreateActor(aDocument,theEntry,true))) {
                   bool needFitAll = noSmeshActors(theWnd); // fit for the first object only
                   DisplayActor(theWnd,anActor);
+                  aStudy->setVisibilityState(theEntry, Qtx::ShownState);
                   // FitAll(); - PAL16770(Display of a group performs an automatic fit all)
                   if (needFitAll) FitAll();
                 } else {
@@ -1226,7 +1267,7 @@ namespace SMESH
                                                 {theBounds[0],theBounds[3],theBounds[5]}, 
                                                 {theBounds[1],theBounds[3],theBounds[5]}};
 
-    int aMaxId = 0, aMinId = aMaxId;
+    int aMaxId = 0;
     theMaxBoundPrj = vtkMath::Dot(theDirection,aBoundPoints[aMaxId]);
     theMinBoundPrj = theMaxBoundPrj;
     for(int i = 1; i < 8; i++){
@@ -1237,7 +1278,6 @@ namespace SMESH
       }
       if(theMinBoundPrj > aTmp){
         theMinBoundPrj = aTmp;
-        aMinId = i;
       }
     }
     vtkFloatingPointType *aMinPnt = aBoundPoints[aMaxId];