From 7f511f7004945ed34b1bd8cea24ce47c295d85c4 Mon Sep 17 00:00:00 2001 From: astridkbjorke Date: Thu, 9 Mar 2017 11:14:13 +0100 Subject: [PATCH] #1294 - Added command feature for exporting well allocation plot data, and writing empty file --- .../FlowCommands/CMakeLists_files.cmake | 2 + ...icAsciiExportWellAllocationPlotFeature.cpp | 118 ++++++++++++++++++ .../RicAsciiExportWellAllocationPlotFeature.h | 42 +++++++ .../RicAsciiExportSummaryPlotFeature.cpp | 2 +- .../Flow/RimWellAllocationPlot.cpp | 1 + .../RimContextCommandBuilder.cpp | 1 + 6 files changed, 165 insertions(+), 1 deletion(-) create mode 100644 ApplicationCode/Commands/FlowCommands/RicAsciiExportWellAllocationPlotFeature.cpp create mode 100644 ApplicationCode/Commands/FlowCommands/RicAsciiExportWellAllocationPlotFeature.h diff --git a/ApplicationCode/Commands/FlowCommands/CMakeLists_files.cmake b/ApplicationCode/Commands/FlowCommands/CMakeLists_files.cmake index eb1c91da91..ab9a79354b 100644 --- a/ApplicationCode/Commands/FlowCommands/CMakeLists_files.cmake +++ b/ApplicationCode/Commands/FlowCommands/CMakeLists_files.cmake @@ -11,6 +11,7 @@ ${CEE_CURRENT_LIST_DIR}RicShowContributingWellsFromPlotFeature.h ${CEE_CURRENT_LIST_DIR}RicShowContributingWellsFeature.h ${CEE_CURRENT_LIST_DIR}RicShowContributingWellsFeatureImpl.h ${CEE_CURRENT_LIST_DIR}RicPlotProductionRateFeature.h +${CEE_CURRENT_LIST_DIR}RicAsciiExportWellAllocationPlotFeature.h ${CEE_CURRENT_LIST_DIR}RicSelectViewUI.h ) @@ -21,6 +22,7 @@ ${CEE_CURRENT_LIST_DIR}RicShowContributingWellsFromPlotFeature.cpp ${CEE_CURRENT_LIST_DIR}RicShowContributingWellsFeature.cpp ${CEE_CURRENT_LIST_DIR}RicShowContributingWellsFeatureImpl.cpp ${CEE_CURRENT_LIST_DIR}RicPlotProductionRateFeature.cpp +${CEE_CURRENT_LIST_DIR}RicAsciiExportWellAllocationPlotFeature.cpp ${CEE_CURRENT_LIST_DIR}RicSelectViewUI.cpp ) diff --git a/ApplicationCode/Commands/FlowCommands/RicAsciiExportWellAllocationPlotFeature.cpp b/ApplicationCode/Commands/FlowCommands/RicAsciiExportWellAllocationPlotFeature.cpp new file mode 100644 index 0000000000..2a2c8aa241 --- /dev/null +++ b/ApplicationCode/Commands/FlowCommands/RicAsciiExportWellAllocationPlotFeature.cpp @@ -0,0 +1,118 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// 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 +// for more details. +// +///////////////////////////////////////////////////////////////////////////////// + +#include "RicAsciiExportWellAllocationPlotFeature.h" + +#include "RiaApplication.h" +#include "RiaLogging.h" + +#include "RimWellAllocationPlot.h" + +#include "RiuMainWindow.h" + +#include "cafPdmUiPropertyViewDialog.h" +#include "cafProgressInfo.h" +#include "cafSelectionManager.h" +#include "cvfAssert.h" + +#include +#include +#include +#include +#include +#include + + + +CAF_CMD_SOURCE_INIT(RicAsciiExportWellAllocationPlotFeature, "RicAsciiExportWellAllocationPlotFeature"); + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool RicAsciiExportWellAllocationPlotFeature::isCommandEnabled() +{ + return true; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RicAsciiExportWellAllocationPlotFeature::onActionTriggered(bool isChecked) +{ + RiaApplication* app = RiaApplication::instance(); + QString projectFolder = app->currentProjectPath(); + + RimProject* project = RiaApplication::instance()->project(); + CVF_ASSERT(project); + + std::vector selectedWellAllocPlots; + caf::SelectionManager::instance()->objectsByType(&selectedWellAllocPlots); + + QString defaultDir = RiaApplication::instance()->lastUsedDialogDirectoryWithFallback("PLOT_ASCIIEXPORT_DIR", projectFolder); + QString defaultFileName = defaultDir + "/" + QString("WellAllocationPlotExport"); + QString fileName = QFileDialog::getSaveFileName(NULL, "Select file for Well Allocation Plot Export", defaultFileName, "All files(*.*)"); + + if (fileName.isEmpty()) return; + bool isOk = writeAsciiExportForWellAllocPlots(fileName, selectedWellAllocPlots); + + if (!isOk) + { + QMessageBox::critical(NULL, "File export", "Failed to exported current result to " + fileName); + } + +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RicAsciiExportWellAllocationPlotFeature::setupActionLook(QAction* actionToSetup) +{ + actionToSetup->setText("Export Well Allocation Plot Data"); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool RicAsciiExportWellAllocationPlotFeature::writeAsciiExportForWellAllocPlots(const QString& fileName, const std::vector& selectedWellAllocPlots) +{ + 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(selectedWellAllocPlots.size(), QString("Writing data to file %1").arg(fileName)); + size_t progress = 0; + + QTextStream out(&file); + for (RimWellAllocationPlot* wellAllocPlot : selectedWellAllocPlots) + { + out << wellAllocPlot->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; +} + + diff --git a/ApplicationCode/Commands/FlowCommands/RicAsciiExportWellAllocationPlotFeature.h b/ApplicationCode/Commands/FlowCommands/RicAsciiExportWellAllocationPlotFeature.h new file mode 100644 index 0000000000..6024307dc1 --- /dev/null +++ b/ApplicationCode/Commands/FlowCommands/RicAsciiExportWellAllocationPlotFeature.h @@ -0,0 +1,42 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// 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 +// for more details. +// +///////////////////////////////////////////////////////////////////////////////// + +#pragma once + +#include "cafCmdFeature.h" +#include "cafPdmField.h" + +class RimWellAllocationPlot; + +//================================================================================================== +/// +//================================================================================================== +class RicAsciiExportWellAllocationPlotFeature : public caf::CmdFeature +{ + CAF_CMD_HEADER_INIT; + +public: + +protected: + virtual bool isCommandEnabled() override; + virtual void onActionTriggered( bool isChecked ) override; + virtual void setupActionLook(QAction* actionToSetup) override; + +private: + bool writeAsciiExportForWellAllocPlots(const QString& fileName, const std::vector& selectedSummaryPlots); +}; diff --git a/ApplicationCode/Commands/SummaryPlotCommands/RicAsciiExportSummaryPlotFeature.cpp b/ApplicationCode/Commands/SummaryPlotCommands/RicAsciiExportSummaryPlotFeature.cpp index 877111c1f7..89d766f76f 100644 --- a/ApplicationCode/Commands/SummaryPlotCommands/RicAsciiExportSummaryPlotFeature.cpp +++ b/ApplicationCode/Commands/SummaryPlotCommands/RicAsciiExportSummaryPlotFeature.cpp @@ -63,7 +63,7 @@ void RicAsciiExportSummaryPlotFeature::onActionTriggered(bool isChecked) std::vector selectedSummaryPlots; caf::SelectionManager::instance()->objectsByType(&selectedSummaryPlots); - QString defaultDir = RiaApplication::instance()->lastUsedDialogDirectoryWithFallback("SUMMARYPLOT_ASCIIEXPORT_DIR", projectFolder); + 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(*.*)"); diff --git a/ApplicationCode/ProjectDataModel/Flow/RimWellAllocationPlot.cpp b/ApplicationCode/ProjectDataModel/Flow/RimWellAllocationPlot.cpp index ef5f723b07..5ffbd7a29d 100644 --- a/ApplicationCode/ProjectDataModel/Flow/RimWellAllocationPlot.cpp +++ b/ApplicationCode/ProjectDataModel/Flow/RimWellAllocationPlot.cpp @@ -274,6 +274,7 @@ void RimWellAllocationPlot::updateFromWell() } addStackedCurve(tracerName, depthValues, *accFlow, plotTrack); + //TODO: THIs is the data to be plotted... } } else diff --git a/ApplicationCode/ProjectDataModel/RimContextCommandBuilder.cpp b/ApplicationCode/ProjectDataModel/RimContextCommandBuilder.cpp index eeeb0e0088..c05eb19a6c 100644 --- a/ApplicationCode/ProjectDataModel/RimContextCommandBuilder.cpp +++ b/ApplicationCode/ProjectDataModel/RimContextCommandBuilder.cpp @@ -355,6 +355,7 @@ QStringList RimContextCommandBuilder::commandsFromSelection() else if (dynamic_cast(uiItem)) { commandIds << "RicAddStoredWellAllocationPlotFeature"; + commandIds << "RicAsciiExportWellAllocationPlotFeature"; }