From 693e2a7ecca39a06a09a6ffabdf59ba52ca251f9 Mon Sep 17 00:00:00 2001 From: David Thompson Date: Tue, 13 Dec 2022 18:41:33 -0500 Subject: [PATCH 1/2] Separate plugins into `core` and `gui` sets. --- CMake/smtkConfig.cmake.in | 10 ++- doc/release/notes/paraview-plugin-reorg.rst | 15 ++++ smtk/extension/paraview/CMakeLists.txt | 52 +++++++++---- .../paraview/appcomponents/CMakeLists.txt | 1 + .../appcomponents/plugin-gui/CMakeLists.txt | 7 ++ .../pqSMTKAppComponentsAutoStart.cxx | 36 --------- .../pqSMTKGuiAppComponentsAutoStart.cxx | 74 +++++++++++++++++++ .../pqSMTKGuiAppComponentsAutoStart.h | 37 ++++++++++ .../pqSMTKNewResourceBehavior.cxx | 6 +- 9 files changed, 182 insertions(+), 56 deletions(-) create mode 100644 doc/release/notes/paraview-plugin-reorg.rst create mode 100644 smtk/extension/paraview/appcomponents/pqSMTKGuiAppComponentsAutoStart.cxx create mode 100644 smtk/extension/paraview/appcomponents/pqSMTKGuiAppComponentsAutoStart.h diff --git a/CMake/smtkConfig.cmake.in b/CMake/smtkConfig.cmake.in index 66ab5a58d8..c11ddf6d4d 100644 --- a/CMake/smtkConfig.cmake.in +++ b/CMake/smtkConfig.cmake.in @@ -162,9 +162,13 @@ endif () # Now include the ParaView-specific targets and information. if (SMTK_ENABLE_PARAVIEW_SUPPORT) - include("${CMAKE_CURRENT_LIST_DIR}/SMTKParaViewExtensionPlugins-smtk_paraview_extension_plugin-targets-depends.cmake") - include("${CMAKE_CURRENT_LIST_DIR}/SMTKParaViewExtensionPlugins-targets.cmake") - include("${CMAKE_CURRENT_LIST_DIR}/SMTKParaViewExtensionPlugins-paraview-plugin-properties.cmake") + include("${CMAKE_CURRENT_LIST_DIR}/SMTKParaViewExtensionCorePlugins-smtk_paraview_extension_core_plugins-targets-depends.cmake") + include("${CMAKE_CURRENT_LIST_DIR}/SMTKParaViewExtensionCorePlugins-targets.cmake") + include("${CMAKE_CURRENT_LIST_DIR}/SMTKParaViewExtensionCorePlugins-paraview-plugin-properties.cmake") + + include("${CMAKE_CURRENT_LIST_DIR}/SMTKParaViewExtensionGuiPlugins-smtk_paraview_extension_gui_plugins-targets-depends.cmake") + include("${CMAKE_CURRENT_LIST_DIR}/SMTKParaViewExtensionGuiPlugins-targets.cmake") + include("${CMAKE_CURRENT_LIST_DIR}/SMTKParaViewExtensionGuiPlugins-paraview-plugin-properties.cmake") include("${CMAKE_CURRENT_LIST_DIR}/SMTKParaViewPlugins-smtk_paraview_plugins-targets-depends.cmake") include("${CMAKE_CURRENT_LIST_DIR}/SMTKParaViewPlugins-targets.cmake") diff --git a/doc/release/notes/paraview-plugin-reorg.rst b/doc/release/notes/paraview-plugin-reorg.rst new file mode 100644 index 0000000000..09ca6e8ac3 --- /dev/null +++ b/doc/release/notes/paraview-plugin-reorg.rst @@ -0,0 +1,15 @@ +ParaView plugins reorganized +---------------------------- + +SMTK's ParaView plugins have been reorganized into ++ a subset (``core``) which, while they may register new UI elements, + do not introduce persistent user interface elements (panels, menus, + toolbars) to ParaView's default interface. ++ a subset (``gui``) which do register new user interface elements + that appear in ParaView-based applications by default. + +This also involves splitting the auto-start class into two classes, +one for each set of plugins. + +Going forward, if you add a plugin (or new functionality to an existing +plugin) please ensure you choose the correct target. diff --git a/smtk/extension/paraview/CMakeLists.txt b/smtk/extension/paraview/CMakeLists.txt index 18d16baffc..3da67e4c69 100644 --- a/smtk/extension/paraview/CMakeLists.txt +++ b/smtk/extension/paraview/CMakeLists.txt @@ -34,25 +34,29 @@ vtk_module_build( HEADERS_DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}/${SMTK_VERSION}" TEST_DIRECTORY_NAME "NONE") -set(plugin_files - server/plugin/paraview.plugin) +set(core_plugin_files + server/plugin/paraview.plugin +) +set(gui_plugin_files) if (TARGET ParaView::pqApplicationComponents) - list(APPEND plugin_files - appcomponents/plugin-panel-defaults/paraview.plugin - appcomponents/plugin-legacy-operations/paraview.plugin - appcomponents/plugin-operations-panel/paraview.plugin + list(APPEND core_plugin_files appcomponents/plugin-core/paraview.plugin - appcomponents/plugin-grouping/paraview.plugin - appcomponents/plugin-gui/paraview.plugin appcomponents/plugin-readers/paraview.plugin mesh/plugin/paraview.plugin model/plugin/paraview.plugin project/plugin-core/paraview.plugin + ) + list(APPEND gui_plugin_files + appcomponents/plugin-panel-defaults/paraview.plugin + appcomponents/plugin-legacy-operations/paraview.plugin + appcomponents/plugin-operations-panel/paraview.plugin + appcomponents/plugin-grouping/paraview.plugin + appcomponents/plugin-gui/paraview.plugin project/plugin-gui/paraview.plugin ) if (ParaView_VERSION VERSION_GREATER_EQUAL "5.10.0") - list(APPEND plugin_files + list(APPEND core_plugin_files widgets/plugin/paraview.plugin operators/plugin/paraview.plugin ) @@ -65,20 +69,36 @@ if (TARGET ParaView::pqApplicationComponents) endif () paraview_plugin_scan( - PLUGIN_FILES ${plugin_files} - PROVIDES_PLUGINS paraview_plugins + PLUGIN_FILES ${core_plugin_files} + PROVIDES_PLUGINS core_paraview_plugins + ENABLE_BY_DEFAULT ON + HIDE_PLUGINS_FROM_CACHE ON) +paraview_plugin_build( + HEADERS_DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}/${SMTK_VERSION}" + LIBRARY_SUBDIRECTORY "${PROJECT_NAME}-${SMTK_VERSION}" + PLUGINS ${core_paraview_plugins} + AUTOLOAD ${core_paraview_plugins} + PLUGINS_FILE_NAME "smtk.extensions.core.xml" + TARGET smtk_paraview_extension_core_plugins + CMAKE_DESTINATION ${SMTK_INSTALL_CONFIG_DIR} + ADD_INSTALL_RPATHS ON + INSTALL_EXPORT SMTKParaViewExtensionCorePlugins) + + paraview_plugin_scan( + PLUGIN_FILES ${gui_plugin_files} + PROVIDES_PLUGINS gui_paraview_plugins ENABLE_BY_DEFAULT ON HIDE_PLUGINS_FROM_CACHE ON) paraview_plugin_build( HEADERS_DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}/${SMTK_VERSION}" LIBRARY_SUBDIRECTORY "${PROJECT_NAME}-${SMTK_VERSION}" - PLUGINS ${paraview_plugins} - AUTOLOAD ${paraview_plugins} - PLUGINS_FILE_NAME "smtk.extensions.xml" - TARGET smtk_paraview_extension_plugin + PLUGINS ${gui_paraview_plugins} + AUTOLOAD ${gui_paraview_plugins} + PLUGINS_FILE_NAME "smtk.extensions.gui.xml" + TARGET smtk_paraview_extension_gui_plugins CMAKE_DESTINATION ${SMTK_INSTALL_CONFIG_DIR} ADD_INSTALL_RPATHS ON - INSTALL_EXPORT SMTKParaViewExtensionPlugins) + INSTALL_EXPORT SMTKParaViewExtensionGuiPlugins) if (SMTK_ENABLE_PYTHON_WRAPPING) add_subdirectory(pybind11) diff --git a/smtk/extension/paraview/appcomponents/CMakeLists.txt b/smtk/extension/paraview/appcomponents/CMakeLists.txt index 3a38f1e09d..2eb8b23a31 100644 --- a/smtk/extension/paraview/appcomponents/CMakeLists.txt +++ b/smtk/extension/paraview/appcomponents/CMakeLists.txt @@ -16,6 +16,7 @@ set(classes pqSMTKResourceRepresentation pqSMTKWrapper pqSMTKAppComponentsAutoStart + pqSMTKGuiAppComponentsAutoStart pqSMTKCallObserversOnMainThreadBehavior pqSMTKCloseResourceBehavior pqSMTKGroupComponentsBehavior diff --git a/smtk/extension/paraview/appcomponents/plugin-gui/CMakeLists.txt b/smtk/extension/paraview/appcomponents/plugin-gui/CMakeLists.txt index db67744587..78cbfd75a1 100644 --- a/smtk/extension/paraview/appcomponents/plugin-gui/CMakeLists.txt +++ b/smtk/extension/paraview/appcomponents/plugin-gui/CMakeLists.txt @@ -1,5 +1,10 @@ set(sources) +paraview_plugin_add_auto_start( + CLASS_NAME pqSMTKGuiAppComponentsAutoStart + INTERFACES auto_start_interfaces + SOURCES auto_start_sources) + paraview_plugin_add_action_group( CLASS_NAME pqSMTKSelectionFilterBehavior GROUP_NAME "ToolBar/SMTK Selection Filters" @@ -22,6 +27,7 @@ paraview_plugin_add_dock_window( SOURCES resource_dock_sources) set(interfaces + ${auto_start_interfaces} ${action_group_interfaces} ${toolbar_interfaces} ${proxy_interfaces} @@ -29,6 +35,7 @@ set(interfaces ${resource_dock_interfaces} ) list(APPEND sources + ${auto_start_sources} ${action_group_sources} ${toolbar_sources} ${proxy_sources} diff --git a/smtk/extension/paraview/appcomponents/pqSMTKAppComponentsAutoStart.cxx b/smtk/extension/paraview/appcomponents/pqSMTKAppComponentsAutoStart.cxx index 68c11ffc0a..d4b8435036 100644 --- a/smtk/extension/paraview/appcomponents/pqSMTKAppComponentsAutoStart.cxx +++ b/smtk/extension/paraview/appcomponents/pqSMTKAppComponentsAutoStart.cxx @@ -13,17 +13,13 @@ #include "smtk/extension/paraview/appcomponents/pqSMTKBehavior.h" #include "smtk/extension/paraview/appcomponents/pqSMTKCallObserversOnMainThreadBehavior.h" -#include "smtk/extension/paraview/appcomponents/pqSMTKCloseResourceBehavior.h" #include "smtk/extension/paraview/appcomponents/pqSMTKCloseWithActiveOperationBehavior.h" #include "smtk/extension/paraview/appcomponents/pqSMTKDisplayAttributeOnLoadBehavior.h" -#include "smtk/extension/paraview/appcomponents/pqSMTKImportIntoResourceBehavior.h" -#include "smtk/extension/paraview/appcomponents/pqSMTKNewResourceBehavior.h" #include "smtk/extension/paraview/appcomponents/pqSMTKOperationHintsBehavior.h" #include "smtk/extension/paraview/appcomponents/pqSMTKPipelineSelectionBehavior.h" #include "smtk/extension/paraview/appcomponents/pqSMTKRegisterImportersBehavior.h" #include "smtk/extension/paraview/appcomponents/pqSMTKRenderResourceBehavior.h" #include "smtk/extension/paraview/appcomponents/pqSMTKSaveOnCloseResourceBehavior.h" -#include "smtk/extension/paraview/appcomponents/pqSMTKSaveResourceBehavior.h" #include "smtk/extension/paraview/appcomponents/pqSMTKWrapper.h" #include "smtk/extension/paraview/appcomponents/pqToolboxEventPlayer.h" #include "smtk/extension/paraview/appcomponents/pqToolboxEventTranslator.h" @@ -31,8 +27,6 @@ #include "smtk/extension/paraview/server/vtkSMSMTKWrapperProxy.h" #ifdef SMTK_PYTHON_ENABLED -#include "smtk/extension/paraview/appcomponents/pqSMTKExportSimulationBehavior.h" -#include "smtk/extension/paraview/appcomponents/pqSMTKImportOperationBehavior.h" #include "smtk/extension/paraview/appcomponents/pqSMTKPythonTrace.h" #endif @@ -101,23 +95,9 @@ void pqSMTKAppComponentsAutoStart::startup() auto* behavior = pqSMTKBehavior::instance(this); auto* renderResourceBehavior = pqSMTKRenderResourceBehavior::instance(this); - auto* closeResourceBehavior = pqSMTKCloseResourceBehavior::instance(this); auto* callObserversOnMainThread = pqSMTKCallObserversOnMainThreadBehavior::instance(this); -#ifdef SMTK_PYTHON_ENABLED - auto* rsrcImportOpMgr = pqSMTKImportOperationBehavior::instance(this); - auto* rsrcExportSimMgr = pqSMTKExportSimulationBehavior::instance(this); -#endif auto* pipelineSync = pqSMTKPipelineSelectionBehavior::instance(this); auto* displayOnLoad = pqSMTKDisplayAttributeOnLoadBehavior::instance(this); - - // The "New Resource" menu item keys off of the "Save Resource" menu item, - // so the order of initialization for the following two global statics is - // important! - // - // TODO: There must be a better way to do this. - auto* rsrcSaveMgr = pqSMTKSaveResourceBehavior::instance(this); - auto* rsrcNewMgr = pqSMTKNewResourceBehavior::instance(this); - auto* rsrcImportIntoMgr = pqSMTKImportIntoResourceBehavior::instance(this); auto* registerImportersBehavior = pqSMTKRegisterImportersBehavior::instance(this); auto* mainWindow = pqCoreUtilities::mainWidget(); @@ -139,14 +119,6 @@ void pqSMTKAppComponentsAutoStart::startup() pqCore->registerManager("smtk close with active operation", closeWithActiveOperationBehavior); } pqCore->registerManager("call observers on main thread", callObserversOnMainThread); - pqCore->registerManager("smtk close resource", closeResourceBehavior); -#ifdef SMTK_PYTHON_ENABLED - pqCore->registerManager("smtk import operation", rsrcImportOpMgr); - pqCore->registerManager("smtk export simulation", rsrcExportSimMgr); -#endif - pqCore->registerManager("smtk save resource", rsrcSaveMgr); - pqCore->registerManager("smtk new resource", rsrcNewMgr); - pqCore->registerManager("smtk import into resource", rsrcImportIntoMgr); pqCore->registerManager("smtk register importers", registerImportersBehavior); pqCore->registerManager("smtk pipeline selection sync", pipelineSync); pqCore->registerManager("smtk display attribute on load", displayOnLoad); @@ -203,14 +175,6 @@ void pqSMTKAppComponentsAutoStart::shutdown() pqCore->unRegisterManager("smtk close with active operation"); } pqCore->unRegisterManager("call observers on main thread"); - pqCore->unRegisterManager("smtk close resource"); -#ifdef SMTK_PYTHON_ENABLED - pqCore->unRegisterManager("smtk import operation"); - pqCore->unRegisterManager("smtk export simulation"); -#endif - pqCore->unRegisterManager("smtk save resource"); - pqCore->unRegisterManager("smtk new resource"); - pqCore->unRegisterManager("smtk import into resource"); pqCore->unRegisterManager("smtk register importers"); pqCore->unRegisterManager("smtk pipeline selection sync"); pqCore->unRegisterManager("smtk display attribute on load"); diff --git a/smtk/extension/paraview/appcomponents/pqSMTKGuiAppComponentsAutoStart.cxx b/smtk/extension/paraview/appcomponents/pqSMTKGuiAppComponentsAutoStart.cxx new file mode 100644 index 0000000000..97be9ff86f --- /dev/null +++ b/smtk/extension/paraview/appcomponents/pqSMTKGuiAppComponentsAutoStart.cxx @@ -0,0 +1,74 @@ +//========================================================================= +// Copyright (c) Kitware, Inc. +// All rights reserved. +// See LICENSE.txt for details. +// +// This software is distributed WITHOUT ANY WARRANTY; without even +// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR +// PURPOSE. See the above copyright notice for more information. +//========================================================================= +#include "smtk/extension/paraview/appcomponents/pqSMTKGuiAppComponentsAutoStart.h" + +#include "smtk/extension/paraview/appcomponents/pqSMTKCloseResourceBehavior.h" +#include "smtk/extension/paraview/appcomponents/pqSMTKImportIntoResourceBehavior.h" +#include "smtk/extension/paraview/appcomponents/pqSMTKNewResourceBehavior.h" +#include "smtk/extension/paraview/appcomponents/pqSMTKSaveResourceBehavior.h" +#ifdef SMTK_PYTHON_ENABLED +#include "smtk/extension/paraview/appcomponents/pqSMTKExportSimulationBehavior.h" +#include "smtk/extension/paraview/appcomponents/pqSMTKImportOperationBehavior.h" +#endif + +#include + +pqSMTKGuiAppComponentsAutoStart::pqSMTKGuiAppComponentsAutoStart(QObject* parent) + : QObject(parent) +{ + // Does nothing +} + +void pqSMTKGuiAppComponentsAutoStart::startup() +{ + auto* closeResourceBehavior = pqSMTKCloseResourceBehavior::instance(this); +#ifdef SMTK_PYTHON_ENABLED + auto* rsrcImportOpMgr = pqSMTKImportOperationBehavior::instance(this); + auto* rsrcExportSimMgr = pqSMTKExportSimulationBehavior::instance(this); +#endif + + // The "New Resource" menu item keys off of the "Save Resource" menu item, + // so the order of initialization for the following two global statics is + // important! + // + // TODO: There must be a better way to do this. + auto* rsrcSaveMgr = pqSMTKSaveResourceBehavior::instance(this); + auto* rsrcNewMgr = pqSMTKNewResourceBehavior::instance(this); + auto* rsrcImportIntoMgr = pqSMTKImportIntoResourceBehavior::instance(this); + + auto* pqCore = pqApplicationCore::instance(); + if (pqCore) + { + pqCore->registerManager("smtk close resource", closeResourceBehavior); +#ifdef SMTK_PYTHON_ENABLED + pqCore->registerManager("smtk import operation", rsrcImportOpMgr); + pqCore->registerManager("smtk export simulation", rsrcExportSimMgr); +#endif + pqCore->registerManager("smtk save resource", rsrcSaveMgr); + pqCore->registerManager("smtk new resource", rsrcNewMgr); + pqCore->registerManager("smtk import into resource", rsrcImportIntoMgr); + } +} + +void pqSMTKGuiAppComponentsAutoStart::shutdown() +{ + auto* pqCore = pqApplicationCore::instance(); + if (pqCore) + { + pqCore->unRegisterManager("smtk close resource"); +#ifdef SMTK_PYTHON_ENABLED + pqCore->unRegisterManager("smtk import operation"); + pqCore->unRegisterManager("smtk export simulation"); +#endif + pqCore->unRegisterManager("smtk save resource"); + pqCore->unRegisterManager("smtk new resource"); + pqCore->unRegisterManager("smtk import into resource"); + } +} diff --git a/smtk/extension/paraview/appcomponents/pqSMTKGuiAppComponentsAutoStart.h b/smtk/extension/paraview/appcomponents/pqSMTKGuiAppComponentsAutoStart.h new file mode 100644 index 0000000000..722227ade2 --- /dev/null +++ b/smtk/extension/paraview/appcomponents/pqSMTKGuiAppComponentsAutoStart.h @@ -0,0 +1,37 @@ +//========================================================================= +// Copyright (c) Kitware, Inc. +// All rights reserved. +// See LICENSE.txt for details. +// +// This software is distributed WITHOUT ANY WARRANTY; without even +// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR +// PURPOSE. See the above copyright notice for more information. +//========================================================================= +#ifndef smtk_extension_paraview_appcomponents_pqSMTKGuiAppComponentsAutoStart_h +#define smtk_extension_paraview_appcomponents_pqSMTKGuiAppComponentsAutoStart_h + +#include "smtk/extension/paraview/appcomponents/smtkPQComponentsExtModule.h" + +#include "smtk/extension/paraview/appcomponents/pqQtKeywordWrapping.h" + +#include + +class pqSMTKWrapper; +class pqServer; +class vtkSMProxy; + +class SMTKPQCOMPONENTSEXT_EXPORT pqSMTKGuiAppComponentsAutoStart : public QObject +{ + Q_OBJECT +public: + pqSMTKGuiAppComponentsAutoStart(QObject* parent = nullptr); + ~pqSMTKGuiAppComponentsAutoStart() override = default; + + void startup(); + void shutdown(); + +private: + Q_DISABLE_COPY(pqSMTKGuiAppComponentsAutoStart); +}; + +#endif diff --git a/smtk/extension/paraview/appcomponents/pqSMTKNewResourceBehavior.cxx b/smtk/extension/paraview/appcomponents/pqSMTKNewResourceBehavior.cxx index d846432551..91708e044c 100644 --- a/smtk/extension/paraview/appcomponents/pqSMTKNewResourceBehavior.cxx +++ b/smtk/extension/paraview/appcomponents/pqSMTKNewResourceBehavior.cxx @@ -353,7 +353,11 @@ pqSMTKNewResourceBehavior::~pqSMTKNewResourceBehavior() pqSMTKWrapper* wrapper = pqSMTKBehavior::instance()->resourceManagerForServer(server); if (wrapper != nullptr) { - wrapper->smtkOperationManager()->groupObservers().erase(m_key); + auto opMgr = wrapper->smtkOperationManager(); + if (opMgr) + { + opMgr->groupObservers().erase(m_key); + } } g_instance = nullptr; -- GitLab From 601650ca9d252e421b20f039d1066d17b7f011e1 Mon Sep 17 00:00:00 2001 From: David Thompson Date: Wed, 4 Jan 2023 07:44:04 -0500 Subject: [PATCH 2/2] Fix a crash induced by plugin-order shutdown. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previously, pqSMTKNewResourceBehavior was destroyed at the same time that the server was shut down. Now, because it has been separated into the pqSMTKGuiAppComponentsAutoStart plugin, the ParaView server may not exist at the time it is destroyed – check before dereferencing. --- .../appcomponents/pqSMTKNewResourceBehavior.cxx | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/smtk/extension/paraview/appcomponents/pqSMTKNewResourceBehavior.cxx b/smtk/extension/paraview/appcomponents/pqSMTKNewResourceBehavior.cxx index 91708e044c..6267dfaff4 100644 --- a/smtk/extension/paraview/appcomponents/pqSMTKNewResourceBehavior.cxx +++ b/smtk/extension/paraview/appcomponents/pqSMTKNewResourceBehavior.cxx @@ -350,13 +350,16 @@ pqSMTKNewResourceBehavior::~pqSMTKNewResourceBehavior() if (g_instance == this) { pqServer* server = pqActiveObjects::instance().activeServer(); - pqSMTKWrapper* wrapper = pqSMTKBehavior::instance()->resourceManagerForServer(server); - if (wrapper != nullptr) + if (server) { - auto opMgr = wrapper->smtkOperationManager(); - if (opMgr) + pqSMTKWrapper* wrapper = pqSMTKBehavior::instance()->resourceManagerForServer(server); + if (wrapper != nullptr) { - opMgr->groupObservers().erase(m_key); + auto opMgr = wrapper->smtkOperationManager(); + if (opMgr) + { + opMgr->groupObservers().erase(m_key); + } } } -- GitLab