1 // Copyright (C) 2007-2012 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #include "LightApp_VTKSelector.h"
24 #include "LightApp_DataOwner.h"
26 #include "SUIT_Desktop.h"
28 #ifndef DISABLE_VTKVIEWER
29 #include "SVTK_ViewModelBase.h"
30 #include "SVTK_ViewManager.h"
31 #include "SVTK_Selector.h"
32 #include "SVTK_ViewWindow.h"
33 #include "SVTK_Functor.h"
34 #include "VTKViewer_Algorithm.h"
35 #include <vtkRenderer.h>
38 #ifndef DISABLE_SALOMEOBJECT
39 #include "SALOME_Actor.h"
40 #include "SALOME_ListIteratorOfListIO.hxx"
45 #ifndef DISABLE_VTKVIEWER
46 #ifndef DISABLE_SALOMEOBJECT
50 LightApp_SVTKDataOwner::LightApp_SVTKDataOwner( const Handle(SALOME_InteractiveObject)& theIO,
51 SUIT_Desktop* theDesktop )
52 : LightApp_DataOwner( theIO ),
53 myDesktop( theDesktop )
57 LightApp_SVTKDataOwner::LightApp_SVTKDataOwner( const QString& theEntry )
58 : LightApp_DataOwner( theEntry )
64 \return active SVTK view window
67 LightApp_SVTKDataOwner
68 ::GetActiveViewWindow() const
70 if(SUIT_ViewWindow* aViewWindow = myDesktop->activeWindow())
71 return dynamic_cast<SVTK_ViewWindow*>(aViewWindow);
77 Gets dataowners ids list.
79 const TColStd_IndexedMapOfInteger&
80 LightApp_SVTKDataOwner
83 if(SVTK_ViewWindow* aViewWindow = GetActiveViewWindow()){
84 if(SVTK_Selector* aSelector = aViewWindow->GetSelector()){
85 aSelector->GetIndex(IO(),myIds);
96 LightApp_SVTKDataOwner
99 if(SVTK_ViewWindow* aViewWindow = GetActiveViewWindow()){
100 if(SVTK_Selector* aSelector = aViewWindow->GetSelector()){
101 return aSelector->SelectionMode();
112 LightApp_SVTKDataOwner
115 if(SVTK_ViewWindow* aViewWindow = GetActiveViewWindow()){
116 using namespace SVTK;
117 VTK::ActorCollectionCopy aCopy(aViewWindow->getRenderer()->GetActors());
118 return Find<SALOME_Actor>(aCopy.GetActors(),TIsSameIObject<SALOME_Actor>(IO()));
130 LightApp_SVTKDataOwner::~LightApp_SVTKDataOwner()
135 #ifndef DISABLE_VTKVIEWER
140 ::LightApp_VTKSelector( SVTK_ViewModelBase* viewer,
141 SUIT_SelectionMgr* mgr ):
142 SUIT_Selector( mgr, viewer ),
146 connect( myViewer, SIGNAL( selectionChanged() ), this, SLOT( onSelectionChanged() ) );
160 Gets type of salome vtk viewer.
166 return myViewer->getType();
171 On selection changed.
175 ::onSelectionChanged()
180 #ifndef DISABLE_VTKVIEWER
183 Gets list of selected data owners.(output \a aList).
187 ::getSelection( SUIT_DataOwnerPtrList& aList ) const
190 if(SUIT_ViewManager* aViewManager = myViewer->getViewManager()){
191 if(SVTK_ViewManager* aViewMgr = dynamic_cast<SVTK_ViewManager*>(aViewManager)){
192 if(SVTK_ViewWindow* aView = dynamic_cast<SVTK_ViewWindow*>(aViewMgr->getActiveView())){
193 if(SVTK_Selector* aSelector = aView->GetSelector()){
194 const SALOME_ListIO& aListIO = aSelector->StoredIObjects();
195 SALOME_ListIteratorOfListIO anIter(aListIO);
196 for(; anIter.More(); anIter.Next()){
197 Handle(SALOME_InteractiveObject) anIO = anIter.Value();
199 aList.append(new LightApp_SVTKDataOwner(anIO,aViewMgr->getDesktop()));
209 Sets selection to selector from data owner list \a theList.
213 ::setSelection( const SUIT_DataOwnerPtrList& theList )
216 if(SUIT_ViewManager* aViewMgr = myViewer->getViewManager()){
217 if(SVTK_ViewWindow* aView = dynamic_cast<SVTK_ViewWindow*>(aViewMgr->getActiveView())){
218 if(SVTK_Selector* aSelector = aView->GetSelector()){
219 SALOME_ListIO anAppendList;
220 const SALOME_ListIO& aStoredList = aSelector->StoredIObjects();
221 SUIT_DataOwnerPtrList::const_iterator anIter = theList.begin();
222 for(; anIter != theList.end(); ++anIter){
223 const SUIT_DataOwner* aDataOwner = (*anIter).get();
224 if(const LightApp_SVTKDataOwner* anOwner = dynamic_cast<const LightApp_SVTKDataOwner*>(aDataOwner)){
225 aSelector->SetSelectionMode(anOwner->GetMode());
226 Handle(SALOME_InteractiveObject) anIO = anOwner->IO();
228 aSelector->AddIObject(anIO);
230 anAppendList.Append(anIO);
231 aSelector->AddOrRemoveIndex(anIO,anOwner->GetIds(),false);
232 }else if(const LightApp_DataOwner* anOwner = dynamic_cast<const LightApp_DataOwner*>(aDataOwner)){
233 Handle(SALOME_InteractiveObject) anIO =
234 new SALOME_InteractiveObject(anOwner->entry().toLatin1(),"");
235 aSelector->AddIObject(anIO);
236 anAppendList.Append(anIO);
239 // To remove IOs, which is not selected.
240 QMap< QString, Handle( SALOME_InteractiveObject )> toRemove;
241 SALOME_ListIteratorOfListIO anIt( aStoredList );
242 for( ; anIt.More(); anIt.Next() )
243 if( !anIt.Value().IsNull() )
244 toRemove[ anIt.Value()->getEntry() ] = anIt.Value();
246 anIt = SALOME_ListIteratorOfListIO(anAppendList);
247 for( ; anIt.More(); anIt.Next() )
248 toRemove.remove( anIt.Value()->getEntry() );
250 QMap< QString, Handle( SALOME_InteractiveObject )>::const_iterator RIt = toRemove.begin(),
251 REnd = toRemove.end();
252 for( ; RIt!=REnd; RIt++ )
253 aSelector->RemoveIObject( RIt.value() );
255 aView->onSelectionChanged();