Back to index

salome-gui  6.5.0
LightApp_Displayer.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 #include "LightApp_Displayer.h"
00024 #include "LightApp_Application.h"
00025 #include "LightApp_Module.h"
00026 #include "LightApp_Study.h"
00027 
00028 #include <CAM_Study.h>
00029 
00030 #include <SUIT_Session.h>
00031 #include <SUIT_Desktop.h>
00032 #include <SUIT_ViewManager.h>
00033 #include <SUIT_ViewModel.h>
00034 #include <SUIT_ViewWindow.h>
00035 
00036 #include <QStringList>
00037 #include <QString>
00038 #ifndef DISABLE_SALOMEOBJECT
00039   #include "SALOME_InteractiveObject.hxx"
00040 #endif
00041 
00045 LightApp_Displayer::LightApp_Displayer()
00046 {
00047 }
00048 
00052 LightApp_Displayer::~LightApp_Displayer()
00053 {
00054 }
00055 
00062 void LightApp_Displayer::Display( const QString& entry, const bool updateViewer,
00063                                   SALOME_View* theViewFrame )
00064 {
00065   QStringList aList;
00066   aList.append( entry );
00067   Display( aList, updateViewer, theViewFrame );
00068 }
00069 
00076 void LightApp_Displayer::Display( const QStringList& list, const bool updateViewer,
00077                                   SALOME_View* theViewFrame )
00078 {
00079   SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
00080   QStringList::const_iterator it = list.constBegin();
00081   for ( ; it != list.constEnd(); ++it)
00082   {
00083     SALOME_Prs* prs = buildPresentation( *it, vf );
00084     if ( prs )
00085     {
00086 
00087       if ( vf )
00088       {
00089        myLastEntry = *it;
00090         vf->BeforeDisplay( this, prs );
00091         vf->Display( prs );
00092         vf->AfterDisplay( this, prs );
00093 
00094         if ( updateViewer )
00095           vf->Repaint();
00096       }
00097       delete prs;  // delete presentation because displayer is its owner
00098       setVisibilityState(*it, Qtx::ShownState);
00099     }
00100 
00101   }
00102 }
00103 
00109 void LightApp_Displayer::Redisplay( const QString& entry, const bool updateViewer )
00110 {
00111   // Remove the object permanently (<forced> == true)
00112   SUIT_Session* ses = SUIT_Session::session();
00113   SUIT_Application* app = ses->activeApplication();
00114   if ( app )
00115   {
00116     SUIT_Desktop* desk = app->desktop();
00117     QListIterator<SUIT_ViewWindow*> itWnds( desk->windows() );
00118     while ( itWnds.hasNext() )
00119     {
00120       SUIT_ViewManager* vman = itWnds.next()->getViewManager();
00121       if( !vman )
00122         continue;
00123 
00124       SUIT_ViewModel* vmodel = vman->getViewModel();
00125       if( !vmodel )
00126         continue;
00127         
00128       SALOME_View* view = dynamic_cast<SALOME_View*>(vmodel);
00129       if( view && ( IsDisplayed( entry, view ) || view == GetActiveView() ) )
00130       {
00131         Erase( entry, true, false, view );
00132         Display( entry, updateViewer, view );
00133       }
00134     }
00135   }
00136 }
00137 
00145 void LightApp_Displayer::Erase( const QString& entry, const bool forced,
00146                                 const bool updateViewer,
00147                                 SALOME_View* theViewFrame )
00148 {
00149   QStringList aList;
00150   aList.append( entry );
00151   Erase( aList, forced, updateViewer, theViewFrame );
00152 }
00153 
00161 void LightApp_Displayer::Erase( const QStringList& list, const bool forced,
00162                                 const bool updateViewer,
00163                                 SALOME_View* theViewFrame )
00164 {
00165   SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
00166 
00167   if ( !vf )
00168     return;
00169 
00170   QStringList::const_iterator it = list.constBegin();
00171   for ( ; it != list.constEnd(); ++it)
00172   {
00173     SALOME_Prs* prs = vf->CreatePrs( (*it).toLatin1().data() );
00174     if ( prs ) {
00175       myLastEntry = *it;
00176       vf->BeforeErase( this, prs );
00177       vf->Erase( prs, forced );
00178       vf->AfterErase( this, prs );
00179       if ( updateViewer )
00180         vf->Repaint();
00181       delete prs;  // delete presentation because displayer is its owner
00182       setVisibilityState(*it,Qtx::HiddenState);
00183     }
00184   }
00185 }
00186 
00193 void LightApp_Displayer::EraseAll( const bool forced, const bool updateViewer, SALOME_View* theViewFrame ) const
00194 {
00195   SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
00196 
00197   if ( vf ) {
00198     vf->EraseAll( forced );
00199     if ( updateViewer )
00200       vf->Repaint();
00201   }
00202 
00203   LightApp_Application* app = dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() );
00204   LightApp_Study* study = app ? dynamic_cast<LightApp_Study*>( app->activeStudy() ) : 0;  
00205   if(study)
00206     study->setVisibilityStateForAll(Qtx::HiddenState);
00207 }
00208 
00214 bool LightApp_Displayer::IsDisplayed( const QString& entry, SALOME_View* theViewFrame ) const
00215 {
00216   SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
00217   bool res = false;
00218   if( vf )
00219   {
00220 #ifndef DISABLE_SALOMEOBJECT
00221     Handle( SALOME_InteractiveObject ) temp = new SALOME_InteractiveObject();
00222     temp->setEntry( entry.toLatin1() );
00223     res = vf->isVisible( temp );
00224 #endif
00225   }
00226   return res;
00227 }
00228 
00232 void LightApp_Displayer::UpdateViewer() const
00233 {
00234   SALOME_View* vf = GetActiveView();
00235   if ( vf )
00236     vf->Repaint();
00237 }
00238 
00245 SALOME_Prs* LightApp_Displayer::buildPresentation( const QString& entry, SALOME_View* theViewFrame )
00246 {
00247   SALOME_Prs* prs = 0;
00248 
00249   SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
00250 
00251   if ( vf )
00252     prs = vf->CreatePrs( entry.toLatin1() );
00253 
00254   return prs;
00255 }
00256 
00260 SALOME_View* LightApp_Displayer::GetActiveView()
00261 {
00262   SUIT_Session* session = SUIT_Session::session();
00263   if (  SUIT_Application* app = session->activeApplication() ) {
00264     if ( LightApp_Application* sApp = dynamic_cast<LightApp_Application*>( app ) ) {
00265       if( SUIT_ViewManager* vman = sApp->activeViewManager() ) {
00266         if ( SUIT_ViewModel* vmod = vman->getViewModel() )
00267           return dynamic_cast<SALOME_View*>( vmod );
00268       }
00269     }
00270   }
00271   return 0;
00272 }
00273 
00279 bool LightApp_Displayer::canBeDisplayed( const QString& /*entry*/, const QString& /*viewer_type*/ ) const
00280 {
00281   return true;
00282 }
00283 
00288 bool LightApp_Displayer::canBeDisplayed( const QString& entry ) const
00289 {
00290   QString viewerType;
00291   SUIT_Session* session = SUIT_Session::session();
00292   if(  SUIT_Application* app = session->activeApplication() )
00293     if( LightApp_Application* sApp = dynamic_cast<LightApp_Application*>( app ) )
00294       if( SUIT_ViewManager* vman = sApp->activeViewManager() )
00295         if( SUIT_ViewModel* vmod = vman->getViewModel() )
00296           viewerType = vmod->getType();
00297   return canBeDisplayed( entry, viewerType );
00298 }
00299 
00305 LightApp_Displayer* LightApp_Displayer::FindDisplayer( const QString& mod_name, const bool load )
00306 {
00307   SUIT_Session* session = SUIT_Session::session();
00308   SUIT_Application* sapp = session ? session->activeApplication() : 0;
00309   LightApp_Application* app = dynamic_cast<LightApp_Application*>( sapp );
00310   if( !app )
00311     return 0;
00312 
00313   LightApp_Module* m = dynamic_cast<LightApp_Module*>( app ? app->module( mod_name ) : 0 );
00314   bool wasLoaded = false;
00315   if( !m && load )
00316   {
00317     m = dynamic_cast<LightApp_Module*>( app->loadModule( mod_name, false ) );
00318        if( m ) {
00319       app->addModule( m );
00320          wasLoaded = true;
00321        }
00322   }
00323 
00324   if( m )
00325   {
00326     m->connectToStudy( dynamic_cast<CAM_Study*>( app->activeStudy() ) );
00327        if( wasLoaded ) 
00328               m->updateModuleVisibilityState();
00329   }
00330   return m ? m->displayer() : 0;
00331 }
00332 
00338 void LightApp_Displayer::setVisibilityState( const QString& theEntry, Qtx::VisibilityState theState) const {
00339   LightApp_Application* app = dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() );
00340   LightApp_Study* study = app ? dynamic_cast<LightApp_Study*>( app->activeStudy() ) : 0;
00341   
00342   if(study)
00343     study->setVisibilityState( theEntry, theState);
00344 }