]> SALOME platform Git repositories - samples/light.git/blob - src/LIGHTGUI/LIGHTGUI_OBSelector.cxx
Salome HOME
Join modifications from branch BR_DEBUG_3_2_0b1
[samples/light.git] / src / LIGHTGUI / LIGHTGUI_OBSelector.cxx
1 //  LIGHT : sample (no-corba-engine) SALOME module
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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.
10 //
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.
15 //
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
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 //  Author : Julia DOROVSKIKH
23 //  Date   : 01/01/2005
24 //  $Header$
25
26 #include "LIGHTGUI_OBSelector.h"
27 #include "LIGHTGUI_DataOwner.h"
28 #include "LIGHTGUI_DataObject.h"
29
30 #include <OB_Browser.h>
31
32 #include <SUIT_DataObjectIterator.h>
33
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 ),
40        myBrowser( ob )
41 {
42   if ( myBrowser ) {
43     connect( myBrowser, SIGNAL( selectionChanged() ), this, SLOT( onSelectionChanged() ) );
44   }    
45 }
46
47 //=================================================================================
48 // function : ~LIGHTGUI_OBSelector()
49 // purpose  : destructor
50 //=================================================================================
51 LIGHTGUI_OBSelector::~LIGHTGUI_OBSelector()
52 {
53 }
54
55 //=================================================================================
56 // function : browser()
57 // purpose  : gets object browser
58 //=================================================================================
59 OB_Browser* LIGHTGUI_OBSelector::browser() const
60 {
61   return myBrowser;
62 }
63
64 //=================================================================================
65 // function : getSelection()
66 // purpose  : gets selection
67 //=================================================================================
68 void LIGHTGUI_OBSelector::getSelection ( SUIT_DataOwnerPtrList& aList ) const
69 {
70   if ( !myBrowser )
71     return;
72
73   DataObjectList objlist;
74   myBrowser->getSelected( objlist );
75   for ( DataObjectListIterator it ( objlist ); it.current(); ++it )
76   {
77     LIGHTGUI_DataObject* obj = dynamic_cast<LIGHTGUI_DataObject*>( it.current() );
78     if ( obj )
79       aList.append( SUIT_DataOwnerPtr( new LIGHTGUI_DataOwner( obj->lineNb() ) ) );
80   }
81 }
82
83 //=================================================================================
84 // function : setSelection()
85 // purpose  : sets selection
86 //=================================================================================
87 void LIGHTGUI_OBSelector::setSelection ( const SUIT_DataOwnerPtrList& aList )
88 {
89   if ( !myBrowser )
90     return;
91
92   // Fill map of all data objects
93   QMap<int, LIGHTGUI_DataObject*> aMap;
94
95   SUIT_DataObjectIterator objit ( myBrowser->getRootObject(),
96                                   SUIT_DataObjectIterator::DepthLeft );
97   for ( ; objit.current(); ++objit )
98   {
99     LIGHTGUI_DataObject* obj = dynamic_cast<LIGHTGUI_DataObject*>( objit.current() );
100     if ( obj )
101       aMap.insert( obj->lineNb(), obj );
102   }
103
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 )
108   {
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()] );
113   }
114
115   myBrowser->setSelected( objList );
116 }
117
118 //=================================================================================
119 // function : onSelectionChanged()
120 // purpose  : called when selection is changed in the Object Browser
121 //=================================================================================
122 void LIGHTGUI_OBSelector::onSelectionChanged()
123 {
124   selectionChanged();
125 }