1 #include "LightApp_VTKSelector.h"
2 #include "LightApp_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>
19 LightApp_SVTKDataOwner
20 ::LightApp_SVTKDataOwner( const Handle(SALOME_InteractiveObject)& theIO,
21 const TColStd_IndexedMapOfInteger& theIds,
22 Selection_Mode theMode,
23 SALOME_Actor* theActor):
24 LightApp_DataOwner( theIO ),
25 mySelectionMode(theMode),
28 myIds = theIds; // workaround - there is no constructor copy for the container
34 LightApp_SVTKDataOwner
35 ::~LightApp_SVTKDataOwner()
43 LightApp_SVTKDataOwner
46 return myActor.GetPointer();
53 ::LightApp_VTKSelector( SVTK_Viewer* viewer,
54 SUIT_SelectionMgr* mgr ):
55 SUIT_Selector( mgr, viewer ),
59 connect( myViewer, SIGNAL( selectionChanged() ), this, SLOT( onSelectionChanged() ) );
66 ::~LightApp_VTKSelector()
81 Gets type of vtk viewer.
87 return SVTK_Viewer::Type();
95 ::onSelectionChanged()
101 Gets list of selected data owners.(output \a aList).
105 ::getSelection( SUIT_DataOwnerPtrList& aList ) const
108 if(SUIT_ViewManager* aViewMgr = myViewer->getViewManager()){
109 if(SVTK_ViewWindow* aView = dynamic_cast<SVTK_ViewWindow*>(aViewMgr->getActiveView())){
110 if(SVTK_Selector* aSelector = aView->GetSelector()){
111 Selection_Mode aMode = aSelector->SelectionMode();
112 const SALOME_ListIO& aListIO = aSelector->StoredIObjects();
113 SALOME_ListIteratorOfListIO anIter(aListIO);
114 for(; anIter.More(); anIter.Next()){
115 Handle(SALOME_InteractiveObject) anIO = anIter.Value();
116 if(anIO->hasEntry()){
117 TColStd_IndexedMapOfInteger anIds;
118 aSelector->GetIndex(anIO,anIds);
119 SALOME_Actor* anActor = aSelector->GetActor(anIO);
121 anActor = VTK::Find<SALOME_Actor>(aView->getRenderer()->GetActors(),VTK::TIsSameIObject<SALOME_Actor>(anIO));
123 aList.append(new LightApp_SVTKDataOwner(anIO,anIds,aMode,anActor));
133 Sets selection to selector from data owner list \a theList.
137 ::setSelection( const SUIT_DataOwnerPtrList& theList )
140 if(SUIT_ViewManager* aViewMgr = myViewer->getViewManager()){
141 if(SVTK_ViewWindow* aView = dynamic_cast<SVTK_ViewWindow*>(aViewMgr->getActiveView())){
142 if(SVTK_Selector* aSelector = aView->GetSelector()){
143 SALOME_ListIO anAppendList;
144 const SALOME_ListIO& aStoredList = aSelector->StoredIObjects();
145 SUIT_DataOwnerPtrList::const_iterator anIter = theList.begin();
146 for(; anIter != theList.end(); ++anIter){
147 const SUIT_DataOwner* aDataOwner = (*anIter).get();
148 if(const LightApp_SVTKDataOwner* anOwner = dynamic_cast<const LightApp_SVTKDataOwner*>(aDataOwner)){
149 aSelector->SetSelectionMode(anOwner->GetMode());
150 Handle(SALOME_InteractiveObject) anIO = anOwner->IO();
152 if( anOwner->GetActor() )
153 aSelector->AddIObject( anOwner->GetActor() );
155 aSelector->AddIObject(anIO);
157 anAppendList.Append(anIO);
158 aSelector->AddOrRemoveIndex(anIO,anOwner->GetIds(),false);
159 }else if(const LightApp_DataOwner* anOwner = dynamic_cast<const LightApp_DataOwner*>(aDataOwner)){
160 Handle(SALOME_InteractiveObject) anIO =
161 new SALOME_InteractiveObject(anOwner->entry().latin1(),"");
162 aSelector->AddIObject(anIO);
163 anAppendList.Append(anIO);
166 // To remove IOs, which is not selected.
167 QMap< QString, Handle( SALOME_InteractiveObject )> toRemove;
168 SALOME_ListIteratorOfListIO anIt( aStoredList );
169 for( ; anIt.More(); anIt.Next() )
170 if( !anIt.Value().IsNull() )
171 toRemove[ anIt.Value()->getEntry() ] = anIt.Value();
173 anIt = SALOME_ListIteratorOfListIO(anAppendList);
174 for( ; anIt.More(); anIt.Next() )
175 toRemove.remove( anIt.Value()->getEntry() );
177 QMap< QString, Handle( SALOME_InteractiveObject )>::const_iterator RIt = toRemove.begin(),
178 REnd = toRemove.end();
179 for( ; RIt!=REnd; RIt++ )
180 aSelector->RemoveIObject( RIt.data() );
182 aView->onSelectionChanged();