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::LightApp_SVTKDataOwner( const Handle(SALOME_InteractiveObject)& theIO,
45 SUIT_Desktop* theDesktop )
46 : LightApp_DataOwner( theIO ),
47 myDesktop( theDesktop )
51 LightApp_SVTKDataOwner::LightApp_SVTKDataOwner( const QString& theEntry )
52 : LightApp_DataOwner( theEntry )
58 \return active SVTK view window
61 LightApp_SVTKDataOwner
62 ::GetActiveViewWindow() const
64 if(SUIT_ViewWindow* aViewWindow = myDesktop->activeWindow())
65 return dynamic_cast<SVTK_ViewWindow*>(aViewWindow);
71 Gets dataowners ids list.
73 const TColStd_IndexedMapOfInteger&
74 LightApp_SVTKDataOwner
77 if(SVTK_ViewWindow* aViewWindow = GetActiveViewWindow()){
78 if(SVTK_Selector* aSelector = aViewWindow->GetSelector()){
79 aSelector->GetIndex(IO(),myIds);
90 LightApp_SVTKDataOwner
93 if(SVTK_ViewWindow* aViewWindow = GetActiveViewWindow()){
94 if(SVTK_Selector* aSelector = aViewWindow->GetSelector()){
95 return aSelector->SelectionMode();
106 LightApp_SVTKDataOwner
109 if(SVTK_ViewWindow* aViewWindow = GetActiveViewWindow()){
110 using namespace SVTK;
111 return Find<SALOME_Actor>(aViewWindow->getRenderer()->GetActors(),TIsSameIObject<SALOME_Actor>(IO()));
123 LightApp_SVTKDataOwner::~LightApp_SVTKDataOwner()
128 #ifndef DISABLE_VTKVIEWER
133 ::LightApp_VTKSelector( SVTK_ViewModelBase* viewer,
134 SUIT_SelectionMgr* mgr ):
135 SUIT_Selector( mgr, viewer ),
139 connect( myViewer, SIGNAL( selectionChanged() ), this, SLOT( onSelectionChanged() ) );
153 Gets type of salome vtk viewer.
159 return myViewer->getType();
164 On selection changed.
168 ::onSelectionChanged()
173 #ifndef DISABLE_VTKVIEWER
176 Gets list of selected data owners.(output \a aList).
180 ::getSelection( SUIT_DataOwnerPtrList& aList ) const
183 if(SUIT_ViewManager* aViewManager = myViewer->getViewManager()){
184 if(SVTK_ViewManager* aViewMgr = dynamic_cast<SVTK_ViewManager*>(aViewManager)){
185 if(SVTK_ViewWindow* aView = dynamic_cast<SVTK_ViewWindow*>(aViewMgr->getActiveView())){
186 if(SVTK_Selector* aSelector = aView->GetSelector()){
187 const SALOME_ListIO& aListIO = aSelector->StoredIObjects();
188 SALOME_ListIteratorOfListIO anIter(aListIO);
189 for(; anIter.More(); anIter.Next()){
190 Handle(SALOME_InteractiveObject) anIO = anIter.Value();
192 aList.append(new LightApp_SVTKDataOwner(anIO,aViewMgr->getDesktop()));
202 Sets selection to selector from data owner list \a theList.
206 ::setSelection( const SUIT_DataOwnerPtrList& theList )
209 if(SUIT_ViewManager* aViewMgr = myViewer->getViewManager()){
210 if(SVTK_ViewWindow* aView = dynamic_cast<SVTK_ViewWindow*>(aViewMgr->getActiveView())){
211 if(SVTK_Selector* aSelector = aView->GetSelector()){
212 SALOME_ListIO anAppendList;
213 const SALOME_ListIO& aStoredList = aSelector->StoredIObjects();
214 SUIT_DataOwnerPtrList::const_iterator anIter = theList.begin();
215 for(; anIter != theList.end(); ++anIter){
216 const SUIT_DataOwner* aDataOwner = (*anIter).get();
217 if(const LightApp_SVTKDataOwner* anOwner = dynamic_cast<const LightApp_SVTKDataOwner*>(aDataOwner)){
218 aSelector->SetSelectionMode(anOwner->GetMode());
219 Handle(SALOME_InteractiveObject) anIO = anOwner->IO();
221 aSelector->AddIObject(anIO);
223 anAppendList.Append(anIO);
224 aSelector->AddOrRemoveIndex(anIO,anOwner->GetIds(),false);
225 }else if(const LightApp_DataOwner* anOwner = dynamic_cast<const LightApp_DataOwner*>(aDataOwner)){
226 Handle(SALOME_InteractiveObject) anIO =
227 new SALOME_InteractiveObject(anOwner->entry().latin1(),"");
228 aSelector->AddIObject(anIO);
229 anAppendList.Append(anIO);
232 // To remove IOs, which is not selected.
233 QMap< QString, Handle( SALOME_InteractiveObject )> toRemove;
234 SALOME_ListIteratorOfListIO anIt( aStoredList );
235 for( ; anIt.More(); anIt.Next() )
236 if( !anIt.Value().IsNull() )
237 toRemove[ anIt.Value()->getEntry() ] = anIt.Value();
239 anIt = SALOME_ListIteratorOfListIO(anAppendList);
240 for( ; anIt.More(); anIt.Next() )
241 toRemove.remove( anIt.Value()->getEntry() );
243 QMap< QString, Handle( SALOME_InteractiveObject )>::const_iterator RIt = toRemove.begin(),
244 REnd = toRemove.end();
245 for( ; RIt!=REnd; RIt++ )
246 aSelector->RemoveIObject( RIt.data() );
248 aView->onSelectionChanged();