]> SALOME platform Git repositories - modules/gui.git/blob - src/LightApp/LightApp_Selection.cxx
Salome HOME
PAL10810 - "Display", "Erase", "Display only" on root objects
[modules/gui.git] / src / LightApp / LightApp_Selection.cxx
1 // Copyright (C) 2005  OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
2 // 
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.
7 // 
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/
18 //
19
20 #include "LightApp_Selection.h"
21 #include "LightApp_SelectionMgr.h"
22 #include "LightApp_DataOwner.h"
23 #include "LightApp_Study.h"
24 #include "LightApp_Application.h"
25 #include "LightApp_Displayer.h"
26
27 #include "SUIT_Session.h"
28 #include "SUIT_ViewWindow.h"
29
30 /*!
31   Constructor
32 */
33 LightApp_Selection::LightApp_Selection()
34 : myStudy( 0 )
35 {
36 }
37
38 /*!
39   Destructor.
40 */
41 LightApp_Selection::~LightApp_Selection()
42 {
43 }
44
45 /*!
46   Initialization.
47 */
48 void LightApp_Selection::init( const QString& client, LightApp_SelectionMgr* mgr)
49 {
50   myPopupClient = client;
51   myStudy = 0;
52   
53   if( mgr )
54   {
55     if( mgr->application() )
56       myStudy = dynamic_cast<LightApp_Study*>( mgr->application()->activeStudy() );
57     if( !myStudy )
58       return;
59
60     //1) to take owners from current popup client
61     SUIT_DataOwnerPtrList sel( true ), cur_sel( true );
62     mgr->selected( sel, client );
63
64     //2) to take such owners from other popup clients that it's entry is different with every entry from current list
65     QPtrList<SUIT_Selector> aSelectors;
66     mgr->selectors( aSelectors );
67     for( SUIT_Selector* selector = aSelectors.first(); selector; selector = aSelectors.next() )
68       if( selector->type()!=client )
69       {
70         mgr->selected( cur_sel, selector->type() );
71         SUIT_DataOwnerPtrList::const_iterator aLIt = cur_sel.begin(), aLLast = cur_sel.end();
72         for( ; aLIt!=aLLast; aLIt++ )
73           sel.append( *aLIt ); //check entry and don't append if such entry is in list already
74       }
75
76     //3) to analyse owner and fill internal data structures
77     SUIT_DataOwnerPtrList::const_iterator anIt = sel.begin(), aLast = sel.end();
78     QString entry;
79     for( ; anIt!=aLast; anIt++ )
80     {
81       LightApp_DataOwner* sowner = dynamic_cast<LightApp_DataOwner*>( (*anIt ).get() );
82       if( sowner )
83       {
84         entry = myStudy->referencedToEntry( sowner->entry() );
85         myEntries.append( entry );
86         myIsReferences.append( sowner->entry() == entry );
87         processOwner( sowner );
88       }
89     }
90   }
91 }
92
93 /*!
94   Gets count of entries.
95 */
96 int LightApp_Selection::count() const
97 {
98   return myEntries.count();
99 }
100
101 /*!
102   Gets QtxValue();
103 */
104 QtxValue LightApp_Selection::param( const int ind, const QString& p ) const
105 {
106   LightApp_Application* app = dynamic_cast<LightApp_Application*>( myStudy ? myStudy->application() : 0 );
107   if( !( ind>=0 && ind<count() ) || !app )
108     return QtxValue();
109
110   if( p=="isVisible" )
111   {
112     QString mod_name = app->moduleTitle( param( ind, "component" ).toString() );
113     LightApp_Displayer* d = LightApp_Displayer::FindDisplayer( mod_name, false );
114     // false in last parameter means that now we doesn't load module, if it isn't loaded
115
116     bool vis = false;
117     if( d )
118       vis = d->IsDisplayed( myEntries[ ind ] );
119     else
120     {
121       LightApp_Displayer local_d;
122       vis = local_d.IsDisplayed( myEntries[ ind ] );
123     }
124     return QtxValue( vis, 0 );
125   }
126
127   else if( p=="component" )
128   {
129     return myStudy->componentDataType( myEntries[ ind ] );
130   }
131   
132   else if( p=="isComponent" )
133   {
134     return QtxValue( myStudy->isComponent( myEntries[ ind ] ), 0 );
135   }
136
137   else if( p=="isReference" )
138     return QtxValue( isReference( ind ), false );
139
140   else if( p=="canBeDisplayed" )
141   {
142     QString mod_name = app->moduleTitle( param( ind, "component" ).toString() );
143     LightApp_Displayer* d = LightApp_Displayer::FindDisplayer( mod_name, false );
144     // false in last parameter means that now we doesn't load module, if it isn't loaded
145
146     return QtxValue( d ? d->canBeDisplayed( myEntries[ ind ] ) : true, 0 );
147     //now if displayer is null, it means, that according module isn't loaded, so that we allow to all display/erase
148     //operations under object
149   }
150
151   return QtxValue();
152 }
153
154 /*!
155   Gets global parameters. client, isActiveView, activeView etc.
156 */
157 QtxValue LightApp_Selection::globalParam( const QString& p ) const
158 {
159   if      ( p == "client" )        return QtxValue( myPopupClient );
160   else if ( p == "activeModule" )
161   {
162     LightApp_Application* app = dynamic_cast<LightApp_Application*>( myStudy->application() );
163     QString mod_name = app ? QString( app->activeModule()->name() ) : QString::null;
164     //cout << "activeModule : " << mod_name.latin1() << endl;
165     if( !mod_name.isEmpty() )
166       return mod_name;
167     else
168       return QtxValue();
169   }
170   else if ( p == "isActiveView" )  return QtxValue( (bool)activeVW() );
171   else if ( p == "activeView" )    return QtxValue( activeViewType() );
172 #ifndef WNT
173   else                             return QtxPopupMgr::Selection::globalParam( p );
174 #else
175   else                             return Selection::globalParam( p );
176 #endif
177 }
178
179 /*!
180   Do nothing. To be redefined by successors
181 */
182 void LightApp_Selection::processOwner( const LightApp_DataOwner* )
183 {
184 }
185
186 /*!
187   Gets entry with index \a index.
188 */
189 QString LightApp_Selection::entry( const int index ) const
190 {
191   if ( index >= 0 && index < count() )
192     return myEntries[ index ];
193   return QString();
194 }
195
196 /*!
197   Returns true if i-th selected object was reference to object with entry( i )
198 */
199 bool LightApp_Selection::isReference( const int index ) const
200 {
201   if( index >= 0 && index < count() )
202     return myIsReferences[ index ];
203   else
204     return false;
205 }
206
207 /*!
208   Gets type of active view manager.
209 */
210 QString LightApp_Selection::activeViewType() const
211 {
212   SUIT_ViewWindow* win = activeVW();
213   if ( win ) {
214     SUIT_ViewManager* vm = win->getViewManager();
215     if ( vm )
216       return vm->getType();
217   }
218   return QString::null;
219 }
220
221 /*!
222   Gets active view window.
223 */
224 SUIT_ViewWindow* LightApp_Selection::activeVW() const
225 {
226   SUIT_Session* session = SUIT_Session::session();
227   if ( session ) {
228     SUIT_Application* app = session->activeApplication();
229     if ( app ) {
230       SUIT_Desktop* desk = app->desktop();
231       if ( desk ) 
232         return desk->activeWindow();
233     }
234   }
235   return 0;
236 }