]> SALOME platform Git repositories - modules/gui.git/blob - src/SalomeApp/SalomeApp_OBSelector.cxx
Salome HOME
New Help for KERNEL & GUI.
[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 /*!
11   Constructor
12 */
13 SalomeApp_OBSelector::SalomeApp_OBSelector( OB_Browser* ob, SUIT_SelectionMgr* mgr )
14 : SUIT_Selector( mgr, ob ),
15   myBrowser( ob )
16 {
17   if ( myBrowser ) {
18     connect( myBrowser, SIGNAL( selectionChanged() ), this, SLOT( onSelectionChanged() ) );
19   }    
20 }
21
22 /*!
23   Destructor
24 */
25 SalomeApp_OBSelector::~SalomeApp_OBSelector()
26 {
27 }
28
29 /*!
30   Gets browser.
31 */
32 OB_Browser* SalomeApp_OBSelector::browser() const
33 {
34   return myBrowser;
35 }
36
37 /*!
38   Gets selection.
39 */
40 void SalomeApp_OBSelector::getSelection( SUIT_DataOwnerPtrList& thelist ) const
41 {
42   if ( !myBrowser )
43     return;
44
45   DataObjectList objlist;
46   myBrowser->getSelected( objlist );
47   for ( DataObjectListIterator it( objlist ); it.current(); ++it )
48   {
49     SalomeApp_DataObject* obj = dynamic_cast<SalomeApp_DataObject*>( it.current() );
50     if ( obj )
51     {
52       Handle( SALOME_InteractiveObject ) aSObj = new SALOME_InteractiveObject
53         ( obj->entry(), obj->componentDataType(), obj->name() );
54       SalomeApp_DataOwner* owner = new SalomeApp_DataOwner( aSObj  );
55       thelist.append( SUIT_DataOwnerPtr( owner ) );
56     }
57   }
58 }
59
60 /*!Sets selection.*/
61 void SalomeApp_OBSelector::setSelection( const SUIT_DataOwnerPtrList& thelist )
62 {
63   if ( !myBrowser )
64     return;
65
66   QMap<QString, SalomeApp_DataObject*> themap;
67   fillEntries( themap );
68
69   DataObjectList objList;
70   for ( SUIT_DataOwnerPtrList::const_iterator it = thelist.begin(); it != thelist.end(); ++it )
71   {
72     const SalomeApp_DataOwner* owner = dynamic_cast<const SalomeApp_DataOwner*>( (*it).operator->() );
73     if ( owner && themap.contains( owner->entry() ) )
74       objList.append( themap[owner->entry()] );
75   }
76
77   myBrowser->setSelected( objList );
78 }
79
80 /*!On selection changed.*/
81 void SalomeApp_OBSelector::onSelectionChanged()
82 {
83   selectionChanged();
84 }
85
86 /*!Fill entries.*/
87 void SalomeApp_OBSelector::fillEntries( QMap<QString, SalomeApp_DataObject*>& entires )
88 {
89   entires.clear();
90
91   if ( !myBrowser )
92     return;
93
94   for ( SUIT_DataObjectIterator it( myBrowser->getRootObject(),
95                                     SUIT_DataObjectIterator::DepthLeft ); it.current(); ++it )
96   {
97     SalomeApp_DataObject* obj = dynamic_cast<SalomeApp_DataObject*>( it.current() );
98     if ( obj )
99       entires.insert( obj->entry(), obj );
100   }
101 }