mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
#878 Command Line : Added support for snapshot of plots
This commit is contained in:
parent
2e8a411df8
commit
f14b4ab4d0
@ -1172,7 +1172,7 @@ bool RiaApplication::parseArguments()
|
|||||||
progOpt.registerOption("project", "<filename>", "Open project file <filename>.", cvf::ProgramOptions::SINGLE_VALUE);
|
progOpt.registerOption("project", "<filename>", "Open project file <filename>.", cvf::ProgramOptions::SINGLE_VALUE);
|
||||||
progOpt.registerOption("case", "<casename>", "Import Eclipse case <casename> (do not include the .GRID/.EGRID extension.)", cvf::ProgramOptions::MULTI_VALUE);
|
progOpt.registerOption("case", "<casename>", "Import Eclipse case <casename> (do not include the .GRID/.EGRID extension.)", cvf::ProgramOptions::MULTI_VALUE);
|
||||||
progOpt.registerOption("startdir", "<folder>", "Set startup directory.", cvf::ProgramOptions::SINGLE_VALUE);
|
progOpt.registerOption("startdir", "<folder>", "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", "<width> <height>", "Set size of the main application window.", cvf::ProgramOptions::MULTI_VALUE);
|
progOpt.registerOption("size", "<width> <height>", "Set size of the main application window.", cvf::ProgramOptions::MULTI_VALUE);
|
||||||
progOpt.registerOption("replaceCase", "[<caseId>] <newGridFile>", "Replace grid in <caseId> or first case with <newgridFile>.", cvf::ProgramOptions::MULTI_VALUE);
|
progOpt.registerOption("replaceCase", "[<caseId>] <newGridFile>", "Replace grid in <caseId> or first case with <newgridFile>.", cvf::ProgramOptions::MULTI_VALUE);
|
||||||
progOpt.registerOption("replaceSourceCases", "[<caseGroupId>] <gridListFile>", "Replace source cases in <caseGroupId> or first grid case group with the grid files listed in the <gridListFile> file.", cvf::ProgramOptions::MULTI_VALUE);
|
progOpt.registerOption("replaceSourceCases", "[<caseGroupId>] <gridListFile>", "Replace source cases in <caseGroupId> or first grid case group with the grid files listed in the <gridListFile> 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();
|
bool snapshotViews = false;
|
||||||
if (m_project.notNull() && !m_project->fileName().isEmpty() && mainWnd)
|
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
|
for (QString s : snapshotItemTexts)
|
||||||
saveSnapshotForAllViews("snapshots");
|
{
|
||||||
|
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();
|
closeProject();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1954,10 +2000,6 @@ void RiaApplication::saveSnapshotForAllViews(const QString& snapshotFolderName)
|
|||||||
RiuMainWindow* mainWnd = RiuMainWindow::instance();
|
RiuMainWindow* mainWnd = RiuMainWindow::instance();
|
||||||
if (!mainWnd) return;
|
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;
|
if (m_project.isNull()) return;
|
||||||
|
|
||||||
QDir snapshotPath(snapshotFolderName);
|
QDir snapshotPath(snapshotFolderName);
|
||||||
@ -2000,7 +2042,7 @@ void RiaApplication::saveSnapshotForAllViews(const QString& snapshotFolderName)
|
|||||||
|
|
||||||
QString absoluteFileName = caf::Utils::constructFullFileName(absSnapshotPath, fileName, ".png");
|
QString absoluteFileName = caf::Utils::constructFullFileName(absSnapshotPath, fileName, ".png");
|
||||||
|
|
||||||
RicSnapshotViewToFileFeature::saveSnapshotAs(absoluteFileName);
|
RicSnapshotViewToFileFeature::saveSnapshotAs(absoluteFileName, riv);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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)
|
if (viewWindow)
|
||||||
{
|
{
|
||||||
QImage image = viewWindow->snapshotWindowContent();
|
QImage image = viewWindow->snapshotWindowContent();
|
||||||
@ -144,7 +142,8 @@ void RicSnapshotViewToFileFeature::onActionTriggered(bool isChecked)
|
|||||||
// Remember the directory to next time
|
// Remember the directory to next time
|
||||||
app->setLastUsedDialogDirectory("IMAGE_SNAPSHOT", QFileInfo(fileName).absolutePath());
|
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()
|
void RicSnapshotAllPlotsToFileFeature::saveAllPlots()
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
|
||||||
///
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
|
||||||
void RicSnapshotAllPlotsToFileFeature::onActionTriggered(bool isChecked)
|
|
||||||
{
|
{
|
||||||
RiaApplication* app = RiaApplication::instance();
|
RiaApplication* app = RiaApplication::instance();
|
||||||
|
|
||||||
@ -195,13 +186,6 @@ void RicSnapshotAllPlotsToFileFeature::onActionTriggered(bool isChecked)
|
|||||||
|
|
||||||
const QString absSnapshotPath = snapshotPath.absolutePath();
|
const QString absSnapshotPath = snapshotPath.absolutePath();
|
||||||
|
|
||||||
|
|
||||||
QWidget* currentActiveWidget = nullptr;
|
|
||||||
if (RiaApplication::activeViewWindow())
|
|
||||||
{
|
|
||||||
currentActiveWidget = RiaApplication::activeViewWindow()->viewWidget();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Well log plots
|
// Well log plots
|
||||||
{
|
{
|
||||||
std::vector<RimWellLogPlot*> wellLogPlots;
|
std::vector<RimWellLogPlot*> wellLogPlots;
|
||||||
@ -210,14 +194,12 @@ void RicSnapshotAllPlotsToFileFeature::onActionTriggered(bool isChecked)
|
|||||||
{
|
{
|
||||||
if (wellLogPlot && wellLogPlot->viewWidget())
|
if (wellLogPlot && wellLogPlot->viewWidget())
|
||||||
{
|
{
|
||||||
mainPlotWindow->setActiveViewer(wellLogPlot->viewWidget());
|
|
||||||
|
|
||||||
QString fileName = wellLogPlot->description();
|
QString fileName = wellLogPlot->description();
|
||||||
fileName.replace(" ", "_");
|
fileName.replace(" ", "_");
|
||||||
|
|
||||||
QString absoluteFileName = caf::Utils::constructFullFileName(absSnapshotPath, fileName, ".png");
|
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())
|
if (summaryPlot && summaryPlot->viewWidget())
|
||||||
{
|
{
|
||||||
mainPlotWindow->setActiveViewer(summaryPlot->viewWidget());
|
|
||||||
|
|
||||||
QString fileName = summaryPlot->description();
|
QString fileName = summaryPlot->description();
|
||||||
fileName.replace(" ", "_");
|
fileName.replace(" ", "_");
|
||||||
|
|
||||||
QString absoluteFileName = caf::Utils::constructFullFileName(absSnapshotPath, fileName, ".png");
|
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)
|
if (currentActiveWidget)
|
||||||
{
|
{
|
||||||
mainPlotWindow->setActiveViewer(currentActiveWidget);
|
RiuMainPlotWindow* mainPlotWindow = RiaApplication::instance()->mainPlotWindow();
|
||||||
|
if (mainPlotWindow)
|
||||||
|
{
|
||||||
|
mainPlotWindow->setActiveViewer(currentActiveWidget);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
|
|
||||||
#include "cafCmdFeature.h"
|
#include "cafCmdFeature.h"
|
||||||
|
|
||||||
|
class RimViewWindow;
|
||||||
|
|
||||||
//==================================================================================================
|
//==================================================================================================
|
||||||
///
|
///
|
||||||
@ -45,7 +46,7 @@ class RicSnapshotViewToFileFeature : public caf::CmdFeature
|
|||||||
CAF_CMD_HEADER_INIT;
|
CAF_CMD_HEADER_INIT;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static void saveSnapshotAs(const QString& fileName);
|
static void saveSnapshotAs(const QString& fileName, RimViewWindow* viewWindow);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// Overrides
|
// Overrides
|
||||||
@ -62,6 +63,9 @@ class RicSnapshotAllPlotsToFileFeature : public caf::CmdFeature
|
|||||||
{
|
{
|
||||||
CAF_CMD_HEADER_INIT;
|
CAF_CMD_HEADER_INIT;
|
||||||
|
|
||||||
|
public:
|
||||||
|
static void saveAllPlots();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// Overrides
|
// Overrides
|
||||||
virtual bool isCommandEnabled() override;
|
virtual bool isCommandEnabled() override;
|
||||||
|
Loading…
Reference in New Issue
Block a user