From: vsr Date: Tue, 3 Jul 2007 15:28:32 +0000 (+0000) Subject: Porting to Qt 4 X-Git-Tag: qt4_porting_delivery_220807~125 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=0f567f96f7bd20d6900d319c60cc65ae3df6c60b;p=modules%2Fgui.git Porting to Qt 4 --- diff --git a/src/LightApp/LightApp_Application.cxx b/src/LightApp/LightApp_Application.cxx index 0b9a534c1..9d69ba44d 100644 --- a/src/LightApp/LightApp_Application.cxx +++ b/src/LightApp/LightApp_Application.cxx @@ -917,49 +917,54 @@ void LightApp_Application::updateCommandsStatus() \class RunBrowser Runs system command in separate thread */ -class RunBrowser: public QThread { +class RunBrowser: public QThread +{ public: - - RunBrowser( LightApp_Application* app, QString theApp, QString theParams, QString theHelpFile, QString theContext=NULL): - myApp(theApp), myParams(theParams), + RunBrowser( LightApp_Application* app, + const QString& theApp, + const QString& theParams, + const QString& theHelpFile, + const QString& theContext = QString() ) + : myApp( theApp ), + myParams( theParams ), #ifdef WIN32 - myHelpFile("file://" + theHelpFile + theContext), + myHelpFile( "file://" + theHelpFile ), #else - myHelpFile("file:" + theHelpFile + theContext), + myHelpFile( "file:" + theHelpFile ), #endif + myContext( theContext ), myStatus(0), myLApp( app ) -{ -}; + { + } virtual void run() { - QString aCommand; + if ( !myApp.isEmpty()) { + QString aCommand = QString( "%1 %2 %3" ).arg( myApp, myParams, myHelpFile ); + if ( !myContext.isEmpty() ) + aCommand += "#" + myContext; - if ( !myApp.isEmpty()) - { - aCommand.sprintf("%s %s %s",myApp.toLatin1().constData(),myParams.toLatin1().constData(),myHelpFile.toLatin1().constData()); - - QProcess* proc = new QProcess(); - //myStatus = system(aCommand); - - //if(myStatus != 0) - proc->start(aCommand); - if (proc->waitForStarted()) - { - SALOME_CustomEvent* ce2000 = new SALOME_CustomEvent( 2000 ); - QString* msg = new QString( QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").arg(myApp).arg(myHelpFile) ); - ce2000->setData( msg ); - QApplication::postEvent( myLApp, ce2000 ); - } + QProcess* proc = new QProcess(); + //myStatus = system(aCommand); + + //if(myStatus != 0) + proc->start( aCommand ); + if ( proc->waitForStarted() ) { + SALOME_CustomEvent* ce2000 = new SALOME_CustomEvent( 2000 ); + QString* msg = new QString( QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").arg(myApp).arg(myHelpFile) ); + ce2000->setData( msg ); + QApplication::postEvent( myLApp, ce2000 ); } + } } private: - QString myApp; - QString myParams; - QString myHelpFile; - int myStatus; + QString myApp; + QString myParams; + QString myHelpFile; + QString myContext; + int myStatus; LightApp_Application* myLApp; }; @@ -1011,10 +1016,21 @@ void LightApp_Application::onHelpContentsModule() /*! SLOT: Displays help contents for choosen dialog */ -void LightApp_Application::onHelpContextModule(const QString& theComponentName, const QString& theFileName) -{ - QString dir = getenv( (theComponentName + "_ROOT_DIR").toLatin1().constData() ); - QString homeDir = Qtx::addSlash(Qtx::addSlash(dir)+Qtx::addSlash("share")+Qtx::addSlash("doc")+Qtx::addSlash("salome")+Qtx::addSlash("gui")+Qtx::addSlash(theComponentName)); +void LightApp_Application::onHelpContextModule( const QString& theComponentName, + const QString& theFileName, + const QString& theContext ) +{ + QString homeDir = ""; + if ( !theComponentName.isEmpty() ) { + QString dir = getenv( ( theComponentName + "_ROOT_DIR" ).toLatin1().constData() ); + if ( !dir.isEmpty() ) + homeDir = Qtx::addSlash( Qtx::addSlash( dir ) + + Qtx::addSlash( "share" ) + + Qtx::addSlash( "doc" ) + + Qtx::addSlash( "salome" ) + + Qtx::addSlash( "gui" ) + + Qtx::addSlash( theComponentName ) ); + } QString helpFile = QFileInfo( homeDir + theFileName ).absoluteFilePath(); SUIT_ResourceMgr* resMgr = resourceMgr(); @@ -1033,7 +1049,7 @@ void LightApp_Application::onHelpContextModule(const QString& theComponentName, QString aParams = resMgr->stringValue("ExternalBrowser", "parameters"); if (!anApp.isEmpty()) { - RunBrowser* rs = new RunBrowser( this, anApp, aParams, helpFile ); + RunBrowser* rs = new RunBrowser( this, anApp, aParams, helpFile, theContext ); rs->start(); } else { diff --git a/src/LightApp/LightApp_Application.h b/src/LightApp/LightApp_Application.h index 2e7a29e3c..7338fafff 100644 --- a/src/LightApp/LightApp_Application.h +++ b/src/LightApp/LightApp_Application.h @@ -168,7 +168,7 @@ signals: public slots: virtual void onHelpContentsModule(); - virtual void onHelpContextModule( const QString&, const QString& ); + virtual void onHelpContextModule( const QString&, const QString&, const QString& = QString() ); virtual void onNewDoc(); virtual void onOpenDoc(); virtual void onHelpAbout(); diff --git a/src/Makefile.am b/src/Makefile.am index 82c33b34d..07679e901 100755 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -67,8 +67,5 @@ endif SUBDIRS += Event LightApp ResExporter if GUI_ENABLE_CORBA -# VSR: this is the original packages list -# SUBDIRS += TOOLSGUI Session SalomeApp SALOME_SWIG SALOME_PY SALOME_PYQT -# VSR: already migrated to Qt4 packages - SUBDIRS += TOOLSGUI Session SalomeApp + SUBDIRS += TOOLSGUI Session SalomeApp SALOME_SWIG SALOME_PY SALOME_PYQT endif diff --git a/src/SALOME_PYQT/SALOME_PYQT_GUI/Makefile.am b/src/SALOME_PYQT/SALOME_PYQT_GUI/Makefile.am index 6d7757c58..c6584d508 100644 --- a/src/SALOME_PYQT/SALOME_PYQT_GUI/Makefile.am +++ b/src/SALOME_PYQT/SALOME_PYQT_GUI/Makefile.am @@ -49,7 +49,7 @@ nodist_libSalomePyQtGUI_la_SOURCES= $(MOC_FILES) $(SIP_SRC) libSalomePyQtGUI_la_CPPFLAGS= $(QT_INCLUDES) $(SIP_INCLUDES) $(PYTHON_INCLUDES) \ $(CAS_CPPFLAGS) $(VTK_INCLUDES) $(OGL_INCLUDES) $(BOOST_CPPFLAGS) \ - -DHAVE_CONFIG_H @KERNEL_CXXFLAGS@ -D__CALL_OLD_METHODS__ \ + -DHAVE_CONFIG_H @KERNEL_CXXFLAGS@ -DCALL_OLD_METHODS \ -I$(srcdir)/../../PyInterp -I$(srcdir)/../../SalomeApp \ -I$(srcdir)/../../SUIT -I$(srcdir)/../../Qtx -I$(srcdir)/../../LightApp \ -I$(srcdir)/../../SalomeApp -I$(srcdir)/../../CAM -I$(srcdir)/../../STD \ diff --git a/src/SALOME_PYQT/SALOME_PYQT_GUI/SALOME_PYQT_GUI.h b/src/SALOME_PYQT/SALOME_PYQT_GUI/SALOME_PYQT_GUI.h index 0b646291a..2931f1faa 100644 --- a/src/SALOME_PYQT/SALOME_PYQT_GUI/SALOME_PYQT_GUI.h +++ b/src/SALOME_PYQT/SALOME_PYQT_GUI/SALOME_PYQT_GUI.h @@ -16,23 +16,23 @@ // // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // +// File : SALOME_PYQT_GUI.h +// Author : Vadim SANDLER, Open CASCADE SAS, vadim.sandler@opencascade.com +// + #if !defined ( SALOME_PYQT_GUI_H ) #define SALOME_PYQT_GUI_H // ======================================================== // set dllexport type for Win platform #ifdef WIN32 - -#ifdef SALOME_PYQT_EXPORTS -#define SALOME_PYQT_EXPORT __declspec(dllexport) -#else -#define SALOME_PYQT_EXPORT __declspec(dllimport) -#endif - +# ifdef SALOME_PYQT_EXPORTS +# define SALOME_PYQT_EXPORT __declspec(dllexport) +# else +# define SALOME_PYQT_EXPORT __declspec(dllimport) +# endif #else // WIN32 - -#define SALOME_PYQT_EXPORT - +# define SALOME_PYQT_EXPORT #endif // WIN32 // ======================================================== diff --git a/src/SALOME_PYQT/SALOME_PYQT_GUI/SALOME_PYQT_GUI.sip b/src/SALOME_PYQT/SALOME_PYQT_GUI/SALOME_PYQT_GUI.sip index 2f0543851..36f59f752 100644 --- a/src/SALOME_PYQT/SALOME_PYQT_GUI/SALOME_PYQT_GUI.sip +++ b/src/SALOME_PYQT/SALOME_PYQT_GUI/SALOME_PYQT_GUI.sip @@ -1,4 +1,5 @@ %Module SalomePyQtGUI -%Import qtmod.sip +%Import QtGuimod.sip +%Import QtXmlmod.sip diff --git a/src/SALOME_PYQT/SALOME_PYQT_GUI/SALOME_PYQT_Module.cxx b/src/SALOME_PYQT/SALOME_PYQT_GUI/SALOME_PYQT_Module.cxx index 4d48c40e5..30889c47a 100644 --- a/src/SALOME_PYQT/SALOME_PYQT_GUI/SALOME_PYQT_Module.cxx +++ b/src/SALOME_PYQT/SALOME_PYQT_GUI/SALOME_PYQT_Module.cxx @@ -16,76 +16,96 @@ // // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // +// File : SALOME_PYQT_Module.cxx +// Author : Vadim SANDLER, Open CASCADE SAS, vadim.sandler@opencascade.com +// -#include "PyInterp_Dispatcher.h" #include "SALOME_PYQT_Module.h" +#include + +#include +#include +#include +#include +#include +#include -#include "SUIT_ResourceMgr.h" -#include "STD_MDIDesktop.h" -#include "STD_TabDesktop.h" -#include "SalomeApp_Application.h" -#include "SalomeApp_Study.h" -#include "LightApp_Preferences.h" +#include +#include +#include +#include -#include "QtxWorkstack.h" -#include "QtxActionMenuMgr.h" -#include "QtxActionToolMgr.h" #include #include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include #include "sipAPISalomePyQtGUI.h" -#include "sipqtQWidget.h" -#include "sipqtQPopupMenu.h" - -#include - -using namespace std; +#include "sipQtGuiQWidget.h" +#include "sipQtGuiQMenu.h" /*! - \var __DEFAULT_NAME__ - Default name of the module, replaced at the moment of module creation + \brief Default name of the module, replaced at the moment + of module creation. + \internal */ -const char* __DEFAULT_NAME__ = "SALOME_PYQT_Module"; +const char* DEFAULT_NAME = "SALOME_PYQT_Module"; /*! - \var __DEFAULT_GROUP__ - Default menu group number + \brief Default menu group number. + \internal */ -const int __DEFAULT_GROUP__ = 40; +const int DEFAULT_GROUP = 40; + +/*! + \var IsCallOldMethods + \brief Allow calling obsolete callback methods. + \internal + + If the macro CALL_OLD_METHODS is not defined, the invoking + of obsolete Python module's methods like setSetting(), definePopup(), + etc. is blocked. -// If __CALL_OLD_METHODS__ macro is not defined the invoking of obsolete Python -// module's methods like setSetting(), definePopup(), etc. is blocked. -// This macro is defined by default (in Makefile) -#ifdef __CALL_OLD_METHODS__ + CALL_OLD_METHODS macro can be defined for example by adding + -DCALL_OLD_METHODS compilation option to the Makefile. +*/ +#ifdef CALL_OLD_METHODS const bool IsCallOldMethods = true; #else const bool IsCallOldMethods = false; #endif +// // NB: Python requests. // General rule for Python requests created by SALOME_PYQT_Module: // all requests should be executed SYNCHRONOUSLY within the main GUI thread. // However, it is obligatory that ANY Python call is wrapped with a request object, // so that ALL Python API calls are serialized with PyInterp_Dispatcher. +// /*! - \class SALOME_PYQT_XmlHandler - The class for parsing of the XML resource files. - Used for backward compatibility with existing Python modules. + \class SALOME_PYQT_Module::XmlHandler + \brief XML resource files parser. + \internal + + This class is used to provide backward compatibility with + existing Python modules in which obsolete menu definition system + (via XML files) is used. */ -class SALOME_PYQT_XmlHandler + +class SALOME_PYQT_Module::XmlHandler { public: - SALOME_PYQT_XmlHandler( SALOME_PYQT_Module* module, const QString& fileName ); + XmlHandler( SALOME_PYQT_Module* module, const QString& fileName ); void createActions(); - void clearActions(); - void createPopup ( QPopupMenu* menu, + void createPopup ( QMenu* menu, const QString& context, const QString& parent, const QString& object ); @@ -94,25 +114,23 @@ protected: void createToolBar ( QDomNode& parentNode ); void createMenu ( QDomNode& parentNode, const int parentMenuId = -1, - QPopupMenu* parentPopup = 0 ); + QMenu* parentPopup = 0 ); void insertPopupItems( QDomNode& parentNode, - QPopupMenu* menu ); + QMenu* menu ); private: SALOME_PYQT_Module* myModule; QDomDocument myDoc; QStringList myMenuItems; - QStringList myCurrentMenu; - bool myMenuCreated; }; -// SALOME_PYQT_Module class implementation (implements CAM_Module API for -// all Python-based SALOME module - -// While the SalomePyQtGUI library is not imported in Python it's initialization function +// +// NB: Library initialization +// Since the SalomePyQtGUI library is not imported in Python it's initialization function // should be called manually (and only once) in order to initialize global sip data // and to get C API from sip : sipBuildResult for example +// #define INIT_FUNCTION initSalomePyQtGUI #if defined(SIP_STATIC_MODULE) extern "C" void INIT_FUNCTION(); @@ -121,14 +139,21 @@ PyMODINIT_FUNC INIT_FUNCTION(); #endif /*! - * This function creates an instance of SALOME_PYQT_Module object by request - * of and application object when the module is loaded. - */ + \fn CAM_Module* createModule() + \brief Module factory function. + \internal + + Creates an instance of SALOME_PYQT_Module object by request + of an application when the module is loaded and initialized. + + \return new module object +*/ + extern "C" { SALOME_PYQT_EXPORT CAM_Module* createModule() { static bool alreadyInitialized = false; if ( !alreadyInitialized ) { - // call only once (see above) ! + // call only once (see comment above) ! PyEval_RestoreThread( KERNEL_PYTHON::_gtstate ); INIT_FUNCTION(); PyEval_ReleaseThread( KERNEL_PYTHON::_gtstate ); @@ -139,14 +164,56 @@ extern "C" { } /*! - * Static variables definition - */ + \class FuncMsg + \brief Function call in/out tracer. + \internal +*/ + +class FuncMsg +{ +public: + FuncMsg( const QString& funcName ) + { + myName = funcName; + MESSAGE( myName.toLatin1().constData() << " [ begin ]" ); + } + ~FuncMsg() + { + MESSAGE( myName.toLatin1().constData() << " [ end ]" ); + } + void message( const QString& msg ) + { + MESSAGE( myName.toLatin1().constData() << " : " << msg.toLatin1().constData() ); + } +private: + QString myName; +}; + +/*! + \class SALOME_PYQT_Module + \brief This class implements module API for all the Python-based + SALOME modules. +*/ + +// +// Static variables definition +// SALOME_PYQT_Module::InterpMap SALOME_PYQT_Module::myInterpMap; SALOME_PYQT_Module* SALOME_PYQT_Module::myInitModule = 0; /*! - * Little trick : provide an access to being activated Python module from outside; - * needed by the SalomePyQt library :( + \brief Get the module being initialized. + + This is a little trick :) needed to provide an access from Python + (SalomePyQt) to the module being currently activated. The problem + that during the process of module initialization (initialize() + function) it is not yet available via application->activeModule() + call. + + This method returns valid pointer only if called in scope of + initialize() function. + + \return the module being currently initialized */ SALOME_PYQT_Module* SALOME_PYQT_Module::getInitModule() { @@ -154,19 +221,20 @@ SALOME_PYQT_Module* SALOME_PYQT_Module::getInitModule() } /*! - * Constructor - */ + \brief Constructor +*/ SALOME_PYQT_Module::SALOME_PYQT_Module() - : SalomeApp_Module( __DEFAULT_NAME__ ), - myModule( 0 ), - myXmlHandler ( 0 ), - myLastActivateStatus( true ) +: SalomeApp_Module( DEFAULT_NAME ), + myInterp( 0 ), + myModule( 0 ), + myXmlHandler ( 0 ), + myLastActivateStatus( true ) { } /*! - * Destructor - */ + \brief Destructor +*/ SALOME_PYQT_Module::~SALOME_PYQT_Module() { if ( myXmlHandler ) @@ -174,37 +242,56 @@ SALOME_PYQT_Module::~SALOME_PYQT_Module() } /*! - * Initialization of the module. - * Inherited from CAM_Module. - * - * This method is used for creation of the menus, toolbars and other staff. - * There are two ways: - * - for obsolete modules this method first tries to read _.xml - * resource file which contains a menu, toolbars and popup menus description. - * - new modules can create menus by by calling the corresponding methods of SalomePyQt - * Python API in the Python module's initialize() method which is called from here. - * NOTE: if postponed modules loading is not used, the active study might be not defined - * yet at this stage, so initialize() method should not perform any study-based initialization. - */ + \brief Initialization of the module. + + This method can be used for creation of the menus, toolbars and + other such staff. + + There are two ways to do this: + - for obsolete modules this method first tries to read + _.xml resource file which contains a menu, + toolbars and popup menus description; + - new modules can create menus by direct calling of the + corresponding methods of SalomePyQt Python API in the Python + module's initialize() method which is called from here. + + NOTE: SALOME supports two modes of modules loading: + - immediate (all the modules are created and initialized + immediately when the application object is created; + - postponed modules loading (used currently); in this mode + the module is loaded only be request. + If postponed modules loading is not used, the active + study might be not yet defined at this stage, so initialize() + method should not perform any study-based initialization. + + \param app parent application object +*/ void SALOME_PYQT_Module::initialize( CAM_Application* app ) { - MESSAGE( "SALOME_PYQT_Module::initialize" ); + FuncMsg fmsg( "SALOME_PYQT_Module::initialize()" ); + // call base implementation SalomeApp_Module::initialize( app ); - // Try to get XML resource file name + // try to get XML resource file name SUIT_ResourceMgr* aResMgr = getApp()->resourceMgr(); - QString aLang = aResMgr->stringValue( "language", "language", QString::null ); - if ( aLang.isEmpty() ) aLang = QString( "en" ); - QString aName = name( "" ); - QString aFileName = aName + "_" + aLang + ".xml"; - aFileName = aResMgr->path( "resources", aName, aFileName ); - - // create XML handler instance - if ( !myXmlHandler && !aFileName.isEmpty() && QFile::exists( aFileName ) ) - myXmlHandler = new SALOME_PYQT_XmlHandler( this, aFileName ); + if ( !myXmlHandler && aResMgr ) { + // get current language + QString aLang = aResMgr->stringValue( "language", "language", QString() ); + if ( aLang.isEmpty() ) + aLang = "en"; + // define resource file name + QString aFileName = name() + "_" + aLang + ".xml"; + aFileName = aResMgr->path( "resources", name(), aFileName ); + // create XML handler instance + if ( !aFileName.isEmpty() && QFile::exists( aFileName ) ) + myXmlHandler = new SALOME_PYQT_Module::XmlHandler( this, aFileName ); + // create menus & toolbars from XML file if required + if ( myXmlHandler ) + myXmlHandler->createActions(); + } - // perform internal initialization and call module's initialize() method + // perform internal initialization and call module's initialize() funtion // InitializeReq: request class for internal init() operation class InitializeReq : public PyInterp_Request { @@ -226,18 +313,28 @@ void SALOME_PYQT_Module::initialize( CAM_Application* app ) SALOME_PYQT_Module* myObj; }; - // Posting the request + // post request PyInterp_Dispatcher::Get()->Exec( new InitializeReq( app, this ) ); } /*! - * Activation of the module. - * Inherited from CAM_Module. - */ + \brief Activation of the module. + + This function is usually used in order to show the module's + specific menus and toolbars, update actions state and perform + other such actions required when the module is activated. + + Note, that returning \c false in this function prevents the + module activation. + + \param theStudy parent study + \return \c true if activation is successful and \c false otherwise +*/ bool SALOME_PYQT_Module::activateModule( SUIT_Study* theStudy ) { - MESSAGE( "SALOME_PYQT_Module::activateModule" ); + FuncMsg fmsg( "SALOME_PYQT_Module::activateModule()" ); + // call base implementation bool res = SalomeApp_Module::activateModule( theStudy ); if ( !res ) @@ -246,6 +343,7 @@ bool SALOME_PYQT_Module::activateModule( SUIT_Study* theStudy ) // reset the activation status to the default value myLastActivateStatus = true; + // perform internal activation // ActivateReq: request class for internal activate() operation class ActivateReq : public PyInterp_Request { @@ -267,9 +365,10 @@ bool SALOME_PYQT_Module::activateModule( SUIT_Study* theStudy ) SALOME_PYQT_Module* myObj; }; - // Posting the request + // post request PyInterp_Dispatcher::Get()->Exec( new ActivateReq( theStudy, this ) ); + // check activation status (set by activate()) if ( !lastActivationStatus() ) return false; @@ -277,16 +376,11 @@ bool SALOME_PYQT_Module::activateModule( SUIT_Study* theStudy ) setMenuShown( true ); setToolShown( true ); - if ( menuMgr() ) - connect( menuMgr(), SIGNAL( menuHighlighted( int, int ) ), - this, SLOT( onMenuHighlighted( int, int ) ) ); + // connect preferences changing signal connect( getApp(), SIGNAL( preferenceChanged( const QString&, const QString&, const QString& ) ), this, SLOT( preferenceChanged( const QString&, const QString&, const QString& ) ) ); - // create menus & toolbars from XML file if required - if ( myXmlHandler ) - myXmlHandler->createActions(); - + // perform custom activation actions // CustomizeReq: request class for internal customize() operation class CustomizeReq : public PyInterp_Request { @@ -308,39 +402,40 @@ bool SALOME_PYQT_Module::activateModule( SUIT_Study* theStudy ) SALOME_PYQT_Module* myObj; }; - // Posting the request + // post request PyInterp_Dispatcher::Get()->Exec( new CustomizeReq( theStudy, this ) ); return true; } /*! - * Deactivation of the module. - * Inherited from CAM_Module. - */ + \brief Deactivation of the module. + + This function is usually used in order to hide the module's + specific menus and toolbars and perform other such actions + required when the module is deactivated. + + \param theStudy parent study + \return \c true if deactivation is successful and \c false otherwise +*/ bool SALOME_PYQT_Module::deactivateModule( SUIT_Study* theStudy ) { - MESSAGE( "SALOME_PYQT_Module::deactivateModule" ); + FuncMsg fmsg( "SALOME_PYQT_Module::deactivateModule()" ); - if ( menuMgr() ) - disconnect( menuMgr(), SIGNAL( menuHighlighted( int, int ) ), - this, SLOT( onMenuHighlighted( int, int ) ) ); + // disconnect preferences changing signal disconnect( getApp(), SIGNAL( preferenceChanged( const QString&, const QString&, const QString& ) ), this, SLOT( preferenceChanged( const QString&, const QString&, const QString& ) ) ); - // remove menus & toolbars created from XML file if required - if ( myXmlHandler ) - myXmlHandler->clearActions(); - // deactivate menus, toolbars, etc setMenuShown( false ); setToolShown( false ); + // perform internal deactivation // DeactivateReq: request class for internal deactivate() operation class DeactivateReq : public PyInterp_LockRequest { public: - DeactivateReq( PyInterp_base* _py_interp, + DeactivateReq( PyInterp_Interp* _py_interp, SUIT_Study* _study, SALOME_PYQT_Module* _obj ) : PyInterp_LockRequest( _py_interp, 0, true ), // this request should be processed synchronously (sync == true) @@ -358,15 +453,17 @@ bool SALOME_PYQT_Module::deactivateModule( SUIT_Study* theStudy ) SALOME_PYQT_Module* myObj; }; - // Posting the request + // post request PyInterp_Dispatcher::Get()->Exec( new DeactivateReq( myInterp, theStudy, this ) ); + // call base implementation return SalomeApp_Module::deactivateModule( theStudy ); } /*! - * Returns the status of last trying of module activation. - * Before fisrt activation - status is false + \brief Get last activation status. + \return status of last module activation operation + \sa activateModule() */ bool SALOME_PYQT_Module::lastActivationStatus() const { @@ -374,19 +471,25 @@ bool SALOME_PYQT_Module::lastActivationStatus() const } /*! - Preferences changing (application) - called when preference is changed + \breif Process application preferences changing. + + Called when any application setting is changed. + + \param module preference module + \param section preference resource file section + \param setting preference resource name */ void SALOME_PYQT_Module::preferenceChanged( const QString& module, const QString& section, const QString& setting ) { - MESSAGE( "SALOME_PYQT_Module::preferenceChanged"); + FuncMsg fmsg( "SALOME_PYQT_Module::preferenceChanged()" ); // perform synchronous request to Python event dispatcher class Event : public PyInterp_LockRequest { public: - Event( PyInterp_base* _py_interp, + Event( PyInterp_Interp* _py_interp, SALOME_PYQT_Module* _obj, const QString& _section, const QString& _setting ) @@ -407,21 +510,25 @@ void SALOME_PYQT_Module::preferenceChanged( const QString& module, }; if ( module != moduleName() ) { - // Module's preferences are processed by preferencesChanged() method + // module's own preferences are processed by preferencesChanged() method // ... - // Posting the request only if dispatcher is not busy! - // Executing the request synchronously + // post the request only if dispatcher is not busy! + // execute request synchronously if ( !PyInterp_Dispatcher::Get()->IsBusy() ) PyInterp_Dispatcher::Get()->Exec( new Event( myInterp, this, section, setting ) ); } } /*! - * Called when study desktop is activated. - * Used for notifying about changing of the active study. - */ + \brief Process study activation. + + Called when study desktop is activated. Used for notifying the Python + module about changing of the active study. +*/ void SALOME_PYQT_Module::studyActivated() { + FuncMsg fmsg( "SALOME_PYQT_Module::studyActivated()" ); + // StudyChangedReq: request class for internal studyChanged() operation class StudyChangedReq : public PyInterp_Request { @@ -443,30 +550,32 @@ void SALOME_PYQT_Module::studyActivated() SALOME_PYQT_Module* myObj; }; - // Posting the request + // post request PyInterp_Dispatcher::Get()->Exec( new StudyChangedReq( application()->activeStudy(), this ) ); } /*! - * Processes GUI action (from main menu, toolbar or context popup menu) - */ + \brief Process GUI action (from main menu, toolbar or + context popup menu action). +*/ void SALOME_PYQT_Module::onGUIEvent() { + FuncMsg fmsg( "SALOME_PYQT_Module::onGUIEvent()" ); + // get sender action - const QObject* obj = sender(); - if ( !obj || !obj->inherits( "QAction" ) ) + QAction* action = qobject_cast( sender() ); + if ( !action ) return; - QAction* action = (QAction*)obj; // get action ID int id = actionId( action ); - MESSAGE( "SALOME_PYQT_Module::onGUIEvent: id = " << id ); + fmsg.message( QString( "action id = %1" ).arg( id ) ); // perform synchronous request to Python event dispatcher class GUIEvent : public PyInterp_LockRequest { public: - GUIEvent( PyInterp_base* _py_interp, + GUIEvent( PyInterp_Interp* _py_interp, SALOME_PYQT_Module* _obj, int _id ) : PyInterp_LockRequest( _py_interp, 0, true ), // this request should be processed synchronously (sync == true) @@ -484,92 +593,35 @@ void SALOME_PYQT_Module::onGUIEvent() SALOME_PYQT_Module* myObj; }; - // Posting the request + // post request PyInterp_Dispatcher::Get()->Exec( new GUIEvent( myInterp, this, id ) ); } /*! - * Processes GUI action (from context popup menu, only for XML-based actions!) - */ -void SALOME_PYQT_Module::onGUIEvent( int id ) -{ - // perform synchronous request to Python event dispatcher - class GUIEvent : public PyInterp_LockRequest - { - public: - GUIEvent( PyInterp_base* _py_interp, - SALOME_PYQT_Module* _obj, - int _id ) - : PyInterp_LockRequest( _py_interp, 0, true ), // this request should be processed synchronously (sync == true) - myId ( _id ), - myObj ( _obj ) {} - - protected: - virtual void execute() - { - myObj->guiEvent( myId ); - } - - private: - int myId; - SALOME_PYQT_Module* myObj; - }; - - // Posting the request - PyInterp_Dispatcher::Get()->Exec( new GUIEvent( myInterp, this, id ) ); -} + \brief Process context popup menu request. + + Called when user activates popup menu in some window + (view, object browser, etc). -/*! - * Menu highlight processing - */ -void SALOME_PYQT_Module::onMenuHighlighted( int menu, int submenu ) + \param theContext popup menu context (e.g. "ObjectBrowser") + \param thePopupMenu popup menu + \param title popup menu title (not used) +*/ +void SALOME_PYQT_Module::contextMenuPopup( const QString& theContext, + QMenu* thePopupMenu, + QString& /*title*/ ) { - if ( !action( menu ) && registered( menu, submenu ) ) { - // perform synchronous request to Python event dispatcher - class MenuHighlightEvent : public PyInterp_LockRequest - { - public: - MenuHighlightEvent( PyInterp_base* _py_interp, - SALOME_PYQT_Module* _obj, - int _menu, - int _submenu ) - : PyInterp_LockRequest( _py_interp, 0, true ), // this request should be processed synchronously (sync == true) - myMenu ( _menu ), - mySubMenu( _submenu ), - myObj ( _obj ) {} - - protected: - virtual void execute() - { - myObj->menuHighlight( myMenu, mySubMenu ); - } + FuncMsg fmsg( "SALOME_PYQT_Module::contextMenuPopup()" ); + fmsg.message( QString( "context: %1" ).arg( theContext ) ); - private: - int myMenu; - int mySubMenu; - SALOME_PYQT_Module* myObj; - }; - - // Posting the request - PyInterp_Dispatcher::Get()->Exec( new MenuHighlightEvent( myInterp, this, menu, submenu ) ); - } -} - -/*! - Context popup menu request. - Called when user activates popup menu in some window (view, object browser, etc). - */ -void SALOME_PYQT_Module::contextMenuPopup( const QString& theContext, QPopupMenu* thePopupMenu, QString& /*title*/ ) -{ - MESSAGE( "SALOME_PYQT_Module::contextMenuPopup : " << theContext.latin1() ); // perform synchronous request to Python event dispatcher class PopupMenuEvent : public PyInterp_LockRequest { public: - PopupMenuEvent( PyInterp_base* _py_interp, + PopupMenuEvent( PyInterp_Interp* _py_interp, SALOME_PYQT_Module* _obj, const QString& _context, - QPopupMenu* _popup ) + QMenu* _popup ) : PyInterp_LockRequest( _py_interp, 0, true ), // this request should be processed synchronously (sync == true) myContext( _context ), myPopup ( _popup ), @@ -584,27 +636,29 @@ void SALOME_PYQT_Module::contextMenuPopup( const QString& theContext, QPopupMenu private: SALOME_PYQT_Module* myObj; QString myContext; - QPopupMenu* myPopup; + QMenu* myPopup; }; - // Posting the request only if dispatcher is not busy! - // Executing the request synchronously + // post request only if dispatcher is not busy! + // execute request synchronously if ( !PyInterp_Dispatcher::Get()->IsBusy() ) PyInterp_Dispatcher::Get()->Exec( new PopupMenuEvent( myInterp, this, theContext, thePopupMenu ) ); } /*! - * Export preferences for the Python module. - * Called only once when the first instance of the module is created. - */ + \brief Export preferences for the Python module. + + Called only once when the first instance of the module is created. +*/ void SALOME_PYQT_Module::createPreferences() { - MESSAGE( "SALOME_PYQT_Module::createPreferences"); + FuncMsg fmsg( "SALOME_PYQT_Module::createPreferences()" ); + // perform synchronous request to Python event dispatcher class Event : public PyInterp_LockRequest { public: - Event( PyInterp_base* _py_interp, + Event( PyInterp_Interp* _py_interp, SALOME_PYQT_Module* _obj ) : PyInterp_LockRequest( _py_interp, 0, true ), // this request should be processed synchronously (sync == true) myObj ( _obj ) {} @@ -619,52 +673,77 @@ void SALOME_PYQT_Module::createPreferences() SALOME_PYQT_Module* myObj; }; - // Posting the request only if dispatcher is not busy! - // Executing the request synchronously + // post request only if dispatcher is not busy! + // execute request synchronously if ( !PyInterp_Dispatcher::Get()->IsBusy() ) PyInterp_Dispatcher::Get()->Exec( new Event( myInterp, this ) ); } /*! - * Defines the dockable window associated with the module. - * To fill the list of windows the correspondind Python module's windows() - * method is called from SALOME_PYQT_Module::init() method. - * By default, ObjectBrowser, PythonConsole and LogWindow are provided. - */ + \brief Define the dockable windows associated with the module. + + To fill the list of windows the correspondind Python module's windows() + method is called from SALOME_PYQT_Module::init() method. + + By default, ObjectBrowser, PythonConsole and LogWindow windows are + associated to the module. + + Allowed dockable windows: + - SalomeApp_Application::WT_ObjectBrowser : object browser + - SalomeApp_Application::WT_PyConsole : python console + - SalomeApp_Application::WT_LogWindow : log messages output window + + Dock area is defined by Qt::DockWidgetArea enumeration: + - Qt::TopDockWidgetArea : top dock area + - Qt::BottomDockWidgetArea : bottom dock area + - Qt::LeftDockWidgetArea : left dock area + - Qt::RightDockWidgetArea : right dock area + + \param mappa map of dockable windows: { : } +*/ void SALOME_PYQT_Module::windows( QMap& mappa ) const { - // First clear the output parameters - QMap::ConstIterator it; - for ( it = myWindowsMap.begin(); it != myWindowsMap.end(); ++it ) { - mappa[ it.key() ] = it.data(); - } + FuncMsg fmsg( "SALOME_PYQT_Module::windows()" ); + + mappa = myWindowsMap; } /*! - * Defines the compatible views which should be opened on module activation. - * To fill the list of views the correspondind Python module's views() - * method is called from SALOME_PYQT_Module::init() method. - * By default, the list is empty. - */ -void SALOME_PYQT_Module::viewManagers( QStringList& listik ) const + \brief Define the compatible view windows associated with the module. + + The associated view windows are opened automatically when the module + is activated. + + To fill the list of views the correspondind Python module's views() + method is called from SALOME_PYQT_Module::init() method. + By default, the list is empty. + + \param listik list of view windows types +*/ +void SALOME_PYQT_Module::viewManagers( QStringList& lst ) const { - for ( QStringList::ConstIterator it = myViewMgrList.begin(); it != myViewMgrList.end(); ++it ) { - listik.append( *it ); - } + FuncMsg fmsg( "SALOME_PYQT_Module::viewManagers()" ); + + lst = myViewMgrList; } /*! - Preferences changing (module) - called when the module's preferences are changed + \brief Process module's preferences changing. + + Called when the module's preferences are changed. + + \param section setting section + \param setting setting name */ void SALOME_PYQT_Module::preferencesChanged( const QString& section, const QString& setting ) { - MESSAGE( "SALOME_PYQT_Module::preferencesChanged"); + FuncMsg fmsg( "SALOME_PYQT_Module::preferencesChanged()" ); // perform synchronous request to Python event dispatcher class Event : public PyInterp_LockRequest { public: - Event( PyInterp_base* _py_interp, + Event( PyInterp_Interp* _py_interp, SALOME_PYQT_Module* _obj, const QString& _section, const QString& _setting ) @@ -684,24 +763,29 @@ void SALOME_PYQT_Module::preferencesChanged( const QString& section, const QStri QString mySection, mySetting; }; - // Posting the request only if dispatcher is not busy! - // Executing the request synchronously + // post request only if dispatcher is not busy! + // execut request synchronously if ( !PyInterp_Dispatcher::Get()->IsBusy() ) PyInterp_Dispatcher::Get()->Exec( new Event( myInterp, this, section, setting ) ); } - /*! - * Performs internal initialization - * - initializes/gets the Python interpreter (one per study) - * - imports the Python module - * - passes the workspace widget to the Python module - * - calls Python module's initialize() method - * - calls Python module's windows() method - * - calls Python module's views() method - */ + \brief Internal module initialization: + + Performs the following actions: + - initialize or get the Python interpreter (one per study) + - import the Python module + - pass the workspace widget to the Python module + - call Python module's initialize() method + - call Python module's windows() method + - call Python module's views() method + + \param app parent application object +*/ void SALOME_PYQT_Module::init( CAM_Application* app ) { + FuncMsg fmsg( "SALOME_PYQT_Module::init()" ); + // reset interpreter to NULL myInterp = NULL; @@ -709,7 +793,6 @@ void SALOME_PYQT_Module::init( CAM_Application* app ) SalomeApp_Application* anApp = dynamic_cast( app ); if ( !anApp ) return; - SalomeApp_Study* aStudy = dynamic_cast( app->activeStudy() ); if ( !aStudy ) return; @@ -725,6 +808,7 @@ void SALOME_PYQT_Module::init( CAM_Application* app ) if ( !myModule ) return; // Error + // this module is being activated now! myInitModule = this; // then call Python module's initialize() method @@ -732,22 +816,23 @@ void SALOME_PYQT_Module::init( CAM_Application* app ) PyLockWrapper aLock = myInterp->GetLockWrapper(); // ... (the Python module is already imported) // ... finally call Python module's initialize() method - if(PyObject_HasAttrString(myModule , "initialize")){ + if ( PyObject_HasAttrString( myModule , "initialize" ) ) { PyObjWrapper res( PyObject_CallMethod( myModule, "initialize", "" ) ); - if( !res ) { + if ( !res ) { PyErr_Print(); } } - // get the windows list from the Python module by calling windows() method + // get required dockable windows list from the Python module + // by calling windows() method // ... first put default values - myWindowsMap.insert( SalomeApp_Application::WT_ObjectBrowser, Qt::DockLeft ); - myWindowsMap.insert( SalomeApp_Application::WT_PyConsole, Qt::DockBottom ); - myWindowsMap.insert( SalomeApp_Application::WT_LogWindow, Qt::DockBottom ); + myWindowsMap.insert( SalomeApp_Application::WT_ObjectBrowser, Qt::LeftDockWidgetArea ); + myWindowsMap.insert( SalomeApp_Application::WT_PyConsole, Qt::BottomDockWidgetArea ); + myWindowsMap.insert( SalomeApp_Application::WT_LogWindow, Qt::BottomDockWidgetArea ); - if(PyObject_HasAttrString(myModule , "windows")){ + if ( PyObject_HasAttrString( myModule , "windows" ) ) { PyObjWrapper res1( PyObject_CallMethod( myModule, "windows", "" ) ); - if( !res1 ) { + if ( !res1 ) { PyErr_Print(); } else { @@ -769,10 +854,12 @@ void SALOME_PYQT_Module::init( CAM_Application* app ) } } } - // get the windows list from the Python module by calling views() method - if(PyObject_HasAttrString(myModule , "views")){ + + // get compatible view windows types from the Python module + // by calling views() method + if ( PyObject_HasAttrString( myModule , "views" ) ) { PyObjWrapper res2( PyObject_CallMethod( myModule, "views", "" ) ); - if( !res2 ) { + if ( !res2 ) { PyErr_Print(); } else { @@ -793,17 +880,24 @@ void SALOME_PYQT_Module::init( CAM_Application* app ) } } } + // module is already activated! myInitModule = 0; } /*! - * Performs internal activation: - * - initializes/gets the Python interpreter (one per study) - * - imports the Python GUI module - * - calls Python module's activate() method (for new modules) - */ + \brief Internal activation: + + Performs the following actions: + - initialize or get the Python interpreter (one per study) + - import the Python GUI module + - call Python module's activate() method + + \param theStudy parent study object +*/ void SALOME_PYQT_Module::activate( SUIT_Study* theStudy ) { + FuncMsg fmsg( "SALOME_PYQT_Module::activate()" ); + // get study Id SalomeApp_Study* aStudy = dynamic_cast( theStudy ); int aStudyId = aStudy ? aStudy->studyDS()->StudyId() : 0; @@ -822,28 +916,35 @@ void SALOME_PYQT_Module::activate( SUIT_Study* theStudy ) PyLockWrapper aLock = myInterp->GetLockWrapper(); // call Python module's activate() method (for the new modules) - if(PyObject_HasAttrString(myModule , "activate")){ + if ( PyObject_HasAttrString( myModule , "activate" ) ) { PyObject* res1 = PyObject_CallMethod( myModule, "activate", "" ); if ( !res1 || !PyBool_Check( res1 ) ) { PyErr_Print(); - //= true: for support of old modules + // always true for old modules (no return value) myLastActivateStatus = true; } else { - //detect return status + // detect return status myLastActivateStatus = PyObject_IsTrue( res1 ); } } } /*! - * Performs additional customization after module is activated: - * - gets the Python interpreter (one per study) - * - imports the Python GUI module - * - calls Python module's setSettings() method (obsolete function, used for compatibility with old code) - */ -void SALOME_PYQT_Module::customize ( SUIT_Study* theStudy ) + \brief Additional customization after module is activated: + + Performs the following actions: + - get the Python interpreter (one per study) + - import the Python GUI module + - call Python module's setSettings() method (obsolete function, + used for compatibility with old code) + + \param theStudy parent study object +*/ +void SALOME_PYQT_Module::customize( SUIT_Study* theStudy ) { + FuncMsg fmsg( "SALOME_PYQT_Module::customize()" ); + // get study Id SalomeApp_Study* aStudy = dynamic_cast( theStudy ); int aStudyId = aStudy ? aStudy->studyDS()->StudyId() : 0; @@ -858,38 +959,44 @@ void SALOME_PYQT_Module::customize ( SUIT_Study* theStudy ) if ( !myModule ) return; // Error - if ( IsCallOldMethods ) { // __CALL_OLD_METHODS__ + if ( IsCallOldMethods ) { // call Python module's setWorkspace() method setWorkSpace(); - } //__CALL_OLD_METHODS__ + } // get python lock PyLockWrapper aLock = myInterp->GetLockWrapper(); - if ( IsCallOldMethods ) { //__CALL_OLD_METHODS__ + if ( IsCallOldMethods ) { // call Python module's setSettings() method (obsolete) - if(PyObject_HasAttrString(myModule , "setSettings")){ + if ( PyObject_HasAttrString( myModule , "setSettings" ) ) { PyObjWrapper res( PyObject_CallMethod( myModule, "setSettings", "" ) ); if( !res ) { PyErr_Print(); } } - } //__CALL_OLD_METHODS__ + } } /*! - * Performs internal deactivation: - * - calls Python module's deactivate() method - */ + \brief Internal deactivation: + + Performs the following actions: + - call Python module's deactivate() method + + \param theStudy parent study object +*/ void SALOME_PYQT_Module::deactivate( SUIT_Study* theStudy ) { + FuncMsg fmsg( "SALOME_PYQT_Module::deactivate()" ); + // check if the subinterpreter is initialized and Python module is imported if ( !myInterp || !myModule ) { // Error! Python subinterpreter should be initialized and module should be imported first! return; } // then call Python module's deactivate() method - if(PyObject_HasAttrString(myModule , "deactivate")){ + if ( PyObject_HasAttrString( myModule , "deactivate" ) ) { PyObjWrapper res( PyObject_CallMethod( myModule, "deactivate", "" ) ); if( !res ) { PyErr_Print(); @@ -898,13 +1005,20 @@ void SALOME_PYQT_Module::deactivate( SUIT_Study* theStudy ) } /*! - * Called when active the study is actived (user brings its desktop to top) - * - initializes/gets the Python interpreter (one per study) - * - imports the Python GUI module - * - calls Python module's activeStudyChanged() method - */ + \brief Perform internal actions when active study is changed. + + Called when active the study is actived (user brings its + desktop to top): + - initialize or get the Python interpreter (one per study) + - import the Python GUI module + - call Python module's activeStudyChanged() method + + \param theStudy study being activated +*/ void SALOME_PYQT_Module::studyChanged( SUIT_Study* theStudy ) { + FuncMsg fmsg( "SALOME_PYQT_Module::studyChanged()" ); + // get study Id SalomeApp_Study* aStudy = dynamic_cast( theStudy ); int aStudyId = aStudy ? aStudy->studyDS()->StudyId() : 0; @@ -919,16 +1033,16 @@ void SALOME_PYQT_Module::studyChanged( SUIT_Study* theStudy ) if ( !myModule ) return; // Error - if ( IsCallOldMethods ) { // __CALL_OLD_METHODS__ + if ( IsCallOldMethods ) { // call Python module's setWorkspace() method setWorkSpace(); - } //__CALL_OLD_METHODS__ + } // get python lock PyLockWrapper aLock = myInterp->GetLockWrapper(); // call Python module's activeStudyChanged() method - if(PyObject_HasAttrString(myModule , "activeStudyChanged")){ + if ( PyObject_HasAttrString( myModule , "activeStudyChanged" ) ) { PyObjWrapper res( PyObject_CallMethod( myModule, "activeStudyChanged", "i", aStudyId ) ); if( !res ) { PyErr_Print(); @@ -937,43 +1051,61 @@ void SALOME_PYQT_Module::studyChanged( SUIT_Study* theStudy ) } /*! - * Get module engine, returns nil var if engine is not found in LifeCycleCORBA - */ + \brief Get module engine. + + Returns nil var if engine is not found in LifeCycleCORBA. + + \return module's engine reference +*/ Engines::Component_var SALOME_PYQT_Module::getEngine() const { + FuncMsg fmsg( "SALOME_PYQT_Module::getEngine()" ); + Engines::Component_var comp; - // temporary solution try { - comp = getApp()->lcc()->FindOrLoad_Component( "FactoryServerPy", name( "" ) ); + comp = getApp()->lcc()->FindOrLoad_Component( "FactoryServerPy", name().toLatin1() ); } - catch (CORBA::Exception&) { + catch ( CORBA::Exception& ) { } return comp; } /*! - * Get module engine IOR, returns empty string if engine is not found in LifeCycleCORBA - */ + \birief Get module engine IOR. + + Returns empty string if engine is not found in LifeCycleCORBA. + + \return module's engine IOR +*/ QString SALOME_PYQT_Module::engineIOR() const { - QString anIOR = QString::null; + FuncMsg fmsg( "SALOME_PYQT_Module::engineIOR()" ); + + QString anIOR = ""; if ( !CORBA::is_nil( getEngine() ) ) - return QString( getApp()->orb()->object_to_string( getEngine() ) ); - return QString( "" ); + anIOR = getApp()->orb()->object_to_string( getEngine() ); + return anIOR; } /*! - * Processes context popup menu request - * - calls Python module's definePopup(...) method (obsolete function, used for compatibility with old code) - * to define the popup menu context - * - parses XML resourses file (if exists) and fills the popup menu with the items) - * - calls Python module's customPopup(...) method (obsolete function, used for compatibility with old code) - * to allow module to customize the popup menu - * - for new modules calls createPopupMenu() function to allow the modules to build the popup menu - * by using insertItem(...) Qt functions. - */ -void SALOME_PYQT_Module::contextMenu( const QString& theContext, QPopupMenu* thePopupMenu ) + \brief Process (internally) context popup menu request. + + Performs the following actions: + - calls Python module's definePopup(...) method (obsolete function, + used for compatibility with old code) to define the popup menu context + - parses XML resourses file (if exists) and fills the popup menu with the items) + - calls Python module's customPopup(...) method (obsolete function, + used for compatibility with old code) to allow module to customize the popup menu + - for new modules calls createPopupMenu() function to allow the + modules to build the popup menu by using insertItem(...) Qt functions. + + \param theContext popup menu context + \param thePopupMenu popup menu +*/ +void SALOME_PYQT_Module::contextMenu( const QString& theContext, QMenu* thePopupMenu ) { + FuncMsg fmsg( "SALOME_PYQT_Module::contextMenu()" ); + // Python interpreter should be initialized and Python module should be // import first if ( !myInterp || !myModule ) @@ -981,15 +1113,15 @@ void SALOME_PYQT_Module::contextMenu( const QString& theContext, QPopupMenu* the QString aContext( "" ), aObject( "" ), aParent( theContext ); - if ( IsCallOldMethods && PyObject_HasAttrString(myModule , "definePopup") ) { //__CALL_OLD_METHODS__ + if ( IsCallOldMethods && PyObject_HasAttrString( myModule , "definePopup" ) ) { // call definePopup() Python module's function // this is obsolete function, used only for compatibility reasons - PyObjWrapper res(PyObject_CallMethod( myModule, - "definePopup", - "sss", - aContext.latin1(), - aObject.latin1(), - aParent.latin1() ) ); + PyObjWrapper res( PyObject_CallMethod( myModule, + "definePopup", + "sss", + aContext.toLatin1().constData(), + aObject.toLatin1().constData(), + aParent.toLatin1().constData() ) ); if( !res ) { PyErr_Print(); } @@ -1002,55 +1134,61 @@ void SALOME_PYQT_Module::contextMenu( const QString& theContext, QPopupMenu* the aParent = pa; } } - } //__CALL_OLD_METHODS__ + } // if ( IsCallOldMethods ... ) // first try to create menu via XML parser: // we create popup menus without help of QtxPopupMgr if ( myXmlHandler ) myXmlHandler->createPopup( thePopupMenu, aContext, aParent, aObject ); - PyObjWrapper sipPopup( sipBuildResult( 0, "M", thePopupMenu, sipClass_QPopupMenu ) ); + PyObjWrapper sipPopup( sipBuildResult( 0, "M", thePopupMenu, sipClass_QMenu ) ); // then call Python module's createPopupMenu() method (for new modules) - if ( PyObject_HasAttrString(myModule , "createPopupMenu") ) { + if ( PyObject_HasAttrString( myModule , "createPopupMenu" ) ) { PyObjWrapper res1( PyObject_CallMethod( myModule, - "createPopupMenu", - "Os", - sipPopup.get(), - aContext.latin1() ) ); + "createPopupMenu", + "Os", + sipPopup.get(), + aContext.toLatin1().constData() ) ); if( !res1 ) { PyErr_Print(); } } - if ( IsCallOldMethods && PyObject_HasAttrString(myModule , "customPopup") ) { //__CALL_OLD_METHODS__ + if ( IsCallOldMethods && PyObject_HasAttrString( myModule , "customPopup" ) ) { // call customPopup() Python module's function // this is obsolete function, used only for compatibility reasons PyObjWrapper res2( PyObject_CallMethod( myModule, "customPopup", "Osss", sipPopup.get(), - aContext.latin1(), - aObject.latin1(), - aParent.latin1() ) ); + aContext.toLatin1().constData(), + aObject.toLatin1().constData(), + aParent.toLatin1().constData() ) ); if( !res2 ) { PyErr_Print(); } - } //__CALL_OLD_METHODS__ + } } /*! - * Processes GUI event - * - calls Python module's OnGUIEvent() method - */ + \brief Internal GUI event handling. + + Performs the following actions: + - calls Python module's OnGUIEvent() method + + \param theId GUI action ID +*/ void SALOME_PYQT_Module::guiEvent( const int theId ) { + FuncMsg fmsg( "SALOME_PYQT_Module::guiEvent()" ); + // Python interpreter should be initialized and Python module should be // import first if ( !myInterp || !myModule ) return; - if ( PyObject_HasAttrString(myModule , "OnGUIEvent") ) { + if ( PyObject_HasAttrString( myModule , "OnGUIEvent" ) ) { PyObjWrapper res( PyObject_CallMethod( myModule, "OnGUIEvent", "i", theId ) ); if( !res ) { PyErr_Print(); @@ -1059,30 +1197,15 @@ void SALOME_PYQT_Module::guiEvent( const int theId ) } /*! - * Menu highlight processing - * - calls Python module's menuActivated(int,int) method - */ -void SALOME_PYQT_Module::menuHighlight( const int menu, const int submenu ) -{ - // Python interpreter should be initialized and Python module should be - // import first - if ( !myInterp || !myModule ) - return; - - if ( PyObject_HasAttrString(myModule , "menuHighlight") ) { - PyObjWrapper res( PyObject_CallMethod( myModule, "menuHighlight", "ii", menu, submenu ) ); - if( !res ) { - PyErr_Print(); - } - } -} + \brief Initialize (internally) preferences for the module. -/*! - * Initialises preferences for the module - * - calls Python module's createPreferences() method - */ + Performs the following actions: + - calls Python module's createPreferences() method +*/ void SALOME_PYQT_Module::initPreferences() { + FuncMsg fmsg( "SALOME_PYQT_Module::initPreferences()" ); + // Python interpreter should be initialized and Python module should be // import first if ( !myInterp || !myModule ) @@ -1092,7 +1215,7 @@ void SALOME_PYQT_Module::initPreferences() // might be called during the module intialization process myInitModule = this; - if ( PyObject_HasAttrString(myModule , "createPreferences") ) { + if ( PyObject_HasAttrString( myModule , "createPreferences" ) ) { PyObjWrapper res( PyObject_CallMethod( myModule, "createPreferences", "" ) ); if( !res ) { PyErr_Print(); @@ -1103,10 +1226,13 @@ void SALOME_PYQT_Module::initPreferences() } /*! - * Initialises python subinterpreter (one per study) - */ + \brief Initialize python subinterpreter (one per study). + \param theStudyId study ID +*/ void SALOME_PYQT_Module::initInterp( int theStudyId ) { + FuncMsg fmsg( "SALOME_PYQT_Module::initInterp()" ); + // check study Id if ( !theStudyId ) { // Error! Study Id must not be 0! @@ -1114,7 +1240,7 @@ void SALOME_PYQT_Module::initInterp( int theStudyId ) return; } // try to find the subinterpreter - if( myInterpMap.find( theStudyId ) != myInterpMap.end() ) { + if( myInterpMap.contains( theStudyId ) ) { // found! myInterp = myInterpMap[ theStudyId ]; return; @@ -1150,11 +1276,14 @@ void SALOME_PYQT_Module::initInterp( int theStudyId ) } /*! - * Imports Python GUI module and remember the reference to the module - * !!! initInterp() should be called first!!! - */ + \brief Import Python GUI module and remember the reference to the module. + + Attention! initInterp() should be called first!!! +*/ void SALOME_PYQT_Module::importModule() { + FuncMsg fmsg( "SALOME_PYQT_Module::importModule()" ); + // check if the subinterpreter is initialized if ( !myInterp ) { // Error! Python subinterpreter should be initialized first! @@ -1165,8 +1294,8 @@ void SALOME_PYQT_Module::importModule() // ... first get python lock PyLockWrapper aLock = myInterp->GetLockWrapper(); // ... then import a module - QString aMod = QString( name("") ) + "GUI"; - myModule = PyImport_ImportModule( (char*)( aMod.latin1() ) ); + QString aMod = name() + "GUI"; + myModule = PyImport_ImportModule( aMod.toLatin1().data() ); if( !myModule ) { // Error! PyErr_Print(); @@ -1175,12 +1304,17 @@ void SALOME_PYQT_Module::importModule() } /*! - * Calls .setWorkSpace() method with PyQt QWidget object to use with - * interpreter. - * !!! initInterp() and importModule() should be called first!!! - */ + \brief Set study workspace to the Python module. + + Calls setWorkSpace() method of the Pythohn module with + PyQt QWidget object to use with interpreter. + + Attention! initInterp() and importModule() should be called first!!! +*/ void SALOME_PYQT_Module::setWorkSpace() { + FuncMsg fmsg( "SALOME_PYQT_Module::setWorkSpace()" ); + // check if the subinterpreter is initialized and Python module is imported if ( !myInterp || !myModule ) { // Error! Python subinterpreter should be initialized and module should be imported first! @@ -1199,7 +1333,7 @@ void SALOME_PYQT_Module::setWorkSpace() return; } - if ( IsCallOldMethods ) { //__CALL_OLD_METHODS__ + if ( IsCallOldMethods ) { // ... then get workspace object QWidget* aWorkspace = 0; if ( getApp()->desktop()->inherits( "STD_MDIDesktop" ) ) { @@ -1214,32 +1348,39 @@ void SALOME_PYQT_Module::setWorkSpace() } PyObjWrapper pyws( sipBuildResult( 0, "M", aWorkspace, sipClass_QWidget ) ); // ... and finally call Python module's setWorkspace() method (obsolete) - if ( PyObject_HasAttrString(myModule , "setWorkSpace") ) { + if ( PyObject_HasAttrString( myModule , "setWorkSpace" ) ) { PyObjWrapper res( PyObject_CallMethod( myModule, "setWorkSpace", "O", pyws.get() ) ); if( !res ) { PyErr_Print(); } } - } //__CALL_OLD_METHODS__ + } } /*! - * Preference changing callback function - * - calls Python module's preferenceChanged(string,string,string) method - */ + \brief Preference changing callback function (internal). + + Performs the following actions: + - call Python module's preferenceChanged() method + + \param section setting section name + \param setting setting name +*/ void SALOME_PYQT_Module::prefChanged( const QString& section, const QString& setting ) { + FuncMsg fmsg( "SALOME_PYQT_Module::prefChanged()" ); + // Python interpreter should be initialized and Python module should be // import first if ( !myInterp || !myModule ) return; - if ( PyObject_HasAttrString(myModule , "preferenceChanged") ) { + if ( PyObject_HasAttrString( myModule , "preferenceChanged" ) ) { PyObjWrapper res( PyObject_CallMethod( myModule, "preferenceChanged", "ss", - section.latin1(), - setting.latin1() ) ); + section.toLatin1().constData(), + setting.toLatin1().constData() ) ); if( !res ) { PyErr_Print(); } @@ -1247,378 +1388,254 @@ void SALOME_PYQT_Module::prefChanged( const QString& section, const QString& set } /*! - * Returns default menu group - */ + \brief Get default menu group identifier + \return menu group ID (40 by default) +*/ int SALOME_PYQT_Module::defaultMenuGroup() { - return __DEFAULT_GROUP__; + return DEFAULT_GROUP; } -/*! - * The next methods call the parent implementation. - * This is done to open protected methods from CAM_Module class. - * Also these methods are used to register created from outside menus - * in order to enable dynamic menus handling. - */ - +// +// The next methods call the parent implementation. +// This is done to open protected methods from CAM_Module class. +// -/*! Create tool bar with name \a name, if it was't created before. - * \retval -1 - if tool manager was't be created. - */ +/*! + \brief Create toolbar with specified \a name. + \param name toolbar name + \return toolbar ID or -1 if toolbar creation is failed +*/ int SALOME_PYQT_Module::createTool( const QString& name ) { return SalomeApp_Module::createTool( name ); } -/*! Create tool. - * Insert QAction with id \a id from action map(myActionMap) to tool manager. - *\param id - integer - *\param tBar - integer - *\param idx - integer - *\retval integer id of new action in tool manager. - *\retval Return -1 if something wrong. - */ + +/*! + \brief Insert action with specified \a id to the toolbar. + \param id action ID + \param tBar toolbar ID + \param idx required index in the toolbar + \return action ID or -1 if action could not be added +*/ int SALOME_PYQT_Module::createTool( const int id, const int tBar, const int idx ) { return SalomeApp_Module::createTool( id, tBar, idx ); } -/*! Create tool. - * Insert QAction with id \a id from action map(myActionMap) to tool manager. - *\param id - integer - *\param tBar - QString& - *\param idx - integer - *\retval integer id of new action in tool manager. - *\retval Return -1 if something wrong. - */ + +/*! + \brief Insert action with specified \a id to the toolbar. + \param id action ID + \param tBar toolbar name + \param idx required index in the toolbar + \return action ID or -1 if action could not be added +*/ int SALOME_PYQT_Module::createTool( const int id, const QString& tBar, const int idx ) { return SalomeApp_Module::createTool( id, tBar, idx ); } -/*! Create tool. Register action \a a with id \a id. - * Insert QAction to tool manager. - *\param a - QAction - *\param tBar - integer - *\param id - integer - *\param idx - integer - *\retval integer id of new action in tool manager. - *\retval Return -1 if something wrong. - */ + +/*! + \brief Insert action to the toolbar. + \param a action + \param tBar toolbar ID + \param id required action ID + \param idx required index in the toolbar + \return action ID or -1 if action could not be added +*/ int SALOME_PYQT_Module::createTool( QAction* a, const int tBar, const int id, const int idx ) { return SalomeApp_Module::createTool( a, tBar, id, idx ); } -/*! Create tool. Register action \a a with id \a id. - * Insert QAction to tool manager. - *\param a - QAction - *\param tBar - QString& - *\param id - integer - *\param idx - integer - *\retval integer id of new action in tool manager. - *\retval Return -1 if something wrong. - */ + +/*! + \brief Insert action to the toolbar. + \param a action + \param tBar toolbar name + \param id required action ID + \param idx required index in the toolbar + \return action ID or -1 if action could not be added +*/ int SALOME_PYQT_Module::createTool( QAction* a, const QString& tBar, const int id, const int idx ) { return SalomeApp_Module::createTool( a, tBar, id, idx ); } -int SALOME_PYQT_Module::createMenu( const QString& subMenu, const int menu, const int id, const int group, const int idx, const bool constantMenu ) +/*! + \brief Create main menu. + \param subMenu menu name + \param menu parent menu ID + \param id required menu ID + \param group menu group ID + \param idx required index in the menu + \return menu ID or -1 if menu could not be added +*/ +int SALOME_PYQT_Module::createMenu( const QString& subMenu, const int menu, const int id, const int group, const int idx ) { - bool exists = hasMenu( subMenu, menu ); - int regId = SalomeApp_Module::createMenu( subMenu, menu, id, group, idx, true ); - if ( !exists ) - registerMenu( regId, menu, constantMenu ); - return regId; + return SalomeApp_Module::createMenu( subMenu, menu, id, group, idx ); } -int SALOME_PYQT_Module::createMenu( const QString& subMenu, const QString& menu, const int id, const int group, const int idx, const bool constantMenu ) +/*! + \brief Create main menu. + \param subMenu menu name + \param menu parent menu name (list of menu names separated by "|") + \param id required menu ID + \param group menu group ID + \param idx required index in the menu + \return menu ID or -1 if menu could not be added +*/ +int SALOME_PYQT_Module::createMenu( const QString& subMenu, const QString& menu, const int id, const int group, const int idx ) { - QStringList menus = QStringList::split( "|", menu, false ); - int pid = -1; - for (int i = 0; i < menus.count(); i++ ) { - pid = createMenu( menus[i], pid, -1, -1, -1, constantMenu ); - if ( pid == -1 ) break; - } - if ( pid != -1 ) - pid = createMenu( subMenu, pid, id, group, idx, constantMenu ); - return pid; + return SalomeApp_Module::createMenu( subMenu, menu, id, group, idx ); } -int SALOME_PYQT_Module::createMenu( const int id, const int menu, const int group, const int idx, const bool constantMenu ) +/*! + \brief Insert action to the main menu. + \param id action ID + \param menu parent menu ID + \param group menu group ID + \param idx required index in the menu + \return action ID or -1 if action could not be added +*/ +int SALOME_PYQT_Module::createMenu( const int id, const int menu, const int group, const int idx ) { - int regId = SalomeApp_Module::createMenu( id, menu, group, idx ); - if ( regId != -1 ) - registerMenu( regId, menu, constantMenu ); - return regId; + return SalomeApp_Module::createMenu( id, menu, group, idx ); } -int SALOME_PYQT_Module::createMenu( const int id, const QString& menu, const int group, const int idx, const bool constantMenu ) +/*! + \brief Insert action to the main menu. + \param id action ID + \param menu parent menu name (list of menu names separated by "|") + \param group menu group ID + \param idx required index in the menu + \return action ID or -1 if action could not be added +*/ +int SALOME_PYQT_Module::createMenu( const int id, const QString& menu, const int group, const int idx ) { - QStringList menus = QStringList::split( "|", menu, false ); - int pid = -1; - for (int i = 0; i < menus.count(); i++ ) { - pid = createMenu( menus[i], pid, -1, -1, -1, constantMenu ); - if ( pid == -1 ) break; - } - if ( pid != -1 ) - pid = createMenu( id, pid, group, idx, constantMenu ); - return pid; + return SalomeApp_Module::createMenu( id, menu, group, idx ); } -int SALOME_PYQT_Module::createMenu( QAction* a, const int menu, const int id, const int group, const int idx, const bool constantMenu ) +/*! + \brief Insert action to the main menu. + \param a action + \param menu parent menu ID + \param group menu group ID + \param idx required index in the menu + \return action ID or -1 if action could not be added +*/ +int SALOME_PYQT_Module::createMenu( QAction* a, const int menu, const int id, const int group, const int idx ) { - int regId = SalomeApp_Module::createMenu( a, menu, id, group, idx ); - if ( regId != -1 ) - registerMenu( regId, menu, constantMenu ); - return regId; + return SalomeApp_Module::createMenu( a, menu, id, group, idx ); } -int SALOME_PYQT_Module::createMenu( QAction* a, const QString& menu, const int id, const int group, const int idx, const bool constantMenu ) +/*! + \brief Insert action to the main menu. + \param a action + \param menu parent menu name (list of menu names separated by "|") + \param group menu group ID + \param idx required index in the menu + \return action ID or -1 if action could not be added +*/ +int SALOME_PYQT_Module::createMenu( QAction* a, const QString& menu, const int id, const int group, const int idx ) { - QStringList menus = QStringList::split( "|", menu, false ); - int pid = -1; - for (int i = 0; i < menus.count(); i++ ) { - pid = createMenu( menus[i], pid, -1, -1, -1, constantMenu ); - if ( pid == -1 ) break; - } - if ( pid != -1 ) - pid = createMenu( a, pid, id, group, idx, constantMenu ); - return pid; + return SalomeApp_Module::createMenu( a, menu, id, group, idx ); } -QAction* SALOME_PYQT_Module::createSeparator() +/*! + \brief Create separator action which can be used in the menu or toolbar. + \return new separator action +*/ +QAction* SALOME_PYQT_Module::separator() { return SalomeApp_Module::separator(); } +/*! + \brief Get action by specified \a id. + \return action or 0 if it is not found +*/ QAction* SALOME_PYQT_Module::action( const int id ) const { return SalomeApp_Module::action( id ); } +/*! + \brief Get action identifier. + \return action ID or -1 if action is not registered +*/ int SALOME_PYQT_Module::actionId( const QAction* a ) const { return SalomeApp_Module::actionId( a ); } +/*! + \brief Create new action. + + If the action with specified identifier already registered + it is not created, but its attributes are only modified. + + \param id action ID + \param text tooltip text + \param icon icon + \param menu menu text + \param tip status tip + \param key keyboard shortcut + \param toggle \c true for checkable action + \return created action +*/ QAction* SALOME_PYQT_Module::createAction( const int id, const QString& text, const QString& icon, const QString& menu, const QString& tip, const int key, - const bool toggle ) + const bool toggle, QObject* parent ) { - QIconSet anIcon = loadIcon( icon ); + QIcon anIcon = loadIcon( icon ); QAction* a = action( id ); if ( a ) { - if ( a->text().isEmpty() && !text.isEmpty() ) a->setText( text ); - if ( a->menuText().isEmpty() && !menu.isEmpty() ) a->setMenuText( menu ); - if ( a->iconSet().isNull() && !anIcon.isNull() ) a->setIconSet( anIcon ); - if ( a->statusTip().isEmpty() && !tip.isNull() ) a->setStatusTip( tip ); - if ( a->accel().isEmpty() && key ) a->setAccel( key ); - if ( a->isToggleAction() != toggle ) a->setToggleAction( toggle ); - disconnect( a, SIGNAL( activated() ), this, SLOT( onGUIEvent() ) ); - connect( a, SIGNAL( activated() ), this, SLOT( onGUIEvent() ) ); + if ( a->toolTip().isEmpty() && !text.isEmpty() ) a->setToolTip( text ); + if ( a->text().isEmpty() && !menu.isEmpty() ) a->setText( menu ); + if ( a->icon().isNull() && !anIcon.isNull() ) a->setIcon( anIcon ); + if ( a->statusTip().isEmpty() && !tip.isEmpty() ) a->setStatusTip( tip ); + if ( a->shortcut().isEmpty() && key ) a->setShortcut( key ); + if ( a->isCheckable() != toggle ) a->setCheckable( toggle ); + disconnect( a, SIGNAL( triggered( bool ) ), this, SLOT( onGUIEvent() ) ); + connect( a, SIGNAL( triggered( bool ) ), this, SLOT( onGUIEvent() ) ); } else { - a = SalomeApp_Module::createAction( id, text, anIcon, menu, tip, key, getApp()->desktop(), toggle, this, SLOT( onGUIEvent() ) ); + a = SalomeApp_Module::createAction( id, + text, + anIcon, + menu, + tip, + key, + parent ? parent : this, + toggle, + this, + SLOT( onGUIEvent() ) ); } return a; } /*! - * Load icon from resource file - */ -QIconSet SALOME_PYQT_Module::loadIcon( const QString& fileName ) + \brief Load icon from resource file. + \param fileName icon file name + \return icon (null icon if loading failed) +*/ +QIcon SALOME_PYQT_Module::loadIcon( const QString& fileName ) { - QIconSet anIcon; + QIcon anIcon; if ( !fileName.isEmpty() ) { - QPixmap pixmap = getApp()->resourceMgr()->loadPixmap( name(""), tr( fileName ) ); + QPixmap pixmap = getApp()->resourceMgr()->loadPixmap( name(), tr( fileName.toLatin1() ) ); if ( !pixmap.isNull() ) - anIcon = QIconSet( pixmap ); + anIcon = QIcon( pixmap ); } return anIcon; } /*! - * Returns TRUE if menu already exists - */ -bool SALOME_PYQT_Module::hasMenu( const QString& subMenu, const int menu ) -{ - return menuMgr() && menuMgr()->containsMenu( subMenu, menu ); -} - -/*! - * Register the menu - */ -void SALOME_PYQT_Module::registerMenu( const int id, const int menu, const bool constantMenu ) -{ - QAction* a = action( id ); - QAction* s = separator(); - if ( a && a == s ) - return; - if ( !registered( id, menu ) ) - myMenus[menu].append( MenuId( id, constantMenu ) ); -} - -/*! - * Unregister the menu - */ -void SALOME_PYQT_Module::unregisterMenu( const int id, const int menu ) -{ - if ( myMenus.find( menu ) != myMenus.end() ) { - MenuIdList::iterator lit; - for ( lit = myMenus[menu].begin(); lit != myMenus[menu].end(); ++lit ) { - if ( (*lit).id == id ) { - myMenus[menu].remove( lit ); - return; - } - } - } -} - -/*! - * Returns TRUE if the menu is registered - */ -bool SALOME_PYQT_Module::registered( const int id, const int menu ) -{ - MenuMap::iterator mit; - for ( mit = myMenus.begin(); mit != myMenus.end(); ++mit ) { - MenuIdList::iterator lit; - for ( lit = mit.data().begin(); lit != mit.data().end(); ++lit ) { - if ( (*lit).id == id && ( menu == 0 || mit.key() == menu ) ) - return true; - } - } - return false; -} - -/*! - * Returns TRUE if the menu is constant (not removed by clearMenu()). - * This concerns the menus which are created from XML files. - */ -bool SALOME_PYQT_Module::isConstantMenu( const int id, const int menu ) -{ - if ( myMenus.find( menu ) != myMenus.end() ) { - MenuIdList& l = myMenus[ menu ]; - MenuIdList::iterator lit; - for ( lit = l.begin(); lit != l.end(); ++lit ) { - if ( (*lit).id == id && (*lit).constantMenu ) - return true; - } - } - return false; -} - -/*! - * Displays/hides the module's menus. - */ -void SALOME_PYQT_Module::setMenuShown( const bool show ) -{ - QtxActionMenuMgr* mMgr = menuMgr(); - if ( !mMgr ) - return; - - bool upd = mMgr->isUpdatesEnabled(); - mMgr->setUpdatesEnabled( false ); - - SalomeApp_Module::setMenuShown( show ); - - for ( MenuMap::iterator mit = myMenus.begin(); mit != myMenus.end(); ++mit ) { - MenuIdList::iterator lit; - for ( lit = mit.data().begin(); lit != mit.data().end(); ++lit ) - if ( !action( (*lit).id ) ) - mMgr->setShown( (*lit).id, show ); - } - - mMgr->setUpdatesEnabled( upd ); - if ( upd ) - mMgr->update(); -} - -/*! - * Displays/hides the module's toolbars. - */ -void SALOME_PYQT_Module::setToolShown( const bool show ) -{ - SalomeApp_Module::setToolShown( show ); -} - -/*! - * Clears the given menu. - * If = 0 : clear all items in the menu - * If = 0 : clear all menus recursively starting from top-level. - * If = 0 : also unregister all removed actions (not delete!). - */ -bool SALOME_PYQT_Module::clearMenu( const int id, const int menu, const bool removeActions ) -{ - QAction* a = action( id ); - QAction* s = separator(); - typedef QValueList IntList; - if ( a && a != s ) { - // action - IntList menus; - if ( menu != 0 ) { - if ( registered( id, menu ) ) menus.append( menu ); - } - else { - MenuMap::iterator mit; - for ( mit = myMenus.begin(); mit != myMenus.end(); ++mit ) - if ( registered( id, mit.key() ) ) menus.append( mit.key() ); - } - for ( int i = 0; i < menus.count(); i++ ) { - if ( !isConstantMenu( id, menus[i] ) ) { - menuMgr()->remove( menuMgr()->actionId( a ), menus[ i ] ); - unregisterMenu( id, menus[i] ); - } - } - if ( !registered( id ) && removeActions ) - unregisterAction( id ); - } - else { - // menu - if ( id == 0 ) { - if ( menu == 0 ) { - // clear all menus recursively starting from top-level (main menu) - IntList l = myMenus.keys(); - IntList::iterator lit; - for ( lit = l.begin(); lit != l.end(); ++lit ) - clearMenu( 0, *lit, removeActions ); - } - else { - if ( myMenus.find( menu ) != myMenus.end() ) { - // remove all items in the parent menu - IntList l; - MenuIdList::iterator lit; - for ( lit = myMenus[menu].begin(); lit != myMenus[menu].end(); ++lit ) - l.append( (*lit).id ); - for ( int i = 0; i < l.count(); i++ ) - clearMenu( l[i], menu, removeActions ); - if ( myMenus[menu].empty() ) - myMenus.remove( menu ); - } - } - } - else { - MenuMap::iterator mit; - for ( mit = myMenus.begin(); mit != myMenus.end(); ++mit ) { - MenuIdList::iterator lit; - for ( lit = mit.data().begin(); lit != mit.data().end(); ++lit ) { - if ( (*lit).id == id && ( menu == 0 || mit.key() == menu ) ) { - clearMenu( 0, id, removeActions ); // first remove all sub-menus - if ( !isConstantMenu( id, mit.key() ) ) { - menuMgr()->remove( id, mit.key() ); - mit.data().remove( lit ); - break; - } - } - } - } - } - } - return false; -} - -/*! - * The next methods call the parent implementation. - * This is done to open protected methods from LightApp_Module class. - */ - + \brief Add global application preference (for example, + application specific section). + \param label preference name + \return preference ID +*/ int SALOME_PYQT_Module::addGlobalPreference( const QString& label ) { LightApp_Preferences* pref = preferences(); @@ -1628,11 +1645,25 @@ int SALOME_PYQT_Module::addGlobalPreference( const QString& label ) return pref->addPreference( label, -1 ); } +/*! + \brief Add preference. + \param label preference name + \return preference ID +*/ int SALOME_PYQT_Module::addPreference( const QString& label ) { return SalomeApp_Module::addPreference( label ); } +/*! + \brief Add preference. + \param label preference name + \param pId parent preference ID + \param type preference type + \param section resource file section name + \param param resource file setting name + \return preference ID +*/ int SALOME_PYQT_Module::addPreference( const QString& label, const int pId, const int type, const QString& section, @@ -1641,6 +1672,12 @@ int SALOME_PYQT_Module::addPreference( const QString& label, return SalomeApp_Module::addPreference( label, pId, type, section, param ); } +/*! + \brief Get the preference property. + \param id preference ID + \param prop property name + \return property value (invalid QVariant() if property is not found) +*/ QVariant SALOME_PYQT_Module::preferenceProperty( const int id, const QString& prop ) const { @@ -1648,6 +1685,12 @@ QVariant SALOME_PYQT_Module::preferenceProperty( const int id, return v; } +/*! + \brief Set the preference property. + \param id preference ID + \param prop property name + \param var property value +*/ void SALOME_PYQT_Module::setPreferenceProperty( const int id, const QString& prop, const QVariant& var ) @@ -1655,39 +1698,64 @@ void SALOME_PYQT_Module::setPreferenceProperty( const int id, SalomeApp_Module::setPreferenceProperty( id, prop, var ); } -// SALOME_PYQT_XmlHandler class implementation - -// gets an tag name for the dom element [ static ] -// returns an empty string if the element does not have tag name -static QString tagName( const QDomElement& element ) { - return element.tagName().stripWhiteSpace(); +/*! + \brief Get tag name for the DOM element. + \param element DOM element + \return empty string if the element does not have tag name + \internal +*/ +static QString tagName( const QDomElement& element ) +{ + return element.tagName().trimmed(); } -// gets an attribute by it's name for the dom element [ static ] -// returns an empty string if the element does not have such attribute -static QString attribute( const QDomElement& element, const QString& attName ) { - return element.attribute( attName ).stripWhiteSpace(); +/*! + \brief Get DOM element's attribute by its name. + \param element DOM element + \param attName attribute name + \return empty string if the element does not have such attribute + \internal +*/ +static QString attribute( const QDomElement& element, const QString& attName ) +{ + return element.attribute( attName ).trimmed(); } -// checks the given value for the boolean value [ static ] -// returns TRUE if string represents boolean value: -// - "true", "yes" or "1" for true -// - "false", "no" or "0" for false -// second parameter allows to check certain boolean value -// - 1: true -// - 0: false -// - other value is not taken into account -static bool checkBool( const QString& value, const int check = -1 ) { - QString v = value.lower(); - if ( ( v == "true" || v == "yes" || v == "1" ) && ( check != 0 ) ) +/*! + \brief Inspect specified string for the boolean value. + + This function returns \c true if string represents boolean value: + - "true", "yes" or "1" for \c true + - "false", "no" or "0" for \c false + Second parameter allows to specify what boolean value is expected: + - 1: \c true + - 0: \c false + - other value is not taken into account (return represented value) + + \param value inspected string + \param check expected boolean value + \return boolean value represented by the string (\a check is not 1 or 0) + or \c true if value correspond to the specified \a check +*/ +static bool checkBool( const QString& value, const int check = -1 ) +{ + QString v = value.toLower(); + if ( ( v == "true" || v == "yes" || v == "1" ) && ( check != 0 ) ) return true; - if ( ( v == "false" || v == "no" || v == "0" ) && ( check != 1 ) ) + if ( ( v == "false" || v == "no" || v == "0" ) && ( check == 0 ) ) return true; return false; } -// checks the given value for the integer value [ static ] -// returns -1 if item is empty or presents and invalid number +/*! + \brief Inspect specified string for the integer value. + + This function returns returns -1 if item is empty or represents + an invalid number. + \param value inspected string + \param def default value + \param shift shift value (it is added to the integer value to produce shifted result) +*/ static int checkInt( const QString& value, const int def = -1, const int shift = -1 ) { bool bOk; @@ -1699,35 +1767,33 @@ static int checkInt( const QString& value, const int def = -1, const int shift = } /*! - * Constructor - */ -SALOME_PYQT_XmlHandler::SALOME_PYQT_XmlHandler( SALOME_PYQT_Module* module, - const QString& fileName ) - : myModule( module ), - myMenuCreated( false ) + \brief Constructor + \internal + \param module parent module pointer + \param fileName XML file path +*/ +SALOME_PYQT_Module::XmlHandler::XmlHandler( SALOME_PYQT_Module* module, + const QString& fileName ) +: myModule( module ) { - if (fileName.isEmpty() ) + if ( fileName.isEmpty() ) return; QFile aFile( fileName ); - if ( !aFile.open( IO_ReadOnly ) ) + if ( !aFile.open( QIODevice::ReadOnly ) ) return; - if ( !myDoc.setContent( &aFile ) ) { - aFile.close(); - return; - } + myDoc.setContent( &aFile ); aFile.close(); } /*! - * Called by SALOME_PYQT_Module::activate() in order to create actions - * (menus, toolbars, popup menus) - */ -void SALOME_PYQT_XmlHandler::createActions() -{ - // check flag : are menus already created? - if ( myMenuCreated && !IsCallOldMethods ) - return; + \brief Parse XML file and create actions. + \internal + Called by SALOME_PYQT_Module::activate() in order to create actions + (menus, toolbars). +*/ +void SALOME_PYQT_Module::XmlHandler::createActions() +{ // get document element QDomElement aDocElem = myDoc.documentElement(); @@ -1744,45 +1810,20 @@ void SALOME_PYQT_XmlHandler::createActions() QDomNode n = aToolsList.item( i ); createToolBar( n ); } - // set flag : menus are already created - myMenuCreated = true; } /*! - * Called by SALOME_PYQT_Module::deactivate() in order to remove actions - * (menus, toolbars, popup menus) - */ -void SALOME_PYQT_XmlHandler::clearActions() -{ - for ( uint i = 0; i < myMenuItems.count(); i++ ) { - QMenuData* md = dynamic_cast( myModule->getApp()->desktop()->menuBar() ); - QStringList menus = QStringList::split( ":", myMenuItems[ i ] ); - for ( uint j = 0; j < menus.count(); j++) { - int id = menus[ j ].toInt(); - QMenuData* smd; - QMenuItem* mi = md->findItem( id, &smd ); - if ( mi && md == smd ) { - if ( j == menus.count()-1 || !mi->popup() ) { // last item or not popup - md->removeItem( id ); - break; - } - else if ( mi->popup() ) - md = dynamic_cast( mi->popup() ); - } - else - break; - } - } - myMenuItems.clear(); -} - -/*! - * Creates popup menu - */ -void SALOME_PYQT_XmlHandler::createPopup( QPopupMenu* menu, - const QString& context, - const QString& parent, - const QString& object ) + \brief Create popup menu. + \internal + \param menu popup menu + \param context popup menu context + \param context popup menu parent object name + \param context popup menu object name +*/ +void SALOME_PYQT_Module::XmlHandler::createPopup( QMenu* menu, + const QString& context, + const QString& parent, + const QString& object ) { // get document element QDomElement aDocElem = myDoc.documentElement(); @@ -1793,7 +1834,7 @@ void SALOME_PYQT_XmlHandler::createPopup( QPopupMenu* menu, QDomNode n = aPopupList.item( i ); if ( !n.isNull() && n.isElement() ) { QDomElement e = n.toElement(); - QString lab = attribute( e, "label-id" ); + // QString lab = attribute( e, "label-id" ); // not used // QString ctx = attribute( e, "context-id" ); QString prt = attribute( e, "parent-id" ); QString obj = attribute( e, "object-id" ); @@ -1806,16 +1847,17 @@ void SALOME_PYQT_XmlHandler::createPopup( QPopupMenu* menu, } /*! - Create main menu with child actions - */ -void SALOME_PYQT_XmlHandler::createMenu( QDomNode& parentNode, - const int parentMenuId, - QPopupMenu* parentPopup ) + \brief Create main menu item and insert actions to it. + \internal + \param parentNode XML node with menu description + \param parentMenuId parent menu ID (-1 for top-level menu) + \param parentPopup parent popup menu (0 for top-level menu) +*/ +void SALOME_PYQT_Module::XmlHandler::createMenu( QDomNode& parentNode, + const int parentMenuId, + QMenu* parentPopup ) { - if ( !myModule ) - return; - - if ( parentNode.isNull() ) + if ( !myModule || parentNode.isNull() ) return; QDomElement parentElement = parentNode.toElement(); @@ -1826,52 +1868,14 @@ void SALOME_PYQT_XmlHandler::createMenu( QDomNode& parentNode, int group = checkInt( attribute( parentElement, "group-id" ), myModule->defaultMenuGroup() ); if ( !plabel.isEmpty() ) { - QPopupMenu* popup = 0; + QMenu* popup = 0; int menuId = -1; // create menu - if ( IsCallOldMethods ) { // __CALL_OLD_METHODS__ - SUIT_Desktop* desktop = myModule->getApp()->desktop(); - if ( parentMenuId == -1 ) { // top-level menu - QMenuBar* mb = desktop->menuBar(); - QMenuItem* mi = mb->findItem( pid ); - if ( mi ) popup = mi->popup(); - if ( !popup ) { - popup = new QPopupMenu( desktop ); - ppos = checkInt( attribute( parentElement, "pos-id" ), -1, mb->count() ); - menuId = mb->insertItem( plabel, popup, pid, ppos ); - myCurrentMenu.push_back( QString::number( menuId ) ); - myMenuItems.append( myCurrentMenu.join( ":" ) ); - } - else { - menuId = pid; - myCurrentMenu.push_back( QString::number( menuId ) ); - } - } - else { - // parentPopup should not be 0 here! - QMenuItem* mi = parentPopup->findItem( pid ); - if ( mi ) popup = mi->popup(); - if ( !popup ) { - popup = new QPopupMenu( desktop ); - ppos = checkInt( attribute( parentElement, "pos-id" ), -1, popup->count() ); - menuId = parentPopup->insertItem( plabel, popup, pid, ppos ); - myCurrentMenu.push_back( QString::number( menuId ) ); - myMenuItems.append( myCurrentMenu.join( ":" ) ); - } - else { - menuId = pid; - myCurrentMenu.push_back( QString::number( menuId ) ); - } - } - } - else { //!__CALL_OLD_METHODS__ - menuId = myModule->createMenu( plabel, // label - parentMenuId, // parent menu ID, should be -1 for main menu - pid, // ID - group, // group ID - ppos, // position - true ); // create constant menu (not removed by clearMenu()) - } // __CALL_OLD_METHODS__ + menuId = myModule->createMenu( plabel, // label + parentMenuId, // parent menu ID, -1 for top-level menu + pid, // ID + group, // group ID + ppos ); // position QDomNode node = parentNode.firstChild(); while ( !node.isNull() ) { if ( node.isElement() ) { @@ -1887,49 +1891,23 @@ void SALOME_PYQT_XmlHandler::createMenu( QDomNode& parentNode, QString tooltip = attribute( elem, "tooltip-id" ); QString accel = attribute( elem, "accel-id" ); bool toggle = checkBool( attribute( elem, "toggle-id" ) ); - ////QString execute = attribute( elem, "execute-action" ); // not used // -1 action ID is not allowed : it means that attribute is missed in the XML file! // also check if the action with given ID is already created if ( id != -1 ) { - if ( IsCallOldMethods ) { // __CALL_OLD_METHODS__ - QIconSet iconSet = myModule->loadIcon( icon ); - pos = checkInt( attribute( elem, "pos-id" ), -1, popup->count() ); - int aid = iconSet.isNull() ? popup->insertItem( label, - myModule, - SLOT( onGUIEvent(int) ), - QKeySequence( accel ), - id, - pos ) : - popup->insertItem( iconSet, - label, - myModule, - SLOT( onGUIEvent(int) ), - QKeySequence( accel ), - id, - pos ); - myCurrentMenu.push_back( QString::number( aid ) ); - myMenuItems.append( myCurrentMenu.join( ":" ) ); - myCurrentMenu.pop_back(); - if ( toggle ) - popup->setItemChecked( aid, checkBool( attribute( elem, "toggle-id" ), 1 ) ); - } - else { //!__CALL_OLD_METHODS__ - // create menu action - QAction* action = myModule->createAction( id, // ID - tooltip, // tooltip - icon, // icon - label, // menu text - tooltip, // status-bar text - QKeySequence( accel ), // keyboard accelerator - toggle ); // toogled action - myModule->createMenu( action, // action - menuId, // parent menu ID - id, // ID (same as for createAction()) - group, // group ID - pos, // position - true ); // create constant menu (not removed by clearMenu()) - } // __CALL_OLD_METHODS__ + // create menu action + QAction* action = myModule->createAction( id, // ID + tooltip, // tooltip + icon, // icon + label, // menu text + tooltip, // status-bar text + QKeySequence( accel ), // keyboard accelerator + toggle ); // toogled action + myModule->createMenu( action, // action + menuId, // parent menu ID + id, // ID (same as for createAction()) + group, // group ID + pos ); // position } } else if ( aTagName == "submenu" ) { @@ -1938,44 +1916,31 @@ void SALOME_PYQT_XmlHandler::createMenu( QDomNode& parentNode, } else if ( aTagName == "separator" ) { // create menu separator - int id = checkInt( attribute( elem, "item-id" ) ); // separator can have ID + int id = checkInt( attribute( elem, "item-id" ) ); // separator can have ID int pos = checkInt( attribute( elem, "pos-id" ) ); int group = checkInt( attribute( elem, "group-id" ), myModule->defaultMenuGroup() ); - if ( IsCallOldMethods ) { // __CALL_OLD_METHODS__ - pos = checkInt( attribute( elem, "pos-id" ), -1, popup->count() ); - int sid = popup->insertSeparator( pos ); - myCurrentMenu.push_back( QString::number( sid ) ); - myMenuItems.append( myCurrentMenu.join( ":" ) ); - myCurrentMenu.pop_back(); - } - else { //!__CALL_OLD_METHODS__ - QAction* action = myModule->createSeparator(); - myModule->createMenu( action, // separator action - menuId, // parent menu ID - id, // ID - group, // group ID - pos, // position - true ); // create constant menu (not removed by clearMenu()) - } // __CALL_OLD_METHODS__ + QAction* action = myModule->separator(); + myModule->createMenu( action, // separator action + menuId, // parent menu ID + id, // ID + group, // group ID + pos ); // position } } node = node.nextSibling(); } - myCurrentMenu.pop_back(); } } } /*! - Create a toolbar with child actions - */ -void SALOME_PYQT_XmlHandler::createToolBar( QDomNode& parentNode ) + \brief Create a toolbar and insert actions to it. + \param parentNode XML node with toolbar description +*/ +void SALOME_PYQT_Module::XmlHandler::createToolBar( QDomNode& parentNode ) { - if ( !myModule ) - return; - - if ( parentNode.isNull() ) + if ( !myModule || parentNode.isNull() ) return; QDomElement parentElement = parentNode.toElement(); @@ -1997,26 +1962,25 @@ void SALOME_PYQT_XmlHandler::createToolBar( QDomNode& parentNode ) QString tooltip = attribute( elem, "tooltip-id" ); QString accel = attribute( elem, "accel-id" ); bool toggle = checkBool( attribute( elem, "toggle-id" ) ); - ////QString execute = attribute( elem, "execute-action" ); // not used // -1 action ID is not allowed : it means that attribute is missed in the XML file! // also check if the action with given ID is already created if ( id != -1 ) { // create toolbar action - QAction* action = myModule->createAction( id, // ID - tooltip, // tooltip - icon, // icon - label, // menu text - tooltip, // status-bar text - QKeySequence( accel ), // keyboard accelerator - toggle ); // toogled action + QAction* action = myModule->createAction( id, // ID + tooltip, // tooltip + icon, // icon + label, // menu text + tooltip, // status-bar text + QKeySequence( accel ), // keyboard accelerator + toggle ); // toogled action myModule->createTool( action, tbId, -1, pos ); } } else if ( aTagName == "separatorTB" || aTagName == "separator" ) { // create toolbar separator - int pos = checkInt( attribute( elem, "pos-id" ) ); - QAction* action = myModule->createSeparator(); + int pos = checkInt( attribute( elem, "pos-id" ) ); + QAction* action = myModule->separator(); myModule->createTool( action, tbId, -1, pos ); } } @@ -2027,68 +1991,72 @@ void SALOME_PYQT_XmlHandler::createToolBar( QDomNode& parentNode ) } /*! - * Fill popup menu with items - */ -void SALOME_PYQT_XmlHandler::insertPopupItems( QDomNode& parentNode, QPopupMenu* menu ) + \brief Fill popup menu with the items. + \param parentNode XML node with popup menu description + \param menu popup menu +*/ +void SALOME_PYQT_Module::XmlHandler::insertPopupItems( QDomNode& parentNode, QMenu* menu ) { - if ( !myModule ) - return; - - if ( parentNode.isNull() ) + if ( !myModule && parentNode.isNull() ) return; // we create popup menus without help of QtxPopupMgr QDomNode node = parentNode.firstChild(); - while ( !node.isNull() ) { + while ( !node.isNull() ) { if ( node.isElement() ) { QDomElement elem = node.toElement(); QString aTagName = tagName( elem ); + QList actions = menu->actions(); if ( aTagName == "popup-item" ) { // insert a command item int id = checkInt( attribute( elem, "item-id" ) ); int pos = checkInt( attribute( elem, "pos-id" ) ); QString label = attribute( elem, "label-id" ); QString icon = attribute( elem, "icon-id" ); - /////QString tooltip = attribute( elem, "tooltip-id" ); // not used + QString tooltip = attribute( elem, "tooltip-id" ); QString accel = attribute( elem, "accel-id" ); - /////bool toggle = checkBool( attribute( elem, "toggle-id" ) ); // not used - /////QString execute = attribute( elem, "execute-action" ); // not used - - QIconSet anIcon; - if ( !icon.isEmpty() ) { - QPixmap pixmap = myModule->getApp()->resourceMgr()->loadPixmap( myModule->name(""), icon ); - if ( !pixmap.isNull() ) - anIcon = QIconSet( pixmap ); - } + bool toggle = checkBool( attribute( elem, "toggle-id" ) ); // -1 action ID is not allowed : it means that attribute is missed in the XML file! // also check if the action with given ID is already created if ( id != -1 ) { - menu->insertItem( anIcon, label, myModule, SLOT( onGUIEvent(int) ), QKeySequence( accel ), id, pos ); + QAction* action = myModule->createAction( id, // ID + tooltip, // tooltip + icon, // icon + label, // menu text + tooltip, // status-bar text + QKeySequence( accel ), // keyboard accelerator + toggle, // toogled action + menu ); // menu should be parent + QAction* before = ( pos >= 0 && pos < actions.count() ) ? actions[ pos ] : 0; + menu->insertAction( before, action ); } } else if ( aTagName == "submenu" ) { // create sub-menu - int id = checkInt( attribute( elem, "item-id" ) ); + ////int id = checkInt( attribute( elem, "item-id" ) ); // not used // int pos = checkInt( attribute( elem, "pos-id" ) ); QString label = attribute( elem, "label-id" ); - QString icon = attribute( elem, "icon-id" ); + QString icon = attribute( elem, "icon-id" ); - QIconSet anIcon; + QIcon anIcon; if ( !icon.isEmpty() ) { - QPixmap pixmap = myModule->getApp()->resourceMgr()->loadPixmap( myModule->name(""), icon ); + QPixmap pixmap = myModule->getApp()->resourceMgr()->loadPixmap( myModule->name(), icon ); if ( !pixmap.isNull() ) - anIcon = QIconSet( pixmap ); + anIcon = QIcon( pixmap ); } - QPopupMenu* newPopup = new QPopupMenu( menu, label ); - menu->insertItem( anIcon, label, newPopup, id, pos ); + QMenu* newPopup = menu->addMenu( anIcon, label ); + QAction* before = ( pos >= 0 && pos < actions.count() ) ? actions[ pos ] : 0; + menu->insertMenu( before, newPopup ); insertPopupItems( node, newPopup ); } else if ( aTagName == "separator" ) { // create menu separator - int pos = checkInt( attribute( elem, "pos-id" ) ); - menu->insertSeparator( pos ); + int pos = checkInt( attribute( elem, "pos-id" ) ); + QAction* action = myModule->separator(); + QAction* before = ( pos >= 0 && pos < actions.count() ) ? actions[ pos ] : 0; + menu->insertAction( before, action ); } } node = node.nextSibling(); diff --git a/src/SALOME_PYQT/SALOME_PYQT_GUI/SALOME_PYQT_Module.h b/src/SALOME_PYQT/SALOME_PYQT_GUI/SALOME_PYQT_Module.h index 65def75f6..594de1038 100644 --- a/src/SALOME_PYQT/SALOME_PYQT_GUI/SALOME_PYQT_Module.h +++ b/src/SALOME_PYQT/SALOME_PYQT_GUI/SALOME_PYQT_Module.h @@ -1,238 +1,152 @@ // 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 +// 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 +// +// 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 +// 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/ or email : webmaster.salome@opencascade.com // +// File : SALOME_PYQT_Module.h +// Author : Vadim SANDLER, Open CASCADE SAS, vadim.sandler@opencascade.com +// #ifndef SALOME_PYQT_MODULE_H #define SALOME_PYQT_MODULE_H #include "SALOME_PYQT_GUI.h" +#include "SALOME_PYQT_PyInterp.h" // this include must be first (see PyInterp_Interp.h)! + +#include -#include "SALOME_PYQT_PyInterp.h" // this include must be first (see PyInterp_base.h)! -#include "SalomeApp_Module.h" -#include -#include -#include -#include -#include +#include +#include +#include +#include #include #include CORBA_CLIENT_HEADER(SALOME_Component) -class SALOME_PYQT_XmlHandler; +class SALOME_PYQT_PyInterp; +class QAction; +class QMenu; class SALOME_PYQT_EXPORT SALOME_PYQT_Module: public SalomeApp_Module { Q_OBJECT; - /****************************** - * Data - ******************************/ - private: - typedef std::map InterpMap; - - /* study-to-subinterpreter map */ - static InterpMap myInterpMap; - /* current Python subinterpreter */ - SALOME_PYQT_PyInterp* myInterp; - /* Python GUI module loaded */ - PyObjWrapper myModule; - /* Python GUI being initialized (not zero only during the initialization)*/ - static SALOME_PYQT_Module* myInitModule; - - /* own menus list */ - struct MenuId - { - int id; - bool constantMenu; - MenuId() : id( -1 ), constantMenu( false ) {} - MenuId( const int _id, const bool _constantMenu ) - : id( _id ), constantMenu( _constantMenu ) {} - }; - typedef QValueList MenuIdList; - typedef QMap MenuMap; - MenuMap myMenus; - - /* XML resource file parser */ - SALOME_PYQT_XmlHandler* myXmlHandler; - /* windows map*/ - QMap myWindowsMap; - /* compatible view managers list */ - QStringList myViewMgrList; - - /* status of last trying of module activation*/ - bool myLastActivateStatus; - - /****************************** - * Construction/destruction - ******************************/ + class XmlHandler; + + //! study to Python subinterpreter map + typedef QMap InterpMap; + + static InterpMap myInterpMap; //!< study to Python subinterpreter map + SALOME_PYQT_PyInterp* myInterp; //!< current Python subinterpreter + PyObjWrapper myModule; //!< Python GUI module + static SALOME_PYQT_Module* myInitModule; //!< Python GUI being initialized (not zero only during the initialization) + + XmlHandler* myXmlHandler; //!< XML resource file parser + QMap myWindowsMap; //!< windows map + QStringList myViewMgrList;//!< compatible view managers list + + bool myLastActivateStatus; //!< latest module activation status public: - /* constructor */ SALOME_PYQT_Module(); - /* destructor */ ~SALOME_PYQT_Module(); - /* get module engine */ - Engines::Component_var getEngine() const; - - /****************************** - * Inherited from SalomeApp_Module - ******************************/ - public: - /* little trick : provide an access to being activated Python module from outside; - needed by the SalomePyQt library :( - */ static SALOME_PYQT_Module* getInitModule(); - /* initialization */ - void initialize ( CAM_Application* ); - - /* getting windows list */ - void windows ( QMap& ) const; - /* getting compatible viewer managers list */ - void viewManagers( QStringList& ) const; - - /* context popup menu request */ - void contextMenuPopup( const QString&, QPopupMenu*, QString& ); - - /* create preferences */ - void createPreferences(); - - /* get module engine IOR */ - virtual QString engineIOR() const; - - /* called when study desktop is activated */ - virtual void studyActivated(); - - /* returns default menu group */ - static int defaultMenuGroup(); - - /* working with toolbars : open protected methods */ - int createTool( const QString& ); - int createTool( const int, const int, const int = -1 ); - int createTool( const int, const QString&, const int = -1 ); - int createTool( QAction*, const int, const int = -1, const int = -1 ); - int createTool( QAction*, const QString&, const int = -1, const int = -1 ); - - /* working with menus : open protected methods */ - int createMenu( const QString&, const int, const int = -1, const int = -1, const int = -1, const bool = false ); - int createMenu( const QString&, const QString&, const int = -1, const int = -1, const int = -1, const bool = false ); - int createMenu( const int, const int, const int = -1, const int = -1, const bool = false ); - int createMenu( const int, const QString&, const int = -1, const int = -1, const bool = false ); - int createMenu( QAction*, const int, const int = -1, const int = -1, const int = -1, const bool = false ); - int createMenu( QAction*, const QString&, const int = -1, const int = -1, const int = -1, const bool = false ); - - /* clear given menu */ - bool clearMenu( const int = 0, const int = 0, const bool = true ); - - /* create separator : open protected method */ - QAction* createSeparator(); - - /* working with actions : open protected methods */ - QAction* action( const int ) const; - int actionId( const QAction* ) const; - QAction* createAction( const int, const QString&, const QString&, const QString&, - const QString&, const int, const bool = false ); - /* load icon from resource file */ - QIconSet loadIcon( const QString& fileName ); - - /* working with preferences : open protected methods */ - int addGlobalPreference( const QString& ); - int addPreference( const QString& ); - int addPreference( const QString&, const int, const int = -1, - const QString& = QString::null, - const QString& = QString::null ); - QVariant preferenceProperty( const int, const QString& ) const; - void setPreferenceProperty( const int, const QString&, const QVariant& ); - - /* Show/hide menus/toolbars */ - void setMenuShown( const bool ); - void setToolShown( const bool ); - - /* Preferences changing (module) */ - void preferencesChanged( const QString&, const QString& ); - -public slots: - /* activation */ - virtual bool activateModule( SUIT_Study* ); - /* deactivation */ - virtual bool deactivateModule( SUIT_Study* ); - - /* Preferences changing (application) */ - void preferenceChanged( const QString&, const QString&, const QString& ); - - /****************************** - * Internal methods - ******************************/ + void initialize( CAM_Application* ); + void windows( QMap& ) const; + void viewManagers( QStringList& ) const; + void contextMenuPopup( const QString&, QMenu*, QString& ); + void createPreferences(); + QString engineIOR() const; + void studyActivated(); + void preferencesChanged( const QString&, const QString& ); + + static int defaultMenuGroup(); + + int createTool( const QString& ); + int createTool( const int, const int, const int = -1 ); + int createTool( const int, const QString&, const int = -1 ); + int createTool( QAction*, const int, + const int = -1, const int = -1 ); + int createTool( QAction*, const QString&, + const int = -1, const int = -1 ); + + int createMenu( const QString&, const int, + const int = -1, const int = -1, const int = -1 ); + int createMenu( const QString&, const QString&, + const int = -1, const int = -1, const int = -1 ); + int createMenu( const int, const int, + const int = -1, const int = -1 ); + int createMenu( const int, const QString&, + const int = -1, const int = -1 ); + int createMenu( QAction*, const int, + const int = -1, const int = -1, const int = -1 ); + int createMenu( QAction*, const QString&, + const int = -1, const int = -1, const int = -1 ); + + QAction* separator(); + + QAction* action( const int ) const; + int actionId( const QAction* ) const; + QAction* createAction( const int, const QString&, const QString&, + const QString&, const QString&, const int, + const bool = false, QObject* = 0 ); + + QIcon loadIcon( const QString& fileName ); + + int addGlobalPreference( const QString& ); + int addPreference( const QString& ); + int addPreference( const QString&, const int, const int = -1, + const QString& = QString::null, + const QString& = QString::null ); + QVariant preferenceProperty( const int, const QString& ) const; + void setPreferenceProperty( const int, const QString&, + const QVariant& ); public slots: - /* GUI action processing slots */ - void onGUIEvent(); - void onGUIEvent( int ); + virtual bool activateModule( SUIT_Study* ); + virtual bool deactivateModule( SUIT_Study* ); + void preferenceChanged( const QString&, + const QString&, + const QString& ); + void onGUIEvent(); protected: - /* Menu processing */ - bool hasMenu( const QString&, const int ); - void registerMenu( const int, const int, const bool = false ); - void unregisterMenu( const int, const int ); - bool registered( const int, const int = 0 ); - bool isConstantMenu( const int, const int ); - -protected slots: - void onMenuHighlighted( int, int ); + Engines::Component_var getEngine() const; private: - /* internal initizalition */ - void init ( CAM_Application* ); - /* internal activation */ - void activate ( SUIT_Study* ); - - /* getting status of last module activation */ - bool lastActivationStatus() const; - - /* internal deactivation */ - void deactivate ( SUIT_Study* ); - /* customization */ - void customize ( SUIT_Study* ); - /* study activation */ - void studyChanged( SUIT_Study* ); - /* context popup menu processing */ - void contextMenu( const QString&, QPopupMenu* ); - /* GUI event processing */ - void guiEvent( const int ); - /* Menu highlight processing */ - void menuHighlight( const int, const int ); - /* Init preferences */ - void initPreferences(); - - /* initialize a Python subinterpreter */ - void initInterp ( int ); - /* import a Python GUI module */ - void importModule(); - /* set workspace to Python GUI module */ - void setWorkSpace(); - - /* preferences changing */ - void prefChanged( const QString&, const QString& ); - - friend class SALOME_PYQT_XmlHandler; + void init( CAM_Application* ); + void activate( SUIT_Study* ); + void deactivate( SUIT_Study* ); + bool lastActivationStatus() const; + void customize( SUIT_Study* ); + void studyChanged( SUIT_Study* ); + void contextMenu( const QString&, QMenu* ); + void guiEvent( const int ); + void initPreferences(); + void prefChanged( const QString&, const QString& ); + + void initInterp ( int ); + void importModule(); + void setWorkSpace(); + + friend class XmlHandler; }; #endif // SALOME_PYQT_MODULE_H diff --git a/src/SALOME_PYQT/SALOME_PYQT_GUI/SALOME_PYQT_PyInterp.cxx b/src/SALOME_PYQT/SALOME_PYQT_GUI/SALOME_PYQT_PyInterp.cxx index f25a2ca05..24d4977d0 100644 --- a/src/SALOME_PYQT/SALOME_PYQT_GUI/SALOME_PYQT_PyInterp.cxx +++ b/src/SALOME_PYQT/SALOME_PYQT_GUI/SALOME_PYQT_PyInterp.cxx @@ -16,26 +16,20 @@ // // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // -// SALOME SALOMEGUI : implementation of desktop and GUI kernel +// File : SALOME_PYQT_PyInterp.cxx +// Author : Vadim SANDLER, Open CASCADE SAS, vadim.sandler@opencascade.com // -// File : SALOME_PYQT_PyInterp.cxx -// Author : Christian CAREMOLI, Paul RASCLE, EDF -// Module : SALOME -// $Header$ #include "SALOME_PYQT_PyInterp.h" // this include must be first (see PyInterp_base.h)! -#include "utilities.h" -#include "Container_init_python.hxx" - -using namespace std; - +#include +#include /*! * constructor : the main SALOME Python interpreter is used for PyQt GUI. * calls initialize method defined in base class, which calls virtual methods * initstate & initcontext redefined here */ -SALOME_PYQT_PyInterp::SALOME_PYQT_PyInterp(): PyInterp_base() +SALOME_PYQT_PyInterp::SALOME_PYQT_PyInterp(): PyInterp_Interp() { } diff --git a/src/SALOME_PYQT/SALOME_PYQT_GUI/SALOME_PYQT_PyInterp.h b/src/SALOME_PYQT/SALOME_PYQT_GUI/SALOME_PYQT_PyInterp.h index 42ac5d2d7..c9ce18128 100644 --- a/src/SALOME_PYQT/SALOME_PYQT_GUI/SALOME_PYQT_PyInterp.h +++ b/src/SALOME_PYQT/SALOME_PYQT_GUI/SALOME_PYQT_PyInterp.h @@ -16,23 +16,26 @@ // // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // +// File : SALOME_PYQT_PyInterp.h +// Author : Vadim SANDLER, Open CASCADE SAS, vadim.sandler@opencascade.com +// #ifndef SALOME_PYQT_PYINTERP_H #define SALOME_PYQT_PYINTERP_H #include "SALOME_PYQT_GUI.h" -#include "PyInterp_base.h" // this include must be first (see PyInterp_base.h)! +#include // this include must be first (see PyInterp_base.h)! -class SALOME_PYQT_EXPORT SALOME_PYQT_PyInterp : public PyInterp_base +class SALOME_PYQT_EXPORT SALOME_PYQT_PyInterp : public PyInterp_Interp { - public: +public: SALOME_PYQT_PyInterp(); ~SALOME_PYQT_PyInterp(); - int run(const char *command); - - protected: + int run( const char* ); + +protected: virtual bool initState(); virtual bool initContext(); }; diff --git a/src/SALOME_PYQT/SalomePyQt/Makefile.am b/src/SALOME_PYQT/SalomePyQt/Makefile.am index 1ae7eee2c..c88e5df04 100644 --- a/src/SALOME_PYQT/SalomePyQt/Makefile.am +++ b/src/SALOME_PYQT/SalomePyQt/Makefile.am @@ -69,3 +69,6 @@ $(SIP_SRC): $(SIP_FILES) install-exec-hook: $(libdir)/SalomePyQt.so $(libdir)/SalomePyQt.so: (cd $(libdir); ln -s libSalomePyQt.so SalomePyQt.so;) + +mostlyclean-local: + rm sip* diff --git a/src/SALOME_PYQT/SalomePyQt/SalomePyQt.cxx b/src/SALOME_PYQT/SalomePyQt/SalomePyQt.cxx index 15ee7c264..7e4791a49 100644 --- a/src/SALOME_PYQT/SalomePyQt/SalomePyQt.cxx +++ b/src/SALOME_PYQT/SalomePyQt/SalomePyQt.cxx @@ -16,44 +16,50 @@ // // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // +// File : SalomePyQt.cxx +// Author : Vadim SANDLER, Open CASCADE SAS, vadim.sandler@opencascade.com +// -#include "SALOME_PYQT_Module.h" // this include must be first!!! +#include // this include must be first!!! #include "SalomePyQt.h" -#include -#include -#include -#include -#include -#include - -#include "SALOME_Event.hxx" +#include +#include +#include +#include +#include -#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 "LightApp_SelectionMgr.h" -#include "OB_Browser.h" -#include "QtxAction.h" -#include "LogWindow.h" +#include -using namespace std; +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include /*! - \return active application object [ static ] + \brief Get the currently active application. + \internal + \return active application object or 0 if there is no any */ -static SalomeApp_Application* getApplication() { +static SalomeApp_Application* getApplication() +{ if ( SUIT_Session::session() ) return dynamic_cast( SUIT_Session::session()->activeApplication() ); - return NULL; + return 0; } /*! - \return active study or 0 if there is no study opened [ static ] + \brief Get the currently active study. + \internal + \return active study or 0 if there is no study opened */ static SalomeApp_Study* getActiveStudy() { @@ -62,10 +68,41 @@ static SalomeApp_Study* getActiveStudy() return 0; } +/*! + \brief Get the currently active module. + \internal + This function returns correct result only if Python-based + module is currently active. Otherwize, 0 is returned. +*/ +static SALOME_PYQT_Module* getActiveModule() +{ + SALOME_PYQT_Module* module = 0; + if ( SalomeApp_Application* anApp = getApplication() ) { + module = SALOME_PYQT_Module::getInitModule(); + if ( !module ) + module = dynamic_cast( anApp->activeModule() ); + } + return module; +} + +/*! + \class SALOME_Selection + \brief The class represents selection which can be used in Python. +*/ + +/*! + \brief Map of created selection objects. + \internal +*/ static QMap SelMap; /*! - Creates or finds the selection object (one per study). + \brief Get the selection object for the specified application. + + Finds or creates the selection object (one per study). + + \param app application object + \return selection object or 0 if \a app is invalid */ SALOME_Selection* SALOME_Selection::GetSelection( SalomeApp_Application* app ) { @@ -78,7 +115,8 @@ SALOME_Selection* SALOME_Selection::GetSelection( SalomeApp_Application* app ) } /*! - Selection constructor. + \brief Constructor. + \param p parent object */ SALOME_Selection::SALOME_Selection( QObject* p ) : QObject( p ), mySelMgr( 0 ) { @@ -90,7 +128,7 @@ SALOME_Selection::SALOME_Selection( QObject* p ) : QObject( p ), mySelMgr( 0 ) } } /*! - Selection destructor. Removes selection object from the map. + \brief Destructor. */ SALOME_Selection::~SALOME_Selection() { @@ -100,7 +138,8 @@ SALOME_Selection::~SALOME_Selection() } /*! - Watches for the selection manager destroying when study is closed. + \brief Called when selection manager is destroyed (usually + when the study is closed). */ void SALOME_Selection::onSelMgrDestroyed() { @@ -108,7 +147,7 @@ void SALOME_Selection::onSelMgrDestroyed() } /*! - Clears the selection. + \brief Clear the selection. */ void SALOME_Selection::Clear() { @@ -126,7 +165,7 @@ void SALOME_Selection::Clear() } /*! - Clears the selection. + \brief Clear the selection. */ void SALOME_Selection::ClearIObjects() { @@ -152,253 +191,309 @@ void SALOME_Selection::ClearFilters() } /*! - \return desktop (0 if error) + \class SalomePyQt + \brief The class provides utility functions which can be used in the Python + to operate with the SALOME GUI. + + All the functionality of this class is implemented as static methods, so they + can be called with the class name prefixed or via creation of the class instance. + For example, next both ways of SalomePyQt class usage are legal: + \code + from SalomePyQt import * + sg = SalomePyQt() + # using SalomePyQt class instance + desktop = sg.getDesktop() + # using SalomePyQt class directly + menubar = SalomePyQt.getMainMenuBar() + \endcode */ -class TGetDesktopEvent: public SALOME_Event { + +/*! + \fn QWidget* SalomePyQt::getDesktop(); + \brief Get the active application's desktop window. + \return desktop window or 0 if there is no any +*/ + +class TGetDesktopEvent: public SALOME_Event +{ public: typedef QWidget* TResult; TResult myResult; TGetDesktopEvent() : myResult( 0 ) {} - virtual void Execute() { + virtual void Execute() + { if ( getApplication() ) myResult = (QWidget*)( getApplication()->desktop() ); } }; - -/*! - \return desktop -*/ QWidget* SalomePyQt::getDesktop() { return ProcessEvent( new TGetDesktopEvent() ); } /*! - \return workspace widget (0 if error) + \fn QWidget* SalomePyQt::getMainFrame(); + \brief Get current application's main frame widget [obsolete]. + + Main frame widget is an internal widget of the application + desktop window (workspace). + + \return workspace widget (0 on any error) */ -class TGetMainFrameEvent: public SALOME_Event { + +class TGetMainFrameEvent: public SALOME_Event +{ public: typedef QWidget* TResult; TResult myResult; TGetMainFrameEvent() : myResult( 0 ) {} - virtual void Execute() { + virtual void Execute() + { if ( getApplication() ) { SUIT_Desktop* aDesktop = getApplication()->desktop(); myResult = (QWidget*)( aDesktop->centralWidget() ); } } }; - -/*! - \return workspace widget (0 if error) -*/ QWidget* SalomePyQt::getMainFrame() { return ProcessEvent( new TGetMainFrameEvent() ); } /*! - SalomePyQt::getMainMenuBar - Gets main menu. Returns 0 in error. + \fn QMenuBar* SalomePyQt::getMainMenuBar(); + \brief Get current application desktop's main menu. + \return main menu object (0 on any error) */ -class TGetMainMenuBarEvent: public SALOME_Event { + +class TGetMainMenuBarEvent: public SALOME_Event +{ public: typedef QMenuBar* TResult; TResult myResult; TGetMainMenuBarEvent() : myResult( 0 ) {} - virtual void Execute() { + virtual void Execute() + { if ( SalomeApp_Application* anApp = getApplication() ) { myResult = anApp->desktop()->menuBar(); } } }; - -/*! - \return main menu - \retval 0 in error. -*/ QMenuBar* SalomePyQt::getMainMenuBar() { return ProcessEvent( new TGetMainMenuBarEvent() ); } /*! - SalomePyQt::getPopupMenu - Gets an main menu's child popup menu by its id + QMenu* SalomePyQt::getPopupMenu( const MenuName menu ); + \brief Get main menu's child popup submenu by its identifier. + + This function is obsolete. + Use QMenu* SalomePyQt::getPopupMenu( const QString& menu ) instead. + + \param menu menu identifier + \return popup submenu object or 0 if it does not exist +*/ + +/*! + QMenu* SalomePyQt::getPopupMenu( const QString& menu ); + \brief Get main menu's child popup submenu by its name. + + The function creates menu if it does not exist. + + \param menu menu name + \return popup submenu object (0 on any error) */ -class TGetPopupMenuEvent: public SALOME_Event { + +class TGetPopupMenuEvent: public SALOME_Event +{ public: - typedef QPopupMenu* TResult; - TResult myResult; - MenuName myMenuName; - TGetPopupMenuEvent( const MenuName menu ) : myResult( 0 ), myMenuName( menu ) {} - virtual void Execute() { - if ( SalomeApp_Application* anApp = getApplication() ) { - QMenuBar* menuBar = anApp->desktop()->menuBar(); - if ( menuBar ) { - QString menu; - switch( myMenuName) { - case File: - menu = QObject::tr( "MEN_DESK_FILE" ); break; - case View: - menu = QObject::tr( "MEN_DESK_VIEW" ); break; - case Edit: - menu = QObject::tr( "MEN_DESK_EDIT" ); break; - case Preferences: - menu = QObject::tr( "MEN_DESK_PREFERENCES" ); break; - case Tools: - menu = QObject::tr( "MEN_DESK_TOOLS" ); break; - case Window: - menu = QObject::tr( "MEN_DESK_WINDOW" ); break; - case Help: - menu = QObject::tr( "MEN_DESK_HELP" ); break; - } - for ( int i = 0; i < menuBar->count() && !myResult; i++ ) { - QMenuItem* item = menuBar->findItem( menuBar->idAt( i ) ); - if ( item && item->text() == menu && item->popup() ) - myResult = item->popup(); - } - } + typedef QMenu* TResult; + TResult myResult; + QString myMenuName; + TGetPopupMenuEvent( const QString& menu ) : myResult( 0 ), myMenuName( menu ) {} + virtual void Execute() + { + SalomeApp_Application* anApp = getApplication(); + if ( anApp && !myMenuName.isEmpty() ) { + QtxActionMenuMgr* mgr = anApp->desktop()->menuMgr(); + SALOME_PYQT_Module* module = getActiveModule(); + int id = -1; + if ( module ) + id = module->createMenu( myMenuName, -1, -1, -1, -1 ); + else + id = mgr->insert( myMenuName, -1, -1, -1, -1 ); + myResult = mgr->findMenu( id ); } } }; - -/*! - \return popup menu - \param menu - menu name -*/ -QPopupMenu* SalomePyQt::getPopupMenu( const MenuName menu ) +QMenu* SalomePyQt::getPopupMenu( const MenuName menu ) +{ + QString menuName; + switch( menu ) { + case File: + menuName = QApplication::translate( "", "MEN_DESK_FILE" ); break; + case View: + menuName = QApplication::translate( "", "MEN_DESK_VIEW" ); break; + case Edit: + menuName = QApplication::translate( "", "MEN_DESK_EDIT" ); break; + case Preferences: + menuName = QApplication::translate( "", "MEN_DESK_PREFERENCES" ); break; + case Tools: + menuName = QApplication::translate( "", "MEN_DESK_TOOLS" ); break; + case Window: + menuName = QApplication::translate( "", "MEN_DESK_WINDOW" ); break; + case Help: + menuName = QApplication::translate( "", "MEN_DESK_HELP" ); break; + } + return ProcessEvent( new TGetPopupMenuEvent( menuName ) ); +} +QMenu* SalomePyQt::getPopupMenu( const QString& menu ) { return ProcessEvent( new TGetPopupMenuEvent( menu ) ); } /*! - SalomePyQt::getStudyId - Returns active study's ID or 0 if there is no active study. + \fn int SalomePyQt::getStudyId(); + \brief Get active study's identifier. + \return active study ID or 0 if there is no active study */ -class TGetStudyIdEvent: public SALOME_Event { + +class TGetStudyIdEvent: public SALOME_Event +{ public: typedef int TResult; TResult myResult; TGetStudyIdEvent() : myResult( 0 ) {} - virtual void Execute() { + virtual void Execute() + { if ( SalomeApp_Study* aStudy = getActiveStudy() ) { myResult = aStudy->studyDS()->StudyId(); } } }; - -/*! - SalomePyQt::getStudyId - Returns active study's ID or 0 if there is no active study. -*/ int SalomePyQt::getStudyId() { return ProcessEvent( new TGetStudyIdEvent() ); } /*! - SalomePyQt::getSelection - Creates a Selection object (to provide a compatibility with previous SALOME GUI). + \fn SALOME_Selection* SalomePyQt::getSelection() + \brief Get the selection object for the current study. + + Creates a Selection object if it has not been created yet. + + \return selection object (0 on error) */ -class TGetSelectionEvent: public SALOME_Event { + +class TGetSelectionEvent: public SALOME_Event +{ public: typedef SALOME_Selection* TResult; TResult myResult; TGetSelectionEvent() : myResult( 0 ) {} - virtual void Execute() { + virtual void Execute() + { 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() ); } /*! - SalomePyQt::putInfo - Puts an information message to the desktop's status bar - (with optional delay parameter given in seconds) + \fn void SalomePyQt::putInfo( const QString& msg, const int sec ) + \brief Put an information message to the current application's + desktop status bar. + + Optional second delay parameter (\a sec) can be used to specify + time of the message diplaying in seconds. If this parameter is less + or equal to zero, the constant message will be put. + + \param msg message text + \param sec message displaying time in seconds */ -class TPutInfoEvent: public SALOME_Event { + +class TPutInfoEvent: public SALOME_Event +{ QString myMsg; int mySecs; public: TPutInfoEvent( const QString& msg, const int sec = 0 ) : myMsg( msg ), mySecs( sec ) {} - virtual void Execute() { + virtual void Execute() + { if ( SalomeApp_Application* anApp = getApplication() ) { anApp->putInfo( myMsg, mySecs * 1000 ); } } }; - -/*! - 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 ) ); } /*! - SalomePyQt::getActiveComponent - Returns an active component name or empty string if there is no active component + \fn const QString SalomePyQt::getActiveComponent(); + \brief Get the currently active module name (for the current study). + \return active module name or empty string if there is no active module */ -class TGetActiveComponentEvent: public SALOME_Event { + +class TGetActiveComponentEvent: public SALOME_Event +{ public: typedef QString TResult; TResult myResult; TGetActiveComponentEvent() {} - virtual void Execute() { + virtual void Execute() + { if ( SalomeApp_Application* anApp = getApplication() ) { if ( CAM_Module* mod = anApp->activeModule() ) { - myResult = mod->name(""); + myResult = mod->name(); } } } }; - -/*! - \return an active component name or empty string if there is no active component -*/ const QString SalomePyQt::getActiveComponent() { return ProcessEvent( new TGetActiveComponentEvent() ); } /*! - SalomePyQt::updateObjBrowser - Updates an Object Browser of a given study. - If <= 0 the active study's object browser is updated. - parameter is obsolete parameter and currently not used. To be removed lately. + \brief Update an Object Browser of the specified (by identifier) study. + + If \a studyId <= 0 the active study's object browser is updated. + The \a updateSelection parameter is obsolete and currently is not used. + This parameter will be removed in future, so try to avoid its usage in + your code. + + \brief studyId study identifier + \brief updateSelection update selection flag (not used) + \sa getActiveStudy() */ void SalomePyQt::updateObjBrowser( const int studyId, bool updateSelection ) { - class TEvent: public SALOME_Event { + class TEvent: public SALOME_Event + { int myStudyId; bool myUpdateSelection; public: TEvent( const int studyId, bool updateSelection ) : myStudyId( studyId ), myUpdateSelection( updateSelection ) {} - virtual void Execute() { + virtual void Execute() + { if ( SUIT_Session::session() ) { if ( getActiveStudy() && myStudyId <= 0 ) myStudyId = getActiveStudy()->id(); if ( myStudyId > 0 ) { - QPtrList apps = SUIT_Session::session()->applications(); - QPtrListIterator it( apps ); - for( ; it.current(); ++it ) { - SalomeApp_Application* anApp = dynamic_cast( it.current() ); - if ( anApp && anApp->activeStudy() && anApp->activeStudy()->id() == myStudyId ) + QList apps = SUIT_Session::session()->applications(); + QList::Iterator it; + for( it = apps.begin(); it != apps.end(); ++it ) { + SalomeApp_Application* anApp = dynamic_cast( *it ); + if ( anApp && anApp->activeStudy() && anApp->activeStudy()->id() == myStudyId ) { anApp->updateObjectBrowser(); + return; + } } } } @@ -407,17 +502,30 @@ void SalomePyQt::updateObjBrowser( const int studyId, bool updateSelection ) ProcessVoidEvent( new TEvent( studyId, updateSelection ) ); } -const char* DEFAULT_SECTION = "SalomePyQt"; +/*! + \brief Default resource file section name. + \internal +*/ +static const char* DEFAULT_SECTION = "SalomePyQt"; /*! - SalomePyQt::addStringSetting - Adds a string setting to the application preferences - parameter is obsolete parameter and currently not used. To be removed lately. - This function is obsolete. Use addSetting() instead. + \brief Add string setting to the application preferences. + + The parameter \a autoValue is obsolete parameter and currently is not used. + This parameter will be removed in future, so try to avoid its usage in + your code. + + This function is obsolete. Use one of addSetting() instead. + + \param name setting name (it should be of kind where + \c section is resources section name and \c setting is setting name) + \param value new setting value + \param autoValue (not used) */ void SalomePyQt::addStringSetting( const QString& name, const QString& value, bool autoValue ) { - class TEvent: public SALOME_Event { + class TEvent: public SALOME_Event + { QString myName; QString myValue; bool myAutoValue; @@ -427,9 +535,9 @@ void SalomePyQt::addStringSetting( const QString& name, const QString& value, bo virtual void Execute() { if ( SUIT_Session::session() ) { SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr(); - QStringList sl = QStringList::split( ":", myName ); - QString _sec = sl.count() > 1 ? sl[ 0 ].stripWhiteSpace() : QString( DEFAULT_SECTION ); - QString _nam = sl.count() > 1 ? sl[ 1 ].stripWhiteSpace() : sl.count() > 0 ? sl[ 0 ].stripWhiteSpace() : QString( "" ); + QStringList sl = myName.split( ":", QString::SkipEmptyParts ); + QString _sec = sl.count() > 1 ? sl[ 0 ].trimmed() : QString( DEFAULT_SECTION ); + QString _nam = sl.count() > 1 ? sl[ 1 ].trimmed() : sl.count() > 0 ? sl[ 0 ].trimmed() : QString( "" ); if ( !_sec.isEmpty() && !_nam.isEmpty() ) resMgr->setValue( _sec, _nam, myValue ); } @@ -439,26 +547,36 @@ void SalomePyQt::addStringSetting( const QString& name, const QString& value, bo } /*! - SalomePyQt::addIntSetting - Adds an integer setting to the application preferences - parameter is obsolete parameter and currently not used. To be removed lately. - This function is obsolete. Use addSetting() instead. + \brief Add integer setting to the application preferences. + + The parameter \a autoValue is obsolete parameter and currently is not used. + This parameter will be removed in future, so try to avoid its usage in + your code. + + This function is obsolete. Use one of addSetting() instead. + + \param name setting name (it should be of kind where + \c section is resources section name and \c setting is setting name) + \param value new setting value + \param autoValue (not used) */ void SalomePyQt::addIntSetting( const QString& name, const int value, bool autoValue) { - class TEvent: public SALOME_Event { + class TEvent: public SALOME_Event + { QString myName; int myValue; bool myAutoValue; public: TEvent( const QString& name, const int value, bool autoValue ) : myName( name ), myValue( value ), myAutoValue( autoValue ) {} - virtual void Execute() { + virtual void Execute() + { if ( SUIT_Session::session() ) { SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr(); - QStringList sl = QStringList::split( ":", myName ); - QString _sec = sl.count() > 1 ? sl[ 0 ].stripWhiteSpace() : QString( DEFAULT_SECTION ); - QString _nam = sl.count() > 1 ? sl[ 1 ].stripWhiteSpace() : sl.count() > 0 ? sl[ 0 ].stripWhiteSpace() : QString( "" ); + QStringList sl = myName.split( ":", QString::SkipEmptyParts ); + QString _sec = sl.count() > 1 ? sl[ 0 ].trimmed() : QString( DEFAULT_SECTION ); + QString _nam = sl.count() > 1 ? sl[ 1 ].trimmed() : sl.count() > 0 ? sl[ 0 ].trimmed() : QString( "" ); if ( !_sec.isEmpty() && !_nam.isEmpty() ) resMgr->setValue( _sec, _nam, myValue ); } @@ -468,26 +586,36 @@ void SalomePyQt::addIntSetting( const QString& name, const int value, bool autoV } /*! - SalomePyQt::addDoubleSetting - Adds an double setting to the application preferences - parameter is obsolete parameter and currently not used. To be removed lately. - This function is obsolete. Use addSetting() instead. + \brief Add double setting to the application preferences. + + The parameter \a autoValue is obsolete parameter and currently is not used. + This parameter will be removed in future, so try to avoid its usage in + your code. + + This function is obsolete. Use one of addSetting() instead. + + \param name setting name (it should be of kind where + \c section is resources section name and \c setting is setting name) + \param value new setting value + \param autoValue (not used) */ void SalomePyQt::addDoubleSetting( const QString& name, const double value, bool autoValue ) { - class TEvent: public SALOME_Event { + class TEvent: public SALOME_Event + { QString myName; double myValue; bool myAutoValue; public: TEvent( const QString& name, const double value, bool autoValue ) : myName( name ), myValue( value ), myAutoValue( autoValue ) {} - virtual void Execute() { + virtual void Execute() + { if ( SUIT_Session::session() ) { SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr(); - QStringList sl = QStringList::split( ":", myName ); - QString _sec = sl.count() > 1 ? sl[ 0 ].stripWhiteSpace() : QString( DEFAULT_SECTION ); - QString _nam = sl.count() > 1 ? sl[ 1 ].stripWhiteSpace() : sl.count() > 0 ? sl[ 0 ].stripWhiteSpace() : QString( "" ); + QStringList sl = myName.split( ":", QString::SkipEmptyParts ); + QString _sec = sl.count() > 1 ? sl[ 0 ].trimmed() : QString( DEFAULT_SECTION ); + QString _nam = sl.count() > 1 ? sl[ 1 ].trimmed() : sl.count() > 0 ? sl[ 0 ].trimmed() : QString( "" ); if ( !_sec.isEmpty() && !_nam.isEmpty() ) resMgr->setValue( _sec, _nam, myValue ); } @@ -497,26 +625,36 @@ void SalomePyQt::addDoubleSetting( const QString& name, const double value, bool } /*! - SalomePyQt::addBoolSetting - Adds an boolean setting to the application preferences - parameter is obsolete parameter and currently not used. To be removed lately. - This function is obsolete. Use addSetting() instead. + \brief Add boolean setting to the application preferences. + + The parameter \a autoValue is obsolete parameter and currently is not used. + This parameter will be removed in future, so try to avoid its usage in + your code. + + This function is obsolete. Use one of addSetting() instead. + + \param name setting name (it should be of kind where + \c section is resources section name and \c setting is setting name) + \param value new setting value + \param autoValue (not used) */ void SalomePyQt::addBoolSetting( const QString& name, const bool value, bool autoValue ) { - class TEvent: public SALOME_Event { + class TEvent: public SALOME_Event + { QString myName; bool myValue; bool myAutoValue; public: TEvent( const QString& name, const bool value, bool autoValue ) : myName( name ), myValue( value ), myAutoValue( autoValue ) {} - virtual void Execute() { + virtual void Execute() + { if ( SUIT_Session::session() ) { SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr(); - QStringList sl = QStringList::split( ":", myName ); - QString _sec = sl.count() > 1 ? sl[ 0 ].stripWhiteSpace() : QString( DEFAULT_SECTION ); - QString _nam = sl.count() > 1 ? sl[ 1 ].stripWhiteSpace() : sl.count() > 0 ? sl[ 0 ].stripWhiteSpace() : QString( "" ); + QStringList sl = myName.split( ":", QString::SkipEmptyParts ); + QString _sec = sl.count() > 1 ? sl[ 0 ].trimmed() : QString( DEFAULT_SECTION ); + QString _nam = sl.count() > 1 ? sl[ 1 ].trimmed() : sl.count() > 0 ? sl[ 0 ].trimmed() : QString( "" ); if ( !_sec.isEmpty() && !_nam.isEmpty() ) resMgr->setValue( _sec, _nam, myValue ); } @@ -526,9 +664,12 @@ void SalomePyQt::addBoolSetting( const QString& name, const bool value, bool aut } /*! - SalomePyQt::removeSettings - Removes a setting from the application preferences + \brief Remove setting from the application preferences. + This function is obsolete. Use removeSetting() instead. + + \param name setting name (it should be of kind where + \c section is resources section name and \c setting is setting name) */ void SalomePyQt::removeSettings( const QString& name ) { @@ -539,9 +680,9 @@ void SalomePyQt::removeSettings( const QString& name ) virtual void Execute() { if ( SUIT_Session::session() ) { SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr(); - QStringList sl = QStringList::split( ":", myName ); - QString _sec = sl.count() > 1 ? sl[ 0 ].stripWhiteSpace() : QString( DEFAULT_SECTION ); - QString _nam = sl.count() > 1 ? sl[ 1 ].stripWhiteSpace() : sl.count() > 0 ? sl[ 0 ].stripWhiteSpace() : QString( "" ); + QStringList sl = myName.split( ":", QString::SkipEmptyParts ); + QString _sec = sl.count() > 1 ? sl[ 0 ].trimmed() : QString( DEFAULT_SECTION ); + QString _nam = sl.count() > 1 ? sl[ 1 ].trimmed() : sl.count() > 0 ? sl[ 0 ].trimmed() : QString( "" ); if ( !_sec.isEmpty() && !_nam.isEmpty() ) resMgr->remove( _sec, _nam ); } @@ -551,52 +692,58 @@ void SalomePyQt::removeSettings( const QString& name ) } /*! - SalomePyQt::getSetting - Gets a setting value (as string) + \fn QString SalomePyQt::getSetting( const QString& name ); + \brief Get application setting value (as string represenation). + This function is obsolete. Use stringSetting(), integerSetting(), boolSetting(), stringSetting() or colorSetting() instead. + + \param name setting name (it should be of kind where + \c section is resources section name and \c setting is setting name) + \return setting name (empty string if setting name is invalid) */ -class TGetSettingEvent: public SALOME_Event { + +class TGetSettingEvent: public SALOME_Event +{ public: typedef QString TResult; TResult myResult; QString myName; TGetSettingEvent( const QString& name ) : myName( name ) {} - virtual void Execute() { + virtual void Execute() + { if ( SUIT_Session::session() ) { SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr(); - QStringList sl = QStringList::split( ":", myName ); - QString _sec = sl.count() > 1 ? sl[ 0 ].stripWhiteSpace() : QString( DEFAULT_SECTION ); - QString _nam = sl.count() > 1 ? sl[ 1 ].stripWhiteSpace() : sl.count() > 0 ? sl[ 0 ].stripWhiteSpace() : QString( "" ); + QStringList sl = myName.split( ":", QString::SkipEmptyParts ); + QString _sec = sl.count() > 1 ? sl[ 0 ].trimmed() : QString( DEFAULT_SECTION ); + QString _nam = sl.count() > 1 ? sl[ 1 ].trimmed() : sl.count() > 0 ? sl[ 0 ].trimmed() : QString( "" ); myResult = ( !_sec.isEmpty() && !_nam.isEmpty() ) ? resMgr->stringValue( _sec, _nam, "" ) : QString( "" ); } } }; - -/*! - \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 ) ); } /*! - SalomePyQt::addSetting - Adds a double setting to the application preferences + \brief Add double setting to the application preferences. + \param section resources file section name + \param name setting name + \param value new setting value */ void SalomePyQt::addSetting( const QString& section, const QString& name, const double value ) { - class TEvent: public SALOME_Event { + class TEvent: public SALOME_Event + { QString mySection; QString myName; double myValue; public: TEvent( const QString& section, const QString& name, double value ) : mySection( section ), myName( name ), myValue( value ) {} - virtual void Execute() { + virtual void Execute() + { if ( SUIT_Session::session() ) { SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr(); if ( !mySection.isEmpty() && !myName.isEmpty() ) @@ -608,19 +755,23 @@ void SalomePyQt::addSetting( const QString& section, const QString& name, const } /*! - SalomePyQt::addSetting - Adds an integer setting to the application preferences + \brief Add integer setting to the application preferences. + \param section resources file section name + \param name setting name + \param value new setting value */ void SalomePyQt::addSetting( const QString& section, const QString& name, const int value ) { - class TEvent: public SALOME_Event { + class TEvent: public SALOME_Event + { QString mySection; QString myName; int myValue; public: TEvent( const QString& section, const QString& name, int value ) : mySection( section ), myName( name ), myValue( value ) {} - virtual void Execute() { + virtual void Execute() + { if ( SUIT_Session::session() ) { SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr(); if ( !mySection.isEmpty() && !myName.isEmpty() ) @@ -632,21 +783,25 @@ void SalomePyQt::addSetting( const QString& section, const QString& name, const } /*! - SalomePyQt::addSetting - Adds a boolean setting to the application preferences - (note: the last "dumb" parameter is used in order to avoid - sip compilation error because of conflicting int and bool types) + \brief Add boolean setting to the application preferences. + \param section resources file section name + \param name setting name + \param value new setting value + \param dumb this parameter is used in order to avoid sip compilation error + because of conflicting int and bool types */ -void SalomePyQt::addSetting( const QString& section, const QString& name, const bool value, const int ) +void SalomePyQt::addSetting( const QString& section, const QString& name, const bool value, const int /*dumb*/ ) { - class TEvent: public SALOME_Event { + class TEvent: public SALOME_Event + { QString mySection; QString myName; bool myValue; public: TEvent( const QString& section, const QString& name, bool value ) : mySection( section ), myName( name ), myValue( value ) {} - virtual void Execute() { + virtual void Execute() + { if ( SUIT_Session::session() ) { SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr(); if ( !mySection.isEmpty() && !myName.isEmpty() ) @@ -658,19 +813,23 @@ void SalomePyQt::addSetting( const QString& section, const QString& name, const } /*! - SalomePyQt::addSetting - Adds a string setting to the application preferences + \brief Add string setting to the application preferences. + \param section resources file section name + \param name setting name + \param value new setting value */ void SalomePyQt::addSetting( const QString& section, const QString& name, const QString& value ) { - class TEvent: public SALOME_Event { + class TEvent: public SALOME_Event + { QString mySection; QString myName; QString myValue; public: TEvent( const QString& section, const QString& name, const QString& value ) : mySection( section ), myName( name ), myValue( value ) {} - virtual void Execute() { + virtual void Execute() + { if ( SUIT_Session::session() ) { SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr(); if ( !mySection.isEmpty() && !myName.isEmpty() ) @@ -682,19 +841,23 @@ void SalomePyQt::addSetting( const QString& section, const QString& name, const } /*! - SalomePyQt::addSetting - Adds a color setting to the application preferences + \brief Add color setting to the application preferences. + \param section resources file section name + \param name setting name + \param value new setting value */ void SalomePyQt::addSetting( const QString& section, const QString& name, const QColor& value ) { - class TEvent: public SALOME_Event { + class TEvent: public SALOME_Event + { QString mySection; QString myName; QColor myValue; public: TEvent( const QString& section, const QString& name, const QColor& value ) : mySection( section ), myName( name ), myValue( value ) {} - virtual void Execute() { + virtual void Execute() + { if ( SUIT_Session::session() ) { SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr(); if ( !mySection.isEmpty() && !myName.isEmpty() ) @@ -706,10 +869,18 @@ void SalomePyQt::addSetting( const QString& section, const QString& name, const } /*! - SalomePyQt::integerSetting - Gets an integer setting from the application preferences + \fn int SalomePyQt::integerSetting( const QString& section, + const QString& name, + const int def ); + \brief Get integer setting from the application preferences. + \param section resources file section name + \param name setting name + \param def default value which is returned if the setting is not found + \return setting value */ -class TGetIntSettingEvent: public SALOME_Event { + +class TGetIntSettingEvent: public SALOME_Event +{ public: typedef int TResult; TResult myResult; @@ -718,27 +889,32 @@ public: TResult myDefault; TGetIntSettingEvent( const QString& section, const QString& name, const int def ) : mySection( section ), myName( name ), myDefault( def ) {} - virtual void Execute() { + virtual void Execute() + { if ( SUIT_Session::session() ) { SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr(); myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->integerValue( mySection, myName, myDefault ) : myDefault; } } }; - -/*! - \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 ) ); } /*! - SalomePyQt::doubleSetting - Gets a double setting from the application preferences + \fn double SalomePyQt::doubleSetting( const QString& section, + const QString& name, + const double def ); + \brief Get double setting from the application preferences. + \param section resources file section name + \param name setting name + \param def default value which is returned if the setting is not found + \return setting value */ -class TGetDblSettingEvent: public SALOME_Event { + +class TGetDblSettingEvent: public SALOME_Event +{ public: typedef double TResult; TResult myResult; @@ -747,27 +923,32 @@ public: TResult myDefault; TGetDblSettingEvent( const QString& section, const QString& name, const double def ) : mySection( section ), myName( name ), myDefault( def ) {} - virtual void Execute() { + virtual void Execute() + { if ( SUIT_Session::session() ) { SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr(); myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->doubleValue( mySection, myName, myDefault ) : myDefault; } } }; - -/*! - \return an double setting from the application preferences -*/ double SalomePyQt::doubleSetting( const QString& section, const QString& name, const double def ) { return ProcessEvent( new TGetDblSettingEvent( section, name, def ) ); } /*! - SalomePyQt::boolSetting - Gets a boolean setting from the application preferences + \fn bool SalomePyQt::boolSetting( const QString& section, + const QString& name, + const bool def ); + \brief Get boolean setting from the application preferences. + \param section resources file section name + \param name setting name + \param def default value which is returned if the setting is not found + \return setting value */ -class TGetBoolSettingEvent: public SALOME_Event { + +class TGetBoolSettingEvent: public SALOME_Event +{ public: typedef bool TResult; TResult myResult; @@ -776,27 +957,32 @@ public: TResult myDefault; TGetBoolSettingEvent( const QString& section, const QString& name, const bool def ) : mySection( section ), myName( name ), myDefault( def ) {} - virtual void Execute() { + virtual void Execute() + { if ( SUIT_Session::session() ) { SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr(); myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->booleanValue( mySection, myName, myDefault ) : myDefault; } } }; - -/*! - \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 ) ); } /*! - SalomePyQt::stringSetting - Gets a string setting from the application preferences + \fn QString SalomePyQt::stringSetting( const QString& section, + const QString& name, + const QString& def ); + \brief Get string setting from the application preferences. + \param section resources file section name + \param name setting name + \param def default value which is returned if the setting is not found + \return setting value */ -class TGetStrSettingEvent: public SALOME_Event { + +class TGetStrSettingEvent: public SALOME_Event +{ public: typedef QString TResult; TResult myResult; @@ -805,27 +991,32 @@ public: TResult myDefault; TGetStrSettingEvent( const QString& section, const QString& name, const QString& def ) : mySection( section ), myName( name ), myDefault( def ) {} - virtual void Execute() { + virtual void Execute() + { if ( SUIT_Session::session() ) { SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr(); myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->stringValue( mySection, myName, myDefault ) : myDefault; } } }; - -/*! - \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 ) ); } /*! - SalomePyQt::colorSetting - Gets a color setting from the application preferences + \fn QColor SalomePyQt::colorSetting( const QString& section, + const QString& name, + const QColor def ); + \brief Get color setting from the application preferences. + \param section resources file section name + \param name setting name + \param def default value which is returned if the setting is not found + \return setting value */ -class TGetColorSettingEvent: public SALOME_Event { + +class TGetColorSettingEvent: public SALOME_Event +{ public: typedef QColor TResult; TResult myResult; @@ -834,34 +1025,34 @@ public: TResult myDefault; TGetColorSettingEvent( const QString& section, const QString& name, const QColor& def ) : mySection( section ), myName( name ), myDefault( def ) {} - virtual void Execute() { + virtual void Execute() + { if ( SUIT_Session::session() ) { SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr(); myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->colorValue( mySection, myName, myDefault ) : myDefault; } } }; - -/*! - \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 ) ); } /*! - SalomePyQt::removeSetting - Removes a setting from the application preferences + \brief Remove setting from the application preferences. + \param section resources file section name + \param name setting name */ void SalomePyQt::removeSetting( const QString& section, const QString& name ) { - class TEvent: public SALOME_Event { + class TEvent: public SALOME_Event + { QString mySection; QString myName; public: TEvent( const QString& section, const QString& name ) : mySection( section ), myName( name ) {} - virtual void Execute() { + virtual void Execute() + { if ( SUIT_Session::session() ) { SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr(); if ( !mySection.isEmpty() && !myName.isEmpty() ) @@ -873,10 +1064,15 @@ void SalomePyQt::removeSetting( const QString& section, const QString& name ) } /*! - SalomePyQt::hasSetting - Returns True if the settings exists + \fn bool SalomePyQt::hasSetting( const QString& section, const QString& name ); + \brief Check setting existence in the application preferences. + \param section resources file section name + \param name setting name + \return \c true if setting exists */ -class THasColorSettingEvent: public SALOME_Event { + +class THasColorSettingEvent: public SALOME_Event +{ public: typedef bool TResult; TResult myResult; @@ -884,7 +1080,8 @@ public: QString myName; THasColorSettingEvent( const QString& section, const QString& name ) : mySection( section ), myName( name ) {} - virtual void Execute() { + virtual void Execute() + { if ( SUIT_Session::session() ) { SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr(); myResult = resMgr->hasValue( mySection, myName ); @@ -897,10 +1094,24 @@ bool SalomePyQt::hasSetting( const QString& section, const QString& name ) } /*! - SalomePyQt::getFileName - Displays 'Open/Save file' dialog box and returns a user's choice (file name) + \fn QString SalomePyQt::getFileName( QWidget* parent, + const QString& initial, + const QStringList& filters, + const QString& caption, + bool open ); + \brief Show 'Open/Save file' dialog box for file selection + and return a user's choice (selected file name). + \param parent parent widget + \param initial initial directory the dialog box to be opened in + \param filters list of files filters (wildcards) + \param caption dialog box title + \param open if \c true, "Open File" dialog box is shown; + otherwise "Save File" dialog box is shown + \return selected file name (null string if user cancels operation) */ -class TGetFileNameEvent: public SALOME_Event { + +class TGetFileNameEvent: public SALOME_Event +{ public: typedef QString TResult; TResult myResult; @@ -919,16 +1130,14 @@ public: myFilters( filters ), myCaption( caption ), myOpen ( open ) {} - virtual void Execute() { + virtual void Execute() + { if ( SalomeApp_Application* anApp = getApplication() ) { - myResult = anApp->getFileName( myOpen, myInitial, myFilters.join(";;"), myCaption, myParent ); + myResult = anApp->getFileName( myOpen, myInitial, myFilters.join(";;"), + myCaption, myParent ); } } }; - -/*! - 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, @@ -939,10 +1148,21 @@ QString SalomePyQt::getFileName( QWidget* parent, } /*! - SalomePyQt::getOpenFileNames - Displays 'Open files' dialog box and returns a user's choice (a list of file names) + \fn QStringList SalomePyQt::getOpenFileNames( QWidget* parent, + const QString& initial, + const QStringList& filters, + const QString& caption ); + \brief Show 'Open files' dialog box for multiple files selection + and return a user's choice (selected file names list). + \param parent parent widget + \param initial initial directory the dialog box to be opened in + \param filters list of files filters (wildcards) + \param caption dialog box title + \return selected file names list (empty list if user cancels operation) */ -class TGetOpenFileNamesEvent: public SALOME_Event { + +class TGetOpenFileNamesEvent: public SALOME_Event +{ public: typedef QStringList TResult; TResult myResult; @@ -958,16 +1178,13 @@ public: myInitial( initial ), myFilters( filters ), myCaption( caption ) {} - virtual void Execute() { + virtual void Execute() + { if ( SalomeApp_Application* anApp = getApplication() ) { myResult = anApp->getOpenFileNames( myInitial, myFilters.join(";;"), myCaption, myParent ); } } }; - -/*! - 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, @@ -977,10 +1194,19 @@ QStringList SalomePyQt::getOpenFileNames( QWidget* parent, } /*! - SalomePyQt::getExistingDirectory - Displays 'Get Directory' dialog box and returns a user's choice (a directory name) + \fn QString SalomePyQt::getExistingDirectory( QWidget* parent, + const QString& initial, + const QString& caption ); + \brief Show 'Get Directory' dialog box for the directory selection + and return a user's choice (selected directory name). + \param parent parent widget + \param initial initial directory the dialog box to be opened in + \param caption dialog box title + \return selected directory name (null string if user cancels operation) */ -class TGetExistingDirectoryEvent: public SALOME_Event { + +class TGetExistingDirectoryEvent: public SALOME_Event +{ public: typedef QString TResult; TResult myResult; @@ -993,16 +1219,13 @@ public: : myParent ( parent ), myInitial( initial ), myCaption( caption ) {} - virtual void Execute() { + virtual void Execute() + { if ( SalomeApp_Application* anApp = getApplication() ) { myResult = anApp->getDirectory( myInitial, myCaption, myParent ); } } }; - -/*! - 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 ) @@ -1011,21 +1234,27 @@ QString SalomePyQt::getExistingDirectory( QWidget* parent, } /*! - SalomePyQt::helpContext - Opens external browser to display 'context help' information - current implementation does nothing. + \brief Open external browser to display context help information. + \todo + + Current implementation does nothing. + + \param source documentation (HTML) file name + \param context context (for example, HTML ancor name) */ -void SalomePyQt::helpContext( const QString& source, const QString& context ) { - class TEvent: public SALOME_Event { +void SalomePyQt::helpContext( const QString& source, const QString& context ) +{ + class TEvent: public SALOME_Event + { QString mySource; QString myContext; public: TEvent( const QString& source, const QString& context ) : mySource( source ), myContext( context ) {} - virtual void Execute() { - if ( /*SalomeApp_Application* anApp =*/ getApplication() ) { - // VSR: TODO - // anApp->helpContext( mySource, myContext ); + virtual void Execute() + { + if ( SalomeApp_Application* anApp = getApplication() ) { + anApp->onHelpContextModule( "", mySource, myContext ); } } }; @@ -1033,18 +1262,28 @@ void SalomePyQt::helpContext( const QString& source, const QString& context ) { } /*! - SalomePyQt::dumpView - Dumps the contents of the currently active view to the image file - in the given format (JPEG, PNG, BMP are supported) + \fn bool SalomePyQt::dumpView( const QString& filename ); + \brief Dump the contents of the currently active view window + to the image file in the specified format. + + For the current moment JPEG, PNG and BMP images formats are supported. + The image format is defined automatically by the file name extension. + By default, BMP format is used. + + \param filename image file name + \return operation status (\c true on success) */ -class TDumpViewEvent: public SALOME_Event { + +class TDumpViewEvent: public SALOME_Event +{ public: typedef bool TResult; TResult myResult; QString myFileName; TDumpViewEvent( const QString& filename ) : myResult ( false ), myFileName( filename ) {} - virtual void Execute() { + virtual void Execute() + { if ( SalomeApp_Application* anApp = getApplication() ) { SUIT_ViewManager* vm = anApp->activeViewManager(); if ( vm ) { @@ -1052,58 +1291,44 @@ public: if ( vw ) { QImage im = vw->dumpView(); if ( !im.isNull() && !myFileName.isEmpty() ) { - QString fmt = SUIT_Tools::extension( myFileName ).upper(); + QString fmt = SUIT_Tools::extension( myFileName ).toUpper(); if ( fmt.isEmpty() ) fmt = QString( "BMP" ); // default format if ( fmt == "JPG" ) fmt = "JPEG"; - myResult = im.save( myFileName, fmt.latin1() ); + myResult = im.save( myFileName, fmt.toLatin1() ); } } } } } }; - -/*! - 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 + \fn int SalomePyQt::defaultMenuGroup(); + \brief Get detault menu group identifier which can be used when + creating menus (insert custom menu commands). + \return default menu group ID */ -class TDefMenuGroupEvent: public SALOME_Event { + +class TDefMenuGroupEvent: public SALOME_Event +{ public: typedef int TResult; TResult myResult; TDefMenuGroupEvent() : myResult( -1 ) {} - virtual void Execute() { + 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: @@ -1144,66 +1369,83 @@ private: int myId; int myIndex; }; -class TCreateToolEvent: public SALOME_Event { + +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( anApp->activeModule() ); + virtual void Execute() + { + SALOME_PYQT_Module* module = getActiveModule(); + if ( module ) myResult = myCrTool.execute( module ); - } } }; /*! - create new toolbar or get existing by name + \brief Create toolbar with specified name. + \param tBar toolbar name + \return toolbar ID or -1 if toolbar creation is failed */ int SalomePyQt::createTool( const QString& tBar ) { return ProcessEvent( new TCreateToolEvent( CrTool( tBar ) ) ); } -/*! add action with id and index to the existing tollbar + +/*! + \brief Insert action with specified \a id to the toolbar. + \param id action ID + \param tBar toolbar ID + \param idx required index in the toolbar + \return action ID or -1 if action could not be added */ 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 + +/*! + \brief Insert action with specified \a id to the toolbar. + \param id action ID + \param tBar toolbar name + \param idx required index in the toolbar + \return action ID or -1 if action could not be added */ 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 + +/*! + \brief Insert action to the toolbar. + \param a action + \param tBar toolbar ID + \param id required action ID + \param idx required index in the toolbar + \return action ID or -1 if action could not be added */ 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 + +/*! + \brief Insert action to the toolbar. + \param a action + \param tBar toolbar name + \param id required action ID + \param idx required index in the toolbar + \return action ID or -1 if action could not be added */ 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: @@ -1250,70 +1492,121 @@ private: int myId; int myIndex; }; -class TCreateMenuEvent: public SALOME_Event { + +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( anApp->activeModule() ); + virtual void Execute() + { + SALOME_PYQT_Module* module = getActiveModule(); + if ( module ) myResult = myCrMenu.execute( module ); - } } }; + +/*! + \brief Create main menu. + \param subMenu menu name + \param menu parent menu ID + \param id required menu ID + \param group menu group ID + \param idx required index in the menu + \return menu ID or -1 if menu could not be added +*/ 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 ) ) ); } +/*! + \brief Create main menu. + \param subMenu menu name + \param menu parent menu name (list of menu names separated by "|") + \param id required menu ID + \param group menu group ID + \param idx required index in the menu + \return menu ID or -1 if menu could not be added +*/ 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 ) ) ); } +/*! + \brief Insert action to the main menu. + \param id action ID + \param menu parent menu ID + \param group menu group ID + \param idx required index in the menu + \return action ID or -1 if action could not be added +*/ int SalomePyQt::createMenu( const int id, const int menu, const int group, const int idx ) { return ProcessEvent( new TCreateMenuEvent( CrMenu( id, menu, group, idx ) ) ); } +/*! + \brief Insert action to the main menu. + \param id action ID + \param menu parent menu name (list of menu names separated by "|") + \param group menu group ID + \param idx required index in the menu + \return action ID or -1 if action could not be added +*/ int SalomePyQt::createMenu( const int id, const QString& menu, const int group, const int idx ) { return ProcessEvent( new TCreateMenuEvent( CrMenu( id, menu, group, idx ) ) ); } +/*! + \brief Insert action to the main menu. + \param a action + \param menu parent menu ID + \param group menu group ID + \param idx required index in the menu + \return action ID or -1 if action could not be added +*/ 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 ) ) ); } +/*! + \brief Insert action to the main menu. + \param a action + \param menu parent menu name (list of menu names separated by "|") + \param group menu group ID + \param idx required index in the menu + \return action ID or -1 if action could not be added +*/ 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. + \fn QtxAction* SalomePyQt::createSeparator(); + \brief Create separator action which can be used in the menu or toolbar. + \return new separator action */ -class TCreateSepEvent: public SALOME_Event { + +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( anApp->activeModule() ); - if ( module ) - myResult = (QtxAction*)module->createSeparator(); - } + virtual void Execute() + { + SALOME_PYQT_Module* module = getActiveModule(); + if ( module ) + myResult = (QtxAction*)module->separator(); } }; QtxAction* SalomePyQt::createSeparator() @@ -1322,17 +1615,25 @@ QtxAction* SalomePyQt::createSeparator() } /*! - 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 + \fn QtxAction* SalomePyQt::createAction( const int id, + const QString& menuText, + const QString& tipText, + const QString& statusText, + const QString& icon, + const int key, + const bool toggle ) + \brief Create an action which can be then used in the menu or toolbar. + \param id the unique id action to be registered to + \param menuText action text which should appear in menu + \param tipText text which should appear in the tooltip + \param statusText text which should appear in the status bar when action is activated + \param icon the name of the icon file (the actual icon file name can be coded in the translation files) + \param key the key accelrator for the action + \param toggle if \c true the action is checkable */ -class TCreateActionEvent: public SALOME_Event { + +class TCreateActionEvent: public SALOME_Event +{ public: typedef QtxAction* TResult; TResult myResult; @@ -1347,14 +1648,11 @@ public: 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( anApp->activeModule() ); - if ( module ) - myResult = (QtxAction*)module->createAction( myId, myTipText, myIcon, myMenuText, myStatusText, myKey, myToggle ); - } + virtual void Execute() + { + SALOME_PYQT_Module* module = getActiveModule(); + if ( module ) + myResult = (QtxAction*)module->createAction( myId, myTipText, myIcon, myMenuText, myStatusText, myKey, myToggle ); } }; QtxAction* SalomePyQt::createAction( const int id, const QString& menuText, @@ -1365,24 +1663,24 @@ QtxAction* SalomePyQt::createAction( const int id, const QString& menu } /*! - SalomePyQt::action - Get an action by its id. Returns 0 if the action with such id was not registered. + \fn QtxAction* SalomePyQt::action( const int id ) + \brief Get action by specified identifier. + \return action or 0 if action is not registered */ -class TActionEvent: public SALOME_Event { + +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( anApp->activeModule() ); - if ( module ) - myResult = (QtxAction*)module->action( myId ); - } + virtual void Execute() + { + SALOME_PYQT_Module* module = getActiveModule(); + if ( module ) + myResult = (QtxAction*)module->action( myId ); } }; QtxAction* SalomePyQt::action( const int id ) @@ -1391,24 +1689,24 @@ QtxAction* SalomePyQt::action( const int id ) } /*! - SalomePyQt::actionId - Get an action id. Returns -1 if the action was not registered. + \fn int SalomePyQt::actionId( const QtxAction* a ); + \brief Get an action identifier. + \return action ID or -1 if action is not registered */ -class TActionIdEvent: public SALOME_Event { + +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( anApp->activeModule() ); - if ( module ) - myResult = module->actionId( myAction ); - } + virtual void Execute() + { + SALOME_PYQT_Module* module = getActiveModule(); + if ( module ) + myResult = module->actionId( myAction ); } }; int SalomePyQt::actionId( const QtxAction* a ) @@ -1417,52 +1715,25 @@ int SalomePyQt::actionId( const QtxAction* a ) } /*! - SalomePyQt::clearMenu - Clears given menu (recursively if necessary) + \fn int SalomePyQt::addGlobalPreference( const QString& label ); + \brief Add global (not module-related) preferences group. + \param label global preferences group name + \return preferences group identifier */ -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( 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 ) ); -} -/*! - SalomePyQt::addGlobalPreference - Adds global (not module) preferences group - */ -class TAddGlobalPrefEvent: public SALOME_Event { +class TAddGlobalPrefEvent: public SALOME_Event +{ public: typedef int TResult; TResult myResult; QString myLabel; TAddGlobalPrefEvent( const QString& label ) : myResult( -1 ), myLabel( label ) {} - virtual void Execute() { - if ( SalomeApp_Application* anApp = getApplication() ) { - SALOME_PYQT_Module* module = SALOME_PYQT_Module::getInitModule(); - if ( !module ) - module = dynamic_cast( anApp->activeModule() ); - if ( module ) - myResult = module->addGlobalPreference( myLabel ); - } + virtual void Execute() + { + SALOME_PYQT_Module* module = getActiveModule(); + if ( module ) + myResult = module->addGlobalPreference( myLabel ); } }; int SalomePyQt::addGlobalPreference( const QString& label ) @@ -1471,24 +1742,25 @@ int SalomePyQt::addGlobalPreference( const QString& label ) } /*! - SalomePyQt::addPreference - Adds preference - */ -class TAddPrefEvent: public SALOME_Event { + \fn int SalomePyQt::addPreference( const QString& label ); + \brief Add module-related preferences group. + \param label preferences group name + \return preferences group identifier +*/ + +class TAddPrefEvent: public SALOME_Event +{ public: typedef int TResult; TResult myResult; QString myLabel; TAddPrefEvent( const QString& label ) : myResult( -1 ), myLabel( label ) {} - virtual void Execute() { - if ( SalomeApp_Application* anApp = getApplication() ) { - SALOME_PYQT_Module* module = SALOME_PYQT_Module::getInitModule(); - if ( !module ) - module = dynamic_cast( anApp->activeModule() ); - if ( module ) - myResult = module->addPreference( myLabel ); - } + virtual void Execute() + { + SALOME_PYQT_Module* module = getActiveModule(); + if ( module ) + myResult = module->addPreference( myLabel ); } }; int SalomePyQt::addPreference( const QString& label ) @@ -1497,10 +1769,19 @@ int SalomePyQt::addPreference( const QString& label ) } /*! - SalomePyQt::addPreference - Adds preference - */ -class TAddPrefParamEvent: public SALOME_Event { + \fn int SalomePyQt::addPreference( const QString& label, const int pId, const int type, + const QString& section, const QString& param ); + \brief Add module-related preferences. + \param label preferences group name + \param pId parent preferences group id + \param type preferences type + \param section resources file section name + \param param resources file setting name + \return preferences identifier +*/ + +class TAddPrefParamEvent: public SALOME_Event +{ public: typedef int TResult; TResult myResult; @@ -1516,14 +1797,11 @@ public: : myResult( -1 ), myLabel( label ), myPId( pId ), myType( type ), mySection( section ), myParam ( param ) {} - virtual void Execute() { - if ( SalomeApp_Application* anApp = getApplication() ) { - SALOME_PYQT_Module* module = SALOME_PYQT_Module::getInitModule(); - if ( !module ) - module = dynamic_cast( anApp->activeModule() ); - if ( module ) - myResult = module->addPreference( myLabel, myPId, myType, mySection, myParam ); - } + virtual void Execute() + { + SALOME_PYQT_Module* module = getActiveModule(); + if ( module ) + myResult = module->addPreference( myLabel, myPId, myType, mySection, myParam ); } }; int SalomePyQt::addPreference( const QString& label, const int pId, const int type, @@ -1533,28 +1811,27 @@ int SalomePyQt::addPreference( const QString& label, const int pId, const int ty } /*! - SalomePyQt::preferenceProperty - Gets the property value for the given (by id) preference - */ -class TPrefPropEvent: public SALOME_Event { + \fn QVariant SalomePyQt::preferenceProperty( const int id, const QString& prop ); + \brief Get the preferences property. + \param id preferences identifier + \param prop preferences property name + \return preferences property value or null QVariant if property is not set +*/ + +class TPrefPropEvent: public SALOME_Event +{ public: typedef QVariant TResult; TResult myResult; int myId; QString myProp; TPrefPropEvent( const int id, const QString& prop ) - : myId( id ), myProp( prop ) - { - myResult = QVariant(); - } - virtual void Execute() { - if ( SalomeApp_Application* anApp = getApplication() ) { - SALOME_PYQT_Module* module = SALOME_PYQT_Module::getInitModule(); - if ( !module ) - module = dynamic_cast( anApp->activeModule() ); - if ( module ) - myResult = module->preferenceProperty( myId, myProp ); - } + : myId( id ), myProp( prop ) {} + virtual void Execute() + { + SALOME_PYQT_Module* module = getActiveModule(); + if ( module ) + myResult = module->preferenceProperty( myId, myProp ); } }; QVariant SalomePyQt::preferenceProperty( const int id, const QString& prop ) @@ -1563,48 +1840,51 @@ QVariant SalomePyQt::preferenceProperty( const int id, const QString& prop ) } /*! - SalomePyQt::setPreferenceProperty - Sets the property value for the given (by id) preference - */ + \brief Set the preferences property. + \param id preferences identifier + \param prop preferences property name + \param var preferences property value +*/ void SalomePyQt::setPreferenceProperty( const int id, const QString& prop, const QVariant& var ) { - class TEvent: public SALOME_Event { + class TEvent: public SALOME_Event + { int myId; QString myProp; QVariant myVar; public: TEvent( const int id, const QString& prop, const QVariant& var ) : myId( id ), myProp( prop ), myVar( var ) {} - virtual void Execute() { - if ( SalomeApp_Application* anApp = getApplication() ) { - SALOME_PYQT_Module* module = SALOME_PYQT_Module::getInitModule(); - if ( !module ) - module = dynamic_cast( anApp->activeModule() ); - if ( module ) - module->setPreferenceProperty( myId, myProp, myVar ); - } + virtual void Execute() + { + SALOME_PYQT_Module* module = getActiveModule(); + if ( module ) + module->setPreferenceProperty( myId, myProp, myVar ); } }; ProcessVoidEvent( new TEvent( id, prop, var) ); } /*! - SalomePyQt::addPreferenceProperty - Adds the property value to the list of values - for the given (by id) preference + \brief Add the property value to the list of values. This method allows creating properties which are QValueList - - there is no way to pass such values directly to QVariant parameter - from Python - */ + - there is no way to pass such values directly to QVariant parameter with PyQt. + + \param id preferences identifier + \param prop preferences property name + \param idx preferences property index + \param var preferences property value for the index \a idx +*/ void SalomePyQt::addPreferenceProperty( const int id, const QString& prop, const int idx, const QVariant& var ) { - class TEvent: public SALOME_Event { + class TEvent: public SALOME_Event + { int myId; QString myProp; int myIdx; @@ -1612,37 +1892,34 @@ void SalomePyQt::addPreferenceProperty( const int id, public: TEvent( const int id, const QString& prop, const int idx, const QVariant& var ) : myId( id ), myProp( prop ), myIdx( idx), myVar( var ) {} - virtual void Execute() { - if ( SalomeApp_Application* anApp = getApplication() ) { - SALOME_PYQT_Module* module = SALOME_PYQT_Module::getInitModule(); - if ( !module ) - module = dynamic_cast( anApp->activeModule() ); - if ( module ) { - QVariant var = module->preferenceProperty( myId, myProp ); - if ( var.isValid() ) { - if ( var.type() == QVariant::StringList ) { - QStringList sl = var.asStringList(); - if ( myIdx >= 0 && myIdx < sl.count() ) - sl[myIdx] = myVar.asString(); - else - sl.append( myVar.asString() ); - module->setPreferenceProperty( myId, myProp, sl ); - } - else if ( var.type() == QVariant::List ) { - QValueList vl = var.asList(); - if ( myIdx >= 0 && myIdx < vl.count() ) - vl[myIdx] = myVar; - else - vl.append( myVar ); - module->setPreferenceProperty( myId, myProp, vl ); - } + virtual void Execute() + { + SALOME_PYQT_Module* module = getActiveModule(); + if ( module ) { + QVariant var = module->preferenceProperty( myId, myProp ); + if ( var.isValid() ) { + if ( var.type() == QVariant::StringList ) { + QStringList sl = var.toStringList(); + if ( myIdx >= 0 && myIdx < sl.count() ) + sl[myIdx] = myVar.toString(); + else + sl.append( myVar.toString() ); + module->setPreferenceProperty( myId, myProp, sl ); } - else { - QValueList vl; - vl.append( myVar ); + else if ( var.type() == QVariant::List ) { + QList vl = var.toList(); + if ( myIdx >= 0 && myIdx < vl.count() ) + vl[myIdx] = myVar; + else + vl.append( myVar ); module->setPreferenceProperty( myId, myProp, vl ); } } + else { + QList vl; + vl.append( myVar ); + module->setPreferenceProperty( myId, myProp, vl ); + } } } }; @@ -1650,18 +1927,22 @@ void SalomePyQt::addPreferenceProperty( const int id, } /*! - SalomePyQt::message - Puts the message to the Log output window - */ + \brief Put the message to the Log messages output window + \param msg message text (it can be of simple rich text format) + \param addSeparator boolean flag which specifies if it is necessary + to separate the message with predefined separator +*/ void SalomePyQt::message( const QString& msg, bool addSeparator ) { - class TEvent: public SALOME_Event { + class TEvent: public SALOME_Event + { QString myMsg; bool myAddSep; public: TEvent( const QString& msg, bool addSeparator ) : myMsg( msg ), myAddSep( addSeparator ) {} - virtual void Execute() { + virtual void Execute() + { if ( SalomeApp_Application* anApp = getApplication() ) { LogWindow* lw = anApp->logWindow(); if ( lw ) @@ -1673,15 +1954,16 @@ void SalomePyQt::message( const QString& msg, bool addSeparator ) } /*! - SalomePyQt::clearMessages - Removes all the messages from the Log output window - */ + \brief Remove all the messages from the Log messages output window. +*/ void SalomePyQt::clearMessages() { - class TEvent: public SALOME_Event { + class TEvent: public SALOME_Event + { public: TEvent() {} - virtual void Execute() { + virtual void Execute() + { if ( SalomeApp_Application* anApp = getApplication() ) { LogWindow* lw = anApp->logWindow(); if ( lw ) diff --git a/src/SALOME_PYQT/SalomePyQt/SalomePyQt.h b/src/SALOME_PYQT/SalomePyQt/SalomePyQt.h index d160c193c..f26cda993 100644 --- a/src/SALOME_PYQT/SalomePyQt/SalomePyQt.h +++ b/src/SALOME_PYQT/SalomePyQt/SalomePyQt.h @@ -16,13 +16,16 @@ // // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // +// File : SalomePyQt.h +// Author : Vadim SANDLER, Open CASCADE SAS, vadim.sandler@opencascade.com +// #ifndef SALOME_PYQT_H #define SALOME_PYQT_H -#include -#include -#include +#include +#include +#include #include #include @@ -30,7 +33,7 @@ class LightApp_SelectionMgr; class SalomeApp_Application; class QMenuBar; -class QPopupMenu; +class QMenu; class QWidget; class QtxAction; @@ -97,7 +100,8 @@ public: static QWidget* getDesktop(); static QWidget* getMainFrame(); static QMenuBar* getMainMenuBar(); - static QPopupMenu* getPopupMenu( const MenuName ); + static QMenu* getPopupMenu( const MenuName ); + static QMenu* getPopupMenu( const QString& ); static SALOME_Selection* getSelection(); static int getStudyId(); static void putInfo( const QString&, const int = 0 ); @@ -142,9 +146,6 @@ public: static QtxAction* action( const int ); static int actionId( const QtxAction* ); - static bool clearMenu( const int = 0, const int = 0, - const bool = true ); - static void addSetting ( const QString&, const QString&, const double ); static void addSetting ( const QString&, const QString&, const int ); static void addSetting ( const QString&, const QString&, const bool, const int ); diff --git a/src/SALOME_PYQT/SalomePyQt/SalomePyQt.sip b/src/SALOME_PYQT/SalomePyQt/SalomePyQt.sip index f73f7b0ea..9218f790d 100644 --- a/src/SALOME_PYQT/SalomePyQt/SalomePyQt.sip +++ b/src/SALOME_PYQT/SalomePyQt/SalomePyQt.sip @@ -9,18 +9,19 @@ %Module SalomePyQt -%Import qtmod.sip +%Import QtGuimod.sip +%Import QtXmlmod.sip class SALOME_Selection : QObject { -%HeaderCode +%TypeHeaderCode #include %End public: - void Clear(); - void ClearIObjects(); - void ClearFilters(); + void Clear() /ReleaseGIL/ ; + void ClearIObjects() /ReleaseGIL/ ; + void ClearFilters() /ReleaseGIL/ ; private: SALOME_Selection( QObject* /TransferThis/ ); @@ -75,97 +76,95 @@ private: class SalomePyQt { -%HeaderCode +%TypeHeaderCode #include %End public: - static QWidget* getDesktop(); - static QWidget* getMainFrame(); - static QMenuBar* getMainMenuBar(); - static QPopupMenu* getPopupMenu( const MenuName ); - static SALOME_Selection* getSelection() /Factory/; - static int getStudyId(); - static void putInfo( const QString&, int = 0 ); - static const QString getActiveComponent(); - static void updateObjBrowser( int = 0, bool = true ); + static QWidget* getDesktop() /ReleaseGIL/ ; + static QWidget* getMainFrame() /ReleaseGIL/ ; + static QMenuBar* getMainMenuBar() /ReleaseGIL/ ; + static QMenu* getPopupMenu( const MenuName ) /ReleaseGIL/ ; + static QMenu* getPopupMenu( const QString& ) /ReleaseGIL/ ; + static SALOME_Selection* getSelection() /Factory,ReleaseGIL/ ; + static int getStudyId() /ReleaseGIL/ ; + static void putInfo( const QString&, const int = 0 ) /ReleaseGIL/ ; + static const QString getActiveComponent() /ReleaseGIL/ ; + static void updateObjBrowser( const int = 0, bool = true ) /ReleaseGIL/ ; - static QString getFileName ( QWidget*, const QString&, const QStringList&, const QString&, bool ); - static QStringList getOpenFileNames ( QWidget*, const QString&, const QStringList&, const QString& ); - static QString getExistingDirectory( QWidget*, const QString&, const QString& ); + static QString getFileName ( QWidget*, const QString&, const QStringList&, const QString&, bool ) /ReleaseGIL/ ; + static QStringList getOpenFileNames ( QWidget*, const QString&, const QStringList&, const QString& ) /ReleaseGIL/ ; + static QString getExistingDirectory( QWidget*, const QString&, const QString& ) /ReleaseGIL/ ; - static void helpContext( const QString&, const QString& ); + static void helpContext( const QString&, const QString& ) /ReleaseGIL/ ; - static bool dumpView( const QString& ); + static bool dumpView( const QString& ) /ReleaseGIL/ ; - static int defaultMenuGroup(); + static int defaultMenuGroup() /ReleaseGIL/ ; - static int createTool( const QString& ); - static int createTool( const int, const int, int = -1 ); - static int createTool( const int, const QString&, int = -1 ); - static int createTool( QtxAction*, const int, int = -1, int = -1 ); - static int createTool( QtxAction*, const QString&, int = -1, int = -1 ); + static int createTool( const QString& ) /ReleaseGIL/ ; + static int createTool( const int, const int, const int = -1 ) /ReleaseGIL/ ; + static int createTool( const int, const QString&, const int = -1 ) /ReleaseGIL/ ; + static int createTool( QtxAction*, const int, const int = -1, const int = -1 ) /ReleaseGIL/ ; + static int createTool( QtxAction*, const QString&, const int = -1, const int = -1 ) /ReleaseGIL/ ; static int createMenu( const QString&, const int, - int = -1, int = -1, int = -1 ); + const int = -1, const int = -1, const int = -1 ) /ReleaseGIL/ ; static int createMenu( const QString&, const QString&, - int = -1, int = -1, int = -1 ); + const int = -1, const int = -1, const int = -1 ) /ReleaseGIL/ ; static int createMenu( const int, const int, - int = -1, int = -1 ); + const int = -1, const int = -1 ) /ReleaseGIL/ ; static int createMenu( const int, const QString&, - int = -1, int = -1 ); - static int createMenu( QtxAction*, const int, int = -1, - int = -1, int = -1 ); - static int createMenu( QtxAction*, const QString&, int = -1, - int = -1, int = -1 ); - - static QtxAction* createSeparator(); + const int = -1, const int = -1 ) /ReleaseGIL/ ; + static int createMenu( QtxAction*, const int, const int = -1, + const int = -1, const int = -1 ) /ReleaseGIL/ ; + static int createMenu( QtxAction*, const QString&, const int = -1, + const int = -1, const int = -1 ) /ReleaseGIL/ ; + static QtxAction* createSeparator() /ReleaseGIL/ ; static QtxAction* createAction( const int, const QString&, const QString& = QString::null, const QString& = QString::null, - const QString& = QString::null, int = 0, bool = false ); - - static QtxAction* action( const int ); - static int actionId( const QtxAction* ); - - static bool clearMenu( int = 0, int = 0, - bool = true ); - - static void addSetting ( const QString&, const QString&, const double ); - static void addSetting ( const QString&, const QString&, const int /Constrained/ ); - static void addSetting ( const QString&, const QString&, const bool, const int ); - static void addSetting ( const QString&, const QString&, const QString& ); - static void addSetting ( const QString&, const QString&, const QColor& ); - static int integerSetting( const QString&, const QString&, int = 0 ); - static double doubleSetting ( const QString&, const QString&, double = 0 ); - static bool boolSetting ( const QString&, const QString&, bool = false ); - static QString stringSetting ( const QString&, const QString&, const QString& = QString("") ); - static QColor colorSetting ( const QString&, const QString&, const QColor& = QColor() ); - static void removeSetting ( const QString&, const QString& ); - static bool hasSetting ( const QString&, const QString& ); + const QString& = QString::null, const int = 0, const bool = false ) /ReleaseGIL/ ; + + static QtxAction* action( const int ) /ReleaseGIL/ ; + static int actionId( const QtxAction* ) /ReleaseGIL/ ; + + static void addSetting ( const QString&, const QString&, const double ) /ReleaseGIL/ ; + static void addSetting ( const QString&, const QString&, const int /Constrained/ ) /ReleaseGIL/ ; + static void addSetting ( const QString&, const QString&, const bool, const int ) /ReleaseGIL/ ; + static void addSetting ( const QString&, const QString&, const QString& ) /ReleaseGIL/ ; + static void addSetting ( const QString&, const QString&, const QColor& ) /ReleaseGIL/ ; + static int integerSetting( const QString&, const QString&, const int = 0 ) /ReleaseGIL/ ; + static double doubleSetting ( const QString&, const QString&, const double = 0 ) /ReleaseGIL/ ; + static bool boolSetting ( const QString&, const QString&, const bool = false ) /ReleaseGIL/ ; + static QString stringSetting ( const QString&, const QString&, const QString& = QString("") ) /ReleaseGIL/ ; + static QColor colorSetting ( const QString&, const QString&, const QColor& = QColor() ) /ReleaseGIL/ ; + static void removeSetting ( const QString&, const QString& ) /ReleaseGIL/ ; + static bool hasSetting ( const QString&, const QString& ) /ReleaseGIL/ ; // obsolete - static void addStringSetting( const QString&, const QString&, bool = true ); - static void addIntSetting ( const QString&, const int, bool = true ); - static void addDoubleSetting( const QString&, const double, bool = true ); - static void addBoolSetting ( const QString&, const bool, bool = true ); - static void removeSettings ( const QString& ); - static QString getSetting ( const QString& ); - - static int addGlobalPreference( const QString& ); - static int addPreference( const QString& ); - static int addPreference( const QString&, const int, int = -1, - const QString& = QString::null, - const QString& = QString::null ); - static QVariant preferenceProperty( const int, const QString& ); + static void addStringSetting( const QString&, const QString&, bool = true ) /ReleaseGIL/ ; + static void addIntSetting ( const QString&, const int, bool = true ) /ReleaseGIL/ ; + static void addDoubleSetting( const QString&, const double, bool = true ) /ReleaseGIL/ ; + static void addBoolSetting ( const QString&, const bool, bool = true ) /ReleaseGIL/ ; + static void removeSettings ( const QString& ) /ReleaseGIL/ ; + static QString getSetting ( const QString& ) /ReleaseGIL/ ; + + static int addGlobalPreference( const QString& ) /ReleaseGIL/ ; + static int addPreference( const QString& ) /ReleaseGIL/ ; + static int addPreference( const QString&, + const int, const int = -1, + const QString& = QString::null, + const QString& = QString::null ) /ReleaseGIL/ ; + static QVariant preferenceProperty( const int, const QString& ) /ReleaseGIL/ ; static void setPreferenceProperty( const int, const QString&, - const QVariant& ); + const QVariant& ) /ReleaseGIL/ ; static void addPreferenceProperty( const int, - const QString&, + const QString&, const int, - const QVariant& ); + const QVariant& ) /ReleaseGIL/ ; - static void message( const QString&, bool = true ); - static void clearMessages(); + static void message( const QString&, bool = true ) /ReleaseGIL/ ; + static void clearMessages() /ReleaseGIL/ ; }; diff --git a/src/src.pro b/src/src.pro index 238dead69..238d8d4b5 100644 --- a/src/src.pro +++ b/src/src.pro @@ -27,5 +27,5 @@ SUBDIRS += Event SUBDIRS += LightApp SUBDIRS += ResExporter SUBDIRS += TOOLSGUI -SUBDIRS += Session SUBDIRS += SalomeApp +SUBDIRS += Session