1 #include "SalomeApp_GLSelector.h"
3 #include "SalomeApp_DataOwner.h"
5 #include <SALOME_GLOwner.h>
7 #include <GLViewer_Context.h>
9 /*!Constructor. Initialize by GLViewer_Viewer2d and SUIT_SelectionMgr.*/
10 SalomeApp_GLSelector::SalomeApp_GLSelector( GLViewer_Viewer2d* viewer, SUIT_SelectionMgr* mgr )
11 : SUIT_Selector( mgr, viewer ),
15 connect( myViewer, SIGNAL( selectionChanged() ), this, SLOT( onSelectionChanged() ) );
18 /*!Destructor. Do nothing.*/
19 SalomeApp_GLSelector::~SalomeApp_GLSelector()
24 GLViewer_Viewer2d* SalomeApp_GLSelector::viewer() const
29 /*!On selection changed event.*/
30 void SalomeApp_GLSelector::onSelectionChanged()
35 /*!Gets list of selected Data Owner objects.*/
36 void SalomeApp_GLSelector::getSelection( SUIT_DataOwnerPtrList& aList ) const
41 GLViewer_Context* cont = myViewer->getGLContext();
45 for ( cont->InitSelected(); cont->MoreSelected(); cont->NextSelected() )
47 GLViewer_Object* obj = cont->SelectedObject();
50 SALOME_GLOwner* owner = dynamic_cast< SALOME_GLOwner* >( obj->owner() );
52 aList.append( SUIT_DataOwnerPtr( new SalomeApp_DataOwner( owner->entry() ) ) );
57 /*!Sets to selected list of Data Owner objects.*/
58 void SalomeApp_GLSelector::setSelection( const SUIT_DataOwnerPtrList& aList )
63 GLViewer_Context* cont = myViewer->getGLContext();
67 QMap<QString, GLViewer_Object*> aDisplayed;
68 const ObjList& displayed = cont->getObjects();
69 for ( ObjList::const_iterator it = displayed.begin(); it != displayed.end(); ++it )
71 GLViewer_Object* obj = *it;
72 if ( obj && obj->getVisible() )
74 SALOME_GLOwner* owner = dynamic_cast< SALOME_GLOwner* >( obj->owner() );
76 aDisplayed.insert( owner->entry(), obj );
81 cont->clearSelected( false );
82 for ( SUIT_DataOwnerPtrList::const_iterator itr = aList.begin(); itr != aList.end(); ++itr )
84 const SalomeApp_DataOwner* owner = dynamic_cast<const SalomeApp_DataOwner*>( (*itr).operator->() );
89 if ( aDisplayed.contains( owner->entry() ) )
91 cont->setSelected( aDisplayed[owner->entry()], false );
97 myViewer->updateAll();