From 4ccdd51ea86c1acb711788a8013de71392177a72 Mon Sep 17 00:00:00 2001 From: astridkbjorke Date: Fri, 10 Mar 2017 13:16:53 +0100 Subject: [PATCH] #1294 - When selecting multiple wellLogPlots, they will now be exported to separate files. --- .../RicAsciiExportWellLogPlotFeature.cpp | 73 +++++++++++++------ .../RicAsciiExportWellLogPlotFeature.h | 4 +- .../RimContextCommandBuilder.cpp | 4 + 3 files changed, 56 insertions(+), 25 deletions(-) diff --git a/ApplicationCode/Commands/WellLogCommands/RicAsciiExportWellLogPlotFeature.cpp b/ApplicationCode/Commands/WellLogCommands/RicAsciiExportWellLogPlotFeature.cpp index 556f24d91a..c2032815f0 100644 --- a/ApplicationCode/Commands/WellLogCommands/RicAsciiExportWellLogPlotFeature.cpp +++ b/ApplicationCode/Commands/WellLogCommands/RicAsciiExportWellLogPlotFeature.cpp @@ -27,6 +27,7 @@ #include "cafPdmUiPropertyViewDialog.h" #include "cafProgressInfo.h" +#include "cafUtils.h" #include "cafSelectionManager.h" #include "cvfAssert.h" @@ -62,17 +63,50 @@ void RicAsciiExportWellLogPlotFeature::onActionTriggered(bool isChecked) std::vector selectedWellLogPlots; caf::SelectionManager::instance()->objectsByType(&selectedWellLogPlots); + QString saveDir = RiaApplication::instance()->lastUsedDialogDirectoryWithFallback("PLOT_ASCIIEXPORT_DIR", projectFolder); - QString defaultDir = RiaApplication::instance()->lastUsedDialogDirectoryWithFallback("PLOT_ASCIIEXPORT_DIR", projectFolder); - QString defaultFileName = defaultDir + "/" + QString("WellLogPlotExport"); - QString fileName = QFileDialog::getSaveFileName(NULL, "Select file for Well Log Plot Export", defaultFileName, "All files(*.*)"); + caf::ProgressInfo pi(selectedWellLogPlots.size(), QString("Exporting to csv")); + size_t progress = 0; - if (fileName.isEmpty()) return; - bool isOk = writeAsciiExportForWellLogPlots(fileName, selectedWellLogPlots); + bool isOk = false; + if (selectedWellLogPlots.size() == 1) + { + RimWellLogPlot* wellLogPlot = selectedWellLogPlots.at(0); + QString defaultFileName = saveDir + "/" + caf::Utils::makeValidFileBasename((wellLogPlot->description())); + QString fileName = QFileDialog::getSaveFileName(NULL, "Select file for Well Log Plot Export", defaultFileName, "All files(*.*)"); + if (fileName.isEmpty()) return; + isOk = writeAsciiExportForWellLogPlots(fileName, wellLogPlot); + + progress++; + pi.setProgress(progress); + } + else if (selectedWellLogPlots.size() > 1) + { + std::vector fileNames; + for (RimWellLogPlot* wellLogPlot : selectedWellLogPlots) + { + QString fileName = caf::Utils::makeValidFileBasename(wellLogPlot->description()); + fileNames.push_back(fileName); + } + + bool writeFiles = caf::Utils::getSaveDirectoryAndCheckOverwriteFiles(saveDir, fileNames); + if (!writeFiles) return; + + RiaLogging::debug(QString("Writing to directory %!").arg(saveDir)); + for (RimWellLogPlot* wellLogPlot : selectedWellLogPlots) + { + QString fileName = saveDir + "/" + caf::Utils::makeValidFileBasename(wellLogPlot->description()); + + isOk = writeAsciiExportForWellLogPlots(fileName, wellLogPlot); + + 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 exported current result "); } } @@ -82,37 +116,28 @@ void RicAsciiExportWellLogPlotFeature::onActionTriggered(bool isChecked) //-------------------------------------------------------------------------------------------------- void RicAsciiExportWellLogPlotFeature::setupActionLook(QAction* actionToSetup) { - actionToSetup->setText("Export Well Allocation Plot Data"); + actionToSetup->setText("Export to csv"); } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -bool RicAsciiExportWellLogPlotFeature::writeAsciiExportForWellLogPlots(const QString& fileName, const std::vector& selectedWellLogPlots) +bool RicAsciiExportWellLogPlotFeature::writeAsciiExportForWellLogPlots(const QString& fileName, RimWellLogPlot* wellLogPlot) { - RiaLogging::info(QString("Writing ascii values for well allocation plot(s) to file: %1").arg(fileName)); - QFile file(fileName); if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) { return false; } - - caf::ProgressInfo pi(selectedWellLogPlots.size(), QString("Writing data to file %1").arg(fileName)); - size_t progress = 0; - + QTextStream out(&file); - for (RimWellLogPlot* wellLogPlot : selectedWellLogPlots) - { - out << wellLogPlot->description(); - out << "\n"; - out << wellLogPlot->asciiDataForPlotExport(); - out << "\n\n"; - progress++; - pi.setProgress(progress); - } - RiaLogging::info(QString("Competed writing ascii values for summary plot(s) to file %1").arg(fileName)); + out << wellLogPlot->description(); + out << "\n"; + out << wellLogPlot->asciiDataForPlotExport(); + out << "\n\n"; + + RiaLogging::info(QString("CVS export completed for %1").arg(fileName)); return true; } diff --git a/ApplicationCode/Commands/WellLogCommands/RicAsciiExportWellLogPlotFeature.h b/ApplicationCode/Commands/WellLogCommands/RicAsciiExportWellLogPlotFeature.h index 7c81f5939e..7b7e7856d9 100644 --- a/ApplicationCode/Commands/WellLogCommands/RicAsciiExportWellLogPlotFeature.h +++ b/ApplicationCode/Commands/WellLogCommands/RicAsciiExportWellLogPlotFeature.h @@ -37,6 +37,8 @@ protected: virtual void onActionTriggered( bool isChecked ) override; virtual void setupActionLook(QAction* actionToSetup) override; + + private: - bool writeAsciiExportForWellLogPlots(const QString& fileName, const std::vector& selectedSummaryPlots); + bool writeAsciiExportForWellLogPlots(const QString& fileName, RimWellLogPlot* wellLogPlot); }; diff --git a/ApplicationCode/ProjectDataModel/RimContextCommandBuilder.cpp b/ApplicationCode/ProjectDataModel/RimContextCommandBuilder.cpp index 84caf68e55..9b123d2d6c 100644 --- a/ApplicationCode/ProjectDataModel/RimContextCommandBuilder.cpp +++ b/ApplicationCode/ProjectDataModel/RimContextCommandBuilder.cpp @@ -407,6 +407,10 @@ QStringList RimContextCommandBuilder::commandsFromSelection() { commandIds << "RicAsciiExportSummaryPlotFeature"; } + else if (dynamic_cast(uiItem)) + { + commandIds << "RicAsciiExportWellLogPlotFeature"; + } else if (dynamic_cast(uiItem) || dynamic_cast(uiItem) || dynamic_cast(uiItem))