From 8821a37b90583f7e0251347e2624ddd40d364bf0 Mon Sep 17 00:00:00 2001 From: Gaute Lindkvist Date: Wed, 12 Dec 2018 13:09:09 +0100 Subject: [PATCH] #3853 Remove zero padding and unnecessary space at beginning and end of row for WSEGAICD --- .../RicWellPathExportMswCompletionsImpl.cpp | 37 ++++++--------- .../RifEclipseDataTableFormatter.cpp | 46 ++++++++++++++----- .../RifEclipseDataTableFormatter.h | 4 +- 3 files changed, 51 insertions(+), 36 deletions(-) diff --git a/ApplicationCode/Commands/CompletionExportCommands/RicWellPathExportMswCompletionsImpl.cpp b/ApplicationCode/Commands/CompletionExportCommands/RicWellPathExportMswCompletionsImpl.cpp index fe9d4e9ea0..a74b168ce7 100644 --- a/ApplicationCode/Commands/CompletionExportCommands/RicWellPathExportMswCompletionsImpl.cpp +++ b/ApplicationCode/Commands/CompletionExportCommands/RicWellPathExportMswCompletionsImpl.cpp @@ -136,7 +136,7 @@ void RicWellPathExportMswCompletionsImpl::exportWellSegmentsForAllCompletions(co else { QString fileName = - QString("%1_Perforations_MSW_%2") + QString("%1_Perforation_MSW_%2") .arg(wellPath->completions()->wellNameForExport(), exportSettings.caseToApply->caseUserDescription()); perforationsExportFile = RicWellPathExportCompletionsFileTools::openFileForExport(exportSettings.folder, fileName); } @@ -679,6 +679,9 @@ void RicWellPathExportMswCompletionsImpl::generateWsegAicdTable(RifEclipseDataTa { int existingColSpacing = formatter.columnSpacing(); formatter.setColumnSpacing(1); + QString existingPrependText = formatter.tableRowPrependText(); + formatter.setTableRowPrependText(""); + bool foundValve = false; for (std::shared_ptr location : exportInfo.wellSegmentLocations()) @@ -716,29 +719,14 @@ void RicWellPathExportMswCompletionsImpl::generateWsegAicdTable(RifEclipseDataTa formatter.comment(QString("%1: %2").arg(i + 1, 2, 10, QChar('0')).arg(columnDescriptions[i])); } - std::vector header = { - RifEclipseOutputTableColumn("01"), - RifEclipseOutputTableColumn("02"), - RifEclipseOutputTableColumn("03"), - RifEclipseOutputTableColumn("04"), - RifEclipseOutputTableColumn("05"), - RifEclipseOutputTableColumn("06"), - RifEclipseOutputTableColumn("07"), - RifEclipseOutputTableColumn("08"), - RifEclipseOutputTableColumn("09"), - RifEclipseOutputTableColumn("10"), - RifEclipseOutputTableColumn("11"), - RifEclipseOutputTableColumn("12"), - RifEclipseOutputTableColumn("13"), - RifEclipseOutputTableColumn("14"), - RifEclipseOutputTableColumn("15"), - RifEclipseOutputTableColumn("16"), - RifEclipseOutputTableColumn("17"), - RifEclipseOutputTableColumn("18"), - RifEclipseOutputTableColumn("19"), - RifEclipseOutputTableColumn("20"), - RifEclipseOutputTableColumn("21"), - }; + std::vector header; + for (size_t i = 1; i <= 21; ++i) + { + QString cName = QString("%1").arg(i, 2, 10, QChar('0')); + RifEclipseOutputTableColumn col(cName, + RifEclipseOutputTableDoubleFormatting(RifEclipseOutputTableDoubleFormat::RIF_CONSISE), RIGHT); + header.push_back(col); + } formatter.header(header); foundValve = true; @@ -783,6 +771,7 @@ void RicWellPathExportMswCompletionsImpl::generateWsegAicdTable(RifEclipseDataTa formatter.tableCompleted(); } formatter.setColumnSpacing(existingColSpacing); + formatter.setTableRowPrependText(existingPrependText); } //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationCode/FileInterface/RifEclipseDataTableFormatter.cpp b/ApplicationCode/FileInterface/RifEclipseDataTableFormatter.cpp index 7297818106..65742d76e3 100644 --- a/ApplicationCode/FileInterface/RifEclipseDataTableFormatter.cpp +++ b/ApplicationCode/FileInterface/RifEclipseDataTableFormatter.cpp @@ -57,6 +57,14 @@ void RifEclipseDataTableFormatter::setColumnSpacing(int spacing) m_colSpacing = spacing; } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +QString RifEclipseDataTableFormatter::tableRowPrependText() const +{ + return m_tableRowPrependText; +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -88,10 +96,14 @@ void RifEclipseDataTableFormatter::outputBuffer() { if (!m_columns.empty() && !isAllHeadersEmpty(m_columns)) { - m_out << m_commentPrefix << " "; - for (RifEclipseOutputTableColumn& column : m_columns) + for (size_t i = 0u; i < m_columns.size(); ++i) { - m_out << formatColumn(column.title, column); + QString colTitle = m_columns[i].title; + if (i == 0u) + { + colTitle = m_commentPrefix + " " + colTitle; + } + m_out << formatColumn(colTitle, i); } m_out << "\n"; } @@ -112,7 +124,7 @@ void RifEclipseDataTableFormatter::outputBuffer() for (size_t i = 0; i < line.data.size(); ++i) { - m_out << formatColumn(line.data[i], m_columns[i]); + m_out << formatColumn(line.data[i], i); } m_out << (line.appendTextSet ? line.appendText : m_tableRowAppendText) << "\n"; @@ -234,9 +246,15 @@ RifEclipseDataTableFormatter& RifEclipseDataTableFormatter::header(const std::ve { outputBuffer(); m_columns = header; - for (RifEclipseOutputTableColumn& column : m_columns) + + for (size_t colNumber = 0u; colNumber < m_columns.size(); ++colNumber) { - column.width = measure(column.title); + QString colTitle = m_columns[colNumber].title; + if (colNumber == 0u) + { + colTitle = m_commentPrefix + " " + colTitle; + } + m_columns[colNumber].width = measure(colTitle); } return *this; } @@ -425,9 +443,9 @@ int RifEclipseDataTableFormatter::tableWidth() const { int characterCount = 0; - for (const auto& col : m_columns) + for (size_t i = 0u; i < m_columns.size(); ++i) { - characterCount += formatColumn(" ", col).size(); + characterCount += formatColumn(" ", i).size(); } return characterCount; @@ -444,6 +462,8 @@ QString RifEclipseDataTableFormatter::format(double num, RifEclipseOutputTableDo return QString("%1").arg(num, 0, 'f', doubleFormat.width); case RifEclipseOutputTableDoubleFormat::RIF_SCIENTIFIC: return QString("%1").arg(num, 0, 'E'); + case RifEclipseOutputTableDoubleFormat::RIF_CONSISE: + return QString("%1").arg(num, doubleFormat.width, 'g'); default: return QString("%1"); } @@ -468,14 +488,18 @@ QString RifEclipseDataTableFormatter::format(size_t num) //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -QString RifEclipseDataTableFormatter::formatColumn(const QString str, RifEclipseOutputTableColumn column) const +QString RifEclipseDataTableFormatter::formatColumn(const QString str, size_t columnIndex) const { + const RifEclipseOutputTableColumn& column = m_columns[columnIndex]; + if (column.alignment == LEFT) { - return str.leftJustified(column.width + m_colSpacing, ' '); + int colSpacing = (columnIndex == m_columns.size() - 1) ? 0 : m_colSpacing; + return str.leftJustified(column.width + colSpacing, ' '); } else { - return str.rightJustified(column.width + m_colSpacing, ' '); + int colSpacing = (columnIndex == 0) ? 0 : m_colSpacing; + return str.rightJustified(column.width + colSpacing, ' '); } } diff --git a/ApplicationCode/FileInterface/RifEclipseDataTableFormatter.h b/ApplicationCode/FileInterface/RifEclipseDataTableFormatter.h index 3608f966a5..ed3890712c 100644 --- a/ApplicationCode/FileInterface/RifEclipseDataTableFormatter.h +++ b/ApplicationCode/FileInterface/RifEclipseDataTableFormatter.h @@ -49,6 +49,7 @@ enum RifEclipseOutputTableDoubleFormat { RIF_SCIENTIFIC, RIF_FLOAT, + RIF_CONSISE }; //================================================================================================== @@ -110,6 +111,7 @@ public: int columnSpacing() const; void setColumnSpacing(int spacing); + QString tableRowPrependText() const; void setTableRowPrependText(const QString& text); void setTableRowLineAppendText(const QString& text); void setCommentPrefix(const QString& commentPrefix); @@ -142,7 +144,7 @@ private: QString format(double num, RifEclipseOutputTableDoubleFormatting doubleFormat); QString format(int num); QString format(size_t num); - QString formatColumn(const QString str, RifEclipseOutputTableColumn column) const; + QString formatColumn(const QString str, size_t columnIndex) const; void outputBuffer(); void outputComment(RifEclipseOutputTableLine& comment);