Back to index

salome-gui  6.5.0
LightApp_VTKSelector.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 #include "LightApp_VTKSelector.h"
00024 #include "LightApp_DataOwner.h"
00025 
00026 #include "SUIT_Desktop.h"
00027 
00028 #ifndef DISABLE_VTKVIEWER
00029   #include "SVTK_ViewModelBase.h"
00030   #include "SVTK_ViewManager.h"
00031   #include "SVTK_Selector.h"
00032   #include "SVTK_ViewWindow.h"
00033   #include "SVTK_Functor.h"
00034   #include "VTKViewer_Algorithm.h"
00035   #include <vtkRenderer.h>
00036 #endif
00037 
00038 #ifndef DISABLE_SALOMEOBJECT
00039   #include "SALOME_Actor.h"
00040   #include "SALOME_ListIteratorOfListIO.hxx"
00041 #endif
00042 
00043 
00044 
00045 #ifndef DISABLE_VTKVIEWER
00046 #ifndef DISABLE_SALOMEOBJECT
00047 
00050 LightApp_SVTKDataOwner::LightApp_SVTKDataOwner( const Handle(SALOME_InteractiveObject)& theIO,
00051                                                                   SUIT_Desktop* theDesktop )
00052 : LightApp_DataOwner( theIO ),
00053 myDesktop( theDesktop )
00054 {
00055 }
00056 #else
00057 LightApp_SVTKDataOwner::LightApp_SVTKDataOwner( const QString& theEntry )
00058 : LightApp_DataOwner( theEntry )
00059 {
00060 }
00061 #endif
00062 
00066 SVTK_ViewWindow* 
00067 LightApp_SVTKDataOwner
00068 ::GetActiveViewWindow() const
00069 {
00070   if(SUIT_ViewWindow* aViewWindow = myDesktop->activeWindow())
00071     return dynamic_cast<SVTK_ViewWindow*>(aViewWindow);
00072 
00073   return NULL;
00074 }
00075 
00079 const TColStd_IndexedMapOfInteger& 
00080 LightApp_SVTKDataOwner
00081 ::GetIds() const
00082 {
00083   if(SVTK_ViewWindow* aViewWindow = GetActiveViewWindow()){
00084     if(SVTK_Selector* aSelector = aViewWindow->GetSelector()){
00085       aSelector->GetIndex(IO(),myIds);
00086     }
00087   }
00088 
00089   return myIds;
00090 }
00091 
00095 Selection_Mode
00096 LightApp_SVTKDataOwner
00097 ::GetMode() const
00098 {
00099   if(SVTK_ViewWindow* aViewWindow = GetActiveViewWindow()){
00100     if(SVTK_Selector* aSelector = aViewWindow->GetSelector()){
00101       return aSelector->SelectionMode();
00102     }
00103   }
00104   
00105   return -1;
00106 }
00107 
00111 SALOME_Actor* 
00112 LightApp_SVTKDataOwner
00113 ::GetActor() const
00114 {
00115   if(SVTK_ViewWindow* aViewWindow = GetActiveViewWindow()){
00116     using namespace SVTK;
00117     VTK::ActorCollectionCopy aCopy(aViewWindow->getRenderer()->GetActors());
00118     return Find<SALOME_Actor>(aCopy.GetActors(),TIsSameIObject<SALOME_Actor>(IO()));
00119   }
00120 
00121   return NULL;
00122 }
00123 
00124 #endif
00125 
00129 /*
00130 LightApp_SVTKDataOwner::~LightApp_SVTKDataOwner()
00131 {
00132 }
00133 */
00134 
00135 #ifndef DISABLE_VTKVIEWER
00136 
00139 LightApp_VTKSelector
00140 ::LightApp_VTKSelector( SVTK_ViewModelBase* viewer, 
00141                         SUIT_SelectionMgr* mgr ): 
00142   SUIT_Selector( mgr, viewer ),
00143   myViewer( viewer )
00144 {
00145   if ( myViewer )
00146     connect( myViewer, SIGNAL( selectionChanged() ), this, SLOT( onSelectionChanged() ) );
00147 }
00148 
00152 SVTK_ViewModelBase* 
00153 LightApp_VTKSelector
00154 ::viewer() const
00155 {
00156   return myViewer;
00157 }
00158 
00162 QString
00163 LightApp_VTKSelector
00164 ::type() const
00165 { 
00166   return myViewer->getType(); 
00167 }
00168 
00169 #endif
00170 
00173 void
00174 LightApp_VTKSelector
00175 ::onSelectionChanged()
00176 {
00177   selectionChanged();
00178 }
00179 
00180 #ifndef DISABLE_VTKVIEWER
00181 
00185 void
00186 LightApp_VTKSelector
00187 ::getSelection( SUIT_DataOwnerPtrList& aList ) const
00188 {
00189   if(myViewer){
00190     if(SUIT_ViewManager* aViewManager = myViewer->getViewManager()){
00191       if(SVTK_ViewManager* aViewMgr = dynamic_cast<SVTK_ViewManager*>(aViewManager)){
00192         if(SVTK_ViewWindow* aView = dynamic_cast<SVTK_ViewWindow*>(aViewMgr->getActiveView())){
00193           if(SVTK_Selector* aSelector = aView->GetSelector()){
00194             const SALOME_ListIO& aListIO = aSelector->StoredIObjects();
00195             SALOME_ListIteratorOfListIO anIter(aListIO);
00196             for(; anIter.More(); anIter.Next()){
00197               Handle(SALOME_InteractiveObject) anIO = anIter.Value();
00198               if(anIO->hasEntry())
00199                 aList.append(new LightApp_SVTKDataOwner(anIO,aViewMgr->getDesktop()));
00200             }
00201           }
00202         }
00203       }
00204     }
00205   }
00206 }
00207 
00211 void 
00212 LightApp_VTKSelector
00213 ::setSelection( const SUIT_DataOwnerPtrList& theList )
00214 {
00215   if(myViewer){
00216     if(SUIT_ViewManager* aViewMgr = myViewer->getViewManager()){
00217       if(SVTK_ViewWindow* aView = dynamic_cast<SVTK_ViewWindow*>(aViewMgr->getActiveView())){
00218         if(SVTK_Selector* aSelector = aView->GetSelector()){
00219           SALOME_ListIO anAppendList;
00220           const SALOME_ListIO& aStoredList = aSelector->StoredIObjects();
00221           SUIT_DataOwnerPtrList::const_iterator anIter = theList.begin();
00222           for(; anIter != theList.end(); ++anIter){
00223             const SUIT_DataOwner* aDataOwner = (*anIter).get();
00224             if(const LightApp_SVTKDataOwner* anOwner = dynamic_cast<const LightApp_SVTKDataOwner*>(aDataOwner)){
00225               aSelector->SetSelectionMode(anOwner->GetMode());
00226               Handle(SALOME_InteractiveObject) anIO = anOwner->IO();
00227 
00228               aSelector->AddIObject(anIO);
00229 
00230               anAppendList.Append(anIO);
00231               aSelector->AddOrRemoveIndex(anIO,anOwner->GetIds(),false);
00232             }else if(const LightApp_DataOwner* anOwner = dynamic_cast<const LightApp_DataOwner*>(aDataOwner)){
00233               Handle(SALOME_InteractiveObject) anIO = 
00234                 new SALOME_InteractiveObject(anOwner->entry().toLatin1(),"");
00235               aSelector->AddIObject(anIO);
00236               anAppendList.Append(anIO);
00237             }
00238           }
00239           // To remove IOs, which is not selected.
00240           QMap< QString, Handle( SALOME_InteractiveObject )> toRemove;
00241           SALOME_ListIteratorOfListIO anIt( aStoredList );
00242           for( ; anIt.More(); anIt.Next() )
00243             if( !anIt.Value().IsNull() )
00244               toRemove[ anIt.Value()->getEntry() ] = anIt.Value();
00245 
00246           anIt = SALOME_ListIteratorOfListIO(anAppendList);
00247           for( ; anIt.More(); anIt.Next() )
00248             toRemove.remove( anIt.Value()->getEntry() );
00249 
00250           QMap< QString, Handle( SALOME_InteractiveObject )>::const_iterator RIt = toRemove.begin(),
00251                                                                              REnd = toRemove.end();
00252           for( ; RIt!=REnd; RIt++ )
00253             aSelector->RemoveIObject( RIt.value() );
00254           
00255           aView->onSelectionChanged();
00256         }
00257       }
00258     }
00259   }
00260 }
00261 
00262 #endif