]> SALOME platform Git repositories - modules/gui.git/blob - src/SalomeApp/SalomeApp_OBSelector.cxx
Salome HOME
Initial version
[modules/gui.git] / src / SalomeApp / SalomeApp_OBSelector.cxx
1 #include "SalomeApp_OBSelector.h"
2
3 #include "SalomeApp_DataOwner.h"
4 #include "SalomeApp_DataObject.h"
5
6 #include <OB_Browser.h>
7
8 #include <SUIT_DataObjectIterator.h>
9
10 SalomeApp_OBSelector::SalomeApp_OBSelector( OB_Browser* ob, SUIT_SelectionMgr* mgr )
11 : QObject( 0 ),
12 SUIT_Selector( mgr ),
13 myBrowser( ob )
14 {
15   if ( myBrowser )
16     connect( myBrowser, SIGNAL( selectionChanged() ), this, SLOT( onSelectionChanged() ) );
17 }
18
19 SalomeApp_OBSelector::~SalomeApp_OBSelector()
20 {
21 }
22
23 OB_Browser* SalomeApp_OBSelector::browser() const
24 {
25   return myBrowser;
26 }
27
28 void SalomeApp_OBSelector::getSelection( SUIT_DataOwnerPtrList& list ) const
29 {
30   if ( !myBrowser )
31     return;
32
33   DataObjectList objlist;
34   myBrowser->getSelected( objlist );
35   for ( DataObjectListIterator it( objlist ); it.current(); ++it )
36   {
37     SalomeApp_DataObject* obj = dynamic_cast<SalomeApp_DataObject*>( it.current() );
38     if ( obj )
39       list.append( SUIT_DataOwnerPtr( new SalomeApp_DataOwner( obj->entry() ) ) );
40   }
41 }
42
43 void SalomeApp_OBSelector::setSelection( const SUIT_DataOwnerPtrList& list )
44 {
45   if ( !myBrowser )
46     return;
47
48   QMap<QString, SalomeApp_DataObject*> map;
49   fillEntries( map );
50
51   DataObjectList objList;
52   for ( SUIT_DataOwnerPtrList::const_iterator it = list.begin(); it != list.end(); ++it )
53   {
54     const SalomeApp_DataOwner* owner = dynamic_cast<const SalomeApp_DataOwner*>( (*it).operator->() );
55     if ( owner && map.contains( owner->entry() ) )
56       objList.append( map[owner->entry()] );
57   }
58
59   myBrowser->setSelected( objList );
60 }
61
62 void SalomeApp_OBSelector::onSelectionChanged()
63 {
64   selectionChanged();
65 }
66
67 void SalomeApp_OBSelector::fillEntries( QMap<QString, SalomeApp_DataObject*>& entires )
68 {
69   entires.clear();
70
71   if ( !myBrowser )
72     return;
73
74   for ( SUIT_DataObjectIterator it( myBrowser->getRootObject(),
75                                     SUIT_DataObjectIterator::DepthLeft ); it.current(); ++it )
76   {
77     SalomeApp_DataObject* obj = dynamic_cast<SalomeApp_DataObject*>( it.current() );
78     if ( obj )
79       entires.insert( obj->entry(), obj );
80   }
81 }