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"
40 LightApp_Displayer::LightApp_Displayer()
47 LightApp_Displayer::~LightApp_Displayer()
52 Displays object in view
53 \param entry - object entry
54 \param updateViewer - is it necessary to update viewer
55 \param theViewFrame - view
57 void LightApp_Displayer::Display( const QString& entry, const bool updateViewer, SALOME_View* theViewFrame )
59 SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
62 SALOME_Prs* prs = buildPresentation( entry, vf );
66 vf->BeforeDisplay( this );
68 vf->AfterDisplay( this );
73 delete prs; // delete presentation because displayer is its owner
79 Redisplays object in view
80 \param entry - object entry
81 \param updateViewer - is it necessary to update viewer
83 void LightApp_Displayer::Redisplay( const QString& entry, const bool updateViewer )
85 // Remove the object permanently (<forced> == true)
86 SUIT_Session* ses = SUIT_Session::session();
87 SUIT_Application* app = ses->activeApplication();
90 SUIT_Desktop* desk = app->desktop();
91 QPtrList<SUIT_ViewWindow> wnds = desk->windows();
93 for ( wnd = wnds.first(); wnd; wnd = wnds.next() )
95 SUIT_ViewManager* vman = wnd->getViewManager();
99 SUIT_ViewModel* vmodel = vman->getViewModel();
103 SALOME_View* view = dynamic_cast<SALOME_View*>(vmodel);
104 if( view && ( IsDisplayed( entry, view ) || view == GetActiveView() ) )
106 Erase( entry, true, false, view );
107 Display( entry, updateViewer, view );
114 Erases object in view
115 \param entry - object entry
116 \param forced - deletes object from viewer (otherwise it will be erased, but cached)
117 \param updateViewer - is it necessary to update viewer
118 \param theViewFrame - view
120 void LightApp_Displayer::Erase( const QString& entry, const bool forced,
121 const bool updateViewer, SALOME_View* theViewFrame )
123 SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
126 SALOME_Prs* prs = vf->CreatePrs( entry.latin1() );
128 vf->Erase( prs, forced );
131 delete prs; // delete presentation because displayer is its owner
137 Erases all objects in view
138 \param forced - deletes objects from viewer
139 \param updateViewer - is it necessary to update viewer
140 \param theViewFrame - view
142 void LightApp_Displayer::EraseAll( const bool forced, const bool updateViewer, SALOME_View* theViewFrame ) const
144 SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
147 vf->EraseAll( forced );
154 \return true if object is displayed in viewer
155 \param entry - object entry
156 \param theViewFrame - view
158 bool LightApp_Displayer::IsDisplayed( const QString& entry, SALOME_View* theViewFrame ) const
160 SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
164 #ifndef DISABLE_SALOMEOBJECT
165 Handle( SALOME_InteractiveObject ) temp = new SALOME_InteractiveObject();
166 temp->setEntry( entry.latin1() );
167 res = vf->isVisible( temp );
176 void LightApp_Displayer::UpdateViewer() const
178 SALOME_View* vf = GetActiveView();
184 \return presentation of object, built with help of CreatePrs method
185 \param entry - object entry
186 \param theViewFrame - view
189 SALOME_Prs* LightApp_Displayer::buildPresentation( const QString& entry, SALOME_View* theViewFrame )
193 SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
196 prs = vf->CreatePrs( entry.latin1() );
204 SALOME_View* LightApp_Displayer::GetActiveView()
206 SUIT_Session* session = SUIT_Session::session();
207 if ( SUIT_Application* app = session->activeApplication() ) {
208 if ( LightApp_Application* sApp = dynamic_cast<LightApp_Application*>( app ) ) {
209 if( SUIT_ViewManager* vman = sApp->activeViewManager() ) {
210 if ( SUIT_ViewModel* vmod = vman->getViewModel() )
211 return dynamic_cast<SALOME_View*>( vmod );
219 \return true, if object can be displayed in this type of viewer
220 \param entry - object entry
221 \param viewer_type - type of viewer
223 bool LightApp_Displayer::canBeDisplayed( const QString& /*entry*/, const QString& /*viewer_type*/ ) const
229 \return true, if object can be displayed in any type of viewer
230 \param entry - object entry
232 bool LightApp_Displayer::canBeDisplayed( const QString& entry ) const
235 SUIT_Session* session = SUIT_Session::session();
236 if( SUIT_Application* app = session->activeApplication() )
237 if( LightApp_Application* sApp = dynamic_cast<LightApp_Application*>( app ) )
238 if( SUIT_ViewManager* vman = sApp->activeViewManager() )
239 if( SUIT_ViewModel* vmod = vman->getViewModel() )
240 viewerType = vmod->getType();
241 return !viewerType.isNull() && canBeDisplayed( entry, viewerType );
245 \return displayer, corresponding to module
246 \param mod_name - name of module
247 \param load - is module has to be forced loaded
249 LightApp_Displayer* LightApp_Displayer::FindDisplayer( const QString& mod_name, const bool load )
251 SUIT_Session* session = SUIT_Session::session();
252 SUIT_Application* sapp = session ? session->activeApplication() : 0;
253 LightApp_Application* app = dynamic_cast<LightApp_Application*>( sapp );
257 LightApp_Module* m = dynamic_cast<LightApp_Module*>( app ? app->module( mod_name ) : 0 );
260 m = dynamic_cast<LightApp_Module*>( app->loadModule( mod_name ) );
267 m->connectToStudy( dynamic_cast<CAM_Study*>( app->activeStudy() ) );
268 if( m!=app->activeModule() && load )
270 m->setMenuShown( false );
271 m->setToolShown( false );
274 return m ? m->displayer() : 0;