1 // Copyright (C) 2007-2016 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, or (at your option) any later version.
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>
36 #include "SVTK_ViewModel.h"
39 #ifndef DISABLE_SALOMEOBJECT
40 #include "SALOME_Actor.h"
41 #include "SALOME_ListIO.hxx"
44 #include <utilities.h>
46 #ifndef DISABLE_VTKVIEWER
47 #ifndef DISABLE_SALOMEOBJECT
51 LightApp_SVTKDataOwner::LightApp_SVTKDataOwner( const Handle(SALOME_InteractiveObject)& theIO,
52 SUIT_Desktop* theDesktop )
53 : LightApp_DataOwner( theIO ),
54 myDesktop( theDesktop )
58 LightApp_SVTKDataOwner::LightApp_SVTKDataOwner( const QString& theEntry )
59 : LightApp_DataOwner( theEntry )
65 \return active SVTK view window
68 LightApp_SVTKDataOwner
69 ::GetActiveViewWindow() const
71 if(SUIT_ViewWindow* aViewWindow = myDesktop->activeWindow())
72 return dynamic_cast<SVTK_ViewWindow*>(aViewWindow);
78 Gets dataowners ids list.
80 const TColStd_IndexedMapOfInteger&
81 LightApp_SVTKDataOwner
84 if(SVTK_ViewWindow* aViewWindow = GetActiveViewWindow()){
85 if(SVTK_Selector* aSelector = aViewWindow->GetSelector()){
86 aSelector->GetIndex(IO(),myIds);
97 LightApp_SVTKDataOwner
100 if(SVTK_ViewWindow* aViewWindow = GetActiveViewWindow()){
101 if(SVTK_Selector* aSelector = aViewWindow->GetSelector()){
102 return aSelector->SelectionMode();
106 return ActorSelection; // workaround for embedded VTK viewer in a module : is it safe ?
113 LightApp_SVTKDataOwner
116 if(SVTK_ViewWindow* aViewWindow = GetActiveViewWindow()){
117 using namespace SVTK;
118 VTK::ActorCollectionCopy aCopy(aViewWindow->getRenderer()->GetActors());
119 return Find<SALOME_Actor>(aCopy.GetActors(),TIsSameIObject<SALOME_Actor>(IO()));
131 LightApp_SVTKDataOwner::~LightApp_SVTKDataOwner()
136 #ifndef DISABLE_VTKVIEWER
141 ::LightApp_VTKSelector( SVTK_ViewModelBase* viewer,
142 SUIT_SelectionMgr* mgr ):
143 SUIT_Selector( mgr, viewer ),
147 connect( myViewer, SIGNAL( selectionChanged() ), this, SLOT( onSelectionChanged() ) );
161 Gets type of salome vtk viewer.
167 return myViewer->getType();
172 On selection changed.
176 ::onSelectionChanged()
181 #ifndef DISABLE_VTKVIEWER
184 Gets list of selected data owners.(output \a aList).
188 ::getSelection( SUIT_DataOwnerPtrList& aList ) const
191 if( SVTK_Viewer* aSViewer = dynamic_cast<SVTK_Viewer*>(myViewer) ) {
192 if( !aSViewer->isSelectionEnabled() )
195 if(SUIT_ViewManager* aViewManager = myViewer->getViewManager()){
196 if(SVTK_ViewManager* aViewMgr = dynamic_cast<SVTK_ViewManager*>(aViewManager)){
197 if(SVTK_ViewWindow* aView = dynamic_cast<SVTK_ViewWindow*>(aViewMgr->getActiveView())){
198 if(SVTK_Selector* aSelector = aView->GetSelector()){
199 const SALOME_ListIO& aListIO = aSelector->StoredIObjects();
200 SALOME_ListIteratorOfListIO anIter(aListIO);
201 for(; anIter.More(); anIter.Next()){
202 Handle(SALOME_InteractiveObject) anIO = anIter.Value();
204 aList.append(new LightApp_SVTKDataOwner(anIO,aViewMgr->getDesktop()));
214 Sets selection to selector from data owner list \a theList.
218 ::setSelection( const SUIT_DataOwnerPtrList& theList )
220 SVTK_Viewer* aViewer = dynamic_cast<SVTK_Viewer*>(myViewer);
221 if ( myViewer && aViewer && ( theList.isEmpty() || aViewer->isSelectionEnabled() )) {
222 if(SUIT_ViewManager* aViewMgr = myViewer->getViewManager()){
223 if(SVTK_ViewWindow* aView = dynamic_cast<SVTK_ViewWindow*>(aViewMgr->getActiveView())){
224 if(SVTK_Selector* aSelector = aView->GetSelector()){
225 SALOME_ListIO anAppendList;
226 const SALOME_ListIO& aStoredList = aSelector->StoredIObjects();
227 SUIT_DataOwnerPtrList::const_iterator anIter = theList.begin();
228 for(; anIter != theList.end(); ++anIter) {
229 const SUIT_DataOwner* aDataOwner = (*anIter).get();
230 if(const LightApp_SVTKDataOwner* anOwner = dynamic_cast<const LightApp_SVTKDataOwner*>(aDataOwner))
232 MESSAGE("aSelector->SetSelectionMode("<<anOwner->GetMode()<<");");
233 aSelector->SetSelectionMode(anOwner->GetMode());
234 Handle(SALOME_InteractiveObject) anIO = anOwner->IO();
236 aSelector->AddIObject(anIO);
238 anAppendList.Append(anIO);
239 aSelector->AddOrRemoveIndex(anIO,anOwner->GetIds(),false);
241 else if(const LightApp_DataOwner* anOwner = dynamic_cast<const LightApp_DataOwner*>(aDataOwner))
243 Handle(SALOME_InteractiveObject) anIO =
244 new SALOME_InteractiveObject(anOwner->entry().toLatin1(),"");
245 aSelector->AddIObject(anIO);
246 anAppendList.Append(anIO);
249 // To remove IOs, which is not selected.
250 QMap< QString, Handle( SALOME_InteractiveObject )> toRemove;
251 SALOME_ListIteratorOfListIO anIt( aStoredList );
252 for( ; anIt.More(); anIt.Next() )
253 if( !anIt.Value().IsNull() )
254 toRemove[ anIt.Value()->getEntry() ] = anIt.Value();
256 anIt = SALOME_ListIteratorOfListIO(anAppendList);
257 for( ; anIt.More(); anIt.Next() )
258 toRemove.remove( anIt.Value()->getEntry() );
260 QMap< QString, Handle( SALOME_InteractiveObject )>::const_iterator RIt = toRemove.begin(),
261 REnd = toRemove.end();
262 for( ; RIt!=REnd; RIt++ )
263 aSelector->RemoveIObject( RIt.value() );
265 aView->onSelectionChanged();