X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FLightApp%2FLightApp_SelectionMgr.cxx;h=aeec9d101bcc39067f9ad73d1297b70776465291;hb=dc50effcf483f1521a619c370d9b85e588752acd;hp=1c9e38b863014c129327abe176660f6d2a9de163;hpb=f830c97c748d8f8a6a7eccc8e3a58e19066a1181;p=modules%2Fgui.git diff --git a/src/LightApp/LightApp_SelectionMgr.cxx b/src/LightApp/LightApp_SelectionMgr.cxx index 1c9e38b86..aeec9d101 100644 --- a/src/LightApp/LightApp_SelectionMgr.cxx +++ b/src/LightApp/LightApp_SelectionMgr.cxx @@ -1,21 +1,25 @@ -// Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D -// +// 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 +// // 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 +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// 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 +// 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 "LightApp_SelectionMgr.h" #include "LightApp_Study.h" @@ -24,23 +28,26 @@ #include "LightApp_Application.h" #include +#include #ifndef DISABLE_SALOMEOBJECT #include - #include // Open CASCADE Include - #include #include - #include + #include #endif +#include + /*! Constructor. */ LightApp_SelectionMgr::LightApp_SelectionMgr( LightApp_Application* app, const bool fb ) : SUIT_SelectionMgr( fb ), -myApp( app ) + myApp( app ), + myTimeStamp( QTime::currentTime() ), + myCacheState( false ) { } @@ -59,6 +66,13 @@ LightApp_Application* LightApp_SelectionMgr::application() const return myApp; } +void LightApp_SelectionMgr::setSelected( const SUIT_DataOwnerPtrList& lst, const bool append ) +{ + SUIT_SelectionMgr::setSelected( lst, append ); + + myTimeStamp = QTime::currentTime(); +} + #ifndef DISABLE_SALOMEOBJECT /*! Get all selected objects from selection manager @@ -66,47 +80,78 @@ LightApp_Application* LightApp_SelectionMgr::application() const void LightApp_SelectionMgr::selectedObjects( SALOME_ListIO& theList, const QString& theType, const bool convertReferences ) const { + LightApp_Study* study = dynamic_cast( application()->activeStudy() ); + if ( !study ) + return; + theList.Clear(); - SUIT_DataOwnerPtrList aList; - selected( aList, theType ); + QList selList; - QMap entryMap; + if ( isActualSelectionCache( theType ) ) { + selList = selectionCache( theType ); + } + else { + QStringList types; + if ( !theType.isEmpty() ) + types.append( theType ); + else + types = selectorTypes(); + + QSet aSet; + for ( QStringList::iterator it = types.begin(); it != types.end(); ++it ) { + SUIT_DataOwnerPtrList aList; + selected( aList, *it ); + + 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; + + if ( !aSet.contains( owner->entry() ) && !owner->IO().IsNull() ) { + selList.append( owner->IO() ); + aSet.insert( owner->entry() ); + } - QString entry, checkEntry; - for ( SUIT_DataOwnerPtrList::const_iterator itr = aList.begin(); itr != aList.end(); ++itr ) - { - const LightApp_DataOwner* owner = dynamic_cast( (*itr).operator->() ); - if( !owner ) - continue; + typeSelList.append( owner->IO() ); + } - LightApp_Study* study = dynamic_cast( application()->activeStudy() ); - if ( !study ) - return; + if ( isSelectionCacheEnabled() ) { + LightApp_SelectionMgr* that = (LightApp_SelectionMgr*)this; + that->myCacheSelection.insert( *it, typeSelList ); + that->myCacheTimes.insert( *it, QTime::currentTime() ); + } + } + } - entry = owner->entry(); + QSet entrySet; + for ( QList::const_iterator itr = selList.begin(); itr != selList.end(); ++itr ) + { + Handle(SALOME_InteractiveObject) io = *itr; + QString entry( io->getEntry() ); // Entry to check object uniqueness. // It is selected owner entry in the case, when we do not convert references, // and entry of a real object, when we convert references. - checkEntry = entry; if ( convertReferences ) { QString refEntry = study->referencedToEntry( entry ); - checkEntry = refEntry; - if ( !entryMap.contains( checkEntry ) ) { + if ( !entrySet.contains( refEntry ) ) { if ( refEntry != entry ) { - QString component = study->componentDataType( refEntry ); - theList.Append( new SALOME_InteractiveObject( refEntry, component, ""/*refobj->Name().c_str()*/ ) ); + entry = refEntry; + QString component = study->componentDataType( entry ); + theList.Append( new SALOME_InteractiveObject( (const char*)entry.toLatin1(), + (const char*)component.toLatin1(), + ""/*refobj->Name().c_str()*/ ) ); } - else if( !owner->IO().IsNull() ) - theList.Append( owner->IO() ); + else if ( !io.IsNull() ) + theList.Append( io ); } } - else { - if( !entryMap.contains( entry ) && !owner->IO().IsNull() ) - theList.Append( owner->IO() ); - } + else if ( !entrySet.contains( entry ) && !io.IsNull() ) + theList.Append( io ); - entryMap.insert(checkEntry, 1); + entrySet.insert( entry ); } } @@ -132,26 +177,66 @@ void LightApp_SelectionMgr::setSelectedObjects( const SALOME_ListIO& lst, const void LightApp_SelectionMgr::selectedObjects( QStringList& theList, const QString& theType, const bool convertReferences ) const { + LightApp_Study* study = dynamic_cast( application()->activeStudy() ); + if ( !study ) + return; + theList.clear(); - SUIT_DataOwnerPtrList aList; - selected( aList, theType ); + QStringList selList; - QString entry; - for ( SUIT_DataOwnerPtrList::const_iterator itr = aList.begin(); itr != aList.end(); ++itr ) - { - const LightApp_DataOwner* owner = dynamic_cast( (*itr).operator->() ); - if( !owner ) - continue; + if ( isActualSelectionCache( theType ) ) + selList = selectionCache( theType ); + else { + QStringList types; + if ( !theType.isEmpty() ) + types.append( theType ); + else + types = selectorTypes(); + + QSet aSet; + for ( QStringList::iterator it = types.begin(); it != types.end(); ++it ) { + SUIT_DataOwnerPtrList aList; + selected( aList, *it ); + + QStringList typeSelList; - LightApp_Study* study = dynamic_cast( application()->activeStudy() ); - if ( !study ) - return; + for ( SUIT_DataOwnerPtrList::const_iterator itr = aList.begin(); itr != aList.end(); ++itr ) { + const LightApp_DataOwner* owner = dynamic_cast( (*itr).operator->() ); + if ( !owner ) + continue; - entry = owner->entry(); - if( !theList.contains( entry ) ) - theList.append( entry ); + if ( !aSet.contains( owner->entry() ) ) { + selList.append( owner->entry() ); + aSet.insert( 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() ); + } + } + } + + theList = selList; +} + +/*! + Append selected objects. +*/ +void LightApp_SelectionMgr::setSelectedObjects( const QStringList& lst, const bool append ) +{ + SUIT_DataOwnerPtrList owners; + foreach( const QString& aValue, lst ) { + if ( !aValue.isNull() ) + owners.append( new LightApp_DataOwner( aValue ) ); } + + setSelected( owners, append ); } #endif @@ -163,6 +248,8 @@ void LightApp_SelectionMgr::selectionChanged( SUIT_Selector* theSel ) { SUIT_SelectionMgr::selectionChanged( theSel ); + myTimeStamp = QTime::currentTime(); + emit currentSelectionChanged(); } @@ -171,7 +258,7 @@ void LightApp_SelectionMgr::selectionChanged( SUIT_Selector* theSel ) /*! get map of indexes for the given SALOME_InteractiveObject */ -void LightApp_SelectionMgr::GetIndexes( const Handle(SALOME_InteractiveObject)& IObject, +void LightApp_SelectionMgr::GetIndexes( const Handle(SALOME_InteractiveObject)& IObject, TColStd_IndexedMapOfInteger& theIndex) { theIndex.Clear(); @@ -181,12 +268,10 @@ void LightApp_SelectionMgr::GetIndexes( const Handle(SALOME_InteractiveObject)& for ( SUIT_DataOwnerPtrList::const_iterator itr = aList.begin(); itr != aList.end(); ++itr ) { - const LightApp_DataSubOwner* subOwner = dynamic_cast( (*itr).operator->() ); - if ( subOwner ) - if ( subOwner->entry() == QString(IObject->getEntry()) ) - theIndex.Add( subOwner->index() ); + LightApp_DataSubOwner* subOwner = dynamic_cast( (*itr).operator->() ); + if ( subOwner && subOwner->entry() == QString(IObject->getEntry()) ) + theIndex.Add( subOwner->index() ); } - } /*! @@ -204,7 +289,7 @@ void LightApp_SelectionMgr::GetIndexes( const QString& theEntry, TColStd_Indexed const LightApp_DataSubOwner* subOwner = dynamic_cast( (*itr).operator->() ); if ( subOwner ) if ( subOwner->entry() == theEntry ) - theIndex.Add( subOwner->index() ); + theIndex.Add( subOwner->index() ); } } @@ -230,14 +315,14 @@ void LightApp_SelectionMgr::AddOrRemoveIndex( const Handle(SALOME_InteractiveObj const LightApp_DataOwner* owner = dynamic_cast( (*itr).operator->() ); if ( owner ) { - if ( owner->entry() != ioEntry ) - { - const LightApp_DataSubOwner* subOwner = dynamic_cast( owner ); - if ( subOwner ) - remainsOwners.append( new LightApp_DataSubOwner( subOwner->entry(), subOwner->index() ) ); - else - remainsOwners.append( new LightApp_DataOwner( owner->entry() ) ); - } + if ( owner->entry() != ioEntry ) + { + const LightApp_DataSubOwner* subOwner = dynamic_cast( owner ); + if ( subOwner ) + remainsOwners.append( new LightApp_DataSubOwner( subOwner->entry(), subOwner->index() ) ); + else + remainsOwners.append( new LightApp_DataOwner( owner->entry() ) ); + } } } } @@ -263,8 +348,8 @@ void LightApp_SelectionMgr::AddOrRemoveIndex( const Handle(SALOME_InteractiveObj /*! select 'subobjects' with given indexes */ -void LightApp_SelectionMgr::selectObjects( const Handle(SALOME_InteractiveObject)& IObject, - TColStd_IndexedMapOfInteger theIndex, bool append ) +void LightApp_SelectionMgr::selectObjects( const Handle(SALOME_InteractiveObject)& IObject, + TColStd_IndexedMapOfInteger theIndex, bool append ) { SUIT_DataOwnerPtrList aList; @@ -274,11 +359,10 @@ void LightApp_SelectionMgr::selectObjects( const Handle(SALOME_InteractiveObject { int i; for ( i = 1; i <= theIndex.Extent(); i++ ) - aList.append( new LightApp_DataSubOwner( QString(IObject->getEntry()), theIndex( i ) ) ); + aList.append( new LightApp_DataSubOwner( QString(IObject->getEntry()), theIndex( i ) ) ); } setSelected( aList, append ); - } /*! @@ -288,21 +372,20 @@ void LightApp_SelectionMgr::selectObjects( MapIOOfMapOfInteger theMapIO, bool ap { SUIT_DataOwnerPtrList aList; - MapIOOfMapOfInteger::Iterator it; - for ( it = theMapIO.begin(); it != theMapIO.end(); ++it ) + MapIOOfMapOfInteger::Iterator it(theMapIO); + for ( ; it.More(); it.Next() ) { - if ( it.data().IsEmpty() ) - aList.append( new LightApp_DataOwner( QString(it.key()->getEntry()) ) ); + if ( it.Value().IsEmpty() ) + aList.append( new LightApp_DataOwner( QString(it.Key()->getEntry()) ) ); else - { - int i; - for ( i = 1; i <= it.data().Extent(); i++ ) - aList.append( new LightApp_DataSubOwner( QString(it.key()->getEntry()), it.data()( i ) ) ); - } + { + int i; + for ( i = 1; i <= it.Value().Extent(); i++ ) + aList.append( new LightApp_DataSubOwner( QString(it.Key()->getEntry()), it.Value()( i ) ) ); + } } - - setSelected( aList, append ); + setSelected( aList, append ); } /*! @@ -310,7 +393,7 @@ void LightApp_SelectionMgr::selectObjects( MapIOOfMapOfInteger theMapIO, bool ap */ void LightApp_SelectionMgr::selectedSubOwners( MapEntryOfMapOfInteger& theMap ) { - theMap.clear(); + theMap.Clear(); TColStd_IndexedMapOfInteger anIndexes; @@ -321,12 +404,16 @@ void LightApp_SelectionMgr::selectedSubOwners( MapEntryOfMapOfInteger& theMap ) { const LightApp_DataSubOwner* subOwner = dynamic_cast( (*itr).operator->() ); - if ( subOwner ) + if ( subOwner ) { - if ( !theMap.contains( subOwner->entry() ) ) +//#ifndef WIN32 + if ( !theMap.IsBound( TCollection_AsciiString(subOwner->entry().toLatin1().data()) ) ) +//#else +// if ( !theMap.IsBound( subOwner->entry().toLatin1().data() ) ) +//#endif { - anIndexes.Clear(); - //Bug 17269: GetIndexes( subOwner->entry(), anIndexes ); + anIndexes.Clear(); + //Bug 17269: GetIndexes( subOwner->entry(), anIndexes ); //Bug 17269: To avoid multiple calling of selected(aList) for ( SUIT_DataOwnerPtrList::const_iterator itr2 = itr; itr2 != aList.end(); ++itr2 ) { @@ -337,10 +424,116 @@ void LightApp_SelectionMgr::selectedSubOwners( MapEntryOfMapOfInteger& theMap ) anIndexes.Add( subOwner2->index() ); } // - theMap.insert( subOwner->entry(), anIndexes ); + theMap.Bind( subOwner->entry().toLatin1().data(), anIndexes ); + } + } + } +} + +#endif + +void LightApp_SelectionMgr::clearSelectionCache() +{ + myCacheTimes.clear(); + myCacheSelection.clear(); +} + +bool LightApp_SelectionMgr::isSelectionCacheEnabled() const +{ + return myCacheState; +} + +void LightApp_SelectionMgr::setSelectionCacheEnabled( bool on ) +{ + if ( myCacheState == on ) + return; + + myCacheState = on; + + if ( !myCacheState ) + clearSelectionCache(); +} + +#ifndef DISABLE_SALOMEOBJECT + +QList LightApp_SelectionMgr::selectionCache( const QString& type ) const +{ + QList res; + + QStringList types; + if ( !type.isEmpty() ) + types.append( type ); + else + types = selectorTypes(); + + QSet set; + for ( QStringList::iterator it = types.begin(); it != types.end(); ++it ) { + 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() ); + } + } + } + } + return res; +} + +#else + +QStringList LightApp_SelectionMgr::selectionCache( const QString& type ) const +{ + QStringList res; + + QStringList types; + if ( !type.isEmpty() ) + types.append( type ); + else + types = selectorTypes(); + + QSet set; + for ( QStringList::iterator it = types.begin(); it != types.end(); ++it ) { + 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 ); + } } } } + return res; } #endif + +bool LightApp_SelectionMgr::isActualSelectionCache( const QString& type ) const +{ + bool ok = true; + + QStringList types; + if ( !type.isEmpty() ) + types.append( type ); + else + types = selectorTypes(); + + for ( QStringList::iterator it = types.begin(); it != types.end() && ok; ++it ) + ok = myCacheTimes.contains( *it ) && myCacheTimes[*it].isValid() && myCacheTimes[*it] >= myTimeStamp; + + return ok; +} + +QStringList LightApp_SelectionMgr::selectorTypes() const +{ + QStringList types; + QList selectorList; + selectors( selectorList ); + for ( QList::const_iterator it = selectorList.begin(); it != selectorList.end(); ++it ) { + if ( (*it)->isEnabled() ) + types.append( (*it)->type() ); + } + return types; +}