1 // Copyright (C) 2007-2012 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #include "LightApp_Displayer.h"
24 #include "LightApp_Application.h"
25 #include "LightApp_Module.h"
26 #include "LightApp_Study.h"
28 #include <CAM_Study.h>
30 #include <SUIT_Session.h>
31 #include <SUIT_Desktop.h>
32 #include <SUIT_ViewManager.h>
33 #include <SUIT_ViewModel.h>
34 #include <SUIT_ViewWindow.h>
36 #include <QStringList>
38 #ifndef DISABLE_SALOMEOBJECT
39 #include "SALOME_InteractiveObject.hxx"
45 LightApp_Displayer::LightApp_Displayer()
52 LightApp_Displayer::~LightApp_Displayer()
57 Displays object in view
58 \param entry - object entry
59 \param updateViewer - is it necessary to update viewer
60 \param theViewFrame - view
62 void LightApp_Displayer::Display( const QString& entry, const bool updateViewer,
63 SALOME_View* theViewFrame )
66 aList.append( entry );
67 Display( aList, updateViewer, theViewFrame );
71 Displays object in view
72 \param list - object entries
73 \param updateViewer - is it necessary to update viewer
74 \param theViewFrame - view
76 void LightApp_Displayer::Display( const QStringList& list, const bool updateViewer,
77 SALOME_View* theViewFrame )
79 SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
80 QStringList::const_iterator it = list.constBegin();
81 for ( ; it != list.constEnd(); ++it)
83 SALOME_Prs* prs = buildPresentation( *it, vf );
90 vf->BeforeDisplay( this, prs );
92 vf->AfterDisplay( this, prs );
97 delete prs; // delete presentation because displayer is its owner
98 setVisibilityState(*it, Qtx::ShownState);
105 Redisplays object in view
106 \param entry - object entry
107 \param updateViewer - is it necessary to update viewer
109 void LightApp_Displayer::Redisplay( const QString& entry, const bool updateViewer )
111 // Remove the object permanently (<forced> == true)
112 SUIT_Session* ses = SUIT_Session::session();
113 SUIT_Application* app = ses->activeApplication();
116 SUIT_Desktop* desk = app->desktop();
117 QListIterator<SUIT_ViewWindow*> itWnds( desk->windows() );
118 while ( itWnds.hasNext() )
120 SUIT_ViewManager* vman = itWnds.next()->getViewManager();
124 SUIT_ViewModel* vmodel = vman->getViewModel();
128 SALOME_View* view = dynamic_cast<SALOME_View*>(vmodel);
129 if( view && ( IsDisplayed( entry, view ) || view == GetActiveView() ) )
131 Erase( entry, true, false, view );
132 Display( entry, updateViewer, view );
139 Erases object in view
140 \param entry - object entry
141 \param forced - deletes object from viewer (otherwise it will be erased, but cached)
142 \param updateViewer - is it necessary to update viewer
143 \param theViewFrame - view
145 void LightApp_Displayer::Erase( const QString& entry, const bool forced,
146 const bool updateViewer,
147 SALOME_View* theViewFrame )
150 aList.append( entry );
151 Erase( aList, forced, updateViewer, theViewFrame );
155 Erases object in view
156 \param list - object entries
157 \param forced - deletes object from viewer (otherwise it will be erased, but cached)
158 \param updateViewer - is it necessary to update viewer
159 \param theViewFrame - view
161 void LightApp_Displayer::Erase( const QStringList& list, const bool forced,
162 const bool updateViewer,
163 SALOME_View* theViewFrame )
165 SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
170 QStringList::const_iterator it = list.constBegin();
171 for ( ; it != list.constEnd(); ++it)
173 SALOME_Prs* prs = vf->CreatePrs( (*it).toLatin1().data() );
176 vf->BeforeErase( this, prs );
177 vf->Erase( prs, forced );
178 vf->AfterErase( this, prs );
181 delete prs; // delete presentation because displayer is its owner
182 setVisibilityState(*it,Qtx::HiddenState);
188 Erases all objects in view
189 \param forced - deletes objects from viewer
190 \param updateViewer - is it necessary to update viewer
191 \param theViewFrame - view
193 void LightApp_Displayer::EraseAll( const bool forced, const bool updateViewer, SALOME_View* theViewFrame ) const
195 SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
198 vf->EraseAll( forced );
203 LightApp_Application* app = dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() );
204 LightApp_Study* study = app ? dynamic_cast<LightApp_Study*>( app->activeStudy() ) : 0;
206 study->setVisibilityStateForAll(Qtx::HiddenState);
210 \return true if object is displayed in viewer
211 \param entry - object entry
212 \param theViewFrame - view
214 bool LightApp_Displayer::IsDisplayed( const QString& entry, SALOME_View* theViewFrame ) const
216 SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
220 #ifndef DISABLE_SALOMEOBJECT
221 Handle( SALOME_InteractiveObject ) temp = new SALOME_InteractiveObject();
222 temp->setEntry( entry.toLatin1() );
223 res = vf->isVisible( temp );
232 void LightApp_Displayer::UpdateViewer() const
234 SALOME_View* vf = GetActiveView();
240 \return presentation of object, built with help of CreatePrs method
241 \param entry - object entry
242 \param theViewFrame - view
245 SALOME_Prs* LightApp_Displayer::buildPresentation( const QString& entry, SALOME_View* theViewFrame )
249 SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
252 prs = vf->CreatePrs( entry.toLatin1() );
260 SALOME_View* LightApp_Displayer::GetActiveView()
262 SUIT_Session* session = SUIT_Session::session();
263 if ( SUIT_Application* app = session->activeApplication() ) {
264 if ( LightApp_Application* sApp = dynamic_cast<LightApp_Application*>( app ) ) {
265 if( SUIT_ViewManager* vman = sApp->activeViewManager() ) {
266 if ( SUIT_ViewModel* vmod = vman->getViewModel() )
267 return dynamic_cast<SALOME_View*>( vmod );
275 \return true, if object can be displayed in this type of viewer
276 \param entry - object entry
277 \param viewer_type - type of viewer
279 bool LightApp_Displayer::canBeDisplayed( const QString& /*entry*/, const QString& /*viewer_type*/ ) const
285 \return true, if object can be displayed in any type of viewer
286 \param entry - object entry
288 bool LightApp_Displayer::canBeDisplayed( const QString& entry ) const
291 SUIT_Session* session = SUIT_Session::session();
292 if( SUIT_Application* app = session->activeApplication() )
293 if( LightApp_Application* sApp = dynamic_cast<LightApp_Application*>( app ) )
294 if( SUIT_ViewManager* vman = sApp->activeViewManager() )
295 if( SUIT_ViewModel* vmod = vman->getViewModel() )
296 viewerType = vmod->getType();
297 return canBeDisplayed( entry, viewerType );
301 \return displayer, corresponding to module
302 \param mod_name - name of module
303 \param load - is module has to be forced loaded
305 LightApp_Displayer* LightApp_Displayer::FindDisplayer( const QString& mod_name, const bool load )
307 SUIT_Session* session = SUIT_Session::session();
308 SUIT_Application* sapp = session ? session->activeApplication() : 0;
309 LightApp_Application* app = dynamic_cast<LightApp_Application*>( sapp );
313 LightApp_Module* m = dynamic_cast<LightApp_Module*>( app ? app->module( mod_name ) : 0 );
314 bool wasLoaded = false;
317 m = dynamic_cast<LightApp_Module*>( app->loadModule( mod_name, false ) );
326 m->connectToStudy( dynamic_cast<CAM_Study*>( app->activeStudy() ) );
328 m->updateModuleVisibilityState();
330 return m ? m->displayer() : 0;
334 Find the active study and set the 'visibility state' property of the object
335 \param mod_name - name of module
336 \param load - is module has to be forced loaded
338 void LightApp_Displayer::setVisibilityState( const QString& theEntry, Qtx::VisibilityState theState) const {
339 LightApp_Application* app = dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() );
340 LightApp_Study* study = app ? dynamic_cast<LightApp_Study*>( app->activeStudy() ) : 0;
343 study->setVisibilityState( theEntry, theState);