1 // Copyright (C) 2007-2016 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, or (at your option) any later version.
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 );
91 vf->Display( this, prs );
92 vf->AfterDisplay( this, prs );
97 delete prs; // delete presentation because displayer is its owner
98 setVisibilityState(*it, Qtx::ShownState);
104 Redisplays object in view
105 \param entry - object entry
106 \param updateViewer - is it necessary to update viewer
108 void LightApp_Displayer::Redisplay( const QString& entry, const bool updateViewer )
110 // Remove the object permanently (<forced> == true)
111 SUIT_Session* ses = SUIT_Session::session();
112 SUIT_Application* app = ses->activeApplication();
115 SUIT_Desktop* desk = app->desktop();
116 QListIterator<SUIT_ViewWindow*> itWnds( desk->windows() );
117 while ( itWnds.hasNext() )
119 SUIT_ViewManager* vman = itWnds.next()->getViewManager();
123 SUIT_ViewModel* vmodel = vman->getViewModel();
127 SALOME_View* view = dynamic_cast<SALOME_View*>(vmodel);
128 if( view && ( IsDisplayed( entry, view ) || view == GetActiveView() ) )
130 Erase( entry, true, false, view );
131 Display( entry, updateViewer, view );
138 Erases object in view
139 \param entry - object entry
140 \param forced - deletes object from viewer (otherwise it will be erased, but cached)
141 \param updateViewer - is it necessary to update viewer
142 \param theViewFrame - view
144 void LightApp_Displayer::Erase( const QString& entry, const bool forced,
145 const bool updateViewer,
146 SALOME_View* theViewFrame )
149 aList.append( entry );
150 Erase( aList, forced, updateViewer, theViewFrame );
154 Erases object in view
155 \param list - object entries
156 \param forced - deletes object from viewer (otherwise it will be erased, but cached)
157 \param updateViewer - is it necessary to update viewer
158 \param theViewFrame - view
160 void LightApp_Displayer::Erase( const QStringList& list, const bool forced,
161 const bool updateViewer,
162 SALOME_View* theViewFrame )
164 SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
169 QStringList::const_iterator it = list.constBegin();
170 for ( ; it != list.constEnd(); ++it)
172 SALOME_Prs* prs = vf->CreatePrs( (*it).toLatin1().data() );
175 vf->BeforeErase( this, prs );
176 vf->Erase( this, prs, forced );
177 vf->AfterErase( this, prs );
180 delete prs; // delete presentation because displayer is its owner
181 setVisibilityState(*it,Qtx::HiddenState);
187 Erases all objects in view
188 \param forced - deletes objects from viewer
189 \param updateViewer - is it necessary to update viewer
190 \param theViewFrame - view
192 void LightApp_Displayer::EraseAll( const bool forced, const bool updateViewer, SALOME_View* theViewFrame )
194 SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
197 vf->EraseAll( this, forced );
202 LightApp_Application* app = dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() );
203 LightApp_Study* study = app ? dynamic_cast<LightApp_Study*>( app->activeStudy() ) : 0;
205 study->setVisibilityStateForAll(Qtx::HiddenState);
209 \return true if object is displayed in viewer
210 \param entry - object entry
211 \param theViewFrame - view
213 bool LightApp_Displayer::IsDisplayed( const QString& entry, SALOME_View* theViewFrame ) const
215 SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
219 #ifndef DISABLE_SALOMEOBJECT
220 Handle( SALOME_InteractiveObject ) temp = new SALOME_InteractiveObject();
221 temp->setEntry( entry.toLatin1() );
222 res = vf->isVisible( temp );
231 void LightApp_Displayer::UpdateViewer() const
233 SALOME_View* vf = GetActiveView();
239 \return presentation of object, built with help of CreatePrs method
240 \param entry - object entry
241 \param theViewFrame - view
244 SALOME_Prs* LightApp_Displayer::buildPresentation( const QString& entry, SALOME_View* theViewFrame )
248 SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
251 prs = vf->CreatePrs( entry.toLatin1() );
259 SALOME_View* LightApp_Displayer::GetActiveView()
261 SUIT_Session* session = SUIT_Session::session();
262 if ( SUIT_Application* app = session->activeApplication() ) {
263 if ( LightApp_Application* sApp = dynamic_cast<LightApp_Application*>( app ) ) {
264 if( SUIT_ViewManager* vman = sApp->activeViewManager() ) {
265 if ( SUIT_ViewModel* vmod = vman->getViewModel() )
266 return dynamic_cast<SALOME_View*>( vmod );
274 \return true, if object can be displayed in this type of viewer
275 \param entry - object entry
276 \param viewer_type - type of viewer
278 bool LightApp_Displayer::canBeDisplayed( const QString& /*entry*/, const QString& /*viewer_type*/ ) const
284 \return true, if object can be displayed in any type of viewer
285 \param entry - object entry
287 bool LightApp_Displayer::canBeDisplayed( const QString& entry ) const
290 SUIT_Session* session = SUIT_Session::session();
291 if( SUIT_Application* app = session->activeApplication() )
292 if( LightApp_Application* sApp = dynamic_cast<LightApp_Application*>( app ) )
293 if( SUIT_ViewManager* vman = sApp->activeViewManager() )
294 if( SUIT_ViewModel* vmod = vman->getViewModel() )
295 viewerType = vmod->getType();
296 return canBeDisplayed( entry, viewerType );
300 \return displayer, corresponding to module
301 \param mod_name - name of module
302 \param load - is module has to be forced loaded
304 LightApp_Displayer* LightApp_Displayer::FindDisplayer( const QString& mod_name, const bool load )
306 SUIT_Session* session = SUIT_Session::session();
307 SUIT_Application* sapp = session ? session->activeApplication() : 0;
308 LightApp_Application* app = dynamic_cast<LightApp_Application*>( sapp );
312 LightApp_Module* m = dynamic_cast<LightApp_Module*>( app ? app->module( mod_name ) : 0 );
313 bool wasLoaded = false;
316 m = dynamic_cast<LightApp_Module*>( app->loadModule( mod_name, false ) );
325 m->connectToStudy( dynamic_cast<CAM_Study*>( app->activeStudy() ) );
327 m->updateModuleVisibilityState();
329 return m ? m->displayer() : 0;
333 Find the active study and set the 'visibility state' property of the object
334 \param mod_name - name of module
335 \param load - is module has to be forced loaded
337 void LightApp_Displayer::setVisibilityState( const QString& theEntry, Qtx::VisibilityState theState) const {
338 LightApp_Application* app = dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() );
339 LightApp_Study* study = app ? dynamic_cast<LightApp_Study*>( app->activeStudy() ) : 0;
342 study->setVisibilityState( theEntry, theState);