From 952333931e278fc7ceaafe5c8b9a193e9314c414 Mon Sep 17 00:00:00 2001 From: abn Date: Fri, 5 Sep 2014 10:20:52 +0200 Subject: [PATCH] on the way to view isolation --- src/PVGUI/PVGUI_Module.cxx | 150 ++------------------------- src/PVGUI/PVGUI_Module.h | 20 +--- src/PVGUI/view/PVGUI_ViewManager.cxx | 7 -- src/PVGUI/view/PVGUI_ViewManager.h | 2 +- src/PVGUI/view/PVGUI_ViewModel.cxx | 136 +++++++++++++++++++++++- src/PVGUI/view/PVGUI_ViewModel.h | 21 +++- 6 files changed, 164 insertions(+), 172 deletions(-) diff --git a/src/PVGUI/PVGUI_Module.cxx b/src/PVGUI/PVGUI_Module.cxx index 8b570956..c71eb100 100644 --- a/src/PVGUI/PVGUI_Module.cxx +++ b/src/PVGUI/PVGUI_Module.cxx @@ -91,7 +91,7 @@ #include #include -#include +//#include #include #include #include @@ -128,7 +128,6 @@ #include #include -#include #include #include #include @@ -138,12 +137,8 @@ #include CORBA_SERVER_HEADER(SALOME_ModuleCatalog) //---------------------------------------------------------------------------- -pqPVApplicationCore* PVGUI_Module::MyCoreApp = 0; - PVGUI_Module* ParavisModule = 0; -PARAVIS_ORB::PARAVIS_Gen_var PVGUI_Module::myEngine; - /*! \mainpage @@ -339,13 +334,7 @@ PVGUI_Module::~PVGUI_Module() PARAVIS_ORB::PARAVIS_Gen_var PVGUI_Module::GetEngine() { - // initialize PARAVIS module engine (load, if necessary) - if ( CORBA::is_nil( myEngine ) ) { - Engines::EngineComponent_var comp = - SalomeApp_Application::lcc()->FindOrLoad_Component( "FactoryServer", "PARAVIS" ); - myEngine = PARAVIS_ORB::PARAVIS_Gen::_narrow( comp ); - } - return myEngine; + return PVGUI_ViewerModel::GetEngine(); } /*! @@ -491,48 +480,6 @@ void PVGUI_Module::initialize( CAM_Application* app ) this, SLOT(onRepresentationChanged(pqRepresentation*))); } -bool PVGUI_Module::connectToExternalPVServer() -{ - pqServer* server = pqActiveObjects::instance().activeServer(); - if (server && server->isRemote()) - { - // Already connected to an external server, do nothing - MESSAGE("connectToExternalPVServer(): Already connected to an external PVServer, won't reconnect."); - return false; - } - - std::stringstream msg; - - // Try to connect to the external PVServer - gives priority to an externally specified URL: - QString serverUrlEnv = getenv("PARAVIS_PVSERVER_URL"); - std::string serverUrl; - if (!serverUrlEnv.isEmpty()) - serverUrl = serverUrlEnv.toStdString(); - else - { - // Get the URL from the engine (possibly starting the pvserver) - CORBA::String_var url = GetEngine()->FindOrStartPVServer(0); // take the first free port - serverUrl = (char *)url; - } - - msg << "connectToExternalPVServer(): Trying to connect to the external PVServer '" << serverUrl << "' ..."; - MESSAGE(msg.str()); - - if (!pqServerConnectReaction::connectToServer(pqServerResource(serverUrl.c_str()))) - { - std::stringstream msg2; - msg2 << "Error while connecting to the requested pvserver '" << serverUrl; - msg2 << "'. Might use default built-in connection instead!" << std::endl; - qWarning(msg2.str().c_str()); // will go to the ParaView console (see ParavisMessageOutput below) - SUIT_MessageBox::warning( getApp()->desktop(), - QString("Error connecting to PVServer"), QString(msg2.str().c_str())); - return false; - } - else - MESSAGE("connectToExternalPVServer(): Connected!"); - return true; -} - void PVGUI_Module::onStartProgress() { QApplication::setOverrideCursor(Qt::WaitCursor); @@ -729,76 +676,12 @@ void PVGUI_Module::windows( QMap& m ) const m.insert( LightApp_Application::WT_LogWindow, Qt::BottomDockWidgetArea ); } -/*! - \brief Static method, performs initialization of ParaView session. - \return \c true if ParaView has been initialized successfully, otherwise false -*/ -bool PVGUI_Module::pvInit() -{ - // if ( !pqImplementation::Core ){ - if ( ! MyCoreApp) { - // Obtain command-line arguments - int argc = 0; - char** argv = 0; - QString aOptions = getenv("PARAVIS_OPTIONS"); - QStringList aOptList = aOptions.split(":", QString::SkipEmptyParts); - argv = new char*[aOptList.size() + 1]; - QStringList args = QApplication::arguments(); - argv[0] = (args.size() > 0)? strdup(args[0].toLatin1().constData()) : strdup("paravis"); - argc++; - - foreach (QString aStr, aOptList) { - argv[argc] = strdup( aStr.toLatin1().constData() ); - argc++; - } - MyCoreApp = new pqPVApplicationCore (argc, argv); - if (MyCoreApp->getOptions()->GetHelpSelected() || - MyCoreApp->getOptions()->GetUnknownArgument() || - MyCoreApp->getOptions()->GetErrorMessage() || - MyCoreApp->getOptions()->GetTellVersion()) { - return false; - } - - /* VTN: Looks like trash. For porting see branded_paraview_initializer.cxx.in - // Not sure why this is needed. Andy added this ages ago with comment saying - // needed for Mac apps. Need to check that it's indeed still required. - QDir dir(QApplication::applicationDirPath()); - dir.cdUp(); - dir.cd("Plugins"); - QApplication::addLibraryPath(dir.absolutePath()); - // Load required application plugins. - QString plugin_string = ""; - QStringList plugin_list = plugin_string.split(';',QString::SkipEmptyParts); - pqBrandPluginsLoader loader; - if (loader.loadPlugins(plugin_list) == false) { - printf("Failed to load required plugins for this application\n"); - return false; - } - - // Load optional plugins. - plugin_string = ""; - plugin_list = plugin_string.split(';',QString::SkipEmptyParts); - loader.loadPlugins(plugin_list, true); //quietly skip not-found plugins. - */ - // End of Initializer code - - vtkOutputWindow::SetInstance(PVGUI_OutputWindowAdapter::New()); - - new pqTabbedMultiViewWidget(); // it registers as "MULTIVIEW_WIDGET on creation - - for (int i = 0; i < argc; i++) - free(argv[i]); - delete[] argv; - } - - return true; -} - /*! \brief Shows (toShow = true) or hides ParaView view window */ void PVGUI_Module::showView( bool toShow ) { + PVGUI_ViewManager SalomeApp_Application* anApp = getApp(); PVGUI_ViewManager* viewMgr = dynamic_cast( anApp->getViewManager( PVGUI_Viewer::Type(), false ) ); @@ -853,15 +736,6 @@ void PVGUI_Module::endWaitCursor() QApplication::restoreOverrideCursor(); } -/*! - \brief Returns the ParaView multi-view manager. -*/ -pqTabbedMultiViewWidget* PVGUI_Module::getMultiViewManager() const -{ - return qobject_cast(pqApplicationCore::instance()->manager("MULTIVIEW_WIDGET")); -} - - static void ParavisMessageOutput(QtMsgType type, const char *msg) { switch(type) @@ -881,8 +755,6 @@ static void ParavisMessageOutput(QtMsgType type, const char *msg) } } - - /*! \brief Activate module. \param study current study @@ -1071,14 +943,14 @@ void PVGUI_Module::onModelOpened() } } -/*! - \brief Returns IOR of current engine -*/ -QString PVGUI_Module::engineIOR() const -{ - CORBA::String_var anIOR = GetEngine()->GetIOR(); - return QString(anIOR.in()); -} +///*! +// \brief Returns IOR of current engine +//*/ +//QString PVGUI_Module::engineIOR() const +//{ +// CORBA::String_var anIOR = GetEngine()->GetIOR(); +// return QString(anIOR.in()); +//} /*! diff --git a/src/PVGUI/PVGUI_Module.h b/src/PVGUI/PVGUI_Module.h index e9becbde..14308f4c 100644 --- a/src/PVGUI/PVGUI_Module.h +++ b/src/PVGUI/PVGUI_Module.h @@ -45,7 +45,6 @@ class QToolBar; class vtkPVMain; class pqOptions; class pqServer; -class pqTabbedMultiViewWidget; class pqMainWindowCore; class vtkEventQtSlotConnect; class pqPythonScriptEditor; @@ -144,14 +143,10 @@ public: PVGUI_Module(); ~PVGUI_Module(); - static PARAVIS_ORB::PARAVIS_Gen_var GetEngine(); - virtual void initialize( CAM_Application* ); virtual void windows( QMap& ) const; - pqTabbedMultiViewWidget* getMultiViewManager() const; - - virtual QString engineIOR() const; +// virtual QString engineIOR() const; void openFile(const char* theName); void executeScript(const char *script); @@ -168,14 +163,13 @@ public: virtual void contextMenuPopup(const QString& theClient, QMenu* theMenu, QString& theTitle); + inline static PARAVIS_ORB::PARAVIS_Gen_var GetEngine() { return PVGUI_ViewerModel::GetEngine(); } + public slots: //void onImportFromVisu(QString theEntry); private: void deleteTemporaryFiles(); - - //! Initialize ParaView if not yet done (once per session) - static bool pvInit(); //! Create actions for ParaView GUI operations void pvCreateActions(); @@ -228,10 +222,6 @@ private: //! run Python command (either in SALOME's Python interpreter, or in ParaView's Python's interpreter) void execPythonCommand(const QString& cmd, bool inSalomeConsole=false); - //! Connect to the external PVServer, using the PARAVIS engine to launch it if it is not - //! already up. - bool connectToExternalPVServer(); - private slots: void showHelpForProxy( const QString&, const QString& ); @@ -299,10 +289,6 @@ private: vtkEventQtSlotConnect *VTKConnect; - static pqPVApplicationCore* MyCoreApp; - static PARAVIS_ORB::PARAVIS_Gen_var myEngine; - - pqPythonScriptEditor* myTraceWindow; int myStateCounter; diff --git a/src/PVGUI/view/PVGUI_ViewManager.cxx b/src/PVGUI/view/PVGUI_ViewManager.cxx index b697123a..5841a112 100644 --- a/src/PVGUI/view/PVGUI_ViewManager.cxx +++ b/src/PVGUI/view/PVGUI_ViewManager.cxx @@ -31,13 +31,6 @@ PVGUI_ViewManager::PVGUI_ViewManager( SUIT_Study* study, SUIT_Desktop* desk ) setTitle( tr( "PARAVIEW_VIEW_TITLE" ) ); } -/*! - Destructor -*/ -PVGUI_ViewManager::~PVGUI_ViewManager() -{ -} - /*! \brief Returns the ParaView multi-view manager for the active view window */ diff --git a/src/PVGUI/view/PVGUI_ViewManager.h b/src/PVGUI/view/PVGUI_ViewManager.h index 4a705316..83cada48 100644 --- a/src/PVGUI/view/PVGUI_ViewManager.h +++ b/src/PVGUI/view/PVGUI_ViewManager.h @@ -31,7 +31,7 @@ class PVGUI_ViewManager : public SUIT_ViewManager public: PVGUI_ViewManager( SUIT_Study*, SUIT_Desktop* ); - ~PVGUI_ViewManager(); + ~PVGUI_ViewManager() {} pqTabbedMultiViewWidget* getMultiViewManager(); }; diff --git a/src/PVGUI/view/PVGUI_ViewModel.cxx b/src/PVGUI/view/PVGUI_ViewModel.cxx index 615b0415..cf91a0e2 100644 --- a/src/PVGUI/view/PVGUI_ViewModel.cxx +++ b/src/PVGUI/view/PVGUI_ViewModel.cxx @@ -19,23 +19,107 @@ #include "PVGUI_ViewModel.h" #include "PVGUI_ViewWindow.h" +#include "PVGUI_OutputWindowAdapter.h" #include "utilities.h" -/*! - Constructor -*/ +#include + +#include +#include + +//---------- Static init ----------------- +pqPVApplicationCore* PVGUI_Viewer::MyCoreApp = 0; +PARAVIS_ORB::PARAVIS_Gen_var PVGUI_Viewer::MyEngine; + +//---------------------------------------- PVGUI_Viewer::PVGUI_Viewer() :SUIT_ViewModel() { MESSAGE("PVGUI_Viewer: creating view ..."); } +pqPVApplicationCore* PVGUI_Viewer::GetPVApplication() +{ + if(!MyCoreApp) + pvInit(); + return MyCoreApp; +} /*! - Destructor + \brief Static method, performs initialization of ParaView session. + \return \c true if ParaView has been initialized successfully, otherwise false */ -PVGUI_Viewer::~PVGUI_Viewer() +bool PVGUI_Viewer::pvInit() { + // if ( !pqImplementation::Core ){ + if ( ! MyCoreApp) { + // Obtain command-line arguments + int argc = 0; + char** argv = 0; + QString aOptions = getenv("PARAVIS_OPTIONS"); + QStringList aOptList = aOptions.split(":", QString::SkipEmptyParts); + argv = new char*[aOptList.size() + 1]; + QStringList args = QApplication::arguments(); + argv[0] = (args.size() > 0)? strdup(args[0].toLatin1().constData()) : strdup("paravis"); + argc++; + + foreach (QString aStr, aOptList) { + argv[argc] = strdup( aStr.toLatin1().constData() ); + argc++; + } + MyCoreApp = new pqPVApplicationCore (argc, argv); + if (MyCoreApp->getOptions()->GetHelpSelected() || + MyCoreApp->getOptions()->GetUnknownArgument() || + MyCoreApp->getOptions()->GetErrorMessage() || + MyCoreApp->getOptions()->GetTellVersion()) { + return false; + } + + /* VTN: Looks like trash. For porting see branded_paraview_initializer.cxx.in + // Not sure why this is needed. Andy added this ages ago with comment saying + // needed for Mac apps. Need to check that it's indeed still required. + QDir dir(QApplication::applicationDirPath()); + dir.cdUp(); + dir.cd("Plugins"); + QApplication::addLibraryPath(dir.absolutePath()); + // Load required application plugins. + QString plugin_string = ""; + QStringList plugin_list = plugin_string.split(';',QString::SkipEmptyParts); + pqBrandPluginsLoader loader; + if (loader.loadPlugins(plugin_list) == false) { + printf("Failed to load required plugins for this application\n"); + return false; + } + + // Load optional plugins. + plugin_string = ""; + plugin_list = plugin_string.split(';',QString::SkipEmptyParts); + loader.loadPlugins(plugin_list, true); //quietly skip not-found plugins. + */ + // End of Initializer code + + vtkOutputWindow::SetInstance(PVGUI_OutputWindowAdapter::New()); + + new pqTabbedMultiViewWidget(); // it registers as "MULTIVIEW_WIDGET" on creation + + for (int i = 0; i < argc; i++) + free(argv[i]); + delete[] argv; + } + + return true; +} + + +PARAVIS_ORB::PARAVIS_Gen_var PVGUI_Viewer::GetEngine() +{ + // initialize PARAVIS module engine (load, if necessary) + if ( CORBA::is_nil( myEngine ) ) { + Engines::EngineComponent_var comp = + SalomeApp_Application::lcc()->FindOrLoad_Component( "FactoryServer", "PARAVIS" ); + myEngine = PARAVIS_ORB::PARAVIS_Gen::_narrow( comp ); + } + return myEngine; } /*! @@ -47,3 +131,45 @@ SUIT_ViewWindow* PVGUI_Viewer::createView(SUIT_Desktop* theDesktop) PVGUI_ViewWindow* aPVView = new PVGUI_ViewWindow(theDesktop, this); return aPVView; } + +bool PVGUI_Viewer::connectToExternalPVServer() +{ + pqServer* server = pqActiveObjects::instance().activeServer(); + if (server && server->isRemote()) + { + // Already connected to an external server, do nothing + MESSAGE("connectToExternalPVServer(): Already connected to an external PVServer, won't reconnect."); + return false; + } + + std::stringstream msg; + + // Try to connect to the external PVServer - gives priority to an externally specified URL: + QString serverUrlEnv = getenv("PARAVIS_PVSERVER_URL"); + std::string serverUrl; + if (!serverUrlEnv.isEmpty()) + serverUrl = serverUrlEnv.toStdString(); + else + { + // Get the URL from the engine (possibly starting the pvserver) + CORBA::String_var url = GetEngine()->FindOrStartPVServer(0); // take the first free port + serverUrl = (char *)url; + } + + msg << "connectToExternalPVServer(): Trying to connect to the external PVServer '" << serverUrl << "' ..."; + MESSAGE(msg.str()); + + if (!pqServerConnectReaction::connectToServer(pqServerResource(serverUrl.c_str()))) + { + std::stringstream msg2; + msg2 << "Error while connecting to the requested pvserver '" << serverUrl; + msg2 << "'. Might use default built-in connection instead!" << std::endl; + qWarning(msg2.str().c_str()); // will go to the ParaView console (see ParavisMessageOutput below) + SUIT_MessageBox::warning( getApp()->desktop(), + QString("Error connecting to PVServer"), QString(msg2.str().c_str())); + return false; + } + else + MESSAGE("connectToExternalPVServer(): Connected!"); + return true; +} diff --git a/src/PVGUI/view/PVGUI_ViewModel.h b/src/PVGUI/view/PVGUI_ViewModel.h index 75ab2fd0..7ecc2e28 100644 --- a/src/PVGUI/view/PVGUI_ViewModel.h +++ b/src/PVGUI/view/PVGUI_ViewModel.h @@ -20,22 +20,37 @@ #define _PVGUI_VIEWMODEL_H #include +#include CORBA_SERVER_HEADER(PARAVIS_Gen) class SUIT_ViewWindow; class SUIT_Desktop; +class pqPVApplicationCore; class PVGUI_Viewer: public SUIT_ViewModel { Q_OBJECT public: - static QString Type() { return "ParaView"; } - PVGUI_Viewer(); - ~PVGUI_Viewer(); + virtual ~PVGUI_Viewer() {} virtual SUIT_ViewWindow* createView(SUIT_Desktop* theDesktop); virtual QString getType() const { return Type(); } + static QString Type() { return "ParaView"; } + + pqPVApplicationCore * getPVApplication(); + static PARAVIS_ORB::PARAVIS_Gen_var GetEngine(); + + //! Initialize ParaView if not yet done (once per session) + static bool pvInit(); + + //! Connect to the external PVServer, using the PARAVIS engine to launch it if it is not + //! already up. + bool connectToExternalPVServer(); + +private: + static pqPVApplicationCore* MyCoreApp; + static PARAVIS_ORB::PARAVIS_Gen_var MyEngine; }; -- 2.39.2