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/
19 #include "LightApp_VTKSelector.h"
20 #include "LightApp_DataOwner.h"
22 #include "SVTK_ViewModel.h"
23 #include "SVTK_Selector.h"
24 #include "SVTK_ViewWindow.h"
25 #include "SVTK_Functor.h"
27 #include "SALOME_Actor.h"
28 #include "SALOME_ListIteratorOfListIO.hxx"
30 #include "VTKViewer_Algorithm.h"
32 #include <vtkRenderer.h>
37 LightApp_SVTKDataOwner
38 ::LightApp_SVTKDataOwner( const Handle(SALOME_InteractiveObject)& theIO,
39 const TColStd_IndexedMapOfInteger& theIds,
40 Selection_Mode theMode,
41 SALOME_Actor* theActor):
42 LightApp_DataOwner( theIO ),
43 mySelectionMode(theMode),
46 myIds = theIds; // workaround - there is no constructor copy for the container
52 LightApp_SVTKDataOwner
53 ::~LightApp_SVTKDataOwner()
61 LightApp_SVTKDataOwner
64 return myActor.GetPointer();
71 ::LightApp_VTKSelector( SVTK_Viewer* viewer,
72 SUIT_SelectionMgr* mgr ):
73 SUIT_Selector( mgr, viewer ),
77 connect( myViewer, SIGNAL( selectionChanged() ), this, SLOT( onSelectionChanged() ) );
84 ::~LightApp_VTKSelector()
99 Gets type of vtk viewer.
105 return SVTK_Viewer::Type();
109 On selection changed.
113 ::onSelectionChanged()
119 Gets list of selected data owners.(output \a aList).
123 ::getSelection( SUIT_DataOwnerPtrList& aList ) const
126 if(SUIT_ViewManager* aViewMgr = myViewer->getViewManager()){
127 if(SVTK_ViewWindow* aView = dynamic_cast<SVTK_ViewWindow*>(aViewMgr->getActiveView())){
128 if(SVTK_Selector* aSelector = aView->GetSelector()){
129 Selection_Mode aMode = aSelector->SelectionMode();
130 const SALOME_ListIO& aListIO = aSelector->StoredIObjects();
131 SALOME_ListIteratorOfListIO anIter(aListIO);
132 for(; anIter.More(); anIter.Next()){
133 Handle(SALOME_InteractiveObject) anIO = anIter.Value();
134 if(anIO->hasEntry()){
135 TColStd_IndexedMapOfInteger anIds;
136 aSelector->GetIndex(anIO,anIds);
137 SALOME_Actor* anActor = aSelector->GetActor(anIO);
139 anActor = VTK::Find<SALOME_Actor>(aView->getRenderer()->GetActors(),VTK::TIsSameIObject<SALOME_Actor>(anIO));
141 aList.append(new LightApp_SVTKDataOwner(anIO,anIds,aMode,anActor));
151 Sets selection to selector from data owner list \a theList.
155 ::setSelection( const SUIT_DataOwnerPtrList& theList )
158 if(SUIT_ViewManager* aViewMgr = myViewer->getViewManager()){
159 if(SVTK_ViewWindow* aView = dynamic_cast<SVTK_ViewWindow*>(aViewMgr->getActiveView())){
160 if(SVTK_Selector* aSelector = aView->GetSelector()){
161 SALOME_ListIO anAppendList;
162 const SALOME_ListIO& aStoredList = aSelector->StoredIObjects();
163 SUIT_DataOwnerPtrList::const_iterator anIter = theList.begin();
164 for(; anIter != theList.end(); ++anIter){
165 const SUIT_DataOwner* aDataOwner = (*anIter).get();
166 if(const LightApp_SVTKDataOwner* anOwner = dynamic_cast<const LightApp_SVTKDataOwner*>(aDataOwner)){
167 aSelector->SetSelectionMode(anOwner->GetMode());
168 Handle(SALOME_InteractiveObject) anIO = anOwner->IO();
170 if( anOwner->GetActor() )
171 aSelector->AddIObject( anOwner->GetActor() );
173 aSelector->AddIObject(anIO);
175 anAppendList.Append(anIO);
176 aSelector->AddOrRemoveIndex(anIO,anOwner->GetIds(),false);
177 }else if(const LightApp_DataOwner* anOwner = dynamic_cast<const LightApp_DataOwner*>(aDataOwner)){
178 Handle(SALOME_InteractiveObject) anIO =
179 new SALOME_InteractiveObject(anOwner->entry().latin1(),"");
180 aSelector->AddIObject(anIO);
181 anAppendList.Append(anIO);
184 // To remove IOs, which is not selected.
185 QMap< QString, Handle( SALOME_InteractiveObject )> toRemove;
186 SALOME_ListIteratorOfListIO anIt( aStoredList );
187 for( ; anIt.More(); anIt.Next() )
188 if( !anIt.Value().IsNull() )
189 toRemove[ anIt.Value()->getEntry() ] = anIt.Value();
191 anIt = SALOME_ListIteratorOfListIO(anAppendList);
192 for( ; anIt.More(); anIt.Next() )
193 toRemove.remove( anIt.Value()->getEntry() );
195 QMap< QString, Handle( SALOME_InteractiveObject )>::const_iterator RIt = toRemove.begin(),
196 REnd = toRemove.end();
197 for( ; RIt!=REnd; RIt++ )
198 aSelector->RemoveIObject( RIt.data() );
200 aView->onSelectionChanged();