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/ or email : webmaster.salome@opencascade.com
19 #include "LightApp_GLSelector.h"
21 #include "LightApp_DataOwner.h"
22 #include "LightApp_DataObject.h"
24 #include <GLViewer_Context.h>
26 /*!Constructor. Initialize by GLViewer_Viewer2d and SUIT_SelectionMgr.*/
27 LightApp_GLSelector::LightApp_GLSelector( GLViewer_Viewer2d* viewer, SUIT_SelectionMgr* mgr )
28 : SUIT_Selector( mgr, viewer ),
32 connect( myViewer, SIGNAL( selectionChanged( SelectionChangeStatus ) ),
33 this, SLOT( onSelectionChanged() ) );
36 /*!Destructor. Do nothing.*/
37 LightApp_GLSelector::~LightApp_GLSelector()
42 GLViewer_Viewer2d* LightApp_GLSelector::viewer() const
47 /*!On selection changed event.*/
48 void LightApp_GLSelector::onSelectionChanged()
53 /*!Gets list of selected Data Owner objects.*/
54 void LightApp_GLSelector::getSelection( SUIT_DataOwnerPtrList& aList ) const
59 GLViewer_Context* cont = myViewer->getGLContext();
63 for ( cont->InitSelected(); cont->MoreSelected(); cont->NextSelected() )
65 GLViewer_Object* obj = cont->SelectedObject();
68 LightApp_DataOwner* owner = dynamic_cast<LightApp_DataOwner*>( obj->owner() );
70 aList.append( SUIT_DataOwnerPtr( new LightApp_DataOwner( owner->entry() ) ) );
75 /*!Sets to selected list of Data Owner objects.*/
76 void LightApp_GLSelector::setSelection( const SUIT_DataOwnerPtrList& aList )
81 GLViewer_Context* cont = myViewer->getGLContext();
85 QMap<QString, int> aSelected;
86 for ( SUIT_DataOwnerPtrList::const_iterator itr = aList.begin(); itr != aList.end(); ++itr )
88 const LightApp_DataOwner* owner = dynamic_cast<const LightApp_DataOwner*>( (*itr).operator->() );
91 aSelected.insert( owner->entry(), 0 );
95 const ObjList& displayed = cont->getObjects();
96 for ( ObjList::const_iterator it = displayed.begin(); it != displayed.end(); ++it )
98 GLViewer_Object* obj = *it;
99 if ( obj && obj->getVisible() )
101 LightApp_DataOwner* owner = dynamic_cast<LightApp_DataOwner*>( obj->owner() );
102 bool sel = owner && aSelected.contains( owner->entry() );
103 changed = changed || sel != (bool)obj->isSelected();
104 if ( sel && !obj->isSelected() )
105 cont->setSelected( obj, false );
106 else if ( !sel && obj->isSelected() )
107 cont->remSelected( obj, false );
112 myViewer->updateAll();