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 "SVTK_SelectorDef.h"
32 #include "SALOME_Actor.h"
34 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
35 #include <TColStd_IndexedMapOfInteger.hxx>
37 #include <vtkCallbackCommand.h>
43 return new SVTK_SelectorDef();
46 //----------------------------------------------------------------------------
50 mySelectionMode = ActorSelection;
58 //----------------------------------------------------------------------------
63 this->InvokeEvent(vtkCommand::StartPickEvent,NULL);
66 //----------------------------------------------------------------------------
71 this->InvokeEvent(vtkCommand::EndPickEvent,NULL);
74 //----------------------------------------------------------------------------
77 ::SetSelectionMode(Selection_Mode theMode)
79 if(mySelectionMode != theMode){
80 mySelectionMode = theMode;
81 myMapIOSubIndex.clear();
82 this->EndPickCallback();
92 myMapIOSubIndex.clear();
95 //----------------------------------------------------------------------------
98 ::IsSelected(const Handle(SALOME_InteractiveObject)& theIO) const
100 return !theIO.IsNull() && (myIObjects.find(theIO) != myIObjects.end());
105 ::IsSelected(SALOME_Actor* theActor) const
107 const Handle(SALOME_InteractiveObject) anIO = theActor->getIO();
108 return IsSelected(anIO) && myIO2Actors.find(anIO) != myIO2Actors.end();
113 ::GetActor(const Handle(SALOME_InteractiveObject)& theIO) const
115 TIO2Actors::const_iterator anIter = myIO2Actors.find(theIO);
116 if(anIter != myIO2Actors.end())
117 return anIter->second.GetPointer();
121 //----------------------------------------------------------------------------
124 ::AddIObject(const Handle(SALOME_InteractiveObject)& theIO)
126 if(!IsSelected(theIO)){
127 myIObjects.insert(theIO);
135 ::AddIObject(SALOME_Actor* theActor)
137 const Handle(SALOME_InteractiveObject) anIO = theActor->getIO();
139 bool anIsIOBound = IsSelected(anIO);
141 myIObjects.insert(anIO);
143 bool anIsActorBound = myIO2Actors.find(anIO) != myIO2Actors.end();
145 myIO2Actors[anIO] = theActor;
147 return !anIsIOBound || !anIsActorBound;
150 //----------------------------------------------------------------------------
153 ::RemoveIObject(const Handle(SALOME_InteractiveObject)& theIO)
155 bool anIsIOBound = myIObjects.find(theIO) != myIObjects.end();
157 myIObjects.erase(theIO);
158 myIO2Actors.erase(theIO);
159 myMapIOSubIndex.erase(theIO);
166 ::RemoveIObject(SALOME_Actor* theActor)
168 const Handle(SALOME_InteractiveObject) anIO = theActor->getIO();
170 bool anIsActorBound = myIO2Actors.find(anIO) != myIO2Actors.end();
172 myIO2Actors.erase(anIO);
174 return RemoveIObject(anIO) || anIsActorBound;
177 //----------------------------------------------------------------------------
180 ::StoredIObjects() const
182 myIObjectList.Clear();
183 TIObjects::const_iterator anIter = myIObjects.begin();
184 TIObjects::const_iterator anIterEnd = myIObjects.end();
185 for(; anIter != anIterEnd; anIter++)
186 myIObjectList.Append(*anIter);
188 return myIObjectList;
193 ::IObjectCount() const
195 return myIObjects.size();
200 ::HasIndex( const Handle(SALOME_InteractiveObject)& theIO) const
202 return myMapIOSubIndex.find(theIO) != myMapIOSubIndex.end();
207 ::GetIndex( const Handle(SALOME_InteractiveObject)& theIO,
208 TColStd_IndexedMapOfInteger& theIndex)
210 TMapIOSubIndex::const_iterator anIter = myMapIOSubIndex.find(theIO);
211 if(anIter != myMapIOSubIndex.end())
212 theIndex = anIter->second.myMap;
219 ::IsIndexSelected(const Handle(SALOME_InteractiveObject)& theIO,
222 TMapIOSubIndex::const_iterator anIter = myMapIOSubIndex.find(theIO);
223 if(anIter != myMapIOSubIndex.end()){
224 const TColStd_IndexedMapOfInteger& aMapIndex = anIter->second.myMap;
225 return aMapIndex.Contains(theIndex);
233 removeIndex(TColStd_IndexedMapOfInteger& theMapIndex,
236 int anId = theMapIndex.FindIndex(theIndex); // i==0 if Index is not in the MapIndex
238 // only the last key can be removed
239 int aLastId = theMapIndex.FindKey(theMapIndex.Extent());
241 theMapIndex.RemoveLast();
243 TColStd_IndexedMapOfInteger aNewMap;
244 aNewMap.ReSize(theMapIndex.Extent()-1);
245 for(int j = 1; j <= theMapIndex.Extent(); j++){
246 int anIndex = theMapIndex(j);
247 if ( anIndex != theIndex )
248 aNewMap.Add( anIndex );
250 theMapIndex = aNewMap;
259 ::AddOrRemoveIndex( const Handle(SALOME_InteractiveObject)& theIO,
260 const TColStd_IndexedMapOfInteger& theIndices,
263 TMapIOSubIndex::iterator aMapIter = myMapIOSubIndex.find(theIO);
264 if(aMapIter == myMapIOSubIndex.end()){
265 TIndexedMapOfInteger anEmpty;
266 aMapIter = myMapIOSubIndex.
267 insert(TMapIOSubIndex::value_type(theIO,anEmpty)).first;
269 TColStd_IndexedMapOfInteger& aMapIndex = aMapIter->second.myMap;
274 for(int i = 1, iEnd = theIndices.Extent(); i <= iEnd; i++)
275 aMapIndex.Add(theIndices(i));
277 if(aMapIndex.IsEmpty()) {
278 myMapIOSubIndex.erase(theIO);
288 ::AddOrRemoveIndex( const Handle(SALOME_InteractiveObject)& theIO,
289 const TColStd_MapOfInteger& theIndices,
292 TMapIOSubIndex::iterator aMapIter = myMapIOSubIndex.find(theIO);
293 if(aMapIter == myMapIOSubIndex.end()){
294 TIndexedMapOfInteger anEmpty;
295 aMapIter = myMapIOSubIndex.
296 insert(TMapIOSubIndex::value_type(theIO,anEmpty)).first;
298 TColStd_IndexedMapOfInteger& aMapIndex = aMapIter->second.myMap;
303 TColStd_MapIteratorOfMapOfInteger anIter(theIndices);
304 for(; anIter.More(); anIter.Next())
305 aMapIndex.Add(anIter.Key());
307 if(aMapIndex.IsEmpty()) {
308 myMapIOSubIndex.erase(theIO);
318 ::AddOrRemoveIndex( const Handle(SALOME_InteractiveObject)& theIO,
322 TMapIOSubIndex::iterator anIter = myMapIOSubIndex.find(theIO);
323 if(anIter == myMapIOSubIndex.end()){
324 TIndexedMapOfInteger anEmpty;
325 anIter = myMapIOSubIndex.
326 insert(TMapIOSubIndex::value_type(theIO,anEmpty)).first;
328 TColStd_IndexedMapOfInteger& aMapIndex = anIter->second.myMap;
330 bool anIsConatains = aMapIndex.Contains(theIndex);
332 removeIndex(aMapIndex,theIndex);
338 aMapIndex.Add( theIndex );
340 if( aMapIndex.IsEmpty())
341 myMapIOSubIndex.erase(theIO);
349 ::RemoveIndex( const Handle(SALOME_InteractiveObject)& theIO,
352 if(IsIndexSelected(theIO,theIndex)){
353 TMapIOSubIndex::iterator anIter = myMapIOSubIndex.find(theIO);
354 TColStd_IndexedMapOfInteger& aMapIndex = anIter->second.myMap;
355 removeIndex(aMapIndex,theIndex);
363 myMapIOSubIndex.clear();
366 //----------------------------------------------------------------------------
369 ::SetFilter(const Handle(VTKViewer_Filter)& theFilter)
371 myFilters.insert(TFilters::value_type(theFilter->GetId(),theFilter));
374 //----------------------------------------------------------------------------
377 ::IsFilterPresent(const TFilterID theId) const
379 return myFilters.find(theId) != myFilters.end();
382 //----------------------------------------------------------------------------
385 ::RemoveFilter(const TFilterID theId)
387 if(IsFilterPresent(theId))
388 myFilters.erase(theId);
391 //----------------------------------------------------------------------------
394 ::IsValid(SALOME_Actor* theActor,
395 const TFilterID theId,
396 const bool theIsNode) const
398 TFilters::const_iterator anIter = myFilters.begin();
399 for(; anIter != myFilters.end(); ++anIter){
400 const Handle(VTKViewer_Filter)& aFilter = anIter->second;
401 if(theIsNode == aFilter->IsNodeFilter() &&
402 !aFilter->IsValid(theActor,theId))
408 //----------------------------------------------------------------------------
409 Handle(VTKViewer_Filter)
411 ::GetFilter(const TFilterID theId) const
413 TFilters::const_iterator anIter = myFilters.find(theId);
414 if(anIter != myFilters.end()){
415 const Handle(VTKViewer_Filter)& aFilter = anIter->second;
418 return Handle(VTKViewer_Filter)();