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 QValueList< QString > anEntryList;
58 Handle(SALOME_InteractiveObject) anIO;
60 for ( SUIT_DataOwnerPtrList::const_iterator itr = aList.begin(); itr != aList.end(); ++itr )
62 const SalomeApp_DataOwner* owner = dynamic_cast<const SalomeApp_DataOwner*>( (*itr).operator->() );
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 );
99 void SalomeApp_SelectionMgr::setSelectedObjects( const SALOME_ListIO& lst, const bool append )
101 if ( !application() )
104 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( application()->activeStudy() );
108 _PTR(Study) aStudy ( appStudy->studyDS() );
112 SUIT_DataOwnerPtrList owners;
113 for ( SALOME_ListIteratorOfListIO it( lst ); it.More(); it.Next() )
115 if ( it.Value()->hasEntry() )
116 owners.append( new SalomeApp_DataOwner( it.Value()->getEntry() ) );
118 setSelected( owners, append );
121 void SalomeApp_SelectionMgr::selectionChanged( SUIT_Selector* theSel )
123 SUIT_SelectionMgr::selectionChanged( theSel );
125 emit currentSelectionChanged();
129 get map of indexes for the given SALOME_InteractiveObject
132 void SalomeApp_SelectionMgr::GetIndexes( const Handle(SALOME_InteractiveObject)& IObject,
133 TColStd_IndexedMapOfInteger& theIndex)
137 SUIT_DataOwnerPtrList aList;
140 for ( SUIT_DataOwnerPtrList::const_iterator itr = aList.begin(); itr != aList.end(); ++itr )
142 const SalomeApp_DataSubOwner* subOwner = dynamic_cast<const SalomeApp_DataSubOwner*>( (*itr).operator->() );
144 if ( subOwner->entry() == QString(IObject->getEntry()) )
145 theIndex.Add( subOwner->index() );
151 get map of indexes for the given entry of SALOME_InteractiveObject
154 void SalomeApp_SelectionMgr::GetIndexes( const QString& theEntry, TColStd_IndexedMapOfInteger& theIndex )
158 SUIT_DataOwnerPtrList aList;
161 for ( SUIT_DataOwnerPtrList::const_iterator itr = aList.begin(); itr != aList.end(); ++itr )
163 const SalomeApp_DataSubOwner* subOwner = dynamic_cast<const SalomeApp_DataSubOwner*>( (*itr).operator->() );
165 if ( subOwner->entry() == theEntry )
166 theIndex.Add( subOwner->index() );
171 bool SalomeApp_SelectionMgr::AddOrRemoveIndex( const Handle(SALOME_InteractiveObject)& IObject,
172 const TColStd_MapOfInteger& theIndexes,
175 SUIT_DataOwnerPtrList remainsOwners;
177 SUIT_DataOwnerPtrList aList;
181 for ( SUIT_DataOwnerPtrList::const_iterator itr = aList.begin(); itr != aList.end(); ++itr )
183 const SalomeApp_DataOwner* owner = dynamic_cast<const SalomeApp_DataOwner*>( (*itr).operator->() );
186 if ( owner->entry() != QString(IObject->getEntry()) )
188 const SalomeApp_DataSubOwner* subOwner = dynamic_cast<const SalomeApp_DataSubOwner*>( owner );
190 remainsOwners.append( new SalomeApp_DataSubOwner( subOwner->entry(), subOwner->index() ) );
192 remainsOwners.append( new SalomeApp_DataOwner( owner->entry() ) );
198 remainsOwners = aList;
200 TColStd_MapIteratorOfMapOfInteger It;
201 It.Initialize(theIndexes);
202 for(;It.More();It.Next())
203 remainsOwners.append( new SalomeApp_DataSubOwner( QString(IObject->getEntry()), It.Key() ) );
206 setSelected( remainsOwners, append );
208 emit currentSelectionChanged();
210 TColStd_IndexedMapOfInteger anIndexes;
211 GetIndexes( IObject, anIndexes );
212 return !anIndexes.IsEmpty();
217 select 'subobjects' with given indexes
220 void SalomeApp_SelectionMgr::selectObjects( const Handle(SALOME_InteractiveObject)& IObject,
221 TColStd_IndexedMapOfInteger theIndex, bool append )
223 SUIT_DataOwnerPtrList aList;
225 if ( theIndex.IsEmpty() )
226 aList.append( new SalomeApp_DataOwner( QString(IObject->getEntry()) ) );
230 for ( i = 1; i <= theIndex.Extent(); i++ )
231 aList.append( new SalomeApp_DataSubOwner( QString(IObject->getEntry()), theIndex( i ) ) );
234 setSelected( aList, append );
239 select 'subobjects' with given indexes
242 void SalomeApp_SelectionMgr::selectObjects( MapIOOfMapOfInteger theMapIO, bool append )
244 SUIT_DataOwnerPtrList aList;
246 MapIOOfMapOfInteger::Iterator it;
247 for ( it = theMapIO.begin(); it != theMapIO.end(); ++it )
249 if ( it.data().IsEmpty() )
250 aList.append( new SalomeApp_DataOwner( QString(it.key()->getEntry()) ) );
254 for ( i = 1; i <= it.data().Extent(); i++ )
255 aList.append( new SalomeApp_DataSubOwner( QString(it.key()->getEntry()), it.data()( i ) ) );
259 setSelected( aList, append );
264 get map of selected subowners : object's entry <-> map of indexes
267 void SalomeApp_SelectionMgr::selectedSubOwners( MapEntryOfMapOfInteger& theMap )
271 TColStd_IndexedMapOfInteger anIndexes;
273 SUIT_DataOwnerPtrList aList;
276 for ( SUIT_DataOwnerPtrList::const_iterator itr = aList.begin(); itr != aList.end(); ++itr )
278 const SalomeApp_DataSubOwner* subOwner = dynamic_cast<const SalomeApp_DataSubOwner*>( (*itr).operator->() );
281 if ( !theMap.contains( subOwner->entry() ) )
284 GetIndexes( subOwner->entry(), anIndexes );
285 theMap.insert( subOwner->entry(), anIndexes );