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 QMap<QString,int> entryMap;
48 for ( SUIT_DataOwnerPtrList::const_iterator itr = aList.begin(); itr != aList.end(); ++itr )
50 const SalomeApp_DataOwner* owner = dynamic_cast<const SalomeApp_DataOwner*>( (*itr).operator->() );
51 if( !owner ) continue;
53 if ( !entryMap.contains(owner->entry()) )
54 theList.Append( owner->IO() );
55 entryMap.insert(owner->entry(), 1);
59 void SalomeApp_SelectionMgr::setSelectedObjects( const SALOME_ListIO& lst, const bool append )
61 SUIT_DataOwnerPtrList owners;
62 for ( SALOME_ListIteratorOfListIO it( lst ); it.More(); it.Next() )
64 if ( it.Value()->hasEntry() )
65 owners.append( new SalomeApp_DataOwner( it.Value() ) );
68 setSelected( owners, append );
71 void SalomeApp_SelectionMgr::selectionChanged( SUIT_Selector* theSel )
73 SUIT_SelectionMgr::selectionChanged( theSel );
75 emit currentSelectionChanged();
79 get map of indexes for the given SALOME_InteractiveObject
82 void SalomeApp_SelectionMgr::GetIndexes( const Handle(SALOME_InteractiveObject)& IObject,
83 TColStd_IndexedMapOfInteger& theIndex)
87 SUIT_DataOwnerPtrList aList;
90 for ( SUIT_DataOwnerPtrList::const_iterator itr = aList.begin(); itr != aList.end(); ++itr )
92 const SalomeApp_DataSubOwner* subOwner = dynamic_cast<const SalomeApp_DataSubOwner*>( (*itr).operator->() );
94 if ( subOwner->entry() == QString(IObject->getEntry()) )
95 theIndex.Add( subOwner->index() );
101 get map of indexes for the given entry of SALOME_InteractiveObject
104 void SalomeApp_SelectionMgr::GetIndexes( const QString& theEntry, TColStd_IndexedMapOfInteger& theIndex )
108 SUIT_DataOwnerPtrList aList;
111 for ( SUIT_DataOwnerPtrList::const_iterator itr = aList.begin(); itr != aList.end(); ++itr )
113 const SalomeApp_DataSubOwner* subOwner = dynamic_cast<const SalomeApp_DataSubOwner*>( (*itr).operator->() );
115 if ( subOwner->entry() == theEntry )
116 theIndex.Add( subOwner->index() );
121 bool SalomeApp_SelectionMgr::AddOrRemoveIndex( const Handle(SALOME_InteractiveObject)& IObject,
122 const TColStd_MapOfInteger& theIndexes,
125 SUIT_DataOwnerPtrList remainsOwners;
127 SUIT_DataOwnerPtrList aList;
131 for ( SUIT_DataOwnerPtrList::const_iterator itr = aList.begin(); itr != aList.end(); ++itr )
133 const SalomeApp_DataOwner* owner = dynamic_cast<const SalomeApp_DataOwner*>( (*itr).operator->() );
136 if ( owner->entry() != QString(IObject->getEntry()) )
138 const SalomeApp_DataSubOwner* subOwner = dynamic_cast<const SalomeApp_DataSubOwner*>( owner );
140 remainsOwners.append( new SalomeApp_DataSubOwner( subOwner->entry(), subOwner->index() ) );
142 remainsOwners.append( new SalomeApp_DataOwner( owner->entry() ) );
148 remainsOwners = aList;
150 TColStd_MapIteratorOfMapOfInteger It;
151 It.Initialize(theIndexes);
152 for(;It.More();It.Next())
153 remainsOwners.append( new SalomeApp_DataSubOwner( QString(IObject->getEntry()), It.Key() ) );
156 setSelected( remainsOwners, append );
158 emit currentSelectionChanged();
160 TColStd_IndexedMapOfInteger anIndexes;
161 GetIndexes( IObject, anIndexes );
162 return !anIndexes.IsEmpty();
167 select 'subobjects' with given indexes
170 void SalomeApp_SelectionMgr::selectObjects( const Handle(SALOME_InteractiveObject)& IObject,
171 TColStd_IndexedMapOfInteger theIndex, bool append )
173 SUIT_DataOwnerPtrList aList;
175 if ( theIndex.IsEmpty() )
176 aList.append( new SalomeApp_DataOwner( QString(IObject->getEntry()) ) );
180 for ( i = 1; i <= theIndex.Extent(); i++ )
181 aList.append( new SalomeApp_DataSubOwner( QString(IObject->getEntry()), theIndex( i ) ) );
184 setSelected( aList, append );
189 select 'subobjects' with given indexes
192 void SalomeApp_SelectionMgr::selectObjects( MapIOOfMapOfInteger theMapIO, bool append )
194 SUIT_DataOwnerPtrList aList;
196 MapIOOfMapOfInteger::Iterator it;
197 for ( it = theMapIO.begin(); it != theMapIO.end(); ++it )
199 if ( it.data().IsEmpty() )
200 aList.append( new SalomeApp_DataOwner( QString(it.key()->getEntry()) ) );
204 for ( i = 1; i <= it.data().Extent(); i++ )
205 aList.append( new SalomeApp_DataSubOwner( QString(it.key()->getEntry()), it.data()( i ) ) );
209 setSelected( aList, append );
214 get map of selected subowners : object's entry <-> map of indexes
217 void SalomeApp_SelectionMgr::selectedSubOwners( MapEntryOfMapOfInteger& theMap )
221 TColStd_IndexedMapOfInteger anIndexes;
223 SUIT_DataOwnerPtrList aList;
226 for ( SUIT_DataOwnerPtrList::const_iterator itr = aList.begin(); itr != aList.end(); ++itr )
228 const SalomeApp_DataSubOwner* subOwner = dynamic_cast<const SalomeApp_DataSubOwner*>( (*itr).operator->() );
231 if ( !theMap.contains( subOwner->entry() ) )
234 GetIndexes( subOwner->entry(), anIndexes );
235 theMap.insert( subOwner->entry(), anIndexes );