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 <GLViewer_Context.h>
25 /*!Constructor. Initialize by GLViewer_Viewer2d and SUIT_SelectionMgr.*/
26 LightApp_GLSelector::LightApp_GLSelector( GLViewer_Viewer2d* viewer, SUIT_SelectionMgr* mgr )
27 : SUIT_Selector( mgr, viewer ),
31 connect( myViewer, SIGNAL( selectionChanged( SelectionChangeStatus ) ),
32 this, SLOT( onSelectionChanged() ) );
35 /*!Destructor. Do nothing.*/
36 LightApp_GLSelector::~LightApp_GLSelector()
41 GLViewer_Viewer2d* LightApp_GLSelector::viewer() const
46 /*!On selection changed event.*/
47 void LightApp_GLSelector::onSelectionChanged()
52 /*!Gets list of selected Data Owner objects.*/
53 void LightApp_GLSelector::getSelection( SUIT_DataOwnerPtrList& aList ) const
58 GLViewer_Context* cont = myViewer->getGLContext();
62 for ( cont->InitSelected(); cont->MoreSelected(); cont->NextSelected() )
64 GLViewer_Object* obj = cont->SelectedObject();
67 LightApp_GLOwner* owner = dynamic_cast< LightApp_GLOwner* >( obj->owner() );
69 aList.append( SUIT_DataOwnerPtr( new LightApp_DataOwner( owner->entry() ) ) );
74 /*!Sets to selected list of Data Owner objects.*/
75 void LightApp_GLSelector::setSelection( const SUIT_DataOwnerPtrList& aList )
80 GLViewer_Context* cont = myViewer->getGLContext();
84 QMap<QString, GLViewer_Object*> aDisplayed;
85 const ObjList& displayed = cont->getObjects();
86 for ( ObjList::const_iterator it = displayed.begin(); it != displayed.end(); ++it )
88 GLViewer_Object* obj = *it;
89 if ( obj && obj->getVisible() )
91 LightApp_GLOwner* owner = dynamic_cast< LightApp_GLOwner* >( obj->owner() );
93 aDisplayed.insert( owner->entry(), obj );
98 cont->clearSelected( false );
99 for ( SUIT_DataOwnerPtrList::const_iterator itr = aList.begin(); itr != aList.end(); ++itr )
101 const LightApp_DataOwner* owner = dynamic_cast<const LightApp_DataOwner*>( (*itr).operator->() );
106 if ( aDisplayed.contains( owner->entry() ) )
108 cont->setSelected( aDisplayed[owner->entry()], false );
114 myViewer->updateAll();
120 \param entry - entry of object
122 LightApp_GLOwner::LightApp_GLOwner( const char* entry )
131 LightApp_GLOwner::~LightApp_GLOwner()
138 const char* LightApp_GLOwner::entry() const
140 return myEntry.c_str();
145 \param entry - entry of object
147 void LightApp_GLOwner::setEntry( const char* entry )