1 #include "SalomeApp_SelectionMgr.h"
3 #include "SalomeApp_Study.h"
4 #include "SalomeApp_DataOwner.h"
5 #include "SalomeApp_DataSubOwner.h"
6 #include "SalomeApp_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>
18 #include "SALOMEDSClient.hxx"
23 SalomeApp_SelectionMgr::SalomeApp_SelectionMgr( SalomeApp_Application* app, const bool fb )
24 : SUIT_SelectionMgr( fb ),
32 SalomeApp_SelectionMgr::~SalomeApp_SelectionMgr()
39 SalomeApp_Application* SalomeApp_SelectionMgr::application() const
45 Get all selected objects from selection manager
47 void SalomeApp_SelectionMgr::selectedObjects( SALOME_ListIO& theList, const QString& theType ) const
51 SUIT_DataOwnerPtrList aList;
52 selected( aList, theType );
54 QMap<QString,int> entryMap;
56 for ( SUIT_DataOwnerPtrList::const_iterator itr = aList.begin(); itr != aList.end(); ++itr )
58 const SalomeApp_DataOwner* owner = dynamic_cast<const SalomeApp_DataOwner*>( (*itr).operator->() );
59 if( !owner ) continue;
61 if ( !entryMap.contains(owner->entry()) )
62 theList.Append( owner->IO() );
63 entryMap.insert(owner->entry(), 1);
68 Append selected objects.
70 void SalomeApp_SelectionMgr::setSelectedObjects( const SALOME_ListIO& lst, const bool append )
72 SUIT_DataOwnerPtrList owners;
73 for ( SALOME_ListIteratorOfListIO it( lst ); it.More(); it.Next() )
75 if ( it.Value()->hasEntry() )
76 owners.append( new SalomeApp_DataOwner( it.Value() ) );
79 setSelected( owners, append );
83 Emit current selection changed.
85 void SalomeApp_SelectionMgr::selectionChanged( SUIT_Selector* theSel )
87 SUIT_SelectionMgr::selectionChanged( theSel );
89 emit currentSelectionChanged();
93 get map of indexes for the given SALOME_InteractiveObject
95 void SalomeApp_SelectionMgr::GetIndexes( const Handle(SALOME_InteractiveObject)& IObject,
96 TColStd_IndexedMapOfInteger& theIndex)
100 SUIT_DataOwnerPtrList aList;
103 for ( SUIT_DataOwnerPtrList::const_iterator itr = aList.begin(); itr != aList.end(); ++itr )
105 const SalomeApp_DataSubOwner* subOwner = dynamic_cast<const SalomeApp_DataSubOwner*>( (*itr).operator->() );
107 if ( subOwner->entry() == QString(IObject->getEntry()) )
108 theIndex.Add( subOwner->index() );
114 get map of indexes for the given entry of SALOME_InteractiveObject
116 void SalomeApp_SelectionMgr::GetIndexes( const QString& theEntry, TColStd_IndexedMapOfInteger& theIndex )
120 SUIT_DataOwnerPtrList aList;
123 for ( SUIT_DataOwnerPtrList::const_iterator itr = aList.begin(); itr != aList.end(); ++itr )
125 const SalomeApp_DataSubOwner* subOwner = dynamic_cast<const SalomeApp_DataSubOwner*>( (*itr).operator->() );
127 if ( subOwner->entry() == theEntry )
128 theIndex.Add( subOwner->index() );
134 Add or remove interactive objects from selection manager.
136 bool SalomeApp_SelectionMgr::AddOrRemoveIndex( const Handle(SALOME_InteractiveObject)& IObject,
137 const TColStd_MapOfInteger& theIndexes,
140 SUIT_DataOwnerPtrList remainsOwners;
142 SUIT_DataOwnerPtrList aList;
146 for ( SUIT_DataOwnerPtrList::const_iterator itr = aList.begin(); itr != aList.end(); ++itr )
148 const SalomeApp_DataOwner* owner = dynamic_cast<const SalomeApp_DataOwner*>( (*itr).operator->() );
151 if ( owner->entry() != QString(IObject->getEntry()) )
153 const SalomeApp_DataSubOwner* subOwner = dynamic_cast<const SalomeApp_DataSubOwner*>( owner );
155 remainsOwners.append( new SalomeApp_DataSubOwner( subOwner->entry(), subOwner->index() ) );
157 remainsOwners.append( new SalomeApp_DataOwner( owner->entry() ) );
163 remainsOwners = aList;
165 TColStd_MapIteratorOfMapOfInteger It;
166 It.Initialize(theIndexes);
167 for(;It.More();It.Next())
168 remainsOwners.append( new SalomeApp_DataSubOwner( QString(IObject->getEntry()), It.Key() ) );
171 setSelected( remainsOwners, append );
173 emit currentSelectionChanged();
175 TColStd_IndexedMapOfInteger anIndexes;
176 GetIndexes( IObject, anIndexes );
177 return !anIndexes.IsEmpty();
182 select 'subobjects' with given indexes
184 void SalomeApp_SelectionMgr::selectObjects( const Handle(SALOME_InteractiveObject)& IObject,
185 TColStd_IndexedMapOfInteger theIndex, bool append )
187 SUIT_DataOwnerPtrList aList;
189 if ( theIndex.IsEmpty() )
190 aList.append( new SalomeApp_DataOwner( QString(IObject->getEntry()) ) );
194 for ( i = 1; i <= theIndex.Extent(); i++ )
195 aList.append( new SalomeApp_DataSubOwner( QString(IObject->getEntry()), theIndex( i ) ) );
198 setSelected( aList, append );
203 select 'subobjects' with given indexes
205 void SalomeApp_SelectionMgr::selectObjects( MapIOOfMapOfInteger theMapIO, bool append )
207 SUIT_DataOwnerPtrList aList;
209 MapIOOfMapOfInteger::Iterator it;
210 for ( it = theMapIO.begin(); it != theMapIO.end(); ++it )
212 if ( it.data().IsEmpty() )
213 aList.append( new SalomeApp_DataOwner( QString(it.key()->getEntry()) ) );
217 for ( i = 1; i <= it.data().Extent(); i++ )
218 aList.append( new SalomeApp_DataSubOwner( QString(it.key()->getEntry()), it.data()( i ) ) );
222 setSelected( aList, append );
227 get map of selected subowners : object's entry <-> map of indexes
229 void SalomeApp_SelectionMgr::selectedSubOwners( MapEntryOfMapOfInteger& theMap )
233 TColStd_IndexedMapOfInteger anIndexes;
235 SUIT_DataOwnerPtrList aList;
238 for ( SUIT_DataOwnerPtrList::const_iterator itr = aList.begin(); itr != aList.end(); ++itr )
240 const SalomeApp_DataSubOwner* subOwner = dynamic_cast<const SalomeApp_DataSubOwner*>( (*itr).operator->() );
243 if ( !theMap.contains( subOwner->entry() ) )
246 GetIndexes( subOwner->entry(), anIndexes );
247 theMap.insert( subOwner->entry(), anIndexes );