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"
20 SalomeApp_SelectionMgr::SalomeApp_SelectionMgr( SalomeApp_Application* app, const bool fb )
21 : SUIT_SelectionMgr( fb ),
26 SalomeApp_SelectionMgr::~SalomeApp_SelectionMgr()
30 SalomeApp_Application* SalomeApp_SelectionMgr::application() const
36 get all selected objects from selection manager
39 void SalomeApp_SelectionMgr::selectedObjects( SALOME_ListIO& theList, const QString& theType ) const
43 SUIT_DataOwnerPtrList aList;
44 selected( aList, theType );
46 for ( SUIT_DataOwnerPtrList::const_iterator itr = aList.begin(); itr != aList.end(); ++itr )
48 const SalomeApp_DataOwner* owner = dynamic_cast<const SalomeApp_DataOwner*>( (*itr).operator->() );
50 theList.Append( owner->IO() );
54 void SalomeApp_SelectionMgr::setSelectedObjects( const SALOME_ListIO& lst, const bool append )
56 SUIT_DataOwnerPtrList owners;
57 for ( SALOME_ListIteratorOfListIO it( lst ); it.More(); it.Next() )
59 if ( it.Value()->hasEntry() )
60 owners.append( new SalomeApp_DataOwner( it.Value() ) );
63 setSelected( owners, append );
66 void SalomeApp_SelectionMgr::selectionChanged( SUIT_Selector* theSel )
68 SUIT_SelectionMgr::selectionChanged( theSel );
70 emit currentSelectionChanged();
74 get map of indexes for the given SALOME_InteractiveObject
77 void SalomeApp_SelectionMgr::GetIndexes( const Handle(SALOME_InteractiveObject)& IObject,
78 TColStd_IndexedMapOfInteger& theIndex)
82 SUIT_DataOwnerPtrList aList;
85 for ( SUIT_DataOwnerPtrList::const_iterator itr = aList.begin(); itr != aList.end(); ++itr )
87 const SalomeApp_DataSubOwner* subOwner = dynamic_cast<const SalomeApp_DataSubOwner*>( (*itr).operator->() );
89 if ( subOwner->entry() == QString(IObject->getEntry()) )
90 theIndex.Add( subOwner->index() );
96 get map of indexes for the given entry of SALOME_InteractiveObject
99 void SalomeApp_SelectionMgr::GetIndexes( const QString& theEntry, TColStd_IndexedMapOfInteger& theIndex )
103 SUIT_DataOwnerPtrList aList;
106 for ( SUIT_DataOwnerPtrList::const_iterator itr = aList.begin(); itr != aList.end(); ++itr )
108 const SalomeApp_DataSubOwner* subOwner = dynamic_cast<const SalomeApp_DataSubOwner*>( (*itr).operator->() );
110 if ( subOwner->entry() == theEntry )
111 theIndex.Add( subOwner->index() );
116 bool SalomeApp_SelectionMgr::AddOrRemoveIndex( const Handle(SALOME_InteractiveObject)& IObject,
117 const TColStd_MapOfInteger& theIndexes,
120 SUIT_DataOwnerPtrList remainsOwners;
122 SUIT_DataOwnerPtrList aList;
126 for ( SUIT_DataOwnerPtrList::const_iterator itr = aList.begin(); itr != aList.end(); ++itr )
128 const SalomeApp_DataOwner* owner = dynamic_cast<const SalomeApp_DataOwner*>( (*itr).operator->() );
131 if ( owner->entry() != QString(IObject->getEntry()) )
133 const SalomeApp_DataSubOwner* subOwner = dynamic_cast<const SalomeApp_DataSubOwner*>( owner );
135 remainsOwners.append( new SalomeApp_DataSubOwner( subOwner->entry(), subOwner->index() ) );
137 remainsOwners.append( new SalomeApp_DataOwner( owner->entry() ) );
143 remainsOwners = aList;
145 TColStd_MapIteratorOfMapOfInteger It;
146 It.Initialize(theIndexes);
147 for(;It.More();It.Next())
148 remainsOwners.append( new SalomeApp_DataSubOwner( QString(IObject->getEntry()), It.Key() ) );
151 setSelected( remainsOwners, append );
153 emit currentSelectionChanged();
155 TColStd_IndexedMapOfInteger anIndexes;
156 GetIndexes( IObject, anIndexes );
157 return !anIndexes.IsEmpty();
162 select 'subobjects' with given indexes
165 void SalomeApp_SelectionMgr::selectObjects( const Handle(SALOME_InteractiveObject)& IObject,
166 TColStd_IndexedMapOfInteger theIndex, bool append )
168 SUIT_DataOwnerPtrList aList;
170 if ( theIndex.IsEmpty() )
171 aList.append( new SalomeApp_DataOwner( QString(IObject->getEntry()) ) );
175 for ( i = 1; i <= theIndex.Extent(); i++ )
176 aList.append( new SalomeApp_DataSubOwner( QString(IObject->getEntry()), theIndex( i ) ) );
179 setSelected( aList, append );
184 select 'subobjects' with given indexes
187 void SalomeApp_SelectionMgr::selectObjects( MapIOOfMapOfInteger theMapIO, bool append )
189 SUIT_DataOwnerPtrList aList;
191 MapIOOfMapOfInteger::Iterator it;
192 for ( it = theMapIO.begin(); it != theMapIO.end(); ++it )
194 if ( it.data().IsEmpty() )
195 aList.append( new SalomeApp_DataOwner( QString(it.key()->getEntry()) ) );
199 for ( i = 1; i <= it.data().Extent(); i++ )
200 aList.append( new SalomeApp_DataSubOwner( QString(it.key()->getEntry()), it.data()( i ) ) );
204 setSelected( aList, append );
209 get map of selected subowners : object's entry <-> map of indexes
212 void SalomeApp_SelectionMgr::selectedSubOwners( MapEntryOfMapOfInteger& theMap )
216 TColStd_IndexedMapOfInteger anIndexes;
218 SUIT_DataOwnerPtrList aList;
221 for ( SUIT_DataOwnerPtrList::const_iterator itr = aList.begin(); itr != aList.end(); ++itr )
223 const SalomeApp_DataSubOwner* subOwner = dynamic_cast<const SalomeApp_DataSubOwner*>( (*itr).operator->() );
226 if ( !theMap.contains( subOwner->entry() ) )
229 GetIndexes( subOwner->entry(), anIndexes );
230 theMap.insert( subOwner->entry(), anIndexes );