-// Copyright (C) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE
-//
-// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
-// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-//
-// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
-//
-
-#include "SUIT_SelectionMgr.h"
-
-#include "SUIT_Selector.h"
-#include "SUIT_SelectionFilter.h"
-
-/*!\class SUIT_SelectionMgr
- * Provide selection manager. Manipulate by selection filters, modes, data owners.
- */
-
-/*!constructor. initialize myIterations and myIsSelChangeEnabled.*/
-SUIT_SelectionMgr::SUIT_SelectionMgr( const bool Feedback, QObject* p )
-: QObject( p ),
-myIterations( Feedback ? 1 : 0 ),
-myAutoDelFilter( false ),
-myIsSelChangeEnabled( true )
-{
-}
-
-/*!destructor. mySelectors auto delete.*/
-SUIT_SelectionMgr::~SUIT_SelectionMgr()
-{
- for ( SelectorList::iterator it = mySelectors.begin(); it != mySelectors.end(); ++it )
- delete *it;
-}
-
-/*!Add selector \a sel to selectors list,if it's not exists in list.*/
-void SUIT_SelectionMgr::installSelector( SUIT_Selector* sel )
-{
- if ( sel && !mySelectors.contains( sel ) )
- mySelectors.append( sel );
-}
-
-/*!Remove selector \a sel from list.*/
-void SUIT_SelectionMgr::removeSelector( SUIT_Selector* sel )
-{
- mySelectors.removeAll( sel );
-}
-
-/*!Gets selectors list to \a lst.*/
-void SUIT_SelectionMgr::selectors( QList<SUIT_Selector*>& lst ) const
-{
- lst.clear();
- for ( SelectorList::const_iterator it = mySelectors.begin(); it != mySelectors.end(); ++it )
- lst.append( *it );
-}
-
-/*!Gets selectors list to \a lst with type \a typ.*/
-void SUIT_SelectionMgr::selectors( const QString& typ, QList<SUIT_Selector*>& lst ) const
-{
- lst.clear();
- for ( SelectorList::const_iterator it = mySelectors.begin(); it != mySelectors.end(); ++it )
- {
- if ( (*it)->type() == typ )
- lst.append( *it );
- }
-}
-
-/*! Sets ebabled to \a on for all data owners with type \a typ.
-*/
-void SUIT_SelectionMgr::setEnabled( const bool on, const QString& typ )
-{
- for ( SelectorList::const_iterator it = mySelectors.begin(); it != mySelectors.end(); ++it )
- {
- if ( typ.isEmpty() || (*it)->type() == typ )
- (*it)->setEnabled( on );
- }
-}
-
-/*! Gets selected data owners from list with type \a type to list \a lst.
-*/
-void SUIT_SelectionMgr::selected( SUIT_DataOwnerPtrList& lst, const QString& type ) const
-{
- lst.clear();
-
- for ( SelectorList::const_iterator it = mySelectors.begin(); it != mySelectors.end(); ++it )
- {
- if ( !type.isEmpty() && (*it)->type() != type )
- continue;
-
- SUIT_DataOwnerPtrList curList;
- (*it)->selected( curList );
- for ( SUIT_DataOwnerPtrList::const_iterator itr = curList.begin(); itr != curList.end(); ++itr )
- lst.append( *itr );
- }
-}
-
-/*! Sets selected data owners from \a lst and append to list, if \a append - true.
-*/
-void SUIT_SelectionMgr::setSelected( const SUIT_DataOwnerPtrList& lst, const bool append )
-{
- SUIT_DataOwnerPtrList owners;
- filterOwners( lst, owners );
-
- for ( SelectorList::const_iterator it = mySelectors.begin(); it != mySelectors.end(); ++it )
- {
- if ( append )
- {
- SUIT_DataOwnerPtrList current;
- (*it)->selected( current );
- for ( SUIT_DataOwnerPtrList::const_iterator it = current.begin(); it != current.end(); ++it )
- owners.append( *it );
- }
- (*it)->setSelected( owners );
- }
-}
-
-/*! Clear selected data owners.
-*/
-void SUIT_SelectionMgr::clearSelected()
-{
- setSelected( SUIT_DataOwnerPtrList() );
-}
-
-/*! On selection \a sel changed.
-*/
-void SUIT_SelectionMgr::selectionChanged( SUIT_Selector* sel )
-{
- if ( !sel || !myIsSelChangeEnabled || !sel->isEnabled() )
- return;
-
- SUIT_DataOwnerPtrList owners;
-
- myIsSelChangeEnabled = false;
- sel->selected( owners );
-
- SUIT_DataOwnerPtrList newOwners;
- filterOwners( owners, newOwners );
-
- for ( int i = 0; i < myIterations; i++ )
- {
- for ( SelectorList::iterator it = mySelectors.begin(); it != mySelectors.end(); ++it )
- {
- // Temporary action(to avoid selection of the objects which don't pass the filters):
- //if ( *it != sel )
- (*it)->setSelected( newOwners );
- }
- }
- myIsSelChangeEnabled = true;
-
- emit selectionChanged();
-}
-
-/*!
- Returns true if selection manger is in synchronising mode
- (during synchonisation of the selectors selection).
-*/
-bool SUIT_SelectionMgr::isSynchronizing() const
-{
- return !myIsSelChangeEnabled;
-}
-
-/*! Checks: Is selection manager has selection mode \a mode?
-*/
-bool SUIT_SelectionMgr::hasSelectionMode( const int mode ) const
-{
- return mySelModes.contains( mode );
-}
-
-/*! Gets selection modes to list \a vals.
-*/
-void SUIT_SelectionMgr::selectionModes( QList<int>& vals ) const
-{
- vals = mySelModes;
-}
-
-/*! Set selection mode \a mode to list of selection modes.
-*/
-void SUIT_SelectionMgr::setSelectionModes( const int mode )
-{
- QList<int> lst;
- lst.append( mode );
- setSelectionModes( lst );
-}
-
-/*! Sets selection modes list from \a lst.
-*/
-void SUIT_SelectionMgr::setSelectionModes( const QList<int>& lst )
-{
- mySelModes = lst;
-}
-
-/*! Append selection mode \a mode to list of selection modes.
-*/
-void SUIT_SelectionMgr::appendSelectionModes( const int mode )
-{
- QList<int> lst;
- lst.append( mode );
- appendSelectionModes( lst );
-}
-
-/*! Append selection modes \a lst list.
-*/
-void SUIT_SelectionMgr::appendSelectionModes( const QList<int>& lst )
-{
- QMap<int, int> map;
- for ( QList<int>::const_iterator it = mySelModes.begin(); it != mySelModes.end(); ++it )
- map.insert( *it, 0 );
-
- for ( QList<int>::const_iterator itr = lst.begin(); itr != lst.end(); ++itr )
- {
- if ( !map.contains( *itr ) )
- mySelModes.append( *itr );
- }
-}
-
-/*! Remove selection mode \a mode from list.
-*/
-void SUIT_SelectionMgr::removeSelectionModes( const int mode )
-{
- QList<int> lst;
- lst.append( mode );
- removeSelectionModes( lst );
-}
-
-/*! Remove selection modea \a lst from list.
-*/
-void SUIT_SelectionMgr::removeSelectionModes( const QList<int>& lst )
-{
- QMap<int, int> map;
- for ( QList<int>::const_iterator it = mySelModes.begin(); it != mySelModes.end(); ++it )
- map.insert( *it, 0 );
-
- for ( QList<int>::const_iterator itr = lst.begin(); itr != lst.end(); ++itr )
- map.remove( *itr );
-
- mySelModes.clear();
- for ( QMap<int, int>::ConstIterator iter = map.begin(); iter != map.end(); ++iter )
- mySelModes.append( iter.key() );
-}
-
-/*! Checks data owner is ok?
-*/
-bool SUIT_SelectionMgr::isOk( const SUIT_DataOwner* owner ) const
-{
- if ( !owner )
- return false;
-
- bool ok = true;
- for ( SelFilterList::const_iterator it = myFilters.begin(); it != myFilters.end() && ok; ++it )
- ok = (*it)->isOk( owner );
-
- return ok;
-}
-
-/*! Checks data owner pointer is ok?
-*/
-bool SUIT_SelectionMgr::isOk( const SUIT_DataOwnerPtr& ptr ) const
-{
- if ( ptr.isNull() )
- return false;
-
- return isOk( ptr.operator->() );
-}
-
-/*! Checks selection manager has filter \a f?
-*/
-bool SUIT_SelectionMgr::hasFilter( SUIT_SelectionFilter* f ) const
-{
- return myFilters.contains( f );
-}
-
-/*! Install filter \a f and set selected, if \a update = true.
-*/
-void SUIT_SelectionMgr::installFilter( SUIT_SelectionFilter* f, const bool updateSelection )
-{
- if ( !hasFilter( f ) )
- {
- SUIT_DataOwnerPtrList selOwners;
- if( updateSelection )
- selected( selOwners );
-
- myFilters.append( f );
-
- if( updateSelection )
- setSelected( selOwners );
- }
-}
-
-/*! Remove filter \a f from filters list.
-*/
-void SUIT_SelectionMgr::removeFilter( SUIT_SelectionFilter* f )
-{
- if ( !myFilters.contains( f ) )
- return;
-
- myFilters.removeAll( f );
-
- if ( autoDeleteFilter() )
- delete f;
-}
-
-/*! Clear filters list.
-*/
-void SUIT_SelectionMgr::clearFilters()
-{
- if ( autoDeleteFilter() )
- {
- for ( SelFilterList::const_iterator it = myFilters.begin(); it != myFilters.end(); ++it )
- delete *it;
- }
-
- myFilters.clear();
-}
-
-/*! Sets auto delete filter.
-*/
-bool SUIT_SelectionMgr::autoDeleteFilter() const
-{
- return myAutoDelFilter;
-}
-
-/*! Sets auto delete filter to \a on.
-*/
-void SUIT_SelectionMgr::setAutoDeleteFilter( const bool on )
-{
- myAutoDelFilter = on;
-}
-
-/*! Gets good data owners list to \a out from \a in.
-*/
-void SUIT_SelectionMgr::filterOwners( const SUIT_DataOwnerPtrList& in, SUIT_DataOwnerPtrList& out ) const
-{
- out.clear();
- for ( SUIT_DataOwnerPtrList::const_iterator it = in.begin(); it != in.end(); ++it )
- {
- if ( isOk( *it ) )
- out.append( *it );
- }
-}
+// Copyright (C) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE\r
+//\r
+// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,\r
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS\r
+//\r
+// This library is free software; you can redistribute it and/or\r
+// modify it under the terms of the GNU Lesser General Public\r
+// License as published by the Free Software Foundation; either\r
+// version 2.1 of the License.\r
+//\r
+// This library is distributed in the hope that it will be useful,\r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\r
+// Lesser General Public License for more details.\r
+//\r
+// You should have received a copy of the GNU Lesser General Public\r
+// License along with this library; if not, write to the Free Software\r
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\r
+//\r
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com\r
+//\r
+\r
+#include "SUIT_SelectionMgr.h"\r
+\r
+#include "SUIT_Selector.h"\r
+#include "SUIT_SelectionFilter.h"\r
+\r
+/*!\class SUIT_SelectionMgr\r
+ * Provide selection manager. Manipulate by selection filters, modes, data owners.\r
+ */\r
+\r
+/*!constructor. initialize myIterations and myIsSelChangeEnabled.*/\r
+SUIT_SelectionMgr::SUIT_SelectionMgr( const bool Feedback, QObject* p )\r
+: QObject( p ),\r
+myIterations( Feedback ? 1 : 0 ),\r
+myAutoDelFilter( false ),\r
+myIsSelChangeEnabled( true )\r
+{\r
+}\r
+\r
+/*!destructor. mySelectors auto delete.*/\r
+SUIT_SelectionMgr::~SUIT_SelectionMgr()\r
+{\r
+ for ( SelectorList::iterator it = mySelectors.begin(); it != mySelectors.end(); ++it )\r
+ delete *it;\r
+}\r
+\r
+/*!Add selector \a sel to selectors list,if it's not exists in list.*/\r
+void SUIT_SelectionMgr::installSelector( SUIT_Selector* sel )\r
+{\r
+ if ( sel && !mySelectors.contains( sel ) )\r
+ mySelectors.append( sel );\r
+}\r
+\r
+/*!Remove selector \a sel from list.*/\r
+void SUIT_SelectionMgr::removeSelector( SUIT_Selector* sel )\r
+{\r
+ mySelectors.removeAll( sel );\r
+}\r
+\r
+/*!Gets selectors list to \a lst.*/\r
+void SUIT_SelectionMgr::selectors( QList<SUIT_Selector*>& lst ) const\r
+{\r
+ lst.clear();\r
+ for ( SelectorList::const_iterator it = mySelectors.begin(); it != mySelectors.end(); ++it )\r
+ lst.append( *it );\r
+}\r
+\r
+/*!Gets selectors list to \a lst with type \a typ.*/\r
+void SUIT_SelectionMgr::selectors( const QString& typ, QList<SUIT_Selector*>& lst ) const\r
+{\r
+ lst.clear();\r
+ for ( SelectorList::const_iterator it = mySelectors.begin(); it != mySelectors.end(); ++it )\r
+ {\r
+ if ( (*it)->type() == typ )\r
+ lst.append( *it );\r
+ }\r
+}\r
+\r
+/*! Sets ebabled to \a on for all data owners with type \a typ.\r
+*/\r
+void SUIT_SelectionMgr::setEnabled( const bool on, const QString& typ )\r
+{\r
+ for ( SelectorList::const_iterator it = mySelectors.begin(); it != mySelectors.end(); ++it )\r
+ {\r
+ if ( typ.isEmpty() || (*it)->type() == typ )\r
+ (*it)->setEnabled( on );\r
+ }\r
+}\r
+\r
+/*! Gets selected data owners from list with type \a type to list \a lst.\r
+*/\r
+void SUIT_SelectionMgr::selected( SUIT_DataOwnerPtrList& lst, const QString& type ) const\r
+{\r
+ lst.clear();\r
+\r
+ for ( SelectorList::const_iterator it = mySelectors.begin(); it != mySelectors.end(); ++it )\r
+ {\r
+ if ( !(*it)->isEnabled() )\r
+ continue;\r
+ if ( !type.isEmpty() && (*it)->type() != type )\r
+ continue;\r
+\r
+ SUIT_DataOwnerPtrList curList;\r
+ (*it)->selected( curList );\r
+ for ( SUIT_DataOwnerPtrList::const_iterator itr = curList.begin(); itr != curList.end(); ++itr )\r
+ lst.append( *itr );\r
+ }\r
+}\r
+\r
+/*! Sets selected data owners from \a lst and append to list, if \a append - true.\r
+*/\r
+void SUIT_SelectionMgr::setSelected( const SUIT_DataOwnerPtrList& lst, const bool append )\r
+{\r
+ SUIT_DataOwnerPtrList owners;\r
+ filterOwners( lst, owners );\r
+\r
+ for ( SelectorList::const_iterator it = mySelectors.begin(); it != mySelectors.end(); ++it )\r
+ {\r
+ if ( append )\r
+ {\r
+ SUIT_DataOwnerPtrList current;\r
+ (*it)->selected( current );\r
+ for ( SUIT_DataOwnerPtrList::const_iterator it = current.begin(); it != current.end(); ++it )\r
+ owners.append( *it );\r
+ }\r
+ (*it)->setSelected( owners );\r
+ }\r
+}\r
+\r
+/*! Clear selected data owners.\r
+*/\r
+void SUIT_SelectionMgr::clearSelected()\r
+{\r
+ setSelected( SUIT_DataOwnerPtrList() );\r
+}\r
+\r
+/*! On selection \a sel changed.\r
+*/\r
+void SUIT_SelectionMgr::selectionChanged( SUIT_Selector* sel )\r
+{\r
+ if ( !sel || !myIsSelChangeEnabled || !sel->isEnabled() )\r
+ return;\r
+\r
+ SUIT_DataOwnerPtrList owners;\r
+\r
+ myIsSelChangeEnabled = false;\r
+ sel->selected( owners );\r
+\r
+ SUIT_DataOwnerPtrList newOwners;\r
+ filterOwners( owners, newOwners );\r
+\r
+ for ( int i = 0; i < myIterations; i++ )\r
+ {\r
+ for ( SelectorList::iterator it = mySelectors.begin(); it != mySelectors.end(); ++it )\r
+ {\r
+ // Temporary action(to avoid selection of the objects which don't pass the filters):\r
+ //if ( *it != sel )\r
+ (*it)->setSelected( newOwners );\r
+ }\r
+ }\r
+ myIsSelChangeEnabled = true;\r
+\r
+ emit selectionChanged();\r
+}\r
+\r
+/*!\r
+ Returns true if selection manger is in synchronising mode\r
+ (during synchonisation of the selectors selection).\r
+*/\r
+bool SUIT_SelectionMgr::isSynchronizing() const\r
+{\r
+ return !myIsSelChangeEnabled;\r
+}\r
+\r
+/*! Checks: Is selection manager has selection mode \a mode?\r
+*/\r
+bool SUIT_SelectionMgr::hasSelectionMode( const int mode ) const\r
+{\r
+ return mySelModes.contains( mode );\r
+}\r
+\r
+/*! Gets selection modes to list \a vals.\r
+*/\r
+void SUIT_SelectionMgr::selectionModes( QList<int>& vals ) const\r
+{\r
+ vals = mySelModes;\r
+}\r
+\r
+/*! Set selection mode \a mode to list of selection modes.\r
+*/\r
+void SUIT_SelectionMgr::setSelectionModes( const int mode )\r
+{\r
+ QList<int> lst;\r
+ lst.append( mode );\r
+ setSelectionModes( lst );\r
+}\r
+\r
+/*! Sets selection modes list from \a lst.\r
+*/\r
+void SUIT_SelectionMgr::setSelectionModes( const QList<int>& lst )\r
+{\r
+ mySelModes = lst;\r
+}\r
+\r
+/*! Append selection mode \a mode to list of selection modes.\r
+*/\r
+void SUIT_SelectionMgr::appendSelectionModes( const int mode )\r
+{\r
+ QList<int> lst;\r
+ lst.append( mode );\r
+ appendSelectionModes( lst );\r
+}\r
+\r
+/*! Append selection modes \a lst list.\r
+*/\r
+void SUIT_SelectionMgr::appendSelectionModes( const QList<int>& lst )\r
+{\r
+ QMap<int, int> map;\r
+ for ( QList<int>::const_iterator it = mySelModes.begin(); it != mySelModes.end(); ++it )\r
+ map.insert( *it, 0 );\r
+\r
+ for ( QList<int>::const_iterator itr = lst.begin(); itr != lst.end(); ++itr )\r
+ {\r
+ if ( !map.contains( *itr ) )\r
+ mySelModes.append( *itr );\r
+ }\r
+}\r
+\r
+/*! Remove selection mode \a mode from list.\r
+*/\r
+void SUIT_SelectionMgr::removeSelectionModes( const int mode )\r
+{\r
+ QList<int> lst;\r
+ lst.append( mode );\r
+ removeSelectionModes( lst );\r
+}\r
+\r
+/*! Remove selection modea \a lst from list.\r
+*/\r
+void SUIT_SelectionMgr::removeSelectionModes( const QList<int>& lst )\r
+{\r
+ QMap<int, int> map;\r
+ for ( QList<int>::const_iterator it = mySelModes.begin(); it != mySelModes.end(); ++it )\r
+ map.insert( *it, 0 );\r
+\r
+ for ( QList<int>::const_iterator itr = lst.begin(); itr != lst.end(); ++itr )\r
+ map.remove( *itr );\r
+\r
+ mySelModes.clear();\r
+ for ( QMap<int, int>::ConstIterator iter = map.begin(); iter != map.end(); ++iter )\r
+ mySelModes.append( iter.key() );\r
+}\r
+\r
+/*! Checks data owner is ok?\r
+*/\r
+bool SUIT_SelectionMgr::isOk( const SUIT_DataOwner* owner ) const\r
+{\r
+ if ( !owner )\r
+ return false;\r
+\r
+ bool ok = true;\r
+ for ( SelFilterList::const_iterator it = myFilters.begin(); it != myFilters.end() && ok; ++it )\r
+ ok = (*it)->isOk( owner );\r
+\r
+ return ok;\r
+}\r
+\r
+/*! Checks data owner pointer is ok?\r
+*/\r
+bool SUIT_SelectionMgr::isOk( const SUIT_DataOwnerPtr& ptr ) const\r
+{\r
+ if ( ptr.isNull() )\r
+ return false;\r
+\r
+ return isOk( ptr.operator->() );\r
+}\r
+\r
+/*! Checks selection manager has filter \a f?\r
+*/\r
+bool SUIT_SelectionMgr::hasFilter( SUIT_SelectionFilter* f ) const\r
+{\r
+ return myFilters.contains( f );\r
+}\r
+\r
+/*! Install filter \a f and set selected, if \a update = true.\r
+*/\r
+void SUIT_SelectionMgr::installFilter( SUIT_SelectionFilter* f, const bool updateSelection )\r
+{\r
+ if ( !hasFilter( f ) )\r
+ {\r
+ SUIT_DataOwnerPtrList selOwners;\r
+ if( updateSelection )\r
+ selected( selOwners );\r
+ \r
+ myFilters.append( f );\r
+ \r
+ if( updateSelection )\r
+ setSelected( selOwners );\r
+ }\r
+}\r
+\r
+/*! Remove filter \a f from filters list.\r
+*/\r
+void SUIT_SelectionMgr::removeFilter( SUIT_SelectionFilter* f )\r
+{\r
+ if ( !myFilters.contains( f ) )\r
+ return;\r
+\r
+ myFilters.removeAll( f );\r
+\r
+ if ( autoDeleteFilter() )\r
+ delete f;\r
+}\r
+\r
+/*! Clear filters list.\r
+*/\r
+void SUIT_SelectionMgr::clearFilters()\r
+{\r
+ if ( autoDeleteFilter() )\r
+ {\r
+ for ( SelFilterList::const_iterator it = myFilters.begin(); it != myFilters.end(); ++it )\r
+ delete *it;\r
+ }\r
+\r
+ myFilters.clear();\r
+}\r
+\r
+/*! Sets auto delete filter.\r
+*/\r
+bool SUIT_SelectionMgr::autoDeleteFilter() const\r
+{\r
+ return myAutoDelFilter;\r
+}\r
+\r
+/*! Sets auto delete filter to \a on.\r
+*/\r
+void SUIT_SelectionMgr::setAutoDeleteFilter( const bool on )\r
+{\r
+ myAutoDelFilter = on;\r
+}\r
+\r
+/*! Gets good data owners list to \a out from \a in.\r
+*/\r
+void SUIT_SelectionMgr::filterOwners( const SUIT_DataOwnerPtrList& in, SUIT_DataOwnerPtrList& out ) const\r
+{\r
+ out.clear();\r
+ for ( SUIT_DataOwnerPtrList::const_iterator it = in.begin(); it != in.end(); ++it )\r
+ {\r
+ if ( isOk( *it ) )\r
+ out.append( *it );\r
+ }\r
+}\r