Salome HOME
Preparation of v.3.0.1
[modules/gui.git] / src / SalomeApp / SalomeApp_Selection.cxx
1
2 #include "SalomeApp_Selection.h"
3
4 #include "SalomeApp_SelectionMgr.h"
5 #include "SalomeApp_DataOwner.h"
6 #include "SalomeApp_Study.h"
7 #include "SalomeApp_Application.h"
8
9 #include "SUIT_Session.h"
10 #include "SUIT_ViewWindow.h"
11
12 /*!
13   Constructor
14 */
15 SalomeApp_Selection::SalomeApp_Selection()
16 : myStudy( 0 )
17 {
18 }
19
20 /*!
21   Destructor.
22 */
23 SalomeApp_Selection::~SalomeApp_Selection()
24 {
25 }
26
27 /*!
28   Initializetion.
29 */
30 void SalomeApp_Selection::init( const QString& client, SalomeApp_SelectionMgr* mgr)
31 {
32   myPopupClient = client;
33   
34   if( mgr )
35   {
36     if ( mgr->application() )
37       myStudy = dynamic_cast<SalomeApp_Study*>( mgr->application()->activeStudy() );
38
39     SUIT_DataOwnerPtrList sel;
40     mgr->selected( sel, client );
41     SUIT_DataOwnerPtrList::const_iterator anIt = sel.begin(), aLast = sel.end();
42     for( ; anIt!=aLast; anIt++ )
43     {
44       SUIT_DataOwner* owner = ( SUIT_DataOwner* )( (*anIt ).get() );
45       SalomeApp_DataOwner* sowner = dynamic_cast<SalomeApp_DataOwner*>( owner );
46       if( sowner ) {
47         myEntries.append( sowner->entry() );
48         processOwner( sowner );
49       }
50     }
51   }
52 }
53
54 /*!
55   Gets count of entries.
56 */
57 int SalomeApp_Selection::count() const
58 {
59   return myEntries.count();
60 }
61
62 /*!
63   Gets QtxValue();
64 */
65 QtxValue SalomeApp_Selection::param( const int, const QString& p ) const
66 {
67   return QtxValue();
68 }
69
70 /*!
71   Gets global parameters. client, isActiveView, activeView etc.
72 */
73 QtxValue SalomeApp_Selection::globalParam( const QString& p ) const
74 {
75   if      ( p == "client" )        return QtxValue( myPopupClient );
76   else if ( p == "isActiveView" )  return QtxValue( (bool)activeVW() );
77   else if ( p == "activeView" )    return QtxValue( activeViewType() );
78   else                             return QtxPopupMgr::Selection::globalParam( p );
79 }
80
81 /*!
82   Do nothing.
83 */
84 void SalomeApp_Selection::processOwner( const SalomeApp_DataOwner* )
85 {
86 }
87
88 /*!
89   Gets entry with index \a index.
90 */
91 QString SalomeApp_Selection::entry( const int index ) const
92 {
93   if ( index >= 0 && index < count() )
94     return myEntries[ index ];
95   return QString();
96 }
97
98 /*!
99   Gets type of active view manager.
100 */
101 QString SalomeApp_Selection::activeViewType() const
102 {
103   SUIT_ViewWindow* win = activeVW();
104   if ( win ) {
105     SUIT_ViewManager* vm = win->getViewManager();
106     if ( vm )
107       return vm->getType();
108   }
109   return QString::null;
110 }
111
112 /*!
113   Gets active view window.
114 */
115 SUIT_ViewWindow* SalomeApp_Selection::activeVW() const
116 {
117   SUIT_Session* session = SUIT_Session::session();
118   if ( session ) {
119     SUIT_Application* app = session->activeApplication();
120     if ( app ) {
121       SUIT_Desktop* desk = app->desktop();
122       if ( desk ) 
123         return desk->activeWindow();
124     }
125   }
126   return 0;
127 }