Salome HOME
Fix for Bug IPAL8945
[modules/visu.git] / src / VISUGUI / VisuGUI_Displayer.cxx
index 09c43537ae75d80a194817bf0602238b5a68c661..1fa6f098984eb6b1e560bf44fc517dd634a0beea 100644 (file)
@@ -27,6 +27,7 @@
 //  $Header: /home/server/cvs/VISU/VISU_SRC/src/VISUGUI/VisuGUI_Displayer.cxx
 
 #include "VisuGUI_Displayer.h"
+#include "VVTK_ViewModel.h"
 #include "VisuGUI_Tools.h"
 #include "VISU_Actor.h"
 
 #include <SPlot2d_Prs.h>
 #include <Plot2d_ViewWindow.h>
 
+#include <SalomeApp_Application.h>
 #include <SalomeApp_Study.h>
 
 #include "VISU_ViewManager_i.hh"
 
-VisuGUI_Displayer::VisuGUI_Displayer( SalomeApp_Study* st )
+VisuGUI_Displayer::VisuGUI_Displayer( SalomeApp_Application* app )
 : LightApp_Displayer(),
-  myStudy( st )
+  myApp( app )
 {
 }
 
@@ -56,17 +58,20 @@ SALOME_Prs* VisuGUI_Displayer::buildPresentation( const QString& entry, SALOME_V
   SALOME_Prs* prs = 0;
 
   SALOME_View* aViewFrame = theViewFrame ? theViewFrame : GetActiveView();
+  SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( myApp->activeStudy() );
 
-  if ( myStudy && aViewFrame )
+  if ( study && aViewFrame )
   {
-    CORBA::Object_var anObj = VISU::ClientSObjectToObject( myStudy->studyDS()->FindObjectID( entry.latin1() ) );
+    _PTR(SObject) obj = study->studyDS()->FindObjectID( entry.latin1() );
+    CORBA::Object_var anObj = VISU::ClientSObjectToObject( obj );
     if( CORBA::is_nil( anObj ) )
       return 0;
 
     SVTK_Viewer* vtk_viewer = dynamic_cast<SVTK_Viewer*>( aViewFrame );
     if( vtk_viewer )
     {
-      SVTK_ViewWindow* wnd = dynamic_cast<SVTK_ViewWindow*>( vtk_viewer->getViewManager()->getActiveView() );
+      SVTK_ViewWindow* wnd =
+        dynamic_cast<SVTK_ViewWindow*>( vtk_viewer->getViewManager()->getActiveView() );
       if( wnd )
       {
        VISU::Prs3d_i* thePrs = dynamic_cast<VISU::Prs3d_i*>( VISU::GetServant( anObj ).in() );
@@ -81,7 +86,8 @@ SALOME_Prs* VisuGUI_Displayer::buildPresentation( const QString& entry, SALOME_V
     SPlot2d_Viewer* plot_viewer = dynamic_cast<SPlot2d_Viewer*>( aViewFrame );
     if( plot_viewer )
     {
-      Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>( plot_viewer->getViewManager()->getActiveView() );
+      Plot2d_ViewWindow* wnd =
+        dynamic_cast<Plot2d_ViewWindow*>( plot_viewer->getViewManager()->getActiveView() );
       if( !wnd )
        return 0;
 
@@ -113,11 +119,9 @@ void VisuGUI_Displayer::buildPrs3d( SVTK_ViewWindow* wnd, VISU::Prs3d_i* thePrs
   VISU_Actor* newAct = VISU::FindActor( wnd, thePrs );
   if( !newAct )
   {
-    VISU_Actor* a = thePrs->CreateActor();
-    if( a )
-      newAct = a->GetParent();
+    newAct = thePrs->CreateActor();
   }
-  if( newAct && newAct )
+  if( newAct )
   {
     wnd->AddActor( newAct );
     wnd->Repaint();
@@ -179,12 +183,16 @@ SPlot2d_Prs* VisuGUI_Displayer::buildContainer( Plot2d_ViewWindow* wnd, VISU::Co
 SPlot2d_Prs* VisuGUI_Displayer::buildTable( Plot2d_ViewWindow* wnd, VISU::Table_i* t ) const
 {
   SPlot2d_Prs* prs = new SPlot2d_Prs();
-  _PTR(SObject) TableSO = myStudy->studyDS()->FindObjectID( t->GetEntry().latin1() );
+  SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( myApp->activeStudy() );
+  if( !study )
+    return prs;
+
+  _PTR(SObject) TableSO = study->studyDS()->FindObjectID( t->GetEntry().latin1() );
 
   if( !TableSO )
     return prs;
 
-  _PTR(ChildIterator) Iter = myStudy->studyDS()->NewChildIterator( TableSO );
+  _PTR(ChildIterator) Iter = study->studyDS()->NewChildIterator( TableSO );
   for( ; Iter->More(); Iter->Next() )
   {
     CORBA::Object_var childObject = VISU::ClientSObjectToObject( Iter->Value() );
@@ -205,3 +213,33 @@ SPlot2d_Prs* VisuGUI_Displayer::buildTable( Plot2d_ViewWindow* wnd, VISU::Table_
   }
   return prs;
 }
+
+bool VisuGUI_Displayer::canBeDisplayed( const QString& entry, const QString& viewer_type ) const
+{
+  SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( myApp->activeStudy() );
+  if( !study )
+    return false;
+
+  _PTR(SObject) obj = study->studyDS()->FindObjectID( entry.latin1() );
+  CORBA::Object_var anObj = VISU::ClientSObjectToObject( obj );
+  if( CORBA::is_nil( anObj ) )
+    return false;
+
+  if( study->isComponent( entry ) )
+    return true;
+
+  if( viewer_type==SVTK_Viewer::Type() || viewer_type==VVTK_Viewer::Type())
+  {
+    VISU::Prs3d_i* thePrs = dynamic_cast<VISU::Prs3d_i*>( VISU::GetServant( anObj ).in() );
+    return thePrs;
+  }
+  else if( viewer_type==SPlot2d_Viewer::Type() )
+  {
+    VISU::Curve_i* aCurve = dynamic_cast<VISU::Curve_i*>( VISU::GetServant( anObj ).in() );
+    VISU::Container_i* aCont = dynamic_cast<VISU::Container_i*>( VISU::GetServant( anObj ).in() );
+    VISU::Table_i* aTable = dynamic_cast<VISU::Table_i*>(VISU::GetServant( anObj ).in() );
+    return aCurve || aCont || aTable;
+  }
+  else 
+    return false;
+}