1 // Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/
20 #include "SalomeApp_Displayer.h"
21 #include "SalomeApp_Application.h"
23 #include <SALOME_InteractiveObject.hxx>
25 #include <SUIT_Session.h>
26 #include <SUIT_Desktop.h>
27 #include <SUIT_ViewManager.h>
28 #include <SUIT_ViewModel.h>
29 #include <SUIT_ViewWindow.h>
33 SalomeApp_Displayer::SalomeApp_Displayer()
37 SalomeApp_Displayer::~SalomeApp_Displayer()
41 void SalomeApp_Displayer::Display( const QString& entry, const bool updateViewer, SALOME_View* theViewFrame )
43 SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
46 SALOME_Prs* prs = buildPresentation( entry, vf );
50 vf->BeforeDisplay( this );
52 vf->AfterDisplay( this );
57 delete prs; // delete presentation because displayer is its owner
62 void SalomeApp_Displayer::Redisplay( const QString& entry, const bool updateViewer )
64 // Remove the object permanently (<forced> == true)
65 SUIT_Session* ses = SUIT_Session::session();
66 SUIT_Application* app = ses->activeApplication();
69 SUIT_Desktop* desk = app->desktop();
70 QPtrList<SUIT_ViewWindow> wnds = desk->windows();
72 for ( wnd = wnds.first(); wnd; wnd = wnds.next() )
74 SUIT_ViewManager* vman = wnd->getViewManager();
78 SUIT_ViewModel* vmodel = vman->getViewModel();
82 SALOME_View* view = dynamic_cast<SALOME_View*>(vmodel);
83 if( view && ( IsDisplayed( entry, view ) || view == GetActiveView() ) )
85 Erase( entry, true, false, view );
86 Display( entry, updateViewer, view );
92 void SalomeApp_Displayer::Erase( const QString& entry, const bool forced,
93 const bool updateViewer, SALOME_View* theViewFrame )
95 SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
98 SALOME_Prs* prs = vf->CreatePrs( entry.latin1() );
100 vf->Erase( prs, forced );
103 delete prs; // delete presentation because displayer is its owner
108 void SalomeApp_Displayer::EraseAll( const bool forced, const bool updateViewer, SALOME_View* theViewFrame ) const
110 SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
113 vf->EraseAll( forced );
119 bool SalomeApp_Displayer::IsDisplayed( const QString& entry, SALOME_View* theViewFrame ) const
121 SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
124 Handle( SALOME_InteractiveObject ) temp = new SALOME_InteractiveObject();
125 temp->setEntry( entry.latin1() );
126 return vf->isVisible( temp );
132 void SalomeApp_Displayer::UpdateViewer() const
134 SALOME_View* vf = GetActiveView();
139 SALOME_Prs* SalomeApp_Displayer::buildPresentation( const QString& entry, SALOME_View* theViewFrame )
143 SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
146 prs = vf->CreatePrs( entry.latin1() );
151 SALOME_View* SalomeApp_Displayer::GetActiveView()
153 SUIT_Session* session = SUIT_Session::session();
154 if ( SUIT_Application* app = session->activeApplication() ) {
155 if ( SalomeApp_Application* sApp = dynamic_cast<SalomeApp_Application*>( app ) ) {
156 if( SUIT_ViewManager* vman = sApp->activeViewManager() ) {
157 if ( SUIT_ViewModel* vmod = vman->getViewModel() )
158 return dynamic_cast<SALOME_View*>( vmod );