Salome HOME
Has functionality from SalomeApp without dependency from CORBA
[modules/gui.git] / src / LightApp / LightApp_Selection.cxx
1
2 #include "LightApp_Selection.h"
3 #include "LightApp_SelectionMgr.h"
4 #include "LightApp_DataOwner.h"
5 #include "LightApp_Study.h"
6 #include "LightApp_Application.h"
7 #include "LightApp_Displayer.h"
8
9 #include "SUIT_Session.h"
10 #include "SUIT_ViewWindow.h"
11
12 /*!
13   Constructor
14 */
15 LightApp_Selection::LightApp_Selection()
16 : myStudy( 0 )
17 {
18 }
19
20 /*!
21   Destructor.
22 */
23 LightApp_Selection::~LightApp_Selection()
24 {
25 }
26
27 /*!
28   Initializetion.
29 */
30 void LightApp_Selection::init( const QString& client, LightApp_SelectionMgr* mgr)
31 {
32   myPopupClient = client;
33   
34   if( mgr )
35   {
36     if ( mgr->application() )
37       myStudy = dynamic_cast<LightApp_Study*>( mgr->application()->activeStudy() );
38     if ( !myStudy )
39       return;
40
41     SUIT_DataOwnerPtrList sel;
42     mgr->selected( sel, client );
43     SUIT_DataOwnerPtrList::const_iterator anIt = sel.begin(), aLast = sel.end();
44
45     QString entry, curEntry;
46     for( ; anIt!=aLast; anIt++ )
47     {
48       SUIT_DataOwner* owner = ( SUIT_DataOwner* )( (*anIt ).get() );
49       LightApp_DataOwner* sowner = dynamic_cast<LightApp_DataOwner*>( owner );
50       if( sowner ) {
51         curEntry = sowner->entry();
52         entry = myStudy->referencedToEntry( curEntry );
53         myEntries.append( entry );
54         if ( curEntry == entry )
55           myIsReferences.append( true );
56         else
57           myIsReferences.append( false );
58         processOwner( sowner );
59       }
60     }
61   }
62 }
63
64 /*!
65   Gets count of entries.
66 */
67 int LightApp_Selection::count() const
68 {
69   return myEntries.count();
70 }
71
72 /*!
73   Gets QtxValue();
74 */
75 QtxValue LightApp_Selection::param( const int ind, const QString& p ) const
76 {
77   if( !( ind>=0 && ind<count() ) )
78     return QtxValue();
79
80   if( p=="isVisible" )
81   {
82     LightApp_Displayer d;
83     bool vis = d.IsDisplayed( myEntries[ ind ] );
84     return QtxValue( vis, 0 );
85   }
86   else if( p=="component" ) {
87     return myStudy->componentDataType( myEntries[ ind ] );
88   }
89   else if( p=="isReference" )
90     return QtxValue( isReference( ind ), false );
91
92   return QtxValue();
93 }
94
95 /*!
96   Gets global parameters. client, isActiveView, activeView etc.
97 */
98 QtxValue LightApp_Selection::globalParam( const QString& p ) const
99 {
100   if      ( p == "client" )        return QtxValue( myPopupClient );
101   else if ( p == "activeModule" )
102   {
103     LightApp_Application* app = dynamic_cast<LightApp_Application*>( myStudy->application() );
104     QString mod_name = app ? QString( app->activeModule()->name() ) : QString::null;
105     //cout << "activeModule : " << mod_name.latin1() << endl;
106     if( !mod_name.isEmpty() )
107       return mod_name;
108     else
109       return QtxValue();
110   }
111   else if ( p == "isActiveView" )  return QtxValue( (bool)activeVW() );
112   else if ( p == "activeView" )    return QtxValue( activeViewType() );
113 #ifndef WNT
114   else                             return QtxPopupMgr::Selection::globalParam( p );
115 #else
116   else                             return Selection::globalParam( p );
117 #endif
118 }
119
120 /*!
121   Do nothing.
122 */
123 void LightApp_Selection::processOwner( const LightApp_DataOwner* )
124 {
125 }
126
127 /*!
128   Gets entry with index \a index.
129 */
130 QString LightApp_Selection::entry( const int index ) const
131 {
132   if ( index >= 0 && index < count() )
133     return myEntries[ index ];
134   return QString();
135 }
136
137 /*!
138   Returns true if i-th selected object was reference to object with entry( i )
139 */
140 bool LightApp_Selection::isReference( const int index ) const
141 {
142   if( index >= 0 && index < count() )
143     return myIsReferences[ index ];
144   else
145     return false;
146 }
147
148 /*!
149   Gets type of active view manager.
150 */
151 QString LightApp_Selection::activeViewType() const
152 {
153   SUIT_ViewWindow* win = activeVW();
154   if ( win ) {
155     SUIT_ViewManager* vm = win->getViewManager();
156     if ( vm )
157       return vm->getType();
158   }
159   return QString::null;
160 }
161
162 /*!
163   Gets active view window.
164 */
165 SUIT_ViewWindow* LightApp_Selection::activeVW() const
166 {
167   SUIT_Session* session = SUIT_Session::session();
168   if ( session ) {
169     SUIT_Application* app = session->activeApplication();
170     if ( app ) {
171       SUIT_Desktop* desk = app->desktop();
172       if ( desk ) 
173         return desk->activeWindow();
174     }
175   }
176   return 0;
177 }