// Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com)
//
+#include <PyInterp_Dispatcher.h>
+
#include "SALOME_PYQT_Module.h"
#include "SalomeApp_Application.h"
#include "SALOME_PYQT_ModuleLight.h"
*/
QString SALOME_PYQT_Module::engineIOR() const
{
- if ( !CORBA::is_nil( getEngine() ) )
- return QString( getApp()->orb()->object_to_string( getEngine() ) );
- return QString( "" );
+ class EngineIORReq : public PyInterp_LockRequest
+ {
+ public:
+ EngineIORReq( PyInterp_Interp* _py_interp,
+ SALOME_PYQT_Module* _obj )
+ : PyInterp_LockRequest( _py_interp, 0, true ), // this request should be processed synchronously (sync == true)
+ myObj( _obj ) {}
+
+ protected:
+ virtual void execute()
+ {
+ myObj->getEngineIOR();
+ }
+
+ private:
+ SALOME_PYQT_Module* myObj;
+ };
+
+ // post request
+ PyInterp_Dispatcher::Get()->Exec( new EngineIORReq( myInterp, const_cast<SALOME_PYQT_Module*>( this ) ) );
+
+ return myIOR;
+}
+
+/*!
+ * Tries to get engine IOR from the Python module using engineIOR() function.
+ * That function can load module engine using appropriate container if required.
+ * If this function is not available in Python module, the default implementation
+ * is used which loads engine to the default FactoryServerPy container.
+ */
+void SALOME_PYQT_Module::getEngineIOR()
+{
+ myIOR = "";
+
+ // Python interpreter should be initialized and Python module should be
+ // import first
+ if ( !myInterp || !myModule )
+ return;
+
+ if ( PyObject_HasAttrString( myModule , "engineIOR" ) ) {
+ PyObjWrapper res( PyObject_CallMethod( myModule, "engineIOR", "" ) );
+ if ( !res ) {
+ PyErr_Print();
+ }
+ else {
+ // parse the return value, result chould be string
+ if ( PyString_Check( res ) ) {
+ myIOR = PyString_AsString( res );
+ }
+ }
+ }
+ else if ( !CORBA::is_nil( getEngine() ) )
+ myIOR = QString( getApp()->orb()->object_to_string( getEngine() ) );
}
CAM_DataModel* SALOME_PYQT_Module::createDataModel()
{
Q_OBJECT;
- public:
+public:
SALOME_PYQT_Module();
~SALOME_PYQT_Module();
/* get module engine IOR */
- virtual QString engineIOR() const;
+ virtual QString engineIOR() const;
- public slots:
+public slots:
void preferenceChanged( const QString&,
const QString&,
const QString& );
void onViewClosed( SUIT_ViewWindow* );
void onViewCloned( SUIT_ViewWindow* );
- protected:
+protected:
/* create data model */
- virtual CAM_DataModel* createDataModel();
+ virtual CAM_DataModel* createDataModel();
Engines::Component_var getEngine() const;
+private:
+ void getEngineIOR();
+
+private:
+ QString myIOR;
};
#endif // SALOME_PYQT_MODULE_H
//! study to Python subinterpreter map
typedef QMap<int, PyInterp_Interp*> InterpMap;
- PyObjWrapper myModule; //!< Python GUI module
static SALOME_PYQT_ModuleLight* myInitModule; //!< Python GUI being initialized (not zero only during the initialization)
XmlHandler* myXmlHandler; //!< XML resource file parser
QStringList myViewMgrList;//!< compatible view managers list
bool myLastActivateStatus; //!< latest module activation status
-
protected:
+ PyObjWrapper myModule; //!< Python GUI module
PyInterp_Interp* myInterp; //!< current Python subinterpreter
static InterpMap myInterpMap; //!< study to Python subinterpreter map