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_GLSelector.h"
21 #include "LightApp_DataOwner.h"
23 #include <SALOME_GLOwner.h>
25 #include <GLViewer_Context.h>
27 /*!Constructor. Initialize by GLViewer_Viewer2d and SUIT_SelectionMgr.*/
28 LightApp_GLSelector::LightApp_GLSelector( GLViewer_Viewer2d* viewer, SUIT_SelectionMgr* mgr )
29 : SUIT_Selector( mgr, viewer ),
33 connect( myViewer, SIGNAL( selectionChanged( SelectionChangeStatus ) ),
34 this, SLOT( onSelectionChanged() ) );
37 /*!Destructor. Do nothing.*/
38 LightApp_GLSelector::~LightApp_GLSelector()
43 GLViewer_Viewer2d* LightApp_GLSelector::viewer() const
48 /*!On selection changed event.*/
49 void LightApp_GLSelector::onSelectionChanged()
54 /*!Gets list of selected Data Owner objects.*/
55 void LightApp_GLSelector::getSelection( SUIT_DataOwnerPtrList& aList ) const
60 GLViewer_Context* cont = myViewer->getGLContext();
64 for ( cont->InitSelected(); cont->MoreSelected(); cont->NextSelected() )
66 GLViewer_Object* obj = cont->SelectedObject();
69 SALOME_GLOwner* owner = dynamic_cast< SALOME_GLOwner* >( obj->owner() );
71 aList.append( SUIT_DataOwnerPtr( new LightApp_DataOwner( owner->entry() ) ) );
76 /*!Sets to selected list of Data Owner objects.*/
77 void LightApp_GLSelector::setSelection( const SUIT_DataOwnerPtrList& aList )
82 GLViewer_Context* cont = myViewer->getGLContext();
86 QMap<QString, GLViewer_Object*> aDisplayed;
87 const ObjList& displayed = cont->getObjects();
88 for ( ObjList::const_iterator it = displayed.begin(); it != displayed.end(); ++it )
90 GLViewer_Object* obj = *it;
91 if ( obj && obj->getVisible() )
93 SALOME_GLOwner* owner = dynamic_cast< SALOME_GLOwner* >( obj->owner() );
95 aDisplayed.insert( owner->entry(), obj );
100 cont->clearSelected( false );
101 for ( SUIT_DataOwnerPtrList::const_iterator itr = aList.begin(); itr != aList.end(); ++itr )
103 const LightApp_DataOwner* owner = dynamic_cast<const LightApp_DataOwner*>( (*itr).operator->() );
108 if ( aDisplayed.contains( owner->entry() ) )
110 cont->setSelected( aDisplayed[owner->entry()], false );
116 myViewer->updateAll();