Salome HOME
Rolling back incorrect integration
[modules/gui.git] / src / SVTK / SVTK_Selector.cxx
index 00e223571f37c0c6a3686da1282778a92bb0930f..96690603ea100e6a8a34cfb2c37dca85171d9967 100644 (file)
@@ -26,6 +26,7 @@
 //  Module : SALOME
 //  $Header$
 
+
 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
 #include <TColStd_IndexedMapOfInteger.hxx>
 
 #include "SALOME_Actor.h"
 #include "SVTK_ViewModel.h"
 #include "SVTK_ViewWindow.h"
-#include "SALOME_ListIteratorOfListIO.hxx"
-
-#include "SVTK_Selector.h"
 
+#include "SVTK_SelectorDef.h"
 #include "utilities.h"
 
-SVTK_Selector
-::SVTK_Selector()
+SVTK_SelectorDef
+::SVTK_SelectorDef()
 {
 }
 
-SVTK_Selector
-::~SVTK_Selector()
+SVTK_SelectorDef
+::~SVTK_SelectorDef()
 {
 }
 
 void 
-SVTK_Selector
+SVTK_SelectorDef
 ::SetSelectionMode(Selection_Mode theMode)
 {
   mySelectionMode = theMode;
 }
 
 void 
-SVTK_Selector
+SVTK_SelectorDef
 ::ClearIObjects() 
 {
-  myIO2Actors.Clear();
-  myIObjects.Clear();
-  myMapIOSubIndex.Clear();
+  myIO2Actors.clear();
+  myIObjects.clear();
+  myMapIOSubIndex.clear();
 }
 
 //----------------------------------------------------------------------------
 bool
-SVTK_Selector
-::IsSelected(const Handle(SALOME_InteractiveObject)& theObject) const
+SVTK_SelectorDef
+::IsSelected(const Handle(SALOME_InteractiveObject)& theIO) const
 {
-  SALOME_ListIteratorOfListIO anIter(myIObjects);
-  for(; anIter.More(); anIter.Next()){
-    if(theObject->isSame(anIter.Value())){
-      return true;
-    }
-  }
-  return false;
+  return myIObjects.find(theIO) != myIObjects.end();
 }
 
 bool
-SVTK_Selector
+SVTK_SelectorDef
 ::IsSelected(SALOME_Actor* theActor) const
 {
   const Handle(SALOME_InteractiveObject) anIO = theActor->getIO();
-  return IsSelected(anIO) && myIO2Actors.IsBound(anIO);
+  return IsSelected(anIO) && myIO2Actors.find(anIO) != myIO2Actors.end();
 }
 
 SALOME_Actor*
-SVTK_Selector
+SVTK_SelectorDef
 ::GetActor(const Handle(SALOME_InteractiveObject)& theIO) const
 {
-  if(myIO2Actors.IsBound(theIO))
-    return myIO2Actors.Find(theIO).GetPointer();
+  TIO2Actors::const_iterator anIter = myIO2Actors.find(theIO);
+  if(anIter != myIO2Actors.end())
+    return anIter->second.GetPointer();
   return NULL;
 }
 
 //----------------------------------------------------------------------------
 bool 
-SVTK_Selector
+SVTK_SelectorDef
 ::AddIObject(const Handle(SALOME_InteractiveObject)& theIO) 
 {
   if(!IsSelected(theIO)){
-    myIObjects.Append(theIO);
+    myIObjects.insert(theIO);
     return true;
   }
   return false;
 }
 
 bool 
-SVTK_Selector
+SVTK_SelectorDef
 ::AddIObject(SALOME_Actor* theActor) 
 {
   const Handle(SALOME_InteractiveObject) anIO = theActor->getIO();
 
   bool anIsIOBound = IsSelected(anIO);
   if(!anIsIOBound)
-    myIObjects.Append(anIO);
+    myIObjects.insert(anIO);
 
-  bool anIsActorBound = myIO2Actors.IsBound(anIO);
+  bool anIsActorBound = myIO2Actors.find(anIO) != myIO2Actors.end();
   if(!anIsActorBound)
-    myIO2Actors.Bind(anIO,theActor);
+    myIO2Actors[anIO] = theActor;
   
   return !anIsIOBound || !anIsActorBound;
 }
 
 //----------------------------------------------------------------------------
 bool 
-SVTK_Selector
+SVTK_SelectorDef
 ::RemoveIObject(const Handle(SALOME_InteractiveObject)& theIO) 
 {
-  bool anIsIOBound = false;
-  for(SALOME_ListIteratorOfListIO anIter(myIObjects); anIter.More(); anIter.Next()){
-    if(theIO->isSame(anIter.Value())){
-      if(myMapIOSubIndex.IsBound(theIO))
-       myMapIOSubIndex.UnBind(theIO);
-      myIObjects.Remove(anIter);
-      anIsIOBound = true; 
-    }
-  }
+  bool anIsIOBound = myIObjects.find(theIO) != myIObjects.end();
 
-  bool anIsActorBound = myIO2Actors.IsBound(theIO);
-  if(anIsActorBound)
-    myIO2Actors.UnBind(theIO);
+  myIObjects.erase(theIO);
+  myIO2Actors.erase(theIO);
 
-  return anIsIOBound || anIsActorBound;
+  return anIsIOBound;
 }
 
 bool 
