Salome HOME
This file in LightApp package
[modules/gui.git] / src / SalomeApp / SalomeApp_Displayer.cxx
1
2 #include "SalomeApp_Displayer.h"
3 #include "SalomeApp_Application.h"
4
5 #include <SALOME_InteractiveObject.hxx>
6
7 #include <SUIT_Session.h>
8 #include <SUIT_Desktop.h>
9 #include <SUIT_ViewManager.h>
10 #include <SUIT_ViewModel.h>
11 #include <SUIT_ViewWindow.h>
12
13 #include <qstring.h>
14
15 SalomeApp_Displayer::SalomeApp_Displayer()
16 {
17 }
18
19 SalomeApp_Displayer::~SalomeApp_Displayer()
20 {
21 }
22
23 void SalomeApp_Displayer::Display( const QString& entry, const bool updateViewer, SALOME_View* theViewFrame )
24 {
25   SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
26   if ( vf )
27   {
28     SALOME_Prs* prs = buildPresentation( entry, vf );
29
30     if ( prs )
31     {
32       vf->BeforeDisplay( this );
33       vf->Display( prs );
34       vf->AfterDisplay( this );
35
36       if ( updateViewer )
37         vf->Repaint();
38
39       delete prs;  // delete presentation because displayer is its owner
40     }
41   }
42 }
43
44 void SalomeApp_Displayer::Redisplay( const QString& entry, const bool updateViewer )
45 {
46   // Remove the object permanently (<forced> == true)
47   SUIT_Session* ses = SUIT_Session::session();
48   SUIT_Application* app = ses->activeApplication();
49   if ( app )
50   {
51     SUIT_Desktop* desk = app->desktop();
52     QPtrList<SUIT_ViewWindow> wnds = desk->windows();
53     SUIT_ViewWindow* wnd;
54     for ( wnd = wnds.first(); wnd; wnd = wnds.next() )
55     {
56       SUIT_ViewManager* vman = wnd->getViewManager();
57       if( !vman )
58         continue;
59
60       SUIT_ViewModel* vmodel = vman->getViewModel();
61       if( !vmodel )
62         continue;
63         
64       SALOME_View* view = dynamic_cast<SALOME_View*>(vmodel);
65       if( view && ( IsDisplayed( entry, view ) || view == GetActiveView() ) )
66       {
67         Erase( entry, true, false, view );
68         Display( entry, updateViewer, view );
69       }
70     }
71   }
72 }
73
74 void SalomeApp_Displayer::Erase( const QString& entry, const bool forced,
75                                  const bool updateViewer, SALOME_View* theViewFrame )
76 {
77   SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
78
79   if ( vf ) {
80     SALOME_Prs* prs = vf->CreatePrs( entry.latin1() );
81     if ( prs ) {
82       vf->Erase( prs, forced );
83       if ( updateViewer )
84         vf->Repaint();
85       delete prs;  // delete presentation because displayer is its owner
86     }
87   }
88 }
89
90 void SalomeApp_Displayer::EraseAll( const bool forced, const bool updateViewer, SALOME_View* theViewFrame ) const
91 {
92   SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
93
94   if ( vf ) {
95     vf->EraseAll( forced );
96     if ( updateViewer )
97       vf->Repaint();
98   }
99 }
100
101 bool SalomeApp_Displayer::IsDisplayed( const QString& entry, SALOME_View* theViewFrame ) const
102 {
103   SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
104   if( vf )
105   {
106     Handle( SALOME_InteractiveObject ) temp = new SALOME_InteractiveObject();
107     temp->setEntry( entry.latin1() );
108     return vf->isVisible( temp );
109   }
110   else
111     return false;
112 }
113
114 void SalomeApp_Displayer::UpdateViewer() const
115 {
116   SALOME_View* vf = GetActiveView();
117   if ( vf )
118     vf->Repaint();
119 }
120
121 SALOME_Prs* SalomeApp_Displayer::buildPresentation( const QString& entry, SALOME_View* theViewFrame )
122 {
123   SALOME_Prs* prs = 0;
124
125   SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
126
127   if ( vf )
128     prs = vf->CreatePrs( entry.latin1() );
129
130   return prs;
131 }
132
133 SALOME_View* SalomeApp_Displayer::GetActiveView()
134 {
135   SUIT_Session* session = SUIT_Session::session();
136   if (  SUIT_Application* app = session->activeApplication() ) {
137     if ( SalomeApp_Application* sApp = dynamic_cast<SalomeApp_Application*>( app ) ) {
138       if( SUIT_ViewManager* vman = sApp->activeViewManager() ) {
139         if ( SUIT_ViewModel* vmod = vman->getViewModel() )
140           return dynamic_cast<SALOME_View*>( vmod );
141       }
142     }
143   }
144   return 0;
145 }