Salome HOME
Merge from V6_main_20120808 08Aug12
[modules/visu.git] / src / VISUGUI / VisuGUI_Displayer.cxx
index 41366ee6b47eee61576d388875d2e550c1f32cd2..52812260d5a760afac2f2a7cd840c3296cd9608e 100644 (file)
@@ -1,24 +1,25 @@
-//  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2012  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
 //
+
 //  VISU VISUGUI : Displayer for VISU module
 //  File   : VisuGUI_Displayer.cxx
 //  Author : Alexander SOLOVYOV
 
 #include "VisuGUI.h"
 #include "VisuGUI_Tools.h"
+#include "VISU_Tools.h"
 #include "VISU_ViewManager_i.hh"
 #include "VISU_Actor.h"
 
+#include <VISU_Table_i.hh>
+
 //#include "VVTK_ViewModel.h"
 
 #include <SVTK_ViewModel.h>
 #include <SUIT_MessageBox.h>
 #include <SUIT_Desktop.h>
 
+
+
+void changeVisibility(int theDisplaying, QString entry, SalomeApp_Study* study)
+{
+  _PTR(SObject) obj = study->studyDS()->FindObjectID( (const char*)entry.toLatin1() );
+  CORBA::Object_var anObj = VISU::ClientSObjectToObject( obj );
+  if( CORBA::is_nil( anObj ) )
+    return;
+
+  if(VISU::Curve_i* aCurve = dynamic_cast<VISU::Curve_i*>( VISU::GetServant( anObj ).in()) ) {
+    VISU::CurveVisibilityChanged(aCurve,theDisplaying, false, true, true);
+  }
+
+  if(VISU::Container_i* aContainer = dynamic_cast<VISU::Container_i*>( VISU::GetServant( anObj ).in()) ) {
+    int nbCurves = aContainer->GetNbCurves();
+    for( int k=1; k<=nbCurves; k++ ) {
+      VISU::Curve_i* aCurve = aContainer->GetCurve( k );
+      if(aCurve)
+       VISU::CurveVisibilityChanged(aCurve,theDisplaying, true, true, true);
+    }
+  }
+
+  if(VISU::Table_i* aTable = dynamic_cast<VISU::Table_i*>( VISU::GetServant( anObj ).in()) ) {
+    _PTR(SObject) TableSO = study->studyDS()->FindObjectID( aTable->GetEntry() );
+    if ( TableSO ) {
+      _PTR(ChildIterator) Iter = study->studyDS()->NewChildIterator( TableSO );
+      
+      for ( ; Iter->More(); Iter->Next() ) {
+       CORBA::Object_var childObject = VISU::ClientSObjectToObject( Iter->Value() );
+       if( !CORBA::is_nil( childObject ) ) {
+         CORBA::Object_ptr aCurve_ptr = VISU::Curve::_narrow( childObject );
+         if( !CORBA::is_nil( aCurve_ptr ) ) {
+           VISU::Curve_i* aCurve = dynamic_cast<VISU::Curve_i*>(VISU::GetServant(aCurve_ptr).in());
+           if(aCurve)
+             VISU::CurveVisibilityChanged(aCurve,theDisplaying, true, false, true);
+         }
+       }
+      }
+    }
+  }
+}
+
+
 VisuGUI_Displayer::VisuGUI_Displayer( SalomeApp_Application* app )
 : LightApp_Displayer(),
   myApp( app )
@@ -58,6 +105,58 @@ VisuGUI_Displayer::~VisuGUI_Displayer()
 {
 }
 
