1 // Copyright (C) 2007-2014 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, or (at your option) any later version.
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
23 #include "LightApp_GLSelector.h"
25 #include "LightApp_DataOwner.h"
27 #include <GLViewer_Context.h>
28 #include <GLViewer_Object.h>
30 /*!Constructor. Initialize by GLViewer_Viewer2d and SUIT_SelectionMgr.*/
31 LightApp_GLSelector::LightApp_GLSelector( GLViewer_Viewer2d* viewer, SUIT_SelectionMgr* mgr )
32 : SUIT_Selector( mgr, viewer ),
36 connect( myViewer, SIGNAL( selectionChanged( SelectionChangeStatus ) ),
37 this, SLOT( onSelectionChanged() ) );
40 /*!Destructor. Do nothing.*/
41 LightApp_GLSelector::~LightApp_GLSelector()
46 GLViewer_Viewer2d* LightApp_GLSelector::viewer() const
51 /*!On selection changed event.*/
52 void LightApp_GLSelector::onSelectionChanged()
57 /*!Gets list of selected Data Owner objects.*/
58 void LightApp_GLSelector::getSelection( SUIT_DataOwnerPtrList& aList ) const
63 GLViewer_Context* cont = myViewer->getGLContext();
67 for ( cont->InitSelected(); cont->MoreSelected(); cont->NextSelected() )
69 GLViewer_Object* obj = cont->SelectedObject();
72 LightApp_DataOwner* owner = dynamic_cast<LightApp_DataOwner*>( obj->owner() );
74 aList.append( SUIT_DataOwnerPtr( new LightApp_DataOwner( owner->entry() ) ) );
79 /*!Sets to selected list of Data Owner objects.*/
80 void LightApp_GLSelector::setSelection( const SUIT_DataOwnerPtrList& aList )
85 GLViewer_Context* cont = myViewer->getGLContext();
89 QMap<QString, int> aSelected;
90 for ( SUIT_DataOwnerPtrList::const_iterator itr = aList.begin(); itr != aList.end(); ++itr )
92 const LightApp_DataOwner* owner = dynamic_cast<const LightApp_DataOwner*>( (*itr).operator->() );
95 aSelected.insert( owner->entry(), 0 );
99 const ObjList& displayed = cont->getObjects();
100 for ( ObjList::const_iterator it = displayed.begin(); it != displayed.end(); ++it )
102 GLViewer_Object* obj = *it;
103 if ( obj && obj->getVisible() )
105 LightApp_DataOwner* owner = dynamic_cast<LightApp_DataOwner*>( obj->owner() );
106 bool sel = owner && aSelected.contains( owner->entry() );
107 changed = changed || sel != (bool)obj->isSelected();
108 if ( sel && !obj->isSelected() )
109 cont->setSelected( obj, false );
110 else if ( !sel && obj->isSelected() )
111 cont->remSelected( obj, false );
116 myViewer->updateAll();