X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FLightApp%2FLightApp_SelectionMgr.cxx;h=89875ec57bb9eb6c88abeb4303fd035a8b054f62;hb=331294345d3e1716fbf79ae25a2851011729be79;hp=dd304ac1441b84dba589d4f4c59b3549cbcbe971;hpb=c47605c13ccf37a7b3fcb9cb6c8baf38d3643f77;p=modules%2Fgui.git diff --git a/src/LightApp/LightApp_SelectionMgr.cxx b/src/LightApp/LightApp_SelectionMgr.cxx old mode 100755 new mode 100644 index dd304ac14..89875ec57 --- a/src/LightApp/LightApp_SelectionMgr.cxx +++ b/src/LightApp/LightApp_SelectionMgr.cxx @@ -1,4 +1,4 @@ -// Copyright (C) 2007-2014 CEA/DEN, EDF R&D, OPEN CASCADE +// Copyright (C) 2007-2016 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 @@ -32,12 +32,9 @@ #ifndef DISABLE_SALOMEOBJECT #include - #include // Open CASCADE Include - #include #include - #include #include #endif @@ -78,10 +75,25 @@ void LightApp_SelectionMgr::setSelected( const SUIT_DataOwnerPtrList& lst, const #ifndef DISABLE_SALOMEOBJECT /*! - Get all selected objects from selection manager + Get a sole selected objects from selection manager. If more than one object selected, return NULL. + Useful to optimize performance in case of large number of objects (IPAL0054049) */ -void LightApp_SelectionMgr::selectedObjects( SALOME_ListIO& theList, const QString& theType, +Handle(SALOME_InteractiveObject) + LightApp_SelectionMgr::soleSelectedObject( const QString& theType, const bool convertReferences ) const +{ + SALOME_ListIO list; + selectedObjects( list, theType, convertReferences, true ); + return list.Extent() == 1 ? list.First() : Handle(SALOME_InteractiveObject)(); +} + +/*! + Get all selected objects from selection manager +*/ +void LightApp_SelectionMgr::selectedObjects( SALOME_ListIO& theList, + const QString& theType, + const bool convertReferences, + const bool sole) const { LightApp_Study* study = dynamic_cast( application()->activeStudy() ); if ( !study ) @@ -91,7 +103,7 @@ void LightApp_SelectionMgr::selectedObjects( SALOME_ListIO& theList, const QStri QList selList; - if ( isActualSelectionCache( theType ) ) { + if ( !sole && isActualSelectionCache( theType )) { selList = selectionCache( theType ); } else { @@ -104,27 +116,27 @@ void LightApp_SelectionMgr::selectedObjects( SALOME_ListIO& theList, const QStri QSet aSet; for ( QStringList::iterator it = types.begin(); it != types.end(); ++it ) { SUIT_DataOwnerPtrList aList; - selected( aList, *it ); + selected( aList, *it, sole ); QList typeSelList; for ( SUIT_DataOwnerPtrList::const_iterator itr = aList.begin(); itr != aList.end(); ++itr ) { - const LightApp_DataOwner* owner = dynamic_cast( (*itr).operator->() ); - if ( !owner ) - continue; + const LightApp_DataOwner* owner = dynamic_cast( (*itr).operator->() ); + if ( !owner ) + continue; - if ( !aSet.contains( owner->entry() ) && !owner->IO().IsNull() ) { - selList.append( owner->IO() ); - aSet.insert( owner->entry() ); - } + if ( !aSet.contains( owner->entry() ) && !owner->IO().IsNull() ) { + selList.append( owner->IO() ); + aSet.insert( owner->entry() ); + } - typeSelList.append( owner->IO() ); + typeSelList.append( owner->IO() ); } - if ( isSelectionCacheEnabled() ) { - LightApp_SelectionMgr* that = (LightApp_SelectionMgr*)this; - that->myCacheSelection.insert( *it, typeSelList ); - that->myCacheTimes.insert( *it, QTime::currentTime() ); + if ( !sole && isSelectionCacheEnabled() ) { + LightApp_SelectionMgr* that = (LightApp_SelectionMgr*)this; + that->myCacheSelection.insert( *it, typeSelList ); + that->myCacheTimes.insert( *it, QTime::currentTime() ); } } } @@ -141,11 +153,11 @@ void LightApp_SelectionMgr::selectedObjects( SALOME_ListIO& theList, const QStri QString refEntry = study->referencedToEntry( entry ); if ( !entrySet.contains( refEntry ) ) { if ( refEntry != entry ) { - entry = refEntry; + entry = refEntry; QString component = study->componentDataType( entry ); - theList.Append( new SALOME_InteractiveObject( (const char*)entry.toLatin1(), - (const char*)component.toLatin1(), - ""/*refobj->Name().c_str()*/ ) ); + theList.Append( new SALOME_InteractiveObject( (const char*)entry.toUtf8(), + (const char*)component.toLatin1(), + ""/*refobj->Name().c_str()*/ ) ); } else if ( !io.IsNull() ) theList.Append( io ); @@ -156,6 +168,9 @@ void LightApp_SelectionMgr::selectedObjects( SALOME_ListIO& theList, const QStri entrySet.insert( entry ); } + + if ( sole && theList.Extent() > 1 ) + theList.Clear(); } /*! @@ -205,22 +220,22 @@ void LightApp_SelectionMgr::selectedObjects( QStringList& theList, const QString QStringList typeSelList; for ( SUIT_DataOwnerPtrList::const_iterator itr = aList.begin(); itr != aList.end(); ++itr ) { - const LightApp_DataOwner* owner = dynamic_cast( (*itr).operator->() ); - if ( !owner ) - continue; + const LightApp_DataOwner* owner = dynamic_cast( (*itr).operator->() ); + if ( !owner ) + continue; if ( !aSet.contains( owner->entry() ) ) { - selList.append( owner->entry() ); - aSet.insert( owner->entry() ); - } + selList.append( owner->entry() ); + aSet.insert( owner->entry() ); + } - typeSelList.append( owner->entry() ); + typeSelList.append( owner->entry() ); } if ( isSelectionCacheEnabled() ) { - LightApp_SelectionMgr* that = (LightApp_SelectionMgr*)this; - that->myCacheSelection.insert( *it, typeSelList ); - that->myCacheTimes.insert( *it, QTime::currentTime() ); + LightApp_SelectionMgr* that = (LightApp_SelectionMgr*)this; + that->myCacheSelection.insert( *it, typeSelList ); + that->myCacheTimes.insert( *it, QTime::currentTime() ); } } } @@ -410,7 +425,7 @@ void LightApp_SelectionMgr::selectedSubOwners( MapEntryOfMapOfInteger& theMap ) if ( subOwner ) { //#ifndef WIN32 - if ( !theMap.IsBound( TCollection_AsciiString(subOwner->entry().toLatin1().data()) ) ) + if ( !theMap.IsBound( TCollection_AsciiString(subOwner->entry().toUtf8().data()) ) ) //#else // if ( !theMap.IsBound( subOwner->entry().toLatin1().data() ) ) //#endif @@ -427,7 +442,7 @@ void LightApp_SelectionMgr::selectedSubOwners( MapEntryOfMapOfInteger& theMap ) anIndexes.Add( subOwner2->index() ); } // - theMap.Bind( subOwner->entry().toLatin1().data(), anIndexes ); + theMap.Bind( subOwner->entry().toUtf8().data(), anIndexes ); } } } @@ -459,9 +474,9 @@ void LightApp_SelectionMgr::setSelectionCacheEnabled( bool on ) #ifndef DISABLE_SALOMEOBJECT -QList LightApp_SelectionMgr::selectionCache( const QString& type ) const +QList LightApp_SelectionMgr::selectionCache( const QString& type ) const { - QList res; + QList res; QStringList types; if ( !type.isEmpty() ) @@ -474,10 +489,10 @@ QList LightApp_SelectionMgr::selectionCache( co if ( myCacheSelection.contains( *it ) ) { const SelList& lst = myCacheSelection[*it]; for ( SelList::const_iterator itr = lst.begin(); itr != lst.end(); ++itr ) { - if ( !(*itr).IsNull() && !set.contains( (*itr)->getEntry() ) ) { - res.append( *itr ); - set.insert( (*itr)->getEntry() ); - } + if ( !(*itr).IsNull() && !set.contains( (*itr)->getEntry() ) ) { + res.append( *itr ); + set.insert( (*itr)->getEntry() ); + } } } } @@ -501,10 +516,10 @@ QStringList LightApp_SelectionMgr::selectionCache( const QString& type ) const if ( myCacheSelection.contains( *it ) ) { const SelList& lst = myCacheSelection[*it]; for ( SelList::const_iterator itr = lst.begin(); itr != lst.end(); ++itr ) { - if ( !set.contains( *itr ) ) { - res.append( *itr ); - set.insert( *itr ); - } + if ( !set.contains( *itr ) ) { + res.append( *itr ); + set.insert( *itr ); + } } } }