From fb576423db54e3b895b4496d35c9f0f6a255ff9b Mon Sep 17 00:00:00 2001 From: abn Date: Wed, 17 Sep 2014 17:12:26 +0200 Subject: [PATCH] First demonstration of the use of a ParaView window outside PARAVIS. --- SalomePARAVISConfig.cmake.in | 4 +- src/PVGUI/PVGUI_Module.cxx | 18 ++--- src/PVGUI/view/PVViewer_Behaviors.cxx | 94 +++++++++++++++---------- src/PVGUI/view/PVViewer_Behaviors.h | 8 ++- src/PVGUI/view/PVViewer_ViewManager.cxx | 46 ++++++++++-- src/PVGUI/view/PVViewer_ViewManager.h | 11 ++- src/PVGUI/view/PVViewer_ViewModel.h | 1 - src/PVGUI/view/PVViewer_ViewWindow.cxx | 14 +++- src/PVGUI/view/PVViewer_ViewWindow.h | 6 ++ 9 files changed, 140 insertions(+), 62 deletions(-) diff --git a/SalomePARAVISConfig.cmake.in b/SalomePARAVISConfig.cmake.in index 823e29a3..07fe64e2 100644 --- a/SalomePARAVISConfig.cmake.in +++ b/SalomePARAVISConfig.cmake.in @@ -30,7 +30,7 @@ # Load the dependencies for the libraries of @PROJECT_NAME@ # (contains definitions for IMPORTED targets). This is only # imported if we are not built as a subproject (in this case targets are already there) -IF(NOT TARGET Event AND NOT @PROJECT_NAME@_BINARY_DIR) +IF(NOT TARGET PARAVIS AND NOT @PROJECT_NAME@_BINARY_DIR) INCLUDE("@PACKAGE_SALOME_INSTALL_CMAKE_LOCAL@/@PROJECT_NAME@Targets.cmake") ENDIF() @@ -132,3 +132,5 @@ ENDIF() SET(PARAVIS_SalomeIDLPARAVIS SalomeIDLPARAVIS) SET(PARAVIS_PARAVIS PARAVIS) SET(PARAVIS_PARAVISEngine PARAVISEngine) +SET(PARAVIS_PVViewer PVViewer) + diff --git a/src/PVGUI/PVGUI_Module.cxx b/src/PVGUI/PVGUI_Module.cxx index 97679fdf..d4f7cc9a 100644 --- a/src/PVGUI/PVGUI_Module.cxx +++ b/src/PVGUI/PVGUI_Module.cxx @@ -340,7 +340,8 @@ void PVGUI_Module::initialize( CAM_Application* app ) setupDockWidgets(); - // Behaviors and connection must be instanciated *after* widgets are in place: + // Behaviors and connection must be instanciated *after* widgets are in place + // In PARAVIS module we do not wait for PVViewer_ViewWindow to be instanciated to have this: PVViewer_ViewManager::ParaviewInitBehaviors(true, aDesktop); PVViewer_ViewManager::ConnectToExternalPVServer(aDesktop); @@ -378,16 +379,7 @@ void PVGUI_Module::initialize( CAM_Application* app ) // } // } - SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr(); - QString aPath = resMgr->stringValue("resources", "PARAVIS", QString()); - if (!aPath.isNull()) { - pqPVApplicationCore * pvApp = GetPVApplication(); - pvApp->loadConfiguration(aPath + QDir::separator() + "ParaViewFilters.xml"); - pvApp->loadConfiguration(aPath + QDir::separator() + "ParaViewReaders.xml"); - pvApp->loadConfiguration(aPath + QDir::separator() + "ParaViewSources.xml"); - pvApp->loadConfiguration(aPath + QDir::separator() + "ParaViewWriters.xml"); - } - + PVViewer_ViewManager::ParaviewLoadConfigurations(); updateObjBrowser(); // Find created toolbars @@ -534,6 +526,7 @@ void PVGUI_Module::showView( bool toShow ) PVViewer_ViewWindow* pvWnd = dynamic_cast( viewMgr->getActiveView() ); if ( !pvWnd ) { pvWnd = dynamic_cast( viewMgr->createViewWindow() ); + // this also connects to the pvserver and instantiates relevant PV behaviors } pvWnd->setShown( toShow ); @@ -611,7 +604,8 @@ bool PVGUI_Module::activateModule( SUIT_Study* study ) bool isDone = SalomeApp_Module::activateModule( study ); if ( !isDone ) return false; - showView( true ); + showView( true ); // this will also trigger the connection to the server + // and the instanciation of the relevant PV behaviors if ( mySourcesMenuId != -1 ) menuMgr()->show(mySourcesMenuId); if ( myFiltersMenuId != -1 ) menuMgr()->show(myFiltersMenuId); if ( myFiltersMenuId != -1 ) menuMgr()->show(myMacrosMenuId); diff --git a/src/PVGUI/view/PVViewer_Behaviors.cxx b/src/PVGUI/view/PVViewer_Behaviors.cxx index 417cd65c..5ff809ff 100644 --- a/src/PVGUI/view/PVViewer_Behaviors.cxx +++ b/src/PVGUI/view/PVViewer_Behaviors.cxx @@ -50,7 +50,9 @@ #include #include -bool PVViewer_Behaviors::hasMinimalInstanciated = false; +#include + +int PVViewer_Behaviors::BehaviorLoadingLevel = 0; PVViewer_Behaviors::PVViewer_Behaviors(SUIT_Desktop * parent) : QObject(static_cast(parent)) @@ -63,27 +65,33 @@ PVViewer_Behaviors::PVViewer_Behaviors(SUIT_Desktop * parent) */ void PVViewer_Behaviors::instanciateMinimalBehaviors(SUIT_Desktop * desk) { - hasMinimalInstanciated = true; - - // Register ParaView interfaces. - pqInterfaceTracker* pgm = pqApplicationCore::instance()->interfaceTracker(); - - // Register standard types of property widgets. - pgm->addInterface(new pqStandardPropertyWidgetInterface(pgm)); - // Register standard types of view-frame actions. - pgm->addInterface(new pqStandardViewFrameActionsImplementation(pgm)); - - // Load plugins distributed with application. - pqApplicationCore::instance()->loadDistributedPlugins(); - - new pqDefaultViewBehavior(this); // shows a 3D view as soon as a server connection is made - new pqAlwaysConnectedBehavior(this); // client always connected to a server - new pqAutoLoadPluginXMLBehavior(this); // auto load plugins - new pqVerifyRequiredPluginBehavior(this); - new pqPluginSettingsBehavior(this); - new pqFixPathsInStateFilesBehavior(this); - new pqCrashRecoveryBehavior(this); - new pqCommandLineOptionsBehavior(this); + if (BehaviorLoadingLevel < 1) + { + // Register ParaView interfaces. + pqInterfaceTracker* pgm = pqApplicationCore::instance()->interfaceTracker(); + + // Register standard types of property widgets. + pgm->addInterface(new pqStandardPropertyWidgetInterface(pgm)); + // Register standard types of view-frame actions. + pgm->addInterface(new pqStandardViewFrameActionsImplementation(pgm)); + + // Load plugins distributed with application. + pqApplicationCore::instance()->loadDistributedPlugins(); + + new pqDefaultViewBehavior(this); // shows a 3D view as soon as a server connection is made + new pqAlwaysConnectedBehavior(this); // client always connected to a server + new pqAutoLoadPluginXMLBehavior(this); // auto load plugins + new pqVerifyRequiredPluginBehavior(this); + new pqPluginSettingsBehavior(this); + new pqFixPathsInStateFilesBehavior(this); + new pqCrashRecoveryBehavior(this); + new pqCommandLineOptionsBehavior(this); + + // Create a hidden pqPropertiesPanel() + hiddenProp = new pqPropertiesPanel(desk); + + BehaviorLoadingLevel = 1; + } } /**! Instanciate usual ParaView behaviors. @@ -97,24 +105,34 @@ void PVViewer_Behaviors::instanciateAllBehaviors(SUIT_Desktop * desk) // exclude using of pqQtMessageHandlerBehaviour // Define application behaviors. - if (!hasMinimalInstanciated) + if (BehaviorLoadingLevel < 1) instanciateMinimalBehaviors(desk); - //new pqQtMessageHandlerBehavior(this); // THIS ONE TO EXCLUDE !! see comment above - new pqDataTimeStepBehavior(this); - new pqSpreadSheetVisibilityBehavior(this); - new pqPipelineContextMenuBehavior(this); - new pqUndoRedoBehavior(this); - new pqPluginDockWidgetsBehavior(desk); - new pqPluginActionGroupBehavior(desk); - new pqPersistentMainWindowStateBehavior(desk); - new pqObjectPickingBehavior(desk); - new pqCollaborationBehavior(this); - new pqViewStreamingBehavior(this); - - pqApplyBehavior* applyBehavior = new pqApplyBehavior(this); - foreach (pqPropertiesPanel* ppanel, desk->findChildren()) + + if (BehaviorLoadingLevel < 2) { - applyBehavior->registerPanel(ppanel); + //new pqQtMessageHandlerBehavior(this); // THIS ONE TO EXCLUDE !! see comment above + new pqDataTimeStepBehavior(this); + new pqSpreadSheetVisibilityBehavior(this); + new pqPipelineContextMenuBehavior(this); + new pqUndoRedoBehavior(this); + new pqPluginDockWidgetsBehavior(desk); + new pqPluginActionGroupBehavior(desk); + new pqPersistentMainWindowStateBehavior(desk); + new pqObjectPickingBehavior(desk); + new pqCollaborationBehavior(this); + new pqViewStreamingBehavior(this); + + pqApplyBehavior* applyBehavior = new pqApplyBehavior(this); + foreach (pqPropertiesPanel* ppanel, desk->findChildren()) + { + applyBehavior->registerPanel(ppanel); + } + BehaviorLoadingLevel = 2; } +} +void PVViewer_Behaviors::onEmulateApply() +{ + if (hiddenProp) + hiddenProp->apply(); } diff --git a/src/PVGUI/view/PVViewer_Behaviors.h b/src/PVGUI/view/PVViewer_Behaviors.h index 6e99c26c..f9858cb3 100644 --- a/src/PVGUI/view/PVViewer_Behaviors.h +++ b/src/PVGUI/view/PVViewer_Behaviors.h @@ -26,6 +26,7 @@ class SalomeApp_Module; class SUIT_Desktop; +class pqPropertiesPanel; /**! * PARAVIS behaviors - mimic what is done in @@ -45,8 +46,13 @@ public: virtual ~PVViewer_Behaviors() {} +public slots: + void onEmulateApply(); + private: - static bool hasMinimalInstanciated; + static int BehaviorLoadingLevel; + + pqPropertiesPanel * hiddenProp; }; #endif /* PVGUIBEHAVIORS_H_ */ diff --git a/src/PVGUI/view/PVViewer_ViewManager.cxx b/src/PVGUI/view/PVViewer_ViewManager.cxx index b187ca44..ae644210 100644 --- a/src/PVGUI/view/PVViewer_ViewManager.cxx +++ b/src/PVGUI/view/PVViewer_ViewManager.cxx @@ -28,12 +28,14 @@ #include #include #include +#include #include #include #include #include #include +#include #include #include @@ -48,7 +50,8 @@ //---------- Static init ----------------- pqPVApplicationCore* PVViewer_ViewManager::MyCoreApp = 0; PARAVIS_ORB::PARAVIS_Gen_var PVViewer_ViewManager::MyEngine; - +bool PVViewer_ViewManager::ConfigLoaded = false; +PVViewer_Behaviors * PVViewer_ViewManager::ParaviewBehaviors = NULL; /*! Constructor @@ -58,6 +61,10 @@ PVViewer_ViewManager::PVViewer_ViewManager( SUIT_Study* study, SUIT_Desktop* des { MESSAGE("PARAVIS - view manager created ...") setTitle( tr( "PARAVIEW_VIEW_TITLE" ) ); + // Initialize minimal paraview stuff (if not already done) + ParaviewInitApp(desk); + + connect(this, SIGNAL(viewCreated(SUIT_ViewWindow*)), this, SLOT(onPVViewCreated(SUIT_ViewWindow*))); } pqPVApplicationCore * PVViewer_ViewManager::GetPVApplication() @@ -124,11 +131,29 @@ bool PVViewer_ViewManager::ParaviewInitApp(SUIT_Desktop * aDesktop) void PVViewer_ViewManager::ParaviewInitBehaviors(bool fullSetup, SUIT_Desktop* aDesktop) { - PVViewer_Behaviors * behav = new PVViewer_Behaviors(aDesktop); + if (!ParaviewBehaviors) + ParaviewBehaviors = new PVViewer_Behaviors(aDesktop); + if(fullSetup) - behav->instanciateAllBehaviors(aDesktop); + ParaviewBehaviors->instanciateAllBehaviors(aDesktop); else - behav->instanciateMinimalBehaviors(aDesktop); + ParaviewBehaviors->instanciateMinimalBehaviors(aDesktop); +} + +void PVViewer_ViewManager::ParaviewLoadConfigurations() +{ + if (!ConfigLoaded) + { + SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr(); + QString aPath = resMgr->stringValue("resources", "PARAVIS", QString()); + if (!aPath.isNull()) { + MyCoreApp->loadConfiguration(aPath + QDir::separator() + "ParaViewFilters.xml"); + MyCoreApp->loadConfiguration(aPath + QDir::separator() + "ParaViewReaders.xml"); + MyCoreApp->loadConfiguration(aPath + QDir::separator() + "ParaViewSources.xml"); + MyCoreApp->loadConfiguration(aPath + QDir::separator() + "ParaViewWriters.xml"); + } + ConfigLoaded = true; + } } void PVViewer_ViewManager::ParaviewCleanup() @@ -144,9 +169,11 @@ void PVViewer_ViewManager::ParaviewCleanup() pqApplicationCore::instance()->settings()->sync(); pqPVApplicationCore * app = GetPVApplication(); + // [ABN] : TODO review this, this triggers an ugly crash (Python thread state mix-up) + // at SALOME's exit. // Schedule destruction of PVApplication singleton: - if (app) - app->deleteLater(); +// if (app) +// app->deleteLater(); } PARAVIS_ORB::PARAVIS_Gen_var PVViewer_ViewManager::GetEngine() @@ -216,3 +243,10 @@ bool PVViewer_ViewManager::ConnectToExternalPVServer(SUIT_Desktop* aDesktop) } return true; } + +void PVViewer_ViewManager::onPVViewCreated(SUIT_ViewWindow* w) +{ + PVViewer_ViewWindow * w2 = dynamic_cast(w); + Q_ASSERT(w2 != NULL); + connect(w2, SIGNAL(applyRequest()), ParaviewBehaviors, SLOT(onEmulateApply())); +} diff --git a/src/PVGUI/view/PVViewer_ViewManager.h b/src/PVGUI/view/PVViewer_ViewManager.h index fe389603..a9951565 100644 --- a/src/PVGUI/view/PVViewer_ViewManager.h +++ b/src/PVGUI/view/PVViewer_ViewManager.h @@ -25,8 +25,11 @@ class SUIT_Desktop; class SUIT_Study; +class SUIT_ViewWindow; class pqTabbedMultiViewWidget; class pqPVApplicationCore; +class PVViewer_Behaviors; +class pqPropertiesPanel; class PVViewer_ViewManager : public SUIT_ViewManager { @@ -42,17 +45,21 @@ public: //! Initialize ParaView if not yet done (once per session) static bool ParaviewInitApp(SUIT_Desktop* aDesktop); static void ParaviewInitBehaviors(bool fullSetup=false, SUIT_Desktop* aDesktop=0); - + static void ParaviewLoadConfigurations(); static void ParaviewCleanup(); //! Connect to the external PVServer, using the PARAVIS engine to launch it if it is not //! already up. static bool ConnectToExternalPVServer(SUIT_Desktop* aDesktop); +public slots: + void onPVViewCreated(SUIT_ViewWindow*); + private: static pqPVApplicationCore* MyCoreApp; static PARAVIS_ORB::PARAVIS_Gen_var MyEngine; - + static bool ConfigLoaded; + static PVViewer_Behaviors * ParaviewBehaviors; }; #endif diff --git a/src/PVGUI/view/PVViewer_ViewModel.h b/src/PVGUI/view/PVViewer_ViewModel.h index 6463c7ac..e70f663c 100644 --- a/src/PVGUI/view/PVViewer_ViewModel.h +++ b/src/PVGUI/view/PVViewer_ViewModel.h @@ -36,7 +36,6 @@ public: virtual SUIT_ViewWindow* createView(SUIT_Desktop* theDesktop); virtual QString getType() const { return Type(); } static QString Type() { return "ParaView"; } - }; #endif // !defined(_PVViewer_VIEWMODEL_H) diff --git a/src/PVGUI/view/PVViewer_ViewWindow.cxx b/src/PVGUI/view/PVViewer_ViewWindow.cxx index 84e37f0e..415717a5 100644 --- a/src/PVGUI/view/PVViewer_ViewWindow.cxx +++ b/src/PVGUI/view/PVViewer_ViewWindow.cxx @@ -21,6 +21,7 @@ // #include "PVViewer_ViewWindow.h" +#include "PVViewer_ViewManager.h" #include #include @@ -38,7 +39,7 @@ /*! \brief Constructor. \param theDesktop parent desktop window - \param theModel plt2d view model + \param theModel view model */ PVViewer_ViewWindow::PVViewer_ViewWindow( SUIT_Desktop* theDesktop, PVViewer_Viewer* theModel ) : SUIT_ViewWindow( theDesktop ), myPVMgr( 0 ) @@ -50,6 +51,12 @@ PVViewer_ViewWindow::PVViewer_ViewWindow( SUIT_Desktop* theDesktop, PVViewer_Vie // This is mandatory, see setParent() method in Qt 4 documentation myPVMgr->show(); setCentralWidget( myPVMgr ); + + // Finish ParaView set up: behaviors, connection and configurations. + // None of this is invoked in PARAVIS module case as it done earlier than View creation: + PVViewer_ViewManager::ParaviewInitBehaviors(true, theDesktop); + PVViewer_ViewManager::ConnectToExternalPVServer(theDesktop); + PVViewer_ViewManager::ParaviewLoadConfigurations(); } else qDebug("No multiViewManager defined"); } @@ -96,3 +103,8 @@ pqTabbedMultiViewWidget* PVViewer_ViewWindow::getMultiViewManager() const { return myPVMgr; } + +void PVViewer_ViewWindow::onEmulateApply() +{ + emit this->applyRequest(); +} diff --git a/src/PVGUI/view/PVViewer_ViewWindow.h b/src/PVGUI/view/PVViewer_ViewWindow.h index fb5dd106..e3ff387c 100644 --- a/src/PVGUI/view/PVViewer_ViewWindow.h +++ b/src/PVGUI/view/PVViewer_ViewWindow.h @@ -43,6 +43,12 @@ public: pqTabbedMultiViewWidget* getMultiViewManager() const; +signals: + void applyRequest(); + +public slots: + void onEmulateApply(); + private: PVViewer_Viewer* myModel; pqTabbedMultiViewWidget* myPVMgr; -- 2.39.2