From e681cd0ccba8f871feecaa7dfdf6868828698dc5 Mon Sep 17 00:00:00 2001 From: Steven Hahn <hahnse@ornl.gov> Date: Fri, 23 Jun 2017 17:37:23 -0400 Subject: [PATCH] Use pqSaveScreenshotReaction instead of custom class. --- .../VatesSimpleGui/ViewWidgets/CMakeLists.txt | 3 - .../MdViewerWidget.h | 4 +- .../SaveScreenshotReaction.h | 77 -------- .../ViewWidgets/src/MdViewerWidget.cpp | 8 +- .../src/SaveScreenshotReaction.cpp | 169 ------------------ 5 files changed, 4 insertions(+), 257 deletions(-) delete mode 100644 Vates/VatesSimpleGui/ViewWidgets/inc/MantidVatesSimpleGuiViewWidgets/SaveScreenshotReaction.h delete mode 100644 Vates/VatesSimpleGui/ViewWidgets/src/SaveScreenshotReaction.cpp diff --git a/Vates/VatesSimpleGui/ViewWidgets/CMakeLists.txt b/Vates/VatesSimpleGui/ViewWidgets/CMakeLists.txt index 3192e10142f..ac64efd1a8b 100644 --- a/Vates/VatesSimpleGui/ViewWidgets/CMakeLists.txt +++ b/Vates/VatesSimpleGui/ViewWidgets/CMakeLists.txt @@ -18,7 +18,6 @@ set( INCLUDE_FILES inc/MantidVatesSimpleGuiViewWidgets/PeaksTableControllerVsi.h inc/MantidVatesSimpleGuiViewWidgets/PeaksWidget.h inc/MantidVatesSimpleGuiViewWidgets/PeaksTabWidget.h - inc/MantidVatesSimpleGuiViewWidgets/SaveScreenshotReaction.h inc/MantidVatesSimpleGuiViewWidgets/RebinnedSourcesManager.h inc/MantidVatesSimpleGuiViewWidgets/VisibleAxesColor.h inc/MantidVatesSimpleGuiViewWidgets/StandardView.h @@ -45,7 +44,6 @@ set( SOURCE_FILES src/PeaksWidget.cpp src/pqCameraToolbarNonOrthogonalAxes.cpp src/pqCameraReactionNonOrthogonalAxes.cpp - src/SaveScreenshotReaction.cpp src/RebinnedSourcesManager.cpp src/VisibleAxesColor.cpp src/StandardView.cpp @@ -72,7 +70,6 @@ qt4_wrap_cpp( MOC_SOURCES inc/MantidVatesSimpleGuiViewWidgets/PeaksTabWidget.h inc/MantidVatesSimpleGuiViewWidgets/pqCameraToolbarNonOrthogonalAxes.h inc/MantidVatesSimpleGuiViewWidgets/pqCameraReactionNonOrthogonalAxes.h - inc/MantidVatesSimpleGuiViewWidgets/SaveScreenshotReaction.h inc/MantidVatesSimpleGuiViewWidgets/RebinnedSourcesManager.h inc/MantidVatesSimpleGuiViewWidgets/StandardView.h inc/MantidVatesSimpleGuiViewWidgets/SplatterPlotView.h diff --git a/Vates/VatesSimpleGui/ViewWidgets/inc/MantidVatesSimpleGuiViewWidgets/MdViewerWidget.h b/Vates/VatesSimpleGui/ViewWidgets/inc/MantidVatesSimpleGuiViewWidgets/MdViewerWidget.h index 11bf5451ec8..86883737462 100644 --- a/Vates/VatesSimpleGui/ViewWidgets/inc/MantidVatesSimpleGuiViewWidgets/MdViewerWidget.h +++ b/Vates/VatesSimpleGui/ViewWidgets/inc/MantidVatesSimpleGuiViewWidgets/MdViewerWidget.h @@ -20,6 +20,7 @@ class pqApplicationSettingsReaction; class pqLoadDataReaction; class pqPipelineSource; +class pqSaveScreenshotReaction; // forward declaration of Qt classes class QAction; @@ -35,7 +36,6 @@ namespace Vates { namespace SimpleGui { class RotationPointDialog; -class SaveScreenshotReaction; class ViewBase; class RebinDialog; class ColorMapEditorPanel; @@ -161,7 +161,7 @@ private: QAction *lodAction; ///< Holder for the LOD threshold menu item bool pluginMode; ///< Flag to say widget is in plugin mode RotationPointDialog *rotPointDialog; ///< Holder for the rotation point dialog - SaveScreenshotReaction *screenShot; ///< Holder for the screen shot reaction + pqSaveScreenshotReaction *screenShot; ///< Holder for the screen shot reaction Ui::MdViewerWidgetClass ui; ///< The MD viewer's UI form QHBoxLayout *viewLayout; ///< Layout manager for the view widget pqApplicationSettingsReaction * diff --git a/Vates/VatesSimpleGui/ViewWidgets/inc/MantidVatesSimpleGuiViewWidgets/SaveScreenshotReaction.h b/Vates/VatesSimpleGui/ViewWidgets/inc/MantidVatesSimpleGuiViewWidgets/SaveScreenshotReaction.h deleted file mode 100644 index 5f73edcfe60..00000000000 --- a/Vates/VatesSimpleGui/ViewWidgets/inc/MantidVatesSimpleGuiViewWidgets/SaveScreenshotReaction.h +++ /dev/null @@ -1,77 +0,0 @@ -#ifndef __SAVESCREENSHOTREACTION_H -#define __SAVESCREENSHOTREACTION_H - -#include "MantidVatesSimpleGuiViewWidgets/WidgetDllOption.h" - -#include <pqReaction.h> - -namespace Mantid { -namespace Vates { -namespace SimpleGui { - -class EXPORT_OPT_MANTIDVATES_SIMPLEGUI_VIEWWIDGETS SaveScreenshotReaction - : public pqReaction { - /** - * - This class is a copy of the ParaView pqSaveScreenshotReaction class and is - modified in order to be used with our "custom" views. - - @date 14/06/2013 - - Copyright © 2011 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge - National Laboratory & European Spallation Source - - This file is part of Mantid. - - Mantid is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - - Mantid is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see <http://www.gnu.org/licenses/>. - - File change history is stored at: <https://github.com/mantidproject/mantid> - Code Documentation is available at: <http://doxygen.mantidproject.org> - */ - - Q_OBJECT - typedef pqReaction Superclass; - -public: - /// Constructor. Parent cannot be NULL. - SaveScreenshotReaction(QAction *parent); - - /// Saves the screenshot. - /// Note that this method is static. Applications can simply use this without - /// having to create a reaction instance. - static void saveScreenshot(); - static bool saveScreenshot(const QString &filename, const QSize &size, - int quality, bool all_views = false); - -public slots: - /// Updates the enabled state. Applications need not explicitly call this. - void updateEnableState() override; - /// Prompt for a filename. Will return empty string if user cancelled the - /// operation. - static QString promptFileName(); - -protected: - /// Called when the action is triggered. - virtual void onTriggered() override { - SaveScreenshotReaction::saveScreenshot(); - } - -private: - Q_DISABLE_COPY(SaveScreenshotReaction) -}; -} -} -} - -#endif // __SAVESCREENSHOTREACTION_H diff --git a/Vates/VatesSimpleGui/ViewWidgets/src/MdViewerWidget.cpp b/Vates/VatesSimpleGui/ViewWidgets/src/MdViewerWidget.cpp index 0d0532bba1a..beaf489790c 100644 --- a/Vates/VatesSimpleGui/ViewWidgets/src/MdViewerWidget.cpp +++ b/Vates/VatesSimpleGui/ViewWidgets/src/MdViewerWidget.cpp @@ -26,7 +26,6 @@ #include "MantidVatesSimpleGuiViewWidgets/ColorSelectionWidget.h" #include "MantidVatesSimpleGuiViewWidgets/MdViewerWidget.h" #include "MantidVatesSimpleGuiViewWidgets/MultisliceView.h" -#include "MantidVatesSimpleGuiViewWidgets/SaveScreenshotReaction.h" #include "MantidVatesSimpleGuiViewWidgets/SplatterPlotView.h" #include "MantidVatesSimpleGuiViewWidgets/StandardView.h" #include "MantidVatesSimpleGuiViewWidgets/ThreesliceView.h" @@ -37,10 +36,6 @@ #include "boost/shared_ptr.hpp" #include "boost/scoped_ptr.hpp" -// Have to deal with ParaView warnings and Intel compiler the hard way. -#if defined(__INTEL_COMPILER) -#pragma warning disable 1170 -#endif #include <pqActiveObjects.h> #include <pqAnimationManager.h> #include <pqAnimationScene.h> @@ -56,6 +51,7 @@ #include <pqPipelineRepresentation.h> #include <pqPipelineSource.h> #include <pqRenderView.h> +#include <pqSaveScreenshotReaction.h> #include <pqServer.h> #include <pqServerManagerModel.h> #include <pqSettings.h> @@ -1367,7 +1363,7 @@ void MdViewerWidget::createMenus() { screenShotAction->setShortcut(QKeySequence::fromString("Ctrl+Shift+R")); screenShotAction->setStatusTip( QApplication::tr("Save a screenshot of the current view.")); - this->screenShot = new SaveScreenshotReaction(screenShotAction); + this->screenShot = new pqSaveScreenshotReaction(screenShotAction); viewMenu->addAction(screenShotAction); QAction *settingsAction = new QAction(QApplication::tr("Settings..."), this); diff --git a/Vates/VatesSimpleGui/ViewWidgets/src/SaveScreenshotReaction.cpp b/Vates/VatesSimpleGui/ViewWidgets/src/SaveScreenshotReaction.cpp deleted file mode 100644 index 572dd2c10fd..00000000000 --- a/Vates/VatesSimpleGui/ViewWidgets/src/SaveScreenshotReaction.cpp +++ /dev/null @@ -1,169 +0,0 @@ -#include "MantidVatesSimpleGuiViewWidgets/SaveScreenshotReaction.h" - -#include "pqActiveObjects.h" -#include "pqApplicationCore.h" -#include "pqCoreUtilities.h" -#include "pqFileDialog.h" -#include "pqProxyWidgetDialog.h" -#include "pqServer.h" -#include "pqSettings.h" -#include "pqView.h" -#include "vtkImageData.h" -#include "vtkNew.h" -#include "vtkSMParaViewPipelineController.h" -#include "vtkSMProperty.h" -#include "vtkSMPropertyHelper.h" -#include "vtkSMSaveScreenshotProxy.h" -#include "vtkSMSessionProxyManager.h" -#include "vtkSMUtilities.h" -#include "vtkSMViewLayoutProxy.h" -#include "vtkSMViewProxy.h" -#include "vtkSmartPointer.h" - -#include <QDebug> -#include <QFileInfo> - -namespace Mantid { -namespace Vates { -namespace SimpleGui { - -//----------------------------------------------------------------------------- -SaveScreenshotReaction::SaveScreenshotReaction(QAction *parentObject) - : Superclass(parentObject) { - // load state enable state depends on whether we are connected to an active - // server or not and whether - pqActiveObjects *activeObjects = &pqActiveObjects::instance(); - QObject::connect(activeObjects, SIGNAL(serverChanged(pqServer *)), this, - SLOT(updateEnableState())); - QObject::connect(activeObjects, SIGNAL(viewChanged(pqView *)), this, - SLOT(updateEnableState())); - this->updateEnableState(); -} - -//----------------------------------------------------------------------------- -void SaveScreenshotReaction::updateEnableState() { - pqActiveObjects *activeObjects = &pqActiveObjects::instance(); - bool is_enabled = - (activeObjects->activeView() && activeObjects->activeServer()); - this->parentAction()->setEnabled(is_enabled); -} - -//----------------------------------------------------------------------------- -QString SaveScreenshotReaction::promptFileName() { - QString lastUsedExt; - // Load the most recently used file extensions from QSettings, if available. - pqSettings *settings = pqApplicationCore::instance()->settings(); - if (settings->contains("extensions/ScreenshotExtension")) { - lastUsedExt = settings->value("extensions/ScreenshotExtension").toString(); - } - - QString filters("PNG image (*.png);;JPG image (*.jpg);;TIFF image (*.tif)" - ";;BMP image (*.bmp);;PPM image (*.ppm)"); - - pqFileDialog file_dialog(NULL, pqCoreUtilities::mainWidget(), - tr("Save Screenshot:"), QString(), filters); - file_dialog.setRecentlyUsedExtension(lastUsedExt); - file_dialog.setObjectName("FileSaveScreenshotDialog"); - file_dialog.setFileMode(pqFileDialog::AnyFile); - if (file_dialog.exec() != QDialog::Accepted) { - return QString(); - } - - QString file = file_dialog.getSelectedFiles()[0]; - QFileInfo fileInfo(file); - lastUsedExt = QString("*.") + fileInfo.suffix(); - settings->setValue("extensions/ScreenshotExtension", lastUsedExt); - return file; -} - -//----------------------------------------------------------------------------- -void SaveScreenshotReaction::saveScreenshot() { - pqView *view = pqActiveObjects::instance().activeView(); - if (!view) { - qDebug() << "Cannot save image. No active view."; - return; - } - - vtkSMViewProxy *viewProxy = view->getViewProxy(); - vtkSMViewLayoutProxy *layout = vtkSMViewLayoutProxy::FindLayout(viewProxy); - int showWindowDecorations = -1; - - vtkSMSessionProxyManager *pxm = view->getServer()->proxyManager(); - vtkSmartPointer<vtkSMProxy> proxy; - proxy.TakeReference(pxm->NewProxy("misc", "SaveScreenshot")); - vtkSMSaveScreenshotProxy *shProxy = - vtkSMSaveScreenshotProxy::SafeDownCast(proxy); - if (!shProxy) { - qCritical() << "Incorrect type for `SaveScreenshot` proxy."; - return; - } - - vtkNew<vtkSMParaViewPipelineController> controller; - controller->PreInitializeProxy(shProxy); - vtkSMPropertyHelper(shProxy, "View").Set(viewProxy); - vtkSMPropertyHelper(shProxy, "Layout").Set(layout); - controller->PostInitializeProxy(shProxy); - - if (shProxy->UpdateSaveAllViewsPanelVisibility()) { - Q_ASSERT(layout != NULL); - // let's hide window decorations. - vtkSMPropertyHelper helper(layout, "ShowWindowDecorations"); - showWindowDecorations = helper.GetAsInt(); - helper.Set(0); - } - - pqProxyWidgetDialog dialog(shProxy, pqCoreUtilities::mainWidget()); - dialog.setObjectName("SaveScreenshotDialog"); - dialog.setApplyChangesImmediately(true); - dialog.setWindowTitle("Save Screenshot Options"); - dialog.setEnableSearchBar(true); - dialog.setSettingsKey("SaveScreenshotDialog"); - if (dialog.exec() == QDialog::Accepted) { - QString filename = SaveScreenshotReaction::promptFileName(); - if (!filename.isEmpty()) { - shProxy->WriteImage(filename.toLocal8Bit().data()); - } - } - - if (layout && showWindowDecorations != -1) { - vtkSMPropertyHelper(layout, "ShowWindowDecorations") - .Set(showWindowDecorations); - layout->UpdateVTKObjects(); - } - - // This should not be needed as image capturing code only affects back buffer, - // however it is currently needed due to paraview/paraview#17256. Once that's - // fixed, we should remove this. - pqApplicationCore::instance()->render(); -} - -//----------------------------------------------------------------------------- -bool SaveScreenshotReaction::saveScreenshot(const QString &filename, - const QSize &size, int quality, - bool all_views) { - pqView *view = pqActiveObjects::instance().activeView(); - if (!view) { - qDebug() << "Cannot save image. No active view."; - return false; - } - - vtkSMViewProxy *viewProxy = view->getViewProxy(); - - vtkSmartPointer<vtkImageData> image; - const vtkVector2i isize(size.width(), size.height()); - if (all_views) { - vtkSMViewLayoutProxy *layout = vtkSMViewLayoutProxy::FindLayout(viewProxy); - image = vtkSMSaveScreenshotProxy::CaptureImage(layout, isize); - } else { - image = vtkSMSaveScreenshotProxy::CaptureImage(viewProxy, isize); - } - - if (image) { - return vtkSMUtilities::SaveImage(image, filename.toLocal8Bit().data(), - quality) != 0; - } - return false; -} -} -} -} -- GitLab