From 758ac9ef8cd383f98444aa1aa18a0e20a7b894d4 Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Tue, 14 Feb 2017 15:03:54 +0100 Subject: [PATCH] #1214 Generalized export of snapshot images for all plot window types --- .../Application/RiaApplication.cpp | 2 +- .../RicSnapshotViewToClipboardFeature.cpp | 53 ++++++------------- .../RicSnapshotViewToClipboardFeature.h | 2 +- .../ProjectDataModel/RimViewWindow.cpp | 13 +++++ .../ProjectDataModel/RimViewWindow.h | 1 + 5 files changed, 33 insertions(+), 38 deletions(-) diff --git a/ApplicationCode/Application/RiaApplication.cpp b/ApplicationCode/Application/RiaApplication.cpp index a6d98e7bd5..2f01a6911f 100644 --- a/ApplicationCode/Application/RiaApplication.cpp +++ b/ApplicationCode/Application/RiaApplication.cpp @@ -2285,7 +2285,7 @@ void RiaApplication::runRegressionTest(const QString& testRootPath) QString fullPathGeneratedFolder = testCaseFolder.absoluteFilePath(generatedFolderName); saveSnapshotForAllViews(fullPathGeneratedFolder); - RicSnapshotAllPlotsToFileFeature::createSnapshotOfAllPlotsInFolder(fullPathGeneratedFolder); + RicSnapshotAllPlotsToFileFeature::exportSnapshotOfAllPlotsIntoFolder(fullPathGeneratedFolder); QDir baseDir(testCaseFolder.filePath(baseFolderName)); QDir genDir(testCaseFolder.filePath(generatedFolderName)); diff --git a/ApplicationCode/Commands/RicSnapshotViewToClipboardFeature.cpp b/ApplicationCode/Commands/RicSnapshotViewToClipboardFeature.cpp index 6c0e0f3f42..47e9f15a39 100644 --- a/ApplicationCode/Commands/RicSnapshotViewToClipboardFeature.cpp +++ b/ApplicationCode/Commands/RicSnapshotViewToClipboardFeature.cpp @@ -20,12 +20,10 @@ #include "RiaApplication.h" +#include "RimMainPlotCollection.h" #include "RimProject.h" -#include "RimSummaryPlot.h" #include "RimViewWindow.h" -#include "RimWellLogPlot.h" #include "RiuMainPlotWindow.h" -#include "RiuWellLogPlot.h" #include "cafUtils.h" @@ -35,6 +33,7 @@ #include #include #include +#include CAF_CMD_SOURCE_INIT(RicSnapshotViewToClipboardFeature, "RicSnapshotViewToClipboardFeature"); @@ -178,13 +177,16 @@ void RicSnapshotAllPlotsToFileFeature::saveAllPlots() // Save images in snapshot catalog relative to project directory QString snapshotFolderName = app->createAbsolutePathFromProjectRelativePath("snapshots"); - createSnapshotOfAllPlotsInFolder(snapshotFolderName); + exportSnapshotOfAllPlotsIntoFolder(snapshotFolderName); + + QString text = QString("Exported snapshots to folder : \n%1").arg(snapshotFolderName); + QMessageBox::information(nullptr, "Export Snapshots To Folder", text); } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -void RicSnapshotAllPlotsToFileFeature::createSnapshotOfAllPlotsInFolder(QString snapshotFolderName) +void RicSnapshotAllPlotsToFileFeature::exportSnapshotOfAllPlotsIntoFolder(QString snapshotFolderName) { RiaApplication* app = RiaApplication::instance(); @@ -199,41 +201,20 @@ void RicSnapshotAllPlotsToFileFeature::createSnapshotOfAllPlotsInFolder(QString const QString absSnapshotPath = snapshotPath.absolutePath(); - // Well log plots + std::vector viewWindows; + proj->mainPlotCollection()->descendantsIncludingThisOfType(viewWindows); + + for (auto viewWindow : viewWindows) { - std::vector wellLogPlots; - proj->descendantsIncludingThisOfType(wellLogPlots); - for (RimWellLogPlot* wellLogPlot : wellLogPlots) + if (viewWindow->isMdiWindow() && viewWindow->viewWidget()) { - if (wellLogPlot && wellLogPlot->viewWidget()) - { - QString fileName = wellLogPlot->description(); - fileName = caf::Utils::makeValidFileBasename(fileName); + QString fileName = viewWindow->userDescriptionField()->uiCapability()->uiValue().toString(); + fileName = caf::Utils::makeValidFileBasename(fileName); - QString absoluteFileName = caf::Utils::constructFullFileName(absSnapshotPath, fileName, ".png"); - absoluteFileName.replace(" ", "_"); + QString absoluteFileName = caf::Utils::constructFullFileName(absSnapshotPath, fileName, ".png"); + absoluteFileName.replace(" ", "_"); - RicSnapshotViewToFileFeature::saveSnapshotAs(absoluteFileName, wellLogPlot); - } - } - } - - // Summary plots - { - std::vector summaryPlots; - proj->descendantsIncludingThisOfType(summaryPlots); - for (RimSummaryPlot* summaryPlot : summaryPlots) - { - if (summaryPlot && summaryPlot->viewWidget()) - { - QString fileName = summaryPlot->description(); - fileName = caf::Utils::makeValidFileBasename(fileName); - - QString absoluteFileName = caf::Utils::constructFullFileName(absSnapshotPath, fileName, ".png"); - absoluteFileName.replace(" ", "_"); - - RicSnapshotViewToFileFeature::saveSnapshotAs(absoluteFileName, summaryPlot); - } + RicSnapshotViewToFileFeature::saveSnapshotAs(absoluteFileName, viewWindow); } } } diff --git a/ApplicationCode/Commands/RicSnapshotViewToClipboardFeature.h b/ApplicationCode/Commands/RicSnapshotViewToClipboardFeature.h index cd61b161af..ede5e606fc 100644 --- a/ApplicationCode/Commands/RicSnapshotViewToClipboardFeature.h +++ b/ApplicationCode/Commands/RicSnapshotViewToClipboardFeature.h @@ -66,7 +66,7 @@ class RicSnapshotAllPlotsToFileFeature : public caf::CmdFeature public: static void saveAllPlots(); - static void createSnapshotOfAllPlotsInFolder(QString snapshotFolderName); + static void exportSnapshotOfAllPlotsIntoFolder(QString snapshotFolderName); protected: // Overrides diff --git a/ApplicationCode/ProjectDataModel/RimViewWindow.cpp b/ApplicationCode/ProjectDataModel/RimViewWindow.cpp index f72bb7aa9c..aa2941ffa3 100644 --- a/ApplicationCode/ProjectDataModel/RimViewWindow.cpp +++ b/ApplicationCode/ProjectDataModel/RimViewWindow.cpp @@ -90,6 +90,19 @@ void RimViewWindow::updateMdiWindowVisibility() } } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool RimViewWindow::isMdiWindow() const +{ + if (m_windowController()) + { + return true; + } + + return false; +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationCode/ProjectDataModel/RimViewWindow.h b/ApplicationCode/ProjectDataModel/RimViewWindow.h index 25921fae10..8466217c07 100644 --- a/ApplicationCode/ProjectDataModel/RimViewWindow.h +++ b/ApplicationCode/ProjectDataModel/RimViewWindow.h @@ -51,6 +51,7 @@ public: void setAs3DViewMdiWindow() { setAsMdiWindow(0); } void setAsPlotMdiWindow() { setAsMdiWindow(1); } + bool isMdiWindow() const; void setMdiWindowGeometry(const RimMdiWindowGeometry& windowGeometry); RimMdiWindowGeometry mdiWindowGeometry();