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,
48 const bool convertReferences ) const
52 SUIT_DataOwnerPtrList aList;
53 selected( aList, theType );
55 QMap<QString,int> entryMap;
56 SalomeApp_Study* st = dynamic_cast<SalomeApp_Study*>( application()->activeStudy() );
60 _PTR(Study) dstudy = st->studyDS();
64 for ( SUIT_DataOwnerPtrList::const_iterator itr = aList.begin(); itr != aList.end(); ++itr )
66 const SalomeApp_DataOwner* owner = dynamic_cast<const SalomeApp_DataOwner*>( (*itr).operator->() );
70 _PTR(SObject) obj = dstudy->FindObjectID( owner->entry() );
71 if( obj && convertReferences && obj->ReferencedObject( refobj ) )
73 entry = refobj->GetID();
74 if( !entryMap.contains( entry ) )
75 theList.Append( new SALOME_InteractiveObject( refobj->GetID().c_str(),
76 refobj->GetFatherComponent()->ComponentDataType().c_str(),
77 refobj->Name().c_str() ) );
81 entry = owner->entry();
82 if( !entryMap.contains( entry ) )
83 theList.Append( owner->IO() );
86 entryMap.insert( entry , 1);
91 Append selected objects.
93 void SalomeApp_SelectionMgr::setSelectedObjects( const SALOME_ListIO& lst, const bool append )
95 SUIT_DataOwnerPtrList owners;
96 for ( SALOME_ListIteratorOfListIO it( lst ); it.More(); it.Next() )
98 if ( it.Value()->hasEntry() )
99 owners.append( new SalomeApp_DataOwner( it.Value() ) );
102 setSelected( owners, append );
106 Emit current selection changed.
108 void SalomeApp_SelectionMgr::selectionChanged( SUIT_Selector* theSel )
110 SUIT_SelectionMgr::selectionChanged( theSel );
112 emit currentSelectionChanged();
116 get map of indexes for the given SALOME_InteractiveObject
118 void SalomeApp_SelectionMgr::GetIndexes( const Handle(SALOME_InteractiveObject)& IObject,
119 TColStd_IndexedMapOfInteger& theIndex)
123 SUIT_DataOwnerPtrList aList;
126 for ( SUIT_DataOwnerPtrList::const_iterator itr = aList.begin(); itr != aList.end(); ++itr )
128 const SalomeApp_DataSubOwner* subOwner = dynamic_cast<const SalomeApp_DataSubOwner*>( (*itr).operator->() );
130 if ( subOwner->entry() == QString(IObject->getEntry()) )
131 theIndex.Add( subOwner->index() );
137 get map of indexes for the given entry of SALOME_InteractiveObject
139 void SalomeApp_SelectionMgr::GetIndexes( const QString& theEntry, TColStd_IndexedMapOfInteger& theIndex )
143 SUIT_DataOwnerPtrList aList;
146 for ( SUIT_DataOwnerPtrList::const_iterator itr = aList.begin(); itr != aList.end(); ++itr )
148 const SalomeApp_DataSubOwner* subOwner = dynamic_cast<const SalomeApp_DataSubOwner*>( (*itr).operator->() );
150 if ( subOwner->entry() == theEntry )
151 theIndex.Add( subOwner->index() );
157 Add or remove interactive objects from selection manager.
159 bool SalomeApp_SelectionMgr::AddOrRemoveIndex( const Handle(SALOME_InteractiveObject)& IObject,
160 const TColStd_MapOfInteger& theIndexes,
163 SUIT_DataOwnerPtrList remainsOwners;
165 SUIT_DataOwnerPtrList aList;
169 for ( SUIT_DataOwnerPtrList::const_iterator itr = aList.begin(); itr != aList.end(); ++itr )
171 const SalomeApp_DataOwner* owner = dynamic_cast<const SalomeApp_DataOwner*>( (*itr).operator->() );
174 if ( owner->entry() != QString(IObject->getEntry()) )
176 const SalomeApp_DataSubOwner* subOwner = dynamic_cast<const SalomeApp_DataSubOwner*>( owner );
178 remainsOwners.append( new SalomeApp_DataSubOwner( subOwner->entry(), subOwner->index() ) );
180 remainsOwners.append( new SalomeApp_DataOwner( owner->entry() ) );
186 remainsOwners = aList;
188 TColStd_MapIteratorOfMapOfInteger It;
189 It.Initialize(theIndexes);
190 for(;It.More();It.Next())
191 remainsOwners.append( new SalomeApp_DataSubOwner( QString(IObject->getEntry()), It.Key() ) );
194 setSelected( remainsOwners, append );
196 emit currentSelectionChanged();
198 TColStd_IndexedMapOfInteger anIndexes;
199 GetIndexes( IObject, anIndexes );
200 return !anIndexes.IsEmpty();
205 select 'subobjects' with given indexes
207 void SalomeApp_SelectionMgr::selectObjects( const Handle(SALOME_InteractiveObject)& IObject,
208 TColStd_IndexedMapOfInteger theIndex, bool append )
210 SUIT_DataOwnerPtrList aList;
212 if ( theIndex.IsEmpty() )
213 aList.append( new SalomeApp_DataOwner( QString(IObject->getEntry()) ) );
217 for ( i = 1; i <= theIndex.Extent(); i++ )
218 aList.append( new SalomeApp_DataSubOwner( QString(IObject->getEntry()), theIndex( i ) ) );
221 setSelected( aList, append );
226 select 'subobjects' with given indexes
228 void SalomeApp_SelectionMgr::selectObjects( MapIOOfMapOfInteger theMapIO, bool append )
230 SUIT_DataOwnerPtrList aList;
232 MapIOOfMapOfInteger::Iterator it;
233 for ( it = theMapIO.begin(); it != theMapIO.end(); ++it )
235 if ( it.data().IsEmpty() )
236 aList.append( new SalomeApp_DataOwner( QString(it.key()->getEntry()) ) );
240 for ( i = 1; i <= it.data().Extent(); i++ )
241 aList.append( new SalomeApp_DataSubOwner( QString(it.key()->getEntry()), it.data()( i ) ) );
245 setSelected( aList, append );
250 get map of selected subowners : object's entry <-> map of indexes
252 void SalomeApp_SelectionMgr::selectedSubOwners( MapEntryOfMapOfInteger& theMap )
256 TColStd_IndexedMapOfInteger anIndexes;
258 SUIT_DataOwnerPtrList aList;
261 for ( SUIT_DataOwnerPtrList::const_iterator itr = aList.begin(); itr != aList.end(); ++itr )
263 const SalomeApp_DataSubOwner* subOwner = dynamic_cast<const SalomeApp_DataSubOwner*>( (*itr).operator->() );
266 if ( !theMap.contains( subOwner->entry() ) )
269 GetIndexes( subOwner->entry(), anIndexes );
270 theMap.insert( subOwner->entry(), anIndexes );