1 #include "LightApp_SelectionMgr.h"
3 #include "LightApp_Study.h"
4 #include "LightApp_DataOwner.h"
5 #include "LightApp_DataSubOwner.h"
6 #include "LightApp_Application.h"
8 #include <SUIT_Session.h>
10 #include <SALOME_ListIO.hxx>
11 #include <SALOME_ListIteratorOfListIO.hxx>
13 // Open CASCADE Include
14 #include <TColStd_MapOfInteger.hxx>
15 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
16 #include <TColStd_IndexedMapOfInteger.hxx>
21 LightApp_SelectionMgr::LightApp_SelectionMgr( LightApp_Application* app, const bool fb )
22 : SUIT_SelectionMgr( fb ),
30 LightApp_SelectionMgr::~LightApp_SelectionMgr()
37 LightApp_Application* LightApp_SelectionMgr::application() const
43 Get all selected objects from selection manager
45 void LightApp_SelectionMgr::selectedObjects( SALOME_ListIO& theList, const QString& theType,
46 const bool convertReferences ) const
50 SUIT_DataOwnerPtrList aList;
51 selected( aList, theType );
53 QMap<QString,int> entryMap;
56 for ( SUIT_DataOwnerPtrList::const_iterator itr = aList.begin(); itr != aList.end(); ++itr )
58 const LightApp_DataOwner* owner = dynamic_cast<const LightApp_DataOwner*>( (*itr).operator->() );
62 LightApp_Study* study = dynamic_cast<LightApp_Study*>( application()->activeStudy() );
66 entry = owner->entry();
67 if ( convertReferences ) {
68 QString refEntry = study->referencedToEntry( entry );
69 if( !entryMap.contains( entry ) ) {
70 if ( refEntry != entry ) {
71 QString component = study->componentDataType( refEntry );
72 theList.Append( new SALOME_InteractiveObject( refEntry, component, ""/*refobj->Name().c_str()*/ ) );
75 theList.Append( owner->IO() );
79 if( !entryMap.contains( entry ) )
80 theList.Append( owner->IO() );
83 entryMap.insert(owner->entry(), 1);
88 Append selected objects.
90 void LightApp_SelectionMgr::setSelectedObjects( const SALOME_ListIO& lst, const bool append )
92 SUIT_DataOwnerPtrList owners;
93 for ( SALOME_ListIteratorOfListIO it( lst ); it.More(); it.Next() )
95 if ( it.Value()->hasEntry() )
96 owners.append( new LightApp_DataOwner( it.Value() ) );
99 setSelected( owners, append );
103 Emit current selection changed.
105 void LightApp_SelectionMgr::selectionChanged( SUIT_Selector* theSel )
107 SUIT_SelectionMgr::selectionChanged( theSel );
109 emit currentSelectionChanged();
113 get map of indexes for the given SALOME_InteractiveObject
115 void LightApp_SelectionMgr::GetIndexes( const Handle(SALOME_InteractiveObject)& IObject,
116 TColStd_IndexedMapOfInteger& theIndex)
120 SUIT_DataOwnerPtrList aList;
123 for ( SUIT_DataOwnerPtrList::const_iterator itr = aList.begin(); itr != aList.end(); ++itr )
125 const LightApp_DataSubOwner* subOwner = dynamic_cast<const LightApp_DataSubOwner*>( (*itr).operator->() );
127 if ( subOwner->entry() == QString(IObject->getEntry()) )
128 theIndex.Add( subOwner->index() );
134 get map of indexes for the given entry of SALOME_InteractiveObject
136 void LightApp_SelectionMgr::GetIndexes( const QString& theEntry, TColStd_IndexedMapOfInteger& theIndex )
140 SUIT_DataOwnerPtrList aList;
143 for ( SUIT_DataOwnerPtrList::const_iterator itr = aList.begin(); itr != aList.end(); ++itr )
145 const LightApp_DataSubOwner* subOwner = dynamic_cast<const LightApp_DataSubOwner*>( (*itr).operator->() );
147 if ( subOwner->entry() == theEntry )
148 theIndex.Add( subOwner->index() );
154 Add or remove interactive objects from selection manager.
156 bool LightApp_SelectionMgr::AddOrRemoveIndex( const Handle(SALOME_InteractiveObject)& IObject,
157 const TColStd_MapOfInteger& theIndexes,
160 SUIT_DataOwnerPtrList remainsOwners;
162 SUIT_DataOwnerPtrList aList;
166 for ( SUIT_DataOwnerPtrList::const_iterator itr = aList.begin(); itr != aList.end(); ++itr )
168 const LightApp_DataOwner* owner = dynamic_cast<const LightApp_DataOwner*>( (*itr).operator->() );
171 if ( owner->entry() != QString(IObject->getEntry()) )
173 const LightApp_DataSubOwner* subOwner = dynamic_cast<const LightApp_DataSubOwner*>( owner );
175 remainsOwners.append( new LightApp_DataSubOwner( subOwner->entry(), subOwner->index() ) );
177 remainsOwners.append( new LightApp_DataOwner( owner->entry() ) );
183 remainsOwners = aList;
185 TColStd_MapIteratorOfMapOfInteger It;
186 It.Initialize(theIndexes);
187 for(;It.More();It.Next())
188 remainsOwners.append( new LightApp_DataSubOwner( QString(IObject->getEntry()), It.Key() ) );
191 setSelected( remainsOwners, append );
193 emit currentSelectionChanged();
195 TColStd_IndexedMapOfInteger anIndexes;
196 GetIndexes( IObject, anIndexes );
197 return !anIndexes.IsEmpty();
202 select 'subobjects' with given indexes
204 void LightApp_SelectionMgr::selectObjects( const Handle(SALOME_InteractiveObject)& IObject,
205 TColStd_IndexedMapOfInteger theIndex, bool append )
207 SUIT_DataOwnerPtrList aList;
209 if ( theIndex.IsEmpty() )
210 aList.append( new LightApp_DataOwner( QString(IObject->getEntry()) ) );
214 for ( i = 1; i <= theIndex.Extent(); i++ )
215 aList.append( new LightApp_DataSubOwner( QString(IObject->getEntry()), theIndex( i ) ) );
218 setSelected( aList, append );
223 select 'subobjects' with given indexes
225 void LightApp_SelectionMgr::selectObjects( MapIOOfMapOfInteger theMapIO, bool append )
227 SUIT_DataOwnerPtrList aList;
229 MapIOOfMapOfInteger::Iterator it;
230 for ( it = theMapIO.begin(); it != theMapIO.end(); ++it )
232 if ( it.data().IsEmpty() )
233 aList.append( new LightApp_DataOwner( QString(it.key()->getEntry()) ) );
237 for ( i = 1; i <= it.data().Extent(); i++ )
238 aList.append( new LightApp_DataSubOwner( QString(it.key()->getEntry()), it.data()( i ) ) );
242 setSelected( aList, append );
247 get map of selected subowners : object's entry <-> map of indexes
249 void LightApp_SelectionMgr::selectedSubOwners( MapEntryOfMapOfInteger& theMap )
253 TColStd_IndexedMapOfInteger anIndexes;
255 SUIT_DataOwnerPtrList aList;
258 for ( SUIT_DataOwnerPtrList::const_iterator itr = aList.begin(); itr != aList.end(); ++itr )
260 const LightApp_DataSubOwner* subOwner = dynamic_cast<const LightApp_DataSubOwner*>( (*itr).operator->() );
263 if ( !theMap.contains( subOwner->entry() ) )
266 GetIndexes( subOwner->entry(), anIndexes );
267 theMap.insert( subOwner->entry(), anIndexes );