-SVTK_Selector
+SVTK_SelectorDef
 ::RemoveIObject(SALOME_Actor* theActor) 
 {
   const Handle(SALOME_InteractiveObject) anIO = theActor->getIO();
 
-  bool anIsActorBound = myIO2Actors.IsBound(anIO);
+  bool anIsActorBound = myIO2Actors.find(anIO) != myIO2Actors.end();
   if(anIsActorBound)
-    myIO2Actors.UnBind(anIO);
-
-  bool anIsIOBound = false;
-  for(SALOME_ListIteratorOfListIO anIter(myIObjects); anIter.More(); anIter.Next()){
-    if(anIO->isSame(anIter.Value())){
-      if(myMapIOSubIndex.IsBound(anIO))
-       myMapIOSubIndex.UnBind(anIO);
-      myIObjects.Remove(anIter);
-      anIsIOBound = true; 
-    }
-  }
+    myIO2Actors.erase(anIO);
 
-  return anIsIOBound || anIsActorBound;
+  return RemoveIObject(anIO) || anIsActorBound;
 }
 
 //----------------------------------------------------------------------------
 const SALOME_ListIO& 
-SVTK_Selector
+SVTK_SelectorDef
 ::StoredIObjects() const
 {
-  return myIObjects;
+  myIObjectList.Clear();
+  TIObjects::const_iterator anIter = myIObjects.begin();
+  TIObjects::const_iterator anIterEnd = myIObjects.end();
+  for(; anIter != anIterEnd; anIter++)
+    myIObjectList.Append(*anIter);
+
+  return myIObjectList;
 }
 
 int
-SVTK_Selector
+SVTK_SelectorDef
 ::IObjectCount() const
 {
-  return myIObjects.Extent();
+  return myIObjects.size();
 }
 
 bool 
-SVTK_Selector
+SVTK_SelectorDef
 ::HasIndex( const Handle(SALOME_InteractiveObject)& theIO) const
 {
-  return myMapIOSubIndex.IsBound(theIO);
+  return myMapIOSubIndex.find(theIO) != myMapIOSubIndex.end();
 }
 
 void 
-SVTK_Selector
+SVTK_SelectorDef
 ::GetIndex( const Handle(SALOME_InteractiveObject)& theIO, 
            TColStd_IndexedMapOfInteger& theIndex)
 {
-  if(myMapIOSubIndex.IsBound(theIO))
-    theIndex = myMapIOSubIndex.Find(theIO);
+  TMapIOSubIndex::const_iterator anIter = myMapIOSubIndex.find(theIO);
+  if(anIter != myMapIOSubIndex.end())
+    theIndex = anIter->second.myMap;
   else
     theIndex.Clear();
 }
 
 bool
-SVTK_Selector
+SVTK_SelectorDef
 ::IsIndexSelected(const Handle(SALOME_InteractiveObject)& theIO, 
                  int theIndex) const
 {
-  if( !myMapIOSubIndex.IsBound(theIO))
-    return false;
+  TMapIOSubIndex::const_iterator anIter = myMapIOSubIndex.find(theIO);
+  if(anIter != myMapIOSubIndex.end()){
+    const TColStd_IndexedMapOfInteger& aMapIndex = anIter->second.myMap;
+    return aMapIndex.Contains(theIndex);
+  }
 
-  const TColStd_IndexedMapOfInteger& aMapIndex = myMapIOSubIndex.Find(theIO);
-  return aMapIndex.Contains(theIndex);
+  return false;
 }
 
 static 
