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 #ifndef DISABLE_VTKVIEWER
23 #include "SVTK_ViewModelBase.h"
24 #include "SVTK_Selector.h"
25 #include "SVTK_ViewWindow.h"
26 #include "SVTK_Functor.h"
27 #include "VTKViewer_Algorithm.h"
28 #include <vtkRenderer.h>
31 #ifndef DISABLE_SALOMEOBJECT
32 #include "SALOME_Actor.h"
33 #include "SALOME_ListIteratorOfListIO.hxx"
38 #ifndef DISABLE_VTKVIEWER
39 #ifndef DISABLE_SALOMEOBJECT
43 LightApp_SVTKDataOwner
44 ::LightApp_SVTKDataOwner( const Handle(SALOME_InteractiveObject)& theIO,
45 const TColStd_IndexedMapOfInteger& theIds,
46 Selection_Mode theMode,
47 SALOME_Actor* theActor):
48 LightApp_DataOwner( theIO ),
49 mySelectionMode(theMode),
52 myIds = theIds; // workaround - there is no constructor copy for the container
59 LightApp_SVTKDataOwner
60 ::~LightApp_SVTKDataOwner()
68 LightApp_SVTKDataOwner
71 return myActor.GetPointer();
77 #ifndef DISABLE_VTKVIEWER
82 ::LightApp_VTKSelector( SVTK_ViewModelBase* viewer,
83 SUIT_SelectionMgr* mgr ):
84 SUIT_Selector( mgr, viewer ),
88 connect( myViewer, SIGNAL( selectionChanged() ), this, SLOT( onSelectionChanged() ) );
95 ::~LightApp_VTKSelector()
110 Gets type of salome vtk viewer.
116 return myViewer->getType();
121 On selection changed.
125 ::onSelectionChanged()
130 #ifndef DISABLE_VTKVIEWER
133 Gets list of selected data owners.(output \a aList).
137 ::getSelection( SUIT_DataOwnerPtrList& aList ) const
140 if(SUIT_ViewManager* aViewMgr = myViewer->getViewManager()){
141 if(SVTK_ViewWindow* aView = dynamic_cast<SVTK_ViewWindow*>(aViewMgr->getActiveView())){
142 if(SVTK_Selector* aSelector = aView->GetSelector()){
143 Selection_Mode aMode = aSelector->SelectionMode();
144 const SALOME_ListIO& aListIO = aSelector->StoredIObjects();
145 SALOME_ListIteratorOfListIO anIter(aListIO);
146 for(; anIter.More(); anIter.Next()){
147 Handle(SALOME_InteractiveObject) anIO = anIter.Value();
148 if(anIO->hasEntry()){
149 TColStd_IndexedMapOfInteger anIds;
150 aSelector->GetIndex(anIO,anIds);
151 SALOME_Actor* anActor = aSelector->GetActor(anIO);
153 using namespace SVTK;
154 anActor = Find<SALOME_Actor>(aView->getRenderer()->GetActors(),TIsSameIObject<SALOME_Actor>(anIO));
156 aList.append(new LightApp_SVTKDataOwner(anIO,anIds,aMode,anActor));
166 Sets selection to selector from data owner list \a theList.
170 ::setSelection( const SUIT_DataOwnerPtrList& theList )
173 if(SUIT_ViewManager* aViewMgr = myViewer->getViewManager()){
174 if(SVTK_ViewWindow* aView = dynamic_cast<SVTK_ViewWindow*>(aViewMgr->getActiveView())){
175 if(SVTK_Selector* aSelector = aView->GetSelector()){
176 SALOME_ListIO anAppendList;
177 const SALOME_ListIO& aStoredList = aSelector->StoredIObjects();
178 SUIT_DataOwnerPtrList::const_iterator anIter = theList.begin();
179 for(; anIter != theList.end(); ++anIter){
180 const SUIT_DataOwner* aDataOwner = (*anIter).get();
181 if(const LightApp_SVTKDataOwner* anOwner = dynamic_cast<const LightApp_SVTKDataOwner*>(aDataOwner)){
182 aSelector->SetSelectionMode(anOwner->GetMode());
183 Handle(SALOME_InteractiveObject) anIO = anOwner->IO();
185 if( anOwner->GetActor() )
186 aSelector->AddIObject( anOwner->GetActor() );
188 aSelector->AddIObject(anIO);
190 anAppendList.Append(anIO);
191 aSelector->AddOrRemoveIndex(anIO,anOwner->GetIds(),false);
192 }else if(const LightApp_DataOwner* anOwner = dynamic_cast<const LightApp_DataOwner*>(aDataOwner)){
193 Handle(SALOME_InteractiveObject) anIO =
194 new SALOME_InteractiveObject(anOwner->entry().latin1(),"");
195 aSelector->AddIObject(anIO);
196 anAppendList.Append(anIO);
199 // To remove IOs, which is not selected.
200 QMap< QString, Handle( SALOME_InteractiveObject )> toRemove;
201 SALOME_ListIteratorOfListIO anIt( aStoredList );
202 for( ; anIt.More(); anIt.Next() )
203 if( !anIt.Value().IsNull() )
204 toRemove[ anIt.Value()->getEntry() ] = anIt.Value();
206 anIt = SALOME_ListIteratorOfListIO(anAppendList);
207 for( ; anIt.More(); anIt.Next() )
208 toRemove.remove( anIt.Value()->getEntry() );
210 QMap< QString, Handle( SALOME_InteractiveObject )>::const_iterator RIt = toRemove.begin(),
211 REnd = toRemove.end();
212 for( ; RIt!=REnd; RIt++ )
213 aSelector->RemoveIObject( RIt.data() );
215 aView->onSelectionChanged();