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);
131 myMapIOSubIndex.erase(theIO);
138 ::RemoveIObject(SALOME_Actor* theActor)
140 const Handle(SALOME_InteractiveObject) anIO = theActor->getIO();
142 bool anIsActorBound = myIO2Actors.find(anIO) != myIO2Actors.end();
144 myIO2Actors.erase(anIO);
146 return RemoveIObject(anIO) || anIsActorBound;
149 //----------------------------------------------------------------------------
152 ::StoredIObjects() const
154 myIObjectList.Clear();
155 TIObjects::const_iterator anIter = myIObjects.begin();
156 TIObjects::const_iterator anIterEnd = myIObjects.end();
157 for(; anIter != anIterEnd; anIter++)
158 myIObjectList.Append(*anIter);
160 return myIObjectList;
165 ::IObjectCount() const
167 return myIObjects.size();
172 ::HasIndex( const Handle(SALOME_InteractiveObject)& theIO) const
174 return myMapIOSubIndex.find(theIO) != myMapIOSubIndex.end();
179 ::GetIndex( const Handle(SALOME_InteractiveObject)& theIO,
180 TColStd_IndexedMapOfInteger& theIndex)
182 TMapIOSubIndex::const_iterator anIter = myMapIOSubIndex.find(theIO);
183 if(anIter != myMapIOSubIndex.end())
184 theIndex = anIter->second.myMap;
191 ::IsIndexSelected(const Handle(SALOME_InteractiveObject)& theIO,
194 TMapIOSubIndex::const_iterator anIter = myMapIOSubIndex.find(theIO);
195 if(anIter != myMapIOSubIndex.end()){
196 const TColStd_IndexedMapOfInteger& aMapIndex = anIter->second.myMap;
197 return aMapIndex.Contains(theIndex);
205 removeIndex(TColStd_IndexedMapOfInteger& theMapIndex,
208 int anId = theMapIndex.FindIndex(theIndex); // i==0 if Index is not in the MapIndex
210 // only the last key can be removed
211 int aLastId = theMapIndex.FindKey(theMapIndex.Extent());
213 theMapIndex.RemoveLast();
215 TColStd_IndexedMapOfInteger aNewMap;
216 aNewMap.ReSize(theMapIndex.Extent()-1);
217 for(int j = 1; j <= theMapIndex.Extent(); j++){
218 int anIndex = theMapIndex(j);
219 if ( anIndex != theIndex )
220 aNewMap.Add( anIndex );
222 theMapIndex = aNewMap;
231 ::AddOrRemoveIndex( const Handle(SALOME_InteractiveObject)& theIO,
232 const TColStd_IndexedMapOfInteger& theIndices,
235 TMapIOSubIndex::iterator aMapIter = myMapIOSubIndex.find(theIO);
236 if(aMapIter == myMapIOSubIndex.end()){
237 TIndexedMapOfInteger anEmpty;
238 aMapIter = myMapIOSubIndex.
239 insert(TMapIOSubIndex::value_type(theIO,anEmpty)).first;
241 TColStd_IndexedMapOfInteger& aMapIndex = aMapIter->second.myMap;
246 for(int i = 0, iEnd = theIndices.Extent(); i < iEnd; i++)
247 aMapIndex.Add(theIndices(i));
249 if(aMapIndex.IsEmpty())
250 RemoveIObject(theIO);
252 return !aMapIndex.IsEmpty();
258 ::AddOrRemoveIndex( const Handle(SALOME_InteractiveObject)& theIO,
259 const TColStd_MapOfInteger& theIndices,
262 TMapIOSubIndex::iterator aMapIter = myMapIOSubIndex.find(theIO);
263 if(aMapIter == myMapIOSubIndex.end()){
264 TIndexedMapOfInteger anEmpty;
265 aMapIter = myMapIOSubIndex.
266 insert(TMapIOSubIndex::value_type(theIO,anEmpty)).first;
268 TColStd_IndexedMapOfInteger& aMapIndex = aMapIter->second.myMap;
273 TColStd_MapIteratorOfMapOfInteger anIter(theIndices);
274 for(; anIter.More(); anIter.Next())
275 aMapIndex.Add(anIter.Key());
277 if(aMapIndex.IsEmpty())
278 RemoveIObject(theIO);
280 return !aMapIndex.IsEmpty();
286 ::AddOrRemoveIndex( const Handle(SALOME_InteractiveObject)& theIO,
290 TMapIOSubIndex::iterator anIter = myMapIOSubIndex.find(theIO);
291 if(anIter == myMapIOSubIndex.end()){
292 TIndexedMapOfInteger anEmpty;
293 anIter = myMapIOSubIndex.
294 insert(TMapIOSubIndex::value_type(theIO,anEmpty)).first;
296 TColStd_IndexedMapOfInteger& aMapIndex = anIter->second.myMap;
298 bool anIsConatains = aMapIndex.Contains(theIndex);
300 removeIndex(aMapIndex,theIndex);
306 aMapIndex.Add( theIndex );
308 if( aMapIndex.IsEmpty())
309 RemoveIObject(theIO);
317 ::RemoveIndex( const Handle(SALOME_InteractiveObject)& theIO,
320 if(IsIndexSelected(theIO,theIndex)){
321 TMapIOSubIndex::iterator anIter = myMapIOSubIndex.find(theIO);
322 TColStd_IndexedMapOfInteger& aMapIndex = anIter->second.myMap;
323 removeIndex(aMapIndex,theIndex);
331 myMapIOSubIndex.clear();