From 3ab3cce87d74112f9251914b6a005e1b02c34228 Mon Sep 17 00:00:00 2001 From: vsr Date: Thu, 28 Jun 2007 14:00:21 +0000 Subject: [PATCH] Porting to Qt 4 --- src/SALOME_PY/SalomePy.cxx | 328 +++++++++++++------ src/SALOME_SWIG/SALOMEGUI_Swig.cxx | 505 ++++++++++++++++------------- src/SALOME_SWIG/SALOMEGUI_Swig.hxx | 35 +- src/SALOME_SWIG/SALOMEGUI_Swig.i | 34 +- 4 files changed, 527 insertions(+), 375 deletions(-) diff --git a/src/SALOME_PY/SalomePy.cxx b/src/SALOME_PY/SalomePy.cxx index 6b8b62410..31fe31868 100755 --- a/src/SALOME_PY/SalomePy.cxx +++ b/src/SALOME_PY/SalomePy.cxx @@ -19,12 +19,8 @@ // // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // -// -// // File : SalomePy.cxx // Author : Paul RASCLE, EDF -// Module : SALOME -// $Header$ #include #include @@ -34,16 +30,39 @@ #include #include -#include "SALOME_Event.hxx" +#include + +#include +#include +#include + +#include +#include -#include "SUIT_Session.h" -#include "SalomeApp_Application.h" -#include "SalomeApp_Study.h" +/*! + \brief Python wrappings for VTK viewer of the SALOME desktop. + + All methods are implemented using Event mechanism. The module + provides the following functions: + - getRenderer() + - getRenderWindow() + - getRenderWindowInteractor() + - showTrihedron() + - fitAll() + - setView() + - resetView() -#include "SVTK_ViewManager.h" -#include "SVTK_ViewWindow.h" + Usage in Python: + \code + import SalomePy + renderer = SalomePy.getRenderer() # get VTK renderer + window = SalomePy.getRenderWindow() # get render window + \endcode -using namespace std; + The methods getRenderer(), getRenderWindow() and getRenderWindowInteractor() + open new VTK viewer if there is no one opened. + In case of any error these methods return None object to the Python. +*/ #define PUBLISH_ENUM(i) \ { \ @@ -55,55 +74,59 @@ using namespace std; if ( rc < 0 ) return; \ } -// enumeration : view type +//! View operation type enum { - ViewFront, // fron view - ViewBack, // back view - ViewTop, // top view - ViewBottom, // bottom view - ViewRight, // right view - ViewLeft // left view + ViewFront, //!< front view + ViewBack, //!< back view + ViewTop, //!< top view + ViewBottom, //!< bottom view + ViewRight, //!< right view + ViewLeft //!< left view }; - /*! - VSR : 19.04.05 : Reimplemented for new SALOME GUI (SUIT-based) - All methods are implemented using Event mechanism: - - getRenderer() - - getRenderWindow() - - getRenderWindowInteractor() - - showTrihedron() - These methods (except showTrihedron() ) open new VTK viewer - if there is no one opened. - In case of error all methods return None object in Python. + \brief Get Python class object by name + \internal + \param theClassName Python class name + \return Python class object or None object if class is not found */ - -static PyObject* GetPyClass(const char* theClassName){ - static PyObject *aVTKModule = NULL; - if(!aVTKModule){ - if (VTK_MAJOR_VERSION > 3) - aVTKModule = PyImport_ImportModule("libvtkRenderingPython"); +static PyObject* GetPyClass( const char* theClassName ) +{ + static PyObject* aVTKModule = 0; + PyObject* aPyClass = 0; + if( !aVTKModule ) { + if ( VTK_MAJOR_VERSION > 3 ) + aVTKModule = PyImport_ImportModule( "libvtkRenderingPython" ); else - aVTKModule = PyImport_ImportModule("libVTKGraphicsPython"); - if(PyErr_Occurred()){ + aVTKModule = PyImport_ImportModule( "libVTKGraphicsPython" ); + if( PyErr_Occurred() ) { PyErr_Print(); - return NULL; } } - PyObject* aVTKDict = PyModule_GetDict(aVTKModule); - char* aClassName = const_cast(theClassName); - PyObject* aPyClass = PyDict_GetItemString(aVTKDict,aClassName); - //Py_DECREF(aVTKModule); + if ( aVTKModule ) { + PyObject* aVTKDict = PyModule_GetDict( aVTKModule ); + aPyClass = PyDict_GetItemString(aVTKDict, const_cast( theClassName ) ); + } return aPyClass; } -// internal enum: find or create VTK window -enum { __Find, // try to find only - __FindOrCreate, // try to find: if not found - create new - __Create }; // try to find: if not found - create new +/*! + \brief VTK window find/create mode + \internal +*/ +enum { + __Find, // try to find VTK window; if not found, do nothing + __FindOrCreate, // try to find VTK window; if not found, create new one + __Create }; // create new VTK window +/*! + \brief Find or create VTK window. + \internal + \param toCreate window find/create mode + \return VTK window pointer or 0 if it could not be found/created +*/ static SVTK_ViewWindow* GetVTKViewWindow( int toCreate = __FindOrCreate ) { - SVTK_ViewWindow* aVW = NULL; + SVTK_ViewWindow* aVW = 0; if ( SUIT_Session::session() ) { // get application SalomeApp_Application* anApp = dynamic_cast( SUIT_Session::session()->activeApplication() ); @@ -121,7 +144,7 @@ static SVTK_ViewWindow* GetVTKViewWindow( int toCreate = __FindOrCreate ) { // VSR : When new view window is created it can be not active yet at this moment, // so the following is a some workaround if ( !aVW && !aVM->getViews().isEmpty() ) - aVW = dynamic_cast( aVM->getViews()[ 0 ] ); + aVW = dynamic_cast( aVM->getViews()[0] ); } } else { @@ -131,7 +154,7 @@ static SVTK_ViewWindow* GetVTKViewWindow( int toCreate = __FindOrCreate ) { // VSR : When new view window is created it can be not active yet at this moment, // so the following is a some workaround if ( !aVW && !aVM->getViews().isEmpty() ) - aVW = dynamic_cast( aVM->getViews()[ 0 ] ); + aVW = dynamic_cast( aVM->getViews()[0] ); } } } @@ -141,30 +164,48 @@ static SVTK_ViewWindow* GetVTKViewWindow( int toCreate = __FindOrCreate ) { } /*! - Get VTK renderer. - Always opens new VTK window if parameter is non zero. - Otherwise opens new VTK window only if there is no one opened. + \fn PyObject* getRenderer( int toCreate = 0 ); + \brief Get VTK renderer (vtkRenderer). + + If \a toCreate parameter is 0 (by default) the function tries to find + and reuse existing VTK window; if it is not found, the new VTK window + is opened. + + If \a toCreate parameter is non-zero, the function always creates + new VTK window. + + If VTK window could not be found and or created, the None Python object + is returned. + + \param toCreate window creation mode + \return VTK window renderer object */ -class TGetRendererEvent: public SALOME_Event { + +class TGetRendererEvent: public SALOME_Event +{ public: typedef PyObject* TResult; TResult myResult; int myCreate; TGetRendererEvent( bool toCreate ) - : myResult( Py_None ), myCreate( toCreate ) {} - virtual void Execute() { - if( SVTK_ViewWindow* aVTKViewWindow = GetVTKViewWindow( myCreate ? __Create : __FindOrCreate ) ) { - PyObject* aPyClass = GetPyClass("vtkRenderer"); + : myResult( Py_None ), myCreate( toCreate ) {} + virtual void Execute() + { + PyObject* aPyClass = ::GetPyClass( "vtkRenderer" ); + SVTK_ViewWindow* aVTKViewWindow = + ::GetVTKViewWindow( myCreate ? __Create : __FindOrCreate ); + if( aVTKViewWindow && aPyClass ) { vtkRenderer* aVTKObject = aVTKViewWindow->getRenderer(); - myResult = PyVTKObject_New(aPyClass,aVTKObject); + myResult = PyVTKObject_New( aPyClass, aVTKObject ); } } }; -extern "C" PyObject *libSalomePy_getRenderer(PyObject *self, PyObject *args) + +extern "C" PyObject* libSalomePy_getRenderer( PyObject* self, PyObject* args ) { PyObject* aResult = Py_None; int toCreate = 0; - if ( !PyArg_ParseTuple(args, "|i:getRenderer", &toCreate) ) + if ( !PyArg_ParseTuple( args, "|i:getRenderer", &toCreate ) ) PyErr_Print(); else aResult = ProcessEvent( new TGetRendererEvent( toCreate ) ); @@ -172,30 +213,48 @@ extern "C" PyObject *libSalomePy_getRenderer(PyObject *self, PyObject *args) } /*! - Get VTK render window. - Always opens new VTK window if parameter is non zero. - Otherwise opens new VTK window only if there is no one opened. + \fn PyObject* getRenderWindow( int toCreate = 0 ); + \brief Get VTK render window (vtkRenderWindow). + + If \a toCreate parameter is 0 (by default) the function tries to find + and reuse existing VTK window; if it is not found, the new VTK window + is opened. + + If \a toCreate parameter is non-zero, the function always creates + new VTK window. + + If VTK window could not be found and or created, the None Python object + is returned. + + \param toCreate window creation mode + \return VTK window render window object */ -class TGetRenderWindowEvent: public SALOME_Event { + +class TGetRenderWindowEvent: public SALOME_Event +{ public: typedef PyObject* TResult; TResult myResult; int myCreate; TGetRenderWindowEvent( bool toCreate ) - : myResult( Py_None ), myCreate( toCreate ) {} - virtual void Execute() { - if( SVTK_ViewWindow* aVTKViewWindow = GetVTKViewWindow( myCreate ? __Create : __FindOrCreate ) ) { - PyObject* aPyClass = GetPyClass("vtkRenderWindow"); + : myResult( Py_None ), myCreate( toCreate ) {} + virtual void Execute() + { + PyObject* aPyClass = ::GetPyClass( "vtkRenderWindow" ); + SVTK_ViewWindow* aVTKViewWindow = + ::GetVTKViewWindow( myCreate ? __Create : __FindOrCreate ); + if( aVTKViewWindow && aPyClass ) { vtkRenderWindow* aVTKObject = aVTKViewWindow->getRenderWindow(); - myResult = PyVTKObject_New(aPyClass,aVTKObject); + myResult = PyVTKObject_New( aPyClass, aVTKObject ); } } }; -extern "C" PyObject *libSalomePy_getRenderWindow(PyObject *self, PyObject *args) + +extern "C" PyObject* libSalomePy_getRenderWindow( PyObject* self, PyObject* args ) { PyObject* aResult = Py_None; int toCreate = 0; - if ( !PyArg_ParseTuple(args, "|i:getRenderWindow", &toCreate) ) + if ( !PyArg_ParseTuple( args, "|i:getRenderWindow", &toCreate ) ) PyErr_Print(); else aResult = ProcessEvent( new TGetRenderWindowEvent( toCreate ) ); @@ -203,30 +262,48 @@ extern "C" PyObject *libSalomePy_getRenderWindow(PyObject *self, PyObject *args) } /*! - Get VTK render window interactor. - Always opens new VTK window if parameter is non zero. - Otherwise opens new VTK window only if there is no one opened. + \fn PyObject* getRenderWindowInteractor( int toCreate = 0 ); + \brief Get VTK render window interactor (getRenderWindowInteractor). + + If \a toCreate parameter is 0 (by default) the function tries to find + and reuse existing VTK window; if it is not found, the new VTK window + is opened. + + If \a toCreate parameter is non-zero, the function always creates + new VTK window. + + If VTK window could not be found and or created, the None Python object + is returned. + + \param toCreate window creation mode + \return VTK window render window interactor object */ -class TGetRenderWindowInteractorEvent: public SALOME_Event { + +class TGetRenderWindowInteractorEvent: public SALOME_Event +{ public: typedef PyObject* TResult; TResult myResult; int myCreate; TGetRenderWindowInteractorEvent( bool toCreate ) - : myResult( Py_None ), myCreate( toCreate ) {} - virtual void Execute() { - if( SVTK_ViewWindow* aVTKViewWindow = GetVTKViewWindow( myCreate ? __Create : __FindOrCreate ) ) { - PyObject* aPyClass = GetPyClass("vtkRenderWindowInteractor"); + : myResult( Py_None ), myCreate( toCreate ) {} + virtual void Execute() + { + PyObject* aPyClass = ::GetPyClass( "vtkRenderWindowInteractor" ); + SVTK_ViewWindow* aVTKViewWindow = + ::GetVTKViewWindow( myCreate ? __Create : __FindOrCreate ); + if( aVTKViewWindow && aPyClass ) { vtkRenderWindowInteractor* aVTKObject = aVTKViewWindow->getInteractor(); - myResult = PyVTKObject_New(aPyClass,aVTKObject); + myResult = PyVTKObject_New( aPyClass, aVTKObject ); } } }; -extern "C" PyObject *libSalomePy_getRenderWindowInteractor(PyObject *self, PyObject *args) + +extern "C" PyObject* libSalomePy_getRenderWindowInteractor( PyObject* self, PyObject* args ) { PyObject* aResult = Py_None; int toCreate = 0; - if ( !PyArg_ParseTuple(args, "|i:getRenderWindowInteractor", &toCreate) ) + if ( !PyArg_ParseTuple( args, "|i:getRenderWindowInteractor", &toCreate ) ) PyErr_Print(); else aResult = ProcessEvent( new TGetRenderWindowInteractorEvent( toCreate ) ); @@ -234,16 +311,25 @@ extern "C" PyObject *libSalomePy_getRenderWindowInteractor(PyObject *self, PyObj } /*! - Show/hide trihedron in the current VTK viewer (if there is one) + \fn PyObject* showTrihedron( int show ); + \brief Show/hide trihedron in the current VTK viewer. + + If there is no active VTK viewer, nothing happens. + + \param show new trihedron visibility state + \return nothing (Py_None) */ -extern "C" PyObject *libSalomePy_showTrihedron(PyObject *self, PyObject *args) + +extern "C" PyObject* libSalomePy_showTrihedron( PyObject* self, PyObject* args ) { - class TEvent: public SALOME_Event { + class TEvent: public SALOME_Event + { public: int myShow; TEvent( int bShow ) - : myShow( bShow ) {} - virtual void Execute() { + : myShow( bShow ) {} + virtual void Execute() + { if( SVTK_ViewWindow* aVTKViewWindow = GetVTKViewWindow( __Find ) ) { if ( aVTKViewWindow->isTrihedronDisplayed() != myShow ) aVTKViewWindow->onViewTrihedron(); @@ -253,7 +339,7 @@ extern "C" PyObject *libSalomePy_showTrihedron(PyObject *self, PyObject *args) PyObject* aResult = Py_None; int bShow = 0; - if ( !PyArg_ParseTuple(args, "i:showTrihedron", &bShow) ) + if ( !PyArg_ParseTuple( args, "i:showTrihedron", &bShow ) ) PyErr_Print(); else ProcessVoidEvent( new TEvent( bShow ) ); @@ -261,14 +347,22 @@ extern "C" PyObject *libSalomePy_showTrihedron(PyObject *self, PyObject *args) } /*! - Fit all the contents in the current VTK viewer (if there is one) + \fn PyObject* fitAll(); + \brief Fit all the contents in the current VTK viewer. + + If there is no active VTK viewer, nothing happens. + + \return nothing (Py_None) */ -extern "C" PyObject *libSalomePy_fitAll(PyObject *self, PyObject *args) + +extern "C" PyObject* libSalomePy_fitAll( PyObject* self, PyObject* args ) { - class TEvent: public SALOME_Event { + class TEvent: public SALOME_Event + { public: TEvent() {} - virtual void Execute() { + virtual void Execute() + { if( SVTK_ViewWindow* aVTKViewWindow = GetVTKViewWindow( __Find ) ) { aVTKViewWindow->onFitAll(); } @@ -280,15 +374,24 @@ extern "C" PyObject *libSalomePy_fitAll(PyObject *self, PyObject *args) } /*! - Set view type fot the current VTK viewer (if there is one) + \fn PyObject* setView( int type ); + \brief Set view type for the current VTK viewer. + + If there is no active VTK viewer, nothing happens. + + \param type view type + \return nothing (Py_None) */ -extern "C" PyObject *libSalomePy_setView(PyObject *self, PyObject *args) + +extern "C" PyObject* libSalomePy_setView( PyObject* self, PyObject* args ) { - class TEvent: public SALOME_Event { + class TEvent: public SALOME_Event + { public: long myType; TEvent( long type ) : myType( type) {} - virtual void Execute() { + virtual void Execute() + { if( SVTK_ViewWindow* aVTKViewWindow = GetVTKViewWindow( __Find ) ) { switch( myType ) { case ViewFront: @@ -312,7 +415,7 @@ extern "C" PyObject *libSalomePy_setView(PyObject *self, PyObject *args) }; long type = -1; - if ( !PyArg_ParseTuple(args, "l:setView", &type) ) + if ( !PyArg_ParseTuple( args, "l:setView", &type ) ) PyErr_Print(); else { ProcessVoidEvent( new TEvent( type ) ); @@ -323,15 +426,22 @@ extern "C" PyObject *libSalomePy_setView(PyObject *self, PyObject *args) } /*! - Reset contents of the current VTK viewer (if there is one) - to the default state + \fn PyObject* resetView(); + \brief Reset contents of the current VTK viewer. + + If there is no active VTK viewer, nothing happens. + + \return nothing (Py_None) */ -extern "C" PyObject *libSalomePy_resetView(PyObject *self, PyObject *args) + +extern "C" PyObject* libSalomePy_resetView( PyObject* self, PyObject* args ) { - class TEvent: public SALOME_Event { + class TEvent: public SALOME_Event + { public: TEvent() {} - virtual void Execute() { + virtual void Execute() + { if( SVTK_ViewWindow* aVTKViewWindow = GetVTKViewWindow( __Find ) ) { aVTKViewWindow->onResetView(); } @@ -342,9 +452,6 @@ extern "C" PyObject *libSalomePy_resetView(PyObject *self, PyObject *args) return Py_None; } -/*! - Library initialization -*/ static PyMethodDef Module_Methods[] = { { "getRenderer", libSalomePy_getRenderer, METH_VARARGS }, @@ -357,20 +464,27 @@ static PyMethodDef Module_Methods[] = { NULL, NULL } }; +/*! + \brief Python module initialization. + \internal +*/ extern "C" void initlibSalomePy() { - static char modulename[] = "libSalomePy"; + static char* modulename = "libSalomePy"; + // init module - PyObject* aModule = Py_InitModule(modulename, Module_Methods); + PyObject* aModule = Py_InitModule( modulename, Module_Methods ); if( PyErr_Occurred() ) { PyErr_Print(); return; } + // get module's dictionary PyObject *aModuleDict = PyModule_GetDict( aModule ); if ( aModuleDict == NULL ) return; - // add View type enumeration + + // export View type enumeration PUBLISH_ENUM( ViewFront ); PUBLISH_ENUM( ViewBack ); PUBLISH_ENUM( ViewTop ); diff --git a/src/SALOME_SWIG/SALOMEGUI_Swig.cxx b/src/SALOME_SWIG/SALOMEGUI_Swig.cxx index 783add5b0..a6f44c2c2 100644 --- a/src/SALOME_SWIG/SALOMEGUI_Swig.cxx +++ b/src/SALOME_SWIG/SALOMEGUI_Swig.cxx @@ -19,12 +19,9 @@ // // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // -// -// // File : SALOMEGUI_Swig.cxx // Author : Vadim SANDLER -// Module : SALOME -// $Header$ +// #include "SALOMEGUI_Swig.hxx" @@ -39,6 +36,7 @@ #include #include #include +#include #include #include #include @@ -51,19 +49,46 @@ #include #include -#include -#include CORBA_CLIENT_HEADER(SALOME_ModuleCatalog) - /*! - asv : 3.12.04 : added checking for NULL GUI objects in almost all methods. - In the scope of fixing bug PAL6869. + \class SALOMEGUI_Swig + \brief Python interface module for SALOME GUI. + + This module provides an access to the SALOME GUI implementing set of functions + which can be used from Python. This module is implemented using SWIG wrappings + for some GUI functionality: + - getActiveStudyId(), getActiveStudyName() : get active study identifier and name + - updateObjBrowser() : update contents of the Object Browser + - SelectedCount() : get number of currently selected items + - getSelected() : get entry of the speicified selected item + - ClearIObjects() : clear selection + - Display(), DisplayOnly(), Erase() : display/erase objects + - etc. - (PR : modify comments) Instance of this class is created every time "import salome" line is typed - - in IAPP embedded Python interpretor (SALOME_Session_Server executable), - - in inline Python nodes in Supervisor (in SALOME_Container executable), - - in stand-alone Python console outside any executable. - SALOME GUI(desktop and other objects) is only available in SALOME_Session_Server + - in IAPP embedded Python interpretor (SALOME_Session_Server executable) + - in inline Python nodes in Supervisor (in SALOME_Container executable) + - in stand-alone Python console outside any executable + + SALOME GUI (desktop and other objects) is only available in SALOME_Session_Server. + It means that it can not be accessed from the external Python console. + + The usage in Python: + \code + import libSALOME_Swig + sg = libSALOME_Swig.SALOMEGUI_Swig() + if sg.hasDesktop(): + selcount = sg.SelectedCount() + if selcount > 0: + sg.Erase( sg.getSelected( 0 ) ) + pass + \endcode +*/ + +/* + --- INTERNAL COMMENTS SECTION --- + + ASV : 03.12.04 : added checking for NULL GUI objects in almost all methods. + In the scope of fixing bug PAL6869. VSR : 19.04.05 : Reimplemented for new SALOME GUI (SUIT-based) All methods are implemeted using Event mechanism. @@ -72,18 +97,21 @@ */ /*! - getApplication() - Returns active application object [ static ] + \brief Get active application object + \internal + \return active application or 0 if there is no any */ -static SalomeApp_Application* getApplication() { +static SalomeApp_Application* getApplication() +{ if ( SUIT_Session::session() ) return dynamic_cast( SUIT_Session::session()->activeApplication() ); - return NULL; + return 0; } /*! - getActiveStudy() - Gets active study or 0 if there is no study opened [ static ] + \brief Get active study object + \internal + \return active study or 0 if there is no study opened */ static SalomeApp_Study* getActiveStudy() { @@ -93,54 +121,53 @@ static SalomeApp_Study* getActiveStudy() } /*! - SALOMEGUI_Swig::SALOMEGUI_Swig - Constructor + \brief Constructor. */ SALOMEGUI_Swig::SALOMEGUI_Swig() { } /*! - SALOMEGUI_Swig::~SALOMEGUI_Swig - Destructor + \brief Destructor */ SALOMEGUI_Swig::~SALOMEGUI_Swig() { } /*! - SALOMEGUI_Swig::hasDesktop - Returns TRUE if GUI is available. + \fn bool SALOMEGUI_Swig::hasDesktop() + \brief Check GUI availability. + \return \c true if GUI is available */ -class THasDesktopEvent: public SALOME_Event { + +class THasDesktopEvent: public SALOME_Event +{ public: typedef bool TResult; TResult myResult; THasDesktopEvent() : myResult( false ) {} - virtual void Execute() { + virtual void Execute() + { myResult = (bool)( getApplication() && getApplication()->desktop() ); } }; - -/*! - \return true if GUI is available. -*/ bool SALOMEGUI_Swig::hasDesktop() { return ProcessEvent( new THasDesktopEvent() ); } /*! - SALOMEGUI_Swig::updateObjBrowser - Updates active study's Object Browser. - VSR: updateSelection parameter is currently not used. Will be implemented or removed lately. + \brief Update active study's Object Browser. + \param updateSelection this parameter is obsolete */ void SALOMEGUI_Swig::updateObjBrowser( bool /*updateSelection*/ ) { - class TEvent: public SALOME_Event { + class TEvent: public SALOME_Event + { public: TEvent() {} - virtual void Execute() { + virtual void Execute() + { if ( SalomeApp_Application* anApp = getApplication() ) { anApp->updateObjectBrowser(); anApp->updateActions(); //SRN: added in order to update the toolbar @@ -151,192 +178,162 @@ void SALOMEGUI_Swig::updateObjBrowser( bool /*updateSelection*/ ) } /*! - SALOMEGUI_Swig::getActiveStudyId - Returns active study's ID or 0 if there is no active study. + \fn int SALOMEGUI_Swig::getActiveStudyId() + \brief Get active study identifier + \return active study's ID or 0 if there is no active study */ -class TGetActiveStudyIdEvent: public SALOME_Event { + +class TGetActiveStudyIdEvent: public SALOME_Event +{ public: typedef int TResult; TResult myResult; TGetActiveStudyIdEvent() : myResult( 0 ) {} - virtual void Execute() { + virtual void Execute() + { if ( SalomeApp_Study* aStudy = getActiveStudy() ) { myResult = aStudy->studyDS()->StudyId(); } } }; - -/*! - \return active study's ID or 0 if there is no active study. -*/ int SALOMEGUI_Swig::getActiveStudyId() { return ProcessEvent( new TGetActiveStudyIdEvent() ); } /*! - SALOMEGUI_Swig::getActiveStudyName - Returns active study's name or NULL if there is no active study. + \fn const char* SALOMEGUI_Swig::getActiveStudyName() + \brief Get active study name + \return active study's name or null string if there is no active study */ -class TGetActiveStudyNameEvent: public SALOME_Event { + +class TGetActiveStudyNameEvent: public SALOME_Event +{ public: typedef std::string TResult; TResult myResult; TGetActiveStudyNameEvent() {} - virtual void Execute() { + virtual void Execute() + { if ( SalomeApp_Study* aStudy = getActiveStudy() ) { myResult = aStudy->studyDS()->Name(); } } }; - -/*! - \return active study's name or NULL if there is no active study. -*/ const char* SALOMEGUI_Swig::getActiveStudyName() { std::string result = ProcessEvent( new TGetActiveStudyNameEvent() ); - return result.empty() ? NULL : result.c_str(); + return result.empty() ? 0 : result.c_str(); } /*! - SALOMEGUI_Swig::getComponentName - Returns the name of the component by its user name. + \fn const char* SALOMEGUI_Swig::getComponentName( const char* componentUserName ) + \brief Get name of the component by its title (user name) + \param componentUserName component title (user name) + \return component name or null string if component title is invalid */ -class TGetModulCatalogEvent: public SALOME_Event { -public: - typedef CORBA::Object_var TResult; - TResult myResult; - TGetModulCatalogEvent() : myResult(CORBA::Object::_nil()) {} - virtual void Execute() { - if (SalomeApp_Application* anApp = getApplication()) - myResult = anApp->namingService()->Resolve("/Kernel/ModulCatalog"); - } -}; /*! - \return the name of the component by its user name. + \fn const char* SALOMEGUI_Swig::getComponentUserName( const char* componentName ) + \brief Get title (user name) of the component by its name + \param componentName component name + \return component title or null string if component name is invalid */ -const char* SALOMEGUI_Swig::getComponentName( const char* componentUserName ) + +class TGetComponentNameEvent: public SALOME_Event { - CORBA::Object_var anObject = ProcessEvent(new TGetModulCatalogEvent()); - if (!CORBA::is_nil(anObject)) { - SALOME_ModuleCatalog::ModuleCatalog_var aCatalogue = - SALOME_ModuleCatalog::ModuleCatalog::_narrow( anObject ); - SALOME_ModuleCatalog::ListOfIAPP_Affich_var aModules = aCatalogue->GetComponentIconeList(); - for ( unsigned int ind = 0; ind < aModules->length(); ind++ ) { - CORBA::String_var aModuleName = aModules[ ind ].modulename; - CORBA::String_var aModuleUserName = aModules[ ind ].moduleusername; - if ( strcmp(componentUserName, aModuleUserName.in()) == 0 ) - return aModuleName._retn(); +public: + typedef QString TResult; + TResult myResult; + QString myName; + bool myIsUserName; + TGetComponentNameEvent( const QString& name, bool isUserName ) + : myName( name ), myIsUserName( isUserName ) {} + virtual void Execute() + { + if ( SalomeApp_Application* app = getApplication() ) { + myResult = myIsUserName ? app->moduleTitle( myName ) : app->moduleName( myName ); } } - return 0; +}; +const char* SALOMEGUI_Swig::getComponentName( const char* componentUserName ) +{ + QString result = ProcessEvent( new TGetComponentNameEvent( componentUserName, false ) ); + return result.isEmpty() ? 0 : strdup( result.toLatin1().constData() ); } - -/*! - SALOMEGUI_Swig::getComponentUserName - Returns the user name of the component by its name. -*/ const char* SALOMEGUI_Swig::getComponentUserName( const char* componentName ) { - CORBA::Object_var anObject = ProcessEvent(new TGetModulCatalogEvent()); - if (!CORBA::is_nil(anObject)) { - SALOME_ModuleCatalog::ModuleCatalog_var aCatalogue = - SALOME_ModuleCatalog::ModuleCatalog::_narrow( anObject ); - SALOME_ModuleCatalog::ListOfIAPP_Affich_var aModules = aCatalogue->GetComponentIconeList(); - for ( unsigned int ind = 0; ind < aModules->length(); ind++ ) { - CORBA::String_var aModuleName = aModules[ ind ].modulename; - CORBA::String_var aModuleUserName = aModules[ ind ].moduleusername; - if ( strcmp(componentName, aModuleName.in()) == 0 ) - return aModuleUserName._retn(); - } - } - return 0; + QString result = ProcessEvent( new TGetComponentNameEvent( componentName, true ) ); + return result.isEmpty() ? 0 : strdup( result.toLatin1().constData() ); } /*! - SALOMEGUI_Swig::SelectedCount - Returns the number of selected objects. + \fn int SALOMEGUI_Swig::SelectedCount() + \brief Get number of selected items + \return number of selected items in the active study */ -class TSelectedCountEvent: public SALOME_Event { -public: - typedef int TResult; - TResult myResult; - TSelectedCountEvent() : myResult( 0 ) {} - virtual void Execute() { - if ( SalomeApp_Application* anApp = getApplication() ) { - SalomeApp_Study* aStudy = dynamic_cast( anApp->activeStudy() ); // for sure! - LightApp_SelectionMgr* aSelMgr = anApp->selectionMgr(); - if ( aStudy && aSelMgr ) { - SALOME_ListIO anIOList; - aSelMgr->selectedObjects( anIOList ); - myResult = anIOList.Extent(); - } - } - } -}; /*! - \return the number of selected objects. + \fn const char* SALOMEGUI_Swig::getSelected( int index ) + \brief Get entry of the specified selected item + \param index selected object index + \return selected object entry (null string if index is invalid) */ -int SALOMEGUI_Swig::SelectedCount() -{ - return ProcessEvent( new TSelectedCountEvent() ); -} -/*! - SALOMEGUI_Swig::getSelected - Returns the selected object entry by the given index. -*/ -class TGetSelectedEvent: public SALOME_Event { +class TGetSelectedEvent: public SALOME_Event +{ public: - typedef QString TResult; + typedef QStringList TResult; TResult myResult; - int myIndex; - TGetSelectedEvent( int theIndex ) : myIndex( theIndex ) {} - virtual void Execute() { + TGetSelectedEvent() {} + virtual void Execute() + { if ( SalomeApp_Application* anApp = getApplication() ) { - SalomeApp_Study* aStudy = dynamic_cast( anApp->activeStudy() ); // for sure! + SalomeApp_Study* aStudy = dynamic_cast( anApp->activeStudy() ); // for sure! LightApp_SelectionMgr* aSelMgr = anApp->selectionMgr(); if ( aStudy && aSelMgr ) { - SALOME_ListIO anIOList; - aSelMgr->selectedObjects( anIOList ); - if ( myIndex < anIOList.Extent() ) { - int index = 0; - SALOME_ListIteratorOfListIO anIter( anIOList ); - for( ; anIter.More(); anIter.Next(), index++ ) { - Handle(SALOME_InteractiveObject) anIO = anIter.Value(); - if ( myIndex == index ) { - myResult = anIO->getEntry(); - return; - } - } + SUIT_DataOwnerPtrList aList; + aSelMgr->selected( aList ); + + for ( SUIT_DataOwnerPtrList::const_iterator itr = aList.begin(); + itr != aList.end(); ++itr ) { + const LightApp_DataOwner* owner = + dynamic_cast( (*itr).operator->() ); + if( !owner ) + continue; + QString entry = owner->entry(); + if( !myResult.contains( entry ) ) + myResult.append( entry ); } } } } }; - -/*! - \return the selected object entry by the given index. -*/ +int SALOMEGUI_Swig::SelectedCount() +{ + QStringList selected = ProcessEvent( new TGetSelectedEvent() ); + return selected.count(); +} const char* SALOMEGUI_Swig::getSelected( int index ) { - QString result = ProcessEvent( new TGetSelectedEvent( index ) ); - return result.isEmpty() ? NULL : strdup( result.toLatin1() ); + QStringList selected = ProcessEvent( new TGetSelectedEvent() ); + return index >= 0 && index < selected.count() ? + strdup( selected[ index ].toLatin1().constData() ) : 0; } /*! - Adds an object with the given entry to the selection. + \brief Add an object to the current selection. + \param theEntry object entry */ void SALOMEGUI_Swig::AddIObject( const char* theEntry ) { - class TEvent: public SALOME_Event { + class TEvent: public SALOME_Event + { public: QString myEntry; TEvent( const char* theEntry ) : myEntry( theEntry ) {} - virtual void Execute() { + virtual void Execute() + { if ( SalomeApp_Application* anApp = getApplication() ) { SalomeApp_Study* aStudy = dynamic_cast( anApp->activeStudy() ); // for sure! LightApp_SelectionMgr* aSelMgr = anApp->selectionMgr(); @@ -352,17 +349,20 @@ void SALOMEGUI_Swig::AddIObject( const char* theEntry ) } /*! - Removes the object with the given entry from the selection. + \brief Remove the object from the selection. + \param theEntry object entry */ void SALOMEGUI_Swig::RemoveIObject( const char* theEntry ) { - class TEvent: public SALOME_Event { + class TEvent: public SALOME_Event + { public: QString myEntry; TEvent( const char* theEntry ) : myEntry( theEntry ) {} - virtual void Execute() { + virtual void Execute() + { if ( SalomeApp_Application* anApp = getApplication() ) { - SalomeApp_Study* aStudy = dynamic_cast( anApp->activeStudy() ); // for sure! + SalomeApp_Study* aStudy = dynamic_cast( anApp->activeStudy() ); // for sure! LightApp_SelectionMgr* aSelMgr = anApp->selectionMgr(); if ( aStudy && aSelMgr ) { SALOME_ListIO anIOList; @@ -388,16 +388,18 @@ void SALOMEGUI_Swig::RemoveIObject( const char* theEntry ) } /*! - Clears selection. + \brief Clear selection (unselect all objects). */ void SALOMEGUI_Swig::ClearIObjects() { - class TEvent: public SALOME_Event { + class TEvent: public SALOME_Event + { public: TEvent() {} - virtual void Execute() { + virtual void Execute() + { if ( SalomeApp_Application* anApp = getApplication() ) { - SalomeApp_Study* aStudy = dynamic_cast( anApp->activeStudy() ); // for sure! + SalomeApp_Study* aStudy = dynamic_cast( anApp->activeStudy() ); // for sure! LightApp_SelectionMgr* aSelMgr = anApp->selectionMgr(); if ( aStudy && aSelMgr ) aSelMgr->clearSelected(); @@ -408,13 +410,19 @@ void SALOMEGUI_Swig::ClearIObjects() } /*! - Displays an object in the current view window - (the presentable object should be previously created and displayed in this viewer). - VSR: For the current moment implemented for OCC and VTK viewers only. + \brief Display an object in the current view window. + + The presentable object should be previously created and + displayed in this viewer. + + For the current moment implemented for OCC and VTK viewers only. + + \param theEntry object entry */ void SALOMEGUI_Swig::Display( const char* theEntry ) { - class TEvent: public SALOME_Event { + class TEvent: public SALOME_Event + { QString myEntry; public: TEvent( const char* theEntry ) : myEntry( theEntry ) {} @@ -433,17 +441,25 @@ void SALOMEGUI_Swig::Display( const char* theEntry ) } /*! - Displays an object in the current view window and erases all other - (the presentable object should be previously created and displayed in this viewer). - VSR: For the current moment implemented for OCC and VTK viewers only. + \brief Displays an object in the current view window and + erases all other ones. + + The presentable object should be previously created and + displayed in this viewer. + + For the current moment implemented for OCC and VTK viewers only. + + \param theEntry object entry */ void SALOMEGUI_Swig::DisplayOnly( const char* theEntry ) { - class TEvent: public SALOME_Event { + class TEvent: public SALOME_Event + { QString myEntry; public: TEvent( const char* theEntry ) : myEntry( theEntry ) {} - virtual void Execute() { + virtual void Execute() + { if ( SalomeApp_Application* anApp = getApplication() ) { SUIT_ViewWindow* window = anApp->desktop()->activeWindow(); if ( window ) { @@ -460,17 +476,24 @@ void SALOMEGUI_Swig::DisplayOnly( const char* theEntry ) } /*! - Erases an object in the current view window - (the presentable object should be previously created and displayed in this viewer). - VSR: For the current moment implemented for OCC and VTK viewers only. + \brief Erase an object in the current view window. + + The presentable object should be previously created and + displayed in this viewer. + + For the current moment implemented for OCC and VTK viewers only. + + \param theEntry object entry */ void SALOMEGUI_Swig::Erase( const char* theEntry ) { - class TEvent: public SALOME_Event { + class TEvent: public SALOME_Event + { QString myEntry; public: TEvent( const char* theEntry ) : myEntry( theEntry ) {} - virtual void Execute() { + virtual void Execute() + { if ( SalomeApp_Application* anApp = getApplication() ) { SUIT_ViewWindow* window = anApp->desktop()->activeWindow(); if ( window ) { @@ -485,16 +508,22 @@ void SALOMEGUI_Swig::Erase( const char* theEntry ) } /*! - Displays all active module's child objects in the current view window - (the presentable objects should be previously created and displayed in this viewer). - VSR: For the current moment implemented for OCC and VTK viewers only. + \brief Display all active module's presentable + child objects in the current view window. + + The presentable objects should be previously created and + displayed in this viewer. + + For the current moment implemented for OCC and VTK viewers only. */ void SALOMEGUI_Swig::DisplayAll() { - class TEvent: public SALOME_Event { + class TEvent: public SALOME_Event + { public: TEvent() {} - virtual void Execute() { + virtual void Execute() + { if ( SalomeApp_Application* anApp = getApplication() ) { SalomeApp_Study* study = dynamic_cast( anApp->activeStudy() ); // for sure! SUIT_ViewWindow* window = anApp->desktop()->activeWindow(); @@ -516,15 +545,18 @@ void SALOMEGUI_Swig::DisplayAll() } /*! - Erases all objects from the current view window - VSR: For the current moment implemented for OCC and VTK viewers only. + \brief Erase all objects from the current view window. + + For the current moment implemented for OCC and VTK viewers only. */ void SALOMEGUI_Swig::EraseAll() { - class TEvent: public SALOME_Event { + class TEvent: public SALOME_Event + { public: TEvent() {} - virtual void Execute() { + virtual void Execute() + { if ( SalomeApp_Application* anApp = getApplication() ) { SUIT_ViewWindow* window = anApp->desktop()->activeWindow(); if ( window ) { @@ -539,16 +571,25 @@ void SALOMEGUI_Swig::EraseAll() } /*! - Returns TRUE if the object with given entry is in the current viewer. + \fn bool SALOMEGUI_Swig::IsInCurrentView( const char* theEntry ) + \brief Check it the object is displayed in the current view window. + VSR: For the current moment implemented for OCC and VTK viewers only. + + \param theEntry object entry + \return \c true if the object with given entry is displayed + in the current viewer */ -class TIsInViewerEvent: public SALOME_Event { + +class TIsInViewerEvent: public SALOME_Event +{ QString myEntry; public: typedef bool TResult; TResult myResult; TIsInViewerEvent( const char* theEntry ) : myEntry( theEntry ), myResult( false ) {} - virtual void Execute() { + virtual void Execute() + { if ( SalomeApp_Application* anApp = getApplication() ) { SUIT_ViewWindow* window = anApp->desktop()->activeWindow(); if ( window ) { @@ -561,25 +602,22 @@ public: } } }; - -/*! - \return TRUE if the object with given entry is in the current viewer. - VSR: For the current moment implemented for OCC and VTK viewers only. -*/ bool SALOMEGUI_Swig::IsInCurrentView( const char* theEntry ) { return ProcessEvent( new TIsInViewerEvent( theEntry ) ); } /*! - Updates (repaint) current view + \brief Update (repaint) current view window. */ void SALOMEGUI_Swig::UpdateView() { - class TEvent: public SALOME_Event { + class TEvent: public SALOME_Event + { public: TEvent() {} - virtual void Execute() { + virtual void Execute() + { if ( SalomeApp_Application* anApp = getApplication() ) { SUIT_ViewWindow* window = anApp->desktop()->activeWindow(); if ( window ) { @@ -594,23 +632,25 @@ void SALOMEGUI_Swig::UpdateView() } /*! - Fit all the contents of the current view window - */ + \brief Fit current view window to display all its contents. +*/ void SALOMEGUI_Swig::FitAll() { - class TEvent: public SALOME_Event { + class TEvent: public SALOME_Event + { public: TEvent() {} - virtual void Execute() { + virtual void Execute() + { if ( SalomeApp_Application* anApp = getApplication() ) { SUIT_ViewWindow* window = anApp->desktop()->activeWindow(); if ( window ) { if ( dynamic_cast( window ) ) - (dynamic_cast( window ))->onFitAll(); + ( dynamic_cast( window ) )->onFitAll(); else if ( dynamic_cast( window ) ) - (dynamic_cast( window ))->onFitAll(); + ( dynamic_cast( window ) )->onFitAll(); else if ( dynamic_cast( window ) ) - (dynamic_cast( window ))->onFitAll(); + ( dynamic_cast( window ) )->onFitAll(); } } } @@ -619,14 +659,16 @@ void SALOMEGUI_Swig::FitAll() } /*! - Reset current view window to the default state. - */ + \brief Reset current view window to the default state. +*/ void SALOMEGUI_Swig::ResetView() { - class TEvent: public SALOME_Event { + class TEvent: public SALOME_Event + { public: TEvent() {} - virtual void Execute() { + virtual void Execute() + { if ( SalomeApp_Application* anApp = getApplication() ) { SUIT_ViewWindow* window = anApp->desktop()->activeWindow(); if ( window ) { @@ -645,23 +687,34 @@ void SALOMEGUI_Swig::ResetView() ProcessVoidEvent( new TEvent() ); } +/*! + \brief View operation type. + \internal +*/ enum { - __ViewTop, - __ViewBottom, - __ViewLeft, - __ViewRight, - __ViewFront, - __ViewBack + __ViewTop, //!< view top side + __ViewBottom, //!< view bottom side + __ViewLeft, //!< view left side + __ViewRight, //!< view right side + __ViewFront, //!< view front side + __ViewBack //!< view back side }; -void setView( int view ) +/*! + \brief Change the view of the current view window. + \internal + \param view view operation type +*/ +static void setView( int view ) { - class TEvent: public SALOME_Event { + class TEvent: public SALOME_Event + { private: int myView; public: TEvent( int view ) : myView( view ) {} - virtual void Execute() { + virtual void Execute() + { if ( SalomeApp_Application* anApp = getApplication() ) { SUIT_ViewWindow* window = anApp->desktop()->activeWindow(); if ( window ) { @@ -709,48 +762,48 @@ void setView( int view ) } /*! - Switch current view window to show top view - */ + \brief Switch current view window to show the top view. +*/ void SALOMEGUI_Swig::ViewTop() { setView( __ViewTop ); } /*! - Switch current view window to show bottom view - */ + \brief Switch current view window to show the bottom view +*/ void SALOMEGUI_Swig::ViewBottom() { setView( __ViewBottom ); } /*! - Switch current view window to show left view - */ + \brief Switch current view window to show the left view +*/ void SALOMEGUI_Swig::ViewLeft() { setView( __ViewLeft ); } /*! - Switch current view window to show right view - */ + \brief Switch current view window to show the right view +*/ void SALOMEGUI_Swig::ViewRight() { setView( __ViewRight ); } /*! - Switch current view window to show front view - */ + \brief Switch current view window to show the front view +*/ void SALOMEGUI_Swig::ViewFront() { setView( __ViewFront ); } /*! - Switch current view window to show back view - */ + \brief Switch current view window to show the back view +*/ void SALOMEGUI_Swig::ViewBack() { setView( __ViewBack ); diff --git a/src/SALOME_SWIG/SALOMEGUI_Swig.hxx b/src/SALOME_SWIG/SALOMEGUI_Swig.hxx index 97e09fa28..76211c33f 100644 --- a/src/SALOME_SWIG/SALOMEGUI_Swig.hxx +++ b/src/SALOME_SWIG/SALOMEGUI_Swig.hxx @@ -19,12 +19,9 @@ // // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // -// -// // File : SALOMEGUI_Swig.hxx // Author : Vadim SANDLER -// Module : SALOME -// $Header$ +// #ifndef SALOMEGUI_SWIG_HXX #define SALOMEGUI_SWIG_HXX @@ -32,37 +29,33 @@ class SALOMEGUI_Swig { public: - /* construction/destruction */ SALOMEGUI_Swig(); ~SALOMEGUI_Swig(); - /* check GUI */ bool hasDesktop(); - /* update object browser*/ - void updateObjBrowser( bool updateSelection ); + void updateObjBrowser( bool ); - /* get active study */ int getActiveStudyId(); const char* getActiveStudyName(); - /* selection processing */ + const char* getComponentName( const char* ); + const char* getComponentUserName( const char* ); + int SelectedCount(); - const char* getSelected(int i); - void AddIObject( const char *Entry ); - void RemoveIObject( const char *Entry ); + const char* getSelected( int i ); + void AddIObject( const char* ); + void RemoveIObject( const char* ); void ClearIObjects(); - /* display/erase */ - void Display( const char *Entry ); - void DisplayOnly( const char *Entry ); - void Erase( const char *Entry ); + void Display( const char* ); + void DisplayOnly( const char* ); + void Erase( const char* ); void DisplayAll(); void EraseAll(); - bool IsInCurrentView( const char *Entry ); + bool IsInCurrentView( const char* ); void UpdateView(); - /* view operations */ void FitAll(); void ResetView(); void ViewTop(); @@ -71,10 +64,6 @@ public: void ViewRight(); void ViewFront(); void ViewBack(); - - /* get component name/username */ - const char* getComponentName( const char* ComponentUserName ); - const char* getComponentUserName( const char* ComponentName ); }; #endif // SALOMEGUI_SWIG_HXX diff --git a/src/SALOME_SWIG/SALOMEGUI_Swig.i b/src/SALOME_SWIG/SALOMEGUI_Swig.i index e01c9cf1e..e19ae9f3e 100644 --- a/src/SALOME_SWIG/SALOMEGUI_Swig.i +++ b/src/SALOME_SWIG/SALOMEGUI_Swig.i @@ -19,12 +19,9 @@ // // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // -// -// // File : SALOMEGUI_Swig.i // Author : Paul RASCLE, EDF -// Module : SALOME -// $Header$ +// %{ #include "SALOMEGUI_Swig.hxx" @@ -39,9 +36,9 @@ // Py_BEGIN_ALLOW_THREADS PyAllowThreadsGuard() { _save = PyEval_SaveThread(); } // Py_END_ALLOW_THREADS - ~PyAllowThreadsGuard() { PyEval_RestoreThread(_save); } + ~PyAllowThreadsGuard() { PyEval_RestoreThread( _save ); } private: - PyThreadState *_save; + PyThreadState* _save; }; PyAllowThreadsGuard guard; @@ -51,29 +48,32 @@ class SALOMEGUI_Swig { - public: -/* construction/destruction */ +public: SALOMEGUI_Swig(); - ~SALOMEGUI_Swig(); + virtual ~SALOMEGUI_Swig(); -/* check GUI */ + /* check GUI */ bool hasDesktop(); -/* update object browser*/ + /* update object browser*/ void updateObjBrowser(bool); -/* get active study */ + /* get active study */ int getActiveStudyId(); const char *getActiveStudyName(); -/* selection processing */ + /* get component name/username */ + const char* getComponentName( const char* ComponentUserName ); + const char* getComponentUserName( const char* ComponentName ); + + /* selection processing */ int SelectedCount(); const char *getSelected(int i); void AddIObject(const char *Entry); void RemoveIObject(const char *Entry); void ClearIObjects(); -/* display/erase */ + /* display/erase */ void Display(const char *Entry); void DisplayOnly(const char *Entry); void Erase(const char *Entry); @@ -82,7 +82,7 @@ class SALOMEGUI_Swig bool IsInCurrentView(const char *Entry); void UpdateView(); -/* view operations */ + /* view operations */ void FitAll(); void ResetView(); void ViewTop(); @@ -91,8 +91,4 @@ class SALOMEGUI_Swig void ViewRight(); void ViewFront(); void ViewBack(); - -/* get component name/username */ - const char* getComponentName( const char* ComponentUserName ); - const char* getComponentUserName( const char* ComponentName ); }; -- 2.39.2