Back to index

salome-gui  6.5.0
LightApp_OCCSelector.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_DataOwner.h"
00024 #include "LightApp_OCCSelector.h"
00025 
00026 #ifndef DISABLE_SALOMEOBJECT
00027   #include <SALOME_InteractiveObject.hxx>
00028 #endif
00029 #include <AIS_ListOfInteractive.hxx>
00030 #include <AIS_ListIteratorOfListOfInteractive.hxx>
00031 
00035 #ifndef DISABLE_OCCVIEWER
00036 LightApp_OCCSelector::LightApp_OCCSelector( OCCViewer_Viewer* viewer, SUIT_SelectionMgr* mgr )
00037 : SUIT_Selector( mgr, viewer ),
00038   myViewer( viewer )
00039 {
00040   if ( myViewer ) {
00041     connect( myViewer, SIGNAL( selectionChanged() ), this, SLOT( onSelectionChanged() ) );
00042     connect( myViewer, SIGNAL( deselection() ), this, SLOT( onDeselection() ) );
00043   }
00044 }
00045 #else
00046 LightApp_OCCSelector::LightApp_OCCSelector(  SUIT_SelectionMgr* mgr )
00047 : SUIT_Selector( mgr )
00048 {}
00049 #endif
00050 
00054 LightApp_OCCSelector::~LightApp_OCCSelector()
00055 {
00056 }
00057 
00061 #ifndef DISABLE_OCCVIEWER
00062 OCCViewer_Viewer* LightApp_OCCSelector::viewer() const
00063 {
00064   return myViewer;
00065 }
00066 #endif
00067 
00068 
00070 void LightApp_OCCSelector::onSelectionChanged()
00071 {
00072   selectionChanged();
00073 }
00074 
00076 void LightApp_OCCSelector::onDeselection()
00077 {
00078   mySelectedExternals.clear();
00079 }
00080 
00082 void LightApp_OCCSelector::getSelection( SUIT_DataOwnerPtrList& aList ) const
00083 {
00084 #ifndef DISABLE_OCCVIEWER
00085   if ( !myViewer )
00086     return;
00087 
00088   AIS_ListOfInteractive aSelList;
00089   myViewer->getSelectedObjects( aSelList );
00090   for ( AIS_ListIteratorOfListOfInteractive anIt( aSelList ); anIt.More(); anIt.Next() )
00091     if ( !anIt.Value().IsNull() )
00092     {
00093 #ifndef DISABLE_SALOMEOBJECT
00094       Handle(SALOME_InteractiveObject) anObj = Handle(SALOME_InteractiveObject)::DownCast(anIt.Value()->GetOwner());
00095       if( !anObj.IsNull() )
00096         aList.append( SUIT_DataOwnerPtr( new LightApp_DataOwner( anObj ) ) );
00097 #else
00098       aList.append( SUIT_DataOwnerPtr( new LightApp_DataOwner( entry( anIt.Value() ) ) ) );
00099 #endif
00100     }
00101   // add externally selected objects
00102   SUIT_DataOwnerPtrList::const_iterator anExtIter;
00103   for(anExtIter = mySelectedExternals.begin(); anExtIter != mySelectedExternals.end(); anExtIter++) {
00104     aList.append(*anExtIter);
00105   }
00106 #endif
00107 }
00108 
00110 void LightApp_OCCSelector::setSelection( const SUIT_DataOwnerPtrList& aList )
00111 {
00112 #ifndef DISABLE_OCCVIEWER
00113   if ( !myViewer )
00114     return;
00115 
00116   QMap<QString, Handle(AIS_InteractiveObject)> aDisplayed;
00117   Handle(AIS_InteractiveContext) aContext = myViewer->getAISContext();
00118   if ( aContext.IsNull() )
00119     return;
00120     
00121   AIS_ListOfInteractive aDispList, aSelList;
00122   aContext->DisplayedObjects( aDispList );
00123 
00124   for ( AIS_ListIteratorOfListOfInteractive it( aDispList ); it.More(); it.Next() )
00125   {
00126     QString entryStr = entry( it.Value() );
00127     if ( !entryStr.isEmpty() )
00128       aDisplayed.insert( entryStr, it.Value() );
00129   }
00130   
00131   mySelectedExternals.clear();
00132 
00133   for ( SUIT_DataOwnerPtrList::const_iterator itr = aList.begin(); itr != aList.end(); ++itr )
00134   {
00135     const LightApp_DataOwner* owner = dynamic_cast<const LightApp_DataOwner*>( (*itr).operator->() );
00136     if ( owner && aDisplayed.contains( owner->entry() ) )
00137       aSelList.Append( aDisplayed[owner->entry()] );
00138     else
00139       mySelectedExternals.append(*itr);
00140   }
00141 
00142   myViewer->unHighlightAll( false );
00143   myViewer->setObjectsSelected( aSelList );
00144 #endif
00145 }
00146 
00147 #ifndef DISABLE_OCCVIEWER
00148 
00149 QString LightApp_OCCSelector::entry( const Handle(AIS_InteractiveObject)& anAIS ) const
00150 {
00151   if ( anAIS.IsNull() || !anAIS->HasOwner() )
00152     return QString();
00153 
00154   QString res;
00155 
00156 #ifndef DISABLE_SALOMEOBJECT
00157   Handle(SALOME_InteractiveObject) anObj = Handle(SALOME_InteractiveObject)::DownCast(anAIS->GetOwner());
00158   if ( !anObj.IsNull() )
00159     res = QString( anObj->getEntry() );
00160 #endif
00161 
00162   return res;
00163 }
00164 #endif