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"
9 #include "SUIT_Session.h"
10 #include "SUIT_ViewWindow.h"
15 LightApp_Selection::LightApp_Selection()
23 LightApp_Selection::~LightApp_Selection()
30 void LightApp_Selection::init( const QString& client, LightApp_SelectionMgr* mgr)
32 myPopupClient = client;
37 if( mgr->application() )
38 myStudy = dynamic_cast<LightApp_Study*>( mgr->application()->activeStudy() );
42 //1) to take owners from current popup client
43 SUIT_DataOwnerPtrList sel( true ), cur_sel( true );
44 mgr->selected( sel, client );
46 //2) to take such owners from other popup clients that it's entry is different with every entry from current list
47 QPtrList<SUIT_Selector> aSelectors;
48 mgr->selectors( aSelectors );
49 for( SUIT_Selector* selector = aSelectors.first(); selector; selector = aSelectors.next() )
50 if( selector->type()!=client )
52 mgr->selected( cur_sel, selector->type() );
53 SUIT_DataOwnerPtrList::const_iterator aLIt = cur_sel.begin(), aLLast = cur_sel.end();
54 for( ; aLIt!=aLLast; aLIt++ )
55 sel.append( *aLIt ); //check entry and don't append if such entry is in list already
58 //3) to analyse owner and fill internal data structures
59 SUIT_DataOwnerPtrList::const_iterator anIt = sel.begin(), aLast = sel.end();
61 for( ; anIt!=aLast; anIt++ )
63 LightApp_DataOwner* sowner = dynamic_cast<LightApp_DataOwner*>( (*anIt ).get() );
66 entry = myStudy->referencedToEntry( sowner->entry() );
67 myEntries.append( entry );
68 myIsReferences.append( sowner->entry() == entry );
69 processOwner( sowner );
76 Gets count of entries.
78 int LightApp_Selection::count() const
80 return myEntries.count();
86 QtxValue LightApp_Selection::param( const int ind, const QString& p ) const
88 LightApp_Application* app = dynamic_cast<LightApp_Application*>( myStudy ? myStudy->application() : 0 );
89 if( !( ind>=0 && ind<count() ) || !app )
94 QString mod_name = app->moduleTitle( param( ind, "component" ).toString() );
95 LightApp_Displayer* d = LightApp_Displayer::FindDisplayer( mod_name, false );
96 // false in last parameter means that now we doesn't load module, if it isn't loaded
100 vis = d->IsDisplayed( myEntries[ ind ] );
103 LightApp_Displayer local_d;
104 vis = local_d.IsDisplayed( myEntries[ ind ] );
106 return QtxValue( vis, 0 );
109 else if( p=="component" )
111 return myStudy->componentDataType( myEntries[ ind ] );
114 else if( p=="isReference" )
115 return QtxValue( isReference( ind ), false );
117 else if( p=="canBeDisplayed" )
119 QString mod_name = app->moduleTitle( param( ind, "component" ).toString() );
120 LightApp_Displayer* d = LightApp_Displayer::FindDisplayer( mod_name, false );
121 // false in last parameter means that now we doesn't load module, if it isn't loaded
123 return QtxValue( d ? d->canBeDisplayed( myEntries[ ind ] ) : true, 0 );
124 //now if displayer is null, it means, that according module isn't loaded, so that we allow to all display/erase
125 //operations under object
132 Gets global parameters. client, isActiveView, activeView etc.
134 QtxValue LightApp_Selection::globalParam( const QString& p ) const
136 if ( p == "client" ) return QtxValue( myPopupClient );
137 else if ( p == "activeModule" )
139 LightApp_Application* app = dynamic_cast<LightApp_Application*>( myStudy->application() );
140 QString mod_name = app ? QString( app->activeModule()->name() ) : QString::null;
141 //cout << "activeModule : " << mod_name.latin1() << endl;
142 if( !mod_name.isEmpty() )
147 else if ( p == "isActiveView" ) return QtxValue( (bool)activeVW() );
148 else if ( p == "activeView" ) return QtxValue( activeViewType() );
150 else return QtxPopupMgr::Selection::globalParam( p );
152 else return Selection::globalParam( p );
157 Do nothing. To be redefined by successors
159 void LightApp_Selection::processOwner( const LightApp_DataOwner* )
164 Gets entry with index \a index.
166 QString LightApp_Selection::entry( const int index ) const
168 if ( index >= 0 && index < count() )
169 return myEntries[ index ];
174 Returns true if i-th selected object was reference to object with entry( i )
176 bool LightApp_Selection::isReference( const int index ) const
178 if( index >= 0 && index < count() )
179 return myIsReferences[ index ];
185 Gets type of active view manager.
187 QString LightApp_Selection::activeViewType() const
189 SUIT_ViewWindow* win = activeVW();
191 SUIT_ViewManager* vm = win->getViewManager();
193 return vm->getType();
195 return QString::null;
199 Gets active view window.
201 SUIT_ViewWindow* LightApp_Selection::activeVW() const
203 SUIT_Session* session = SUIT_Session::session();
205 SUIT_Application* app = session->activeApplication();
207 SUIT_Desktop* desk = app->desktop();
209 return desk->activeWindow();