1 // Copyright (C) 2007-2008 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
22 #include "LightApp_Selection.h"
23 #include "LightApp_SelectionMgr.h"
24 #include "LightApp_DataOwner.h"
25 #include "LightApp_Study.h"
26 #include "LightApp_Application.h"
27 #include "LightApp_Displayer.h"
29 #include "CAM_Module.h"
31 #include "SUIT_Session.h"
32 #include "SUIT_ViewWindow.h"
33 #include "SUIT_ViewManager.h"
34 #include "SUIT_Desktop.h"
35 #include "SUIT_Selector.h"
40 LightApp_Selection::LightApp_Selection()
48 LightApp_Selection::~LightApp_Selection()
55 void LightApp_Selection::init( const QString& client, LightApp_SelectionMgr* mgr)
57 myPopupClient = client;
61 if( mgr->application() )
62 myStudy = dynamic_cast<LightApp_Study*>( mgr->application()->activeStudy() );
66 //1) to take owners from current popup client
67 SUIT_DataOwnerPtrList sel( true ), cur_sel( true );
68 mgr->selected( sel, client );
70 //2) to take such owners from other popup clients that it's entry is different with every entry from current list
71 QList<SUIT_Selector*> aSelectors;
72 mgr->selectors( aSelectors );
73 QListIterator<SUIT_Selector*> it( aSelectors );
74 while ( it.hasNext() )
76 SUIT_Selector* selector = it.next();
77 if( selector->type() != client && selector->isEnabled() )
79 //mgr->selected( cur_sel, selector->type() );
80 selector->selected( cur_sel );
81 SUIT_DataOwnerPtrList::const_iterator aLIt = cur_sel.begin(), aLLast = cur_sel.end();
82 for( ; aLIt!=aLLast; aLIt++ )
83 sel.append( *aLIt ); //check entry and don't append if such entry is in list already
87 //3) to analyse owner and fill internal data structures
88 SUIT_DataOwnerPtrList::const_iterator anIt = sel.begin(), aLast = sel.end();
89 QMap<QString,int> entries;
92 for( ; anIt!=aLast; anIt++ )
94 LightApp_DataOwner* sowner = dynamic_cast<LightApp_DataOwner*>( (*anIt ).get() );
97 entry = referencedToEntry( sowner->entry() );
98 if( entries.contains( entry ) )
101 entries.insert( entry, 0 );
102 myEntries.insert( num, entry );
103 myIsReferences.insert( num, sowner->entry() != entry );
104 processOwner( sowner );
111 QString LightApp_Selection::referencedToEntry( const QString& entry ) const
113 return myStudy->referencedToEntry( entry );
117 Gets count of entries.
119 int LightApp_Selection::count() const
121 return myEntries.count();
127 QVariant LightApp_Selection::parameter( const int ind, const QString& p ) const
129 LightApp_Application* app = dynamic_cast<LightApp_Application*>( myStudy ? myStudy->application() : 0 );
130 if( !( ind>=0 && ind<count() ) || !app )
135 QString mod_name = app->moduleTitle( parameter( ind, "component" ).toString() );
136 LightApp_Displayer* d = LightApp_Displayer::FindDisplayer( mod_name, false );
137 // false in last parameter means that now we doesn't load module, if it isn't loaded
141 vis = d->IsDisplayed( myEntries[ ind ] );
144 LightApp_Displayer local_d;
145 vis = local_d.IsDisplayed( myEntries[ ind ] );
147 return QVariant( vis );
150 else if( p=="component" )
152 return myStudy->componentDataType( myEntries[ ind ] );
155 else if( p=="isComponent" )
157 return QVariant( myStudy->isComponent( myEntries[ ind ] ) );
160 else if( p=="isReference" )
161 return QVariant( isReference( ind ) );
163 else if( p=="displayer" )
164 return parameter( ind, "component" );
166 else if( p=="canBeDisplayed" )
168 QString mod_name = app->moduleTitle( parameter( ind, "component" ).toString() );
169 LightApp_Displayer* d = LightApp_Displayer::FindDisplayer( mod_name, false );
170 // false in last parameter means that now we doesn't load module, if it isn't loaded
173 return d->canBeDisplayed( myEntries[ ind ] );
174 else if ( myEntries[ ind ].startsWith( QObject::tr( "SAVE_POINT_DEF_NAME" ) ) ) // object is a Save Point object
178 //now if displayer is null, it means, that according module isn't loaded, so that we allow to all display/erase
179 //operations under object
186 Gets global parameters. client, isActiveView, activeView etc.
188 QVariant LightApp_Selection::parameter( const QString& p ) const
190 if ( p == "client" ) return QVariant( myPopupClient );
191 else if ( p == "activeModule" )
193 LightApp_Application* app = dynamic_cast<LightApp_Application*>( myStudy->application() );
194 QString mod_name = app ? QString( app->activeModule()->name() ) : QString();
195 //cout << "activeModule : " << mod_name.latin1() << endl;
196 if( !mod_name.isEmpty() )
201 else if ( p == "isActiveView" ) return QVariant( (bool)activeVW() );
202 else if ( p == "activeView" ) return QVariant( activeViewType() );
203 else return QtxPopupSelection::parameter( p );
207 Do nothing. To be redefined by successors
209 void LightApp_Selection::processOwner( const LightApp_DataOwner* )
214 Gets entry with index \a index.
216 QString LightApp_Selection::entry( const int index ) const
218 if ( index >= 0 && index < count() )
219 return myEntries[ index ];
224 Returns true if i-th selected object was reference to object with entry( i )
226 bool LightApp_Selection::isReference( const int index ) const
228 if( index >= 0 && index < count() )
229 return myIsReferences[ index ];
235 Gets type of active view manager.
237 QString LightApp_Selection::activeViewType() const
239 SUIT_ViewWindow* win = activeVW();
241 SUIT_ViewManager* vm = win->getViewManager();
243 return vm->getType();
249 Gets active view window.
251 SUIT_ViewWindow* LightApp_Selection::activeVW() const
253 SUIT_Session* session = SUIT_Session::session();
255 SUIT_Application* app = session->activeApplication();
257 SUIT_Desktop* desk = app->desktop();
259 return desk->activeWindow();