mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
#1730 Move snapshot features to separate files
This commit is contained in:
@@ -88,7 +88,8 @@
|
|||||||
#include "RiuFlowCharacteristicsPlot.h"
|
#include "RiuFlowCharacteristicsPlot.h"
|
||||||
|
|
||||||
#include "RicImportSummaryCaseFeature.h"
|
#include "RicImportSummaryCaseFeature.h"
|
||||||
#include "ExportCommands/RicSnapshotViewToClipboardFeature.h"
|
#include "ExportCommands/RicSnapshotViewToFileFeature.h"
|
||||||
|
#include "ExportCommands/RicSnapshotAllPlotsToFileFeature.h"
|
||||||
#include "SummaryPlotCommands/RicNewSummaryPlotFeature.h"
|
#include "SummaryPlotCommands/RicNewSummaryPlotFeature.h"
|
||||||
|
|
||||||
#include "RicfCommandFileExecutor.h"
|
#include "RicfCommandFileExecutor.h"
|
||||||
|
|||||||
@@ -20,7 +20,7 @@
|
|||||||
|
|
||||||
#include "RicfCommandFileExecutor.h"
|
#include "RicfCommandFileExecutor.h"
|
||||||
|
|
||||||
#include "ExportCommands/RicSnapshotViewToClipboardFeature.h"
|
#include "ExportCommands/RicSnapshotAllPlotsToFileFeature.h"
|
||||||
|
|
||||||
#include "RiaApplication.h"
|
#include "RiaApplication.h"
|
||||||
|
|
||||||
|
|||||||
@@ -5,31 +5,35 @@ if (${CMAKE_VERSION} VERSION_GREATER "2.8.2")
|
|||||||
endif()
|
endif()
|
||||||
|
|
||||||
set (SOURCE_GROUP_HEADER_FILES
|
set (SOURCE_GROUP_HEADER_FILES
|
||||||
|
${CEE_CURRENT_LIST_DIR}RicCellRangeUi.h
|
||||||
${CEE_CURRENT_LIST_DIR}RicExportCarfin.h
|
${CEE_CURRENT_LIST_DIR}RicExportCarfin.h
|
||||||
${CEE_CURRENT_LIST_DIR}RicExportCarfinUi.h
|
${CEE_CURRENT_LIST_DIR}RicExportCarfinUi.h
|
||||||
${CEE_CURRENT_LIST_DIR}RicExportToLasFileFeature.h
|
|
||||||
${CEE_CURRENT_LIST_DIR}RicExportToLasFileResampleUi.h
|
|
||||||
${CEE_CURRENT_LIST_DIR}RicSnapshotViewToClipboardFeature.h
|
|
||||||
${CEE_CURRENT_LIST_DIR}RicExportFaultsFeature.h
|
${CEE_CURRENT_LIST_DIR}RicExportFaultsFeature.h
|
||||||
${CEE_CURRENT_LIST_DIR}RicExportMultipleSnapshotsFeature.h
|
${CEE_CURRENT_LIST_DIR}RicExportMultipleSnapshotsFeature.h
|
||||||
|
${CEE_CURRENT_LIST_DIR}RicExportToLasFileFeature.h
|
||||||
|
${CEE_CURRENT_LIST_DIR}RicExportToLasFileResampleUi.h
|
||||||
${CEE_CURRENT_LIST_DIR}RicSaveEclipseInputPropertyFeature.h
|
${CEE_CURRENT_LIST_DIR}RicSaveEclipseInputPropertyFeature.h
|
||||||
${CEE_CURRENT_LIST_DIR}RicSaveEclipseResultAsInputPropertyExec.h
|
${CEE_CURRENT_LIST_DIR}RicSaveEclipseResultAsInputPropertyExec.h
|
||||||
${CEE_CURRENT_LIST_DIR}RicSaveEclipseResultAsInputPropertyFeature.h
|
${CEE_CURRENT_LIST_DIR}RicSaveEclipseResultAsInputPropertyFeature.h
|
||||||
${CEE_CURRENT_LIST_DIR}RicCellRangeUi.h
|
${CEE_CURRENT_LIST_DIR}RicSnapshotAllPlotsToFileFeature.h
|
||||||
|
${CEE_CURRENT_LIST_DIR}RicSnapshotViewToClipboardFeature.h
|
||||||
|
${CEE_CURRENT_LIST_DIR}RicSnapshotViewToFileFeature.h
|
||||||
)
|
)
|
||||||
|
|
||||||
set (SOURCE_GROUP_SOURCE_FILES
|
set (SOURCE_GROUP_SOURCE_FILES
|
||||||
|
${CEE_CURRENT_LIST_DIR}RicCellRangeUi.cpp
|
||||||
${CEE_CURRENT_LIST_DIR}RicExportCarfin.cpp
|
${CEE_CURRENT_LIST_DIR}RicExportCarfin.cpp
|
||||||
${CEE_CURRENT_LIST_DIR}RicExportCarfinUi.cpp
|
${CEE_CURRENT_LIST_DIR}RicExportCarfinUi.cpp
|
||||||
${CEE_CURRENT_LIST_DIR}RicExportToLasFileFeature.cpp
|
|
||||||
${CEE_CURRENT_LIST_DIR}RicExportToLasFileResampleUi.cpp
|
|
||||||
${CEE_CURRENT_LIST_DIR}RicSnapshotViewToClipboardFeature.cpp
|
|
||||||
${CEE_CURRENT_LIST_DIR}RicExportFaultsFeature.cpp
|
${CEE_CURRENT_LIST_DIR}RicExportFaultsFeature.cpp
|
||||||
${CEE_CURRENT_LIST_DIR}RicExportMultipleSnapshotsFeature.cpp
|
${CEE_CURRENT_LIST_DIR}RicExportMultipleSnapshotsFeature.cpp
|
||||||
|
${CEE_CURRENT_LIST_DIR}RicExportToLasFileFeature.cpp
|
||||||
|
${CEE_CURRENT_LIST_DIR}RicExportToLasFileResampleUi.cpp
|
||||||
${CEE_CURRENT_LIST_DIR}RicSaveEclipseInputPropertyFeature.cpp
|
${CEE_CURRENT_LIST_DIR}RicSaveEclipseInputPropertyFeature.cpp
|
||||||
${CEE_CURRENT_LIST_DIR}RicSaveEclipseResultAsInputPropertyExec.cpp
|
${CEE_CURRENT_LIST_DIR}RicSaveEclipseResultAsInputPropertyExec.cpp
|
||||||
${CEE_CURRENT_LIST_DIR}RicSaveEclipseResultAsInputPropertyFeature.cpp
|
${CEE_CURRENT_LIST_DIR}RicSaveEclipseResultAsInputPropertyFeature.cpp
|
||||||
${CEE_CURRENT_LIST_DIR}RicCellRangeUi.cpp
|
${CEE_CURRENT_LIST_DIR}RicSnapshotAllPlotsToFileFeature.cpp
|
||||||
|
${CEE_CURRENT_LIST_DIR}RicSnapshotViewToClipboardFeature.cpp
|
||||||
|
${CEE_CURRENT_LIST_DIR}RicSnapshotViewToFileFeature.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
list(APPEND CODE_HEADER_FILES
|
list(APPEND CODE_HEADER_FILES
|
||||||
|
|||||||
@@ -20,7 +20,7 @@
|
|||||||
|
|
||||||
#include "RiaApplication.h"
|
#include "RiaApplication.h"
|
||||||
|
|
||||||
#include "RicSnapshotViewToClipboardFeature.h"
|
#include "RicSnapshotViewToFileFeature.h"
|
||||||
|
|
||||||
#include "RigFemResultPosEnum.h"
|
#include "RigFemResultPosEnum.h"
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,152 @@
|
|||||||
|
/////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// Copyright (C) 2016 Statoil ASA
|
||||||
|
//
|
||||||
|
// ResInsight 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.
|
||||||
|
//
|
||||||
|
// ResInsight 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 at <http://www.gnu.org/licenses/gpl.html>
|
||||||
|
// for more details.
|
||||||
|
//
|
||||||
|
/////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
#include "RicSnapshotAllPlotsToFileFeature.h"
|
||||||
|
|
||||||
|
#include "RiaApplication.h"
|
||||||
|
#include "RiaLogging.h"
|
||||||
|
|
||||||
|
#include "RimMainPlotCollection.h"
|
||||||
|
#include "RimProject.h"
|
||||||
|
#include "RimViewWindow.h"
|
||||||
|
|
||||||
|
#include "RicSnapshotViewToFileFeature.h"
|
||||||
|
|
||||||
|
#include "RiuMainPlotWindow.h"
|
||||||
|
|
||||||
|
#include "cafUtils.h"
|
||||||
|
|
||||||
|
#include <QAction>
|
||||||
|
#include <QClipboard>
|
||||||
|
#include <QDebug>
|
||||||
|
#include <QFileDialog>
|
||||||
|
#include <QFileInfo>
|
||||||
|
#include <QMdiSubWindow>
|
||||||
|
#include <QMessageBox>
|
||||||
|
|
||||||
|
|
||||||
|
CAF_CMD_SOURCE_INIT(RicSnapshotAllPlotsToFileFeature, "RicSnapshotAllPlotsToFileFeature");
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
void RicSnapshotAllPlotsToFileFeature::saveAllPlots()
|
||||||
|
{
|
||||||
|
RiaApplication* app = RiaApplication::instance();
|
||||||
|
|
||||||
|
RiuMainPlotWindow* mainPlotWindow = app->mainPlotWindow();
|
||||||
|
if (!mainPlotWindow) return;
|
||||||
|
|
||||||
|
RimProject* proj = app->project();
|
||||||
|
if (!proj) return;
|
||||||
|
|
||||||
|
// Save images in snapshot catalog relative to project directory
|
||||||
|
QString snapshotFolderName = app->createAbsolutePathFromProjectRelativePath("snapshots");
|
||||||
|
|
||||||
|
exportSnapshotOfAllPlotsIntoFolder(snapshotFolderName);
|
||||||
|
|
||||||
|
QString text = QString("Exported snapshots to folder : \n%1").arg(snapshotFolderName);
|
||||||
|
QMessageBox::information(nullptr, "Export Snapshots To Folder", text);
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
void RicSnapshotAllPlotsToFileFeature::exportSnapshotOfAllPlotsIntoFolder(QString snapshotFolderName)
|
||||||
|
{
|
||||||
|
RiaApplication* app = RiaApplication::instance();
|
||||||
|
|
||||||
|
RimProject* proj = app->project();
|
||||||
|
if (!proj) return;
|
||||||
|
|
||||||
|
QDir snapshotPath(snapshotFolderName);
|
||||||
|
if (!snapshotPath.exists())
|
||||||
|
{
|
||||||
|
if (!snapshotPath.mkpath(".")) return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const QString absSnapshotPath = snapshotPath.absolutePath();
|
||||||
|
|
||||||
|
std::vector<RimViewWindow*> viewWindows;
|
||||||
|
proj->mainPlotCollection()->descendantsIncludingThisOfType(viewWindows);
|
||||||
|
|
||||||
|
for (auto viewWindow : viewWindows)
|
||||||
|
{
|
||||||
|
if (viewWindow->isMdiWindow() && viewWindow->viewWidget())
|
||||||
|
{
|
||||||
|
QString fileName;
|
||||||
|
if ( viewWindow->userDescriptionField())
|
||||||
|
{
|
||||||
|
fileName = viewWindow->userDescriptionField()->uiCapability()->uiValue().toString();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
fileName = viewWindow->uiCapability()->uiName();
|
||||||
|
}
|
||||||
|
|
||||||
|
fileName = caf::Utils::makeValidFileBasename(fileName);
|
||||||
|
|
||||||
|
QString absoluteFileName = caf::Utils::constructFullFileName(absSnapshotPath, fileName, ".png");
|
||||||
|
absoluteFileName.replace(" ", "_");
|
||||||
|
|
||||||
|
RicSnapshotViewToFileFeature::saveSnapshotAs(absoluteFileName, viewWindow);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
bool RicSnapshotAllPlotsToFileFeature::isCommandEnabled()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
void RicSnapshotAllPlotsToFileFeature::onActionTriggered(bool isChecked)
|
||||||
|
{
|
||||||
|
QWidget* currentActiveWidget = nullptr;
|
||||||
|
if (RiaApplication::activeViewWindow())
|
||||||
|
{
|
||||||
|
currentActiveWidget = RiaApplication::activeViewWindow()->viewWidget();
|
||||||
|
}
|
||||||
|
|
||||||
|
RicSnapshotAllPlotsToFileFeature::saveAllPlots();
|
||||||
|
|
||||||
|
if (currentActiveWidget)
|
||||||
|
{
|
||||||
|
RiuMainPlotWindow* mainPlotWindow = RiaApplication::instance()->mainPlotWindow();
|
||||||
|
if (mainPlotWindow)
|
||||||
|
{
|
||||||
|
mainPlotWindow->setActiveViewer(currentActiveWidget);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
void RicSnapshotAllPlotsToFileFeature::setupActionLook(QAction* actionToSetup)
|
||||||
|
{
|
||||||
|
actionToSetup->setText("Snapshot All Plots To File");
|
||||||
|
actionToSetup->setIcon(QIcon(":/SnapShotSaveViews.png"));
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
/////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// Copyright (C) 2016 Statoil ASA
|
||||||
|
//
|
||||||
|
// ResInsight 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.
|
||||||
|
//
|
||||||
|
// ResInsight 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 at <http://www.gnu.org/licenses/gpl.html>
|
||||||
|
// for more details.
|
||||||
|
//
|
||||||
|
/////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "cafCmdFeature.h"
|
||||||
|
|
||||||
|
class RimViewWindow;
|
||||||
|
|
||||||
|
//==================================================================================================
|
||||||
|
///
|
||||||
|
//==================================================================================================
|
||||||
|
class RicSnapshotAllPlotsToFileFeature : public caf::CmdFeature
|
||||||
|
{
|
||||||
|
CAF_CMD_HEADER_INIT;
|
||||||
|
|
||||||
|
public:
|
||||||
|
static void saveAllPlots();
|
||||||
|
|
||||||
|
static void exportSnapshotOfAllPlotsIntoFolder(QString snapshotFolderName);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
// Overrides
|
||||||
|
virtual bool isCommandEnabled() override;
|
||||||
|
virtual void onActionTriggered(bool isChecked) override;
|
||||||
|
virtual void setupActionLook(QAction* actionToSetup) override;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -78,206 +78,3 @@ void RicSnapshotViewToClipboardFeature::setupActionLook(QAction* actionToSetup)
|
|||||||
actionToSetup->setText("Snapshot To Clipboard");
|
actionToSetup->setText("Snapshot To Clipboard");
|
||||||
actionToSetup->setIcon(QIcon(":/SnapShot.png"));
|
actionToSetup->setIcon(QIcon(":/SnapShot.png"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
CAF_CMD_SOURCE_INIT(RicSnapshotViewToFileFeature, "RicSnapshotViewToFileFeature");
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
|
||||||
///
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
|
||||||
void RicSnapshotViewToFileFeature::saveSnapshotAs(const QString& fileName, RimViewWindow* viewWindow)
|
|
||||||
{
|
|
||||||
if (viewWindow)
|
|
||||||
{
|
|
||||||
QImage image = viewWindow->snapshotWindowContent();
|
|
||||||
if (!image.isNull())
|
|
||||||
{
|
|
||||||
if (image.save(fileName))
|
|
||||||
{
|
|
||||||
qDebug() << "Exported snapshot image to " << fileName;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
qDebug() << "Error when trying to export snapshot image to " << fileName;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
|
||||||
///
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
|
||||||
bool RicSnapshotViewToFileFeature::isCommandEnabled()
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
|
||||||
///
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
|
||||||
void RicSnapshotViewToFileFeature::onActionTriggered(bool isChecked)
|
|
||||||
{
|
|
||||||
RiaApplication* app = RiaApplication::instance();
|
|
||||||
RimProject* proj = app->project();
|
|
||||||
|
|
||||||
// Get active view window before displaying the file selection dialog
|
|
||||||
// If this is done after the file save dialog is displayed (and closed)
|
|
||||||
// app->activeViewWindow() returns NULL on Linux
|
|
||||||
RimViewWindow* viewWindow = app->activeViewWindow();
|
|
||||||
if (!viewWindow)
|
|
||||||
{
|
|
||||||
RiaLogging::error("No view window is available, nothing to do");
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
QString startPath;
|
|
||||||
if (!proj->fileName().isEmpty())
|
|
||||||
{
|
|
||||||
QFileInfo fi(proj->fileName());
|
|
||||||
startPath = fi.absolutePath();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
startPath = app->lastUsedDialogDirectory("IMAGE_SNAPSHOT");
|
|
||||||
}
|
|
||||||
|
|
||||||
startPath += "/image.png";
|
|
||||||
|
|
||||||
QString fileName = QFileDialog::getSaveFileName(NULL, tr("Export to File"), startPath);
|
|
||||||
if (fileName.isEmpty())
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Remember the directory to next time
|
|
||||||
app->setLastUsedDialogDirectory("IMAGE_SNAPSHOT", QFileInfo(fileName).absolutePath());
|
|
||||||
|
|
||||||
RicSnapshotViewToFileFeature::saveSnapshotAs(fileName, viewWindow);
|
|
||||||
}
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
|
||||||
///
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
|
||||||
void RicSnapshotViewToFileFeature::setupActionLook(QAction* actionToSetup)
|
|
||||||
{
|
|
||||||
actionToSetup->setText("Snapshot To File");
|
|
||||||
actionToSetup->setIcon(QIcon(":/SnapShotSave.png"));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
CAF_CMD_SOURCE_INIT(RicSnapshotAllPlotsToFileFeature, "RicSnapshotAllPlotsToFileFeature");
|
|
||||||
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
|
||||||
///
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
|
||||||
void RicSnapshotAllPlotsToFileFeature::saveAllPlots()
|
|
||||||
{
|
|
||||||
RiaApplication* app = RiaApplication::instance();
|
|
||||||
|
|
||||||
RiuMainPlotWindow* mainPlotWindow = app->mainPlotWindow();
|
|
||||||
if (!mainPlotWindow) return;
|
|
||||||
|
|
||||||
RimProject* proj = app->project();
|
|
||||||
if (!proj) return;
|
|
||||||
|
|
||||||
// Save images in snapshot catalog relative to project directory
|
|
||||||
QString snapshotFolderName = app->createAbsolutePathFromProjectRelativePath("snapshots");
|
|
||||||
|
|
||||||
exportSnapshotOfAllPlotsIntoFolder(snapshotFolderName);
|
|
||||||
|
|
||||||
QString text = QString("Exported snapshots to folder : \n%1").arg(snapshotFolderName);
|
|
||||||
QMessageBox::information(nullptr, "Export Snapshots To Folder", text);
|
|
||||||
}
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
|
||||||
///
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
|
||||||
void RicSnapshotAllPlotsToFileFeature::exportSnapshotOfAllPlotsIntoFolder(QString snapshotFolderName)
|
|
||||||
{
|
|
||||||
RiaApplication* app = RiaApplication::instance();
|
|
||||||
|
|
||||||
RimProject* proj = app->project();
|
|
||||||
if (!proj) return;
|
|
||||||
|
|
||||||
QDir snapshotPath(snapshotFolderName);
|
|
||||||
if (!snapshotPath.exists())
|
|
||||||
{
|
|
||||||
if (!snapshotPath.mkpath(".")) return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const QString absSnapshotPath = snapshotPath.absolutePath();
|
|
||||||
|
|
||||||
std::vector<RimViewWindow*> viewWindows;
|
|
||||||
proj->mainPlotCollection()->descendantsIncludingThisOfType(viewWindows);
|
|
||||||
|
|
||||||
for (auto viewWindow : viewWindows)
|
|
||||||
{
|
|
||||||
if (viewWindow->isMdiWindow() && viewWindow->viewWidget())
|
|
||||||
{
|
|
||||||
QString fileName;
|
|
||||||
if ( viewWindow->userDescriptionField())
|
|
||||||
{
|
|
||||||
fileName = viewWindow->userDescriptionField()->uiCapability()->uiValue().toString();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
fileName = viewWindow->uiCapability()->uiName();
|
|
||||||
}
|
|
||||||
|
|
||||||
fileName = caf::Utils::makeValidFileBasename(fileName);
|
|
||||||
|
|
||||||
QString absoluteFileName = caf::Utils::constructFullFileName(absSnapshotPath, fileName, ".png");
|
|
||||||
absoluteFileName.replace(" ", "_");
|
|
||||||
|
|
||||||
RicSnapshotViewToFileFeature::saveSnapshotAs(absoluteFileName, viewWindow);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
|
||||||
///
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
|
||||||
bool RicSnapshotAllPlotsToFileFeature::isCommandEnabled()
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
|
||||||
///
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
|
||||||
void RicSnapshotAllPlotsToFileFeature::onActionTriggered(bool isChecked)
|
|
||||||
{
|
|
||||||
QWidget* currentActiveWidget = nullptr;
|
|
||||||
if (RiaApplication::activeViewWindow())
|
|
||||||
{
|
|
||||||
currentActiveWidget = RiaApplication::activeViewWindow()->viewWidget();
|
|
||||||
}
|
|
||||||
|
|
||||||
RicSnapshotAllPlotsToFileFeature::saveAllPlots();
|
|
||||||
|
|
||||||
if (currentActiveWidget)
|
|
||||||
{
|
|
||||||
RiuMainPlotWindow* mainPlotWindow = RiaApplication::instance()->mainPlotWindow();
|
|
||||||
if (mainPlotWindow)
|
|
||||||
{
|
|
||||||
mainPlotWindow->setActiveViewer(currentActiveWidget);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
|
||||||
///
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
|
||||||
void RicSnapshotAllPlotsToFileFeature::setupActionLook(QAction* actionToSetup)
|
|
||||||
{
|
|
||||||
actionToSetup->setText("Snapshot All Plots To File");
|
|
||||||
actionToSetup->setIcon(QIcon(":/SnapShotSaveViews.png"));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|||||||
@@ -37,42 +37,3 @@ protected:
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
//==================================================================================================
|
|
||||||
///
|
|
||||||
//==================================================================================================
|
|
||||||
class RicSnapshotViewToFileFeature : public caf::CmdFeature
|
|
||||||
{
|
|
||||||
CAF_CMD_HEADER_INIT;
|
|
||||||
|
|
||||||
public:
|
|
||||||
static void saveSnapshotAs(const QString& fileName, RimViewWindow* viewWindow);
|
|
||||||
|
|
||||||
protected:
|
|
||||||
// Overrides
|
|
||||||
virtual bool isCommandEnabled() override;
|
|
||||||
virtual void onActionTriggered(bool isChecked) override;
|
|
||||||
virtual void setupActionLook(QAction* actionToSetup) override;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
//==================================================================================================
|
|
||||||
///
|
|
||||||
//==================================================================================================
|
|
||||||
class RicSnapshotAllPlotsToFileFeature : public caf::CmdFeature
|
|
||||||
{
|
|
||||||
CAF_CMD_HEADER_INIT;
|
|
||||||
|
|
||||||
public:
|
|
||||||
static void saveAllPlots();
|
|
||||||
|
|
||||||
static void exportSnapshotOfAllPlotsIntoFolder(QString snapshotFolderName);
|
|
||||||
|
|
||||||
protected:
|
|
||||||
// Overrides
|
|
||||||
virtual bool isCommandEnabled() override;
|
|
||||||
virtual void onActionTriggered(bool isChecked) override;
|
|
||||||
virtual void setupActionLook(QAction* actionToSetup) override;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,123 @@
|
|||||||
|
/////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// Copyright (C) 2016 Statoil ASA
|
||||||
|
//
|
||||||
|
// ResInsight 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.
|
||||||
|
//
|
||||||
|
// ResInsight 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 at <http://www.gnu.org/licenses/gpl.html>
|
||||||
|
// for more details.
|
||||||
|
//
|
||||||
|
/////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
#include "RicSnapshotViewToFileFeature.h"
|
||||||
|
|
||||||
|
#include "RiaApplication.h"
|
||||||
|
#include "RiaLogging.h"
|
||||||
|
|
||||||
|
#include "RimMainPlotCollection.h"
|
||||||
|
#include "RimProject.h"
|
||||||
|
#include "RimViewWindow.h"
|
||||||
|
#include "RiuMainPlotWindow.h"
|
||||||
|
|
||||||
|
#include "cafUtils.h"
|
||||||
|
|
||||||
|
#include <QAction>
|
||||||
|
#include <QClipboard>
|
||||||
|
#include <QDebug>
|
||||||
|
#include <QFileDialog>
|
||||||
|
#include <QFileInfo>
|
||||||
|
#include <QMdiSubWindow>
|
||||||
|
#include <QMessageBox>
|
||||||
|
|
||||||
|
|
||||||
|
CAF_CMD_SOURCE_INIT(RicSnapshotViewToFileFeature, "RicSnapshotViewToFileFeature");
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
void RicSnapshotViewToFileFeature::saveSnapshotAs(const QString& fileName, RimViewWindow* viewWindow)
|
||||||
|
{
|
||||||
|
if (viewWindow)
|
||||||
|
{
|
||||||
|
QImage image = viewWindow->snapshotWindowContent();
|
||||||
|
if (!image.isNull())
|
||||||
|
{
|
||||||
|
if (image.save(fileName))
|
||||||
|
{
|
||||||
|
qDebug() << "Exported snapshot image to " << fileName;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
qDebug() << "Error when trying to export snapshot image to " << fileName;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
bool RicSnapshotViewToFileFeature::isCommandEnabled()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
void RicSnapshotViewToFileFeature::onActionTriggered(bool isChecked)
|
||||||
|
{
|
||||||
|
RiaApplication* app = RiaApplication::instance();
|
||||||
|
RimProject* proj = app->project();
|
||||||
|
|
||||||
|
// Get active view window before displaying the file selection dialog
|
||||||
|
// If this is done after the file save dialog is displayed (and closed)
|
||||||
|
// app->activeViewWindow() returns NULL on Linux
|
||||||
|
RimViewWindow* viewWindow = app->activeViewWindow();
|
||||||
|
if (!viewWindow)
|
||||||
|
{
|
||||||
|
RiaLogging::error("No view window is available, nothing to do");
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString startPath;
|
||||||
|
if (!proj->fileName().isEmpty())
|
||||||
|
{
|
||||||
|
QFileInfo fi(proj->fileName());
|
||||||
|
startPath = fi.absolutePath();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
startPath = app->lastUsedDialogDirectory("IMAGE_SNAPSHOT");
|
||||||
|
}
|
||||||
|
|
||||||
|
startPath += "/image.png";
|
||||||
|
|
||||||
|
QString fileName = QFileDialog::getSaveFileName(NULL, tr("Export to File"), startPath);
|
||||||
|
if (fileName.isEmpty())
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remember the directory to next time
|
||||||
|
app->setLastUsedDialogDirectory("IMAGE_SNAPSHOT", QFileInfo(fileName).absolutePath());
|
||||||
|
|
||||||
|
RicSnapshotViewToFileFeature::saveSnapshotAs(fileName, viewWindow);
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
void RicSnapshotViewToFileFeature::setupActionLook(QAction* actionToSetup)
|
||||||
|
{
|
||||||
|
actionToSetup->setText("Snapshot To File");
|
||||||
|
actionToSetup->setIcon(QIcon(":/SnapShotSave.png"));
|
||||||
|
}
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
/////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// Copyright (C) 2016 Statoil ASA
|
||||||
|
//
|
||||||
|
// ResInsight 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.
|
||||||
|
//
|
||||||
|
// ResInsight 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 at <http://www.gnu.org/licenses/gpl.html>
|
||||||
|
// for more details.
|
||||||
|
//
|
||||||
|
/////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "cafCmdFeature.h"
|
||||||
|
|
||||||
|
class RimViewWindow;
|
||||||
|
|
||||||
|
//==================================================================================================
|
||||||
|
///
|
||||||
|
//==================================================================================================
|
||||||
|
class RicSnapshotViewToFileFeature : public caf::CmdFeature
|
||||||
|
{
|
||||||
|
CAF_CMD_HEADER_INIT;
|
||||||
|
|
||||||
|
public:
|
||||||
|
static void saveSnapshotAs(const QString& fileName, RimViewWindow* viewWindow);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
// Overrides
|
||||||
|
virtual bool isCommandEnabled() override;
|
||||||
|
virtual void onActionTriggered(bool isChecked) override;
|
||||||
|
virtual void setupActionLook(QAction* actionToSetup) override;
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user