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/ or email : webmaster.salome@opencascade.com
19 #include "SUIT_SelectionMgr.h"
21 /*!\class SUIT_SelectionMgr
22 * Provide selection manager. Manipulate by selection filters, modes, data owners.
25 /*!constructor. initialize myIterations and myIsSelChangeEnabled.*/
26 SUIT_SelectionMgr::SUIT_SelectionMgr( const bool Feedback, QObject* p )
28 myIterations( Feedback ? 1 : 0 ),
29 myIsSelChangeEnabled( true )
33 /*!destructor. mySelectors auto delete.*/
34 SUIT_SelectionMgr::~SUIT_SelectionMgr()
36 mySelectors.setAutoDelete( true );
39 /*!Add selector \a sel to selectors list,if it's not exists in list.*/
40 void SUIT_SelectionMgr::installSelector( SUIT_Selector* sel )
42 if ( sel && !mySelectors.contains( sel ) )
43 mySelectors.append( sel );
46 /*!Remove selector \a sel from list.*/
47 void SUIT_SelectionMgr::removeSelector( SUIT_Selector* sel )
49 mySelectors.remove( sel );
52 /*!Gets selectors list to \a lst.*/
53 void SUIT_SelectionMgr::selectors( QPtrList<SUIT_Selector>& lst ) const
56 for ( SelectorListIterator it( mySelectors ); it.current(); ++it )
57 lst.append( it.current() );
60 /*!Gets selectors list to \a lst with type \a typ.*/
61 void SUIT_SelectionMgr::selectors( const QString& typ, QPtrList<SUIT_Selector>& lst ) const
64 for ( SelectorListIterator it( mySelectors ); it.current(); ++it )
66 if ( it.current()->type() == typ )
67 lst.append( it.current() );
71 /*! Sets ebabled to \a on for all data owners with type \a typ.
73 void SUIT_SelectionMgr::setEnabled( const bool on, const QString& typ )
75 for ( SelectorListIterator it( mySelectors ); it.current(); ++it )
77 if ( typ.isEmpty() || it.current()->type() == typ )
78 it.current()->setEnabled( on );
82 /*! Gets selected data owners from list with type \a type to list \a lst.
84 void SUIT_SelectionMgr::selected( SUIT_DataOwnerPtrList& lst, const QString& type ) const
88 for ( SelectorListIterator it( mySelectors ); it.current(); ++it )
90 if ( !type.isEmpty() && it.current()->type() != type )
92 SUIT_DataOwnerPtrList curList;
93 it.current()->selected( curList );
94 for ( SUIT_DataOwnerPtrList::const_iterator itr = curList.begin(); itr != curList.end(); ++itr )
99 /*! Sets selected data owners from \a lst and append to list, if \a append - true.
101 void SUIT_SelectionMgr::setSelected( const SUIT_DataOwnerPtrList& lst, const bool append )
103 SUIT_DataOwnerPtrList owners;
104 filterOwners( lst, owners );
106 for ( SelectorListIterator it( mySelectors ); it.current(); ++it )
110 SUIT_DataOwnerPtrList current;
111 it.current()->selected( current );
112 for ( SUIT_DataOwnerPtrList::const_iterator it = current.begin(); it != current.end(); ++it )
113 owners.append( *it );
115 it.current()->setSelected( owners );
119 /*! Clear selected data owners.
121 void SUIT_SelectionMgr::clearSelected()
123 setSelected( SUIT_DataOwnerPtrList() );
126 /*! On selection \a sel changed.
128 void SUIT_SelectionMgr::selectionChanged( SUIT_Selector* sel )
130 if ( !sel || !myIsSelChangeEnabled || !sel->isEnabled() )
133 SUIT_DataOwnerPtrList owners;
135 myIsSelChangeEnabled = false;
136 sel->selected( owners );
138 SUIT_DataOwnerPtrList newOwners;
139 filterOwners( owners, newOwners );
141 for ( int i = 0; i < myIterations; i++ )
143 for ( SUIT_Selector* aSel = mySelectors.first(); aSel; aSel = mySelectors.next() )
145 // Temporary action(to avoid selection of the objects which don't pass the filters):
147 aSel->setSelected( newOwners );
150 myIsSelChangeEnabled = true;
152 emit selectionChanged();
156 Returns true if selection manger is in synchronising mode
157 (during synchonisation of the selectors selection).
159 bool SUIT_SelectionMgr::isSynchronizing() const
161 return !myIsSelChangeEnabled;
164 /*! Checks: Is selection manager has selection mode \a mode?
166 bool SUIT_SelectionMgr::hasSelectionMode( const int mode ) const
168 return mySelModes.contains( mode );
171 /*! Gets selection modes to list \a vals.
173 void SUIT_SelectionMgr::selectionModes( QValueList<int>& vals ) const
178 /*! Set selection mode \a mode to list of selection modes.
180 void SUIT_SelectionMgr::setSelectionModes( const int mode )
184 setSelectionModes( lst );
187 /*! Sets selection modes list from \a lst.
189 void SUIT_SelectionMgr::setSelectionModes( const QValueList<int>& lst )
194 /*! Append selection mode \a mode to list of selection modes.
196 void SUIT_SelectionMgr::appendSelectionModes( const int mode )
200 appendSelectionModes( lst );
203 /*! Append selection modes \a lst list.
205 void SUIT_SelectionMgr::appendSelectionModes( const QValueList<int>& lst )
208 for ( QValueList<int>::const_iterator it = mySelModes.begin(); it != mySelModes.end(); ++it )
209 map.insert( *it, 0 );
211 for ( QValueList<int>::const_iterator itr = lst.begin(); itr != lst.end(); ++itr )
213 if ( !map.contains( *itr ) )
214 mySelModes.append( *itr );
218 /*! Remove selection mode \a mode from list.
220 void SUIT_SelectionMgr::removeSelectionModes( const int mode )
224 removeSelectionModes( lst );
227 /*! Remove selection modea \a lst from list.
229 void SUIT_SelectionMgr::removeSelectionModes( const QValueList<int>& lst )
232 for ( QValueList<int>::const_iterator it = mySelModes.begin(); it != mySelModes.end(); ++it )
233 map.insert( *it, 0 );
235 for ( QValueList<int>::const_iterator itr = lst.begin(); itr != lst.end(); ++itr )
239 for ( QMap<int, int>::ConstIterator iter = map.begin(); iter != map.end(); ++iter )
240 mySelModes.append( iter.key() );
243 /*! Checks data owner is ok?
245 bool SUIT_SelectionMgr::isOk( const SUIT_DataOwner* owner ) const
251 for ( SelFilterListIterator it( myFilters ); it.current() && ok; ++it )
252 ok = it.current()->isOk( owner );
257 /*! Checks data owner pointer is ok?
259 bool SUIT_SelectionMgr::isOk( const SUIT_DataOwnerPtr& ptr ) const
264 return isOk( ptr.operator->() );
267 /*! Checks selection manager has filter \a f?
269 bool SUIT_SelectionMgr::hasFilter( SUIT_SelectionFilter* f ) const
271 return myFilters.contains( f );
274 /*! Install filter \a f and set selected, if \a update = true.
276 void SUIT_SelectionMgr::installFilter( SUIT_SelectionFilter* f, const bool updateSelection )
278 if ( !hasFilter( f ) )
280 SUIT_DataOwnerPtrList selOwners;
281 if( updateSelection )
282 selected( selOwners );
284 myFilters.append( f );
286 if( updateSelection )
287 setSelected( selOwners );
291 /*! Remove filter \a f from filters list.
293 void SUIT_SelectionMgr::removeFilter( SUIT_SelectionFilter* f )
295 myFilters.remove( f );
298 /*! Clear filters list.
300 void SUIT_SelectionMgr::clearFilters()
305 /*! Sets auto delete filter.
307 bool SUIT_SelectionMgr::autoDeleteFilter() const
309 return myFilters.autoDelete();
312 /*! Sets auto delete filter to \a on.
314 void SUIT_SelectionMgr::setAutoDeleteFilter( const bool on )
316 myFilters.setAutoDelete( on );
319 /*! Gets good data owners list to \a out from \a in.
321 void SUIT_SelectionMgr::filterOwners( const SUIT_DataOwnerPtrList& in, SUIT_DataOwnerPtrList& out ) const
324 for ( SUIT_DataOwnerPtrList::const_iterator it = in.begin(); it != in.end(); ++it )