Salome HOME
Additional fix for the issue "20937: EDF 1399 GEOM: extend the properties of GEOM...
[modules/geom.git] / src / GEOMGUI / GEOM_Displayer.cxx
index af7b1e54bb1333767336060715d9bf9277f104da..1f3a7e09a93421187ee93166890cbe0de4a285d3 100644 (file)
 #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>
 
@@ -343,9 +345,9 @@ void GEOM_Displayer::Display( const Handle(SALOME_InteractiveObject)& theIO,
 
     if ( prs )
     {
-      vf->BeforeDisplay( this );
+      vf->BeforeDisplay( this, prs );
       vf->Display( prs );
-      vf->AfterDisplay( this );
+      vf->AfterDisplay( this, prs );
 
       if ( updateViewer )
         vf->Repaint();
@@ -399,7 +401,9 @@ void GEOM_Displayer::Erase( const Handle(SALOME_InteractiveObject)& theIO,
   if ( vf ) {
     SALOME_Prs* prs = vf->CreatePrs( theIO->getEntry() );
     if ( prs ) {
+      vf->BeforeErase( this, prs );
       vf->Erase( prs, forced );
+      vf->AfterErase( this, prs );
       if ( updateViewer )
         vf->Repaint();
       delete prs;  // delete presentation because displayer is its owner
@@ -662,7 +666,7 @@ void GEOM_Displayer::Update( SALOME_OCCPrs* prs )
          QStringList uv =  anIsos.split(DIGIT_SEPARATOR);
          anUIsoNumber = uv[0].toInt();
          aVIsoNumber = uv[1].toInt();
-         AISShape->SetTransparency(aPropMap.value(TRANSPARENCY_PROP).toDouble());
+         //AISShape->SetTransparency(aPropMap.value(TRANSPARENCY_PROP).toDouble());
        } else {
          anUIsoNumber = aResMgr->integerValue("OCCViewer", "iso_number_u", 1);
          aVIsoNumber  = aResMgr->integerValue("OCCViewer", "iso_number_v", 1);
@@ -1429,7 +1433,7 @@ void GEOM_Displayer::LocalSelection( const SALOME_ListIO& theIOList, const int t
  *  [ Reimplemented from SALOME_Displayer ]
  */
 //=================================================================
-void GEOM_Displayer::BeforeDisplay( SALOME_View* v, const SALOME_OCCViewType& )
+void GEOM_Displayer::BeforeDisplay( SALOME_View* v, const SALOME_OCCPrs* )
 {
   SOCC_Viewer* vf = dynamic_cast<SOCC_Viewer*>( v );
   if ( vf )
@@ -1443,11 +1447,34 @@ void GEOM_Displayer::BeforeDisplay( SALOME_View* v, const SALOME_OCCViewType& )
   }
 }
 
-void GEOM_Displayer::AfterDisplay( SALOME_View*, const SALOME_OCCViewType& )
+void GEOM_Displayer::AfterDisplay( SALOME_View* v, const SALOME_OCCPrs* p )
 {
+  SalomeApp_Study* aStudy = getStudy();
+  if (!aStudy) return;
+  SOCC_Viewer* vf = dynamic_cast<SOCC_Viewer*>( v );
+  if ( vf && !p->IsNull() ) {
+    int aMgrId = getViewManagerId( vf );
+    Handle(AIS_InteractiveContext) ic = vf->getAISContext();
+    const SOCC_Prs* prs = dynamic_cast<const SOCC_Prs*>( p );
+    if ( !ic.IsNull() && prs ) {
+      AIS_ListOfInteractive objects;
+      prs->GetObjects( objects );
+      AIS_ListIteratorOfListOfInteractive it( objects );
+      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();
+       if ( IO.IsNull() ) continue;
+       PropMap aPropMap = aStudy->getObjectPropMap( aMgrId, IO->getEntry() );
+       if ( aPropMap.contains( TRANSPARENCY_PROP ) ) {
+         double transparency = aPropMap.value(TRANSPARENCY_PROP).toDouble();
+         ic->SetTransparency( sh, transparency, true );
+       }
+      }
+    }
+  }
 }
 
-
 //=================================================================
 /*!
  *  GEOM_Displayer::SetColor
@@ -1791,3 +1818,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();
+  }
+}