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);
143 bool anIsActorBound = myIO2Actors.IsBound(theIO);
145 myIO2Actors.UnBind(theIO);
147 return anIsIOBound || anIsActorBound;
152 ::RemoveIObject(SALOME_Actor* theActor)
154 const Handle(SALOME_InteractiveObject) anIO = theActor->getIO();
156 bool anIsActorBound = myIO2Actors.IsBound(anIO);
158 myIO2Actors.UnBind(anIO);
160 bool anIsIOBound = false;
161 for(SALOME_ListIteratorOfListIO anIter(myIObjects); anIter.More(); anIter.Next()){
162 if(anIO->isSame(anIter.Value())){
163 if(myMapIOSubIndex.IsBound(anIO))
164 myMapIOSubIndex.UnBind(anIO);
165 myIObjects.Remove(anIter);
170 return anIsIOBound || anIsActorBound;
173 //----------------------------------------------------------------------------
176 ::StoredIObjects() const
183 ::IObjectCount() const
185 return myIObjects.Extent();
190 ::HasIndex( const Handle(SALOME_InteractiveObject)& theIO) const
192 return myMapIOSubIndex.IsBound(theIO);
197 ::GetIndex( const Handle(SALOME_InteractiveObject)& theIO,
198 TColStd_IndexedMapOfInteger& theIndex)
200 if(myMapIOSubIndex.IsBound(theIO))
201 theIndex = myMapIOSubIndex.Find(theIO);
208 ::IsIndexSelected(const Handle(SALOME_InteractiveObject)& theIO,
211 if( !myMapIOSubIndex.IsBound(theIO))
214 const TColStd_IndexedMapOfInteger& aMapIndex = myMapIOSubIndex.Find(theIO);
215 return aMapIndex.Contains(theIndex);
220 removeIndex(TColStd_IndexedMapOfInteger& theMapIndex,
223 int anId = theMapIndex.FindIndex(theIndex); // i==0 if Index is not in the MapIndex
225 // only the last key can be removed
226 int aLastId = theMapIndex.FindKey(theMapIndex.Extent());
228 theMapIndex.RemoveLast();
230 TColStd_IndexedMapOfInteger aNewMap;
231 aNewMap.ReSize(theMapIndex.Extent()-1);
232 for(int j = 1; j <= theMapIndex.Extent(); j++){
233 int anIndex = theMapIndex(j);
234 if ( anIndex != theIndex )
235 aNewMap.Add( anIndex );
237 theMapIndex = aNewMap;
246 ::AddOrRemoveIndex( const Handle(SALOME_InteractiveObject)& theIO,
247 const TColStd_IndexedMapOfInteger& theIndices,
250 TColStd_IndexedMapOfInteger empty;
251 if(!myMapIOSubIndex.IsBound(theIO))
252 myMapIOSubIndex.Bind(theIO, empty);
254 TColStd_IndexedMapOfInteger& aMapIndex = myMapIOSubIndex.ChangeFind(theIO);
255 aMapIndex = theIndices;
260 if(aMapIndex.IsEmpty()){
261 myMapIOSubIndex.UnBind(theIO);
262 RemoveIObject(theIO);
265 return !aMapIndex.IsEmpty();
271 ::AddOrRemoveIndex( const Handle(SALOME_InteractiveObject)& theIO,
272 const TColStd_MapOfInteger& theIndices,
275 TColStd_IndexedMapOfInteger empty;
276 if(!myMapIOSubIndex.IsBound(theIO))
277 myMapIOSubIndex.Bind(theIO, empty);
279 TColStd_IndexedMapOfInteger& aMapIndex = myMapIOSubIndex.ChangeFind(theIO);
284 for(TColStd_MapIteratorOfMapOfInteger anIter(theIndices); anIter.More(); anIter.Next())
285 aMapIndex.Add(anIter.Key());
287 if(aMapIndex.IsEmpty()){
288 myMapIOSubIndex.UnBind(theIO);
289 RemoveIObject(theIO);
292 return !aMapIndex.IsEmpty();
298 ::AddOrRemoveIndex( const Handle(SALOME_InteractiveObject)& theIO,
302 TColStd_IndexedMapOfInteger empty;
303 if(!myMapIOSubIndex.IsBound(theIO))
304 myMapIOSubIndex.Bind(theIO, empty);
306 TColStd_IndexedMapOfInteger& aMapIndex = myMapIOSubIndex.ChangeFind(theIO);
308 bool anIsConatains = aMapIndex.Contains( theIndex );
311 removeIndex( aMapIndex, theIndex );
317 aMapIndex.Add( theIndex );
319 if ( aMapIndex.IsEmpty() ) {
320 myMapIOSubIndex.UnBind(theIO);
321 RemoveIObject(theIO);
330 ::RemoveIndex( const Handle(SALOME_InteractiveObject)& theIO,
333 if ( myMapIOSubIndex.IsBound( theIO ) ) {
334 TColStd_IndexedMapOfInteger& aMapIndex = myMapIOSubIndex.ChangeFind( theIO );
335 removeIndex( aMapIndex, theIndex );
343 myMapIOSubIndex.Clear();