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"
37 #include "SALOME_ListIteratorOfListIO.hxx"
39 #include "SVTK_Selector.h"
40 #include "utilities.h"
54 ::SetSelectionMode(Selection_Mode theMode)
56 mySelectionMode = theMode;
65 myMapIOSubIndex.Clear();
68 //----------------------------------------------------------------------------
71 ::IsSelected(const Handle(SALOME_InteractiveObject)& theObject) const
73 SALOME_ListIteratorOfListIO anIter(myIObjects);
74 for(; anIter.More(); anIter.Next()){
75 if(theObject->isSame(anIter.Value())){
84 ::IsSelected(SALOME_Actor* theActor) const
86 const Handle(SALOME_InteractiveObject) anIO = theActor->getIO();
87 return IsSelected(anIO) && myIO2Actors.IsBound(anIO);
92 ::GetActor(const Handle(SALOME_InteractiveObject)& theIO) const
94 if(myIO2Actors.IsBound(theIO))
95 return myIO2Actors.Find(theIO).GetPointer();
99 //----------------------------------------------------------------------------
102 ::AddIObject(const Handle(SALOME_InteractiveObject)& theIO)
104 if(!IsSelected(theIO)){
105 myIObjects.Append(theIO);
113 ::AddIObject(SALOME_Actor* theActor)
115 const Handle(SALOME_InteractiveObject) anIO = theActor->getIO();
117 bool anIsIOBound = IsSelected(anIO);
119 myIObjects.Append(anIO);
121 bool anIsActorBound = myIO2Actors.IsBound(anIO);
123 myIO2Actors.Bind(anIO,theActor);
125 return !anIsIOBound || !anIsActorBound;
128 //----------------------------------------------------------------------------
131 ::RemoveIObject(const Handle(SALOME_InteractiveObject)& theIO)
133 bool anIsIOBound = false;
134 for(SALOME_ListIteratorOfListIO anIter(myIObjects); anIter.More(); anIter.Next()){
135 if(theIO->isSame(anIter.Value())){
136 if(myMapIOSubIndex.IsBound(theIO))
137 myMapIOSubIndex.UnBind(theIO);
138 myIObjects.Remove(anIter);
144 bool anIsActorBound = myIO2Actors.IsBound(theIO);
146 myIO2Actors.UnBind(theIO);
148 return anIsIOBound || anIsActorBound;
153 ::RemoveIObject(SALOME_Actor* theActor)
155 const Handle(SALOME_InteractiveObject) anIO = theActor->getIO();
157 bool anIsActorBound = myIO2Actors.IsBound(anIO);
159 myIO2Actors.UnBind(anIO);
161 bool anIsIOBound = false;
162 for(SALOME_ListIteratorOfListIO anIter(myIObjects); anIter.More(); anIter.Next()){
163 if(anIO->isSame(anIter.Value())){
164 if(myMapIOSubIndex.IsBound(anIO))
165 myMapIOSubIndex.UnBind(anIO);
166 myIObjects.Remove(anIter);
172 return anIsIOBound || anIsActorBound;
175 //----------------------------------------------------------------------------
178 ::StoredIObjects() const
185 ::IObjectCount() const
187 return myIObjects.Extent();
192 ::HasIndex( const Handle(SALOME_InteractiveObject)& theIO) const
194 return myMapIOSubIndex.IsBound(theIO);
199 ::GetIndex( const Handle(SALOME_InteractiveObject)& theIO,
200 TColStd_IndexedMapOfInteger& theIndex)
202 if(myMapIOSubIndex.IsBound(theIO))
203 theIndex = myMapIOSubIndex.Find(theIO);
210 ::IsIndexSelected(const Handle(SALOME_InteractiveObject)& theIO,
213 if( !myMapIOSubIndex.IsBound(theIO))
216 const TColStd_IndexedMapOfInteger& aMapIndex = myMapIOSubIndex.Find(theIO);
217 return aMapIndex.Contains(theIndex);
222 removeIndex(TColStd_IndexedMapOfInteger& theMapIndex,
225 int anId = theMapIndex.FindIndex(theIndex); // i==0 if Index is not in the MapIndex
227 // only the last key can be removed
228 int aLastId = theMapIndex.FindKey(theMapIndex.Extent());
230 theMapIndex.RemoveLast();
232 TColStd_IndexedMapOfInteger aNewMap;
233 aNewMap.ReSize(theMapIndex.Extent()-1);
234 for(int j = 1; j <= theMapIndex.Extent(); j++){
235 int anIndex = theMapIndex(j);
236 if ( anIndex != theIndex )
237 aNewMap.Add( anIndex );
239 theMapIndex = aNewMap;
248 ::AddOrRemoveIndex( const Handle(SALOME_InteractiveObject)& theIO,
249 const TColStd_IndexedMapOfInteger& theIndices,
252 TColStd_IndexedMapOfInteger empty;
253 if(!myMapIOSubIndex.IsBound(theIO))
254 myMapIOSubIndex.Bind(theIO, empty);
256 TColStd_IndexedMapOfInteger& aMapIndex = myMapIOSubIndex.ChangeFind(theIO);
257 aMapIndex = theIndices;
262 if(aMapIndex.IsEmpty()){
263 myMapIOSubIndex.UnBind(theIO);
264 RemoveIObject(theIO);
267 return !aMapIndex.IsEmpty();
273 ::AddOrRemoveIndex( const Handle(SALOME_InteractiveObject)& theIO,
274 const TColStd_MapOfInteger& theIndices,
277 TColStd_IndexedMapOfInteger empty;
278 if(!myMapIOSubIndex.IsBound(theIO))
279 myMapIOSubIndex.Bind(theIO, empty);
281 TColStd_IndexedMapOfInteger& aMapIndex = myMapIOSubIndex.ChangeFind(theIO);
286 for(TColStd_MapIteratorOfMapOfInteger anIter(theIndices); anIter.More(); anIter.Next())
287 aMapIndex.Add(anIter.Key());
289 if(aMapIndex.IsEmpty()){
290 myMapIOSubIndex.UnBind(theIO);
291 RemoveIObject(theIO);
294 return !aMapIndex.IsEmpty();
300 ::AddOrRemoveIndex( const Handle(SALOME_InteractiveObject)& theIO,
304 TColStd_IndexedMapOfInteger empty;
305 if(!myMapIOSubIndex.IsBound(theIO))
306 myMapIOSubIndex.Bind(theIO, empty);
308 TColStd_IndexedMapOfInteger& aMapIndex = myMapIOSubIndex.ChangeFind(theIO);
310 bool anIsConatains = aMapIndex.Contains( theIndex );
313 removeIndex( aMapIndex, theIndex );
319 aMapIndex.Add( theIndex );
321 if ( aMapIndex.IsEmpty() ) {
322 myMapIOSubIndex.UnBind(theIO);
323 RemoveIObject(theIO);
332 ::RemoveIndex( const Handle(SALOME_InteractiveObject)& theIO,
335 if ( myMapIOSubIndex.IsBound( theIO ) ) {
336 TColStd_IndexedMapOfInteger& aMapIndex = myMapIOSubIndex.ChangeFind( theIO );
337 removeIndex( aMapIndex, theIndex );
345 myMapIOSubIndex.Clear();