From 0abe978c75584232cb4ae51b0f09b77b308fdec4 Mon Sep 17 00:00:00 2001 From: nri Date: Fri, 30 Apr 2004 12:37:08 +0000 Subject: [PATCH] NRI : Merge from Event_Server. --- src/Makefile.in | 2 +- src/SALOMEGUI/Makefile.in | 6 +- src/SALOMEGUI/PyInterp_PyQt.cxx | 59 +-- src/SALOMEGUI/PyInterp_PyQt.h | 7 +- src/SALOMEGUI/PyInterp_base.cxx | 520 ++++++++++-------------- src/SALOMEGUI/PyInterp_base.h | 120 ++++-- src/SALOMEGUI/QAD_Application.cxx | 2 + src/SALOMEGUI/QAD_Desktop.cxx | 344 ++++++++-------- src/SALOMEGUI/QAD_Desktop.h | 17 +- src/SALOMEGUI/QAD_ObjectBrowser.cxx | 16 +- src/SALOMEGUI/QAD_PyEditor.cxx | 358 +++++++++++----- src/SALOMEGUI/QAD_PyEditor.h | 36 +- src/SALOMEGUI/QAD_PyInterp.cxx | 104 +++-- src/SALOMEGUI/QAD_PyInterp_mono.cxx | 7 +- src/SALOMEGUI/QAD_RightFrame.cxx | 35 +- src/SALOMEGUI/QAD_RightFrame.h | 16 +- src/SALOMEGUI/QAD_Study.cxx | 155 ++++--- src/SALOMEGUI/QAD_Study.h | 9 +- src/SALOMEGUI/QAD_StudyFrame.cxx | 63 +-- src/SALOMEGUI/QAD_StudyFrame.h | 21 +- src/SALOMEGUI/SALOMEGUI.cxx | 242 ++++++----- src/SALOMEGUI/SALOMEGUI.h | 79 ++++ src/SALOMEGUI/SALOMEGUI_Application.cxx | 112 +---- src/SALOME_SWIG/batchmode_salome.py | 9 +- src/Session/Makefile.in | 2 +- src/Session/SALOME_Session_i.cxx | 10 +- 26 files changed, 1302 insertions(+), 1049 deletions(-) create mode 100644 src/SALOMEGUI/SALOMEGUI.h diff --git a/src/Makefile.in b/src/Makefile.in index ef5ce55e6..5c3530e4b 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -38,7 +38,7 @@ SUBDIRS = MSG2QM SALOMELocalTrace Logger SALOMELogger Utils PatchQt \ 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 \ diff --git a/src/SALOMEGUI/Makefile.in b/src/SALOMEGUI/Makefile.in index 08d0682d3..3f7bc1c78 100644 --- a/src/SALOMEGUI/Makefile.in +++ b/src/SALOMEGUI/Makefile.in @@ -92,6 +92,7 @@ EXPORT_HEADERS = \ Handle_SALOME_NumberFilter.hxx \ SALOME_DataMapOfIOMapOfInteger.hxx \ Handle_SALOME_DataMapNodeOfDataMapOfIOMapOfInteger.hxx \ + SALOMEGUI.h \ SALOMEGUI_LoadStudiesDlg.h \ SALOMEGUI_TableDlg.h \ SALOMEGUI_NameDlg.h \ @@ -99,7 +100,6 @@ EXPORT_HEADERS = \ SALOMEGUI_SetupCurveDlg.h \ SALOMEGUI_CloseDlg.h - # .po files to transform in .qm PO_FILES = \ QAD_icons.po \ @@ -150,6 +150,7 @@ LIB_SRC = \ QAD_StudyFrame.cxx \ QAD_Tools.cxx \ QAD_ViewFrame.cxx \ + SALOMEGUI.cxx \ SALOMEGUI_Application.cxx \ SALOMEGUI_Desktop.cxx \ SALOMEGUI_ImportOperation.cxx \ @@ -182,6 +183,7 @@ LIB_SRC = \ SALOMEGUI_CloseDlg.cxx \ SALOMEGUI_ActivateComponentDlg.cxx LIB_MOC = \ + SALOMEGUI.h \ SALOMEGUI_Application.h \ SALOMEGUI_Desktop.h \ QAD_Application.h \ @@ -218,7 +220,7 @@ LIB_CLIENT_IDL = SALOMEDS.idl \ 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) diff --git a/src/SALOMEGUI/PyInterp_PyQt.cxx b/src/SALOMEGUI/PyInterp_PyQt.cxx index ecd145c4b..ae688800f 100644 --- a/src/SALOMEGUI/PyInterp_PyQt.cxx +++ b/src/SALOMEGUI/PyInterp_PyQt.cxx @@ -9,13 +9,11 @@ // 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. @@ -33,7 +31,6 @@ PyInterp_PyQt::~PyInterp_PyQt() void PyInterp_PyQt::initState() { - salomeAcquireLock(); //acquire python global lock (one for all interpreters) SCRUTE(PyInterp_base::_gtstate); _tstate=PyInterp_base::_gtstate; PyThreadState_Swap(_tstate); @@ -48,49 +45,23 @@ void PyInterp_PyQt::initContext() 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(); } diff --git a/src/SALOMEGUI/PyInterp_PyQt.h b/src/SALOMEGUI/PyInterp_PyQt.h index bc6a29849..74d743e27 100644 --- a/src/SALOMEGUI/PyInterp_PyQt.h +++ b/src/SALOMEGUI/PyInterp_PyQt.h @@ -19,13 +19,12 @@ class PyInterp_PyQt : public PyInterp_base 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 diff --git a/src/SALOMEGUI/PyInterp_base.cxx b/src/SALOMEGUI/PyInterp_base.cxx index f9d03e760..d460ee541 100644 --- a/src/SALOMEGUI/PyInterp_base.cxx +++ b/src/SALOMEGUI/PyInterp_base.cxx @@ -9,200 +9,133 @@ // Module : SALOME // $Header$ -using namespace std; -#include "PyInterp_base.h" -#include "utilities.h" #include #include + +#include #include +#include + +#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 = "<locked()); + myMutex->lock(); } -extern "C" void salomeCondReleaseLock(int rellock) -{ - MESSAGE("salomeCondReleaseLock"); - if(rellock ) - salomeReleaseLock(); + +ThreadLock::~ThreadLock(){ + if(MYDEBUG && myComment != "") MESSAGE("~ThreadLock "<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 = "<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 = "<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 = "<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; +} + diff --git a/src/SALOMEGUI/PyInterp_base.h b/src/SALOMEGUI/PyInterp_base.h index 1e4ac5fea..157d5c3f7 100644 --- a/src/SALOMEGUI/PyInterp_base.h +++ b/src/SALOMEGUI/PyInterp_base.h @@ -12,66 +12,126 @@ #ifndef _PYINTERP_BASE_H_ #define _PYINTERP_BASE_H_ -#include -#include #include #include +#include -using namespace std; +#include + +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 _history; - list ::iterator _ith; + PyObject * _vout; + PyObject * _verr; + PyObject * _g; + std::list _history; + std::list::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 diff --git a/src/SALOMEGUI/QAD_Application.cxx b/src/SALOMEGUI/QAD_Application.cxx index 99e1eca15..eb8b43d5e 100644 --- a/src/SALOMEGUI/QAD_Application.cxx +++ b/src/SALOMEGUI/QAD_Application.cxx @@ -823,6 +823,8 @@ QAD_Study* QAD_Application::newStudy() newStudy = new QAD_Study( this, aStudy, StudyName); } + newStudy->Init(); + if ( newStudy->getResult() ) { addStudy( newStudy ); diff --git a/src/SALOMEGUI/QAD_Desktop.cxx b/src/SALOMEGUI/QAD_Desktop.cxx index 380702a0d..8aef9880c 100644 --- a/src/SALOMEGUI/QAD_Desktop.cxx +++ b/src/SALOMEGUI/QAD_Desktop.cxx @@ -43,6 +43,7 @@ #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" @@ -55,6 +56,7 @@ //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" @@ -71,6 +73,8 @@ #include "SALOMEGUI_CloseDlg.h" #include "SALOMEGUI_ActivateComponentDlg.h" +#include "SALOME_Event.hxx" + // QT Includes #include #include @@ -101,6 +105,7 @@ #endif // Open CASCADE Includes +#include #include #include #include @@ -446,9 +451,28 @@ bool QAD_Desktop::eventFilter( QObject* o, QEvent* e ) } } } + 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 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'. @@ -2580,28 +2604,20 @@ void QAD_Desktop::onOpenWith() 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() ); + } } } @@ -2681,95 +2697,19 @@ bool QAD_Desktop::loadComponent(QString Component) 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 = @@ -3048,14 +2988,9 @@ void QAD_Desktop::onDispatchTools(int id) */ 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); } /*! @@ -3246,13 +3181,9 @@ typedef bool TwoDim1(QKeyEvent* pe, QAD_Desktop*, QAD_StudyFrame*); 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*); @@ -3262,13 +3193,9 @@ 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; } @@ -3277,13 +3204,9 @@ bool QAD_Desktop::onMousePress( QMouseEvent* pe ) */ 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()); } /*! @@ -3294,20 +3217,129 @@ const QString& QAD_Desktop::getActiveComponent() const 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); } @@ -3388,47 +3420,29 @@ void QAD_Desktop::createPopup(QPopupMenu* popup, const QString & theContext, } -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() diff --git a/src/SALOMEGUI/QAD_Desktop.h b/src/SALOMEGUI/QAD_Desktop.h index 2f1fab179..96d3b9089 100644 --- a/src/SALOMEGUI/QAD_Desktop.h +++ b/src/SALOMEGUI/QAD_Desktop.h @@ -60,10 +60,9 @@ #include #include -// Open CASCADE Includes -#include - class QAD_XmlHandler; +class SALOMEGUI; +class SALOME_Event; class QAD_EXPORT QAD_Desktop : public QMainWindow { @@ -163,8 +162,9 @@ public: 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, @@ -324,12 +324,17 @@ protected: QMap mapComponentName; +private: + void processEvent( SALOME_Event* ); + +private: + typedef QMap ComponentMap; + private: static QAD_ResourceMgr* resourceMgr; static QPalette* palette; void createActions(); void updateActions(); - OSD_SharedLibrary mySharedLibrary; QAD_XmlHandler* myXmlHandler; QString myActiveComp; SALOME_NamingService* myNameService; @@ -338,6 +343,8 @@ private: QComboBox * myCombo; bool myQueryClose; bool _islibso; + + ComponentMap myComponents; }; /******************************************************************** diff --git a/src/SALOMEGUI/QAD_ObjectBrowser.cxx b/src/SALOMEGUI/QAD_ObjectBrowser.cxx index 9fa4ef038..4516e9934 100644 --- a/src/SALOMEGUI/QAD_ObjectBrowser.cxx +++ b/src/SALOMEGUI/QAD_ObjectBrowser.cxx @@ -73,6 +73,14 @@ using namespace std; #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 */ @@ -658,7 +666,7 @@ void QAD_ObjectBrowser::Update( SALOMEDS::SObject_ptr SO, myListViewMap[ RefSOEntry ].append( Item ); } else { - MESSAGE("QAD_ObjectBrowser::Update : noname item: "<GetID()); + if(MYDEBUG) MESSAGE("QAD_ObjectBrowser::Update : noname item: "<GetID()); } } else { // getting Value @@ -675,7 +683,7 @@ void QAD_ObjectBrowser::Update( SALOMEDS::SObject_ptr SO, myListViewMap[ CSOEntry ].append( Item ); } else { - MESSAGE("QAD_ObjectBrowser::Update : noname item: "<GetID()); + if(MYDEBUG) MESSAGE("QAD_ObjectBrowser::Update : noname item: "<GetID()); } // adding other attributes if (Item) { @@ -860,8 +868,8 @@ void QAD_ObjectBrowser::Update() 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 )*/ )); diff --git a/src/SALOMEGUI/QAD_PyEditor.cxx b/src/SALOMEGUI/QAD_PyEditor.cxx index a125e4fa7..de74767d5 100644 --- a/src/SALOMEGUI/QAD_PyEditor.cxx +++ b/src/SALOMEGUI/QAD_PyEditor.cxx @@ -26,7 +26,6 @@ // Module : SALOME // $Header$ -using namespace std; #include "QAD_PyEditor.h" #include "QAD_PyInterp.h" #include "QAD_Application.h" @@ -34,11 +33,11 @@ using namespace std; #include "QAD_Config.h" #include "QAD_Tools.h" #include "QAD_MessageBox.h" -//#include "QAD_RightFrame.h" #include #include #include +#include // NRI : Temporary added // IDL Headers @@ -47,39 +46,164 @@ using namespace std; #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 = "<run( myCommand.latin1() ); + if(MYDEBUG) MESSAGE("TExecCommand::run() - myInterp = "< 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; + } } /*! @@ -87,12 +211,11 @@ QAD_PyEditor::~QAD_PyEditor() */ 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)); } /*! @@ -100,9 +223,8 @@ void QAD_PyEditor::setText(QString s) */ 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(); @@ -121,24 +243,10 @@ void QAD_PyEditor::handleReturn() } // 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()); } /* @@ -150,10 +258,10 @@ void QAD_PyEditor::mousePressEvent (QMouseEvent * event) QPopupMenu *popup = new QPopupMenu( this ); QMap 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); @@ -164,7 +272,7 @@ void QAD_PyEditor::mousePressEvent (QMouseEvent * event) 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 ], @@ -181,8 +289,8 @@ void QAD_PyEditor::mousePressEvent (QMouseEvent * event) } 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 ] ) { @@ -191,7 +299,7 @@ void QAD_PyEditor::mousePressEvent (QMouseEvent * event) return; } else { - QMultiLineEdit::mousePressEvent(event); + QTextEdit::mousePressEvent(event); } } @@ -201,14 +309,14 @@ void QAD_PyEditor::mousePressEvent (QMouseEvent * 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); } /*! @@ -239,7 +347,7 @@ void QAD_PyEditor::keyPressEvent( QKeyEvent *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()); @@ -257,34 +365,30 @@ void QAD_PyEditor::keyPressEvent( QKeyEvent *e ) { case 0 : { - if (curLine 0 ){ - setCursorPosition(curLine-1, curCol, true); + moveCursor(QTextEdit::MoveUp, true); } // scroll the commands stack up else { @@ -292,18 +396,18 @@ void QAD_PyEditor::keyPressEvent( QKeyEvent *e ) 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; } @@ -311,74 +415,91 @@ void QAD_PyEditor::keyPressEvent( QKeyEvent *e ) { // 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; } } @@ -398,3 +519,48 @@ void QAD_PyEditor::keyPressEvent( QKeyEvent *e ) 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; +} diff --git a/src/SALOMEGUI/QAD_PyEditor.h b/src/SALOMEGUI/QAD_PyEditor.h index 5086b7d94..94c92c3af 100644 --- a/src/SALOMEGUI/QAD_PyEditor.h +++ b/src/SALOMEGUI/QAD_PyEditor.h @@ -29,36 +29,54 @@ #ifndef QAD_PyEditor_H #define QAD_PyEditor_H -#include +#include +#include + +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 diff --git a/src/SALOMEGUI/QAD_PyInterp.cxx b/src/SALOMEGUI/QAD_PyInterp.cxx index 5f04d820f..d7da14e42 100644 --- a/src/SALOMEGUI/QAD_PyInterp.cxx +++ b/src/SALOMEGUI/QAD_PyInterp.cxx @@ -26,11 +26,19 @@ // 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 @@ -38,7 +46,6 @@ using namespace std; */ QAD_PyInterp::QAD_PyInterp(): PyInterp_base() { - initialize(); } QAD_PyInterp::~QAD_PyInterp() @@ -65,71 +72,58 @@ 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 = "<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 = "< // QT Include @@ -40,6 +42,8 @@ using namespace std; // Open CASCADE Include #include +using namespace std; + /*! \class QAD_RightFrame QAD_RightFrame.h \brief Frame window which contains QAD_ViewFrame, QAD_PyInterp and QAD_Message. @@ -51,19 +55,19 @@ typedef QAD_ViewFrame* View(QAD_RightFrame*); /*! 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; @@ -184,12 +188,15 @@ QAD_RightFrame::QAD_RightFrame(QWidget *parent, const char *name, QValueList 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) ); @@ -198,7 +205,7 @@ QAD_RightFrame::QAD_RightFrame(QWidget *parent, const char *name, sizes.clear(); sizes.append( (int)(0.25 * DesktopWidth) ); sizes.append( (int)(0.25 * DesktopWidth) ); - vsplitter->setSizes( sizes ); + mySplitter->setSizes( sizes ); } /*! @@ -226,7 +233,7 @@ QAD_Message* QAD_RightFrame::getMessage() const */ QAD_PyInterp* QAD_RightFrame::get_PyInterp(void) { - return _interp; + return myInterp; } /*! diff --git a/src/SALOMEGUI/QAD_RightFrame.h b/src/SALOMEGUI/QAD_RightFrame.h index 1b454310a..b92b6eb66 100644 --- a/src/SALOMEGUI/QAD_RightFrame.h +++ b/src/SALOMEGUI/QAD_RightFrame.h @@ -31,15 +31,19 @@ #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; @@ -58,8 +62,8 @@ protected: QAD_ViewFrame* myViewFrame; QAD_PyEditor* myPyEditor; QAD_Message* myMessage; - QAD_Splitter* vsplitter; - QAD_PyInterp* _interp; + QAD_Splitter* mySplitter; + QAD_PyInterp*& myInterp; }; #endif diff --git a/src/SALOMEGUI/QAD_Study.cxx b/src/SALOMEGUI/QAD_Study.cxx index 1be9aef0e..fbd95d9e4 100644 --- a/src/SALOMEGUI/QAD_Study.cxx +++ b/src/SALOMEGUI/QAD_Study.cxx @@ -26,7 +26,6 @@ // Module : SALOME // $Header$ -using namespace std; /*! \class QAD_Study QAD_Study.h \brief Study for QAD-based application. @@ -43,6 +42,7 @@ using namespace std; #include "QAD_ObjectBrowser.h" #include "QAD_PyInterp.h" #include "QAD_Config.h" +#include "QAD_PyInterp.h" #include "utilities.h" @@ -59,58 +59,104 @@ using namespace std; // QT Include #include +#include +#include -/*! - 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 */ @@ -119,6 +165,13 @@ QAD_Study::~QAD_Study () 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; + } } /*! @@ -344,10 +397,10 @@ void QAD_Study::setReadOnly(bool state) */ 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 */ @@ -591,7 +644,8 @@ QAD_StudyFrame* QAD_Study::createStudyFrame( const QString& title, ViewType theV 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"); @@ -608,7 +662,8 @@ QAD_StudyFrame* QAD_Study::createStudyFrame( const QString& title, ViewType theV 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); @@ -624,7 +679,8 @@ QAD_StudyFrame* QAD_Study::createStudyFrame( const QString& title, ViewType theV 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); @@ -639,7 +695,8 @@ QAD_StudyFrame* QAD_Study::createStudyFrame( const QString& title, ViewType theV } 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); @@ -1245,7 +1302,7 @@ QString QAD_Study::getNextStudyFrameName() */ QAD_PyInterp* QAD_Study::get_PyInterp(void) { - return _interp; + return myInterp; } /*! diff --git a/src/SALOMEGUI/QAD_Study.h b/src/SALOMEGUI/QAD_Study.h index 94fe80305..8139e8a5d 100644 --- a/src/SALOMEGUI/QAD_Study.h +++ b/src/SALOMEGUI/QAD_Study.h @@ -44,7 +44,10 @@ #include class QAD_Application; + +class QMutex; class QAD_PyInterp; +class TInitStudyThread; class QAD_EXPORT QAD_Study : public QObject { @@ -54,6 +57,7 @@ public: QAD_Study(QAD_Application* app, SALOMEDS::Study_var aStudy, const QString& title); + virtual void Init(); ~QAD_Study(); /* Event filter */ @@ -189,7 +193,10 @@ private: bool myIsModified; bool myIsReadOnly; bool myResult; - QAD_PyInterp* _interp; + + QMutex* myMutex; + QAD_PyInterp* myInterp; + TInitStudyThread* myInitStudyThread; }; #endif diff --git a/src/SALOMEGUI/QAD_StudyFrame.cxx b/src/SALOMEGUI/QAD_StudyFrame.cxx index 29bde65b1..b54b6dfc0 100644 --- a/src/SALOMEGUI/QAD_StudyFrame.cxx +++ b/src/SALOMEGUI/QAD_StudyFrame.cxx @@ -26,7 +26,6 @@ // Module : SALOME // $Header$ -using namespace std; /*! \class QAD_StudyFrame QAD_StudyFrame.h \brief Frame window which contains QAD_LeftFrame and QAD_RightFrame. @@ -35,54 +34,51 @@ using namespace std; #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 +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 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 @@ -124,6 +120,11 @@ void QAD_StudyFrame::setVisible( bool visible ) */ void QAD_StudyFrame::closeEvent(QCloseEvent* e) { + if ( IsPyLocked() ) { + e->ignore(); + return; + } + emit sfStudyFrameClosing(this); } @@ -132,22 +133,22 @@ void QAD_StudyFrame::closeEvent(QCloseEvent* e) */ 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); } /*! @@ -201,5 +202,5 @@ void QAD_StudyFrame::onStudyFrameActivated ( QWidget* activeWindow ) */ QAD_PyInterp* QAD_StudyFrame::get_PyInterp(void) { - return _interp; + return myInterp; } diff --git a/src/SALOMEGUI/QAD_StudyFrame.h b/src/SALOMEGUI/QAD_StudyFrame.h index e8b393b44..cdb83befa 100644 --- a/src/SALOMEGUI/QAD_StudyFrame.h +++ b/src/SALOMEGUI/QAD_StudyFrame.h @@ -30,17 +30,18 @@ #define QAD_StudyFrame_H #include "QAD.h" -#include "QAD_Splitter.h" -#include "QAD_PyInterp.h" // QT Includes #include #include +class QMutex; + class QAD_RightFrame; class QAD_LeftFrame; class QAD_Splitter; class QAD_Study; +class QAD_PyInterp; enum ViewType { VIEW_OCC, @@ -55,11 +56,9 @@ class QAD_EXPORT QAD_StudyFrame: public QMainWindow 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; } @@ -77,7 +76,6 @@ class QAD_EXPORT QAD_StudyFrame: public QMainWindow const QString& entry() const; void setVisible( bool isVisible = true ); - void closeEvent(QCloseEvent* e); void compressLeft(); void compressRight(); @@ -90,6 +88,9 @@ class QAD_EXPORT QAD_StudyFrame: public QMainWindow public slots: void onStudyFrameActivated ( QWidget* ); + + protected: + virtual void closeEvent ( QCloseEvent* ); private: @@ -99,9 +100,9 @@ class QAD_EXPORT QAD_StudyFrame: public QMainWindow ViewType myTypeView; QAD_LeftFrame* myLeftFrm; QAD_RightFrame* myRightFrm; - QAD_Splitter* s1; - QAD_PyInterp* _interp; + QAD_Splitter* mySplitter; QAD_Study* myStudy; + QAD_PyInterp*& myInterp; }; #endif diff --git a/src/SALOMEGUI/SALOMEGUI.cxx b/src/SALOMEGUI/SALOMEGUI.cxx index 69a3b241b..ba9f6a56e 100644 --- a/src/SALOMEGUI/SALOMEGUI.cxx +++ b/src/SALOMEGUI/SALOMEGUI.cxx @@ -22,109 +22,147 @@ // // // File : SALOMEGUI.cxx -// Author : Nicolas REJNERI +// Author : Sergey ANIKIN // Module : SALOME // $Header$ -using namespace std; -#include -#include CORBA_SERVER_HEADER(SALOMEDS) - -#include "QAD.h" -#include "QAD_MessageBox.h" -#include "QAD_Application.h" -#include "SALOMEGUI_Application.h" - -#include -#include - -#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(); +} + diff --git a/src/SALOMEGUI/SALOMEGUI.h b/src/SALOMEGUI/SALOMEGUI.h new file mode 100644 index 000000000..d823c6e41 --- /dev/null +++ b/src/SALOMEGUI/SALOMEGUI.h @@ -0,0 +1,79 @@ +// 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 + +#include +#include + +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 diff --git a/src/SALOMEGUI/SALOMEGUI_Application.cxx b/src/SALOMEGUI/SALOMEGUI_Application.cxx index fa67befd6..8d95761e9 100644 --- a/src/SALOMEGUI/SALOMEGUI_Application.cxx +++ b/src/SALOMEGUI/SALOMEGUI_Application.cxx @@ -26,10 +26,10 @@ // 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" @@ -51,6 +51,7 @@ using namespace std; // Open CASCADE Include #include #include +using namespace std; /*! Constructor @@ -429,104 +430,26 @@ void SALOMEGUI_Application::onDisplay(int id) 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; } } @@ -557,7 +480,6 @@ void SALOMEGUI_Application::onDisplay(int id) 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() ); @@ -598,13 +520,13 @@ void SALOMEGUI_Application::onDisplay(int id) 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; } @@ -614,8 +536,6 @@ void SALOMEGUI_Application::onDisplay(int id) if (needRepaint) viewFrame->Repaint(); - if (isForeignGUIUsed) - ;//foreignGUI.DlClose(); // VSR: Fix crash on Display objects from non-parent components myActiveStudy->updateObjBrowser(true); } diff --git a/src/SALOME_SWIG/batchmode_salome.py b/src/SALOME_SWIG/batchmode_salome.py index a6a7753ed..7cf675756 100644 --- a/src/SALOME_SWIG/batchmode_salome.py +++ b/src/SALOME_SWIG/batchmode_salome.py @@ -226,8 +226,13 @@ obj = naming_service.Resolve('myStudyManager') 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() diff --git a/src/Session/Makefile.in b/src/Session/Makefile.in index 4d2bd69b9..2072c8e84 100644 --- a/src/Session/Makefile.in +++ b/src/Session/Makefile.in @@ -52,7 +52,7 @@ BIN_CLIENT_IDL = SALOMEDS.idl SALOMEDS_Attributes.idl SALOME_Component.idl SALOM 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@ diff --git a/src/Session/SALOME_Session_i.cxx b/src/Session/SALOME_Session_i.cxx index ba5eecf39..890028127 100644 --- a/src/Session/SALOME_Session_i.cxx +++ b/src/Session/SALOME_Session_i.cxx @@ -69,13 +69,13 @@ SALOME_Session_i::SALOME_Session_i(int argc, char ** argv, CORBA::ORB_ptr orb, P 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(); } -- 2.39.2