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 "LightApp_Displayer.h"
21 #include "LightApp_Application.h"
22 #include "LightApp_Module.h"
24 #include <CAM_Study.h>
26 #include <SUIT_Session.h>
27 #include <SUIT_Desktop.h>
28 #include <SUIT_ViewManager.h>
29 #include <SUIT_ViewModel.h>
30 #include <SUIT_ViewWindow.h>
33 #ifndef DISABLE_SALOMEOBJECT
34 #include "SALOME_InteractiveObject.hxx"
37 LightApp_Displayer::LightApp_Displayer()
41 LightApp_Displayer::~LightApp_Displayer()
45 void LightApp_Displayer::Display( const QString& entry, const bool updateViewer, SALOME_View* theViewFrame )
47 SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
50 SALOME_Prs* prs = buildPresentation( entry, vf );
54 vf->BeforeDisplay( this );
56 vf->AfterDisplay( this );
61 delete prs; // delete presentation because displayer is its owner
66 void LightApp_Displayer::Redisplay( const QString& entry, const bool updateViewer )
68 // Remove the object permanently (<forced> == true)
69 SUIT_Session* ses = SUIT_Session::session();
70 SUIT_Application* app = ses->activeApplication();
73 SUIT_Desktop* desk = app->desktop();
74 QPtrList<SUIT_ViewWindow> wnds = desk->windows();
76 for ( wnd = wnds.first(); wnd; wnd = wnds.next() )
78 SUIT_ViewManager* vman = wnd->getViewManager();
82 SUIT_ViewModel* vmodel = vman->getViewModel();
86 SALOME_View* view = dynamic_cast<SALOME_View*>(vmodel);
87 if( view && ( IsDisplayed( entry, view ) || view == GetActiveView() ) )
89 Erase( entry, true, false, view );
90 Display( entry, updateViewer, view );
96 void LightApp_Displayer::Erase( const QString& entry, const bool forced,
97 const bool updateViewer, SALOME_View* theViewFrame )
99 SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
102 SALOME_Prs* prs = vf->CreatePrs( entry.latin1() );
104 vf->Erase( prs, forced );
107 delete prs; // delete presentation because displayer is its owner
112 void LightApp_Displayer::EraseAll( const bool forced, const bool updateViewer, SALOME_View* theViewFrame ) const
114 SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
117 vf->EraseAll( forced );
123 bool LightApp_Displayer::IsDisplayed( const QString& entry, SALOME_View* theViewFrame ) const
125 SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
129 #ifndef DISABLE_SALOMEOBJECT
130 Handle( SALOME_InteractiveObject ) temp = new SALOME_InteractiveObject();
131 temp->setEntry( entry.latin1() );
132 res = vf->isVisible( temp );
138 void LightApp_Displayer::UpdateViewer() const
140 SALOME_View* vf = GetActiveView();
145 SALOME_Prs* LightApp_Displayer::buildPresentation( const QString& entry, SALOME_View* theViewFrame )
149 SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
152 prs = vf->CreatePrs( entry.latin1() );
157 SALOME_View* LightApp_Displayer::GetActiveView()
159 SUIT_Session* session = SUIT_Session::session();
160 if ( SUIT_Application* app = session->activeApplication() ) {
161 if ( LightApp_Application* sApp = dynamic_cast<LightApp_Application*>( app ) ) {
162 if( SUIT_ViewManager* vman = sApp->activeViewManager() ) {
163 if ( SUIT_ViewModel* vmod = vman->getViewModel() )
164 return dynamic_cast<SALOME_View*>( vmod );
171 bool LightApp_Displayer::canBeDisplayed( const QString&, const QString& ) const
176 bool LightApp_Displayer::canBeDisplayed( const QString& entry ) const
179 SUIT_Session* session = SUIT_Session::session();
180 if( SUIT_Application* app = session->activeApplication() )
181 if( LightApp_Application* sApp = dynamic_cast<LightApp_Application*>( app ) )
182 if( SUIT_ViewManager* vman = sApp->activeViewManager() )
183 if( SUIT_ViewModel* vmod = vman->getViewModel() )
184 viewerType = vmod->getType();
185 return !viewerType.isNull() && canBeDisplayed( entry, viewerType );
188 LightApp_Displayer* LightApp_Displayer::FindDisplayer( const QString& mod_name, const bool load )
190 SUIT_Session* session = SUIT_Session::session();
191 SUIT_Application* sapp = session ? session->activeApplication() : 0;
192 LightApp_Application* app = dynamic_cast<LightApp_Application*>( sapp );
196 LightApp_Module* m = dynamic_cast<LightApp_Module*>( app ? app->module( mod_name ) : 0 );
199 m = dynamic_cast<LightApp_Module*>( app->loadModule( mod_name ) );
206 m->connectToStudy( dynamic_cast<CAM_Study*>( app->activeStudy() ) );
207 if( m!=app->activeModule() && load )
209 m->setMenuShown( false );
210 m->setToolShown( false );
213 return m ? m->displayer() : 0;