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& lst ) const
46 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( application()->activeStudy() );
50 _PTR(Study) aStudy ( appStudy->studyDS() );
54 SUIT_DataOwnerPtrList aList;
57 for ( SUIT_DataOwnerPtrList::const_iterator itr = aList.begin(); itr != aList.end(); ++itr )
59 const SalomeApp_DataOwner* owner = dynamic_cast<const SalomeApp_DataOwner*>( (*itr).operator->() );
61 lst.Append( owner->IO() );
64 if ( owner && dynamic_cast<const SalomeApp_DataSubOwner*>( owner ) )
65 { //get only subowners, insert into lst unique subowners (subowners with different entries)
66 if ( !anEntryList.contains( owner->entry() ) )
68 anEntryList.append( owner->entry() );
70 //construct SALOME_InteractiveObject with predefined entry
71 _PTR(SObject) anObj ( aStudy->FindObjectID( owner->entry().latin1() ) );
74 _PTR(SComponent) aFC (anObj->GetFatherComponent());
77 anIO = new SALOME_InteractiveObject( anObj->GetID().c_str(), aFC->ComponentDataType().c_str(), anObj->GetName().c_str() );
78 if ( anIO ) lst.Append( anIO );
84 { //get not subowners data owners
85 _PTR(SObject) anObj ( aStudy->FindObjectID( owner->entry().latin1() ) );
88 _PTR(SComponent) aFC (anObj->GetFatherComponent());
91 anIO = new SALOME_InteractiveObject( anObj->GetID().c_str(), aFC->ComponentDataType().c_str(), anObj->GetName().c_str() );
92 if ( anIO ) lst.Append( anIO );
100 void SalomeApp_SelectionMgr::setSelectedObjects( const SALOME_ListIO& lst, const bool append )
102 if ( !application() )
105 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( application()->activeStudy() );
109 _PTR(Study) aStudy ( appStudy->studyDS() );
113 SUIT_DataOwnerPtrList owners;
114 for ( SALOME_ListIteratorOfListIO it( lst ); it.More(); it.Next() )
116 if ( it.Value()->hasEntry() )
117 owners.append( new SalomeApp_DataOwner( it.Value()->getEntry() ) );
119 setSelected( owners, append );
122 void SalomeApp_SelectionMgr::selectionChanged( SUIT_Selector* theSel )
124 SUIT_SelectionMgr::selectionChanged( theSel );
126 emit currentSelectionChanged();
130 get map of indexes for the given SALOME_InteractiveObject
133 void SalomeApp_SelectionMgr::GetIndexes( const Handle(SALOME_InteractiveObject)& IObject,
134 TColStd_IndexedMapOfInteger& theIndex)
138 SUIT_DataOwnerPtrList aList;
141 for ( SUIT_DataOwnerPtrList::const_iterator itr = aList.begin(); itr != aList.end(); ++itr )
143 const SalomeApp_DataSubOwner* subOwner = dynamic_cast<const SalomeApp_DataSubOwner*>( (*itr).operator->() );
145 if ( subOwner->entry() == QString(IObject->getEntry()) )
146 theIndex.Add( subOwner->index() );
152 get map of indexes for the given entry of SALOME_InteractiveObject
155 void SalomeApp_SelectionMgr::GetIndexes( const QString& theEntry, TColStd_IndexedMapOfInteger& theIndex )
159 SUIT_DataOwnerPtrList aList;
162 for ( SUIT_DataOwnerPtrList::const_iterator itr = aList.begin(); itr != aList.end(); ++itr )
164 const SalomeApp_DataSubOwner* subOwner = dynamic_cast<const SalomeApp_DataSubOwner*>( (*itr).operator->() );
166 if ( subOwner->entry() == theEntry )
167 theIndex.Add( subOwner->index() );
172 bool SalomeApp_SelectionMgr::AddOrRemoveIndex( const Handle(SALOME_InteractiveObject)& IObject,
173 const TColStd_MapOfInteger& theIndexes,
176 SUIT_DataOwnerPtrList remainsOwners;
178 SUIT_DataOwnerPtrList aList;
182 for ( SUIT_DataOwnerPtrList::const_iterator itr = aList.begin(); itr != aList.end(); ++itr )
184 const SalomeApp_DataOwner* owner = dynamic_cast<const SalomeApp_DataOwner*>( (*itr).operator->() );
187 if ( owner->entry() != QString(IObject->getEntry()) )
189 const SalomeApp_DataSubOwner* subOwner = dynamic_cast<const SalomeApp_DataSubOwner*>( owner );
191 remainsOwners.append( new SalomeApp_DataSubOwner( subOwner->entry(), subOwner->index() ) );
193 remainsOwners.append( new SalomeApp_DataOwner( owner->entry() ) );
199 remainsOwners = aList;
201 TColStd_MapIteratorOfMapOfInteger It;
202 It.Initialize(theIndexes);
203 for(;It.More();It.Next())
204 remainsOwners.append( new SalomeApp_DataSubOwner( QString(IObject->getEntry()), It.Key() ) );
207 setSelected( remainsOwners, append );
209 emit currentSelectionChanged();
211 TColStd_IndexedMapOfInteger anIndexes;
212 GetIndexes( IObject, anIndexes );
213 return !anIndexes.IsEmpty();
218 select 'subobjects' with given indexes
221 void SalomeApp_SelectionMgr::selectObjects( const Handle(SALOME_InteractiveObject)& IObject,
222 TColStd_IndexedMapOfInteger theIndex, bool append )
224 SUIT_DataOwnerPtrList aList;
226 if ( theIndex.IsEmpty() )
227 aList.append( new SalomeApp_DataOwner( QString(IObject->getEntry()) ) );
231 for ( i = 1; i <= theIndex.Extent(); i++ )
232 aList.append( new SalomeApp_DataSubOwner( QString(IObject->getEntry()), theIndex( i ) ) );
235 setSelected( aList, append );
240 select 'subobjects' with given indexes
243 void SalomeApp_SelectionMgr::selectObjects( MapIOOfMapOfInteger theMapIO, bool append )
245 SUIT_DataOwnerPtrList aList;
247 MapIOOfMapOfInteger::Iterator it;
248 for ( it = theMapIO.begin(); it != theMapIO.end(); ++it )
250 if ( it.data().IsEmpty() )
251 aList.append( new SalomeApp_DataOwner( QString(it.key()->getEntry()) ) );
255 for ( i = 1; i <= it.data().Extent(); i++ )
256 aList.append( new SalomeApp_DataSubOwner( QString(it.key()->getEntry()), it.data()( i ) ) );
260 setSelected( aList, append );
265 get map of selected subowners : object's entry <-> map of indexes
268 void SalomeApp_SelectionMgr::selectedSubOwners( MapEntryOfMapOfInteger& theMap )
272 TColStd_IndexedMapOfInteger anIndexes;
274 SUIT_DataOwnerPtrList aList;
277 for ( SUIT_DataOwnerPtrList::const_iterator itr = aList.begin(); itr != aList.end(); ++itr )
279 const SalomeApp_DataSubOwner* subOwner = dynamic_cast<const SalomeApp_DataSubOwner*>( (*itr).operator->() );
282 if ( !theMap.contains( subOwner->entry() ) )
285 GetIndexes( subOwner->entry(), anIndexes );
286 theMap.insert( subOwner->entry(), anIndexes );