diff --git a/ApplicationCode/Application/RiaApplication.cpp b/ApplicationCode/Application/RiaApplication.cpp index 0396cf71c3..bc89b6b656 100644 --- a/ApplicationCode/Application/RiaApplication.cpp +++ b/ApplicationCode/Application/RiaApplication.cpp @@ -1172,7 +1172,7 @@ bool RiaApplication::parseArguments() progOpt.registerOption("project", "", "Open project file .", cvf::ProgramOptions::SINGLE_VALUE); progOpt.registerOption("case", "", "Import Eclipse case (do not include the .GRID/.EGRID extension.)", cvf::ProgramOptions::MULTI_VALUE); progOpt.registerOption("startdir", "", "Set startup directory.", cvf::ProgramOptions::SINGLE_VALUE); - progOpt.registerOption("savesnapshots", "", "Save snapshot of all views to 'snapshots' folder. Application closes after snapshots have been written."); + progOpt.registerOption("savesnapshots", "all|views|plots", "Save snapshot of all views or plots to project file location sub folder 'snapshots'. Option 'all' will include both views and plots. Application closes after snapshots have been written.", cvf::ProgramOptions::OPTIONAL_MULTI_VALUE); progOpt.registerOption("size", " ", "Set size of the main application window.", cvf::ProgramOptions::MULTI_VALUE); progOpt.registerOption("replaceCase", "[] ", "Replace grid in or first case with .", cvf::ProgramOptions::MULTI_VALUE); progOpt.registerOption("replaceSourceCases", "[] ", "Replace source cases in or first grid case group with the grid files listed in the file.", cvf::ProgramOptions::MULTI_VALUE); @@ -1345,18 +1345,64 @@ bool RiaApplication::parseArguments() } - if (progOpt.hasOption("savesnapshots")) + if (cvf::Option o = progOpt.option("savesnapshots")) { - RiuMainWindow* mainWnd = RiuMainWindow::instance(); - if (m_project.notNull() && !m_project->fileName().isEmpty() && mainWnd) + bool snapshotViews = false; + bool snapshotPlots = false; + + QStringList snapshotItemTexts = cvfqt::Utils::toQStringList(o.values()); + if (snapshotItemTexts.size() == 0) { - mainWnd->hideAllDockWindows(); + // No options will keep backwards compability before we introduced snapshot of plots + snapshotViews = true; + } - // Will be saved relative to current directory - saveSnapshotForAllViews("snapshots"); + for (QString s : snapshotItemTexts) + { + if (s.toLower() == "all") + { + snapshotViews = true; + snapshotPlots = true; + } + else if (s.toLower() == "views") + { + snapshotViews = true; + } + else if (s.toLower() == "plots") + { + snapshotPlots = true; + } + } - mainWnd->loadWinGeoAndDockToolBarLayout(); + if (m_project.notNull() && !m_project->fileName().isEmpty()) + { + if (snapshotViews) + { + RiuMainWindow* mainWnd = RiuMainWindow::instance(); + CVF_ASSERT(mainWnd); + mainWnd->hideAllDockWindows(); + // 2016-11-09 : Location of snapshot folder was previously located in 'snapshot' folder + // relative to current working folder. Now harmonized to behave as RiuMainWindow::slotSnapshotAllViewsToFile() + QString absolutePathToSnapshotDir = createAbsolutePathFromProjectRelativePath("snapshots"); + saveSnapshotForAllViews(absolutePathToSnapshotDir); + + mainWnd->loadWinGeoAndDockToolBarLayout(); + } + + if (snapshotPlots) + { + if (m_mainPlotWindow) + { + m_mainPlotWindow->hideAllDockWindows(); + + // Will be saved relative to current directory + RicSnapshotAllPlotsToFileFeature::saveAllPlots(); + + m_mainPlotWindow->loadWinGeoAndDockToolBarLayout(); + } + } + closeProject(); } @@ -1954,10 +2000,6 @@ void RiaApplication::saveSnapshotForAllViews(const QString& snapshotFolderName) RiuMainWindow* mainWnd = RiuMainWindow::instance(); if (!mainWnd) return; - // Activate RiuMainWindow to make sure there is an active main window used from snapshot code in - // RicSnapshotViewToFileFeature::saveSnapshotAs() - QApplication::setActiveWindow(mainWnd); - if (m_project.isNull()) return; QDir snapshotPath(snapshotFolderName); @@ -2000,7 +2042,7 @@ void RiaApplication::saveSnapshotForAllViews(const QString& snapshotFolderName) QString absoluteFileName = caf::Utils::constructFullFileName(absSnapshotPath, fileName, ".png"); - RicSnapshotViewToFileFeature::saveSnapshotAs(absoluteFileName); + RicSnapshotViewToFileFeature::saveSnapshotAs(absoluteFileName, riv); } } } diff --git a/ApplicationCode/Commands/RicSnapshotViewToClipboardFeature.cpp b/ApplicationCode/Commands/RicSnapshotViewToClipboardFeature.cpp index 7c17b428b9..6db549a04c 100644 --- a/ApplicationCode/Commands/RicSnapshotViewToClipboardFeature.cpp +++ b/ApplicationCode/Commands/RicSnapshotViewToClipboardFeature.cpp @@ -85,10 +85,8 @@ CAF_CMD_SOURCE_INIT(RicSnapshotViewToFileFeature, "RicSnapshotViewToFileFeature" //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -void RicSnapshotViewToFileFeature::saveSnapshotAs(const QString& fileName) +void RicSnapshotViewToFileFeature::saveSnapshotAs(const QString& fileName, RimViewWindow* viewWindow) { - RimViewWindow* viewWindow = RiaApplication::activeViewWindow(); - if (viewWindow) { QImage image = viewWindow->snapshotWindowContent(); @@ -144,7 +142,8 @@ void RicSnapshotViewToFileFeature::onActionTriggered(bool isChecked) // Remember the directory to next time app->setLastUsedDialogDirectory("IMAGE_SNAPSHOT", QFileInfo(fileName).absolutePath()); - RicSnapshotViewToFileFeature::saveSnapshotAs(fileName); + RimViewWindow* viewWindow = app->activeViewWindow(); + RicSnapshotViewToFileFeature::saveSnapshotAs(fileName, viewWindow); } //-------------------------------------------------------------------------------------------------- @@ -166,15 +165,7 @@ CAF_CMD_SOURCE_INIT(RicSnapshotAllPlotsToFileFeature, "RicSnapshotAllPlotsToFile //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -bool RicSnapshotAllPlotsToFileFeature::isCommandEnabled() -{ - return true; -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -void RicSnapshotAllPlotsToFileFeature::onActionTriggered(bool isChecked) +void RicSnapshotAllPlotsToFileFeature::saveAllPlots() { RiaApplication* app = RiaApplication::instance(); @@ -195,13 +186,6 @@ void RicSnapshotAllPlotsToFileFeature::onActionTriggered(bool isChecked) const QString absSnapshotPath = snapshotPath.absolutePath(); - - QWidget* currentActiveWidget = nullptr; - if (RiaApplication::activeViewWindow()) - { - currentActiveWidget = RiaApplication::activeViewWindow()->viewWidget(); - } - // Well log plots { std::vector wellLogPlots; @@ -210,14 +194,12 @@ void RicSnapshotAllPlotsToFileFeature::onActionTriggered(bool isChecked) { if (wellLogPlot && wellLogPlot->viewWidget()) { - mainPlotWindow->setActiveViewer(wellLogPlot->viewWidget()); - QString fileName = wellLogPlot->description(); fileName.replace(" ", "_"); QString absoluteFileName = caf::Utils::constructFullFileName(absSnapshotPath, fileName, ".png"); - RicSnapshotViewToFileFeature::saveSnapshotAs(absoluteFileName); + RicSnapshotViewToFileFeature::saveSnapshotAs(absoluteFileName, wellLogPlot); } } } @@ -230,21 +212,45 @@ void RicSnapshotAllPlotsToFileFeature::onActionTriggered(bool isChecked) { if (summaryPlot && summaryPlot->viewWidget()) { - mainPlotWindow->setActiveViewer(summaryPlot->viewWidget()); - QString fileName = summaryPlot->description(); fileName.replace(" ", "_"); QString absoluteFileName = caf::Utils::constructFullFileName(absSnapshotPath, fileName, ".png"); - RicSnapshotViewToFileFeature::saveSnapshotAs(absoluteFileName); + RicSnapshotViewToFileFeature::saveSnapshotAs(absoluteFileName, summaryPlot); } } } +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool RicSnapshotAllPlotsToFileFeature::isCommandEnabled() +{ + return true; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RicSnapshotAllPlotsToFileFeature::onActionTriggered(bool isChecked) +{ + QWidget* currentActiveWidget = nullptr; + if (RiaApplication::activeViewWindow()) + { + currentActiveWidget = RiaApplication::activeViewWindow()->viewWidget(); + } + + RicSnapshotAllPlotsToFileFeature::saveAllPlots(); if (currentActiveWidget) { - mainPlotWindow->setActiveViewer(currentActiveWidget); + RiuMainPlotWindow* mainPlotWindow = RiaApplication::instance()->mainPlotWindow(); + if (mainPlotWindow) + { + mainPlotWindow->setActiveViewer(currentActiveWidget); + } } } diff --git a/ApplicationCode/Commands/RicSnapshotViewToClipboardFeature.h b/ApplicationCode/Commands/RicSnapshotViewToClipboardFeature.h index a95aa61f0f..2112d4e19f 100644 --- a/ApplicationCode/Commands/RicSnapshotViewToClipboardFeature.h +++ b/ApplicationCode/Commands/RicSnapshotViewToClipboardFeature.h @@ -20,6 +20,7 @@ #include "cafCmdFeature.h" +class RimViewWindow; //================================================================================================== /// @@ -45,7 +46,7 @@ class RicSnapshotViewToFileFeature : public caf::CmdFeature CAF_CMD_HEADER_INIT; public: - static void saveSnapshotAs(const QString& fileName); + static void saveSnapshotAs(const QString& fileName, RimViewWindow* viewWindow); protected: // Overrides @@ -62,6 +63,9 @@ class RicSnapshotAllPlotsToFileFeature : public caf::CmdFeature { CAF_CMD_HEADER_INIT; +public: + static void saveAllPlots(); + protected: // Overrides virtual bool isCommandEnabled() override;