-//=============================================================================
-// File : SalomePyQt.cxx
-// Created : 25/04/05
-// Author : Vadim SANDLER
-// Project : SALOME
-// Copyright : 2003-2005 CEA/DEN, EDF R&D
-// $Header : $
-//=============================================================================
+// Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/
+//
+#include "SALOME_PYQT_Module.h" // this include must be first!!!
#include "SalomePyQt.h"
#include <qapplication.h>
#include <qmenubar.h>
+#include <qwidget.h>
+#include <qpopupmenu.h>
+#include <qimage.h>
#include <qstringlist.h>
#include "SALOME_Event.hxx"
#include "SUIT_Session.h"
#include "SUIT_Desktop.h"
#include "SUIT_ResourceMgr.h"
+#include "SUIT_Tools.h"
#include "STD_MDIDesktop.h"
#include "SalomeApp_Application.h"
#include "SalomeApp_Study.h"
-#include "SalomeApp_SelectionMgr.h"
+#include "LightApp_SelectionMgr.h"
#include "OB_Browser.h"
+#include "QtxAction.h"
using namespace std;
-//====================================================================================
-// static functions
-//====================================================================================
/*!
- getApplication()
- Returns active application object [ static ]
+ \return active application object [ static ]
*/
static SalomeApp_Application* getApplication() {
if ( SUIT_Session::session() )
}
/*!
- getActiveStudy()
- Gets active study or 0 if there is no study opened [ static ]
+ \return active study or 0 if there is no study opened [ static ]
*/
static SalomeApp_Study* getActiveStudy()
{
return 0;
}
-//====================================================================================
-// SALOME_Selection class.
-//====================================================================================
+static QMap<SalomeApp_Application*, SALOME_Selection*> SelMap;
+
+/*!
+ Creates or finds the selection object (one per study).
+*/
+SALOME_Selection* SALOME_Selection::GetSelection( SalomeApp_Application* app )
+{
+ SALOME_Selection* sel = 0;
+ if ( app && SelMap.find( app ) != SelMap.end() )
+ sel = SelMap[ app ];
+ else
+ sel = SelMap[ app ] = new SALOME_Selection( app );
+ return sel;
+}
+
/*!
- SALOME_Selection::SALOME_Selection
- Selection constructor. Gets an instance of selection manager.
+ Selection constructor.
*/
-SALOME_Selection::SALOME_Selection() : mySelMgr( 0 )
+SALOME_Selection::SALOME_Selection( QObject* p ) : QObject( p ), mySelMgr( 0 )
{
- if ( SalomeApp_Application* anApp = getApplication() ) {
- mySelMgr = anApp->selectionMgr();
+ SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( p );
+ if ( app ) {
+ mySelMgr = app->selectionMgr();
connect( mySelMgr, SIGNAL( selectionChanged() ), this, SIGNAL( currentSelectionChanged() ) );
connect( mySelMgr, SIGNAL( destroyed() ), this, SLOT ( onSelMgrDestroyed() ) );
}
}
+/*!
+ Selection destructor. Removes selection object from the map.
+*/
+SALOME_Selection::~SALOME_Selection()
+{
+ SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( parent() );
+ if ( app && SelMap.find( app ) != SelMap.end() )
+ SelMap.remove( app );
+}
/*!
- SALOME_Selection::onSelMgrDestroyed
Watches for the selection manager destroying when study is closed.
*/
void SALOME_Selection::onSelMgrDestroyed()
}
/*!
- SALOME_Selection::Clear
Clears the selection.
*/
void SALOME_Selection::Clear()
{
class TEvent: public SALOME_Event {
- SalomeApp_SelectionMgr* mySelMgr;
+ LightApp_SelectionMgr* mySelMgr;
public:
- TEvent( SalomeApp_SelectionMgr* selMgr )
+ TEvent( LightApp_SelectionMgr* selMgr )
: mySelMgr( selMgr ) {}
virtual void Execute() {
if ( mySelMgr )
}
/*!
- SALOME_Selection::ClearIObjects
Clears the selection.
*/
void SALOME_Selection::ClearIObjects()
}
/*!
- SALOME_Selection::ClearFilters
Removes all selection filters.
*/
void SALOME_Selection::ClearFilters()
{
class TEvent: public SALOME_Event {
- SalomeApp_SelectionMgr* mySelMgr;
+ LightApp_SelectionMgr* mySelMgr;
public:
- TEvent( SalomeApp_SelectionMgr* selMgr )
+ TEvent( LightApp_SelectionMgr* selMgr )
: mySelMgr( selMgr ) {}
virtual void Execute() {
if ( mySelMgr )
mySelMgr->clearFilters();
}
};
+ ProcessVoidEvent( new TEvent( mySelMgr ) );
}
-//====================================================================================
-// SalomePyQt class
-//====================================================================================
-
/*!
- SalomePyQt::getDesktop
- Gets desktop. Returns 0 in error.
+ \return desktop (0 if error)
*/
class TGetDesktopEvent: public SALOME_Event {
public:
myResult = (QWidget*)( getApplication()->desktop() );
}
};
+
+/*!
+ \return desktop
+*/
QWidget* SalomePyQt::getDesktop()
{
return ProcessEvent( new TGetDesktopEvent() );
}
/*!
- SalomePyQt::getMainFrame
- Gets workspace widget. Returns 0 in error.
+ \return workspace widget (0 if error)
*/
class TGetMainFrameEvent: public SALOME_Event {
public:
}
}
};
+
+/*!
+ \return workspace widget (0 if error)
+*/
QWidget* SalomePyQt::getMainFrame()
{
return ProcessEvent( new TGetMainFrameEvent() );
}
}
};
+
+/*!
+ \return main menu
+ \retval 0 in error.
+*/
QMenuBar* SalomePyQt::getMainMenuBar()
{
return ProcessEvent( new TGetMainMenuBarEvent() );
}
}
};
+
+/*!
+ \return popup menu
+ \param menu - menu name
+*/
QPopupMenu* SalomePyQt::getPopupMenu( const MenuName menu )
{
return ProcessEvent( new TGetPopupMenuEvent( menu ) );
}
}
};
+
+/*!
+ SalomePyQt::getStudyId
+ Returns active study's ID or 0 if there is no active study.
+*/
int SalomePyQt::getStudyId()
{
return ProcessEvent( new TGetStudyIdEvent() );
TResult myResult;
TGetSelectionEvent() : myResult( 0 ) {}
virtual void Execute() {
- myResult = new SALOME_Selection();
+ myResult = SALOME_Selection::GetSelection( getApplication() );
}
};
+
+/*!
+ Creates a Selection object (to provide a compatibility with previous SALOME GUI).
+ \return just created selection object
+*/
SALOME_Selection* SalomePyQt::getSelection()
{
return ProcessEvent( new TGetSelectionEvent() );
}
}
};
+
+/*!
+ Puts an information message to the desktop's status bar
+ (with optional delay parameter given in seconds)
+ \param msg - message text
+ \param sec - delay in seconds
+*/
void SalomePyQt::putInfo( const QString& msg, const int sec )
{
ProcessVoidEvent( new TPutInfoEvent( msg, sec ) );
}
}
};
+
+/*!
+ \return an active component name or empty string if there is no active component
+*/
const QString SalomePyQt::getActiveComponent()
{
return ProcessEvent( new TGetActiveComponentEvent() );
}
}
};
+
+/*!
+ \return a setting value (as string)
+ This function is obsolete. Use stringSetting(), integerSetting(),
+ boolSetting(), stringSetting() or colorSetting() instead.
+*/
QString SalomePyQt::getSetting( const QString& name )
{
return ProcessEvent( new TGetSettingEvent( name ) );
}
}
};
+
+/*!
+ \return an integer setting from the application preferences
+*/
int SalomePyQt::integerSetting( const QString& section, const QString& name, const int def )
{
return ProcessEvent( new TGetIntSettingEvent( section, name, def ) );
}
}
};
+
+/*!
+ \return an double setting from the application preferences
+*/
double SalomePyQt::doubleSetting( const QString& section, const QString& name, const int def )
{
return ProcessEvent( new TGetDblSettingEvent( section, name, def ) );
}
}
};
+
+/*!
+ \return an boolean setting from the application preferences
+*/
bool SalomePyQt::boolSetting( const QString& section, const QString& name, const bool def )
{
return ProcessEvent( new TGetBoolSettingEvent( section, name, def ) );
}
}
};
+
+/*!
+ \return an string setting from the application preferences
+*/
QString SalomePyQt::stringSetting( const QString& section, const QString& name, const QString& def )
{
return ProcessEvent( new TGetStrSettingEvent( section, name, def ) );
}
}
};
+
+/*!
+ \return a color setting from the application preferences
+*/
QColor SalomePyQt::colorSetting ( const QString& section, const QString& name, const QColor& def )
{
return ProcessEvent( new TGetColorSettingEvent( section, name, def ) );
}
}
};
+
+/*!
+ Displays 'Open/Save file' dialog box and returns a user's choice (file name)
+*/
QString SalomePyQt::getFileName( QWidget* parent,
const QString& initial,
const QStringList& filters,
}
}
};
+
+/*!
+ Displays 'Open files' dialog box and returns a user's choice (a list of file names)
+*/
QStringList SalomePyQt::getOpenFileNames( QWidget* parent,
const QString& initial,
const QStringList& filters,
}
}
};
+
+/*!
+ Displays 'Get Directory' dialog box and returns a user's choice (a directory name)
+*/
QString SalomePyQt::getExistingDirectory( QWidget* parent,
const QString& initial,
const QString& caption )
virtual void Execute() {
if ( /*SalomeApp_Application* anApp =*/ getApplication() ) {
// VSR: TODO
-////QAD_Application::getDesktop()->helpContext(source, context);
+ // anApp->helpContext( mySource, myContext );
}
}
};
TDumpViewEvent( const QString& filename )
: myResult ( false ), myFileName( filename ) {}
virtual void Execute() {
- if ( /*SalomeApp_Study* aStudy = */getActiveStudy() ) {
- // VSR: TODO
-// QAD_Study* activeStudy = QAD_Application::getDesktop()->getActiveApp()->getActiveStudy();
-// if ( !activeStudy )
-// return false;
-// QAD_ViewFrame* activeViewFrame = activeStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame();
-// if ( !activeViewFrame )
-// return false;
-// if ( !activeViewFrame->getViewWidget() )
-// return false;
-
-// qApp->processEvents();
-// QPixmap px = QPixmap::grabWindow( activeViewFrame->getViewWidget()->winId() );
-// if ( !filename.isNull() ) {
-// QString fmt = QAD_Tools::getFileExtensionFromPath( filename ).upper();
-// if ( fmt.isEmpty() )
-// fmt = QString( "PNG" ); // default format
-// if ( fmt == "JPG" )
-// fmt = "JPEG";
-// bool bOk = px.save( filename, fmt.latin1() );
-// return bOk;
-// }
-// return false;
+ if ( SalomeApp_Application* anApp = getApplication() ) {
+ SUIT_ViewManager* vm = anApp->activeViewManager();
+ if ( vm ) {
+ SUIT_ViewWindow* vw = vm->getActiveView();
+ if ( vw ) {
+ QImage im = vw->dumpView();
+ if ( !im.isNull() && !myFileName.isEmpty() ) {
+ QString fmt = SUIT_Tools::extension( myFileName ).upper();
+ if ( fmt.isEmpty() ) fmt = QString( "BMP" ); // default format
+ if ( fmt == "JPG" ) fmt = "JPEG";
+ myResult = im.save( myFileName, fmt.latin1() );
+ }
+ }
+ }
}
}
};
+
+/*!
+ Dumps the contents of the currently active view to the image file
+ in the given format (JPEG, PNG, BMP are supported)
+*/
bool SalomePyQt::dumpView( const QString& filename )
{
return ProcessEvent( new TDumpViewEvent( filename ) );
}
+/*!
+ SalomePyQt::defaultMenuGroup
+ Returns default menu group
+*/
+class TDefMenuGroupEvent: public SALOME_Event {
+public:
+ typedef int TResult;
+ TResult myResult;
+ TDefMenuGroupEvent() : myResult( -1 ) {}
+ virtual void Execute() {
+ myResult = SALOME_PYQT_Module::defaultMenuGroup();
+ }
+};
+
+/*!
+ \return default menu group
+*/
+int SalomePyQt::defaultMenuGroup()
+{
+ return ProcessEvent( new TDefMenuGroupEvent() );
+}
+
+/*!
+ SalomePyQt::createTool
+ These methods allow operating with the toolbars:
+ - create a new toolbar or get the existing one (the toolbar name is passed as parameter);
+ this method returns an id of the toolbar;
+ - add action with given id (must be created previously) and optional index to the existing toolbar
+ (toobar is identified either by its id or by its name)
+ these methods return an id of the action.
+ If error occurs, the -1 value is returned.
+*/
+class CrTool
+{
+public:
+ CrTool( const QString& tBar )
+ : myCase( 0 ), myTbName( tBar ) {}
+ CrTool( const int id, const int tBar, const int idx )
+ : myCase( 1 ), myId( id ), myTbId( tBar ), myIndex( idx ) {}
+ CrTool( const int id, const QString& tBar, const int idx )
+ : myCase( 2 ), myId( id ), myTbName( tBar ), myIndex( idx ) {}
+ CrTool( QtxAction* action, const int tbId, const int id, const int idx )
+ : myCase( 3 ), myAction( action ), myTbId( tbId ), myId( id ), myIndex( idx ) {}
+ CrTool( QtxAction* action, const QString& tBar, const int id, const int idx )
+ : myCase( 4 ), myAction( action ), myTbName( tBar ), myId( id ), myIndex( idx ) {}
+
+ int execute( SALOME_PYQT_Module* module ) const
+ {
+ if ( module ) {
+ switch ( myCase ) {
+ case 0:
+ return module->createTool( myTbName );
+ case 1:
+ return module->createTool( myId, myTbId, myIndex );
+ case 2:
+ return module->createTool( myId, myTbName, myIndex );
+ case 3:
+ return module->createTool( myAction, myTbId, myId, myIndex );
+ case 4:
+ return module->createTool( myAction, myTbName, myId, myIndex );
+ }
+ }
+ return -1;
+ }
+private:
+ int myCase;
+ QString myTbName;
+ int myTbId;
+ QtxAction* myAction;
+ int myId;
+ int myIndex;
+};
+class TCreateToolEvent: public SALOME_Event {
+public:
+ typedef int TResult;
+ TResult myResult;
+ const CrTool& myCrTool;
+ TCreateToolEvent( const CrTool& crTool )
+ : myResult( -1 ), myCrTool( crTool ) {}
+ virtual void Execute() {
+ if ( SalomeApp_Application* anApp = getApplication() ) {
+ SALOME_PYQT_Module* module = SALOME_PYQT_Module::getInitModule();
+ if ( !module )
+ module = dynamic_cast<SALOME_PYQT_Module*>( anApp->activeModule() );
+ myResult = myCrTool.execute( module );
+ }
+ }
+};
+
+/*!
+ create new toolbar or get existing by name
+*/
+int SalomePyQt::createTool( const QString& tBar )
+{
+ return ProcessEvent( new TCreateToolEvent( CrTool( tBar ) ) );
+}
+/*! add action with id and index to the existing tollbar
+*/
+int SalomePyQt::createTool( const int id, const int tBar, const int idx )
+{
+ return ProcessEvent( new TCreateToolEvent( CrTool( id, tBar, idx ) ) );
+}
+/*! add action with id and index to the existing tollbar
+*/
+int SalomePyQt::createTool( const int id, const QString& tBar, const int idx )
+{
+ return ProcessEvent( new TCreateToolEvent( CrTool( id, tBar, idx ) ) );
+}
+/*! add action with id and index to the existing tollbar
+*/
+int SalomePyQt::createTool( QtxAction* a, const int tBar, const int id, const int idx )
+{
+ return ProcessEvent( new TCreateToolEvent( CrTool( a, tBar, id, idx ) ) );
+}
+/*! add action with id and index to the existing tollbar
+*/
+int SalomePyQt::createTool( QtxAction* a, const QString& tBar, const int id, const int idx )
+{
+ return ProcessEvent( new TCreateToolEvent( CrTool( a, tBar, id, idx ) ) );
+}
+
+/*!
+ SalomePyQt::createMenu
+ These methods allow operating with the main menu:
+ - create a new menu or submenu or get the existing one (the parent menu name or id is passed as parameter,
+ if it is empty or -1, it means that main menu is created, otherwise submenu is created);
+ this method returns an id of the menu/submenu;
+ - add action with given id (must be created previously) and optional index and group number to the existing menu
+ or submenu (menu name or id us passed as parameter)
+ these methods return an id of the action.
+ If error occurs, the -1 value is returned.
+*/
+class CrMenu
+{
+public:
+ CrMenu( const QString& subMenu, const int menu, const int id, const int group, const int idx )
+ : myCase( 0 ), mySubMenuName( subMenu ), myMenuId( menu ), myId( id ), myGroup( group ), myIndex( idx ) {}
+ CrMenu( const QString& subMenu, const QString& menu, const int id, const int group, const int idx )
+ : myCase( 1 ), mySubMenuName( subMenu ), myMenuName( menu ), myId( id ), myGroup( group ), myIndex( idx ) {}
+ CrMenu( const int id, const int menu, const int group, const int idx )
+ : myCase( 2 ), myId( id ), myMenuId( menu ), myGroup( group ), myIndex( idx ) {}
+ CrMenu( const int id, const QString& menu, const int group, const int idx )
+ : myCase( 3 ), myId( id ), myMenuName( menu ), myGroup( group ), myIndex( idx ) {}
+ CrMenu( QtxAction* action, const int menu, const int id, const int group, const int idx )
+ : myCase( 4 ), myAction( action ), myMenuId( menu ), myId( id ), myGroup( group ), myIndex( idx ) {}
+ CrMenu( QtxAction* action, const QString& menu, const int id, const int group, const int idx )
+ : myCase( 5 ), myAction( action ), myMenuName( menu ), myId( id ), myGroup( group ), myIndex( idx ) {}
+
+ int execute( SALOME_PYQT_Module* module ) const
+ {
+ if ( module ) {
+ switch ( myCase ) {
+ case 0:
+ return module->createMenu( mySubMenuName, myMenuId, myId, myGroup, myIndex );
+ case 1:
+ return module->createMenu( mySubMenuName, myMenuName, myId, myGroup, myIndex );
+ case 2:
+ return module->createMenu( myId, myMenuId, myGroup, myIndex );
+ case 3:
+ return module->createMenu( myId, myMenuName, myGroup, myIndex );
+ case 4:
+ return module->createMenu( myAction, myMenuId, myId, myGroup, myIndex );
+ case 5:
+ return module->createMenu( myAction, myMenuName, myId, myGroup, myIndex );
+ }
+ }
+ return -1;
+ }
+private:
+ int myCase;
+ QString myMenuName;
+ int myMenuId;
+ QString mySubMenuName;
+ int myGroup;
+ QtxAction* myAction;
+ int myId;
+ int myIndex;
+};
+class TCreateMenuEvent: public SALOME_Event {
+public:
+ typedef int TResult;
+ TResult myResult;
+ const CrMenu& myCrMenu;
+ TCreateMenuEvent( const CrMenu& crMenu )
+ : myResult( -1 ), myCrMenu( crMenu ) {}
+ virtual void Execute() {
+ if ( SalomeApp_Application* anApp = getApplication() ) {
+ SALOME_PYQT_Module* module = SALOME_PYQT_Module::getInitModule();
+ if ( !module )
+ module = dynamic_cast<SALOME_PYQT_Module*>( anApp->activeModule() );
+ myResult = myCrMenu.execute( module );
+ }
+ }
+};
+int SalomePyQt::createMenu( const QString& subMenu, const int menu, const int id, const int group, const int idx )
+{
+ return ProcessEvent( new TCreateMenuEvent( CrMenu( subMenu, menu, id, group, idx ) ) );
+}
+
+int SalomePyQt::createMenu( const QString& subMenu, const QString& menu, const int id, const int group, const int idx )
+{
+ return ProcessEvent( new TCreateMenuEvent( CrMenu( subMenu, menu, id, group, idx ) ) );
+}
+
+int SalomePyQt::createMenu( const int id, const int menu, const int group, const int idx )
+{
+ return ProcessEvent( new TCreateMenuEvent( CrMenu( id, menu, group, idx ) ) );
+}
+
+int SalomePyQt::createMenu( const int id, const QString& menu, const int group, const int idx )
+{
+ return ProcessEvent( new TCreateMenuEvent( CrMenu( id, menu, group, idx ) ) );
+}
+
+int SalomePyQt::createMenu( QtxAction* a, const int menu, const int id, const int group, const int idx )
+{
+ return ProcessEvent( new TCreateMenuEvent( CrMenu( a, menu, id, group, idx ) ) );
+}
+
+int SalomePyQt::createMenu( QtxAction* a, const QString& menu, const int id, const int group, const int idx )
+{
+ return ProcessEvent( new TCreateMenuEvent( CrMenu( a, menu, id, group, idx ) ) );
+}
+
+/*!
+ SalomePyQt::createSeparator
+ Create a separator action which can be then used in the menu or toolbar.
+*/
+class TCreateSepEvent: public SALOME_Event {
+public:
+ typedef QtxAction* TResult;
+ TResult myResult;
+ TCreateSepEvent()
+ : myResult( 0 ) {}
+ virtual void Execute() {
+ if ( SalomeApp_Application* anApp = getApplication() ) {
+ SALOME_PYQT_Module* module = SALOME_PYQT_Module::getInitModule();
+ if ( !module )
+ module = dynamic_cast<SALOME_PYQT_Module*>( anApp->activeModule() );
+ if ( module )
+ myResult = (QtxAction*)module->createSeparator();
+ }
+ }
+};
+QtxAction* SalomePyQt::createSeparator()
+{
+ return ProcessEvent( new TCreateSepEvent() );
+}
+
+/*!
+ SalomePyQt::createAction
+ Create an action which can be then used in the menu or toolbar:
+ - id : the unique id action to be registered to;
+ - menuText : action text which should appear in menu;
+ - tipText : text which should appear in the tooltip;
+ - statusText : text which should appear in the status bar when action is activated;
+ - icon : the name of the icon file (the actual icon file name can be coded in the translation files);
+ - key : the key accelrator for the action
+ - toggle : if true the action is checkable
+*/
+class TCreateActionEvent: public SALOME_Event {
+public:
+ typedef QtxAction* TResult;
+ TResult myResult;
+ int myId;
+ QString myMenuText;
+ QString myTipText;
+ QString myStatusText;
+ QString myIcon;
+ int myKey;
+ bool myToggle;
+ TCreateActionEvent( const int id, const QString& menuText, const QString& tipText,
+ const QString& statusText, const QString& icon, const int key, const bool toggle )
+ : myResult( 0 ), myId( id ), myMenuText( menuText ), myTipText( tipText ),
+ myStatusText( statusText ), myIcon( icon ), myKey( key ), myToggle( toggle ) {}
+ virtual void Execute() {
+ if ( SalomeApp_Application* anApp = getApplication() ) {
+ SALOME_PYQT_Module* module = SALOME_PYQT_Module::getInitModule();
+ if ( !module )
+ module = dynamic_cast<SALOME_PYQT_Module*>( anApp->activeModule() );
+ if ( module )
+ myResult = (QtxAction*)module->createAction( myId, myTipText, myIcon, myMenuText, myStatusText, myKey, myToggle );
+ }
+ }
+};
+QtxAction* SalomePyQt::createAction( const int id, const QString& menuText,
+ const QString& tipText, const QString& statusText,
+ const QString& icon, const int key, const bool toggle )
+{
+ return ProcessEvent( new TCreateActionEvent( id, menuText, tipText, statusText, icon, key, toggle ) );
+}
+
+/*!
+ SalomePyQt::action
+ Get an action by its id. Returns 0 if the action with such id was not registered.
+*/
+class TActionEvent: public SALOME_Event {
+public:
+ typedef QtxAction* TResult;
+ TResult myResult;
+ int myId;
+ TActionEvent( const int id )
+ : myResult( 0 ), myId( id ) {}
+ virtual void Execute() {
+ if ( SalomeApp_Application* anApp = getApplication() ) {
+ SALOME_PYQT_Module* module = SALOME_PYQT_Module::getInitModule();
+ if ( !module )
+ module = dynamic_cast<SALOME_PYQT_Module*>( anApp->activeModule() );
+ if ( module )
+ myResult = (QtxAction*)module->action( myId );
+ }
+ }
+};
+QtxAction* SalomePyQt::action( const int id )
+{
+ return ProcessEvent( new TActionEvent( id ) );
+}
+
+/*!
+ SalomePyQt::actionId
+ Get an action id. Returns -1 if the action was not registered.
+*/
+class TActionIdEvent: public SALOME_Event {
+public:
+ typedef int TResult;
+ TResult myResult;
+ const QtxAction* myAction;
+ TActionIdEvent( const QtxAction* action )
+ : myResult( -1 ), myAction( action ) {}
+ virtual void Execute() {
+ if ( SalomeApp_Application* anApp = getApplication() ) {
+ SALOME_PYQT_Module* module = SALOME_PYQT_Module::getInitModule();
+ if ( !module )
+ module = dynamic_cast<SALOME_PYQT_Module*>( anApp->activeModule() );
+ if ( module )
+ myResult = module->actionId( myAction );
+ }
+ }
+};
+int SalomePyQt::actionId( const QtxAction* a )
+{
+ return ProcessEvent( new TActionIdEvent( a ) );
+}
+
+/*!
+ SalomePyQt::clearMenu
+ Clears given menu (recursively if necessary)
+*/
+class TClearMenuEvent: public SALOME_Event {
+public:
+ typedef bool TResult;
+ TResult myResult;
+ int myId;
+ int myMenu;
+ bool myRemoveActions;
+ TClearMenuEvent( const int id, const int menu, const bool removeActions )
+ : myResult( false ), myId( id ), myMenu( menu ), myRemoveActions( removeActions ) {}
+ virtual void Execute() {
+ if ( SalomeApp_Application* anApp = getApplication() ) {
+ SALOME_PYQT_Module* module = SALOME_PYQT_Module::getInitModule();
+ if ( !module )
+ module = dynamic_cast<SALOME_PYQT_Module*>( anApp->activeModule() );
+ if ( module )
+ myResult = module->clearMenu( myId, myMenu, myRemoveActions );
+ }
+ }
+};
+bool SalomePyQt::clearMenu( const int id, const int menu, const bool removeActions )
+{
+ return ProcessEvent( new TClearMenuEvent( id, menu, removeActions ) );
+}
+