1 // SALOME SALOMEGUI : implementation of desktop and GUI kernel
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : SALOME_Selection.cxx
25 // Author : Nicolas REJNERI
30 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
31 #include <TColStd_IndexedMapOfInteger.hxx>
34 #include "SALOME_Actor.h"
35 #include "SVTK_ViewModel.h"
36 #include "SVTK_ViewWindow.h"
38 #include "SVTK_SelectorDef.h"
39 #include "utilities.h"
53 ::SetSelectionMode(Selection_Mode theMode)
55 mySelectionMode = theMode;
64 myMapIOSubIndex.clear();
67 //----------------------------------------------------------------------------
70 ::IsSelected(const Handle(SALOME_InteractiveObject)& theIO) const
72 return myIObjects.find(theIO) != myIObjects.end();
77 ::IsSelected(SALOME_Actor* theActor) const
79 const Handle(SALOME_InteractiveObject) anIO = theActor->getIO();
80 return IsSelected(anIO) && myIO2Actors.find(anIO) != myIO2Actors.end();
85 ::GetActor(const Handle(SALOME_InteractiveObject)& theIO) const
87 TIO2Actors::const_iterator anIter = myIO2Actors.find(theIO);
88 if(anIter != myIO2Actors.end())
89 return anIter->second.GetPointer();
93 //----------------------------------------------------------------------------
96 ::AddIObject(const Handle(SALOME_InteractiveObject)& theIO)
98 if(!IsSelected(theIO)){
99 myIObjects.insert(theIO);
107 ::AddIObject(SALOME_Actor* theActor)
109 const Handle(SALOME_InteractiveObject) anIO = theActor->getIO();
111 bool anIsIOBound = IsSelected(anIO);
113 myIObjects.insert(anIO);
115 bool anIsActorBound = myIO2Actors.find(anIO) != myIO2Actors.end();
117 myIO2Actors[anIO] = theActor;
119 return !anIsIOBound || !anIsActorBound;
122 //----------------------------------------------------------------------------
125 ::RemoveIObject(const Handle(SALOME_InteractiveObject)& theIO)
127 bool anIsIOBound = myIObjects.find(theIO) != myIObjects.end();
129 myIObjects.erase(theIO);
130 myIO2Actors.erase(theIO);
137 ::RemoveIObject(SALOME_Actor* theActor)
139 const Handle(SALOME_InteractiveObject) anIO = theActor->getIO();
141 bool anIsActorBound = myIO2Actors.find(anIO) != myIO2Actors.end();
143 myIO2Actors.erase(anIO);
145 return RemoveIObject(anIO) || anIsActorBound;
148 //----------------------------------------------------------------------------
151 ::StoredIObjects() const
153 myIObjectList.Clear();
154 TIObjects::const_iterator anIter = myIObjects.begin();
155 TIObjects::const_iterator anIterEnd = myIObjects.end();
156 for(; anIter != anIterEnd; anIter++)
157 myIObjectList.Append(*anIter);
159 return myIObjectList;
164 ::IObjectCount() const
166 return myIObjects.size();
171 ::HasIndex( const Handle(SALOME_InteractiveObject)& theIO) const
173 return myMapIOSubIndex.find(theIO) != myMapIOSubIndex.end();
178 ::GetIndex( const Handle(SALOME_InteractiveObject)& theIO,
179 TColStd_IndexedMapOfInteger& theIndex)
181 TMapIOSubIndex::const_iterator anIter = myMapIOSubIndex.find(theIO);
182 if(anIter != myMapIOSubIndex.end())
183 theIndex = anIter->second.myMap;
190 ::IsIndexSelected(const Handle(SALOME_InteractiveObject)& theIO,
193 TMapIOSubIndex::const_iterator anIter = myMapIOSubIndex.find(theIO);
194 if(anIter != myMapIOSubIndex.end()){
195 const TColStd_IndexedMapOfInteger& aMapIndex = anIter->second.myMap;
196 return aMapIndex.Contains(theIndex);
204 removeIndex(TColStd_IndexedMapOfInteger& theMapIndex,
207 int anId = theMapIndex.FindIndex(theIndex); // i==0 if Index is not in the MapIndex
209 // only the last key can be removed
210 int aLastId = theMapIndex.FindKey(theMapIndex.Extent());
212 theMapIndex.RemoveLast();
214 TColStd_IndexedMapOfInteger aNewMap;
215 aNewMap.ReSize(theMapIndex.Extent()-1);
216 for(int j = 1; j <= theMapIndex.Extent(); j++){
217 int anIndex = theMapIndex(j);
218 if ( anIndex != theIndex )
219 aNewMap.Add( anIndex );
221 theMapIndex = aNewMap;
230 ::AddOrRemoveIndex( const Handle(SALOME_InteractiveObject)& theIO,
231 const TColStd_IndexedMapOfInteger& theIndices,
234 TMapIOSubIndex::iterator aMapIter = myMapIOSubIndex.find(theIO);
235 if(aMapIter == myMapIOSubIndex.end()){
236 TIndexedMapOfInteger anEmpty;
237 aMapIter = myMapIOSubIndex.
238 insert(TMapIOSubIndex::value_type(theIO,anEmpty)).first;
240 TColStd_IndexedMapOfInteger& aMapIndex = aMapIter->second.myMap;
245 for(int i = 1, iEnd = theIndices.Extent(); i <= iEnd; i++)
246 aMapIndex.Add(theIndices(i));
248 if(aMapIndex.IsEmpty())
249 myMapIOSubIndex.erase(theIO);
251 return !aMapIndex.IsEmpty();
257 ::AddOrRemoveIndex( const Handle(SALOME_InteractiveObject)& theIO,
258 const TColStd_MapOfInteger& theIndices,
261 TMapIOSubIndex::iterator aMapIter = myMapIOSubIndex.find(theIO);
262 if(aMapIter == myMapIOSubIndex.end()){
263 TIndexedMapOfInteger anEmpty;
264 aMapIter = myMapIOSubIndex.
265 insert(TMapIOSubIndex::value_type(theIO,anEmpty)).first;
267 TColStd_IndexedMapOfInteger& aMapIndex = aMapIter->second.myMap;
272 TColStd_MapIteratorOfMapOfInteger anIter(theIndices);
273 for(; anIter.More(); anIter.Next())
274 aMapIndex.Add(anIter.Key());
276 if(aMapIndex.IsEmpty())
277 myMapIOSubIndex.erase(theIO);
279 return !aMapIndex.IsEmpty();
285 ::AddOrRemoveIndex( const Handle(SALOME_InteractiveObject)& theIO,
289 TMapIOSubIndex::iterator anIter = myMapIOSubIndex.find(theIO);
290 if(anIter == myMapIOSubIndex.end()){
291 TIndexedMapOfInteger anEmpty;
292 anIter = myMapIOSubIndex.
293 insert(TMapIOSubIndex::value_type(theIO,anEmpty)).first;
295 TColStd_IndexedMapOfInteger& aMapIndex = anIter->second.myMap;
297 bool anIsConatains = aMapIndex.Contains(theIndex);
299 removeIndex(aMapIndex,theIndex);
305 aMapIndex.Add( theIndex );
307 if( aMapIndex.IsEmpty())
308 myMapIOSubIndex.erase(theIO);
316 ::RemoveIndex( const Handle(SALOME_InteractiveObject)& theIO,
319 if(IsIndexSelected(theIO,theIndex)){
320 TMapIOSubIndex::iterator anIter = myMapIOSubIndex.find(theIO);
321 TColStd_IndexedMapOfInteger& aMapIndex = anIter->second.myMap;
322 removeIndex(aMapIndex,theIndex);
330 myMapIOSubIndex.clear();