Salome HOME
PAL10471 - incorrect popup for objects hidden in OCCViewer, but selected in Object...
[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     //asl: fix for PAL10471
43     //mgr->selected( sel, client );
44     mgr->selected( sel );
45     SUIT_DataOwnerPtrList::const_iterator anIt = sel.begin(), aLast = sel.end();
46
47     QString entry, curEntry;
48     for( ; anIt!=aLast; anIt++ )
49     {
50       SUIT_DataOwner* owner = ( SUIT_DataOwner* )( (*anIt ).get() );
51       LightApp_DataOwner* sowner = dynamic_cast<LightApp_DataOwner*>( owner );
52       if( sowner ) {
53         curEntry = sowner->entry();
54         entry = myStudy->referencedToEntry( curEntry );
55         myEntries.append( entry );
56         if ( curEntry == entry )
57           myIsReferences.append( true );
58         else
59           myIsReferences.append( false );
60         processOwner( sowner );
61       }
62     }
63   }
64 }
65
66 /*!
67   Gets count of entries.
68 */
69 int LightApp_Selection::count() const
70 {
71   return myEntries.count();
72 }
73
74 /*!
75   Gets QtxValue();
76 */
77 QtxValue LightApp_Selection::param( const int ind, const QString& p ) const
78 {
79   if( !( ind>=0 && ind<count() ) )
80     return QtxValue();
81
82   if( p=="isVisible" )
83   {
84     LightApp_Displayer d;
85     bool vis = d.IsDisplayed( myEntries[ ind ] );
86     return QtxValue( vis, 0 );
87   }
88   else if( p=="component" ) {
89     return myStudy->componentDataType( myEntries[ ind ] );
90   }
91   else if( p=="isReference" )
92     return QtxValue( isReference( ind ), false );
93
94   return QtxValue();
95 }
96
97 /*!
98   Gets global parameters. client, isActiveView, activeView etc.
99 */
100 QtxValue LightApp_Selection::globalParam( const QString& p ) const
101 {
102   if      ( p == "client" )        return QtxValue( myPopupClient );
103   else if ( p == "activeModule" )
104   {
105     LightApp_Application* app = dynamic_cast<LightApp_Application*>( myStudy->application() );
106     QString mod_name = app ? QString( app->activeModule()->name() ) : QString::null;
107     //cout << "activeModule : " << mod_name.latin1() << endl;
108     if( !mod_name.isEmpty() )
109       return mod_name;
110     else
111       return QtxValue();
112   }
113   else if ( p == "isActiveView" )  return QtxValue( (bool)activeVW() );
114   else if ( p == "activeView" )    return QtxValue( activeViewType() );
115 #ifndef WNT
116   else                             return QtxPopupMgr::Selection::globalParam( p );
117 #else
118   else                             return Selection::globalParam( p );
119 #endif
120 }
121
122 /*!
123   Do nothing.
124 */
125 void LightApp_Selection::processOwner( const LightApp_DataOwner* )
126 {
127 }
128
129 /*!
130   Gets entry with index \a index.
131 */
132 QString LightApp_Selection::entry( const int index ) const
133 {
134   if ( index >= 0 && index < count() )
135     return myEntries[ index ];
136   return QString();
137 }
138
139 /*!
140   Returns true if i-th selected object was reference to object with entry( i )
141 */
142 bool LightApp_Selection::isReference( const int index ) const
143 {
144   if( index >= 0 && index < count() )
145     return myIsReferences[ index ];
146   else
147     return false;
148 }
149
150 /*!
151   Gets type of active view manager.
152 */
153 QString LightApp_Selection::activeViewType() const
154 {
155   SUIT_ViewWindow* win = activeVW();
156   if ( win ) {
157     SUIT_ViewManager* vm = win->getViewManager();
158     if ( vm )
159       return vm->getType();
160   }
161   return QString::null;
162 }
163
164 /*!
165   Gets active view window.
166 */
167 SUIT_ViewWindow* LightApp_Selection::activeVW() const
168 {
169   SUIT_Session* session = SUIT_Session::session();
170   if ( session ) {
171     SUIT_Application* app = session->activeApplication();
172     if ( app ) {
173       SUIT_Desktop* desk = app->desktop();
174       if ( desk ) 
175         return desk->activeWindow();
176     }
177   }
178   return 0;
179 }