@@ -242,100 +226,106 @@ removeIndex(TColStd_IndexedMapOfInteger& theMapIndex,
 
 
 bool
-SVTK_Selector
+SVTK_SelectorDef
 ::AddOrRemoveIndex( const Handle(SALOME_InteractiveObject)& theIO, 
                    const TColStd_IndexedMapOfInteger& theIndices, 
                    bool theIsModeShift)
 {
-  if(!myMapIOSubIndex.IsBound(theIO))
-    myMapIOSubIndex.Bind(theIO,TColStd_IndexedMapOfInteger());
-
-  TColStd_IndexedMapOfInteger& aMapIndex = myMapIOSubIndex.ChangeFind(theIO);
-  aMapIndex = theIndices;
+  TMapIOSubIndex::iterator aMapIter = myMapIOSubIndex.find(theIO);
+  if(aMapIter == myMapIOSubIndex.end()){
+    TIndexedMapOfInteger anEmpty;
+    aMapIter = myMapIOSubIndex.
+      insert(TMapIOSubIndex::value_type(theIO,anEmpty)).first;
+  }
+  TColStd_IndexedMapOfInteger& aMapIndex = aMapIter->second.myMap;
 
   if(!theIsModeShift)
     aMapIndex.Clear();
   
-  if(aMapIndex.IsEmpty()){
-    myMapIOSubIndex.UnBind(theIO);
-    RemoveIObject(theIO);
-  }
+  for(int i = 1, iEnd = theIndices.Extent(); i <= iEnd; i++)
+    aMapIndex.Add(theIndices(i));
+  
+  if(aMapIndex.IsEmpty())
+    myMapIOSubIndex.erase(theIO);
 
   return !aMapIndex.IsEmpty();
 }
 
 
 bool
-SVTK_Selector
+SVTK_SelectorDef
 ::AddOrRemoveIndex( const Handle(SALOME_InteractiveObject)& theIO, 
                    const TColStd_MapOfInteger& theIndices, 
                    bool theIsModeShift)
 {
-  if(!myMapIOSubIndex.IsBound(theIO))
-    myMapIOSubIndex.Bind(theIO,TColStd_IndexedMapOfInteger());
-
-  TColStd_IndexedMapOfInteger& aMapIndex = myMapIOSubIndex.ChangeFind(theIO);
+  TMapIOSubIndex::iterator aMapIter = myMapIOSubIndex.find(theIO);
+  if(aMapIter == myMapIOSubIndex.end()){
+    TIndexedMapOfInteger anEmpty;
+    aMapIter = myMapIOSubIndex.
+      insert(TMapIOSubIndex::value_type(theIO,anEmpty)).first;
+  }
+  TColStd_IndexedMapOfInteger& aMapIndex = aMapIter->second.myMap;
 
   if(!theIsModeShift)
     aMapIndex.Clear();
   
-  for(TColStd_MapIteratorOfMapOfInteger anIter(theIndices); anIter.More(); anIter.Next())
+  TColStd_MapIteratorOfMapOfInteger anIter(theIndices);
+  for(; anIter.More(); anIter.Next())
     aMapIndex.Add(anIter.Key());
   
-  if(aMapIndex.IsEmpty()){
-    myMapIOSubIndex.UnBind(theIO);
-    RemoveIObject(theIO);
-  }
+  if(aMapIndex.IsEmpty())
+    myMapIOSubIndex.erase(theIO);
 
   return !aMapIndex.IsEmpty();
 }
 
 
 bool 
-SVTK_Selector
+SVTK_SelectorDef
 ::AddOrRemoveIndex( const Handle(SALOME_InteractiveObject)& theIO, 
                    int theIndex, 
                    bool theIsModeShift)
 {
-  if(!myMapIOSubIndex.IsBound(theIO))
-    myMapIOSubIndex.Bind(theIO,TColStd_IndexedMapOfInteger());
-  
-  TColStd_IndexedMapOfInteger& aMapIndex = myMapIOSubIndex.ChangeFind(theIO);
-
-  bool anIsConatains = aMapIndex.Contains( theIndex );
+  TMapIOSubIndex::iterator anIter = myMapIOSubIndex.find(theIO);
+  if(anIter == myMapIOSubIndex.end()){
+    TIndexedMapOfInteger anEmpty;
+    anIter = myMapIOSubIndex.
+      insert(TMapIOSubIndex::value_type(theIO,anEmpty)).first;
+  }
+  TColStd_IndexedMapOfInteger& aMapIndex = anIter->second.myMap;
 
-  if (anIsConatains)
-    removeIndex( aMapIndex, theIndex );
+  bool anIsConatains = aMapIndex.Contains(theIndex);
+  if(anIsConatains)
+    removeIndex(aMapIndex,theIndex);
   
-  if (!theIsModeShift)
+  if(!theIsModeShift)
     aMapIndex.Clear();
   
   if(!anIsConatains)
     aMapIndex.Add( theIndex );
 
-  if ( aMapIndex.IsEmpty() ) {
-    myMapIOSubIndex.UnBind(theIO);
-    RemoveIObject(theIO);
-  }
+  if( aMapIndex.IsEmpty())
+    myMapIOSubIndex.erase(theIO);
 
   return false;
 }
 
 
 void
-SVTK_Selector
+SVTK_SelectorDef
 ::RemoveIndex( const Handle(SALOME_InteractiveObject)& theIO, 
               int theIndex)
 {
-  if ( myMapIOSubIndex.IsBound( theIO ) ) {
-    TColStd_IndexedMapOfInteger& aMapIndex = myMapIOSubIndex.ChangeFind( theIO );
-    removeIndex( aMapIndex, theIndex );
+  if(IsIndexSelected(theIO,theIndex)){
+    TMapIOSubIndex::iterator anIter = myMapIOSubIndex.find(theIO);
+    TColStd_IndexedMapOfInteger& aMapIndex = anIter->second.myMap;
+    removeIndex(aMapIndex,theIndex);
   }
 }
 
 void 
-SVTK_Selector
+SVTK_SelectorDef
 ::ClearIndex()
 {
-  myMapIOSubIndex.Clear();  
+  myMapIOSubIndex.clear();  
 }