Salome HOME
Merge from V6_3_BR 06/06/2011
[modules/geom.git] / src / GEOMGUI / GEOM_Displayer.cxx
index 063cb70af9febf34309832cb9d4e429e4767bf7b..0746d67c4c19e754e1311db4fd4652ace649aca3 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
 //
 
 // GEOM GEOMGUI : GUI for Geometry component
 #include <SUIT_ViewManager.h>
 #include <SUIT_ResourceMgr.h>
 
+
 #include <SalomeApp_Study.h>
 #include <SalomeApp_Application.h>
 #include <LightApp_SelectionMgr.h>
+#include <LightApp_DataObject.h>
 #include <SalomeApp_TypeFilter.h>
 #include <SalomeApp_Tools.h>
 
@@ -137,7 +139,7 @@ static inline int getTopAbsMode( const int implType )
   }
 }
 
-static int getMinMaxShapeType( const TopoDS_Shape& shape, bool ismin )
+int GEOM_Displayer::getMinMaxShapeType( const TopoDS_Shape& shape, bool ismin )
 {
   if ( shape.IsNull() )
     return TopAbs_SHAPE;
@@ -161,7 +163,7 @@ static int getMinMaxShapeType( const TopoDS_Shape& shape, bool ismin )
   return ret;
 }
 
-static bool isCompoundOfVertices( const TopoDS_Shape& theShape )
+bool GEOM_Displayer::isCompoundOfVertices( const TopoDS_Shape& theShape )
 {
   return theShape.ShapeType() == TopAbs_COMPOUND && getMinMaxShapeType( theShape, false ) == TopAbs_VERTEX;
 }
@@ -613,11 +615,8 @@ void GEOM_Displayer::Update( SALOME_OCCPrs* prs )
        
        if(useStudy){
          aPropMap = aStudy->getObjectPropMap(aMgrId,anEntry);
-         aDefPropMap = getDefaultPropepryMap(SOCC_Viewer::Type());
-         bool isDiff = MergePropertyMaps(aPropMap, aDefPropMap);
-                    
-         if(isDiff)
-           aStudy->setObjectPropMap(aMgrId,anEntry,aPropMap);
+         aDefPropMap = getDefaultPropertyMap(SOCC_Viewer::Type());
+         MergePropertyMaps(aPropMap, aDefPropMap);
        }
 
         //Handle(GEOM_AISShape) AISShape = new GEOM_AISShape( myShape, "" );
@@ -982,7 +981,7 @@ void GEOM_Displayer::Update( SALOME_VTKPrs* prs )
     theActors->AddItem( aTrh );
   }
   else {
-    PropMap aDefPropMap = getDefaultPropepryMap(SVTK_Viewer::Type());
+    PropMap aDefPropMap = getDefaultPropertyMap(SVTK_Viewer::Type());
 
     QString anEntry;
     if(!myIO.IsNull()) {
@@ -998,11 +997,9 @@ void GEOM_Displayer::Update( SALOME_VTKPrs* prs )
     theActors->AddItem(aGeomActor);
     aGeomActor->Delete();
     
-    if(useStudy){
+    if(useStudy) {
       aPropMap = aStudy->getObjectPropMap(aMgrId,anEntry);
-      bool isDiff = MergePropertyMaps(aPropMap, aDefPropMap);
-      if(isDiff)
-       aStudy->setObjectPropMap(aMgrId,anEntry,aPropMap);
+      MergePropertyMaps(aPropMap, aDefPropMap);
     }
   }
 
@@ -1458,7 +1455,7 @@ void GEOM_Displayer::AfterDisplay( SALOME_View* v, const SALOME_OCCPrs* p )
       AIS_ListOfInteractive objects;
       prs->GetObjects( objects );
       AIS_ListIteratorOfListOfInteractive it( objects );
-      while( it.More() ) {
+      for ( ; it.More(); it.Next() ) {
         Handle(GEOM_AISShape) sh = Handle(GEOM_AISShape)::DownCast( it.Value() );
        if ( sh.IsNull() ) continue;
        Handle(SALOME_InteractiveObject) IO = sh->getIO();
@@ -1467,7 +1464,6 @@ void GEOM_Displayer::AfterDisplay( SALOME_View* v, const SALOME_OCCPrs* p )
        if ( aPropMap.contains( TRANSPARENCY_PROP ) ) {
          double transparency = aPropMap.value(TRANSPARENCY_PROP).toDouble();
          ic->SetTransparency( sh, transparency, true );
-         it.Next();
        }
       }
     }
@@ -1688,7 +1684,7 @@ SALOMEDS::Color GEOM_Displayer::getUniqueColor( const QList<SALOMEDS::Color>& th
 
 
 
-PropMap GEOM_Displayer::getDefaultPropepryMap(const QString& viewer_type){
+PropMap GEOM_Displayer::getDefaultPropertyMap(const QString& viewer_type) {
   PropMap aDefaultMap;
   SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();    
   //1. Visibility 
@@ -1817,3 +1813,56 @@ SALOMEDS::Color GEOM_Displayer::getColor(GEOM::GEOM_Object_var theGeomObject, bo
   }
   return aSColor;
 }
+
+
+void GEOM_Displayer::EraseWithChildren(const Handle(SALOME_InteractiveObject)& theIO,
+                                      const bool eraseOnlyChildren) {
+  SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
+  if ( !app )
+    return;
+
+  SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
+  if ( !appStudy )
+    return;
+
+  LightApp_DataObject* parent = appStudy->findObjectByEntry(theIO->getEntry());
+  
+  if( !parent)
+    return;
+
+  // Erase from all views
+  QList<SALOME_View*> views;
+  SALOME_View* view;
+  ViewManagerList vmans = app->viewManagers();
+  SUIT_ViewManager* vman;
+  foreach ( vman, vmans ) {
+    SUIT_ViewModel* vmod = vman->getViewModel();
+    view = dynamic_cast<SALOME_View*> ( vmod );
+    if ( view ) 
+      views.append( view );
+  }
+  
+  if( views.count() == 0 )
+    return;
+  
+  //Erase childrens w/o update views
+  DataObjectList listObj = parent->children( true );
+  SUIT_DataObject* obj;
+  foreach( obj, listObj ) {
+    LightApp_DataObject* l_obj = dynamic_cast<LightApp_DataObject*>(obj);
+    if(l_obj)
+      foreach ( view, views ) {
+      Handle(SALOME_InteractiveObject) anIO = 
+       new SALOME_InteractiveObject(qPrintable(l_obj->entry()), "GEOM", "");
+      Erase(anIO, false, false, view);
+    }
+  }
+  
+  //Erase parent with view update or repaint views
+  foreach ( view, views ) {
+    if(!eraseOnlyChildren)
+      Erase(theIO, false, true, view);
+    else
+      view->Repaint();
+  }
+}