Salome HOME
To introduce default launch mode of SALOMEDS server
[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 #ifndef WNT
79   else                             return QtxPopupMgr::Selection::globalParam( p );
80 #else
81   else                             return Selection::globalParam( p );
82 #endif
83 }
84
85 /*!
86   Do nothing.
87 */
88 void SalomeApp_Selection::processOwner( const SalomeApp_DataOwner* )
89 {
90 }
91
92 /*!
93   Gets entry with index \a index.
94 */
95 QString SalomeApp_Selection::entry( const int index ) const
96 {
97   if ( index >= 0 && index < count() )
98     return myEntries[ index ];
99   return QString();
100 }
101
102 /*!
103   Gets type of active view manager.
104 */
105 QString SalomeApp_Selection::activeViewType() const
106 {
107   SUIT_ViewWindow* win = activeVW();
108   if ( win ) {
109     SUIT_ViewManager* vm = win->getViewManager();
110     if ( vm )
111       return vm->getType();
112   }
113   return QString::null;
114 }
115
116 /*!
117   Gets active view window.
118 */
119 SUIT_ViewWindow* SalomeApp_Selection::activeVW() const
120 {
121   SUIT_Session* session = SUIT_Session::session();
122   if ( session ) {
123     SUIT_Application* app = session->activeApplication();
124     if ( app ) {
125       SUIT_Desktop* desk = app->desktop();
126       if ( desk ) 
127         return desk->activeWindow();
128     }
129   }
130   return 0;
131 }