]> SALOME platform Git repositories - modules/gui.git/commitdiff
Salome HOME
To change CASCADE's collections to STL ones (first step)
authorapo <apo@opencascade.com>
Fri, 3 Jun 2005 14:35:27 +0000 (14:35 +0000)
committerapo <apo@opencascade.com>
Fri, 3 Jun 2005 14:35:27 +0000 (14:35 +0000)
src/SVTK/SVTK_Selector.cxx
src/SVTK/SVTK_Selector.h
src/SVTK/SVTK_SelectorDef.h
src/SalomeApp/SalomeApp_VTKSelector.cxx

index e88d96bb9390db1b8e9c93783d4fdcf24af8e43c..2d7c1848056cc0e0b2e11fe0d0debc33a9460665 100644 (file)
@@ -34,7 +34,6 @@
 #include "SALOME_Actor.h"
 #include "SVTK_ViewModel.h"
 #include "SVTK_ViewWindow.h"
-#include "SALOME_ListIteratorOfListIO.hxx"
 
 #include "SVTK_SelectorDef.h"
 #include "utilities.h"
@@ -60,23 +59,17 @@ void
 SVTK_SelectorDef
 ::ClearIObjects() 
 {
-  myIO2Actors.Clear();
-  myIObjects.Clear();
-  //myMapIOSubIndex.Clear();
+  myIO2Actors.clear();
+  myIObjects.clear();
+  myMapIOSubIndex.clear();
 }
 
 //----------------------------------------------------------------------------
 bool
 SVTK_SelectorDef
-::IsSelected(const Handle(SALOME_InteractiveObject)& theObject) const
+::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
@@ -84,15 +77,16 @@ 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_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;
 }
 
@@ -102,7 +96,7 @@ SVTK_SelectorDef
 ::AddIObject(const Handle(SALOME_InteractiveObject)& theIO) 
 {
   if(!IsSelected(theIO)){
-    myIObjects.Append(theIO);
+    myIObjects.insert(theIO);
     return true;
   }
   return false;
@@ -116,11 +110,11 @@ SVTK_SelectorDef
 
   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;
 }
@@ -130,22 +124,13 @@ bool
 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; 
-      break;
-    }
-  }
+  bool anIsIOBound = myIObjects.find(theIO) != myIObjects.end();
 
-  bool anIsActorBound = myIO2Actors.IsBound(theIO);
-  if(anIsActorBound)
-    myIO2Actors.UnBind(theIO);
+  myIObjects.erase(theIO);
+  myIO2Actors.erase(theIO);
+  myMapIOSubIndex.erase(theIO);
 
-  return anIsIOBound || anIsActorBound;
+  return anIsIOBound;
 }
 
 bool 
@@ -154,22 +139,11 @@ SVTK_SelectorDef
 {
   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; 
-      break;
-    }
-  }
+    myIO2Actors.erase(anIO);
 
-  return anIsIOBound || anIsActorBound;
+  return RemoveIObject(anIO) || anIsActorBound;
 }
 
 //----------------------------------------------------------------------------
@@ -177,21 +151,27 @@ const SALOME_ListIO&
 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_SelectorDef
 ::IObjectCount() const
 {
-  return myIObjects.Extent();
+  return myIObjects.size();
 }
 
 bool 
 SVTK_SelectorDef
 ::HasIndex( const Handle(SALOME_InteractiveObject)& theIO) const
 {
-  return myMapIOSubIndex.IsBound(theIO);
+  return myMapIOSubIndex.find(theIO) != myMapIOSubIndex.end();
 }
 
 void 
@@ -199,8 +179,9 @@ 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();
 }
@@ -210,11 +191,13 @@ 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 
@@ -249,20 +232,22 @@ SVTK_SelectorDef
                    const TColStd_IndexedMapOfInteger& theIndices, 
                    bool theIsModeShift)
 {
-  TColStd_IndexedMapOfInteger empty;
-  if(!myMapIOSubIndex.IsBound(theIO))
-    myMapIOSubIndex.Bind(theIO, empty);
-
-  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);
+  for(int i = 0, iEnd = theIndices.Extent(); i < iEnd; i++)
+    aMapIndex.Add(theIndices(i));
+  
+  if(aMapIndex.IsEmpty())
     RemoveIObject(theIO);
-  }
 
   return !aMapIndex.IsEmpty();
 }
@@ -274,22 +259,23 @@ SVTK_SelectorDef
                    const TColStd_MapOfInteger& theIndices, 
                    bool theIsModeShift)
 {
-  TColStd_IndexedMapOfInteger empty;   
-  if(!myMapIOSubIndex.IsBound(theIO))
-    myMapIOSubIndex.Bind(theIO, empty);
-
-  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);
+  if(aMapIndex.IsEmpty())
     RemoveIObject(theIO);
-  }
 
   return !aMapIndex.IsEmpty();
 }
@@ -301,27 +287,26 @@ SVTK_SelectorDef
                    int theIndex, 
                    bool theIsModeShift)
 {
-  TColStd_IndexedMapOfInteger empty;           
-  if(!myMapIOSubIndex.IsBound(theIO))
-    myMapIOSubIndex.Bind(theIO, empty);
-  
-  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);
+  if( aMapIndex.IsEmpty())
     RemoveIObject(theIO);
-  }
 
   return false;
 }
@@ -332,9 +317,10 @@ 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);
   }
 }
 
@@ -342,5 +328,5 @@ void
 SVTK_SelectorDef
 ::ClearIndex()
 {
-  myMapIOSubIndex.Clear();  
+  myMapIOSubIndex.clear();  
 }
index 0bcd90bc79b19c56e030dcdd5d0954f5465a5b25..6d3c3ec500afe8696b5972328981405104d5d469 100644 (file)
 #define SVTK_SELECTOR_H
 
 #include <TColStd_MapOfInteger.hxx>
