mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
#872 When exporting several summary plots the data from different plots are stored to different files, and adding extension .csv to files files exported for wellLogPlots and summaryPlots.
This commit is contained in:
parent
4ccdd51ea8
commit
0a945155c5
@ -36,6 +36,7 @@
|
||||
#include <QFileInfo>
|
||||
#include <QMessageBox>
|
||||
#include <vector>
|
||||
#include "cafUtils.h"
|
||||
|
||||
|
||||
|
||||
@ -62,19 +63,52 @@ void RicAsciiExportSummaryPlotFeature::onActionTriggered(bool isChecked)
|
||||
|
||||
std::vector<RimSummaryPlot*> selectedSummaryPlots;
|
||||
caf::SelectionManager::instance()->objectsByType(&selectedSummaryPlots);
|
||||
|
||||
QString defaultDir = RiaApplication::instance()->lastUsedDialogDirectoryWithFallback("PLOT_ASCIIEXPORT_DIR", projectFolder);
|
||||
QString defaultFileName = defaultDir + "/" + QString("SummaryPlotExport");
|
||||
QString fileName = QFileDialog::getSaveFileName(NULL, "Select file for Summary Plot Export", defaultFileName, "All files(*.*)");
|
||||
|
||||
if (fileName.isEmpty()) return;
|
||||
bool isOk = writeAsciiExportForSummaryPlots(fileName, selectedSummaryPlots);
|
||||
|
||||
caf::ProgressInfo pi(selectedSummaryPlots.size(), QString("Exporting to csv"));
|
||||
size_t progress = 0;
|
||||
|
||||
|
||||
bool isOk = false;
|
||||
if (selectedSummaryPlots.size() == 1)
|
||||
{
|
||||
RimSummaryPlot* summaryPlot = selectedSummaryPlots.at(0);
|
||||
QString defaultFileName = defaultDir + "/" + caf::Utils::makeValidFileBasename((summaryPlot->description())) + ".csv";
|
||||
QString fileName = QFileDialog::getSaveFileName(NULL, "Select file for Summary Plot Export", defaultFileName, "All files(*.*)");
|
||||
if (fileName.isEmpty()) return;
|
||||
isOk = writeAsciiExportForSummaryPlots(fileName, summaryPlot);
|
||||
|
||||
progress++;
|
||||
pi.setProgress(progress);
|
||||
}
|
||||
else if (selectedSummaryPlots.size() > 1)
|
||||
{
|
||||
std::vector<QString> fileNames;
|
||||
for (RimSummaryPlot* summaryPlot : selectedSummaryPlots)
|
||||
{
|
||||
QString fileName = caf::Utils::makeValidFileBasename(summaryPlot->description()) + ".csv";
|
||||
fileNames.push_back(fileName);
|
||||
}
|
||||
|
||||
QString saveDir;
|
||||
bool writeFiles = caf::Utils::getSaveDirectoryAndCheckOverwriteFiles(defaultDir, fileNames, &saveDir);
|
||||
if (!writeFiles) return;
|
||||
|
||||
RiaLogging::debug(QString("Writing to directory %!").arg(saveDir));
|
||||
for (RimSummaryPlot* summaryPlot : selectedSummaryPlots)
|
||||
{
|
||||
QString fileName = saveDir + "/" + caf::Utils::makeValidFileBasename(summaryPlot->description()) + ".csv";
|
||||
isOk = writeAsciiExportForSummaryPlots(fileName, summaryPlot);
|
||||
progress++;
|
||||
pi.setProgress(progress);
|
||||
}
|
||||
}
|
||||
|
||||
if (!isOk)
|
||||
{
|
||||
QMessageBox::critical(NULL, "File export", "Failed to exported current result to " + fileName);
|
||||
QMessageBox::critical(NULL, "File export", "Failed to export summary plots to csv");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@ -88,7 +122,7 @@ void RicAsciiExportSummaryPlotFeature::setupActionLook(QAction* actionToSetup)
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RicAsciiExportSummaryPlotFeature::writeAsciiExportForSummaryPlots(const QString& fileName, const std::vector<RimSummaryPlot*>& selectedSummaryPlots)
|
||||
bool RicAsciiExportSummaryPlotFeature::writeAsciiExportForSummaryPlots(const QString& fileName, const RimSummaryPlot* summaryPlot)
|
||||
{
|
||||
RiaLogging::info(QString("Writing ascii values for summary plot(s) to file: %1").arg(fileName));
|
||||
|
||||
@ -98,19 +132,12 @@ bool RicAsciiExportSummaryPlotFeature::writeAsciiExportForSummaryPlots(const QSt
|
||||
return false;
|
||||
}
|
||||
|
||||
caf::ProgressInfo pi(selectedSummaryPlots.size(), QString("Writing data to file %1").arg(fileName));
|
||||
size_t progress = 0;
|
||||
|
||||
QTextStream out(&file);
|
||||
for (RimSummaryPlot* summaryPlot : selectedSummaryPlots)
|
||||
{
|
||||
out << summaryPlot->description();
|
||||
out << summaryPlot->asciiDataForPlotExport();
|
||||
out << "\n\n";
|
||||
out << summaryPlot->description();
|
||||
out << summaryPlot->asciiDataForPlotExport();
|
||||
out << "\n\n";
|
||||
|
||||
progress++;
|
||||
pi.setProgress(progress);
|
||||
}
|
||||
RiaLogging::info(QString("Competed writing ascii values for summary plot(s) to file %1").arg(fileName));
|
||||
return true;
|
||||
}
|
||||
|
@ -38,5 +38,5 @@ protected:
|
||||
virtual void setupActionLook(QAction* actionToSetup) override;
|
||||
|
||||
private:
|
||||
bool writeAsciiExportForSummaryPlots(const QString& fileName, const std::vector<RimSummaryPlot*>& selectedSummaryPlots);
|
||||
bool writeAsciiExportForSummaryPlots(const QString& fileName, const RimSummaryPlot* selectedSummaryPlots);
|
||||
};
|
||||
|
@ -63,7 +63,7 @@ void RicAsciiExportWellLogPlotFeature::onActionTriggered(bool isChecked)
|
||||
|
||||
std::vector<RimWellLogPlot*> selectedWellLogPlots;
|
||||
caf::SelectionManager::instance()->objectsByType(&selectedWellLogPlots);
|
||||
QString saveDir = RiaApplication::instance()->lastUsedDialogDirectoryWithFallback("PLOT_ASCIIEXPORT_DIR", projectFolder);
|
||||
QString defaultDir = RiaApplication::instance()->lastUsedDialogDirectoryWithFallback("PLOT_ASCIIEXPORT_DIR", projectFolder);
|
||||
|
||||
caf::ProgressInfo pi(selectedWellLogPlots.size(), QString("Exporting to csv"));
|
||||
size_t progress = 0;
|
||||
@ -72,7 +72,7 @@ void RicAsciiExportWellLogPlotFeature::onActionTriggered(bool isChecked)
|
||||
if (selectedWellLogPlots.size() == 1)
|
||||
{
|
||||
RimWellLogPlot* wellLogPlot = selectedWellLogPlots.at(0);
|
||||
QString defaultFileName = saveDir + "/" + caf::Utils::makeValidFileBasename((wellLogPlot->description()));
|
||||
QString defaultFileName = defaultDir + "/" + caf::Utils::makeValidFileBasename((wellLogPlot->description())) + ".csv";
|
||||
QString fileName = QFileDialog::getSaveFileName(NULL, "Select file for Well Log Plot Export", defaultFileName, "All files(*.*)");
|
||||
if (fileName.isEmpty()) return;
|
||||
isOk = writeAsciiExportForWellLogPlots(fileName, wellLogPlot);
|
||||
@ -85,18 +85,18 @@ void RicAsciiExportWellLogPlotFeature::onActionTriggered(bool isChecked)
|
||||
std::vector<QString> fileNames;
|
||||
for (RimWellLogPlot* wellLogPlot : selectedWellLogPlots)
|
||||
{
|
||||
QString fileName = caf::Utils::makeValidFileBasename(wellLogPlot->description());
|
||||
QString fileName = caf::Utils::makeValidFileBasename(wellLogPlot->description()) + ".csv";
|
||||
fileNames.push_back(fileName);
|
||||
}
|
||||
|
||||
bool writeFiles = caf::Utils::getSaveDirectoryAndCheckOverwriteFiles(saveDir, fileNames);
|
||||
QString saveDir;
|
||||
bool writeFiles = caf::Utils::getSaveDirectoryAndCheckOverwriteFiles(defaultDir, fileNames, &saveDir);
|
||||
if (!writeFiles) return;
|
||||
|
||||
RiaLogging::debug(QString("Writing to directory %!").arg(saveDir));
|
||||
for (RimWellLogPlot* wellLogPlot : selectedWellLogPlots)
|
||||
{
|
||||
QString fileName = saveDir + "/" + caf::Utils::makeValidFileBasename(wellLogPlot->description());
|
||||
|
||||
QString fileName = saveDir + "/" + caf::Utils::makeValidFileBasename(wellLogPlot->description()) + ".csv";
|
||||
isOk = writeAsciiExportForWellLogPlots(fileName, wellLogPlot);
|
||||
|
||||
progress++;
|
||||
@ -106,7 +106,7 @@ void RicAsciiExportWellLogPlotFeature::onActionTriggered(bool isChecked)
|
||||
|
||||
if (!isOk)
|
||||
{
|
||||
QMessageBox::critical(NULL, "File export", "Failed to exported current result ");
|
||||
QMessageBox::critical(NULL, "File export", "Failed to export well log plot to csv");
|
||||
}
|
||||
|
||||
}
|
||||
@ -122,7 +122,7 @@ void RicAsciiExportWellLogPlotFeature::setupActionLook(QAction* actionToSetup)
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RicAsciiExportWellLogPlotFeature::writeAsciiExportForWellLogPlots(const QString& fileName, RimWellLogPlot* wellLogPlot)
|
||||
bool RicAsciiExportWellLogPlotFeature::writeAsciiExportForWellLogPlots(const QString& fileName, const RimWellLogPlot* wellLogPlot)
|
||||
{
|
||||
QFile file(fileName);
|
||||
if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
|
||||
|
@ -40,5 +40,5 @@ protected:
|
||||
|
||||
|
||||
private:
|
||||
bool writeAsciiExportForWellLogPlots(const QString& fileName, RimWellLogPlot* wellLogPlot);
|
||||
bool writeAsciiExportForWellLogPlots(const QString& fileName, const RimWellLogPlot* wellLogPlot);
|
||||
};
|
||||
|
@ -388,7 +388,7 @@ QWidget* RimWellLogPlot::viewWidget()
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RimWellLogPlot::asciiDataForPlotExport()
|
||||
QString RimWellLogPlot::asciiDataForPlotExport() const
|
||||
{
|
||||
QString out;
|
||||
|
||||
|
@ -99,7 +99,7 @@ public:
|
||||
virtual void zoomAll() override;
|
||||
virtual QWidget* viewWidget() override;
|
||||
|
||||
QString asciiDataForPlotExport();
|
||||
QString asciiDataForPlotExport() const;
|
||||
|
||||
protected:
|
||||
|
||||
|
@ -205,7 +205,7 @@ QWidget* RimSummaryPlot::viewWidget()
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RimSummaryPlot::asciiDataForPlotExport()
|
||||
QString RimSummaryPlot::asciiDataForPlotExport() const
|
||||
{
|
||||
QString out;
|
||||
|
||||
@ -222,10 +222,15 @@ QString RimSummaryPlot::asciiDataForPlotExport()
|
||||
for (RimSummaryCurve* curve : curves)
|
||||
{
|
||||
if (!curve->isCurveVisible()) continue;
|
||||
|
||||
QString curveCaseName = curve->summaryCase()->caseName();
|
||||
int casePosInList = casePositionInList(curveCaseName, caseNames);
|
||||
if (casePosInList < 0) //case is not yet considered
|
||||
|
||||
int casePosInList = -1;
|
||||
for (int i = 0; i < caseNames.size(); i++)
|
||||
{
|
||||
if (curveCaseName == caseNames[i]) casePosInList = i;
|
||||
}
|
||||
|
||||
if (casePosInList < 0)
|
||||
{
|
||||
caseNames.push_back(curveCaseName);
|
||||
|
||||
@ -279,20 +284,7 @@ QString RimSummaryPlot::asciiDataForPlotExport()
|
||||
return out;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
int RimSummaryPlot::casePositionInList(QString curveCase, std::vector<QString> caseNames)
|
||||
{
|
||||
if (caseNames.size() < 1) return -1;
|
||||
|
||||
for (int i = 0; i < caseNames.size(); i++)
|
||||
{
|
||||
if (curveCase == caseNames[i]) return i;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
|
@ -87,7 +87,7 @@ public:
|
||||
|
||||
virtual QWidget* viewWidget() override;
|
||||
|
||||
QString asciiDataForPlotExport();
|
||||
QString asciiDataForPlotExport() const;
|
||||
|
||||
protected:
|
||||
// Overridden PDM methods
|
||||
@ -112,8 +112,6 @@ private:
|
||||
void updateMdiWindowTitle() override;
|
||||
virtual void deleteViewWidget() override;
|
||||
|
||||
int casePositionInList(QString curveCase, std::vector<QString> caseNames);
|
||||
|
||||
private:
|
||||
caf::PdmField<bool> m_showPlotTitle;
|
||||
caf::PdmField<QString> m_userName;
|
||||
|
@ -167,29 +167,34 @@ QString Utils::indentString(int numSpacesToIndent, const QString& str)
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool Utils::getSaveDirectoryAndCheckOverwriteFiles(QString& saveDir, std::vector<QString> fileNames)
|
||||
bool Utils::getSaveDirectoryAndCheckOverwriteFiles(const QString& defaultDir, std::vector<QString> fileNames, QString* saveDir)
|
||||
{
|
||||
bool overWriteFiles = false;
|
||||
saveDir = QFileDialog::getExistingDirectory(NULL, "Select save directory", saveDir);
|
||||
(*saveDir) = QFileDialog::getExistingDirectory(NULL, "Select save directory", defaultDir);
|
||||
|
||||
std::vector<QString> filesToOverwrite;
|
||||
for (QString fileName : fileNames)
|
||||
{
|
||||
QFileInfo fileInfo(saveDir + "/" + fileName);
|
||||
QFileInfo fileInfo((*saveDir) + "/" +fileName);
|
||||
if (fileInfo.exists())
|
||||
{
|
||||
filesToOverwrite.push_back(fileName);
|
||||
}
|
||||
}
|
||||
|
||||
if (filesToOverwrite.size() > 0)
|
||||
if (filesToOverwrite.size() == 0)
|
||||
{
|
||||
overWriteFiles = true;
|
||||
return overWriteFiles;
|
||||
}
|
||||
else if (filesToOverwrite.size() > 0)
|
||||
{
|
||||
QMessageBox msgBox;
|
||||
|
||||
QString message = "The following files will be overwritten in the export:";
|
||||
for (QString fileName : filesToOverwrite)
|
||||
{
|
||||
message += "\n" + saveDir + "/" + fileName;
|
||||
message += "\n" + (*saveDir) + "/" + fileName;
|
||||
}
|
||||
msgBox.setText(message);
|
||||
|
||||
|
@ -62,8 +62,7 @@ public:
|
||||
|
||||
static QString indentString(int numSpacesToIndent, const QString& str);
|
||||
|
||||
static bool getSaveDirectoryAndCheckOverwriteFiles(QString& defaultDir, std::vector<QString> fileNames);
|
||||
|
||||
static bool getSaveDirectoryAndCheckOverwriteFiles(const QString& defaultDir, std::vector<QString> fileNames, QString* saveDir);
|
||||
};
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user