Notification NOTIFICATION_SWIG \
Container TestContainer LifeCycleCORBA HDFPersist \
VTKFilter OBJECT \
- TOOLSDS SALOMEDS \
+ TOOLSDS SALOMEDS Event \
SALOMEGUI Plot2d VTKViewer OCCViewer \
SUPERVGraph \
Session SALOME_SWIG TOOLSGUI SALOME_PY \
Handle_SALOME_NumberFilter.hxx \
SALOME_DataMapOfIOMapOfInteger.hxx \
Handle_SALOME_DataMapNodeOfDataMapOfIOMapOfInteger.hxx \
+ SALOMEGUI.h \
SALOMEGUI_LoadStudiesDlg.h \
SALOMEGUI_TableDlg.h \
SALOMEGUI_NameDlg.h \
SALOMEGUI_SetupCurveDlg.h \
SALOMEGUI_CloseDlg.h
-
# .po files to transform in .qm
PO_FILES = \
QAD_icons.po \
QAD_StudyFrame.cxx \
QAD_Tools.cxx \
QAD_ViewFrame.cxx \
+ SALOMEGUI.cxx \
SALOMEGUI_Application.cxx \
SALOMEGUI_Desktop.cxx \
SALOMEGUI_ImportOperation.cxx \
SALOMEGUI_CloseDlg.cxx \
SALOMEGUI_ActivateComponentDlg.cxx
LIB_MOC = \
+ SALOMEGUI.h \
SALOMEGUI_Application.h \
SALOMEGUI_Desktop.h \
QAD_Application.h \
SALOME_Exception.idl
CPPFLAGS+=$(QT_INCLUDES) $(PYTHON_INCLUDES) $(OCC_INCLUDES)
-LDFLAGS+=$(QT_MT_LIBS) -lSalomeNS -lqsplitterP -lSalomeLifeCycleCORBA -lOpUtil -lSalomeObject
+LDFLAGS+=$(QT_MT_LIBS) -lSalomeNS -lqsplitterP -lSalomeLifeCycleCORBA -lOpUtil -lSalomeObject -lEvent
LIBS+= $(PYTHON_LIBS)
// Module : SALOME
// $Header$
-using namespace std;
-using namespace std;
#include "PyInterp_PyQt.h"
-
#include "utilities.h"
-extern "C" PyObject * PyEval_EvalCode(PyObject *co, PyObject *g, PyObject *l);
+using namespace std;
+
/*!
* constructor : the main SALOME Python interpreter is used for PyQt GUI.
void PyInterp_PyQt::initState()
{
- salomeAcquireLock(); //acquire python global lock (one for all interpreters)
SCRUTE(PyInterp_base::_gtstate);
_tstate=PyInterp_base::_gtstate;
PyThreadState_Swap(_tstate);
Py_DECREF(bimod);
}
-void PyInterp_PyQt::enter()
-{
- PyThreadState *oldstate;
- SCRUTE(_tstate);
- salomeAcquireLock();
- oldstate=PyThreadState_Swap(_tstate);
- SCRUTE(oldstate);
-}
-
-void PyInterp_PyQt::quit()
-{
- MESSAGE("quit");
- salomeReleaseLock();
- MESSAGE("fin quit");
-}
-
void PyInterp_PyQt::run(const char *command)
{
- PyObject *code,*r;
- enter();
MESSAGE("compile");
- code=Py_CompileString((char *)command,"PyGUI",Py_file_input);
- if (code == NULL)
- {
- /*
- Une erreur s est produite en general SyntaxError
- */
- PyErr_Print();
- quit();
- return;
- }
- r = PyEval_EvalCode(code,_g,_g);
+ PyLockWrapper aLock(_tstate);
+ PyObject *code = Py_CompileString((char *)command,"PyGUI",Py_file_input);
+ if(!code){
+ // Une erreur s est produite en general SyntaxError
+ PyErr_Print();
+ return;
+ }
+ PyObject *r = PyEval_EvalCode(code,_g,_g);
Py_DECREF(code);
- if (r==NULL)
- {
- /*
- Une erreur s est produite a l execution
- */
- PyErr_Print();
- quit();
- return;
- }
+ if(!r){
+ // Une erreur s est produite a l execution
+ PyErr_Print();
+ return;
+ }
Py_DECREF(r);
- quit();
}
public:
PyInterp_PyQt();
~PyInterp_PyQt();
- void enter();
- void quit();
+
void run(const char *command);
protected:
- void initState();
- void initContext();
+ virtual void initState();
+ virtual void initContext();
};
#endif
// Module : SALOME
// $Header$
-using namespace std;
-#include "PyInterp_base.h"
-#include "utilities.h"
#include <string>
#include <vector>
+
+#include <Python.h>
#include <cStringIO.h>
+#include <qmutex.h>
+
+#include "PyInterp_base.h"
+#include "utilities.h"
+
+
using namespace std;
-extern "C" PyObject * PyEval_EvalCode(PyObject *co, PyObject *g, PyObject *l);
-static PyThreadState *savedThreadState = NULL;
+#ifdef _DEBUG_
+static int MYDEBUG = 0;
+#else
+static int MYDEBUG = 0;
+#endif
-/*!
- * We have our own routines which are identical to the SIP routines
- * to not depend from SIP software evolutions
- */
-extern "C" void salomeAcquireLock()
+static QMutex myMutex(false);
+
+
+PyLockWrapper::PyLockWrapper(PyThreadState* theThreadState):
+ myThreadState(theThreadState),
+ mySaveThreadState(PyInterp_base::_gtstate)
{
- MESSAGE("salomeAcquireLock");
- PyEval_RestoreThread(savedThreadState);
- savedThreadState = NULL;
+ //if(MYDEBUG) MESSAGE(" PyLockWrapper(...) - myThreadState = "<<myThreadState<<" - "<<myMutex.locked());
+ //myMutex.lock();
+ //PyEval_RestoreThread(myThreadState);
+
+ PyEval_AcquireLock();
+ mySaveThreadState = PyThreadState_Swap(myThreadState);
+
+ //PyEval_SaveThread();
+
+ //mySaveThreadState = PyThreadState_Swap(myThreadState);
+ //PyEval_ReleaseLock();
}
-extern "C" void salomeReleaseLock()
-{
- MESSAGE("salomeReleaseLock");
- savedThreadState = PyEval_SaveThread();
+
+PyLockWrapper::~PyLockWrapper(){
+ //if(MYDEBUG) MESSAGE("~PyLockWrapper(...) - myThreadState = "<<myThreadState);
+ //PyEval_SaveThread();
+ //myMutex.unlock();
+
+ PyThreadState_Swap(mySaveThreadState);
+ PyEval_ReleaseLock();
+
+ //PyEval_RestoreThread(myThreadState);
+
+ //PyEval_AcquireLock();
+ //PyThreadState_Swap(mySaveThreadState);
}
-extern "C" int salomeCondAcquireLock()
+
+ThreadLock::ThreadLock(QMutex* theMutex, const char* theComment):
+ myMutex(theMutex),
+ myComment(theComment)
{
- MESSAGE("salomeCondAcquireLock");
- if(savedThreadState != NULL)
- {
- /*
- * If savedThreadState is not NULL, Python global lock is not already acquired
- * We acquire it
- * and return 1 to the caller
- */
- salomeAcquireLock();
- //MESSAGE("We got it (the lock)");
- return 1;
- }
- /*
- * If savedThreadState is NULL, Python global lock is already acquired
- * We don't acquire or release it
- * We return 0 to the caller
- * CAUTION : it's only true when there is no event programming running (Tkinter, PyQt)
- */
- return 0;
+ if(MYDEBUG && myComment != "") MESSAGE(" ThreadLock "<<this<<"::"<<myMutex<<" - "<<myComment<<" - "<<myMutex->locked());
+ myMutex->lock();
}
-extern "C" void salomeCondReleaseLock(int rellock)
-{
- MESSAGE("salomeCondReleaseLock");
- if(rellock )
- salomeReleaseLock();
+
+ThreadLock::~ThreadLock(){
+ if(MYDEBUG && myComment != "") MESSAGE("~ThreadLock "<<this<<"::"<<myMutex<<" - "<<myComment);
+ myMutex->unlock();
}
-// main python interpreter
-PyThreadState *PyInterp_base::_gtstate=0; // force 0 before execution
-int PyInterp_base::_argc=1;
-char* PyInterp_base::_argv[] = {""};
+bool IsPyLocked(){
+ return myMutex.locked();
+}
-PyObject *PyInterp_base::builtinmodule=NULL;
-PyObject *PyInterp_base::salome_shared_modules_module=NULL;
-void init_python()
-{
- SCRUTE(PyInterp_base::_gtstate);
- if (PyInterp_base::_gtstate) return;
- Py_Initialize(); // Initialize the interpreter
- PyEval_InitThreads(); // Create (and acquire) the interpreter lock
- PySys_SetArgv(PyInterp_base::_argc,PyInterp_base::_argv); // initialize sys.argv
- PyInterp_base::_gtstate = PyThreadState_Get();
- SCRUTE(PyInterp_base::_gtstate);
-
- // /*
- // * Import __builtin__ module and store it to use it with all sub-interpreters
- // * This hack could be used with event programming (PyQt) to avoid errors
- // * encountered with incoherent builtins
- // */
-
- // PyInterp_base::builtinmodule =PyImport_ImportModule("__builtin__");
- // SCRUTE(PyInterp_base::builtinmodule->ob_refcnt);
-
- /*
- * Import salome_shared_modules module and store it to use it with all sub-interpreters
- */
-
- PyInterp_base::salome_shared_modules_module =PyImport_ImportModule("salome_shared_modules");
- if(PyInterp_base::salome_shared_modules_module == NULL){
- MESSAGE("init_python: problem with salome_shared_modules import");
- PyErr_Print();
- PyErr_Clear();
- salomeReleaseLock();
- return;
- }
- SCRUTE(PyInterp_base::salome_shared_modules_module->ob_refcnt);
- salomeReleaseLock();
+ThreadLock GetPyThreadLock(const char* theComment){
+ return ThreadLock(&myMutex,theComment);
}
-/*!
- * This function compiles a string (command) and then evaluates it in the dictionnary
- * context if possible.
- * Returns :
- * -1 : fatal error
- * 1 : incomplete text
- * 0 : complete text executed with success
- */
-int compile_command(const char *command,PyObject *context)
-{
- SCRUTE(command);
- PyObject *m,*v,*r;
-
- m=PyImport_AddModule("codeop");
- if(m == NULL)
- {
- /*
- * Fatal error. No way to go on.
- */
- PyErr_Print();
- return -1;
- }
- v= PyObject_CallMethod(m,"compile_command","s",command);
- if (v == NULL)
- {
- /*
- * Error encountered. It should be SyntaxError
- * so we don't write out traceback
- */
- PyObject *exception,*value,*tb;
- PyErr_Fetch(&exception, &value, &tb);
- PyErr_NormalizeException(&exception, &value, &tb);
- PyErr_Display(exception, value, NULL);
- Py_XDECREF(exception);
- Py_XDECREF(value);
- Py_XDECREF(tb);
+class PyReleaseLock{
+public:
+ ~PyReleaseLock(){
+ //if(MYDEBUG) MESSAGE("~PyReleaseLock()");
+ //PyEval_SaveThread();
- return -1;
- }
- else if (v == Py_None)
- {
- /*
- * Incomplete text we return 1 : we need a complete text to execute
- */
- return 1;
- }
- else
- {
- /*
- * Complete and correct text. We evaluate it.
- */
- r = PyEval_EvalCode(v,context,context);
- Py_DECREF(v);
- if (r==NULL)
- {
- /*
- * Execution error. We return -1
- */
- PyErr_Print();
- return -1;
- }
- Py_DECREF(r);
- /*
- * The command has been successfully executed. Return 0
- */
- return 0;
- }
+ PyEval_ReleaseLock();
+ }
+};
+
+
+PyLockWrapper PyInterp_base::GetLockWrapper(){
+ return PyLockWrapper(_tstate);
}
+
+// main python interpreter
+
+PyThreadState *PyInterp_base::_gtstate = 0; // force 0 before execution
+int PyInterp_base::_argc = 1;
+char* PyInterp_base::_argv[] = {""};
+
+PyObject *PyInterp_base::builtinmodule = NULL;
+PyObject *PyInterp_base::salome_shared_modules_module = NULL;
+
+
/*!
* basic constructor here : herited classes constructors must call initalize() method
* defined here.
*/
-
-PyInterp_base::PyInterp_base():_tstate(0),_vout(0),_verr(0),_g(0),_atFirst(true)
+PyInterp_base::PyInterp_base(): _tstate(0), _vout(0), _verr(0), _g(0), _atFirst(true)
{
- MESSAGE("PyInterp_base::PyInterp_base()");
+ //if(MYDEBUG) MESSAGE("PyInterp_base::PyInterp_base() - this = "<<this);
}
PyInterp_base::~PyInterp_base()
{
- MESSAGE("PyInterp_base::~PyInterp_base()");
- salomeAcquireLock();
+ if(MYDEBUG) MESSAGE("PyInterp_base::~PyInterp_base() - this = "<<this);
+ PyLockWrapper aLock(_tstate);
PyThreadState_Swap(_tstate);
Py_EndInterpreter(_tstate);
- salomeReleaseLock();
}
+
/*!
* Must be called by herited classes constructors. initialize() calls virtuals methods
* initstate & initcontext, not defined here in base class. initstate & initcontext methods
*/
void PyInterp_base::initialize()
{
- MESSAGE("PyInterp_base::initialize()");
- PyObject *m,*v,*c;
-
_history.clear(); // start a new list of user's commands
_ith = _history.begin();
- init_python();
+ PyReleaseLock aReleaseLock;
+ if(!_gtstate){
+ Py_Initialize(); // Initialize the interpreter
+ PyEval_InitThreads(); // Initialize and acquire the global interpreter lock
+ PySys_SetArgv(_argc,_argv); // initialize sys.argv
+ _gtstate = PyThreadState_Get();
+ }
+ //if(MYDEBUG) MESSAGE("PyInterp_base::initialize() - this = "<<this<<"; _gtstate = "<<_gtstate);
+
+ salome_shared_modules_module = PyImport_ImportModule("salome_shared_modules");
+ if(!salome_shared_modules_module){
+ if(MYDEBUG) MESSAGE("init_python: problem with salome_shared_modules import");
+ PyErr_Print();
+ PyErr_Clear();
+ }
+ //PyLockWrapper aLock(_tstate);
initState();
-
initContext();
- m=PyImport_ImportModule("codeop"); // used to interpret & compile commands
- if(m == NULL)
- {
- MESSAGE("Problem...");
- PyErr_Print();
- ASSERT(0);
- salomeReleaseLock();
- return;
- }
- Py_DECREF(m);
+ // used to interpret & compile commands
+ PyObjWrapper m(PyImport_ImportModule("codeop"));
+ if(!m){
+ if(MYDEBUG) MESSAGE("Problem...");
+ PyErr_Print();
+ ASSERT(0);
+ return;
+ }
- /*
- * Create cStringIO to capture stdout and stderr
- */
+ // Create cStringIO to capture stdout and stderr
//PycString_IMPORT;
- PycStringIO=(PycStringIO_CAPI *)xxxPyCObject_Import("cStringIO", "cStringIO_CAPI");
- _vout=PycStringIO->NewOutput(128);
- _verr=PycStringIO->NewOutput(128);
+ PycStringIO = (PycStringIO_CAPI *)xxxPyCObject_Import("cStringIO", "cStringIO_CAPI");
+ _vout = PycStringIO->NewOutput(128);
+ _verr = PycStringIO->NewOutput(128);
// All the initRun outputs are redirected to the standard output (console)
- this->initRun();
-
- // We go out of Python world to enter the C++ world. Release the Python global lock
- salomeReleaseLock();
- SCRUTE(_tstate);
- SCRUTE(this);
+ initRun();
}
+
string PyInterp_base::getbanner()
{
- MESSAGE("PyInterp_base::getbanner()");
- string banner = "Python ";
- banner = banner + Py_GetVersion() + " on " + Py_GetPlatform() ;
- banner = banner + "\ntype help to get general information on environment\n";
- return banner.c_str();
+ string aBanner("Python ");
+ aBanner = aBanner + Py_GetVersion() + " on " + Py_GetPlatform() ;
+ aBanner = aBanner + "\ntype help to get general information on environment\n";
+ return aBanner;
}
+
int PyInterp_base::initRun()
{
- MESSAGE("PyInterp_base::initRun()");
PySys_SetObject("stderr",_verr);
PySys_SetObject("stdout",_vout);
- PyObject *v = PyObject_CallMethod(_verr,"reset","");
- Py_XDECREF(v);
- v = PyObject_CallMethod(_vout,"reset","");
- Py_XDECREF(v);
-
+ PyObjWrapper verr(PyObject_CallMethod(_verr,"reset",""));
+ PyObjWrapper vout(PyObject_CallMethod(_vout,"reset",""));
- PyObject *m;
- m = PyImport_GetModuleDict();
+ PyObject *m = PyImport_GetModuleDict();
PySys_SetObject("stdout",PySys_GetObject("__stdout__"));
PySys_SetObject("stderr",PySys_GetObject("__stderr__"));
- MESSAGE(this->getvout());
- MESSAGE(this->getverr());
-
+ //if(MYDEBUG) MESSAGE("PyInterp_base::initRun() - this = "<<this<<"; _verr = "<<_verr<<"; _vout = "<<_vout);
return 0;
}
-void PyInterp_base::enter()
-{
- MESSAGE("PyInterp_base::enter()");
- salomeAcquireLock();
- PyThreadState_Swap(_tstate);
-}
-
-void PyInterp_base::quit()
-{
- MESSAGE("PyInterp_base::quit()");
- salomeReleaseLock();
-}
-void PyInterp_base::basicRun(const char *command)
+/*!
+ * This function compiles a string (command) and then evaluates it in the dictionnary
+ * context if possible.
+ * Returns :
+ * -1 : fatal error
+ * 1 : incomplete text
+ * 0 : complete text executed with success
+ */
+int compile_command(const char *command,PyObject *context)
{
- SCRUTE(command);
- PyObject *code,*r;
- enter();
- code=Py_CompileString((char *)command,"PyInterp_base",Py_file_input);
- if (code == NULL)
- {
- /*
- * Caught an error : SyntaxError
- * Print it and quit
- */
- PyErr_Print();
- quit();
- return;
- }
- r = PyEval_EvalCode(code,_g,_g);
- Py_DECREF(code);
- if (r==NULL)
- {
- /*
- * Caught an error during execution
- * Print it and quit
- */
+ PyObject *m = PyImport_AddModule("codeop");
+ if(!m){ // Fatal error. No way to go on.
+ PyErr_Print();
+ return -1;
+ }
+ PyObjWrapper v(PyObject_CallMethod(m,"compile_command","s",command));
+ if(!v){
+ // Error encountered. It should be SyntaxError,
+ //so we don't write out traceback
+ PyObjWrapper exception, value, tb;
+ PyErr_Fetch(&exception, &value, &tb);
+ PyErr_NormalizeException(&exception, &value, &tb);
+ PyErr_Display(exception, value, NULL);
+ return -1;
+ }else if (v == Py_None){
+ // Incomplete text we return 1 : we need a complete text to execute
+ return 1;
+ }else{
+ // Complete and correct text. We evaluate it.
+ PyObjWrapper r(PyEval_EvalCode(v,context,context));
+ if(!r){
+ // Execution error. We return -1
PyErr_Print();
- quit();
- return;
+ return -1;
}
- Py_DECREF(r);
- quit();
+ // The command has been successfully executed. Return 0
+ return 0;
+ }
}
+
int PyInterp_base::run(const char *command)
{
- SCRUTE(command);
- int ret = 0;
- if (_atFirst)
- {
- _atFirst = false;
- ret = this->simpleRun("from Help import *");
- MESSAGE(this->getvout())
- MESSAGE(this->getverr())
- if (ret != 0) return ret;
- ret = this->simpleRun("import salome");
- MESSAGE(this->getvout());
- MESSAGE(this->getverr())
- if (ret != 0) return ret;
- }
- ret = this->simpleRun(command);
- return ret;
+ if(_atFirst){
+ int ret = 0;
+ _atFirst = false;
+ ret = simpleRun("from Help import *");
+ if (ret) return ret;
+ ret = simpleRun("import salome");
+ if (ret) return ret;
+ }
+ return simpleRun(command);
}
+
int PyInterp_base::simpleRun(const char *command)
{
- SCRUTE(command);
- PyObject *v,*m,*r,*g;
- char *output;
- int ier=0;
- string s_com = command;
-
- if (s_com.size() > 0)
- {
- _history.push_back(s_com);
- _ith = _history.end();
- SCRUTE(_history.back());
- }
+ if(strcmp(command,"") != 0){
+ _history.push_back(command);
+ _ith = _history.end();
+ }
- // SCRUTE(this);
- // SCRUTE(_tstate);
// We come from C++ to enter Python world
// We need to acquire the Python global lock
- salomeAcquireLock();
- // Restore the sub interpreter thread state : this._tstate
- PyThreadState_Swap(_tstate);
+ PyLockWrapper aLock(_tstate);
- /*
- Reset redirected outputs before treatment
- */
+ // Reset redirected outputs before treatment
PySys_SetObject("stderr",_verr);
PySys_SetObject("stdout",_vout);
-
- v = PyObject_CallMethod(_verr,"reset","");
- Py_XDECREF(v);
- v = PyObject_CallMethod(_vout,"reset","");
- Py_XDECREF(v);
+
+ PyObjWrapper verr(PyObject_CallMethod(_verr,"reset",""));
+ PyObjWrapper vout(PyObject_CallMethod(_vout,"reset",""));
- ier=compile_command(command,_g);
+ int ier = compile_command(command,_g);
+ //if(MYDEBUG) MESSAGE("simpleRun(...) - this = "<<this<<"; command = '"<<command<<"'; ier = "<<ier);
// Outputs are redirected on standards outputs (console)
PySys_SetObject("stdout",PySys_GetObject("__stdout__"));
PySys_SetObject("stderr",PySys_GetObject("__stderr__"));
-
- // We go back to the C++ world. Release the lock.
- salomeReleaseLock();
return ier;
}
-static string vout_buffer;
-static string verr_buffer;
-
-char * PyInterp_base::getverr()
-{
- MESSAGE("PyInterp_base::getverr");
- PyObject *v;
- v=PycStringIO->cgetvalue(_verr);
- verr_buffer=PyString_AsString(v);
- Py_DECREF(v);
- return (char *)verr_buffer.c_str();
-}
-char * PyInterp_base::getvout()
-{
- MESSAGE("PyInterp_base::getvout");
- PyObject *v;
- v=PycStringIO->cgetvalue(_vout);
- vout_buffer=PyString_AsString(v);
- Py_DECREF(v);
- return (char *)vout_buffer.c_str();
-}
-
const char * PyInterp_base::getPrevious()
{
- MESSAGE("PyInterp_base::getPrevious");
- if (_ith != _history.begin())
- {
- _ith--;
- return (*_ith).c_str();
- }
+ if(_ith != _history.begin()){
+ _ith--;
+ return (*_ith).c_str();
+ }
else
return BEGIN_HISTORY_PY;
}
+
const char * PyInterp_base::getNext()
{
- MESSAGE("PyInterp_base::getNext");
- if (_ith != _history.end())
- {
- _ith++;
- }
+ if(_ith != _history.end()){
+ _ith++;
+ }
if (_ith == _history.end())
return TOP_HISTORY_PY;
else
return (*_ith).c_str();
}
+
+
+string PyInterp_base::getverr(){
+ PyLockWrapper aLock(_tstate);
+ PyObjWrapper v(PycStringIO->cgetvalue(_verr));
+ string aRet(PyString_AsString(v));
+ return aRet;
+}
+
+
+string PyInterp_base::getvout(){
+ PyLockWrapper aLock(_tstate);
+ PyObjWrapper v(PycStringIO->cgetvalue(_vout));
+ string aRet(PyString_AsString(v));
+ return aRet;
+}
+
#ifndef _PYINTERP_BASE_H_
#define _PYINTERP_BASE_H_
-#include <iostream>
-#include <Python.h>
#include <list>
#include <string>
+#include <iostream>
-using namespace std;
+#include <Python.h>
+
+class QSemaphore;
+class QMutex;
+
+extern "C" PyObject * PyEval_EvalCode(PyObject *co, PyObject *g, PyObject *l);
#define TOP_HISTORY_PY "--- top of history ---"
#define BEGIN_HISTORY_PY "--- begin of history ---"
-/*!
- * We have our own routines which are identical to the SIP routines
- * to not depend from SIP software evolutions
- */
-extern "C" void salomeAcquireLock();
-extern "C" void salomeReleaseLock();
-extern "C" int salomeCondAcquireLock();
-extern "C" void salomeCondReleaseLock(int rellock);
+class SemaphoreLock{
+ QSemaphore* mySemaphore;
+ std::string myComment;
+ public:
+ SemaphoreLock(QSemaphore* theSemaphore, const char* theComment = "");
+ ~SemaphoreLock();
+};
+
+
+class PyLockWrapper{
+ PyThreadState* myThreadState;
+ PyThreadState* mySaveThreadState;
+ public:
+ PyLockWrapper(PyThreadState* theThreadState);
+ ~PyLockWrapper();
+};
+
+
+class ThreadLock{
+ QMutex* myMutex;
+ std::string myComment;
+ public:
+ ThreadLock(QMutex* theMutex, const char* theComment = "");
+ ~ThreadLock();
+};
+
+
+bool IsPyLocked();
-/*! this class can only be used with derivation :
- * 2 pure virtual methods, initstate() & initcontext()
- */
+ThreadLock GetPyThreadLock(const char* theComment = "");
-class PyInterp_base
-{
+
+class PyInterp_base{
public:
static PyThreadState *_gtstate;
static int _argc;
static char* _argv[];
static PyObject *builtinmodule;
static PyObject *salome_shared_modules_module;
-
+
PyInterp_base();
~PyInterp_base();
- void initialize();
+
+ virtual void initialize();
+
int run(const char *command);
- char * getverr();
- char * getvout();
- string getbanner();
+
+ PyLockWrapper GetLockWrapper();
+
+ std::string getbanner();
+ std::string getverr();
+ std::string getvout();
+
const char * getPrevious();
const char * getNext();
- void enter();
- void quit();
- void basicRun(const char *command);
protected:
PyThreadState * _tstate;
- PyObject * _vout;
- PyObject * _verr;
- PyObject * _g;
- list <string> _history;
- list <string>::iterator _ith;
+ PyObject * _vout;
+ PyObject * _verr;
+ PyObject * _g;
+ std::list<std::string> _history;
+ std::list<std::string>::iterator _ith;
bool _atFirst;
int simpleRun(const char* command);
int initRun();
virtual void initState() = 0;
- virtual void initContext() =0;
+ virtual void initContext() = 0;
};
+
+class PyObjWrapper{
+ PyObject* myObject;
+public:
+ PyObjWrapper(PyObject* theObject): myObject(theObject) {}
+ PyObjWrapper(): myObject(0) {}
+ operator PyObject*(){
+ return myObject;
+ }
+ PyObject* operator->(){
+ return myObject;
+ }
+ PyObject* get(){
+ return myObject;
+ }
+ bool operator!(){
+ return !myObject;
+ }
+ bool operator==(PyObject* theObject){
+ return myObject == theObject;
+ }
+ PyObject** operator&(){
+ return &myObject;
+ }
+ PyObjWrapper& operator=(PyObjWrapper* theObjWrapper){
+ Py_XDECREF(myObject);
+ myObject = theObjWrapper->myObject;
+ return *this;
+ }
+ virtual ~PyObjWrapper(){
+ Py_XDECREF(myObject);
+ }
+};
+
+
#endif
newStudy = new QAD_Study( this, aStudy, StudyName);
}
+ newStudy->Init();
+
if ( newStudy->getResult() ) {
addStudy( newStudy );
#include "QAD_Desktop.h"
#include "QAD_LeftFrame.h"
#include "QAD_RightFrame.h"
+#include "QAD_PyEditor.h"
#include "QAD_Operation.h"
#include "QAD_XmlHandler.h"
#include "QAD_MessageBox.h"
//NRI #include "QAD_HelpWindow.h"
#include "QAD_DirListDlg.h"
#include "QAD_WaitCursor.h"
+#include "SALOMEGUI.h"
#include "SALOMEGUI_OpenWith.h"
#include "SALOMEGUI_StudyPropertiesDlg.h"
#include "SALOMEGUI_TrihedronSizeDlg.h"
#include "SALOMEGUI_CloseDlg.h"
#include "SALOMEGUI_ActivateComponentDlg.h"
+#include "SALOME_Event.hxx"
+
// QT Includes
#include <qlabel.h>
#include <qlayout.h>
#endif
// Open CASCADE Includes
+#include <OSD_SharedLibrary.hxx>
#include <OSD_LoadMode.hxx>
#include <OSD_Function.hxx>
#include <TCollection_AsciiString.hxx>
}
}
}
+ else if ( e->type() == SALOME_EVENT ) {
+ SALOME_Event* aSE = (SALOME_Event*)((QCustomEvent*)e)->data();
+ processEvent( aSE );
+ // Signal the calling thread that the event has been processed
+ aSE->processed();
+ ((QCustomEvent*)e)->setData( 0 );
+ delete aSE;
+ return TRUE;
+ }
return QMainWindow::eventFilter( o, e );
}
+/*!
+ Dispatches <theEvent> to the target component GUI
+*/
+void QAD_Desktop::processEvent( SALOME_Event* theEvent )
+{
+ if ( !theEvent )
+ return;
+ theEvent->Execute();
+}
+
/*!
Creates and initializes the standard file operations
such as 'New/Open/Save/SaveAs/Close' and 'Help'.
QApplication::restoreOverrideCursor();
}
-typedef bool OneDim1(QAD_Desktop*);
-typedef bool OneDim2(QAD_Desktop*, char*);
/*!
Called to define settings of component.
*/
void QAD_Desktop::setSettings()
{
- if (!myActiveComp.isEmpty()) {
- OSD_Function osdF = mySharedLibrary.DlSymb("SetSettings");
- if ( osdF != NULL )
- if (_islibso)
- {
- OneDim1 (*f1) = (bool (*) (QAD_Desktop*)) osdF;
- (*f1)(this);
- }
- else
- {
- QString Component =mapComponentName[myActiveComp];
- OneDim2 (*f1) = (bool (*) (QAD_Desktop*, char*)) osdF;
- (*f1)(this, (char*)Component.latin1());
- }
+ SALOMEGUI* anActiveGUI = getActiveGUI();
+ if ( anActiveGUI ) {
+ if (_islibso)
+ anActiveGUI->SetSettings( this );
+ else {
+ QString Component = mapComponentName[myActiveComp];
+ anActiveGUI->SetSettings( this, (char*)Component.latin1() );
+ }
}
}
int nbToolbars = 0;
if (myActiveMenus)
nbToolbars = myActiveMenus->getToolBarList().count();
- /* Open Shared Library */
- mySharedLibrary = OSD_SharedLibrary();
- _islibso = false;
-
- QString ComponentLib;
- QCString libs;
- QFileInfo fileInfo ;
- QString fileString ;
- QString dir;
-
- if ( libs = getenv("LD_LIBRARY_PATH")) {
- // MESSAGE ( " LD_LIBRARY_PATH : " << libs );
- QStringList dirList = QStringList::split( SEPARATOR, libs, false ); // skip empty entries
- for ( int i = dirList.count()-1; i >= 0; i-- ) {
- dir = dirList[ i ];
-#ifdef WNT
- fileString = QAD_Tools::addSlash( dir ) + "lib" + Component + "GUI.dll" ;
-#else
- fileString = QAD_Tools::addSlash( dir ) + "lib" + Component + "GUI.so" ;
-#endif
-
- fileInfo.setFile(fileString) ;
- if (fileInfo.exists()) {
- // MESSAGE ( " GUI library = " << fileString );
- ComponentLib = fileInfo.fileName() ;
- _islibso = true;
- break;
- }
- }
- }
-
- if (!_islibso) // component GUI could be in PyQt, use generic library
- {
- MESSAGE("GUI library not found, trying generic library for PyQt GUI");
- bool found = false;
- if (dir = getenv("KERNEL_ROOT_DIR"))
- {
- dir = QAD_Tools::addSlash(dir) ;
- dir = dir + "lib" ;
- dir = QAD_Tools::addSlash(dir) ;
- dir = dir + "salome" ;
- dir = QAD_Tools::addSlash(dir) ;
-#ifdef WNT
- dir = dir + "libSalomePyQtcmodule.dll" ;
-#else
- dir = dir + "libSalomePyQtcmodule.so" ;
-#endif
- MESSAGE ( " GUI library = " << dir );
- fileInfo.setFile(dir) ;
- if (fileInfo.exists())
- {
- ComponentLib = fileInfo.fileName() ;
- found = true;
- }
- }
- if ( !found )
- {
- QMessageBox::critical( this,
- tr("ERR_ERROR"),
- tr("ERR_LIBGUI" ).arg(Component) );
- return false;
- }
- }
- mySharedLibrary.SetName(TCollection_AsciiString((char*)ComponentLib.latin1()).ToCString());
- ok = mySharedLibrary.DlOpen(OSD_RTLD_LAZY);
- if (!ok) {
- wc.stop();
- QMessageBox::critical( this,
- tr("ERR_ERROR"),
- tr( mySharedLibrary.DlError() ) );
+ // san - avoid loading component GUI library multiple times
+ QString aUserName( getComponentUserName( Component ) );
+
+ SALOMEGUI* anActiveGUI = getComponentGUI(aUserName);
+ if ( !anActiveGUI )
return false;
- }
/* SETTINGS */
- OSD_Function osdF = mySharedLibrary.DlSymb("SetSettings");
- if ( osdF != NULL )
- if (_islibso)
- {
- OneDim1 (*f1) = (bool (*) (QAD_Desktop*)) osdF;
- (*f1)(this);
- }
- else
- {
- OneDim2 (*f1) = (bool (*) (QAD_Desktop*, char*)) osdF;
- (*f1)(this, (char*)Component.latin1());
- }
-
-
+ if (_islibso)
+ anActiveGUI->SetSettings( this );
+ else
+ anActiveGUI->SetSettings( this, (char*)Component.latin1() );
/* COMPONENT INTERFACE */
SALOME_ModuleCatalog::Acomponent_ptr aComponent =
*/
void QAD_Desktop::onDispatch(int id)
{
- if (!myActiveComp.isEmpty()) {
- OSD_Function osdF = mySharedLibrary.DlSymb("OnGUIEvent");
- OneDim (*f1) = NULL;
- if ( osdF != NULL ) {
- f1 = (bool (*) (int, QAD_Desktop*)) osdF;
- (*f1)(id,this);
- }
- }
+ SALOMEGUI* anActiveGUI = getActiveGUI();
+ if ( anActiveGUI )
+ anActiveGUI->OnGUIEvent(id,this);
}
/*!
void QAD_Desktop::onKeyPress( QKeyEvent* pe )
{
// MESSAGE ( "QAD_Desktop::onKeyPress" )
- if (!myActiveComp.isEmpty()) {
- OSD_Function osdF = mySharedLibrary.DlSymb("OnKeyPress");
- if ( osdF != NULL ) {
- TwoDim1 (*f1) = (bool (*) (QKeyEvent*, QAD_Desktop*, QAD_StudyFrame*)) osdF;
- (*f1)(pe,this,myActiveStudy->getActiveStudyFrame());
- }
- }
+ SALOMEGUI* anActiveGUI = getActiveGUI();
+ if ( anActiveGUI )
+ anActiveGUI->OnKeyPress(pe,this,myActiveStudy->getActiveStudyFrame());
}
typedef bool TwoDim(QMouseEvent* pe, QAD_Desktop*, QAD_StudyFrame*);
bool QAD_Desktop::onMousePress( QMouseEvent* pe )
{
// MESSAGE ( "QAD_Desktop::onMousePress" )
- if (!myActiveComp.isEmpty()) {
- OSD_Function osdF = mySharedLibrary.DlSymb("OnMousePress");
- if ( osdF != NULL ) {
- TwoDim (*f1) = (bool (*) (QMouseEvent*, QAD_Desktop*, QAD_StudyFrame*)) osdF;
- return (*f1)(pe,this,myActiveStudy->getActiveStudyFrame());
- }
- }
+ SALOMEGUI* anActiveGUI = getActiveGUI();
+ if ( anActiveGUI )
+ return anActiveGUI->OnMousePress(pe,this,myActiveStudy->getActiveStudyFrame());
return false;
}
*/
void QAD_Desktop::onMouseMove( QMouseEvent* pe )
{
- if (!myActiveComp.isEmpty()) {
- OSD_Function osdF = mySharedLibrary.DlSymb("OnMouseMove");
- if ( osdF != NULL ) {
- TwoDim (*f1) = (bool (*) (QMouseEvent*, QAD_Desktop*, QAD_StudyFrame*)) osdF;
- (*f1)(pe,this,myActiveStudy->getActiveStudyFrame());
- }
- }
+ SALOMEGUI* anActiveGUI = getActiveGUI();
+ if ( anActiveGUI )
+ anActiveGUI->OnMouseMove(pe,this,myActiveStudy->getActiveStudyFrame());
}
/*!
return myActiveComp;
}
+SALOMEGUI* QAD_Desktop::getActiveGUI()
+{
+ SALOMEGUI* anActiveGUI = 0;
+ if ( myComponents.find( myActiveComp ) != myComponents.end() )
+ anActiveGUI = myComponents[myActiveComp];
+ return anActiveGUI;
+}
-typedef bool defineP( QString & theContext, QString & theParent, QString & theObject);
+typedef SALOMEGUI* (*ComponentGUI)();
-void QAD_Desktop::definePopup(QString & theContext,
- QString & theParent,
- QString & theObject )
+SALOMEGUI* QAD_Desktop::getComponentGUI( const QString& component )
{
- if (!myActiveComp.isEmpty()) {
- OSD_Function osdF = mySharedLibrary.DlSymb("definePopup");
+ SALOMEGUI* aCompGUI = 0;
+
+ // Load component GUI if requested for the first time
+ if ( myComponents.find( component ) == myComponents.end() ) {
+ OSD_SharedLibrary aSharedLibrary;
+ QString ComponentLib;
+ QCString libs;
+ QFileInfo fileInfo ;
+ QString fileString ;
+ QString dir;
+
+ QAD_WaitCursor wc;
+
+ if ( libs = getenv("LD_LIBRARY_PATH")) {
+ // MESSAGE ( " LD_LIBRARY_PATH : " << libs );
+ QStringList dirList = QStringList::split( SEPARATOR, libs, false ); // skip empty entries
+ for ( int i = dirList.count()-1; i >= 0; i-- ) {
+ dir = dirList[ i ];
+#ifdef WNT
+ fileString = QAD_Tools::addSlash( dir ) + "lib" + getComponentName( component ) + "GUI.dll" ;
+#else
+ fileString = QAD_Tools::addSlash( dir ) + "lib" + getComponentName( component ) + "GUI.so" ;
+#endif
+
+ fileInfo.setFile(fileString) ;
+ if (fileInfo.exists()) {
+ // MESSAGE ( " GUI library = " << fileString );
+ ComponentLib = fileInfo.fileName() ;
+ _islibso = true;
+ break;
+ }
+ }
+ }
+
+ if (!_islibso) // component GUI could be in PyQt, use generic library
+ {
+ MESSAGE("GUI library not found, trying generic library for PyQt GUI");
+ bool found = false;
+ if (dir = getenv("KERNEL_ROOT_DIR"))
+ {
+ dir = QAD_Tools::addSlash(dir) ;
+ dir = dir + "lib" ;
+ dir = QAD_Tools::addSlash(dir) ;
+ dir = dir + "salome" ;
+ dir = QAD_Tools::addSlash(dir) ;
+#ifdef WNT
+ dir = dir + "libSalomePyQtcmodule.dll" ;
+#else
+ dir = dir + "libSalomePyQtcmodule.so" ;
+#endif
+ MESSAGE ( " GUI library = " << dir );
+ fileInfo.setFile(dir) ;
+ if (fileInfo.exists())
+ {
+ ComponentLib = fileInfo.fileName() ;
+ found = true;
+ }
+ }
+ if ( !found )
+ {
+ QMessageBox::critical( this,
+ tr("ERR_ERROR"),
+ tr("ERR_LIBGUI" ).arg(component) );
+ return aCompGUI;
+ }
+ }
+
+ aSharedLibrary.SetName(TCollection_AsciiString((char*)ComponentLib.latin1()).ToCString());
+ bool ok = aSharedLibrary.DlOpen(OSD_RTLD_LAZY);
+ if (!ok) {
+ wc.stop();
+ QMessageBox::critical( this,
+ tr("ERR_ERROR"),
+ tr( aSharedLibrary.DlError() ) );
+ return aCompGUI;
+ }
+
+ OSD_Function osdF = aSharedLibrary.DlSymb("GetComponentGUI");
if ( osdF != NULL ) {
- defineP (*f1) = (bool (*) (QString &, QString &, QString &)) osdF;
- (*f1)(theContext, theParent, theObject);
+ ComponentGUI f1 = (SALOMEGUI* (*) ()) osdF;
+ SALOMEGUI* aCompGUI = (*f1)();
+ if ( aCompGUI )
+ myComponents.insert( component, aCompGUI );
+ else {
+ wc.stop();
+ QMessageBox::critical( this,
+ tr("ERR_ERROR"),
+ tr("ERR_LIBGUI" ).arg(component) );
+ return aCompGUI;
+ }
+ }
+ else {
+ wc.stop();
+ QMessageBox::critical( this,
+ tr("ERR_ERROR"),
+ tr("ERR_LIBGUI" ).arg(component) );
+ return aCompGUI;
}
}
+ aCompGUI = myComponents[component];
+ return aCompGUI;
+}
+
+
+void QAD_Desktop::definePopup(QString & theContext,
+ QString & theParent,
+ QString & theObject )
+{
+ SALOMEGUI* anActiveGUI = getActiveGUI();
+ if ( anActiveGUI )
+ anActiveGUI->DefinePopup(theContext, theParent, theObject);
}
}
-typedef bool activeStudyChanged(QAD_Desktop*);
-typedef void deactivate();
-
void QAD_Desktop::onActiveStudyChanged()
{
- if (!myActiveComp.isEmpty()) {
- OSD_Function osdF = mySharedLibrary.DlSymb("activeStudyChanged");
- if ( osdF != NULL ) {
- activeStudyChanged (*f1) = (bool (*) (QAD_Desktop*)) osdF;
- (*f1)(this);
- }
- }
+ SALOMEGUI* anActiveGUI = getActiveGUI();
+ if ( anActiveGUI )
+ anActiveGUI->ActiveStudyChanged(this);
}
void QAD_Desktop::deactivateComponent()
{
- if (!myActiveComp.isEmpty()) {
- OSD_Function osdF = mySharedLibrary.DlSymb("deactivate");
- if ( osdF != NULL ) {
- deactivate (*f1) = (void (*)()) osdF;
- (*f1)();
- }
- }
+ SALOMEGUI* anActiveGUI = getActiveGUI();
+ if ( anActiveGUI )
+ anActiveGUI->Deactivate();
}
-typedef bool customP(QAD_Desktop*, QPopupMenu*, const QString & theContext,
- const QString & theParent, const QString & theObject);
/*!
Custom popup ( GUI Library )
*/
void QAD_Desktop::customPopup(QPopupMenu* popup, const QString & theContext,
const QString & theParent, const QString & theObject)
{
- if (!myActiveComp.isEmpty()) {
- OSD_Function osdF = mySharedLibrary.DlSymb("customPopup");
- if ( osdF != NULL ) {
- customP (*f1) = (bool (*) (QAD_Desktop*, QPopupMenu*, const QString &,
- const QString &, const QString &)) osdF;
- (*f1)(this, popup, theContext, theParent, theObject);
- }
- }
+ SALOMEGUI* anActiveGUI = getActiveGUI();
+ if ( anActiveGUI )
+ anActiveGUI->CustomPopup(this, popup, theContext, theParent, theObject);
}
void QAD_Desktop::onObjectBrowser()
#include <qfiledialog.h>
#include <qtoolbutton.h>
-// Open CASCADE Includes
-#include <OSD_SharedLibrary.hxx>
-
class QAD_XmlHandler;
+class SALOMEGUI;
+class SALOME_Event;
class QAD_EXPORT QAD_Desktop : public QMainWindow
{
QAD_Menus* getActiveMenus() {return myActiveMenus;}
QAD_OperatorMenus* getOperatorMenus() {return myOperatorMenus;}
- const OSD_SharedLibrary& getHandle() const {return mySharedLibrary;}// never return sych objects "by value"
const QString& getActiveComponent() const;
+ SALOMEGUI* getActiveGUI();
+ SALOMEGUI* getComponentGUI( const QString& ); // accepts component`s user name
SALOME_NamingService* getNameService() {return myNameService;}
Engines::Component_var getEngine(const char *containerName,
QMap<QString,QString> mapComponentName;
+private:
+ void processEvent( SALOME_Event* );
+
+private:
+ typedef QMap<QString, SALOMEGUI*> ComponentMap;
+
private:
static QAD_ResourceMgr* resourceMgr;
static QPalette* palette;
void createActions();
void updateActions();
- OSD_SharedLibrary mySharedLibrary;
QAD_XmlHandler* myXmlHandler;
QString myActiveComp;
SALOME_NamingService* myNameService;
QComboBox * myCombo;
bool myQueryClose;
bool _islibso;
+
+ ComponentMap myComponents;
};
/********************************************************************
#define UC_CLEAR_ID 1000014
#define UC_SET_CURRENT_ID 1000016
+
+#ifdef _DEBUG_
+static int MYDEBUG = 0;
+#else
+static int MYDEBUG = 0;
+#endif
+
+
/*!
Small button which updates Object Browser's contents
*/
myListViewMap[ RefSOEntry ].append( Item );
}
else {
- MESSAGE("QAD_ObjectBrowser::Update : noname item: "<<CSO->GetID());
+ if(MYDEBUG) MESSAGE("QAD_ObjectBrowser::Update : noname item: "<<CSO->GetID());
}
} else {
// getting Value
myListViewMap[ CSOEntry ].append( Item );
}
else {
- MESSAGE("QAD_ObjectBrowser::Update : noname item: "<<CSO->GetID());
+ if(MYDEBUG) MESSAGE("QAD_ObjectBrowser::Update : noname item: "<<CSO->GetID());
}
// adding other attributes
if (Item) {
QString msg;
QAD_ResourceMgr* resMgr = QAD_Desktop::createResourceManager();
if ( resMgr ) {
- MESSAGE ( " Component " << aName->Value() )
- MESSAGE ( " Icon " << aPixmap->GetPixMap() )
+ if(MYDEBUG) MESSAGE ( " Component " << aName->Value() );
+ if(MYDEBUG) MESSAGE ( " Icon " << aPixmap->GetPixMap() );
if(resMgr->loadResources( QAD_Application::getDesktop()->getComponentName(QString(aName->Value())), msg )) {
QPixmap icon ( resMgr->loadPixmap( QAD_Application::getDesktop()->getComponentName(QString(aName->Value())),
tr(aPixmap->GetPixMap()) /*tr( "ICON_OBJBROWSER_" + theComponent )*/ ));
// Module : SALOME
// $Header$
-using namespace std;
#include "QAD_PyEditor.h"
#include "QAD_PyInterp.h"
#include "QAD_Application.h"
#include "QAD_Config.h"
#include "QAD_Tools.h"
#include "QAD_MessageBox.h"
-//#include "QAD_RightFrame.h"
#include <qapplication.h>
#include <qmap.h>
#include <qclipboard.h>
+#include <qthread.h>
// NRI : Temporary added
// IDL Headers
#include CORBA_SERVER_HEADER(SALOMEDS_Attributes)
//NRI
+using namespace std;
+
+
+#ifdef _DEBUG_
+static int MYDEBUG = 1;
+#else
+static int MYDEBUG = 0;
+#endif
+
+
#define SIZEPR 4
enum { IdCopy, IdPaste, IdClear, IdSelectAll };
+
+static QString PROMPT = ">>> ";
+
+
+class TInitEditorThread : public QThread
+{
+public:
+ TInitEditorThread(QAD_PyInterp*& theInterp,
+ QMutex* theStudyMutex, QMutex* theMutex,
+ QAD_PyEditor* theListener):
+ myInterp(theInterp),
+ myMutex(theMutex),
+ myStudyMutex(theStudyMutex),
+ myListener(theListener)
+ {
+ QThread::postEvent(myListener, new QCustomEvent(QAD_PyEditor::SET_WAIT_CURSOR));
+ }
+
+ virtual ~TInitEditorThread(){}
+
+protected:
+ virtual void run(){
+ ThreadLock anEditorLock(myMutex,"TInitEditorThread::anEditorLock");
+ ThreadLock aStudyLock(myStudyMutex,"TInitEditorThread::aStudyLock");
+ ThreadLock aPyLock = GetPyThreadLock("TInitEditorThread::aPyLock");
+ if(MYDEBUG) MESSAGE("TInitEditorThread::run() - myInterp = "<<myInterp<<"; myMutex = "<<myMutex);
+ QThread::postEvent(myListener, new QCustomEvent(QAD_PyEditor::INITIALIZE));
+ QThread::postEvent(myListener, new QCustomEvent(QAD_PyEditor::PYTHON_OK));
+ QThread::postEvent(myListener, new QCustomEvent(QAD_PyEditor::UNSET_CURSOR));
+ }
+
+private:
+ QMutex* myMutex;
+ QMutex* myStudyMutex;
+ QAD_PyInterp*& myInterp;
+ QAD_PyEditor* myListener;
+};
+
+
+class TExecCommandThread : public QThread
+{
+public:
+ TExecCommandThread(QAD_PyInterp*& theInterp,
+ QMutex* theStudyMutex, QMutex* theMutex,
+ QAD_PyEditor* theListener):
+ myInterp(theInterp),
+ myMutex(theMutex),
+ myStudyMutex(theStudyMutex),
+ myListener(theListener),
+ myCommand("")
+ {
+ QThread::postEvent(myListener, new QCustomEvent(QAD_PyEditor::SET_WAIT_CURSOR));
+ }
+
+ virtual ~TExecCommandThread() {}
+
+ void exec(const char* theCommand){
+ myCommand = theCommand;
+ start();
+ }
+
+protected:
+ virtual void run(){
+ if(myCommand != ""){
+ ThreadLock anEditorLock(myMutex,"TExecCommandThread::anEditorLock");
+ //ThreadLock aStudyLock(myStudyMutex,"TExecCommandThread::aStudyLock");
+ ThreadLock aPyLock = GetPyThreadLock("TExecCommandThread::aPyLock");
+ int ret = myInterp->run( myCommand.latin1() );
+ if(MYDEBUG) MESSAGE("TExecCommand::run() - myInterp = "<<myInterp<<"; myCommand = '"<<myCommand.latin1()<<"' - "<<ret);
+ int anId = QAD_PyEditor::PYTHON_OK;
+ if(ret < 0)
+ anId = QAD_PyEditor::PYTHON_ERROR;
+ if(ret > 0)
+ anId = QAD_PyEditor::PYTHON_INCOMPLETE;
+ myListener->viewport()->unsetCursor();
+ QThread::postEvent(myListener, new QCustomEvent(anId));
+ QThread::postEvent(myListener, new QCustomEvent(QAD_PyEditor::UNSET_CURSOR));
+ }
+ }
+
+private:
+ QMutex* myMutex;
+ QMutex* myStudyMutex;
+ QAD_PyInterp*& myInterp;
+ QAD_PyEditor* myListener;
+ QString myCommand;
+};
+
+
/*!
Constructor
*/
-QAD_PyEditor::QAD_PyEditor(QAD_PyInterp* interp,
- QWidget *parent, const char *name)
- : QMultiLineEdit(parent,name)
+QAD_PyEditor::QAD_PyEditor(QAD_PyInterp*& theInterp, QMutex* theMutex,
+ QWidget *theParent, const char* theName):
+ QTextEdit(theParent,theName),
+ myStudyMutex(theMutex),
+ myInitEditorMutex(new QMutex),
+ myExecCommandMutex(new QMutex),
+ myInterp(theInterp),
+ myInitEditorThread(0),
+ myExecCommandThread(0)
{
QString fntSet = QAD_CONFIG->getSetting("Viewer:ConsoleFont");
QFont myFont = QAD_Tools::stringToFont( fntSet );
// QFont myFont("Courier",11);
setFont(myFont);
- _interp = interp;
- string banner = _interp->getbanner();
- setText(banner.c_str());
- _isInHistory = false;
- _currentPrompt = ">>> ";
- // put error messages of interpreter if they exist.
- _buf.truncate(0);
- setText(_interp->getverr());
- setText(_currentPrompt);
+ setTextFormat(QTextEdit::PlainText);
+
+ myInitEditorThread = new TInitEditorThread(myInterp,myStudyMutex,myInitEditorMutex,this);
+ myExecCommandThread = new TExecCommandThread(myInterp,myStudyMutex,myExecCommandMutex,this);
+
+ _currentPrompt = PROMPT;
setPalette( QAD_Application::getPalette(true) );
setWordWrap(NoWrap);
+
connect(this,SIGNAL(returnPressed()),this,SLOT(handleReturn()) );
}
+
+void QAD_PyEditor::Init()
+{
+ myInitEditorThread->start();
+}
+
+
/*!
Destructor
*/
QAD_PyEditor::~QAD_PyEditor()
{
+ if(MYDEBUG) MESSAGE("QAD_PyEditor::~QAD_PyEditor()");
+ {
+ {
+ ThreadLock aLock(myInitEditorMutex,"myInitEditorMutex");
+ delete myInitEditorThread;
+ }
+ delete myInitEditorMutex;
+ }
+ {
+ {
+ ThreadLock aLock(myExecCommandMutex,"myExecCommandMutex");
+ delete myExecCommandThread;
+ }
+ delete myExecCommandMutex;
+ }
}
/*!
*/
void QAD_PyEditor::setText(QString s)
{
-// MESSAGE("setText");
- int line=numLines()-1;
- int col=lineLength(line);
- insertAt(s,line,col);
- int n = numLines()-1;
- setCursorPosition( n, textLine(n).length());
+ int para=paragraphs()-1;
+ int col=paragraphLength(para);
+ insertAt(s,para,col);
+ int n = paragraphs()-1;
+ setCursorPosition( n, paragraphLength(n));
}
/*!
*/
void QAD_PyEditor::handleReturn()
{
- QApplication::setOverrideCursor( Qt::waitCursor );
int ret;
- int line=numLines()-2;
+ int para=paragraphs()-2;
// NRI : Temporary added
SALOMEDS::Study_var aStudy = QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument();
}
// NRI
- _buf.append(textLine(line).remove(0,SIZEPR));
- ret = _interp->run(_buf);
- if(ret <= 0)
- {
- _buf.truncate(0);
- setText(_interp->getvout());
- setText(_interp->getverr());
- _currentPrompt = ">>> ";
- setText(_currentPrompt);
- }
- if(ret == 1)
- {
- _buf.append("\n");
- _currentPrompt = "... ";
- setText(_currentPrompt);
- }
- _isInHistory = false;
- QApplication::restoreOverrideCursor();
+ _buf.append(text(para).remove(0,SIZEPR));
+ _buf.truncate( _buf.length() - 1 );
+ setReadOnly( true );
+ myExecCommandThread->exec(_buf.latin1());
}
/*
QPopupMenu *popup = new QPopupMenu( this );
QMap<int, int> idMap;
- int line1, col1, line2, col2;
- getMarkedRegion(&line1, &col1, &line2, &col2);
- bool allSelected = getMarkedRegion(&line1, &col1, &line2, &col2) &&
- line1 == 0 && line2 == numLines()-1 && col1 == 0 && col2 == lineLength(line2);
+ int para1, col1, para2, col2;
+ getSelection(¶1, &col1, ¶2, &col2);
+ bool allSelected = hasSelectedText() &&
+ para1 == 0 && para2 == paragraphs()-1 && col1 == 0 && para2 == paragraphLength(para2);
int id;
id = popup->insertItem( tr( "EDIT_COPY_CMD" ) );
idMap.insert(IdCopy, id);
popup->insertSeparator();
id = popup->insertItem( tr( "EDIT_SELECTALL_CMD" ) );
idMap.insert(IdSelectAll, id);
- popup->setItemEnabled( idMap[ IdCopy ], hasMarkedText() );
+ popup->setItemEnabled( idMap[ IdCopy ], hasSelectedText() );
popup->setItemEnabled( idMap[ IdPaste ],
!isReadOnly() && (bool)QApplication::clipboard()->text().length() );
popup->setItemEnabled( idMap[ IdSelectAll ],
}
else if ( r == idMap[ IdClear ] ) {
clear();
- string banner = _interp->getbanner();
- setText(banner.c_str());
+ ThreadLock aPyLock = GetPyThreadLock();
+ setText(myInterp->getbanner().c_str());
setText(_currentPrompt);
}
else if ( r == idMap[ IdSelectAll ] ) {
return;
}
else {
- QMultiLineEdit::mousePressEvent(event);
+ QTextEdit::mousePressEvent(event);
}
}
void QAD_PyEditor::mouseReleaseEvent ( QMouseEvent * e )
{
// MESSAGE("mouseReleaseEvent");
- int curLine, curCol; // for cursor position
- int endLine, endCol; // for last edited line
- getCursorPosition(&curLine, &curCol);
- endLine = numLines() -1;
+ int curPara, curCol; // for cursor position
+ int endPara, endCol; // for last edited line
+ getCursorPosition(&curPara, &curCol);
+ endPara = paragraphs() -1;
if (e->button() != MidButton)
- QMultiLineEdit::mouseReleaseEvent(e);
- else if ((curLine == endLine) && (curCol >= SIZEPR))
- QMultiLineEdit::mouseReleaseEvent(e);
+ QTextEdit::mouseReleaseEvent(e);
+ else if ((curPara == endPara) && (curCol >= SIZEPR))
+ QTextEdit::mouseReleaseEvent(e);
}
/*!
int curLine, curCol; // for cursor position
int endLine, endCol; // for last edited line
getCursorPosition(&curLine, &curCol);
- endLine = numLines() -1;
+ endLine = paragraphs() -1;
//MESSAGE("current position " << curLine << ", " << curCol);
//MESSAGE("last line " << endLine);
//MESSAGE(e->key());
{
case 0 :
{
- if (curLine <endLine)
- {
- setCursorPosition(endLine, SIZEPR);
- end();
- }
- QMultiLineEdit::keyPressEvent( e );
+ if (curLine <endLine || curCol < SIZEPR )
+ moveCursor(QTextEdit::MoveEnd, false);
+ QTextEdit::keyPressEvent( e );
break;
}
case Key_Return:
case Key_Enter:
{
if (curLine <endLine)
- {
- setCursorPosition(endLine, SIZEPR);
- }
- end();
- QMultiLineEdit::keyPressEvent( e );
+ moveCursor(QTextEdit::MoveEnd, false);
+ else
+ moveCursor(QTextEdit::MoveLineEnd, false);
+ QTextEdit::keyPressEvent( e );
break;
}
case Key_Up:
{
// if Cntr+Key_Up event then move cursor up
if (ctrlPressed) {
- QMultiLineEdit::cursorUp( );
+ moveCursor(QTextEdit::MoveUp, false);
}
// if Shift+Key_Up event then move cursor up and select the text
else if ( shftPressed && curLine > 0 ){
- setCursorPosition(curLine-1, curCol, true);
+ moveCursor(QTextEdit::MoveUp, true);
}
// scroll the commands stack up
else {
if (! _isInHistory)
{
_isInHistory = true;
- _currentCommand = textLine(endLine).remove(0,SIZEPR);
+ _currentCommand = text(endLine).remove(0,SIZEPR);
+ _currentCommand.truncate( _currentCommand.length() - 1 );
SCRUTE(_currentCommand);
}
- QString previousCommand = _interp->getPrevious();
+ QString previousCommand = myInterp->getPrevious();
if (previousCommand.compare(BEGIN_HISTORY_PY) != 0)
{
- removeLine(endLine);
+ removeParagraph(endLine);
histLine.append(previousCommand);
- insertLine(histLine);
+ insertParagraph(histLine, -1);
}
- endLine = numLines() -1;
- setCursorPosition(endLine, lineLength(endLine));
+ moveCursor(QTextEdit::MoveEnd, false);
}
break;
}
{
// if Cntr+Key_Down event then move cursor down
if (ctrlPressed) {
- QMultiLineEdit::cursorDown( );
+ moveCursor(QTextEdit::MoveDown, false);
}
// if Shift+Key_Down event then move cursor down and select the text
else if ( shftPressed && curLine < endLine ) {
- setCursorPosition(curLine+1, curCol, true);
+ moveCursor(QTextEdit::MoveDown, true);
}
// scroll the commands stack down
else {
QString histLine = _currentPrompt;
- QString nextCommand = _interp->getNext();
+ QString nextCommand = myInterp->getNext();
if (nextCommand.compare(TOP_HISTORY_PY) != 0)
{
- removeLine(endLine);
+ removeParagraph(endLine);
histLine.append(nextCommand);
- insertLine(histLine);
+ insertParagraph(histLine, -1);
}
else
if (_isInHistory)
{
_isInHistory = false;
- removeLine(endLine);
+ removeParagraph(endLine);
histLine.append(_currentCommand);
- insertLine(histLine);
+ insertParagraph(histLine, -1);
}
- endLine = numLines() -1;
- setCursorPosition(endLine, lineLength(endLine));
+ moveCursor(QTextEdit::MoveEnd, false);
}
break;
}
case Key_Left:
{
- if (!shftPressed && isCommand(textLine(curLine)) && curCol <= SIZEPR )
+ if (!shftPressed && isCommand(text(curLine)) && curCol <= SIZEPR )
{
setCursorPosition((curLine -1), SIZEPR);
- end();
+ moveCursor(QTextEdit::MoveLineEnd, false);
}
- else QMultiLineEdit::keyPressEvent( e );
+ else QTextEdit::keyPressEvent( e );
break;
}
case Key_Right:
{
- if (!shftPressed && isCommand(textLine(curLine))
- && curCol < SIZEPR) setCursorPosition(curLine, SIZEPR-1);
- QMultiLineEdit::keyPressEvent( e );
+ if (!shftPressed && isCommand(text(curLine))
+ && curCol < SIZEPR) setCursorPosition(curLine, SIZEPR);
+ QTextEdit::keyPressEvent( e );
break;
}
case Key_Home:
{
- if (isCommand(textLine(curLine)) && curCol <= SIZEPR)
- setCursorPosition(curLine, SIZEPR, shftPressed);
- else setCursorPosition(curLine, 0, shftPressed);
+ horizontalScrollBar()->setValue( horizontalScrollBar()->minValue() );
+ if (isCommand(text(curLine))) {
+ setCursorPosition(curLine, SIZEPR);
+ if ( curCol > SIZEPR && shftPressed )
+ setSelection( curLine, SIZEPR, curLine, curCol );
+ else
+ selectAll( false );
+ }
+ else moveCursor(QTextEdit::MoveLineStart, shftPressed);
break;
}
case Key_End:
{
- setCursorPosition(curLine, textLine(curLine).length(), shftPressed);
+ moveCursor(QTextEdit::MoveLineEnd, shftPressed);
break;
}
case Key_Backspace :
{
if ((curLine == endLine) && (curCol > SIZEPR))
- QMultiLineEdit::keyPressEvent( e );
+ QTextEdit::keyPressEvent( e );
break;
}
case Key_Delete :
{
if ((curLine == endLine) && (curCol > SIZEPR-1))
- QMultiLineEdit::keyPressEvent( e );
+ QTextEdit::keyPressEvent( e );
+ break;
+ }
+ case Key_Insert :
+ {
+ if ( ctrlPressed )
+ copy();
+ else if ( shftPressed ) {
+ moveCursor(QTextEdit::MoveEnd, false);
+ paste();
+ }
+ else
+ QTextEdit::keyPressEvent( e );
break;
}
}
QAD_Application::getDesktop()->onKeyPress( e );
// NRI //
}
+
+void QAD_PyEditor::customEvent(QCustomEvent *e)
+{
+ switch( e->type() ) {
+ case PYTHON_OK:
+ case PYTHON_ERROR:
+ {
+ _buf.truncate(0);
+ ThreadLock aPyLock = GetPyThreadLock();
+ setText(myInterp->getvout().c_str());
+ setText(myInterp->getverr().c_str());
+ _currentPrompt = ">>> ";
+ setText(_currentPrompt);
+ break;
+ }
+ case PYTHON_INCOMPLETE:
+ {
+ _buf.append("\n");
+ _currentPrompt = "... ";
+ setText(_currentPrompt);
+ break;
+ }
+ case INITIALIZE:
+ {
+ setText(myInterp->getbanner().c_str());
+ _buf.truncate(0);
+ break;
+ }
+ case SET_WAIT_CURSOR:
+ {
+ viewport()->setCursor( waitCursor );
+ break;
+ }
+ case UNSET_CURSOR:
+ {
+ viewport()->unsetCursor();
+ break;
+ }
+ default:
+ QTextEdit::customEvent( e );
+ }
+
+ setReadOnly( false );
+ _isInHistory = false;
+}
#ifndef QAD_PyEditor_H
#define QAD_PyEditor_H
-#include <qmultilineedit.h>
+#include <qtextedit.h>
+#include <qevent.h>
+
+class QMutex;
class QAD_PyInterp;
+class TInitEditorThread;
+class TExecCommandThread;
-class QAD_PyEditor : public QMultiLineEdit
+class QAD_PyEditor : public QTextEdit
{
Q_OBJECT
public:
- QAD_PyEditor(QAD_PyInterp* interp, QWidget *parent=0, const char *name=0);
+ enum { PYTHON_OK = QEvent::User + 5000, PYTHON_ERROR, PYTHON_INCOMPLETE,
+ INITIALIZE, SET_WAIT_CURSOR, UNSET_CURSOR };
+
+public:
+ QAD_PyEditor(QAD_PyInterp*& theInterp, QMutex* theMutex,
+ QWidget *theParent = 0, const char* theName = "");
+ virtual void Init();
~QAD_PyEditor();
- void setText(QString s);
+ virtual void setText(QString s);
bool isCommand(const QString& str) const;
protected:
- void keyPressEvent (QKeyEvent * e);
- void mousePressEvent (QMouseEvent * e);
- void mouseReleaseEvent (QMouseEvent * e);
- void dropEvent (QDropEvent *e);
+ virtual void keyPressEvent (QKeyEvent * e);
+ virtual void mousePressEvent (QMouseEvent * e);
+ virtual void mouseReleaseEvent (QMouseEvent * e);
+ virtual void dropEvent (QDropEvent *e);
+ virtual void customEvent (QCustomEvent *e);
public slots:
void handleReturn();
private:
- QAD_PyInterp * _interp;
QString _buf;
QString _currentCommand;
QString _currentPrompt;
bool _isInHistory;
+
+ QAD_PyInterp*& myInterp;
+ QMutex* myStudyMutex;
+ QMutex* myInitEditorMutex;
+ QMutex* myExecCommandMutex;
+ TInitEditorThread* myInitEditorThread;
+ TExecCommandThread* myExecCommandThread;
};
#endif
// Module : SALOME
// $Header$
-using namespace std;
-using namespace std;
#include "QAD_PyInterp.h"
#include "utilities.h"
+using namespace std;
+
+
+#ifdef _DEBUG_
+static int MYDEBUG = 0;
+#else
+static int MYDEBUG = 0;
+#endif
+
+
/*!
* constructor : multi Python interpreter, one per SALOME study.
* calls initialize method defined in base class, which calls virtual methods
*/
QAD_PyInterp::QAD_PyInterp(): PyInterp_base()
{
- initialize();
}
QAD_PyInterp::~QAD_PyInterp()
void QAD_PyInterp::initState()
{
- MESSAGE("QAD_PyInterp::initState");
- salomeAcquireLock(); //acquire python global lock (one for all interpreters)
- _tstate = Py_NewInterpreter(); //create an interpreter and save current state
- SCRUTE(_tstate);
- SCRUTE(PyInterp_base::_argc);
- SCRUTE(PyInterp_base::_argv[0]);
- PySys_SetArgv(PyInterp_base::_argc,PyInterp_base::_argv); // initialize sys.argv
+ _tstate = Py_NewInterpreter(); // create an interpreter and save current state
+ PySys_SetArgv(PyInterp_base::_argc,PyInterp_base::_argv); // initialize sys.argv
+ if(MYDEBUG) MESSAGE("QAD_PyInterp::initState - this = "<<this<<"; _tstate = "<<_tstate);
- if(builtinmodule == NULL)return;
/*
* If builtinmodule has been initialized all the sub interpreters
* will have the same __builtin__ module
*/
- PyObject *m=PyImport_GetModuleDict();
- PyDict_SetItemString(m, "__builtin__", builtinmodule);
- SCRUTE(builtinmodule->ob_refcnt); // builtinmodule reference counter
- _tstate->interp->builtins = PyModule_GetDict(builtinmodule);
- Py_INCREF(_tstate->interp->builtins);
+ if(builtinmodule){
+ PyObject *m = PyImport_GetModuleDict();
+ PyDict_SetItemString(m, "__builtin__", builtinmodule);
+ SCRUTE(builtinmodule->ob_refcnt); // builtinmodule reference counter
+ _tstate->interp->builtins = PyModule_GetDict(builtinmodule);
+ Py_INCREF(_tstate->interp->builtins);
+ }
}
+
void QAD_PyInterp::initContext()
{
- MESSAGE("QAD_PyInterp::initContext");
- PyObject *m;
- m=PyImport_AddModule("__main__"); // interpreter main module (module context)
- if(m == NULL)
- {
- MESSAGE("problem...");
- PyErr_Print();
- ASSERT(0);
- salomeReleaseLock();
- return;
- }
+ PyObject *m = PyImport_AddModule("__main__"); // interpreter main module (module context)
+ if(!m){
+ if(MYDEBUG) MESSAGE("problem...");
+ PyErr_Print();
+ ASSERT(0);
+ return;
+ }
_g = PyModule_GetDict(m); // get interpreter dictionnary context
- SCRUTE(_g);
+ if(MYDEBUG) MESSAGE("QAD_PyInterp::initContext - this = "<<this<<"; _g = "<<_g);
- if(builtinmodule)
- {
- PyDict_SetItemString(_g, "__builtins__", builtinmodule); // assign singleton __builtin__ module
- }
-// Debut modif CCAR
- /*
- * Import special module to change the import mechanism
- */
- m =PyImport_ImportModule("import_hook");
- if(m == NULL){
- MESSAGE("initContext: problem with import_hook import");
+ if(builtinmodule){
+ PyDict_SetItemString(_g, "__builtins__", builtinmodule); // assign singleton __builtin__ module
+ }
+
+ // Debut modif CCAR
+ // Import special module to change the import mechanism
+ PyObjWrapper m1(PyImport_ImportModule("import_hook"));
+ if(!m1){
+ MESSAGE("initContext: problem with import_hook import");
+ PyErr_Print();
+ PyErr_Clear();
+ ASSERT(0);
+ }else{
+ // Call init_shared_modules to initialize the shared import mechanism for modules
+ //that must not be imported twice
+ PyObjWrapper m2(PyObject_CallMethod(m1,"init_shared_modules","O",salome_shared_modules_module));
+ if(!m2){
+ MESSAGE("initContext: problem with init_shared_modules call");
PyErr_Print();
PyErr_Clear();
ASSERT(0);
+ }
}
- /*
- * Call init_shared_modules to initialize the shared import mechanism for modules
- * that must not be imported twice
- */
- if(m != NULL){
- m= PyObject_CallMethod(m,
- "init_shared_modules","O",salome_shared_modules_module);
- if (m == NULL){
- MESSAGE("initContext: problem with init_shared_modules call");
- PyErr_Print();
- PyErr_Clear();
- ASSERT(0);
- }
- }
-// Fin modif CCAR
-
+ // Fin modif CCAR
}
// Module : SALOME
// $Header$
-using namespace std;
-using namespace std;
+
#include "QAD_PyInterp_mono.h"
#include "utilities.h"
+using namespace std;
+
/*!
* constructor : only one Python interpreter, shared within SALOME studies.
* calls initialize method defined in base class, which calls virtual methods
*/
QAD_PyInterp_mono::QAD_PyInterp_mono(): PyInterp_base()
{
- initialize();
}
QAD_PyInterp_mono::~QAD_PyInterp_mono()
void QAD_PyInterp_mono::initState()
{
- salomeAcquireLock(); //acquire python global lock (one for all interpreters)
_tstate = PyThreadState_Get();
PySys_SetArgv(PyInterp_base::_argc,PyInterp_base::_argv); // initialize sys.argv
}
// Module : SALOME
// $Header$
-using namespace std;
#include "QAD_RightFrame.h"
#include "QAD_Application.h"
#include "QAD_Desktop.h"
#include "QAD_StudyFrame.h"
#include "QAD_Tools.h"
+#include "QAD_PyEditor.h"
+#include "QAD_PyInterp.h"
+
#include <qvaluelist.h>
// QT Include
// Open CASCADE Include
#include <OSD_SharedLibrary.hxx>
+using namespace std;
+
/*!
\class QAD_RightFrame QAD_RightFrame.h
\brief Frame window which contains QAD_ViewFrame, QAD_PyInterp and QAD_Message.
/*!
Constructor
*/
-QAD_RightFrame::QAD_RightFrame(QWidget *parent, const char *name,
- QAD_PyInterp* interp, ViewType vt)
- : QAD_Splitter( Qt::Vertical, parent, name )
+QAD_RightFrame::QAD_RightFrame(QWidget *theParent,
+ const char *theTitle, ViewType theTypeView,
+ QAD_PyInterp*& theInterp, QMutex* theMutex):
+ QAD_Splitter( Qt::Vertical, theParent, theTitle ),
+ myViewType(theTypeView),
+ myInterp(theInterp)
{
this->setCompressEnabled( true );
- myViewType = vt;
QAD_Desktop* Desktop = QAD_Application::getDesktop();
int DesktopHeight = Desktop->getMainFrame()->width();
int DesktopWidth = Desktop->getMainFrame()->height();
- _interp = interp;
-
OSD_SharedLibrary SharedLib = OSD_SharedLibrary();
QString ComponentLib;
QCString dir;
QValueList<int> sizes;
myViewFrame->setMinimumSize( 1, 1 );
- vsplitter = new QAD_Splitter( Qt::Horizontal, this );
- vsplitter->setMinimumSize( 1, 1 );
- vsplitter->setCompressEnabled( true );
- myPyEditor = new QAD_PyEditor(_interp, vsplitter ,"Python Interpreter");
+ mySplitter = new QAD_Splitter( Qt::Horizontal, this );
+ mySplitter->setMinimumSize( 1, 1 );
+ mySplitter->setCompressEnabled( true );
+
+ myPyEditor = new QAD_PyEditor(myInterp, theMutex, mySplitter ,"Python Interpreter");
myPyEditor->setMinimumSize( 1, 1 );
- myMessage = new QAD_Message( vsplitter ,"Message");
+ myPyEditor->Init();
+
+ myMessage = new QAD_Message( mySplitter ,"Message");
myMessage->setMinimumSize( 1, 1 );
sizes.append( (int)(0.48 * DesktopHeight) );
sizes.clear();
sizes.append( (int)(0.25 * DesktopWidth) );
sizes.append( (int)(0.25 * DesktopWidth) );
- vsplitter->setSizes( sizes );
+ mySplitter->setSizes( sizes );
}
/*!
*/
QAD_PyInterp* QAD_RightFrame::get_PyInterp(void)
{
- return _interp;
+ return myInterp;
}
/*!
#include "QAD_ViewFrame.h"
#include "QAD_Message.h"
-#include "QAD_PyEditor.h"
#include "QAD_Splitter.h"
-#include "QAD_PyInterp.h"
+
+class QMutex;
+
+class QAD_PyEditor;
+class QAD_PyInterp;
class QAD_EXPORT QAD_RightFrame : public QAD_Splitter
{
public:
- QAD_RightFrame(QWidget *parent, const char *name,
- QAD_PyInterp* interp, ViewType vt);
+ QAD_RightFrame(QWidget *theParent,
+ const char *theTitle, ViewType theTypeView,
+ QAD_PyInterp*& theInterp, QMutex* theMutex);
~QAD_RightFrame();
QAD_ViewFrame* getViewFrame() const;
QAD_ViewFrame* myViewFrame;
QAD_PyEditor* myPyEditor;
QAD_Message* myMessage;
- QAD_Splitter* vsplitter;
- QAD_PyInterp* _interp;
+ QAD_Splitter* mySplitter;
+ QAD_PyInterp*& myInterp;
};
#endif
// Module : SALOME
// $Header$
-using namespace std;
/*!
\class QAD_Study QAD_Study.h
\brief Study for QAD-based application.
#include "QAD_ObjectBrowser.h"
#include "QAD_PyInterp.h"
#include "QAD_Config.h"
+#include "QAD_PyInterp.h"
#include "utilities.h"
// QT Include
#include <qapplication.h>
+#include <qthread.h>
+#include <qmutex.h>
-/*!
- Constructor
-*/
-QAD_Study::QAD_Study(QAD_Application* app,
- SALOMEDS::Study_var aStudy,
- const QString& path ) :
-myOperationState( Undef ),
-myApp( app ),
-myActiveStudyFrame( 0 ),
-myStudyFrameCount( 0 ),
-myPath( path )
-{
- myStudy = aStudy;
+using namespace std;
- myTitle = QAD_Tools::getFileNameFromPath( path, true );
- myIsActive = false;
- myIsSaved = false;
- myIsModified = false;
- myIsReadOnly = false;
+#ifdef _DEBUG_
+static int MYDEBUG = 1;
+#else
+static int MYDEBUG = 0;
+#endif
- myStudyFrames.clear();
- myOperations.clear();
- myStudyFrames.setAutoDelete( true );
- myOperations.setAutoDelete( true );
- myChildWidgets.setAutoDelete( true );
+class TInitStudyThread : public QThread{
+ TInitStudyThread();
+ TInitStudyThread(const TInitStudyThread&);
- /* create python interpreter */
- _interp = new QAD_PyInterp();
- SCRUTE(_interp);
+public:
+ TInitStudyThread(QAD_PyInterp*& theInterp, QMutex* theMutex):
+ myInterp(theInterp),
+ myStudyLock(new ThreadLock(theMutex,"TInitStudyThread::TInitStudyThread"))
+ {}
+ virtual ~TInitStudyThread() {
+ if(myStudyLock)
+ delete myStudyLock;
+ }
- /* create default selection */
- //NRI Selection( "Salome" );
- Selection( QAD_Application::getDesktop()->getComponentUserName( "KERNEL" ) );
+protected:
+ virtual void run(){
+ {
+ ThreadLock aPyLock = GetPyThreadLock("TInitStudyThread::aPyLock");
+ if(MYDEBUG) MESSAGE("TInitStudyThread::run()");
+ myInterp = new QAD_PyInterp();
+ myInterp->initialize();
+ }
+ delete myStudyLock;
+ myStudyLock = NULL;
+ }
+
+private:
+ QAD_PyInterp*& myInterp;
+ ThreadLock* myStudyLock;
+};
- /* create study frame */
- myResult = true;
- createStudyFrame( getNextStudyFrameName() );
- /* set default Undo/Redo limit */
- QAD_ASSERT_DEBUG_ONLY( !myStudy->_is_nil() );
- SALOMEDS::StudyBuilder_var SB = myStudy->NewBuilder();
+/*!
+ Constructor
+*/
+QAD_Study::QAD_Study(QAD_Application* theApp,
+ SALOMEDS::Study_var theStudy,
+ const QString& thePath):
+ myStudy(theStudy),
+ myOperationState(Undef),
+ myApp(theApp),
+ myActiveStudyFrame(0),
+ myStudyFrameCount(0),
+ myPath(thePath),
+ myTitle(QAD_Tools::getFileNameFromPath(thePath,true)),
+ myIsActive(false),
+ myIsSaved(false),
+ myIsModified(false),
+ myIsReadOnly(false),
+ myResult(true),
+ myInterp(0),
+ myInitStudyThread(0),
+ myMutex(new QMutex())
+{
+ myStudyFrames.setAutoDelete( true );
+ myOperations.setAutoDelete( true );
+ myChildWidgets.setAutoDelete( true );
+
+ /* create default selection */
+ //NRI Selection( "Salome" );
+ Selection( QAD_Application::getDesktop()->getComponentUserName( "KERNEL" ) );
+
+ /* create python interpreter */
+ myInitStudyThread = new TInitStudyThread(myInterp,myMutex);
+ myInitStudyThread->start();
+
+ /* create study frame */
+ createStudyFrame( getNextStudyFrameName() );
+
+ /* set default Undo/Redo limit */
+ QAD_ASSERT_DEBUG_ONLY( !myStudy->_is_nil() );
+ SALOMEDS::StudyBuilder_var SB = myStudy->NewBuilder();
+
+ int aLocked = myStudy->GetProperties()->IsLocked();
+ if (aLocked) myStudy->GetProperties()->SetLocked(false);
+ SB->UndoLimit(QAD_Desktop::getUndoLevel());
+ if (aLocked) myStudy->GetProperties()->SetLocked(true);
+}
- int aLocked = myStudy->GetProperties()->IsLocked();
- if (aLocked) myStudy->GetProperties()->SetLocked(false);
- SB->UndoLimit(QAD_Desktop::getUndoLevel());
- if (aLocked) myStudy->GetProperties()->SetLocked(true);
+void QAD_Study::Init()
+{
}
+
/*!
Destructor
*/
close();
//SRN: added - clear selection in case the study will be loaded again so the title will coincide
SALOME_Selection::RemoveSelection( QString(myTitle + "_" + mySelection) );
+ {
+ {
+ ThreadLock aLock(myMutex,"QAD_Study::~QAD_Study()");
+ delete myInitStudyThread;
+ }
+ delete myMutex;
+ }
}
/*!
*/
void QAD_Study::onStudyFrameActivated( QAD_StudyFrame* activeStudyFrame )
{
- static int IS_FIRST_STUDY = 1;
- if(IS_FIRST_STUDY){ //for normally initialize "salome.py and ..."
- _interp->run(""); IS_FIRST_STUDY = 0;
- }
+// static int IS_FIRST_STUDY = 1;
+// if(IS_FIRST_STUDY){ //for normally initialize "salome.py and ..."
+// _interp->run(""); IS_FIRST_STUDY = 0;
+// }
// bool found = false;
for ( QAD_StudyFrame* studyframe = myStudyFrames.first(); studyframe; studyframe = myStudyFrames.next() ) {
if ( studyframe == activeStudyFrame) { /* one of my study frames */
if ( theViewType == VIEW_OCC) {
// MESSAGE ("Create Study Frame for OCC viewer");
sf = new QAD_StudyFrame ( this, parent->getMainFrame(),
- title, _interp, VIEW_OCC );
+ title, VIEW_OCC,
+ myInterp, myMutex );
Standard_CString name = strdup(sf->title().latin1());
anAttr = aStudyBuilder->FindOrCreateAttribute(newObj, "AttributeName");
else if ( theViewType == VIEW_VTK) {
// MESSAGE ("Create Study Frame for VTK viewer");
sf = new QAD_StudyFrame ( this, parent->getMainFrame(),
- title, _interp, VIEW_VTK );
+ title, VIEW_VTK,
+ myInterp, myMutex );
Standard_CString name = strdup(sf->title().latin1());
anAttr = aStudyBuilder->FindOrCreateAttribute(newObj, "AttributeName");
aName = SALOMEDS::AttributeName::_narrow(anAttr);
else if ( theViewType == VIEW_GRAPHSUPERV) {
//MESSAGE ("Create Study Frame for SUPER`VISOR Graph");
sf = new QAD_StudyFrame ( this, parent->getMainFrame(),
- title, _interp, VIEW_GRAPHSUPERV );
+ title, VIEW_GRAPHSUPERV,
+ myInterp, myMutex );
Standard_CString name = strdup(sf->title().latin1());
anAttr = aStudyBuilder->FindOrCreateAttribute(newObj, "AttributeName");
aName = SALOMEDS::AttributeName::_narrow(anAttr);
}
else if ( theViewType == VIEW_PLOT2D ) {
sf = new QAD_StudyFrame ( this, parent->getMainFrame(),
- title, _interp, VIEW_PLOT2D );
+ title, VIEW_PLOT2D,
+ myInterp, myMutex );
Standard_CString name = strdup(sf->title().latin1());
anAttr = aStudyBuilder->FindOrCreateAttribute(newObj, "AttributeName");
aName = SALOMEDS::AttributeName::_narrow(anAttr);
*/
QAD_PyInterp* QAD_Study::get_PyInterp(void)
{
- return _interp;
+ return myInterp;
}
/*!
#include <qstring.h>
class QAD_Application;
+
+class QMutex;
class QAD_PyInterp;
+class TInitStudyThread;
class QAD_EXPORT QAD_Study : public QObject
{
QAD_Study(QAD_Application* app,
SALOMEDS::Study_var aStudy,
const QString& title);
+ virtual void Init();
~QAD_Study();
/* Event filter */
bool myIsModified;
bool myIsReadOnly;
bool myResult;
- QAD_PyInterp* _interp;
+
+ QMutex* myMutex;
+ QAD_PyInterp* myInterp;
+ TInitStudyThread* myInitStudyThread;
};
#endif
// Module : SALOME
// $Header$
-using namespace std;
/*!
\class QAD_StudyFrame QAD_StudyFrame.h
\brief Frame window which contains QAD_LeftFrame and QAD_RightFrame.
#include "QAD_StudyFrame.h"
#include "QAD_RightFrame.h"
#include "QAD_LeftFrame.h"
+#include "QAD_Splitter.h"
#include "QAD_Application.h"
#include "QAD_Desktop.h"
#include "QAD_Study.h"
#include "QAD_ObjectBrowser.h"
+#include "QAD_PyInterp.h"
+
#include <qvaluelist.h>
+using namespace std;
+
/*!
Constructor
*/
-QAD_StudyFrame::QAD_StudyFrame(QAD_Study* study, QWidget* parent, const QString& title,
- QAD_PyInterp* interp, ViewType typeView) :
- QMainWindow( parent , title, WStyle_NormalBorder |
+QAD_StudyFrame::QAD_StudyFrame(QAD_Study* theStudy, QWidget* theParent,
+ const QString& theTitle, ViewType theTypeView,
+ QAD_PyInterp*& theInterp, QMutex* theMutex):
+ QMainWindow( theParent , theTitle, WStyle_NormalBorder |
WStyle_MinMax | WStyle_SysMenu | WDestructiveClose),
- myStudy(study)
+ myTitle(theTitle),
+ myEntry(""),
+ myTypeView(theTypeView),
+ myStudy(theStudy),
+ myInterp(theInterp)
{
- myTypeView = typeView;
- myTitle = title;
setCaption( myTitle );
setPalette(QAD_Application::getPalette());
- myEntry = "";
- _interp = interp;
-
- s1 = new QAD_Splitter( Qt::Horizontal, this);
- s1->setCompressEnabled( true );
+ mySplitter = new QAD_Splitter( Qt::Horizontal, this);
+ mySplitter->setCompressEnabled( true );
- setCentralWidget( s1 );
- myLeftFrm = new QAD_LeftFrame(study->getStudyDocument(), s1 , title );
- myRightFrm = new QAD_RightFrame( s1, title, _interp, myTypeView);
+ setCentralWidget(mySplitter);
+ myLeftFrm = new QAD_LeftFrame(myStudy->getStudyDocument(), mySplitter, theTitle );
+ myRightFrm = new QAD_RightFrame( mySplitter, theTitle, myTypeView, myInterp, theMutex);
QValueList<int> sizes;
sizes.append( (int)(0.30*QAD_Application::getDesktop()->getMainFrame()->width()) );
sizes.append( (int)(0.50*QAD_Application::getDesktop()->getMainFrame()->width()) );
- s1->setSizes( sizes );
+ mySplitter->setSizes( sizes );
- QAD_ASSERT_DEBUG_ONLY ( parent->inherits("QWorkspaceP") );
- QAD_ASSERT ( QObject::connect( (QWorkspaceP*)parent, SIGNAL(windowActivated(QWidget*)),
+ QAD_ASSERT_DEBUG_ONLY ( theParent->inherits("QWorkspaceP") );
+ QAD_ASSERT ( QObject::connect( (QWorkspaceP*)theParent, SIGNAL(windowActivated(QWidget*)),
this, SLOT(onStudyFrameActivated(QWidget*))) );
}
-/*!
- Constructor
-*/
-QAD_StudyFrame::QAD_StudyFrame(QAD_Study* study, QWidget* parent ) :
- QMainWindow ( parent ),
- myStudy(study)
-{
-}
/*!
Destructor
*/
void QAD_StudyFrame::closeEvent(QCloseEvent* e)
{
+ if ( IsPyLocked() ) {
+ e->ignore();
+ return;
+ }
+
emit sfStudyFrameClosing(this);
}
*/
void QAD_StudyFrame::compressLeft()
{
- s1->compress(myLeftFrm);
+ mySplitter->compress(myLeftFrm);
}
void QAD_StudyFrame::compressRight()
{
- s1->compress(myRightFrm);
+ mySplitter->compress(myRightFrm);
}
void QAD_StudyFrame::unCompressLeft()
{
- s1->unCompress(myLeftFrm);
+ mySplitter->unCompress(myLeftFrm);
}
void QAD_StudyFrame::unCompressRight()
{
- s1->unCompress(myRightFrm);
+ mySplitter->unCompress(myRightFrm);
}
/*!
*/
QAD_PyInterp* QAD_StudyFrame::get_PyInterp(void)
{
- return _interp;
+ return myInterp;
}
#define QAD_StudyFrame_H
#include "QAD.h"
-#include "QAD_Splitter.h"
-#include "QAD_PyInterp.h"
// QT Includes
#include <qwidget.h>
#include <qmainwindow.h>
+class QMutex;
+
class QAD_RightFrame;
class QAD_LeftFrame;
class QAD_Splitter;
class QAD_Study;
+class QAD_PyInterp;
enum ViewType {
VIEW_OCC,
Q_OBJECT
public:
- QAD_StudyFrame(QAD_Study* study,
- QWidget* parent, const QString& title,
- QAD_PyInterp* interp, ViewType typeView);
- QAD_StudyFrame(QAD_Study*,
- QWidget* parent = 0);
+ QAD_StudyFrame(QAD_Study* theStudy, QWidget* theParent,
+ const QString& theTitle, ViewType theTypeView,
+ QAD_PyInterp*& theInterp, QMutex* theMutex);
virtual ~QAD_StudyFrame();
QAD_Study* getStudy() { return myStudy; }
const QString& entry() const;
void setVisible( bool isVisible = true );
- void closeEvent(QCloseEvent* e);
void compressLeft();
void compressRight();
public slots:
void onStudyFrameActivated ( QWidget* );
+
+ protected:
+ virtual void closeEvent ( QCloseEvent* );
private:
ViewType myTypeView;
QAD_LeftFrame* myLeftFrm;
QAD_RightFrame* myRightFrm;
- QAD_Splitter* s1;
- QAD_PyInterp* _interp;
+ QAD_Splitter* mySplitter;
QAD_Study* myStudy;
+ QAD_PyInterp*& myInterp;
};
#endif
//
//
// File : SALOMEGUI.cxx
-// Author : Nicolas REJNERI
+// Author : Sergey ANIKIN
// Module : SALOME
// $Header$
-using namespace std;
-#include <SALOMEconfig.h>
-#include CORBA_SERVER_HEADER(SALOMEDS)
-
-#include "QAD.h"
-#include "QAD_MessageBox.h"
-#include "QAD_Application.h"
-#include "SALOMEGUI_Application.h"
-
-#include <qmainwindow.h>
-#include <qapplication.h>
-
-#include "SALOME_NamingService.hxx"
-
-int main(int argc, char* argv[])
-{
- QApplication a( argc, argv );
-
- // Setting up the CORBA environment
- // Initializing omniORB
- SALOME_NamingService * name_service;
- CORBA::ORB_var orb;
-
- // orb = CORBA::ORB_init(argc, argv, "omniORB4");
- orb = CORBA::ORB_init(argc, argv, "omniORB3");
-
- // Get the reference the server.
- name_service = new SALOME_NamingService(orb);
-
- QAD_ASSERT ( QObject::connect( &a, SIGNAL(lastWindowClosed()), &a, SLOT(quit()) ) );
-
- /* Initialize the desktop and 'SALOMEGUI' application */
- SALOMEGUI_Application* app =
- new SALOMEGUI_Application ( "MDTV-Standard", "HDF","hdf" );
-
- if ( !SALOMEGUI_Application::addToDesktop ( app, name_service ) )
- {
- QAD_MessageBox::error1 ( 0,
- QObject::tr("ERR_ERROR"),
- QObject::tr("ERR_APP_INITFAILED"),
- QObject::tr("BUT_OK") );
- return -1;
- }
-
- QPalette pal;
- QColorGroup cg;
- cg.setColor( QColorGroup::Foreground, Qt::black );
- cg.setColor( QColorGroup::Button, QColor( 192, 192, 192) );
- cg.setColor( QColorGroup::Light, Qt::white );
- cg.setColor( QColorGroup::Midlight, QColor( 223, 223, 223) );
- cg.setColor( QColorGroup::Dark, QColor( 96, 96, 96) );
- cg.setColor( QColorGroup::Mid, QColor( 128, 128, 128) );
- cg.setColor( QColorGroup::Text, Qt::black );
- cg.setColor( QColorGroup::BrightText, Qt::white );
- cg.setColor( QColorGroup::ButtonText, Qt::black );
- cg.setColor( QColorGroup::Base, Qt::white );
- cg.setColor( QColorGroup::Background, QColor( 192, 192, 192) );
- cg.setColor( QColorGroup::Shadow, Qt::black );
- cg.setColor( QColorGroup::Highlight, QColor( 0, 0, 128) );
- cg.setColor( QColorGroup::HighlightedText, Qt::white );
- pal.setActive( cg );
- cg.setColor( QColorGroup::Foreground, Qt::black );
- cg.setColor( QColorGroup::Button, QColor( 192, 192, 192) );
- cg.setColor( QColorGroup::Light, Qt::white );
- cg.setColor( QColorGroup::Midlight, QColor( 220, 220, 220) );
- cg.setColor( QColorGroup::Dark, QColor( 96, 96, 96) );
- cg.setColor( QColorGroup::Mid, QColor( 128, 128, 128) );
- cg.setColor( QColorGroup::Text, Qt::black );
- cg.setColor( QColorGroup::BrightText, Qt::white );
- cg.setColor( QColorGroup::ButtonText, Qt::black );
- cg.setColor( QColorGroup::Base, Qt::white );
- cg.setColor( QColorGroup::Background, QColor( 192, 192, 192) );
- cg.setColor( QColorGroup::Shadow, Qt::black );
- cg.setColor( QColorGroup::Highlight, QColor( 0, 0, 128) );
- cg.setColor( QColorGroup::HighlightedText, Qt::white );
- pal.setInactive( cg );
- cg.setColor( QColorGroup::Foreground, QColor( 128, 128, 128) );
- cg.setColor( QColorGroup::Button, QColor( 192, 192, 192) );
- cg.setColor( QColorGroup::Light, Qt::white );
- cg.setColor( QColorGroup::Midlight, QColor( 220, 220, 220) );
- cg.setColor( QColorGroup::Dark, QColor( 96, 96, 96) );
- cg.setColor( QColorGroup::Mid, QColor( 128, 128, 128) );
- cg.setColor( QColorGroup::Text, Qt::black );
- cg.setColor( QColorGroup::BrightText, Qt::white );
- cg.setColor( QColorGroup::ButtonText, QColor( 128, 128, 128) );
- cg.setColor( QColorGroup::Base, Qt::white );
- cg.setColor( QColorGroup::Background, QColor( 192, 192, 192) );
- cg.setColor( QColorGroup::Shadow, Qt::black );
- cg.setColor( QColorGroup::Highlight, QColor( 0, 0, 128) );
- cg.setColor( QColorGroup::HighlightedText, Qt::white );
- pal.setDisabled( cg );
- qApp->setPalette( pal );
-
- /* Run 'SALOMEGUI' application */
- QAD_Application::run();
- a.exec();
-
- delete name_service;
- orb->destroy();
-
- return 0;
+#include "SALOMEGUI.h"
+
+//=============================================================================
+/*!
+ *
+ */
+//=============================================================================
+SALOMEGUI::SALOMEGUI( const QString& name, QObject* parent )
+: QObject( parent ),
+ myName( name )
+{
+}
+
+//=============================================================================
+/*!
+ *
+ */
+//=============================================================================
+SALOMEGUI::~SALOMEGUI()
+{
+}
+
+//=============================================================================
+/*!
+ *
+ */
+//=============================================================================
+bool SALOMEGUI::OnGUIEvent(int theCommandID, QAD_Desktop* parent)
+{
+ return true;
+}
+
+//=============================================================================
+/*!
+ *
+ */
+//=============================================================================
+bool SALOMEGUI::OnKeyPress(QKeyEvent* pe, QAD_Desktop* parent, QAD_StudyFrame* studyFrame)
+{
+ return true;
+}
+
+//=============================================================================
+/*!
+ *
+ */
+//=============================================================================
+bool SALOMEGUI::OnMousePress(QMouseEvent* pe, QAD_Desktop* parent, QAD_StudyFrame* studyFrame)
+{
+ return true;
+}
+
+//=============================================================================
+/*!
+ *
+ */
+//=============================================================================
+bool SALOMEGUI::OnMouseMove(QMouseEvent* pe, QAD_Desktop* parent, QAD_StudyFrame* studyFrame)
+{
+ return true;
+}
+
+//=============================================================================
+/*!
+ *
+ */
+//=============================================================================
+bool SALOMEGUI::SetSettings( QAD_Desktop* parent )
+{
+ return true;
+}
+
+//=============================================================================
+/*!
+ *
+ */
+//=============================================================================
+bool SALOMEGUI::SetSettings( QAD_Desktop* parent, char* compName )
+{
+ return true;
+}
+
+//=============================================================================
+/*!
+ *
+ */
+//=============================================================================
+bool SALOMEGUI::CustomPopup( QAD_Desktop* parent, QPopupMenu* popup, const QString & theContext,
+ const QString & theParent, const QString & theObject )
+{
+ return true;
+}
+
+//=============================================================================
+/*!
+ *
+ */
+//=============================================================================
+void SALOMEGUI::DefinePopup( QString & theContext, QString & theParent, QString & theObject )
+{
+}
+
+//=============================================================================
+/*!
+ *
+ */
+//=============================================================================
+bool SALOMEGUI::ActiveStudyChanged( QAD_Desktop* parent )
+{
+ return true;
}
+
+//=============================================================================
+/*!
+ *
+ */
+//=============================================================================
+void SALOMEGUI::BuildPresentation( const Handle(SALOME_InteractiveObject)& theIO )
+{
+}
+
+//=============================================================================
+/*!
+ *
+ */
+//=============================================================================
+void SALOMEGUI::SupportedViewType(int* buffer, int bufferSize)
+{
+}
+
+//=============================================================================
+/*!
+ *
+ */
+//=============================================================================
+void SALOMEGUI::Deactivate()
+{
+ emit SignalCloseAllDialogs();
+}
+
--- /dev/null
+// SALOME SALOMEGUI : implementation of desktop and GUI kernel
+//
+// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
+//
+//
+//
+// File : SALOMEGUI.hxx
+// Author : Sergey ANIKIN
+// Module : SALOME
+// $Header$
+
+#ifndef SALOMEGUI_HeaderFile
+#define SALOMEGUI_HeaderFile
+
+#include <Standard_Macro.hxx>
+
+#include <qobject.h>
+#include <qstring.h>
+
+class QAD_Desktop;
+class QAD_StudyFrame;
+class SALOME_Event;
+
+class Handle_SALOME_InteractiveObject;
+
+class QKeyEvent;
+class QMouseEvent;
+class QPopupMenu;
+class QString;
+
+
+class Standard_EXPORT SALOMEGUI : public QObject
+{
+ Q_OBJECT
+
+public:
+ SALOMEGUI( const QString& name = "", QObject* parent = 0 );
+ virtual ~SALOMEGUI();
+
+ virtual bool OnGUIEvent (int theCommandID, QAD_Desktop* parent);
+ virtual bool OnKeyPress (QKeyEvent* pe, QAD_Desktop* parent, QAD_StudyFrame* studyFrame);
+ virtual bool OnMousePress (QMouseEvent* pe, QAD_Desktop* parent, QAD_StudyFrame* studyFrame);
+ virtual bool OnMouseMove (QMouseEvent* pe, QAD_Desktop* parent, QAD_StudyFrame* studyFrame);
+ virtual bool SetSettings ( QAD_Desktop* parent );
+ virtual bool SetSettings ( QAD_Desktop* parent, char* compName );
+ virtual bool CustomPopup ( QAD_Desktop* parent, QPopupMenu* popup, const QString & theContext,
+ const QString & theParent, const QString & theObject );
+ virtual void DefinePopup ( QString & theContext, QString & theParent, QString & theObject );
+ virtual bool ActiveStudyChanged( QAD_Desktop* parent );
+ virtual void BuildPresentation ( const Handle(SALOME_InteractiveObject)& theIO );
+ virtual void SupportedViewType (int* buffer, int bufferSize);
+ virtual void Deactivate ();
+
+signals:
+ void SignalDeactivateActiveDialog();
+ void SignalCloseAllDialogs ();
+
+private:
+ QString myName;
+};
+
+#endif
// Module : SALOME
// $Header$
-using namespace std;
#include "SALOMEGUI_Application.h"
#include "SALOMEGUI_Desktop.h"
#include "SALOMEGUI_ImportOperation.h"
+#include "SALOMEGUI.h"
#include "SALOME_Selection.h"
#include "SALOME_ListIO.hxx"
#include "SALOME_ListIteratorOfListIO.hxx"
// Open CASCADE Include
#include <Standard_Failure.hxx>
#include <TCollection_AsciiString.hxx>
+using namespace std;
/*!
Constructor
return;
}
- // Obtain the component's GUI library
- // Library cashing will be implemented soon in QAD_Desktop to increase performance
- OSD_Function osdF, osdViewTypeFunc;
- OSD_SharedLibrary foreignGUI;
- void (*builder)(const Handle(SALOME_InteractiveObject)&);
- bool isForeignGUIUsed = false;
bool isViewTypeOK = true;
int viewTypes[VIEW_TYPE_MAX];
for (int i = 0; i < VIEW_TYPE_MAX; i++)
viewTypes[i] = -1;
- if (parentComp.compare(desktop->getActiveComponent()) == 0) { // use active GUI library
- const OSD_SharedLibrary& compGUI = desktop->getHandle();
- osdF = compGUI.DlSymb("buildPresentation");
- if ( osdF == NULL ) {
- MESSAGE("BuildPresentation method not found in component's GUI")
- return;
- }
- osdViewTypeFunc = compGUI.DlSymb("supportedViewType");
- if ( osdViewTypeFunc == NULL ) {
- MESSAGE("supportedViewType method not found in component's GUI")
- }
- MESSAGE("onDisplay(): using active GUI to build presentations")
- } else { // use native GUI library
- QString ComponentLib;
- QCString dir;
- QFileInfo fileInfo ;
- bool found = false;
- if ( getenv( QAD_Application::getDesktop()->getComponentName(parentComp) + "_ROOT_DIR") ) {
- dir.fill('\0');
- dir.sprintf("%s", getenv( QAD_Application::getDesktop()->getComponentName(parentComp) + "_ROOT_DIR"));
- dir = QAD_Tools::addSlash(dir) ;
- dir = dir + "lib" ;
- dir = QAD_Tools::addSlash(dir) ;
- dir = dir + "salome" ;
- dir = QAD_Tools::addSlash(dir) ;
-#ifdef WNT
- dir = dir + "lib" + QAD_Application::getDesktop()->getComponentName(parentComp).latin1() + "GUI.dll" ;
-#else
- dir = dir + "lib" + QAD_Application::getDesktop()->getComponentName(parentComp).latin1() + "GUI.so" ;
-#endif
- MESSAGE ( " GUI library = " << dir )
- fileInfo.setFile(dir) ;
- if (fileInfo.exists()) {
- ComponentLib = fileInfo.fileName() ;
- found = true;
- MESSAGE ( " found " )
- } else {
- MESSAGE ( " Not found " )
- }
- }
-
- if (ComponentLib.isEmpty()) {
- waitCursor.stop();
- QMessageBox::critical( desktop,
- tr("ERR_ERROR"),
- "Empty name of component "+ parentComp + " library");
- return;
- }
-
- foreignGUI.SetName(TCollection_AsciiString((char*)ComponentLib.latin1()).ToCString());
-
- bool ok = foreignGUI.DlOpen(OSD_RTLD_LAZY);
- if (!ok) {
- waitCursor.stop();
- QMessageBox::critical( desktop,
- tr("ERR_ERROR"),
- tr( foreignGUI.DlError() ) );
- return;
- }
-
- osdF = foreignGUI.DlSymb("buildPresentation");
- if ( osdF == NULL ) {
- MESSAGE("BuildPresentation method not found in component's GUI")
- foreignGUI.DlClose();
- return;
- }
- osdViewTypeFunc = foreignGUI.DlSymb("supportedViewType");
- if ( osdViewTypeFunc == NULL ) {
- MESSAGE("supportedViewType method not found in component's GUI")
- }
- isForeignGUIUsed = true;
- MESSAGE("onDisplay(): using parent component's GUI to build presentations")
- }
+ // Obtain the component's GUI
+ SALOMEGUI* aGUI = desktop->getComponentGUI( parentComp );
+ if ( !aGUI )
+ return;
// Check if another view type is required (if viewToActivate < 0 then any type of view is acceptable)
- if (osdViewTypeFunc) {
- void (*viewTypeChecker)(int*, int) = (void (*)(int*, int)) osdViewTypeFunc;
- (*viewTypeChecker)(viewTypes, VIEW_TYPE_MAX);
- if (viewTypes[0] >= 0) { // not all the view types are supported
- for (int i = 0; i < VIEW_TYPE_MAX; i++) {
- if (viewTypes[i] < 0) // no more types supported
- break;
- isViewTypeOK = ((int)myActiveStudy->getActiveStudyFrame()->getTypeView() == viewTypes[i]);
- if (isViewTypeOK) // one of supported views is already active
- break;
- }
+ aGUI->SupportedViewType(viewTypes, VIEW_TYPE_MAX);
+ if (viewTypes[0] >= 0) { // not all the view types are supported
+ for (int i = 0; i < VIEW_TYPE_MAX; i++) {
+ if (viewTypes[i] < 0) // no more types supported
+ break;
+ isViewTypeOK = ((int)myActiveStudy->getActiveStudyFrame()->getTypeView() == viewTypes[i]);
+ if (isViewTypeOK) // one of supported views is already active
+ break;
}
}
QAD_ViewFrame* viewFrame = myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame();
// Build the graphic presentation (it is stored in the corresponding viewer)
- builder = (void (*) (const Handle(SALOME_InteractiveObject)&)) osdF;
// Copy the selection
SALOME_ListIteratorOfListIO itInit( Sel->StoredIObjects() );
childIObject->setEntry(child->GetID());
// Ensure that proper 3D presentation exists for IObject
- (*builder)(childIObject);
+ aGUI->BuildPresentation(childIObject);
viewFrame->Display(childIObject, false);
needRepaint = true;
}
} else { // for child object -> simply display it (no children are displayed)
// Ensure that proper 3D presentation exists for IObject
- (*builder)(IObject);
+ aGUI->BuildPresentation(IObject);
viewFrame->Display(IObject, false);
needRepaint = true;
}
if (needRepaint)
viewFrame->Repaint();
- if (isForeignGUIUsed)
- ;//foreignGUI.DlClose(); // VSR: Fix crash on Display objects from non-parent components
myActiveStudy->updateObjBrowser(true);
}
myStudyManager = obj._narrow(SALOMEDS.StudyManager)
# create new study
-myStudy = myStudyManager.NewStudy("Study1")
-
+aListOfOpenStudies = myStudyManager.GetOpenStudies();
+myStudy = None;
+if len(aListOfOpenStudies) == 0 :
+ myStudy = myStudyManager.NewStudy("Study1")
+else:
+ myStudy = aListOfOpenStudies[0]
+
myStudyName = myStudy._get_Name()
myStudyId = myStudy._get_StudyId()
CPPFLAGS+=$(QT_MT_INCLUDES) $(OCC_INCLUDES) $(PYTHON_INCLUDES) $(HDF5_INCLUDES)
CXXFLAGS+=$(OCC_CXXFLAGS)
-LDFLAGS+=$(QT_MT_LIBS) $(HDF5_LIBS) -lSalomeHDFPersist -lSalomeNS -lSalomeGUI -lSalomeObject -lSalomeLifeCycleCORBA -lqsplitterP -lOpUtil -lPlot2d -lSalomeVTKFilter -lSALOMELocalTrace -lSalomeContainer -lRegistry -lSalomeNotification -lSalomeDS -lTOOLSDS -lSalomeGenericObj -lSalomeCatalog
+LDFLAGS+=$(QT_MT_LIBS) $(HDF5_LIBS) -lSalomeHDFPersist -lSalomeNS -lSalomeGUI -lSalomeObject -lSalomeLifeCycleCORBA -lqsplitterP -lOpUtil -lPlot2d -lSalomeVTKFilter -lSALOMELocalTrace -lSalomeContainer -lRegistry -lSalomeNotification -lSalomeDS -lTOOLSDS -lSalomeGenericObj -lSalomeCatalog -lEvent
@CONCLUDE@
Engines::Component_ptr SALOME_Session_i::GetVisuComponent()
{
MESSAGE("SALOME_Session_i::GetVisuGen");
- typedef Engines::Component_ptr VisuGen(CORBA::ORB_ptr,
+ typedef Engines::Component_ptr TGetImpl(CORBA::ORB_ptr,
PortableServer::POA_ptr,
SALOME_NamingService*,QMutex*);
- OSD_SharedLibrary visuSharedLibrary("libVISUEngine.so");
- if(visuSharedLibrary.DlOpen(OSD_RTLD_LAZY))
- if(OSD_Function osdFun = visuSharedLibrary.DlSymb("GetVisuGen"))
- return ((VisuGen (*)) osdFun)(_orb,_poa,_NS,_GUIMutex);
+ OSD_SharedLibrary aSharedLibrary("libVISUEngineImpl.so");
+ if(aSharedLibrary.DlOpen(OSD_RTLD_LAZY))
+ if(OSD_Function anOSDFun = aSharedLibrary.DlSymb("GetImpl"))
+ return ((TGetImpl (*)) anOSDFun)(_orb,_poa,_NS,_GUIMutex);
return Engines::Component::_nil();
}