From f1bd7ad816b39100dc19887b9b65232a78041167 Mon Sep 17 00:00:00 2001 From: abn Date: Wed, 15 Oct 2014 14:22:01 +0200 Subject: [PATCH] Various bug fixes for the PVViewer. --- src/LightApp/LightApp_Application.cxx | 2 +- src/PVViewer/CMakeLists.txt | 13 +- src/PVViewer/PVViewer_Behaviors.cxx | 1 - src/PVViewer/PVViewer_EngineWrapper.cxx | 210 ++++++++++----------- src/PVViewer/PVViewer_EngineWrapper.h | 16 +- src/PVViewer/PVViewer_GUIElements.cxx | 4 +- src/PVViewer/PVViewer_LogWindowAdapter.cxx | 21 ++- src/PVViewer/PVViewer_LogWindowAdapter.h | 6 + src/PVViewer/PVViewer_ViewManager.cxx | 12 +- src/PVViewer/PVViewer_ViewManager.h | 6 +- src/PVViewer/PVViewer_ViewModel.cxx | 2 - src/PVViewer/resources/PVViewer_msg_en.ts | 16 ++ 12 files changed, 170 insertions(+), 139 deletions(-) create mode 100644 src/PVViewer/resources/PVViewer_msg_en.ts diff --git a/src/LightApp/LightApp_Application.cxx b/src/LightApp/LightApp_Application.cxx index aadbc566f..a63720714 100644 --- a/src/LightApp/LightApp_Application.cxx +++ b/src/LightApp/LightApp_Application.cxx @@ -1452,7 +1452,7 @@ SUIT_ViewManager* LightApp_Application::createViewManager( const QString& vmType #ifndef DISABLE_PVVIEWER if( vmType == PVViewer_Viewer::Type() ) { - viewMgr = new PVViewer_ViewManager( activeStudy(), desktop() ); + viewMgr = new PVViewer_ViewManager( activeStudy(), desktop(), logWindow() ); } #endif #ifndef DISABLE_OCCVIEWER diff --git a/src/PVViewer/CMakeLists.txt b/src/PVViewer/CMakeLists.txt index f7a25ee6f..ac492e4cc 100644 --- a/src/PVViewer/CMakeLists.txt +++ b/src/PVViewer/CMakeLists.txt @@ -27,8 +27,6 @@ INCLUDE_DIRECTORIES(${GUI_INCLUDE_DIRS} ${CMAKE_SOURCE_DIR}/src/SUIT ${CMAKE_SOURCE_DIR}/src/CAM ${CMAKE_SOURCE_DIR}/src/STD - ${CMAKE_SOURCE_DIR}/src/LightApp - ${CMAKE_SOURCE_DIR}/src/SalomeApp ${CMAKE_SOURCE_DIR}/src/Qtx ${CMAKE_SOURCE_DIR}/src/Event ${CMAKE_SOURCE_DIR}/src/PyInterp @@ -68,11 +66,19 @@ SET(_other_HEADERS # header files / to install SET(PVViewer_HEADERS ${_moc_HEADERS} ${_other_HEADERS}) +# resource files / to be processed by lrelease +SET(_ts_RESOURCES + resources/PVViewer_msg_en.ts +) + # --- sources --- # sources / moc wrappings QT4_WRAP_CPP(_moc_SOURCES ${_moc_HEADERS}) +# sources / rcc wrappings +QT4_ADD_RESOURCES(_rcc_SOURCES ${_rcc_RESOURCES}) + # sources / static SET(_other_SOURCES PVViewer_ViewManager.cxx @@ -88,6 +94,7 @@ SET(_other_SOURCES SET(PVViewer_SOURCES ${_other_SOURCES} ${_moc_SOURCES} + ${_rcc_SOURCES} ) # --- rules --- @@ -96,5 +103,7 @@ ADD_LIBRARY(PVViewer ${PVViewer_SOURCES}) TARGET_LINK_LIBRARIES(PVViewer ${_link_LIBRARIES}) INSTALL(TARGETS PVViewer EXPORT ${PROJECT_NAME}TargetGroup DESTINATION ${SALOME_INSTALL_LIBS}) +QT4_INSTALL_TS_RESOURCES("${_ts_RESOURCES}" "${SALOME_GUI_INSTALL_RES_DATA}") + # --- header and resources installation --- INSTALL(FILES ${PVViewer_HEADERS} DESTINATION ${SALOME_INSTALL_HEADERS}) diff --git a/src/PVViewer/PVViewer_Behaviors.cxx b/src/PVViewer/PVViewer_Behaviors.cxx index 75fc467cc..4b85167b4 100644 --- a/src/PVViewer/PVViewer_Behaviors.cxx +++ b/src/PVViewer/PVViewer_Behaviors.cxx @@ -21,7 +21,6 @@ #include "PVViewer_Behaviors.h" #include -#include #include #include diff --git a/src/PVViewer/PVViewer_EngineWrapper.cxx b/src/PVViewer/PVViewer_EngineWrapper.cxx index 24f026f31..1f1eeee73 100644 --- a/src/PVViewer/PVViewer_EngineWrapper.cxx +++ b/src/PVViewer/PVViewer_EngineWrapper.cxx @@ -21,7 +21,7 @@ #include "PVViewer_EngineWrapper.h" #include -#include +//#include #include PVViewer_EngineWrapper * PVViewer_EngineWrapper::instance = NULL; @@ -33,123 +33,123 @@ PVViewer_EngineWrapper * PVViewer_EngineWrapper::GetInstance() return instance; } -static SalomeApp_Application* getApplication() -{ - if ( SUIT_Session::session() ) - return dynamic_cast( SUIT_Session::session()->activeApplication() ); - return 0; -} - -PVViewer_EngineWrapper::PVViewer_EngineWrapper() -// : paravisEngine(NULL) -{ - _component = getApplication()->lcc()->FindOrLoad_Component( "FactoryServer", "PARAVIS" ); -} - -bool PVViewer_EngineWrapper::GetGUIConnected() -{ - CORBA::Request_var req = _component->_request("GetGUIConnected"); - req->set_return_type(CORBA::_tc_boolean); - req->invoke(); - CORBA::Exception *exc =req->env()->exception(); - if( exc ) - throw SALOME_Exception("Unable to invoke PARAVIS engine!"); - CORBA::Any & ret = req->return_value(); - CORBA::Boolean bo; - - if (ret >>= bo) - return bool(bo); - else - throw SALOME_Exception("Unable to convert engine result!"); -} - -void PVViewer_EngineWrapper::SetGUIConnected(bool isConnected) -{ - CORBA::Request_var req = _component->_request("SetGUIConnected"); - CORBA::Boolean arg = isConnected; - req->add_in_arg() <<= arg; - req->set_return_type(CORBA::_tc_void); - req->invoke(); - CORBA::Exception *exc =req->env()->exception(); - if( exc ) - throw SALOME_Exception("Unable to invoke PARAVIS engine!"); -} - -std::string PVViewer_EngineWrapper::FindOrStartPVServer(int port) -{ - CORBA::Request_var req = _component->_request("FindOrStartPVServer"); - CORBA::Long arg = port; - req->add_in_arg() <<= arg; - req->set_return_type(CORBA::_tc_string); - req->invoke(); - CORBA::Exception *exc =req->env()->exception(); - if( exc ) - throw SALOME_Exception("Unable to invoke PARAVIS engine!"); - - const char* ret; - if(req->return_value() >>= ret) - return std::string(ret); - else - throw SALOME_Exception("Unable to convert engine result!"); -} - -//PVViewer_EngineWrapper::PVViewer_EngineWrapper() : -// paravisEngine(NULL) +//static SalomeApp_Application* getApplication() //{ -//// const char * cmd = "import PARAVIS_utils;e="; -// PyLockWrapper lock; -// const char* code = "import PARAVIS_utils as pa;__enginePARAVIS=pa.getEngine()"; -// int ret = PyRun_SimpleString(const_cast(code)); -// -// if (ret == -1) -// throw SALOME_Exception("Unable to retrieve PARAVIS engine!"); -// -// // Now get the reference to __engine and save the pointer. -// PyObject* main_module = PyImport_AddModule((char*)"__main__"); -// PyObject* global_dict = PyModule_GetDict(main_module); -// PyObjWrapper tmp(PyDict_GetItemString(global_dict, "__enginePARAVIS")); -// paravisEngine = tmp; +// if ( SUIT_Session::session() ) +// return dynamic_cast( SUIT_Session::session()->activeApplication() ); +// return 0; //} // -// +//PVViewer_EngineWrapper::PVViewer_EngineWrapper() +//// : paravisEngine(NULL) +//{ +// _component = getApplication()->lcc()->FindOrLoad_Component( "FactoryServer", "PARAVIS" ); +//} // //bool PVViewer_EngineWrapper::GetGUIConnected() //{ -// PyLockWrapper lock; -// PyObjWrapper obj(PyObject_CallMethod(paravisEngine, (char*)("GetGUIConnected"), NULL)); -// if (!obj) -// { -// PyErr_Print(); -// throw SALOME_Exception("Unable to invoke PARAVIS engine!"); -// } -// return PyObject_IsTrue(obj); +// CORBA::Request_var req = _component->_request("GetGUIConnected"); +// req->set_return_type(CORBA::_tc_boolean); +// req->invoke(); +// CORBA::Exception *exc =req->env()->exception(); +// if( exc ) +// throw SALOME_Exception("Unable to invoke PARAVIS engine!"); +// CORBA::Any & ret = req->return_value(); +// CORBA::Boolean bo; +// +// if (ret >>= bo) +// return bool(bo); +// else +// throw SALOME_Exception("Unable to convert engine result!"); //} // //void PVViewer_EngineWrapper::SetGUIConnected(bool isConnected) //{ -// PyLockWrapper lock; -// -// PyObjWrapper obj(PyObject_CallMethod(paravisEngine, (char*)("SetGUIConnected"), -// (char *)"i", (int)isConnected ) ); -// if (!obj) -// { -// PyErr_Print(); -// throw SALOME_Exception("Unable to invoke PARAVIS engine!"); -// } +// CORBA::Request_var req = _component->_request("SetGUIConnected"); +// CORBA::Boolean arg = isConnected; +// req->add_in_arg() <<= arg; +// req->set_return_type(CORBA::_tc_void); +// req->invoke(); +// CORBA::Exception *exc =req->env()->exception(); +// if( exc ) +// throw SALOME_Exception("Unable to invoke PARAVIS engine!"); //} // //std::string PVViewer_EngineWrapper::FindOrStartPVServer(int port) //{ -// PyLockWrapper lock; -// -// PyObjWrapper obj(PyObject_CallMethod(paravisEngine, (char*)("FindOrStartPVServer"), -// (char *)"i", port ) ); -// if (!obj) -// { -// PyErr_Print(); -// throw SALOME_Exception("Unable to invoke PARAVIS engine!"); -// } -// char * s = PyString_AsString(obj); +// CORBA::Request_var req = _component->_request("FindOrStartPVServer"); +// CORBA::Long arg = port; +// req->add_in_arg() <<= arg; +// req->set_return_type(CORBA::_tc_string); +// req->invoke(); +// CORBA::Exception *exc =req->env()->exception(); +// if( exc ) +// throw SALOME_Exception("Unable to invoke PARAVIS engine!"); // -// return std::string(s); +// const char* ret; +// if(req->return_value() >>= ret) +// return std::string(ret); +// else +// throw SALOME_Exception("Unable to convert engine result!"); //} + +PVViewer_EngineWrapper::PVViewer_EngineWrapper() : + paravisEngine(NULL) +{ +// const char * cmd = "import PARAVIS_utils;e="; + PyLockWrapper lock; + const char* code = "import PARAVIS_utils as pa;__enginePARAVIS=pa.getEngine()"; + int ret = PyRun_SimpleString(const_cast(code)); + + if (ret == -1) + throw SALOME_Exception("Unable to retrieve PARAVIS engine!"); + + // Now get the reference to __engine and save the pointer. + PyObject* main_module = PyImport_AddModule((char*)"__main__"); + PyObject* global_dict = PyModule_GetDict(main_module); + PyObjWrapper tmp(PyDict_GetItemString(global_dict, "__enginePARAVIS")); + paravisEngine = tmp; +} + + + +bool PVViewer_EngineWrapper::GetGUIConnected() +{ + PyLockWrapper lock; + PyObjWrapper obj(PyObject_CallMethod(paravisEngine, (char*)("GetGUIConnected"), NULL)); + if (!obj) + { + PyErr_Print(); + throw SALOME_Exception("Unable to invoke PARAVIS engine!"); + } + return PyObject_IsTrue(obj); +} + +void PVViewer_EngineWrapper::SetGUIConnected(bool isConnected) +{ + PyLockWrapper lock; + + PyObjWrapper obj(PyObject_CallMethod(paravisEngine, (char*)("SetGUIConnected"), + (char *)"i", (int)isConnected ) ); + if (!obj) + { + PyErr_Print(); + throw SALOME_Exception("Unable to invoke PARAVIS engine!"); + } +} + +std::string PVViewer_EngineWrapper::FindOrStartPVServer(int port) +{ + PyLockWrapper lock; + + PyObjWrapper obj(PyObject_CallMethod(paravisEngine, (char*)("FindOrStartPVServer"), + (char *)"i", port ) ); + if (!obj) + { + PyErr_Print(); + throw SALOME_Exception("Unable to invoke PARAVIS engine!"); + } + char * s = PyString_AsString(obj); + + return std::string(s); +} diff --git a/src/PVViewer/PVViewer_EngineWrapper.h b/src/PVViewer/PVViewer_EngineWrapper.h index b0c5f4db1..8f78d685a 100644 --- a/src/PVViewer/PVViewer_EngineWrapper.h +++ b/src/PVViewer/PVViewer_EngineWrapper.h @@ -21,14 +21,14 @@ #ifndef PVVIEWERENGINEWRAPPER_H_ #define PVVIEWERENGINEWRAPPER_H_ -//#include +#include #include -#include -#include -#include -#include CORBA_SERVER_HEADER(SALOME_ModuleCatalog) -#include CORBA_SERVER_HEADER(SALOMEDS) +//#include +//#include +//#include +//#include CORBA_SERVER_HEADER(SALOME_ModuleCatalog) +//#include CORBA_SERVER_HEADER(SALOMEDS) /*! @@ -53,9 +53,9 @@ private: virtual ~PVViewer_EngineWrapper() {} static PVViewer_EngineWrapper * instance; - Engines::EngineComponent_var _component; + //Engines::EngineComponent_var _component; - //PyObjWrapper paravisEngine; + PyObjWrapper paravisEngine; }; #endif /* PVVIEWERENGINEWRAPPER_H_ */ diff --git a/src/PVViewer/PVViewer_GUIElements.cxx b/src/PVViewer/PVViewer_GUIElements.cxx index ff139e682..70b4751fe 100644 --- a/src/PVViewer/PVViewer_GUIElements.cxx +++ b/src/PVViewer/PVViewer_GUIElements.cxx @@ -35,8 +35,8 @@ PVViewer_GUIElements::PVViewer_GUIElements(SUIT_Desktop* desk) : propertiesPanel(0), pipelineBrowserWidget(0), sourcesMenu(0) { - propertiesPanel = new pqPropertiesPanel(desk); - propertiesPanel->hide(); +// propertiesPanel = new pqPropertiesPanel(desk); +// propertiesPanel->hide(); pipelineBrowserWidget = new pqPipelineBrowserWidget(desk); pipelineBrowserWidget->hide(); diff --git a/src/PVViewer/PVViewer_LogWindowAdapter.cxx b/src/PVViewer/PVViewer_LogWindowAdapter.cxx index 736b77b68..880295cdc 100644 --- a/src/PVViewer/PVViewer_LogWindowAdapter.cxx +++ b/src/PVViewer/PVViewer_LogWindowAdapter.cxx @@ -21,7 +21,7 @@ #include -#include +#include #include #include #include @@ -57,7 +57,8 @@ PVViewer_LogWindowAdapter::PVViewer_LogWindowAdapter() : TextCount(0), ErrorCount(0), WarningCount(0), - GenericWarningCount(0) + GenericWarningCount(0), + logWindow(0) { } @@ -85,14 +86,14 @@ const unsigned int PVViewer_LogWindowAdapter::getGenericWarningCount() return this->GenericWarningCount; } -static LogWindow* getLogWindow() -{ - LogWindow* wnd = 0; - LightApp_Application* anApp = dynamic_cast( SUIT_Session::session()->activeApplication() ); - if ( anApp ) - wnd = anApp->logWindow(); - return wnd; -} +//LogWindow* PVViewer_LogWindowAdapter::getLogWindow() +//{ +// LogWindow* wnd = 0; +// LightApp_Application* anApp = dynamic_cast( SUIT_Session::session()->activeApplication() ); +// if ( anApp ) +// wnd = anApp->logWindow(); +// return wnd; +//} void PVViewer_LogWindowAdapter::DisplayText(const char* text) { diff --git a/src/PVViewer/PVViewer_LogWindowAdapter.h b/src/PVViewer/PVViewer_LogWindowAdapter.h index cd8332a8f..863ddbcb8 100644 --- a/src/PVViewer/PVViewer_LogWindowAdapter.h +++ b/src/PVViewer/PVViewer_LogWindowAdapter.h @@ -22,6 +22,8 @@ #include +class LogWindow; + /*! vtkOutputWindow implementation that puts VTK output messages to SALOME log window. @@ -45,6 +47,9 @@ public: //! Returns the number of generic warning messages received const unsigned int getGenericWarningCount(); + void setLogWindow( LogWindow* w) { logWindow = w; } + LogWindow* getLogWindow() { return logWindow; } + private: PVViewer_LogWindowAdapter(); PVViewer_LogWindowAdapter(const PVViewer_LogWindowAdapter&); @@ -55,6 +60,7 @@ private: unsigned int ErrorCount; unsigned int WarningCount; unsigned int GenericWarningCount; + LogWindow * logWindow; virtual void DisplayText(const char*); virtual void DisplayErrorText(const char*); diff --git a/src/PVViewer/PVViewer_ViewManager.cxx b/src/PVViewer/PVViewer_ViewManager.cxx index 31e5ab634..82aba0ac4 100644 --- a/src/PVViewer/PVViewer_ViewManager.cxx +++ b/src/PVViewer/PVViewer_ViewManager.cxx @@ -25,7 +25,6 @@ #include "PVViewer_EngineWrapper.h" #include -#include #include #include #include @@ -34,6 +33,7 @@ #include #include #include +#include #include #include @@ -61,14 +61,14 @@ PVViewer_Behaviors * PVViewer_ViewManager::ParaviewBehaviors = NULL; /*! Constructor */ -PVViewer_ViewManager::PVViewer_ViewManager( SUIT_Study* study, SUIT_Desktop* desk ) +PVViewer_ViewManager::PVViewer_ViewManager( SUIT_Study* study, SUIT_Desktop* desk, LogWindow * logWindow ) : SUIT_ViewManager( study, desk, new PVViewer_Viewer() ), desktop(desk) { MESSAGE("PARAVIS - view manager created ...") setTitle( tr( "PARAVIEW_VIEW_TITLE" ) ); // Initialize minimal paraview stuff (if not already done) - ParaviewInitApp(desk); + ParaviewInitApp(desk, logWindow); // connect(this, SIGNAL(viewCreated(SUIT_ViewWindow*)), this, SLOT(onPVViewCreated(SUIT_ViewWindow*))); } @@ -83,7 +83,7 @@ pqPVApplicationCore * PVViewer_ViewManager::GetPVApplication() \param fullSetup whether to instanciate all behaviors or just the minimal ones. \return \c true if ParaView has been initialized successfully, otherwise false */ -bool PVViewer_ViewManager::ParaviewInitApp(SUIT_Desktop * aDesktop) +bool PVViewer_ViewManager::ParaviewInitApp(SUIT_Desktop * aDesktop, LogWindow * logWindow) { if ( ! MyCoreApp) { // Obtain command-line arguments @@ -109,7 +109,9 @@ bool PVViewer_ViewManager::ParaviewInitApp(SUIT_Desktop * aDesktop) } // Direct VTK log messages to our SALOME window - TODO: review this - vtkOutputWindow::SetInstance(PVViewer_LogWindowAdapter::New()); + PVViewer_LogWindowAdapter * w = PVViewer_LogWindowAdapter::New(); + w->setLogWindow(logWindow); + vtkOutputWindow::SetInstance(w); new pqTabbedMultiViewWidget(); // registers a "MULTIVIEW_WIDGET" on creation diff --git a/src/PVViewer/PVViewer_ViewManager.h b/src/PVViewer/PVViewer_ViewManager.h index 78652de05..0925698f7 100644 --- a/src/PVViewer/PVViewer_ViewManager.h +++ b/src/PVViewer/PVViewer_ViewManager.h @@ -30,20 +30,21 @@ class pqPVApplicationCore; class PVViewer_Behaviors; class pqPropertiesPanel; class pqPipelineBrowserWidget; +class LogWindow; class PVViewer_ViewManager : public SUIT_ViewManager { Q_OBJECT public: - PVViewer_ViewManager( SUIT_Study*, SUIT_Desktop* ); + PVViewer_ViewManager( SUIT_Study*, SUIT_Desktop*, LogWindow *); ~PVViewer_ViewManager() {} static pqPVApplicationCore * GetPVApplication(); static PVViewer_EngineWrapper * GetEngine(); //! Initialize ParaView if not yet done (once per session) - static bool ParaviewInitApp(SUIT_Desktop* aDesktop); + static bool ParaviewInitApp(SUIT_Desktop* aDesktop, LogWindow * w); static void ParaviewInitBehaviors(bool fullSetup=false, SUIT_Desktop* aDesktop=0); static void ParaviewLoadConfigurations(); static void ParaviewCleanup(); @@ -53,7 +54,6 @@ public: static bool ConnectToExternalPVServer(SUIT_Desktop* aDesktop); public slots: -// void onPVViewCreated(SUIT_ViewWindow*); void onEmulateApply(); private: diff --git a/src/PVViewer/PVViewer_ViewModel.cxx b/src/PVViewer/PVViewer_ViewModel.cxx index ef1771eb1..5a15067e4 100644 --- a/src/PVViewer/PVViewer_ViewModel.cxx +++ b/src/PVViewer/PVViewer_ViewModel.cxx @@ -23,8 +23,6 @@ #include #include -#include - //---------------------------------------- PVViewer_Viewer::PVViewer_Viewer() :SUIT_ViewModel() diff --git a/src/PVViewer/resources/PVViewer_msg_en.ts b/src/PVViewer/resources/PVViewer_msg_en.ts new file mode 100644 index 000000000..fa629810a --- /dev/null +++ b/src/PVViewer/resources/PVViewer_msg_en.ts @@ -0,0 +1,16 @@ + + + + + @default + + + + + PVViewer_ViewManager + + PARAVIEW_VIEW_TITLE + ParaView scene:%M - viewer:%V + + + -- 2.39.2