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() );
42 _PTR(Study) studyds = myStudy->studyDS();
45 SUIT_DataOwnerPtrList sel;
46 mgr->selected( sel, client );
47 SUIT_DataOwnerPtrList::const_iterator anIt = sel.begin(), aLast = sel.end();
48 for( ; anIt!=aLast; anIt++ )
50 SUIT_DataOwner* owner = ( SUIT_DataOwner* )( (*anIt ).get() );
51 SalomeApp_DataOwner* sowner = dynamic_cast<SalomeApp_DataOwner*>( owner );
54 _PTR(SObject) obj = studyds->FindObjectID( sowner->entry() );
55 if( obj->ReferencedObject( refobj ) )
57 myEntries.append( refobj->GetID() );
58 myIsReferences.append( true );
62 myEntries.append( sowner->entry() );
63 myIsReferences.append( false );
65 processOwner( sowner );
72 Gets count of entries.
74 int SalomeApp_Selection::count() const
76 return myEntries.count();
82 QtxValue SalomeApp_Selection::param( const int ind, const QString& p ) const
84 if( !( ind>=0 && ind<count() ) )
89 SalomeApp_Displayer d;
90 bool vis = d.IsDisplayed( myEntries[ ind ] );
91 return QtxValue( vis, 0 );
93 else if( p=="component" )
95 _PTR(SObject) obj( study()->studyDS()->FindObjectID( myEntries[ ind ].latin1() ) );
96 _PTR(SComponent) comp = obj->GetFatherComponent();
97 QString mod_name = comp->ComponentDataType().c_str();
98 //cout << "component : " << ind << " >> " << mod_name.latin1() << endl;
99 if( !mod_name.isEmpty() )
102 else if( p=="isReference" )
103 return QtxValue( isReference( ind ), false );
109 Gets global parameters. client, isActiveView, activeView etc.
111 QtxValue SalomeApp_Selection::globalParam( const QString& p ) const
113 if ( p == "client" ) return QtxValue( myPopupClient );
114 else if ( p == "activeModule" )
116 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( myStudy->application() );
117 QString mod_name = app ? QString( app->activeModule()->name() ) : QString::null;
118 //cout << "activeModule : " << mod_name.latin1() << endl;
119 if( !mod_name.isEmpty() )
124 else if ( p == "isActiveView" ) return QtxValue( (bool)activeVW() );
125 else if ( p == "activeView" ) return QtxValue( activeViewType() );
127 else return QtxPopupMgr::Selection::globalParam( p );
129 else return Selection::globalParam( p );
136 void SalomeApp_Selection::processOwner( const SalomeApp_DataOwner* )
141 Gets entry with index \a index.
143 QString SalomeApp_Selection::entry( const int index ) const
145 if ( index >= 0 && index < count() )
146 return myEntries[ index ];
151 Returns true if i-th selected object was reference to object with entry( i )
153 bool SalomeApp_Selection::isReference( const int index ) const
155 if( index >= 0 && index < count() )
156 return myIsReferences[ index ];
162 Gets type of active view manager.
164 QString SalomeApp_Selection::activeViewType() const
166 SUIT_ViewWindow* win = activeVW();
168 SUIT_ViewManager* vm = win->getViewManager();
170 return vm->getType();
172 return QString::null;
176 Gets active view window.
178 SUIT_ViewWindow* SalomeApp_Selection::activeVW() const
180 SUIT_Session* session = SUIT_Session::session();
182 SUIT_Application* app = session->activeApplication();
184 SUIT_Desktop* desk = app->desktop();
186 return desk->activeWindow();