-// 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
#ifndef DISABLE_SALOMEOBJECT
#include <SALOME_ListIO.hxx>
- #include <SALOME_ListIteratorOfListIO.hxx>
// Open CASCADE Include
- #include <TColStd_MapOfInteger.hxx>
#include <TColStd_MapIteratorOfMapOfInteger.hxx>
- #include <TColStd_IndexedMapOfInteger.hxx>
#include <TCollection_AsciiString.hxx>
#endif
#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<LightApp_Study*>( application()->activeStudy() );
if ( !study )
QList<Handle(SALOME_InteractiveObject)> selList;
- if ( isActualSelectionCache( theType ) ) {
+ if ( !sole && isActualSelectionCache( theType )) {
selList = selectionCache( theType );
}
else {
QSet<QString> aSet;
for ( QStringList::iterator it = types.begin(); it != types.end(); ++it ) {
SUIT_DataOwnerPtrList aList;
- selected( aList, *it );
+ selected( aList, *it, sole );
QList<Handle(SALOME_InteractiveObject)> typeSelList;
for ( SUIT_DataOwnerPtrList::const_iterator itr = aList.begin(); itr != aList.end(); ++itr ) {
- const LightApp_DataOwner* owner = dynamic_cast<const LightApp_DataOwner*>( (*itr).operator->() );
- if ( !owner )
- continue;
+ const LightApp_DataOwner* owner = dynamic_cast<const LightApp_DataOwner*>( (*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() );
}
}
}
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 );
entrySet.insert( entry );
}
+
+ if ( sole && theList.Extent() > 1 )
+ theList.Clear();
}
/*!
QStringList typeSelList;
for ( SUIT_DataOwnerPtrList::const_iterator itr = aList.begin(); itr != aList.end(); ++itr ) {
- const LightApp_DataOwner* owner = dynamic_cast<const LightApp_DataOwner*>( (*itr).operator->() );
- if ( !owner )
- continue;
+ const LightApp_DataOwner* owner = dynamic_cast<const LightApp_DataOwner*>( (*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() );
}
}
}
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
anIndexes.Add( subOwner2->index() );
}
//
- theMap.Bind( subOwner->entry().toLatin1().data(), anIndexes );
+ theMap.Bind( subOwner->entry().toUtf8().data(), anIndexes );
}
}
}
#ifndef DISABLE_SALOMEOBJECT
-QList<Handle_SALOME_InteractiveObject> LightApp_SelectionMgr::selectionCache( const QString& type ) const
+QList<Handle(SALOME_InteractiveObject)> LightApp_SelectionMgr::selectionCache( const QString& type ) const
{
- QList<Handle_SALOME_InteractiveObject> res;
+ QList<Handle(SALOME_InteractiveObject)> res;
QStringList types;
if ( !type.isEmpty() )
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() );
+ }
}
}
}
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 );
+ }
}
}
}