1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 #include "LightApp_GLSelector.h"
24 #include "LightApp_DataOwner.h"
26 #include <GLViewer_Context.h>
27 #include <GLViewer_Object.h>
29 /*!Constructor. Initialize by GLViewer_Viewer2d and SUIT_SelectionMgr.*/
30 LightApp_GLSelector::LightApp_GLSelector( GLViewer_Viewer2d* viewer, SUIT_SelectionMgr* mgr )
31 : SUIT_Selector( mgr, viewer ),
35 connect( myViewer, SIGNAL( selectionChanged( SelectionChangeStatus ) ),
36 this, SLOT( onSelectionChanged() ) );
39 /*!Destructor. Do nothing.*/
40 LightApp_GLSelector::~LightApp_GLSelector()
45 GLViewer_Viewer2d* LightApp_GLSelector::viewer() const
50 /*!On selection changed event.*/
51 void LightApp_GLSelector::onSelectionChanged()
56 /*!Gets list of selected Data Owner objects.*/
57 void LightApp_GLSelector::getSelection( SUIT_DataOwnerPtrList& aList ) const
62 GLViewer_Context* cont = myViewer->getGLContext();
66 for ( cont->InitSelected(); cont->MoreSelected(); cont->NextSelected() )
68 GLViewer_Object* obj = cont->SelectedObject();
71 LightApp_DataOwner* owner = dynamic_cast<LightApp_DataOwner*>( obj->owner() );
73 aList.append( SUIT_DataOwnerPtr( new LightApp_DataOwner( owner->entry() ) ) );
78 /*!Sets to selected list of Data Owner objects.*/
79 void LightApp_GLSelector::setSelection( const SUIT_DataOwnerPtrList& aList )
84 GLViewer_Context* cont = myViewer->getGLContext();
88 QMap<QString, int> aSelected;
89 for ( SUIT_DataOwnerPtrList::const_iterator itr = aList.begin(); itr != aList.end(); ++itr )
91 const LightApp_DataOwner* owner = dynamic_cast<const LightApp_DataOwner*>( (*itr).operator->() );
94 aSelected.insert( owner->entry(), 0 );
98 const ObjList& displayed = cont->getObjects();
99 for ( ObjList::const_iterator it = displayed.begin(); it != displayed.end(); ++it )
101 GLViewer_Object* obj = *it;
102 if ( obj && obj->getVisible() )
104 LightApp_DataOwner* owner = dynamic_cast<LightApp_DataOwner*>( obj->owner() );
105 bool sel = owner && aSelected.contains( owner->entry() );
106 changed = changed || sel != (bool)obj->isSelected();
107 if ( sel && !obj->isSelected() )
108 cont->setSelected( obj, false );
109 else if ( !sel && obj->isSelected() )
110 cont->remSelected( obj, false );
115 myViewer->updateAll();