+
+bool VisuGUI_Displayer::IsDisplayed( const QString& id, SALOME_View* vf ) const {
+
+  bool displayed = false;
+  SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( myApp->activeStudy() );
+  if(!aStudy)
+    return displayed;
+  
+  _PTR(SObject) aSObject = aStudy->studyDS()->FindObjectID( (const char*)id.toLatin1() );
+  CORBA::Object_var anObj = VISU::ClientSObjectToObject( aSObject );
+  if( CORBA::is_nil( anObj ) )
+    return LightApp_Displayer::IsDisplayed(id, vf);
+  
+  if(VISU::Container_i* aContainer = dynamic_cast<VISU::Container_i*>( VISU::GetServant( anObj ).in())) {
+    int nbCurves = aContainer->GetNbCurves();
+    for( int k=1; k<=nbCurves; k++ ) {
+      VISU::Curve_i* aCurve = aContainer->GetCurve( k );
+      if(aCurve && LightApp_Displayer::IsDisplayed(aCurve->GetEntry().c_str(), vf)) {
+       displayed = true;
+       break;
+      }
+    }
+    return displayed;
+  } else if( VISU::Table_i* aTable = dynamic_cast<VISU::Table_i*>( VISU::GetServant( anObj ).in()) ) {
+
+    SPlot2d_Viewer* view2D = dynamic_cast<SPlot2d_Viewer*>(vf);
+    if( !view2D )
+      return LightApp_Displayer::IsDisplayed(id, vf);
+    
+    _PTR(SObject) TableSO = aStudy->studyDS()->FindObjectID( (const char*)id.toLatin1() );
+    if( TableSO ) {
+      _PTR(ChildIterator) Iter = aStudy->studyDS()->NewChildIterator( TableSO );
+      for( ; Iter->More(); Iter->Next() ) {
+       CORBA::Object_var childObject = VISU::ClientSObjectToObject( Iter->Value() );
+       if( !CORBA::is_nil( childObject ) ) {
+         CORBA::Object_ptr aCurve = VISU::Curve::_narrow( childObject );
+         if( !CORBA::is_nil( aCurve ) ) {
+           VISU::Curve_i* aCurve_i = dynamic_cast<VISU::Curve_i*>(VISU::GetServant(aCurve).in());
+           if(aCurve && LightApp_Displayer::IsDisplayed(aCurve_i->GetEntry().c_str(), vf)) {
+             displayed = true;
+             break;
+           }       
+         }
+       }
+      }      
+    }
+    return displayed;
+  } else {
+    return LightApp_Displayer::IsDisplayed(id, vf);
+  }
+}
+
 SALOME_Prs* VisuGUI_Displayer::buildPresentation( const QString& theEntry, SALOME_View* theView )
 {
   SALOME_Prs* aPrs = 0;
@@ -84,42 +183,43 @@ SALOME_Prs* VisuGUI_Displayer::buildPresentation( const QString& theEntry, SALOM
       //if (!aViewer)
       //aViewer = dynamic_cast<SVTK_Viewer*>( aView );
       if( aViewer ){
-       SUIT_ViewManager* aViewManager = aViewer->getViewManager();
-       SUIT_ViewWindow* aWindow = aViewManager->getActiveView();
-       if(SVTK_ViewWindow* aViewWindow = dynamic_cast<SVTK_ViewWindow*>( aWindow )){
-         VISU::Prs3d_i* aPrs3d = NULL;
-         if(aType == VISU::TCOLOREDPRS3DHOLDER){
-           VISU::ColoredPrs3dHolder_var aHolder = VISU::ColoredPrs3dHolder::_narrow(aBase);
-           VISU::ColoredPrs3d_var aColoredPrs3d = aHolder->GetDevice();
-           aPrs3d = dynamic_cast<VISU::Prs3d_i*>(VISU::GetServant(aColoredPrs3d).in());
-         }else if (aType == VISU::TPOINTMAP3D) {
-           VISU::PointMap3d_i* aTable3d = dynamic_cast<VISU::PointMap3d_i*>(aBaseServant);
-           VISU_ActorBase* anActorBase = VISU::FindActorBase(aViewWindow, aTable3d);
-           if (anActorBase) {
-             anActorBase->SetVisibility(true);
-             aViewWindow->Repaint();
-           }
-           else {
-             VISU_PointMap3dActor* aPointMap3dActor = aTable3d->CreateActor();
-             if (aPointMap3dActor) {
-               aViewWindow->AddActor(aPointMap3dActor);
-               aPointMap3dActor->SetVisibility(true);
-               aViewWindow->Repaint();
-             }
-           }
-         }
-         else
-           aPrs3d = dynamic_cast<VISU::Prs3d_i*>(aBaseServant);
-
-         if(aPrs3d){
-           buildPrs3d( aViewWindow, aPrs3d );
-           Handle(SALOME_InteractiveObject) anIO = aPrs3d->GetIO();
-           if(anIO->hasEntry()){
-             std::string anEntry = anIO->getEntry();
-             aPrs = LightApp_Displayer::buildPresentation( anEntry.c_str(), aView );
-           }
-         }
-       }
+        SUIT_ViewManager* aViewManager = aViewer->getViewManager();
+        SUIT_ViewWindow* aWindow = aViewManager->getActiveView();
+        if(SVTK_ViewWindow* aViewWindow = dynamic_cast<SVTK_ViewWindow*>( aWindow )){
+          VISU::Prs3d_i* aPrs3d = NULL;
+          if(aType == VISU::TCOLOREDPRS3DHOLDER){
+            VISU::ColoredPrs3dHolder_var aHolder = VISU::ColoredPrs3dHolder::_narrow(aBase);
+            VISU::ColoredPrs3d_var aColoredPrs3d = aHolder->GetDevice();
+            aPrs3d = dynamic_cast<VISU::Prs3d_i*>(VISU::GetServant(aColoredPrs3d).in());
+          }else if (aType == VISU::TPOINTMAP3D) {
+            VISU::PointMap3d_i* aTable3d = dynamic_cast<VISU::PointMap3d_i*>(aBaseServant);
+            VISU_ActorBase* anActorBase = VISU::FindActorBase(aViewWindow, aTable3d);
+            if (anActorBase) {
+              anActorBase->SetVisibility(true);
+              aViewWindow->Repaint();
+            }
+            else {
+              VISU_PointMap3dActor* aPointMap3dActor = aTable3d->CreateActor();
+              if (aPointMap3dActor) {
+                aViewWindow->AddActor(aPointMap3dActor);
+                aPointMap3dActor->SetVisibility(true);
+                aViewWindow->Repaint();
+              }
+            }
+           VISU::SetVisibilityState(qPrintable(theEntry),Qtx::ShownState);
+          }
+          else
+            aPrs3d = dynamic_cast<VISU::Prs3d_i*>(aBaseServant);
+
+          if(aPrs3d){
+            buildPrs3d( aViewWindow, aPrs3d );
+            Handle(SALOME_InteractiveObject) anIO = aPrs3d->GetIO();
+            if(anIO->hasEntry()){
+              std::string anEntry = anIO->getEntry();
+              aPrs = LightApp_Displayer::buildPresentation( anEntry.c_str(), aView );
+            }
+          }
+        }
       }
     }
 
@@ -127,43 +227,43 @@ SALOME_Prs* VisuGUI_Displayer::buildPresentation( const QString& theEntry, SALOM
     if (aView) aViewer = dynamic_cast<SPlot2d_Viewer*>(aView);
     if(!aViewer && (aType==VISU::TCURVE || aType==VISU::TCONTAINER))
       if(VisuGUI* aVisuGUI = dynamic_cast<VisuGUI*>(myApp->activeModule()))
-       aViewer = VISU::GetPlot2dViewer( (SalomeApp_Module*)aVisuGUI, true );
+        aViewer = VISU::GetPlot2dViewer( (SalomeApp_Module*)aVisuGUI, true );
     
     if(aViewer){
       SUIT_ViewManager* aViewManager = aViewer->getViewManager();
       SUIT_ViewWindow* aWindow = aViewManager->getActiveView();
       Plot2d_ViewWindow* aViewWindow = dynamic_cast<Plot2d_ViewWindow*>( aWindow );
       if( !aViewWindow )
-       return 0;
+        return 0;
       
       SPlot2d_Prs* aPlot2dPrs = 0;
       switch (aType) {
       case VISU::TCURVE: {
-       VISU::Curve_i* aCurve = dynamic_cast<VISU::Curve_i*>(aBaseServant);
-       aPlot2dPrs = buildCurve( aViewWindow, aCurve );
-       break;
+        VISU::Curve_i* aCurve = dynamic_cast<VISU::Curve_i*>(aBaseServant);
+        aPlot2dPrs = buildCurve( aViewWindow, aCurve );
+        break;
       }
       case VISU::TCONTAINER: {
-       VISU::Container_i* aContainer = dynamic_cast<VISU::Container_i*>(aBaseServant);
-       aPlot2dPrs = buildContainer( aViewWindow, aContainer );
-       break;
+        VISU::Container_i* aContainer = dynamic_cast<VISU::Container_i*>(aBaseServant);
+        aPlot2dPrs = buildContainer( aViewWindow, aContainer );
+        break;
       }
       case VISU::TPOINTMAP3D: {
-       VISU::Table_i* aTable = dynamic_cast<VISU::Table_i*>(aBaseServant);
-       aPlot2dPrs = buildTable( aViewWindow, aTable );
-       break;
+        VISU::Table_i* aTable = dynamic_cast<VISU::Table_i*>(aBaseServant);
+        aPlot2dPrs = buildTable( aViewWindow, aTable );
+        break;
       }
       case VISU::TTABLE: {
-       VISU::Table_i* aTable = dynamic_cast<VISU::Table_i*>(aBaseServant);
-       aPlot2dPrs = buildTable( aViewWindow, aTable );
-       break;
+        VISU::Table_i* aTable = dynamic_cast<VISU::Table_i*>(aBaseServant);
+        aPlot2dPrs = buildTable( aViewWindow, aTable );
+        break;
       }}
 
       if( aPlot2dPrs )
-       aPrs = new SPlot2d_Prs( aPlot2dPrs );
+        aPrs = new SPlot2d_Prs( aPlot2dPrs );
 
       if( aPrs )
-       UpdatePrs( aPrs );
+        UpdatePrs( aPrs );
     }
   }
   return aPrs;
@@ -236,7 +336,7 @@ SPlot2d_Prs* VisuGUI_Displayer::buildContainer( Plot2d_ViewWindow* wnd, VISU::Co
     if( theCurve && theCurve->IsValid() )
       addCurve( prs, wnd, theCurve );
   }
-  if( prs->getCurves().count()==0 )
+  if( prs->getObjects().count()==0 )
   {
     delete prs;
     prs = 0;
@@ -265,12 +365,12 @@ SPlot2d_Prs* VisuGUI_Displayer::buildTable( Plot2d_ViewWindow* wnd, VISU::Table_
       CORBA::Object_ptr aCurve = VISU::Curve::_narrow( childObject );
       if( !CORBA::is_nil( aCurve ) )
       {
-       VISU::Curve_i* theCurve = dynamic_cast<VISU::Curve_i*>(VISU::GetServant(aCurve).in());
-       addCurve( prs, wnd, theCurve );
+        VISU::Curve_i* theCurve = dynamic_cast<VISU::Curve_i*>(VISU::GetServant(aCurve).in());
+        addCurve( prs, wnd, theCurve );
       }
     }
   }
-  if( prs->getCurves().count()==0 )
+  if( prs->getObjects().count()==0 )
   {
     delete prs;
     prs = 0;
@@ -292,9 +392,10 @@ bool VisuGUI_Displayer::canBeDisplayed( const QString& entry, const QString& vie
   if( study->isComponent( entry ) )
     return true;
 
-  if( dynamic_cast<VISU::Curve_i*>( VISU::GetServant( anObj ).in() )
-      ||
-      dynamic_cast<VISU::Container_i*>( VISU::GetServant( anObj ).in() ) )
+  if( (dynamic_cast<VISU::Curve_i*>( VISU::GetServant( anObj ).in() )
+       ||
+       dynamic_cast<VISU::Container_i*>( VISU::GetServant( anObj ).in() ))
+      && viewer_type==SPlot2d_Viewer::Type())
     return true;
 
   if( viewer_type==SVTK_Viewer::Type() /*|| viewer_type==VVTK_Viewer::Type()*/)
@@ -320,3 +421,11 @@ bool VisuGUI_Displayer::canBeDisplayed( const QString& entry, const QString& vie
   else 
     return false;
 }
+
+void VisuGUI_Displayer::AfterDisplay( SALOME_View* vf, const SALOME_Prs2d* p ) {
+  changeVisibility(VISU::eDisplay, myLastEntry, dynamic_cast<SalomeApp_Study*>( myApp->activeStudy()));
+}
+
+void VisuGUI_Displayer::AfterErase( SALOME_View* vf, const SALOME_Prs2d* p ) {
+  changeVisibility(VISU::eErase, myLastEntry, dynamic_cast<SalomeApp_Study*>( myApp->activeStudy()));
+}