2017-03-07 06:48:17 -06:00
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// Copyright (C) 2017- 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 "RicAsciiExportSummaryPlotFeature.h"
|
|
|
|
|
|
|
|
#include "RiaApplication.h"
|
2017-03-08 05:25:32 -06:00
|
|
|
#include "RiaLogging.h"
|
2017-03-07 06:48:17 -06:00
|
|
|
|
|
|
|
#include "RimSummaryPlot.h"
|
|
|
|
|
2017-03-08 05:25:32 -06:00
|
|
|
#include "RiuMainWindow.h"
|
2017-03-07 06:48:17 -06:00
|
|
|
|
2017-03-08 05:25:32 -06:00
|
|
|
#include "cafPdmUiPropertyViewDialog.h"
|
|
|
|
#include "cafProgressInfo.h"
|
2017-03-07 06:48:17 -06:00
|
|
|
#include "cafSelectionManager.h"
|
2017-03-15 06:27:40 -05:00
|
|
|
#include "cafUtils.h"
|
|
|
|
|
2017-03-08 05:25:32 -06:00
|
|
|
#include "cvfAssert.h"
|
2017-03-07 06:48:17 -06:00
|
|
|
|
|
|
|
#include <QAction>
|
2017-03-08 05:25:32 -06:00
|
|
|
#include <QDebug>
|
2017-03-08 06:27:17 -06:00
|
|
|
#include <QFileDialog>
|
2017-03-08 05:25:32 -06:00
|
|
|
#include <QFileInfo>
|
2017-03-15 06:27:40 -05:00
|
|
|
|
2017-03-08 05:25:32 -06:00
|
|
|
|
2017-03-07 06:48:17 -06:00
|
|
|
|
|
|
|
|
|
|
|
CAF_CMD_SOURCE_INIT(RicAsciiExportSummaryPlotFeature, "RicAsciiExportSummaryPlotFeature");
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
bool RicAsciiExportSummaryPlotFeature::isCommandEnabled()
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void RicAsciiExportSummaryPlotFeature::onActionTriggered(bool isChecked)
|
|
|
|
{
|
2017-04-20 03:38:58 -05:00
|
|
|
this->disableModelChangeContribution();
|
|
|
|
|
2017-03-08 06:27:17 -06:00
|
|
|
RiaApplication* app = RiaApplication::instance();
|
|
|
|
QString projectFolder = app->currentProjectPath();
|
|
|
|
|
2017-03-07 06:48:17 -06:00
|
|
|
RimProject* project = RiaApplication::instance()->project();
|
|
|
|
CVF_ASSERT(project);
|
|
|
|
|
|
|
|
std::vector<RimSummaryPlot*> selectedSummaryPlots;
|
|
|
|
caf::SelectionManager::instance()->objectsByType(&selectedSummaryPlots);
|
2017-03-09 04:14:13 -06:00
|
|
|
QString defaultDir = RiaApplication::instance()->lastUsedDialogDirectoryWithFallback("PLOT_ASCIIEXPORT_DIR", projectFolder);
|
2017-03-07 06:48:17 -06:00
|
|
|
|
2017-03-15 06:27:40 -05:00
|
|
|
caf::ProgressInfo pi(selectedSummaryPlots.size(), QString("Exporting plot data to ASCII"));
|
2017-03-10 07:50:04 -06:00
|
|
|
size_t progress = 0;
|
|
|
|
|
|
|
|
if (selectedSummaryPlots.size() == 1)
|
|
|
|
{
|
|
|
|
RimSummaryPlot* summaryPlot = selectedSummaryPlots.at(0);
|
2017-03-15 06:27:40 -05:00
|
|
|
QString defaultFileName = defaultDir + "/" + caf::Utils::makeValidFileBasename((summaryPlot->description())) + ".ascii";
|
2017-03-15 07:28:25 -05:00
|
|
|
QString fileName = QFileDialog::getSaveFileName(nullptr, "Select File for Summary Plot Export", defaultFileName, "Text File(*.ascii);;All files(*.*)");
|
2017-03-10 07:50:04 -06:00
|
|
|
if (fileName.isEmpty()) return;
|
2017-03-15 07:28:25 -05:00
|
|
|
RicAsciiExportSummaryPlotFeature::exportAsciiForSummaryPlot(fileName, summaryPlot);
|
2017-03-10 07:50:04 -06:00
|
|
|
|
|
|
|
progress++;
|
|
|
|
pi.setProgress(progress);
|
|
|
|
}
|
|
|
|
else if (selectedSummaryPlots.size() > 1)
|
|
|
|
{
|
|
|
|
std::vector<QString> fileNames;
|
|
|
|
for (RimSummaryPlot* summaryPlot : selectedSummaryPlots)
|
|
|
|
{
|
2017-03-15 06:27:40 -05:00
|
|
|
QString fileName = caf::Utils::makeValidFileBasename(summaryPlot->description()) + ".ascii";
|
2017-03-10 07:50:04 -06:00
|
|
|
fileNames.push_back(fileName);
|
|
|
|
}
|
|
|
|
|
|
|
|
QString saveDir;
|
|
|
|
bool writeFiles = caf::Utils::getSaveDirectoryAndCheckOverwriteFiles(defaultDir, fileNames, &saveDir);
|
|
|
|
if (!writeFiles) return;
|
|
|
|
|
2017-04-27 07:14:06 -05:00
|
|
|
RiaLogging::info(QString("Writing to directory %1").arg(saveDir));
|
2017-03-10 07:50:04 -06:00
|
|
|
for (RimSummaryPlot* summaryPlot : selectedSummaryPlots)
|
|
|
|
{
|
2017-03-15 06:27:40 -05:00
|
|
|
QString fileName = saveDir + "/" + caf::Utils::makeValidFileBasename(summaryPlot->description()) + ".ascii";
|
2017-03-15 07:28:25 -05:00
|
|
|
RicAsciiExportSummaryPlotFeature::exportAsciiForSummaryPlot(fileName, summaryPlot);
|
2017-03-10 07:50:04 -06:00
|
|
|
progress++;
|
|
|
|
pi.setProgress(progress);
|
|
|
|
}
|
|
|
|
}
|
2017-03-07 06:48:17 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void RicAsciiExportSummaryPlotFeature::setupActionLook(QAction* actionToSetup)
|
|
|
|
{
|
2017-03-15 06:27:40 -05:00
|
|
|
actionToSetup->setText("Export Plot Data to Text File");
|
2017-03-15 07:30:16 -05:00
|
|
|
actionToSetup->setIcon(QIcon(":/Save.png"));
|
2017-03-07 06:48:17 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2017-03-15 06:27:40 -05:00
|
|
|
bool RicAsciiExportSummaryPlotFeature::exportAsciiForSummaryPlot(const QString& fileName, const RimSummaryPlot* summaryPlot)
|
2017-03-07 06:48:17 -06:00
|
|
|
{
|
|
|
|
QFile file(fileName);
|
|
|
|
if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-03-15 07:28:25 -05:00
|
|
|
RiaLogging::info(QString("Writing values for summary plot(s) to file: %1").arg(fileName));
|
|
|
|
|
2017-03-07 06:48:17 -06:00
|
|
|
QTextStream out(&file);
|
2017-03-15 06:27:40 -05:00
|
|
|
|
2017-03-10 07:50:04 -06:00
|
|
|
out << summaryPlot->description();
|
|
|
|
out << summaryPlot->asciiDataForPlotExport();
|
|
|
|
out << "\n\n";
|
2017-03-08 05:25:32 -06:00
|
|
|
|
2017-03-15 06:27:40 -05:00
|
|
|
RiaLogging::info(QString("Competed writing values for summary plot(s) to file %1").arg(fileName));
|
|
|
|
|
2017-03-07 06:48:17 -06:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|