2 #include "LightApp_Displayer.h"
3 #include "LightApp_Application.h"
4 #include "LightApp_Module.h"
8 #include <SALOME_InteractiveObject.hxx>
10 #include <SUIT_Session.h>
11 #include <SUIT_Desktop.h>
12 #include <SUIT_ViewManager.h>
13 #include <SUIT_ViewModel.h>
14 #include <SUIT_ViewWindow.h>
18 LightApp_Displayer::LightApp_Displayer()
22 LightApp_Displayer::~LightApp_Displayer()
26 void LightApp_Displayer::Display( const QString& entry, const bool updateViewer, SALOME_View* theViewFrame )
28 SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
31 SALOME_Prs* prs = buildPresentation( entry, vf );
35 vf->BeforeDisplay( this );
37 vf->AfterDisplay( this );
42 delete prs; // delete presentation because displayer is its owner
47 void LightApp_Displayer::Redisplay( const QString& entry, const bool updateViewer )
49 // Remove the object permanently (<forced> == true)
50 SUIT_Session* ses = SUIT_Session::session();
51 SUIT_Application* app = ses->activeApplication();
54 SUIT_Desktop* desk = app->desktop();
55 QPtrList<SUIT_ViewWindow> wnds = desk->windows();
57 for ( wnd = wnds.first(); wnd; wnd = wnds.next() )
59 SUIT_ViewManager* vman = wnd->getViewManager();
63 SUIT_ViewModel* vmodel = vman->getViewModel();
67 SALOME_View* view = dynamic_cast<SALOME_View*>(vmodel);
68 if( view && ( IsDisplayed( entry, view ) || view == GetActiveView() ) )
70 Erase( entry, true, false, view );
71 Display( entry, updateViewer, view );
77 void LightApp_Displayer::Erase( const QString& entry, const bool forced,
78 const bool updateViewer, SALOME_View* theViewFrame )
80 SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
83 SALOME_Prs* prs = vf->CreatePrs( entry.latin1() );
85 vf->Erase( prs, forced );
88 delete prs; // delete presentation because displayer is its owner
93 void LightApp_Displayer::EraseAll( const bool forced, const bool updateViewer, SALOME_View* theViewFrame ) const
95 SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
98 vf->EraseAll( forced );
104 bool LightApp_Displayer::IsDisplayed( const QString& entry, SALOME_View* theViewFrame ) const
106 SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
109 Handle( SALOME_InteractiveObject ) temp = new SALOME_InteractiveObject();
110 temp->setEntry( entry.latin1() );
111 return vf->isVisible( temp );
117 void LightApp_Displayer::UpdateViewer() const
119 SALOME_View* vf = GetActiveView();
124 SALOME_Prs* LightApp_Displayer::buildPresentation( const QString& entry, SALOME_View* theViewFrame )
128 SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
131 prs = vf->CreatePrs( entry.latin1() );
136 SALOME_View* LightApp_Displayer::GetActiveView()
138 SUIT_Session* session = SUIT_Session::session();
139 if ( SUIT_Application* app = session->activeApplication() ) {
140 if ( LightApp_Application* sApp = dynamic_cast<LightApp_Application*>( app ) ) {
141 if( SUIT_ViewManager* vman = sApp->activeViewManager() ) {
142 if ( SUIT_ViewModel* vmod = vman->getViewModel() )
143 return dynamic_cast<SALOME_View*>( vmod );
150 bool LightApp_Displayer::canBeDisplayed( const QString&, const QString& ) const
155 bool LightApp_Displayer::canBeDisplayed( const QString& entry ) const
158 SUIT_Session* session = SUIT_Session::session();
159 if( SUIT_Application* app = session->activeApplication() )
160 if( LightApp_Application* sApp = dynamic_cast<LightApp_Application*>( app ) )
161 if( SUIT_ViewManager* vman = sApp->activeViewManager() )
162 if( SUIT_ViewModel* vmod = vman->getViewModel() )
163 viewerType = vmod->getType();
164 return !viewerType.isNull() && canBeDisplayed( entry, viewerType );
167 LightApp_Displayer* LightApp_Displayer::FindDisplayer( const QString& mod_name, const bool load )
169 SUIT_Session* session = SUIT_Session::session();
170 SUIT_Application* sapp = session ? session->activeApplication() : 0;
171 LightApp_Application* app = dynamic_cast<LightApp_Application*>( sapp );
175 LightApp_Module* m = dynamic_cast<LightApp_Module*>( app ? app->module( mod_name ) : 0 );
178 m = dynamic_cast<LightApp_Module*>( app->loadModule( mod_name ) );
185 m->connectToStudy( dynamic_cast<CAM_Study*>( app->activeStudy() ) );
186 if( m!=app->activeModule() && load )
188 m->setMenuShown( false );
189 m->setToolShown( false );
192 return m ? m->displayer() : 0;