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"
9 #include "SUIT_Session.h"
10 #include "SUIT_ViewWindow.h"
15 SalomeApp_Selection::SalomeApp_Selection()
23 SalomeApp_Selection::~SalomeApp_Selection()
30 void SalomeApp_Selection::init( const QString& client, SalomeApp_SelectionMgr* mgr)
32 myPopupClient = client;
36 if ( mgr->application() )
37 myStudy = dynamic_cast<SalomeApp_Study*>( mgr->application()->activeStudy() );
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++ )
44 SUIT_DataOwner* owner = ( SUIT_DataOwner* )( (*anIt ).get() );
45 SalomeApp_DataOwner* sowner = dynamic_cast<SalomeApp_DataOwner*>( owner );
47 myEntries.append( sowner->entry() );
48 processOwner( sowner );
55 Gets count of entries.
57 int SalomeApp_Selection::count() const
59 return myEntries.count();
65 QtxValue SalomeApp_Selection::param( const int ind, const QString& p ) const
67 if( !( ind>=0 && ind<count() ) )
72 SalomeApp_Displayer d;
73 bool vis = d.IsDisplayed( myEntries[ ind ] );
74 return QtxValue( vis, 0 );
76 else if( p=="component" )
78 _PTR(SObject) obj( study()->studyDS()->FindObjectID( myEntries[ ind ].latin1() ) );
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() )
90 Gets global parameters. client, isActiveView, activeView etc.
92 QtxValue SalomeApp_Selection::globalParam( const QString& p ) const
94 if ( p == "client" ) return QtxValue( myPopupClient );
95 else if ( p == "activeModule" )
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() )
105 else if ( p == "isActiveView" ) return QtxValue( (bool)activeVW() );
106 else if ( p == "activeView" ) return QtxValue( activeViewType() );
108 else return QtxPopupMgr::Selection::globalParam( p );
110 else return Selection::globalParam( p );
117 void SalomeApp_Selection::processOwner( const SalomeApp_DataOwner* )
122 Gets entry with index \a index.
124 QString SalomeApp_Selection::entry( const int index ) const
126 if ( index >= 0 && index < count() )
127 return myEntries[ index ];
132 Gets type of active view manager.
134 QString SalomeApp_Selection::activeViewType() const
136 SUIT_ViewWindow* win = activeVW();
138 SUIT_ViewManager* vm = win->getViewManager();
140 return vm->getType();
142 return QString::null;
146 Gets active view window.
148 SUIT_ViewWindow* SalomeApp_Selection::activeVW() const
150 SUIT_Session* session = SUIT_Session::session();
152 SUIT_Application* app = session->activeApplication();
154 SUIT_Desktop* desk = app->desktop();
156 return desk->activeWindow();