1 #include "SalomeApp_VTKSelector.h"
2 #include "SalomeApp_DataOwner.h"
4 #include "SVTK_ViewModel.h"
5 #include "SVTK_Selector.h"
6 #include "SVTK_ViewWindow.h"
7 #include "SVTK_Functor.h"
9 #include "SALOME_Actor.h"
10 #include "SALOME_ListIteratorOfListIO.hxx"
12 #include "VTKViewer_Algorithm.h"
14 #include <vtkRenderer.h>
16 #include "utilities.h"
19 static int MYDEBUG = 1;
21 static int MYDEBUG = 0;
27 SalomeApp_SVTKDataOwner
28 ::SalomeApp_SVTKDataOwner( const Handle(SALOME_InteractiveObject)& theIO,
29 const TColStd_IndexedMapOfInteger& theIds,
30 Selection_Mode theMode,
31 SALOME_Actor* theActor):
32 SalomeApp_DataOwner( theIO ),
33 mySelectionMode(theMode),
36 myIds = theIds; // workaround - there is no constructor copy for the container
42 SalomeApp_SVTKDataOwner
43 ::~SalomeApp_SVTKDataOwner()
51 SalomeApp_SVTKDataOwner
54 return myActor.GetPointer();
61 ::SalomeApp_VTKSelector( SVTK_Viewer* viewer,
62 SUIT_SelectionMgr* mgr ):
63 SUIT_Selector( mgr, viewer ),
67 connect( myViewer, SIGNAL( selectionChanged() ), this, SLOT( onSelectionChanged() ) );
74 ::~SalomeApp_VTKSelector()
89 Gets type of salome vtk viewer.
95 return SVTK_Viewer::Type();
102 SalomeApp_VTKSelector
103 ::onSelectionChanged()
109 Gets list of selected data owners.(output \a aList).
112 SalomeApp_VTKSelector
113 ::getSelection( SUIT_DataOwnerPtrList& aList ) const
116 if(SUIT_ViewManager* aViewMgr = myViewer->getViewManager()){
117 if(SVTK_ViewWindow* aView = dynamic_cast<SVTK_ViewWindow*>(aViewMgr->getActiveView())){
118 if(SVTK_Selector* aSelector = aView->GetSelector()){
119 Selection_Mode aMode = aSelector->SelectionMode();
120 const SALOME_ListIO& aListIO = aSelector->StoredIObjects();
121 SALOME_ListIteratorOfListIO anIter(aListIO);
122 for(; anIter.More(); anIter.Next()){
123 Handle(SALOME_InteractiveObject) anIO = anIter.Value();
124 if(anIO->hasEntry()){
125 TColStd_IndexedMapOfInteger anIds;
126 aSelector->GetIndex(anIO,anIds);
127 SALOME_Actor* anActor = aSelector->GetActor(anIO);
129 anActor = VTK::Find<SALOME_Actor>(aView->getRenderer()->GetActors(),VTK::TIsSameIObject<SALOME_Actor>(anIO));
131 aList.append(new SalomeApp_SVTKDataOwner(anIO,anIds,aMode,anActor));
132 if(MYDEBUG) MESSAGE("VTKSelector::getSelection - "<<anIO->getEntry());
142 Sets selection to selector from data owner list \a theList.
145 SalomeApp_VTKSelector
146 ::setSelection( const SUIT_DataOwnerPtrList& theList )
149 if(SUIT_ViewManager* aViewMgr = myViewer->getViewManager()){
150 if(SVTK_ViewWindow* aView = dynamic_cast<SVTK_ViewWindow*>(aViewMgr->getActiveView())){
151 if(SVTK_Selector* aSelector = aView->GetSelector()){
152 SALOME_ListIO anAppendList;
153 const SALOME_ListIO& aStoredList = aSelector->StoredIObjects();
154 SUIT_DataOwnerPtrList::const_iterator anIter = theList.begin();
155 for(; anIter != theList.end(); ++anIter){
156 const SUIT_DataOwner* aDataOwner = (*anIter).get();
157 if(const SalomeApp_SVTKDataOwner* anOwner = dynamic_cast<const SalomeApp_SVTKDataOwner*>(aDataOwner)){
158 aSelector->SetSelectionMode(anOwner->GetMode());
159 Handle(SALOME_InteractiveObject) anIO = anOwner->IO();
161 if( anOwner->GetActor() )
162 aSelector->AddIObject( anOwner->GetActor() );
164 aSelector->AddIObject(anIO);
166 anAppendList.Append(anIO);
167 aSelector->AddOrRemoveIndex(anIO,anOwner->GetIds(),false);
168 if(MYDEBUG) MESSAGE("VTKSelector::setSelection - SVTKDataOwner - "<<anIO->getEntry());
169 }else if(const SalomeApp_DataOwner* anOwner = dynamic_cast<const SalomeApp_DataOwner*>(aDataOwner)){
170 Handle(SALOME_InteractiveObject) anIO =
171 new SALOME_InteractiveObject(anOwner->entry().latin1(),"");
172 aSelector->AddIObject(anIO);
173 anAppendList.Append(anIO);
174 if(MYDEBUG) MESSAGE("VTKSelector::setSelection - DataOwner - "<<anIO->getEntry());
177 // To remove IOs, which is not selected.
178 QMap< QString, Handle( SALOME_InteractiveObject )> toRemove;
179 SALOME_ListIteratorOfListIO anIt( aStoredList );
180 for( ; anIt.More(); anIt.Next() )
181 if( !anIt.Value().IsNull() )
182 toRemove[ anIt.Value()->getEntry() ] = anIt.Value();
184 anIt = SALOME_ListIteratorOfListIO(anAppendList);
185 for( ; anIt.More(); anIt.Next() )
186 toRemove.remove( anIt.Value()->getEntry() );
188 QMap< QString, Handle( SALOME_InteractiveObject )>::const_iterator RIt = toRemove.begin(),
189 REnd = toRemove.end();
190 for( ; RIt!=REnd; RIt++ )
191 aSelector->RemoveIObject( RIt.data() );
193 aView->onSelectionChanged();