#include "SALOME_Actor.h"
#include "SVTK_ViewModel.h"
#include "SVTK_ViewWindow.h"
-#include "SALOME_ListIteratorOfListIO.hxx"
#include "SVTK_SelectorDef.h"
#include "utilities.h"
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
::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;
}
::AddIObject(const Handle(SALOME_InteractiveObject)& theIO)
{
if(!IsSelected(theIO)){
- myIObjects.Append(theIO);
+ myIObjects.insert(theIO);
return true;
}
return false;
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;
}
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
{
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;
}
//----------------------------------------------------------------------------
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
::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();
}
::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
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();
}
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();
}
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;
}
::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);
}
}
SVTK_SelectorDef
::ClearIndex()
{
- myMapIOSubIndex.Clear();
+ myMapIOSubIndex.clear();
}
#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"
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;
};
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();
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();
}
}