+#include <TColStd_IndexedMapOfInteger.hxx>
 
 #include "SVTK_Selection.h"
 #include "SALOME_ListIO.hxx"
-#include "SALOME_InteractiveObject.hxx"
-#include "SALOME_DataMapOfIOMapOfInteger.hxx"
 
 class SALOME_Actor;
 
index ec7ae91aa6beaa6446731d8a595c22c210356320..47f593e9a3b438ee3bd533b4affe93f653d34846 100644 (file)
 #ifndef SVTK_SELECTORDEF_H
 #define SVTK_SELECTORDEF_H
 
-#include <NCollection_DataMap.hxx>
-#include <vtkSmartPointer.h>
+#include <set>
+#include <map>
+
+#include <TColStd_IndexedMapOfInteger.hxx>
 #include <TColStd_MapOfInteger.hxx>
+#include <vtkSmartPointer.h>
 
 #include "SVTK_Selector.h"
 
@@ -131,12 +134,42 @@ public:
   ClearIndex();
 
 private:
-  typedef NCollection_DataMap<Handle(SALOME_InteractiveObject),
-                              vtkSmartPointer<SALOME_Actor> > TIO2Actors;
-  TIO2Actors myIO2Actors;
   Selection_Mode mySelectionMode;
-  SALOME_ListIO myIObjects;
-  SALOME_DataMapOfIOMapOfInteger myMapIOSubIndex;
+
+  struct TIOLessThan
+  {
+    bool 
+    operator()(const Handle(SALOME_InteractiveObject)& theRightIO,
+              const Handle(SALOME_InteractiveObject)& theLeftIO) const
+    {
+      return strcmp(theRightIO->getEntry(),theLeftIO->getEntry()) < 0;
+    }
+  };
+
+  struct TIndexedMapOfInteger{
+    TColStd_IndexedMapOfInteger myMap;
+    TIndexedMapOfInteger()
+    {}
+    TIndexedMapOfInteger(const TIndexedMapOfInteger& theIndexedMapOfInteger)
+    {
+      myMap = theIndexedMapOfInteger.myMap;
+    }
+  };
+
+  mutable SALOME_ListIO myIObjectList;
+  typedef std::set<Handle(SALOME_InteractiveObject),
+                   TIOLessThan> TIObjects;
+  TIObjects myIObjects;
+
+  typedef std::map<Handle(SALOME_InteractiveObject),
+                   vtkSmartPointer<SALOME_Actor>,
+                   TIOLessThan> TIO2Actors;
+  TIO2Actors myIO2Actors;
+
+  typedef std::map<Handle(SALOME_InteractiveObject),
+                   TIndexedMapOfInteger,
+                   TIOLessThan> TMapIOSubIndex;
+  TMapIOSubIndex myMapIOSubIndex;
 };
 
 
index 062128c3bbb6f59f3e963d2beaa035cf92e873b2..3b3a8a30478f454bb1b2d157dcbb7563b501b27d 100644 (file)
@@ -113,7 +113,8 @@ SalomeApp_VTKSelector
     if(SUIT_ViewManager* aViewMgr = myViewer->getViewManager()){
       if(SVTK_ViewWindow* aView = dynamic_cast<SVTK_ViewWindow*>(aViewMgr->getActiveView())){
        if(SVTK_Selector* aSelector = aView->GetSelector()){
-         aSelector->ClearIObjects();
+         SALOME_ListIO anAppendList;
+         const SALOME_ListIO& aStoredList = aSelector->StoredIObjects();
          SUIT_DataOwnerPtrList::const_iterator anIter = theList.begin();
          for(; anIter != theList.end(); ++anIter){
            const SUIT_DataOwner* aDataOwner = (*anIter).get();
@@ -121,15 +122,33 @@ SalomeApp_VTKSelector
              aSelector->SetSelectionMode(anOwner->GetMode());
              Handle(SALOME_InteractiveObject) anIO = anOwner->IO();
              aSelector->AddIObject(anIO);
+             anAppendList.Append(anIO);
              aSelector->AddOrRemoveIndex(anIO,anOwner->GetIds(),false);
              if(MYDEBUG) MESSAGE("VTKSelector::setSelection - SVTKDataOwner - "<<anIO->getEntry());
            }else if(const SalomeApp_DataOwner* anOwner = dynamic_cast<const SalomeApp_DataOwner*>(aDataOwner)){
              Handle(SALOME_InteractiveObject) anIO = 
                new SALOME_InteractiveObject(anOwner->entry().latin1(),"");
              aSelector->AddIObject(anIO);
+             anAppendList.Append(anIO);
              if(MYDEBUG) MESSAGE("VTKSelector::setSelection - DataOwner - "<<anIO->getEntry());
            }
          }
+         // To remove IOs, which is not selected.
+         SALOME_ListIO aRemoveList;
+         SALOME_ListIteratorOfListIO anAppendListIter(anAppendList);
+         for(; anAppendListIter.More(); anAppendListIter.Next()){
+           Handle(SALOME_InteractiveObject) anIO = anAppendListIter.Value();
+           SALOME_ListIteratorOfListIO aStoredListIter(aStoredList);
+           for(; aStoredListIter.More(); aStoredListIter.Next()){
+             if(anIO->isSame(aStoredListIter.Value())){
+               aRemoveList.Append(anIO);
+             }
+           }
+         }
+         SALOME_ListIteratorOfListIO aRemoveListIter(aRemoveList);
+         for(; aRemoveListIter.More(); aRemoveListIter.Next()){
+           aSelector->RemoveIObject(aRemoveListIter.Value());
+         }
          aView->onSelectionChanged();
        }
       }