Salome HOME
14bcc8ad544f8f9e0a0e34a2b1d6f50149b21c7a
[modules/gui.git] / src / SalomeApp / SalomeApp_Selection.cxx
1
2 #include "SalomeApp_Selection.h"
3 #include "SalomeApp_SelectionMgr.h"
4 #include "SalomeApp_DataOwner.h"
5 #include "SalomeApp_Study.h"
6 #include "SalomeApp_Application.h"
7 #include "SalomeApp_Displayer.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 ind, const QString& p ) const
66 {
67   if( !( ind>=0 && ind<count() ) )
68     return QtxValue();
69
70   if( p=="isVisible" )
71   {
72     SalomeApp_Displayer d;
73     bool vis = d.IsDisplayed( myEntries[ ind ] );
74     return QtxValue( vis, 0 );
75   }
76   else if( p=="component" )
77   {
78     _PTR(SObject) obj( study()->studyDS()->FindObjectID( myEntries[ ind ] ) );
79     _PTR(SComponent) comp = obj->GetFatherComponent();
80     QString mod_name = comp->ComponentDataType().c_str();
81     //cout << "component : " << ind << " >> " << mod_name.latin1() << endl;
82     if( !mod_name.isEmpty() )
83       return mod_name;
84   }
85
86   return QtxValue();
87 }
88
89 /*!
90   Gets global parameters. client, isActiveView, activeView etc.
91 */
92 QtxValue SalomeApp_Selection::globalParam( const QString& p ) const
93 {
94   if      ( p == "client" )        return QtxValue( myPopupClient );
95   else if ( p == "activeModule" )
96   {
97     SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( myStudy->application() );
98     QString mod_name = app ? QString( app->activeModule()->name() ) : QString::null;
99     //cout << "activeModule : " << mod_name.latin1() << endl;
100     if( !mod_name.isEmpty() )
101       return mod_name;
102     else
103       return QtxValue();
104   }
105   else if ( p == "isActiveView" )  return QtxValue( (bool)activeVW() );
106   else if ( p == "activeView" )    return QtxValue( activeViewType() );
107 #ifndef WNT
108   else                             return QtxPopupMgr::Selection::globalParam( p );
109 #else
110   else                             return Selection::globalParam( p );
111 #endif
112 }
113
114 /*!
115   Do nothing.
116 */
117 void SalomeApp_Selection::processOwner( const SalomeApp_DataOwner* )
118 {
119 }
120
121 /*!
122   Gets entry with index \a index.
123 */
124 QString SalomeApp_Selection::entry( const int index ) const
125 {
126   if ( index >= 0 && index < count() )
127     return myEntries[ index ];
128   return QString();
129 }
130
131 /*!
132   Gets type of active view manager.
133 */
134 QString SalomeApp_Selection::activeViewType() const
135 {
136   SUIT_ViewWindow* win = activeVW();
137   if ( win ) {
138     SUIT_ViewManager* vm = win->getViewManager();
139     if ( vm )
140       return vm->getType();
141   }
142   return QString::null;
143 }
144
145 /*!
146   Gets active view window.
147 */
148 SUIT_ViewWindow* SalomeApp_Selection::activeVW() const
149 {
150   SUIT_Session* session = SUIT_Session::session();
151   if ( session ) {
152     SUIT_Application* app = session->activeApplication();
153     if ( app ) {
154       SUIT_Desktop* desk = app->desktop();
155       if ( desk ) 
156         return desk->activeWindow();
157     }
158   }
159   return 0;
160 }