From e66c20243a6cbf888eedb1c3594349fb9c35f7fe Mon Sep 17 00:00:00 2001 From: vsr Date: Tue, 24 Oct 2006 15:22:25 +0000 Subject: [PATCH] For all libSalomePy methods provide "toCreate" parameter (with default value 0) - if this parameter is not 0, the new VTK window is always created. If this parameter is 0, new VTK window is created only if there is no existing one. --- src/LightApp/LightApp_Application.h | 2 +- src/SALOME_PY/SalomePy.cxx | 81 ++++++++++++++++++++--------- 2 files changed, 56 insertions(+), 27 deletions(-) diff --git a/src/LightApp/LightApp_Application.h b/src/LightApp/LightApp_Application.h index b7131da99..cec21a876 100644 --- a/src/LightApp/LightApp_Application.h +++ b/src/LightApp/LightApp_Application.h @@ -126,6 +126,7 @@ public: void updateActions(); SUIT_ViewManager* getViewManager( const QString&, const bool ); + virtual SUIT_ViewManager* createViewManager( const QString& vmType ); virtual void addViewManager( SUIT_ViewManager* ); virtual void removeViewManager( SUIT_ViewManager* ); QWidget* getWindow( const int, const int = -1 ); @@ -226,7 +227,6 @@ protected: QString defaultModule() const; void currentWindows( QMap& ) const; void currentViewManagers( QStringList& ) const; - virtual SUIT_ViewManager* createViewManager( const QString& vmType ); void moduleIconNames( QMap& ) const; void activateWindows(); diff --git a/src/SALOME_PY/SalomePy.cxx b/src/SALOME_PY/SalomePy.cxx index 4603f0dbe..be9a0ca43 100755 --- a/src/SALOME_PY/SalomePy.cxx +++ b/src/SALOME_PY/SalomePy.cxx @@ -74,7 +74,7 @@ static PyObject* GetPyClass(const char* theClassName){ return aPyClass; } -static SVTK_ViewWindow* GetVTKViewWindow() { +static SVTK_ViewWindow* GetVTKViewWindow( bool toCreate = false ) { SVTK_ViewWindow* aVW = NULL; if ( SUIT_Session::session() ) { // get application @@ -84,13 +84,27 @@ static SVTK_ViewWindow* GetVTKViewWindow() { SalomeApp_Study* aStudy = dynamic_cast( anApp->activeStudy() ); if ( aStudy ) { // find or create VTK view manager - SVTK_ViewManager* aVM = dynamic_cast( anApp->getViewManager( "VTKViewer", true ) ); - if ( aVM ) { - aVW = dynamic_cast( aVM->getActiveView() ); - // 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 ] ); + if ( toCreate ) { + SVTK_ViewManager* aVM = dynamic_cast( anApp->createViewManager( "VTKViewer" ) ); + if ( aVM ) { + aVW = dynamic_cast( aVM->getActiveView() ); + if ( !aVW ) + aVW = dynamic_cast( aVM->createViewWindow() ); + // 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 ] ); + } + } + else { + SVTK_ViewManager* aVM = dynamic_cast( anApp->getViewManager( "VTKViewer", true ) ); + if ( aVM ) { + aVW = dynamic_cast( aVM->getActiveView() ); + // 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 ] ); + } } } } @@ -105,9 +119,11 @@ class TGetRendererEvent: public SALOME_Event { public: typedef PyObject* TResult; TResult myResult; - TGetRendererEvent() : myResult( Py_None ) {} + int myCreate; + TGetRendererEvent( bool toCreate ) + : myResult( Py_None ), myCreate( toCreate ) {} virtual void Execute() { - if( SVTK_ViewWindow* aVTKViewWindow = GetVTKViewWindow() ) { + if( SVTK_ViewWindow* aVTKViewWindow = GetVTKViewWindow( myCreate ) ) { PyObject* aPyClass = GetPyClass("vtkRenderer"); vtkRenderer* aVTKObject = aVTKViewWindow->getRenderer(); myResult = PyVTKObject_New(aPyClass,aVTKObject); @@ -116,9 +132,12 @@ public: }; extern "C" PyObject *libSalomePy_getRenderer(PyObject *self, PyObject *args) { - //return ProcessEvent( new TGetRendererEvent() ); - PyObject * aResult; - aResult = ProcessEvent( new TGetRendererEvent() ); + PyObject* aResult = Py_None; + int toCreate = 0; + if ( !PyArg_ParseTuple(args, "|i:test", &toCreate) ) + PyErr_Print(); + else + aResult = ProcessEvent( new TGetRendererEvent( toCreate ) ); return aResult; } @@ -129,9 +148,11 @@ class TGetRenderWindowEvent: public SALOME_Event { public: typedef PyObject* TResult; TResult myResult; - TGetRenderWindowEvent() : myResult( Py_None ) {} + int myCreate; + TGetRenderWindowEvent( bool toCreate ) + : myResult( Py_None ), myCreate( toCreate ) {} virtual void Execute() { - if( SVTK_ViewWindow* aVTKViewWindow = GetVTKViewWindow() ) { + if( SVTK_ViewWindow* aVTKViewWindow = GetVTKViewWindow( myCreate ) ) { PyObject* aPyClass = GetPyClass("vtkRenderWindow"); vtkRenderWindow* aVTKObject = aVTKViewWindow->getRenderWindow(); myResult = PyVTKObject_New(aPyClass,aVTKObject); @@ -140,9 +161,12 @@ public: }; extern "C" PyObject *libSalomePy_getRenderWindow(PyObject *self, PyObject *args) { - //return ProcessEvent( new TGetRenderWindowEvent() ); - PyObject * aResult; - aResult = ProcessEvent( new TGetRenderWindowEvent() ); + PyObject* aResult = Py_None; + int toCreate = 0; + if ( !PyArg_ParseTuple(args, "|i:test", &toCreate) ) + PyErr_Print(); + else + aResult = ProcessEvent( new TGetRenderWindowEvent( toCreate ) ); return aResult; } @@ -153,9 +177,11 @@ class TGetRenderWindowInteractorEvent: public SALOME_Event { public: typedef PyObject* TResult; TResult myResult; - TGetRenderWindowInteractorEvent() : myResult( Py_None ) {} + int myCreate; + TGetRenderWindowInteractorEvent( bool toCreate ) + : myResult( Py_None ), myCreate( toCreate ) {} virtual void Execute() { - if( SVTK_ViewWindow* aVTKViewWindow = GetVTKViewWindow() ) { + if( SVTK_ViewWindow* aVTKViewWindow = GetVTKViewWindow( myCreate ) ) { PyObject* aPyClass = GetPyClass("vtkRenderWindowInteractor"); vtkRenderWindowInteractor* aVTKObject = aVTKViewWindow->getInteractor(); myResult = PyVTKObject_New(aPyClass,aVTKObject); @@ -164,9 +190,12 @@ public: }; extern "C" PyObject *libSalomePy_getRenderWindowInteractor(PyObject *self, PyObject *args) { - //return ProcessEvent( new TGetRenderWindowInteractorEvent() ); - PyObject * aResult; - aResult = ProcessEvent( new TGetRenderWindowInteractorEvent() ); + PyObject* aResult = Py_None; + int toCreate = 0; + if ( !PyArg_ParseTuple(args, "|i:test", &toCreate) ) + PyErr_Print(); + else + aResult = ProcessEvent( new TGetRenderWindowInteractorEvent( toCreate ) ); return aResult; } @@ -175,9 +204,9 @@ extern "C" PyObject *libSalomePy_getRenderWindowInteractor(PyObject *self, PyObj */ static PyMethodDef Module_Methods[] = { - { "getRenderer", libSalomePy_getRenderer, METH_NOARGS }, - { "getRenderWindow", libSalomePy_getRenderWindow, METH_NOARGS }, - { "getRenderWindowInteractor", libSalomePy_getRenderWindowInteractor, METH_NOARGS }, + { "getRenderer", libSalomePy_getRenderer, METH_VARARGS }, + { "getRenderWindow", libSalomePy_getRenderWindow, METH_VARARGS }, + { "getRenderWindowInteractor", libSalomePy_getRenderWindowInteractor, METH_VARARGS }, { NULL, NULL } }; -- 2.39.2