2016-06-27 14:01:17 -05:00
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// 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 "RicSnapshotViewToClipboardFeature.h"
|
|
|
|
|
|
|
|
#include "RiaApplication.h"
|
|
|
|
|
2016-10-27 01:09:49 -05:00
|
|
|
#include "RimProject.h"
|
2016-10-27 04:03:13 -05:00
|
|
|
#include "RimSummaryPlot.h"
|
2016-06-27 14:01:17 -05:00
|
|
|
#include "RimViewWindow.h"
|
2016-10-27 04:03:13 -05:00
|
|
|
#include "RimWellLogPlot.h"
|
|
|
|
#include "RiuMainPlotWindow.h"
|
|
|
|
#include "RiuWellLogPlot.h"
|
|
|
|
|
|
|
|
#include "cafUtils.h"
|
2016-06-27 14:01:17 -05:00
|
|
|
|
|
|
|
#include <QAction>
|
2016-06-28 04:38:11 -05:00
|
|
|
#include <QClipboard>
|
2016-10-27 01:09:49 -05:00
|
|
|
#include <QDebug>
|
|
|
|
#include <QFileDialog>
|
|
|
|
#include <QFileInfo>
|
2016-06-28 04:38:11 -05:00
|
|
|
#include <QMdiSubWindow>
|
2016-06-27 14:01:17 -05:00
|
|
|
|
2016-10-27 01:09:49 -05:00
|
|
|
|
2016-06-27 14:01:17 -05:00
|
|
|
CAF_CMD_SOURCE_INIT(RicSnapshotViewToClipboardFeature, "RicSnapshotViewToClipboardFeature");
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
bool RicSnapshotViewToClipboardFeature::isCommandEnabled()
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void RicSnapshotViewToClipboardFeature::onActionTriggered(bool isChecked)
|
|
|
|
{
|
2016-08-31 10:34:31 -05:00
|
|
|
RimViewWindow* viewWindow = RiaApplication::activeViewWindow();
|
2016-06-27 14:01:17 -05:00
|
|
|
|
|
|
|
if (viewWindow)
|
|
|
|
{
|
|
|
|
QClipboard* clipboard = QApplication::clipboard();
|
|
|
|
if (clipboard)
|
|
|
|
{
|
|
|
|
QImage image = viewWindow->snapshotWindowContent();
|
|
|
|
if (!image.isNull())
|
|
|
|
{
|
|
|
|
clipboard->setImage(image);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void RicSnapshotViewToClipboardFeature::setupActionLook(QAction* actionToSetup)
|
|
|
|
{
|
2016-06-28 03:58:22 -05:00
|
|
|
actionToSetup->setText("Snapshot To Clipboard");
|
|
|
|
actionToSetup->setIcon(QIcon(":/SnapShot.png"));
|
2016-06-27 14:01:17 -05:00
|
|
|
}
|
|
|
|
|
2016-10-27 01:09:49 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CAF_CMD_SOURCE_INIT(RicSnapshotViewToFileFeature, "RicSnapshotViewToFileFeature");
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2016-11-09 05:22:07 -06:00
|
|
|
void RicSnapshotViewToFileFeature::saveSnapshotAs(const QString& fileName, RimViewWindow* viewWindow)
|
2016-10-27 01:09:49 -05:00
|
|
|
{
|
|
|
|
if (viewWindow)
|
|
|
|
{
|
|
|
|
QImage image = viewWindow->snapshotWindowContent();
|
|
|
|
if (!image.isNull())
|
|
|
|
{
|
|
|
|
if (image.save(fileName))
|
|
|
|
{
|
|
|
|
qDebug() << "Saved snapshot image to " << fileName;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
qDebug() << "Error when trying to save snapshot image to " << fileName;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
bool RicSnapshotViewToFileFeature::isCommandEnabled()
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void RicSnapshotViewToFileFeature::onActionTriggered(bool isChecked)
|
|
|
|
{
|
|
|
|
RiaApplication* app = RiaApplication::instance();
|
|
|
|
RimProject* proj = app->project();
|
|
|
|
|
|
|
|
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("Save File"), startPath, tr("Image files (*.bmp *.png * *.jpg)"));
|
|
|
|
if (fileName.isEmpty())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Remember the directory to next time
|
|
|
|
app->setLastUsedDialogDirectory("IMAGE_SNAPSHOT", QFileInfo(fileName).absolutePath());
|
|
|
|
|
2016-11-09 05:22:07 -06:00
|
|
|
RimViewWindow* viewWindow = app->activeViewWindow();
|
|
|
|
RicSnapshotViewToFileFeature::saveSnapshotAs(fileName, viewWindow);
|
2016-10-27 01:09:49 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void RicSnapshotViewToFileFeature::setupActionLook(QAction* actionToSetup)
|
|
|
|
{
|
|
|
|
actionToSetup->setText("Snapshot To File");
|
|
|
|
actionToSetup->setIcon(QIcon(":/SnapShotSave.png"));
|
|
|
|
}
|
|
|
|
|
2016-10-27 04:03:13 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CAF_CMD_SOURCE_INIT(RicSnapshotAllPlotsToFileFeature, "RicSnapshotAllPlotsToFileFeature");
|
|
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2016-11-09 05:22:07 -06:00
|
|
|
void RicSnapshotAllPlotsToFileFeature::saveAllPlots()
|
2016-10-27 04:03:13 -05:00
|
|
|
{
|
|
|
|
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");
|
|
|
|
|
2016-11-29 08:18:55 -06:00
|
|
|
createSnapshotOfAllPlotsInFolder(snapshotFolderName);
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void RicSnapshotAllPlotsToFileFeature::createSnapshotOfAllPlotsInFolder(QString snapshotFolderName)
|
|
|
|
{
|
|
|
|
RiaApplication* app = RiaApplication::instance();
|
|
|
|
|
|
|
|
RimProject* proj = app->project();
|
|
|
|
if (!proj) return;
|
|
|
|
|
2016-10-27 04:03:13 -05:00
|
|
|
QDir snapshotPath(snapshotFolderName);
|
|
|
|
if (!snapshotPath.exists())
|
|
|
|
{
|
|
|
|
if (!snapshotPath.mkpath(".")) return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const QString absSnapshotPath = snapshotPath.absolutePath();
|
|
|
|
|
|
|
|
// Well log plots
|
|
|
|
{
|
|
|
|
std::vector<RimWellLogPlot*> wellLogPlots;
|
|
|
|
proj->descendantsIncludingThisOfType(wellLogPlots);
|
|
|
|
for (RimWellLogPlot* wellLogPlot : wellLogPlots)
|
|
|
|
{
|
|
|
|
if (wellLogPlot && wellLogPlot->viewWidget())
|
|
|
|
{
|
|
|
|
QString fileName = wellLogPlot->description();
|
2017-01-04 03:45:04 -06:00
|
|
|
fileName = caf::Utils::makeValidFileBasename(fileName);
|
2016-10-27 04:03:13 -05:00
|
|
|
|
|
|
|
QString absoluteFileName = caf::Utils::constructFullFileName(absSnapshotPath, fileName, ".png");
|
2017-01-31 02:58:11 -06:00
|
|
|
absoluteFileName.replace(" ", "_");
|
2016-10-27 04:03:13 -05:00
|
|
|
|
2016-11-09 05:22:07 -06:00
|
|
|
RicSnapshotViewToFileFeature::saveSnapshotAs(absoluteFileName, wellLogPlot);
|
2016-10-27 04:03:13 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Summary plots
|
|
|
|
{
|
|
|
|
std::vector<RimSummaryPlot*> summaryPlots;
|
|
|
|
proj->descendantsIncludingThisOfType(summaryPlots);
|
|
|
|
for (RimSummaryPlot* summaryPlot : summaryPlots)
|
|
|
|
{
|
|
|
|
if (summaryPlot && summaryPlot->viewWidget())
|
|
|
|
{
|
|
|
|
QString fileName = summaryPlot->description();
|
2017-01-04 03:45:04 -06:00
|
|
|
fileName = caf::Utils::makeValidFileBasename(fileName);
|
2016-10-27 04:03:13 -05:00
|
|
|
|
|
|
|
QString absoluteFileName = caf::Utils::constructFullFileName(absSnapshotPath, fileName, ".png");
|
2017-01-31 02:58:11 -06:00
|
|
|
absoluteFileName.replace(" ", "_");
|
2016-10-27 04:03:13 -05:00
|
|
|
|
2016-11-09 05:22:07 -06:00
|
|
|
RicSnapshotViewToFileFeature::saveSnapshotAs(absoluteFileName, summaryPlot);
|
2016-10-27 04:03:13 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-11-09 05:22:07 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
bool RicSnapshotAllPlotsToFileFeature::isCommandEnabled()
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void RicSnapshotAllPlotsToFileFeature::onActionTriggered(bool isChecked)
|
|
|
|
{
|
|
|
|
QWidget* currentActiveWidget = nullptr;
|
|
|
|
if (RiaApplication::activeViewWindow())
|
|
|
|
{
|
|
|
|
currentActiveWidget = RiaApplication::activeViewWindow()->viewWidget();
|
|
|
|
}
|
|
|
|
|
|
|
|
RicSnapshotAllPlotsToFileFeature::saveAllPlots();
|
2016-10-27 04:03:13 -05:00
|
|
|
|
|
|
|
if (currentActiveWidget)
|
|
|
|
{
|
2016-11-09 05:22:07 -06:00
|
|
|
RiuMainPlotWindow* mainPlotWindow = RiaApplication::instance()->mainPlotWindow();
|
|
|
|
if (mainPlotWindow)
|
|
|
|
{
|
|
|
|
mainPlotWindow->setActiveViewer(currentActiveWidget);
|
|
|
|
}
|
2016-10-27 04:03:13 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void RicSnapshotAllPlotsToFileFeature::setupActionLook(QAction* actionToSetup)
|
|
|
|
{
|
|
|
|
actionToSetup->setText("Snapshot All Plots To File");
|
|
|
|
actionToSetup->setIcon(QIcon(":/SnapShotSave.png"));
|
|
|
|
}
|
|
|
|
|