]> SALOME platform Git repositories - modules/gui.git/blob - src/SalomeApp/SalomeApp_SelectionMgr.cxx
Salome HOME
modified method getStudy
[modules/gui.git] / src / SalomeApp / SalomeApp_SelectionMgr.cxx
1 #include "SalomeApp_SelectionMgr.h"
2
3 #include "SalomeApp_Study.h"
4 #include "SalomeApp_DataOwner.h"
5 #include "SalomeApp_DataSubOwner.h"
6 #include "SalomeApp_Application.h"
7
8 #include <SUIT_Session.h>
9
10 #include <SALOME_ListIO.hxx>
11 #include <SALOME_ListIteratorOfListIO.hxx>
12
13 // Open CASCADE Include
14 #include <TColStd_MapOfInteger.hxx>
15 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
16 #include <TColStd_IndexedMapOfInteger.hxx>
17
18 #include "SALOMEDSClient.hxx"
19
20 /*!
21   Constructor.
22 */
23 SalomeApp_SelectionMgr::SalomeApp_SelectionMgr( SalomeApp_Application* app, const bool fb )
24 : SUIT_SelectionMgr( fb ),
25 myApp( app )
26 {
27 }
28
29 /*!
30   Destructor.
31 */
32 SalomeApp_SelectionMgr::~SalomeApp_SelectionMgr()
33 {
34 }
35
36 /*!
37   Gets application.
38 */
39 SalomeApp_Application* SalomeApp_SelectionMgr::application() const
40 {
41   return myApp;
42 }
43
44 /*!
45   Get all selected objects from selection manager
46 */
47 void SalomeApp_SelectionMgr::selectedObjects( SALOME_ListIO& theList, const QString& theType ) const
48 {
49   theList.Clear();
50
51   SUIT_DataOwnerPtrList aList;
52   selected( aList, theType );
53
54   QMap<QString,int> entryMap;
55
56   for ( SUIT_DataOwnerPtrList::const_iterator itr = aList.begin(); itr != aList.end(); ++itr )
57   {
58     const SalomeApp_DataOwner* owner = dynamic_cast<const SalomeApp_DataOwner*>( (*itr).operator->() );
59     if( !owner ) continue;
60     
61     if ( !entryMap.contains(owner->entry()) )
62       theList.Append( owner->IO() );
63     entryMap.insert(owner->entry(), 1);
64   }
65 }
66
67 /*!
68   Append selected objects.
69 */
70 void SalomeApp_SelectionMgr::setSelectedObjects( const SALOME_ListIO& lst, const bool append )
71 {
72   SUIT_DataOwnerPtrList owners;
73   for ( SALOME_ListIteratorOfListIO it( lst ); it.More(); it.Next() )
74   {
75     if ( it.Value()->hasEntry() )
76       owners.append( new SalomeApp_DataOwner( it.Value() ) );
77   }
78
79   setSelected( owners, append );
80 }
81
82 /*!
83   Emit current selection changed.
84 */
85 void SalomeApp_SelectionMgr::selectionChanged( SUIT_Selector* theSel )
86 {
87   SUIT_SelectionMgr::selectionChanged( theSel );
88
89   emit currentSelectionChanged();
90 }
91
92 /*!
93   get map of indexes for the given SALOME_InteractiveObject
94 */
95 void SalomeApp_SelectionMgr::GetIndexes( const Handle(SALOME_InteractiveObject)& IObject, 
96                                          TColStd_IndexedMapOfInteger& theIndex)
97 {
98   theIndex.Clear();
99
100   SUIT_DataOwnerPtrList aList;
101   selected( aList );
102
103   for ( SUIT_DataOwnerPtrList::const_iterator itr = aList.begin(); itr != aList.end(); ++itr )
104   {
105     const SalomeApp_DataSubOwner* subOwner = dynamic_cast<const SalomeApp_DataSubOwner*>( (*itr).operator->() );
106     if ( subOwner )
107       if ( subOwner->entry() == QString(IObject->getEntry()) )
108         theIndex.Add( subOwner->index() );
109   }
110   
111 }
112
113 /*!
114   get map of indexes for the given entry of SALOME_InteractiveObject
115 */
116 void SalomeApp_SelectionMgr::GetIndexes( const QString& theEntry, TColStd_IndexedMapOfInteger& theIndex )
117 {
118   theIndex.Clear();
119
120   SUIT_DataOwnerPtrList aList;
121   selected( aList );
122
123   for ( SUIT_DataOwnerPtrList::const_iterator itr = aList.begin(); itr != aList.end(); ++itr )
124   {
125     const SalomeApp_DataSubOwner* subOwner = dynamic_cast<const SalomeApp_DataSubOwner*>( (*itr).operator->() );
126     if ( subOwner )
127       if ( subOwner->entry() == theEntry )
128         theIndex.Add( subOwner->index() );
129   }
130
131 }
132
133 /*!
134   Add or remove interactive objects from selection manager.
135 */
136 bool SalomeApp_SelectionMgr::AddOrRemoveIndex( const Handle(SALOME_InteractiveObject)& IObject, 
137                                                const TColStd_MapOfInteger& theIndexes, 
138                                                bool modeShift)
139 {
140   SUIT_DataOwnerPtrList remainsOwners;
141   
142   SUIT_DataOwnerPtrList aList;
143   selected( aList );
144
145   if ( !modeShift ) {
146     for ( SUIT_DataOwnerPtrList::const_iterator itr = aList.begin(); itr != aList.end(); ++itr )
147     {
148       const SalomeApp_DataOwner* owner = dynamic_cast<const SalomeApp_DataOwner*>( (*itr).operator->() );
149       if ( owner ) 
150       {
151         if ( owner->entry() != QString(IObject->getEntry()) ) 
152         {         
153           const SalomeApp_DataSubOwner* subOwner = dynamic_cast<const SalomeApp_DataSubOwner*>( owner );
154           if ( subOwner )
155             remainsOwners.append( new SalomeApp_DataSubOwner( subOwner->entry(), subOwner->index() ) );
156           else
157             remainsOwners.append( new SalomeApp_DataOwner( owner->entry() ) );
158         }
159       }
160     }
161   }
162   else
163     remainsOwners = aList;
164
165   TColStd_MapIteratorOfMapOfInteger It;
166   It.Initialize(theIndexes);
167   for(;It.More();It.Next())
168     remainsOwners.append( new SalomeApp_DataSubOwner( QString(IObject->getEntry()), It.Key() ) );
169   
170   bool append = false;
171   setSelected( remainsOwners, append );
172
173   emit currentSelectionChanged();
174
175   TColStd_IndexedMapOfInteger anIndexes;
176   GetIndexes( IObject, anIndexes );
177   return !anIndexes.IsEmpty();
178
179 }
180
181 /*!
182   select 'subobjects' with given indexes
183 */
184 void SalomeApp_SelectionMgr::selectObjects( const Handle(SALOME_InteractiveObject)& IObject, 
185                                             TColStd_IndexedMapOfInteger theIndex, bool append )
186 {
187   SUIT_DataOwnerPtrList aList;
188
189   if ( theIndex.IsEmpty() )
190     aList.append( new SalomeApp_DataOwner( QString(IObject->getEntry()) ) );
191   else
192     {
193       int i;
194       for ( i = 1; i <= theIndex.Extent(); i++ )
195         aList.append( new SalomeApp_DataSubOwner( QString(IObject->getEntry()), theIndex( i ) ) );
196     }
197
198   setSelected( aList, append );
199
200 }
201
202 /*!
203   select 'subobjects' with given indexes
204 */
205 void SalomeApp_SelectionMgr::selectObjects( MapIOOfMapOfInteger theMapIO, bool append )
206 {
207   SUIT_DataOwnerPtrList aList;
208
209   MapIOOfMapOfInteger::Iterator it;
210   for ( it = theMapIO.begin(); it != theMapIO.end(); ++it ) 
211     {
212       if ( it.data().IsEmpty() )
213         aList.append( new SalomeApp_DataOwner( QString(it.key()->getEntry()) ) );
214       else
215         {
216           int i;
217           for ( i = 1; i <= it.data().Extent(); i++ )
218             aList.append( new SalomeApp_DataSubOwner( QString(it.key()->getEntry()), it.data()( i ) ) );
219         }
220     }
221   
222   setSelected( aList, append );
223
224 }
225
226 /*!
227   get map of selected subowners : object's entry <-> map of indexes
228 */
229 void SalomeApp_SelectionMgr::selectedSubOwners( MapEntryOfMapOfInteger& theMap )
230 {
231   theMap.clear();
232
233   TColStd_IndexedMapOfInteger anIndexes;
234
235   SUIT_DataOwnerPtrList aList;
236   selected( aList );
237
238   for ( SUIT_DataOwnerPtrList::const_iterator itr = aList.begin(); itr != aList.end(); ++itr )
239   {
240     const SalomeApp_DataSubOwner* subOwner = dynamic_cast<const SalomeApp_DataSubOwner*>( (*itr).operator->() );
241     if ( subOwner ) 
242     {
243       if ( !theMap.contains( subOwner->entry() ) )
244       {
245         anIndexes.Clear();
246         GetIndexes( subOwner->entry(), anIndexes );
247         theMap.insert( subOwner->entry(), anIndexes );
248       }
249     }
250   }
251 }