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"
52 ::SetSelectionMode(Selection_Mode theMode)
54 mySelectionMode = theMode;
63 myMapIOSubIndex.clear();
66 //----------------------------------------------------------------------------
69 ::IsSelected(const Handle(SALOME_InteractiveObject)& theIO) const
71 return myIObjects.find(theIO) != myIObjects.end();
76 ::IsSelected(SALOME_Actor* theActor) const
78 const Handle(SALOME_InteractiveObject) anIO = theActor->getIO();
79 return IsSelected(anIO) && myIO2Actors.find(anIO) != myIO2Actors.end();
84 ::GetActor(const Handle(SALOME_InteractiveObject)& theIO) const
86 TIO2Actors::const_iterator anIter = myIO2Actors.find(theIO);
87 if(anIter != myIO2Actors.end())
88 return anIter->second.GetPointer();
92 //----------------------------------------------------------------------------
95 ::AddIObject(const Handle(SALOME_InteractiveObject)& theIO)
97 if(!IsSelected(theIO)){
98 myIObjects.insert(theIO);
106 ::AddIObject(SALOME_Actor* theActor)
108 const Handle(SALOME_InteractiveObject) anIO = theActor->getIO();
110 bool anIsIOBound = IsSelected(anIO);
112 myIObjects.insert(anIO);
114 bool anIsActorBound = myIO2Actors.find(anIO) != myIO2Actors.end();
116 myIO2Actors[anIO] = theActor;
118 return !anIsIOBound || !anIsActorBound;
121 //----------------------------------------------------------------------------
124 ::RemoveIObject(const Handle(SALOME_InteractiveObject)& theIO)
126 bool anIsIOBound = myIObjects.find(theIO) != myIObjects.end();
128 myIObjects.erase(theIO);
129 myIO2Actors.erase(theIO);
136 ::RemoveIObject(SALOME_Actor* theActor)
138 const Handle(SALOME_InteractiveObject) anIO = theActor->getIO();
140 bool anIsActorBound = myIO2Actors.find(anIO) != myIO2Actors.end();
142 myIO2Actors.erase(anIO);
144 return RemoveIObject(anIO) || anIsActorBound;
147 //----------------------------------------------------------------------------
150 ::StoredIObjects() const
152 myIObjectList.Clear();
153 TIObjects::const_iterator anIter = myIObjects.begin();
154 TIObjects::const_iterator anIterEnd = myIObjects.end();
155 for(; anIter != anIterEnd; anIter++)
156 myIObjectList.Append(*anIter);
158 return myIObjectList;
163 ::IObjectCount() const
165 return myIObjects.size();
170 ::HasIndex( const Handle(SALOME_InteractiveObject)& theIO) const
172 return myMapIOSubIndex.find(theIO) != myMapIOSubIndex.end();
177 ::GetIndex( const Handle(SALOME_InteractiveObject)& theIO,
178 TColStd_IndexedMapOfInteger& theIndex)
180 TMapIOSubIndex::const_iterator anIter = myMapIOSubIndex.find(theIO);
181 if(anIter != myMapIOSubIndex.end())
182 theIndex = anIter->second.myMap;
189 ::IsIndexSelected(const Handle(SALOME_InteractiveObject)& theIO,
192 TMapIOSubIndex::const_iterator anIter = myMapIOSubIndex.find(theIO);
193 if(anIter != myMapIOSubIndex.end()){
194 const TColStd_IndexedMapOfInteger& aMapIndex = anIter->second.myMap;
195 return aMapIndex.Contains(theIndex);
203 removeIndex(TColStd_IndexedMapOfInteger& theMapIndex,
206 int anId = theMapIndex.FindIndex(theIndex); // i==0 if Index is not in the MapIndex
208 // only the last key can be removed
209 int aLastId = theMapIndex.FindKey(theMapIndex.Extent());
211 theMapIndex.RemoveLast();
213 TColStd_IndexedMapOfInteger aNewMap;
214 aNewMap.ReSize(theMapIndex.Extent()-1);
215 for(int j = 1; j <= theMapIndex.Extent(); j++){
216 int anIndex = theMapIndex(j);
217 if ( anIndex != theIndex )
218 aNewMap.Add( anIndex );
220 theMapIndex = aNewMap;
229 ::AddOrRemoveIndex( const Handle(SALOME_InteractiveObject)& theIO,
230 const TColStd_IndexedMapOfInteger& theIndices,
233 TMapIOSubIndex::iterator aMapIter = myMapIOSubIndex.find(theIO);
234 if(aMapIter == myMapIOSubIndex.end()){
235 TIndexedMapOfInteger anEmpty;
236 aMapIter = myMapIOSubIndex.
237 insert(TMapIOSubIndex::value_type(theIO,anEmpty)).first;
239 TColStd_IndexedMapOfInteger& aMapIndex = aMapIter->second.myMap;
244 for(int i = 1, iEnd = theIndices.Extent(); i <= iEnd; i++)
245 aMapIndex.Add(theIndices(i));
247 if(aMapIndex.IsEmpty())
248 myMapIOSubIndex.erase(theIO);
250 return !aMapIndex.IsEmpty();
256 ::AddOrRemoveIndex( const Handle(SALOME_InteractiveObject)& theIO,
257 const TColStd_MapOfInteger& theIndices,
260 TMapIOSubIndex::iterator aMapIter = myMapIOSubIndex.find(theIO);
261 if(aMapIter == myMapIOSubIndex.end()){
262 TIndexedMapOfInteger anEmpty;
263 aMapIter = myMapIOSubIndex.
264 insert(TMapIOSubIndex::value_type(theIO,anEmpty)).first;
266 TColStd_IndexedMapOfInteger& aMapIndex = aMapIter->second.myMap;
271 TColStd_MapIteratorOfMapOfInteger anIter(theIndices);
272 for(; anIter.More(); anIter.Next())
273 aMapIndex.Add(anIter.Key());
275 if(aMapIndex.IsEmpty())
276 myMapIOSubIndex.erase(theIO);
278 return !aMapIndex.IsEmpty();
284 ::AddOrRemoveIndex( const Handle(SALOME_InteractiveObject)& theIO,
288 TMapIOSubIndex::iterator anIter = myMapIOSubIndex.find(theIO);
289 if(anIter == myMapIOSubIndex.end()){
290 TIndexedMapOfInteger anEmpty;
291 anIter = myMapIOSubIndex.
292 insert(TMapIOSubIndex::value_type(theIO,anEmpty)).first;
294 TColStd_IndexedMapOfInteger& aMapIndex = anIter->second.myMap;
296 bool anIsConatains = aMapIndex.Contains(theIndex);
298 removeIndex(aMapIndex,theIndex);
304 aMapIndex.Add( theIndex );
306 if( aMapIndex.IsEmpty())
307 myMapIOSubIndex.erase(theIO);
315 ::RemoveIndex( const Handle(SALOME_InteractiveObject)& theIO,
318 if(IsIndexSelected(theIO,theIndex)){
319 TMapIOSubIndex::iterator anIter = myMapIOSubIndex.find(theIO);
320 TColStd_IndexedMapOfInteger& aMapIndex = anIter->second.myMap;
321 removeIndex(aMapIndex,theIndex);
329 myMapIOSubIndex.clear();