1 // Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #include "LightApp_VTKSelector.h"
20 #include "LightApp_DataOwner.h"
22 #ifndef DISABLE_VTKVIEWER
23 #include "SVTK_ViewModelBase.h"
24 #include "SVTK_ViewManager.h"
25 #include "SVTK_Selector.h"
26 #include "SVTK_ViewWindow.h"
27 #include "SVTK_Functor.h"
28 #include "VTKViewer_Algorithm.h"
29 #include <vtkRenderer.h>
32 #ifndef DISABLE_SALOMEOBJECT
33 #include "SALOME_Actor.h"
34 #include "SALOME_ListIteratorOfListIO.hxx"
39 #ifndef DISABLE_VTKVIEWER
40 #ifndef DISABLE_SALOMEOBJECT
44 LightApp_SVTKDataOwner
45 ::LightApp_SVTKDataOwner( const Handle(SALOME_InteractiveObject)& theIO,
46 SUIT_Desktop* theDesktop ):
47 LightApp_DataOwner( theIO ),
48 myDesktop( theDesktop )
55 LightApp_SVTKDataOwner
56 ::~LightApp_SVTKDataOwner()
61 \return active SVTK view window
64 LightApp_SVTKDataOwner
65 ::GetActiveViewWindow() const
67 if(SUIT_ViewWindow* aViewWindow = myDesktop->activeWindow())
68 return dynamic_cast<SVTK_ViewWindow*>(aViewWindow);
74 Gets dataowners ids list.
76 const TColStd_IndexedMapOfInteger&
77 LightApp_SVTKDataOwner
80 if(SVTK_ViewWindow* aViewWindow = GetActiveViewWindow()){
81 if(SVTK_Selector* aSelector = aViewWindow->GetSelector()){
82 aSelector->GetIndex(IO(),myIds);
93 LightApp_SVTKDataOwner
96 if(SVTK_ViewWindow* aViewWindow = GetActiveViewWindow()){
97 if(SVTK_Selector* aSelector = aViewWindow->GetSelector()){
98 return aSelector->SelectionMode();
109 LightApp_SVTKDataOwner
112 if(SVTK_ViewWindow* aViewWindow = GetActiveViewWindow()){
113 using namespace SVTK;
114 return Find<SALOME_Actor>(aViewWindow->getRenderer()->GetActors(),TIsSameIObject<SALOME_Actor>(IO()));
123 #ifndef DISABLE_VTKVIEWER
128 ::LightApp_VTKSelector( SVTK_ViewModelBase* viewer,
129 SUIT_SelectionMgr* mgr ):
130 SUIT_Selector( mgr, viewer ),
134 connect( myViewer, SIGNAL( selectionChanged() ), this, SLOT( onSelectionChanged() ) );
141 ::~LightApp_VTKSelector()
156 Gets type of salome vtk viewer.
162 return myViewer->getType();
167 On selection changed.
171 ::onSelectionChanged()
176 #ifndef DISABLE_VTKVIEWER
179 Gets list of selected data owners.(output \a aList).
183 ::getSelection( SUIT_DataOwnerPtrList& aList ) const
186 if(SUIT_ViewManager* aViewManager = myViewer->getViewManager()){
187 if(SVTK_ViewManager* aViewMgr = dynamic_cast<SVTK_ViewManager*>(aViewManager)){
188 if(SVTK_ViewWindow* aView = dynamic_cast<SVTK_ViewWindow*>(aViewMgr->getActiveView())){
189 if(SVTK_Selector* aSelector = aView->GetSelector()){
190 const SALOME_ListIO& aListIO = aSelector->StoredIObjects();
191 SALOME_ListIteratorOfListIO anIter(aListIO);
192 for(; anIter.More(); anIter.Next()){
193 Handle(SALOME_InteractiveObject) anIO = anIter.Value();
195 aList.append(new LightApp_SVTKDataOwner(anIO,aViewMgr->getDesktop()));
205 Sets selection to selector from data owner list \a theList.
209 ::setSelection( const SUIT_DataOwnerPtrList& theList )
212 if(SUIT_ViewManager* aViewMgr = myViewer->getViewManager()){
213 if(SVTK_ViewWindow* aView = dynamic_cast<SVTK_ViewWindow*>(aViewMgr->getActiveView())){
214 if(SVTK_Selector* aSelector = aView->GetSelector()){
215 SALOME_ListIO anAppendList;
216 const SALOME_ListIO& aStoredList = aSelector->StoredIObjects();
217 SUIT_DataOwnerPtrList::const_iterator anIter = theList.begin();
218 for(; anIter != theList.end(); ++anIter){
219 const SUIT_DataOwner* aDataOwner = (*anIter).get();
220 if(const LightApp_SVTKDataOwner* anOwner = dynamic_cast<const LightApp_SVTKDataOwner*>(aDataOwner)){
221 aSelector->SetSelectionMode(anOwner->GetMode());
222 Handle(SALOME_InteractiveObject) anIO = anOwner->IO();
224 aSelector->AddIObject(anIO);
226 anAppendList.Append(anIO);
227 aSelector->AddOrRemoveIndex(anIO,anOwner->GetIds(),false);
228 }else if(const LightApp_DataOwner* anOwner = dynamic_cast<const LightApp_DataOwner*>(aDataOwner)){
229 Handle(SALOME_InteractiveObject) anIO =
230 new SALOME_InteractiveObject(anOwner->entry().latin1(),"");
231 aSelector->AddIObject(anIO);
232 anAppendList.Append(anIO);
235 // To remove IOs, which is not selected.
236 QMap< QString, Handle( SALOME_InteractiveObject )> toRemove;
237 SALOME_ListIteratorOfListIO anIt( aStoredList );
238 for( ; anIt.More(); anIt.Next() )
239 if( !anIt.Value().IsNull() )
240 toRemove[ anIt.Value()->getEntry() ] = anIt.Value();
242 anIt = SALOME_ListIteratorOfListIO(anAppendList);
243 for( ; anIt.More(); anIt.Next() )
244 toRemove.remove( anIt.Value()->getEntry() );
246 QMap< QString, Handle( SALOME_InteractiveObject )>::const_iterator RIt = toRemove.begin(),
247 REnd = toRemove.end();
248 for( ; RIt!=REnd; RIt++ )
249 aSelector->RemoveIObject( RIt.data() );
251 aView->onSelectionChanged();