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 "SalomeApp_Displayer.h"
21 #include "SalomeApp_Application.h"
23 #include <SALOME_InteractiveObject.hxx>
25 #include <SUIT_Session.h>
26 #include <SUIT_Desktop.h>
27 #include <SUIT_ViewManager.h>
28 #include <SUIT_ViewModel.h>
29 #include <SUIT_ViewWindow.h>
36 SalomeApp_Displayer::SalomeApp_Displayer()
43 SalomeApp_Displayer::~SalomeApp_Displayer()
48 Displays object in view
49 \param entry - object entry
50 \param updateViewer - is it necessary to update viewer
51 \param theViewFrame - view
53 void SalomeApp_Displayer::Display( const QString& entry, const bool updateViewer, SALOME_View* theViewFrame )
55 SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
58 SALOME_Prs* prs = buildPresentation( entry, vf );
62 vf->BeforeDisplay( this );
64 vf->AfterDisplay( this );
69 delete prs; // delete presentation because displayer is its owner
75 Redisplays object in view
76 \param entry - object entry
77 \param updateViewer - is it necessary to update viewer
79 void SalomeApp_Displayer::Redisplay( const QString& entry, const bool updateViewer )
81 // Remove the object permanently (<forced> == true)
82 SUIT_Session* ses = SUIT_Session::session();
83 SUIT_Application* app = ses->activeApplication();
86 SUIT_Desktop* desk = app->desktop();
87 QPtrList<SUIT_ViewWindow> wnds = desk->windows();
89 for ( wnd = wnds.first(); wnd; wnd = wnds.next() )
91 SUIT_ViewManager* vman = wnd->getViewManager();
95 SUIT_ViewModel* vmodel = vman->getViewModel();
99 SALOME_View* view = dynamic_cast<SALOME_View*>(vmodel);
100 if( view && ( IsDisplayed( entry, view ) || view == GetActiveView() ) )
102 Erase( entry, true, false, view );
103 Display( entry, updateViewer, view );
110 Erases object in view
111 \param entry - object entry
112 \param forced - deletes object from viewer (otherwise it will be erased, but cached)
113 \param updateViewer - is it necessary to update viewer
114 \param theViewFrame - view
116 void SalomeApp_Displayer::Erase( const QString& entry, const bool forced,
117 const bool updateViewer, SALOME_View* theViewFrame )
119 SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
122 SALOME_Prs* prs = vf->CreatePrs( entry.latin1() );
124 vf->Erase( prs, forced );
127 delete prs; // delete presentation because displayer is its owner
133 Erases all objects in view
134 \param forced - deletes objects from viewer
135 \param updateViewer - is it necessary to update viewer
136 \param theViewFrame - view
138 void SalomeApp_Displayer::EraseAll( const bool forced, const bool updateViewer, SALOME_View* theViewFrame ) const
140 SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
143 vf->EraseAll( forced );
150 \return true if object is displayed in viewer
151 \param entry - object entry
152 \param theViewFrame - view
154 bool SalomeApp_Displayer::IsDisplayed( const QString& entry, SALOME_View* theViewFrame ) const
156 SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
159 Handle( SALOME_InteractiveObject ) temp = new SALOME_InteractiveObject();
160 temp->setEntry( entry.latin1() );
161 return vf->isVisible( temp );
170 void SalomeApp_Displayer::UpdateViewer() const
172 SALOME_View* vf = GetActiveView();
178 \return presentation of object, built with help of CreatePrs method
179 \param entry - object entry
180 \param theViewFrame - view
183 SALOME_Prs* SalomeApp_Displayer::buildPresentation( const QString& entry, SALOME_View* theViewFrame )
187 SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
190 prs = vf->CreatePrs( entry.latin1() );
198 SALOME_View* SalomeApp_Displayer::GetActiveView()
200 SUIT_Session* session = SUIT_Session::session();
201 if ( SUIT_Application* app = session->activeApplication() ) {
202 if ( SalomeApp_Application* sApp = dynamic_cast<SalomeApp_Application*>( app ) ) {
203 if( SUIT_ViewManager* vman = sApp->activeViewManager() ) {
204 if ( SUIT_ViewModel* vmod = vman->getViewModel() )
205 return dynamic_cast<SALOME_View*>( vmod );