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_Selection.h"
24 #include "LightApp_SelectionMgr.h"
25 #include "LightApp_DataOwner.h"
26 #include "LightApp_Study.h"
27 #include "LightApp_Application.h"
28 #include "LightApp_Displayer.h"
30 #include "CAM_Module.h"
32 #include "SUIT_Session.h"
33 #include "SUIT_ViewWindow.h"
34 #include "SUIT_ViewManager.h"
35 #include "SUIT_Desktop.h"
36 #include "SUIT_Selector.h"
38 #include <QtCore/QSet>
43 LightApp_Selection::LightApp_Selection()
51 LightApp_Selection::~LightApp_Selection()
58 void LightApp_Selection::init( const QString& client, LightApp_SelectionMgr* mgr)
63 if ( mgr->application() )
64 myStudy = dynamic_cast<LightApp_Study*>( mgr->application()->activeStudy() );
69 //1) to take owners from current popup client
70 SUIT_DataOwnerPtrList sel( true ), cur_sel( true );
71 mgr->selected( sel, client );
73 //2) to take such owners from other popup clients that it's entry is different with every entry from current list
74 QList<SUIT_Selector*> aSelectors;
75 mgr->selectors( aSelectors );
76 QListIterator<SUIT_Selector*> it( aSelectors );
77 while ( it.hasNext() )
79 SUIT_Selector* selector = it.next();
80 if ( selector->type() != client && selector->isEnabled() ) {
81 selector->selected( cur_sel );
83 for ( SUIT_DataOwnerPtrList::const_iterator aLIt = cur_sel.begin(); aLIt != cur_sel.end(); ++aLIt )
84 sel.append( *aLIt ); //check entry and don't append if such entry is in list already
88 //3) to analyse owner and fill internal data structures
91 QSet<QString> entries;
92 myObjects.resize( sel.size() );
93 myObjects.fill( ObjectInfo() );
94 for ( SUIT_DataOwnerPtrList::const_iterator anIt = sel.begin(); anIt != sel.end(); anIt++ )
96 LightApp_DataOwner* sowner = dynamic_cast<LightApp_DataOwner*>( (*anIt ).get() );
99 QString entry = referencedToEntry( sowner->entry() );
100 if ( entries.contains( entry ) )
103 entries.insert( entry );
105 setObjectInfo( num, OI_Entry, entry );
106 setObjectInfo( num, OI_Reference, sowner->entry() != entry );
108 if ( processOwner( sowner ) )
111 entries.remove( entry );
115 myObjects.resize( num );
117 myContextParams.clear();
118 myObjectsParams.resize( num );
119 myObjectsParams.fill( ParameterMap() );
124 QString LightApp_Selection::referencedToEntry( const QString& entry ) const
126 return myStudy->referencedToEntry( entry );
130 Gets count of entries.
132 int LightApp_Selection::count() const
134 return myObjects.size();
138 Gets global parameters.
141 QVariant LightApp_Selection::parameter( const QString& p ) const
144 if ( myContextParams.contains( p ) )
145 v = myContextParams[p];
147 v = contextParameter( p );
149 v = QtxPopupSelection::parameter( p );
150 LightApp_Selection* that = (LightApp_Selection*)this;
151 that->myContextParams.insert( p, v );
158 Gets the object parameter.
161 QVariant LightApp_Selection::parameter( const int idx, const QString& p ) const
164 if ( 0 <= idx && idx < myObjectsParams.size() ) {
165 if ( myObjectsParams[idx].contains( p ) )
166 v = myObjectsParams[idx][p];
168 v = objectParameter( idx, p );
169 LightApp_Selection* that = (LightApp_Selection*)this;
170 that->myObjectsParams[idx].insert( p, v );
177 Gets global parameters. client, isActiveView, activeView etc.
179 //QVariant LightApp_Selection::contextParameter( const QString& p ) const
180 QVariant LightApp_Selection::parameter( const QString& p ) const
186 else if ( p == "activeModule" ) {
187 LightApp_Application* app = dynamic_cast<LightApp_Application*>( myStudy->application() );
188 QString mod_name = app ? QString( app->activeModule()->name() ) : QString();
189 if ( !mod_name.isEmpty() )
192 else if ( p == "isActiveView" )
194 else if ( p == "activeView" )
195 v = activeViewType();
197 v = QtxPopupSelection::parameter( p );
203 Gets the object parameter.
205 //QVariant LightApp_Selection::objectParameter( const int idx, const QString& p ) const
206 QVariant LightApp_Selection::parameter( const int idx, const QString& p ) const
208 LightApp_Application* app = 0;
210 app = dynamic_cast<LightApp_Application*>( myStudy->application() );
214 QString e = entry( idx );
215 if ( !e.isEmpty() ) {
216 if ( p == "isVisible" ) {
217 QString mod_name = app->moduleTitle( myStudy->componentDataType( e ) );
218 LightApp_Displayer* d = LightApp_Displayer::FindDisplayer( mod_name, false );
219 // false in last parameter means that now we doesn't load module, if it isn't loaded
223 vis = d->IsDisplayed( e );
225 vis = LightApp_Displayer().IsDisplayed( e );
228 else if ( p == "component" || p == "displayer" )
229 v = myStudy->componentDataType( e );
230 else if ( p == "isComponent" )
231 v = myStudy->isComponent( e );
232 else if ( p == "isReference" )
233 v = isReference( idx );
234 else if ( p == "canBeDisplayed" ) {
235 QString mod_name = app->moduleTitle( myStudy->componentDataType( e ) );
236 LightApp_Displayer* d = LightApp_Displayer::FindDisplayer( mod_name, false );
237 // false in last parameter means that now we doesn't load module, if it isn't loaded
240 v = d->canBeDisplayed( e );
241 else if ( e.startsWith( QObject::tr( "SAVE_POINT_DEF_NAME" ) ) ) // object is a Save Point object
245 //now if displayer is null, it means, that according module isn't loaded, so that we allow to all display/erase
246 //operations under object
255 Perform additional processing of the selected item (to be redefined by successors if necessary).
256 Returns \c true by default.
257 Note: if this method returns \c false, the item will be removed from the items list and
258 not taken into account when showing popup menu.
260 \param owner a data owner being processed
261 \return \c true if the owner should be collected and \c false otherwise
263 bool LightApp_Selection::processOwner( const LightApp_DataOwner* /*owner*/ )
269 Gets entry with index \a index.
271 QString LightApp_Selection::entry( const int index ) const
273 QVariant v = objectInfo( index, OI_Entry );
274 return v.canConvert( QVariant::String ) ? v.toString() : QString();
278 Returns true if i-th selected object was reference to object with entry( i )
280 bool LightApp_Selection::isReference( const int index ) const
282 QVariant v = objectInfo( index, OI_Reference );
283 return v.canConvert( QVariant::Bool ) ? v.toBool() : false;
287 Gets type of active view manager.
289 QString LightApp_Selection::activeViewType() const
291 SUIT_ViewWindow* win = activeVW();
293 SUIT_ViewManager* vm = win->getViewManager();
295 return vm->getType();
301 Gets active view window.
303 SUIT_ViewWindow* LightApp_Selection::activeVW() const
305 SUIT_Session* session = SUIT_Session::session();
307 SUIT_Application* app = session->activeApplication();
309 SUIT_Desktop* desk = app->desktop();
311 return desk->activeWindow();
318 Gets specified information about object with index idx.
320 QVariant LightApp_Selection::objectInfo( const int idx, const int inf ) const
323 if ( 0 <= idx && idx < myObjects.size() ) {
324 if ( myObjects[idx].contains( inf ) )
325 res = myObjects[idx][inf];
331 Sets specified information about object with index idx.
333 void LightApp_Selection::setObjectInfo( const int idx, const int inf, const QVariant& val )
335 if ( 0 <= idx && idx < myObjects.size() )
336 myObjects[idx].insert( inf, val );