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>
40 \return new SVTK_Selector
46 return new SVTK_SelectorDef();
55 mySelectionMode = ActorSelection;
67 To invoke selectionChanged signals
73 this->InvokeEvent(vtkCommand::StartPickEvent,NULL);
77 To invoke selectionChanged signals
83 this->InvokeEvent(vtkCommand::EndPickEvent,NULL);
87 To change current Selection_Mode (as outside effect, it invokes selectionChange signal)
91 ::SetSelectionMode(Selection_Mode theMode)
93 if(mySelectionMode != theMode){
94 mySelectionMode = theMode;
95 myMapIOSubIndex.clear();
96 this->EndPickCallback();
109 myMapIOSubIndex.clear();
113 \return true if the SALOME_InteractiveObject presents into selection
117 ::IsSelected(const Handle(SALOME_InteractiveObject)& theIO) const
119 return !theIO.IsNull() && (myIObjects.find(theIO) != myIObjects.end());
123 \return true if the SALOME_Actor presents into selection
127 ::IsSelected(SALOME_Actor* theActor) const
129 const Handle(SALOME_InteractiveObject) anIO = theActor->getIO();
130 return IsSelected(anIO) && myIO2Actors.find(anIO) != myIO2Actors.end();
134 \return corresponding SALOME_Actor for SALOME_InteractiveObject
135 \param theIO - SALOME_InteractiveObject
139 ::GetActor(const Handle(SALOME_InteractiveObject)& theIO) const
141 TIO2Actors::const_iterator anIter = myIO2Actors.find(theIO);
142 if(anIter != myIO2Actors.end())
143 return anIter->second.GetPointer();
148 Adds SALOME_InteractiveObject into selection
149 \param theIO - SALOME_InteractiveObject
153 ::AddIObject(const Handle(SALOME_InteractiveObject)& theIO)
155 if(!IsSelected(theIO)){
156 myIObjects.insert(theIO);
163 Adds SALOME_Actor into selection
164 \param theActor - SALOME_Actor
168 ::AddIObject(SALOME_Actor* theActor)
170 const Handle(SALOME_InteractiveObject) anIO = theActor->getIO();
172 bool anIsIOBound = IsSelected(anIO);
174 myIObjects.insert(anIO);
176 bool anIsActorBound = myIO2Actors.find(anIO) != myIO2Actors.end();
178 myIO2Actors[anIO] = theActor;
180 return !anIsIOBound || !anIsActorBound;
184 Removes SALOME_InteractiveObject from selection
185 \param theIO - SALOME_InteractiveObject
189 ::RemoveIObject(const Handle(SALOME_InteractiveObject)& theIO)
191 bool anIsIOBound = myIObjects.find(theIO) != myIObjects.end();
193 myIObjects.erase(theIO);
194 myIO2Actors.erase(theIO);
195 myMapIOSubIndex.erase(theIO);
201 Removes SALOME_Actor from selection
202 \param theActor - SALOME_Actor
206 ::RemoveIObject(SALOME_Actor* theActor)
208 const Handle(SALOME_InteractiveObject) anIO = theActor->getIO();
210 bool anIsActorBound = myIO2Actors.find(anIO) != myIO2Actors.end();
212 myIO2Actors.erase(anIO);
214 return RemoveIObject(anIO) || anIsActorBound;
218 \return list of all SALOME_InteractiveObject presenting in selection
222 ::StoredIObjects() const
224 myIObjectList.Clear();
225 TIObjects::const_iterator anIter = myIObjects.begin();
226 TIObjects::const_iterator anIterEnd = myIObjects.end();
227 for(; anIter != anIterEnd; anIter++)
228 myIObjectList.Append(*anIter);
230 return myIObjectList;
234 \return number of selected objects
238 ::IObjectCount() const
240 return myIObjects.size();
244 \return true if the SALOME_InteractiveObject has a subselection
245 \param theIO - SALOME_InteractiveObject
249 ::HasIndex( const Handle(SALOME_InteractiveObject)& theIO) const
251 return myMapIOSubIndex.find(theIO) != myMapIOSubIndex.end();
255 Gets indices of subselection for SALOME_InteractiveObject
256 \param theIO - SALOME_InteractiveObject
260 ::GetIndex( const Handle(SALOME_InteractiveObject)& theIO,
261 TColStd_IndexedMapOfInteger& theIndex)
263 TMapIOSubIndex::const_iterator anIter = myMapIOSubIndex.find(theIO);
264 if(anIter != myMapIOSubIndex.end())
265 theIndex = anIter->second.myMap;
271 \return true if the index presents in subselection
272 \param theIO - SALOME_InteractiveObject
273 \param theIndex - index
277 ::IsIndexSelected(const Handle(SALOME_InteractiveObject)& theIO,
280 TMapIOSubIndex::const_iterator anIter = myMapIOSubIndex.find(theIO);
281 if(anIter != myMapIOSubIndex.end()){
282 const TColStd_IndexedMapOfInteger& aMapIndex = anIter->second.myMap;
283 return aMapIndex.Contains(theIndex);
291 removeIndex(TColStd_IndexedMapOfInteger& theMapIndex,
294 int anId = theMapIndex.FindIndex(theIndex); // i==0 if Index is not in the MapIndex
296 // only the last key can be removed
297 int aLastId = theMapIndex.FindKey(theMapIndex.Extent());
299 theMapIndex.RemoveLast();
301 TColStd_IndexedMapOfInteger aNewMap;
302 aNewMap.ReSize(theMapIndex.Extent()-1);
303 for(int j = 1; j <= theMapIndex.Extent(); j++){
304 int anIndex = theMapIndex(j);
305 if ( anIndex != theIndex )
306 aNewMap.Add( anIndex );
308 theMapIndex = aNewMap;
315 Changes indices of subselection for SALOME_InteractiveObject
316 \param theIO - SALOME_InteractiveObject
317 \param theIndices - indices
318 \param theIsModeShift - if it is false, then map will be cleared before indices are added
322 ::AddOrRemoveIndex( const Handle(SALOME_InteractiveObject)& theIO,
323 const TColStd_IndexedMapOfInteger& theIndices,
326 TMapIOSubIndex::iterator aMapIter = myMapIOSubIndex.find(theIO);
327 if(aMapIter == myMapIOSubIndex.end()){
328 TIndexedMapOfInteger anEmpty;
329 aMapIter = myMapIOSubIndex.
330 insert(TMapIOSubIndex::value_type(theIO,anEmpty)).first;
332 TColStd_IndexedMapOfInteger& aMapIndex = aMapIter->second.myMap;
337 for(int i = 1, iEnd = theIndices.Extent(); i <= iEnd; i++)
338 aMapIndex.Add(theIndices(i));
340 if(aMapIndex.IsEmpty()) {
341 myMapIOSubIndex.erase(theIO);
350 Changes indices of subselection for SALOME_InteractiveObject
351 \param theIO - SALOME_InteractiveObject
352 \param theIndices - indices
353 \param theIsModeShift - if it is false, then map will be cleared before indices are added
357 ::AddOrRemoveIndex( const Handle(SALOME_InteractiveObject)& theIO,
358 const TColStd_MapOfInteger& theIndices,
361 TMapIOSubIndex::iterator aMapIter = myMapIOSubIndex.find(theIO);
362 if(aMapIter == myMapIOSubIndex.end()){
363 TIndexedMapOfInteger anEmpty;
364 aMapIter = myMapIOSubIndex.
365 insert(TMapIOSubIndex::value_type(theIO,anEmpty)).first;
367 TColStd_IndexedMapOfInteger& aMapIndex = aMapIter->second.myMap;
372 TColStd_MapIteratorOfMapOfInteger anIter(theIndices);
373 for(; anIter.More(); anIter.Next())
374 aMapIndex.Add(anIter.Key());
376 if(aMapIndex.IsEmpty()) {
377 myMapIOSubIndex.erase(theIO);
386 Changes indices of subselection for SALOME_InteractiveObject
387 \param theIO - SALOME_InteractiveObject
388 \param theIndex - index
389 \param theIsModeShift - if it is false, then map will be cleared before indices are added
393 ::AddOrRemoveIndex( const Handle(SALOME_InteractiveObject)& theIO,
397 TMapIOSubIndex::iterator anIter = myMapIOSubIndex.find(theIO);
398 if(anIter == myMapIOSubIndex.end()){
399 TIndexedMapOfInteger anEmpty;
400 anIter = myMapIOSubIndex.
401 insert(TMapIOSubIndex::value_type(theIO,anEmpty)).first;
403 TColStd_IndexedMapOfInteger& aMapIndex = anIter->second.myMap;
405 bool anIsConatains = aMapIndex.Contains(theIndex);
407 removeIndex(aMapIndex,theIndex);
413 aMapIndex.Add( theIndex );
415 if( aMapIndex.IsEmpty())
416 myMapIOSubIndex.erase(theIO);
423 Removes index of subselection for SALOME_InteractiveObject
424 \param theIO - SALOME_InteractiveObject
425 \param theIndex - index
429 ::RemoveIndex( const Handle(SALOME_InteractiveObject)& theIO,
432 if(IsIndexSelected(theIO,theIndex)){
433 TMapIOSubIndex::iterator anIter = myMapIOSubIndex.find(theIO);
434 TColStd_IndexedMapOfInteger& aMapIndex = anIter->second.myMap;
435 removeIndex(aMapIndex,theIndex);
440 Clears all indices of subselection
446 myMapIOSubIndex.clear();
450 To apply a filter on the selection
451 \param theFilter - new filter
455 ::SetFilter(const Handle(VTKViewer_Filter)& theFilter)
457 myFilters.insert(TFilters::value_type(theFilter->GetId(),theFilter));
461 \return true if filter with given number is applyed
462 \param theId - filter id
466 ::IsFilterPresent(const TFilterID theId) const
468 return myFilters.find(theId) != myFilters.end();
472 To remove a filter from the selection
473 \param theId - filter id
477 ::RemoveFilter(const TFilterID theId)
479 if(IsFilterPresent(theId))
480 myFilters.erase(theId);
484 \return true if the index satisfy installed filters
485 \param theActor - actor
486 \param theId - filter id
487 \param theIsNode - whether it is node
491 ::IsValid(SALOME_Actor* theActor,
492 const TFilterID theId,
493 const bool theIsNode) const
495 TFilters::const_iterator anIter = myFilters.begin();
496 for(; anIter != myFilters.end(); ++anIter){
497 const Handle(VTKViewer_Filter)& aFilter = anIter->second;
498 if(theIsNode == aFilter->IsNodeFilter() &&
499 !aFilter->IsValid(theActor,theId))
506 \return filter by it's id
507 \param theId - filter id
509 Handle(VTKViewer_Filter)
511 ::GetFilter(const TFilterID theId) const
513 TFilters::const_iterator anIter = myFilters.find(theId);
514 if(anIter != myFilters.end()){
515 const Handle(VTKViewer_Filter)& aFilter = anIter->second;
518 return Handle(VTKViewer_Filter)();