1 // LIGHT : sample (no-corba-engine) SALOME module
3 // Copyright (C) 2003 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 // Author : Julia DOROVSKIKH
26 #include "LIGHTGUI_OBSelector.h"
27 #include "LIGHTGUI_DataOwner.h"
28 #include "LIGHTGUI_DataObject.h"
30 #include <OB_Browser.h>
32 #include <SUIT_DataObjectIterator.h>
34 //=================================================================================
35 // function : LIGHTGUI_OBSelector()
36 // purpose : constructor
37 //=================================================================================
38 LIGHTGUI_OBSelector::LIGHTGUI_OBSelector ( OB_Browser* ob, SUIT_SelectionMgr* mgr )
39 : SUIT_Selector( mgr, ob ),
43 connect( myBrowser, SIGNAL( selectionChanged() ), this, SLOT( onSelectionChanged() ) );
47 //=================================================================================
48 // function : ~LIGHTGUI_OBSelector()
49 // purpose : destructor
50 //=================================================================================
51 LIGHTGUI_OBSelector::~LIGHTGUI_OBSelector()
55 //=================================================================================
56 // function : browser()
57 // purpose : gets object browser
58 //=================================================================================
59 OB_Browser* LIGHTGUI_OBSelector::browser() const
64 //=================================================================================
65 // function : getSelection()
66 // purpose : gets selection
67 //=================================================================================
68 void LIGHTGUI_OBSelector::getSelection ( SUIT_DataOwnerPtrList& aList ) const
73 DataObjectList objlist;
74 myBrowser->getSelected( objlist );
75 for ( DataObjectListIterator it ( objlist ); it.current(); ++it )
77 LIGHTGUI_DataObject* obj = dynamic_cast<LIGHTGUI_DataObject*>( it.current() );
79 aList.append( SUIT_DataOwnerPtr( new LIGHTGUI_DataOwner( obj->lineNb() ) ) );
83 //=================================================================================
84 // function : setSelection()
85 // purpose : sets selection
86 //=================================================================================
87 void LIGHTGUI_OBSelector::setSelection ( const SUIT_DataOwnerPtrList& aList )
92 // Fill map of all data objects
93 QMap<int, LIGHTGUI_DataObject*> aMap;
95 SUIT_DataObjectIterator objit ( myBrowser->getRootObject(),
96 SUIT_DataObjectIterator::DepthLeft );
97 for ( ; objit.current(); ++objit )
99 LIGHTGUI_DataObject* obj = dynamic_cast<LIGHTGUI_DataObject*>( objit.current() );
101 aMap.insert( obj->lineNb(), obj );
104 // Fill list with all selected data objects
105 DataObjectList objList;
106 SUIT_DataOwnerPtrList::const_iterator ownit = aList.begin();
107 for ( ; ownit != aList.end(); ++ownit )
109 const LIGHTGUI_DataOwner* owner =
110 dynamic_cast<const LIGHTGUI_DataOwner*>( (*ownit).get() );
111 if ( owner && aMap.contains( owner->lineNb() ) )
112 objList.append( aMap[owner->lineNb()] );
115 myBrowser->setSelected( objList );
118 //=================================================================================
119 // function : onSelectionChanged()
120 // purpose : called when selection is changed in the Object Browser
121 //=================================================================================
122 void LIGHTGUI_OBSelector::onSelectionChanged()