mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
#2797 Ensemble curves. Support for text ensemble parameters. Unit test
This commit is contained in:
parent
736277e0ef
commit
92fd4183a9
@ -139,7 +139,7 @@ bool RiaDateStringParser::tryParseMonthFirst(const std::string& s, int& year, in
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RiaDateStringParser::tryParseYear(const std::string& s, int &year)
|
||||
{
|
||||
if (containsAlphabetic(s)) return false;
|
||||
if (RiaStdStringTools::containsAlphabetic(s)) return false;
|
||||
|
||||
auto today = QDate::currentDate();
|
||||
int y = RiaStdStringTools::toInt(s);
|
||||
@ -158,7 +158,7 @@ bool RiaDateStringParser::tryParseYear(const std::string& s, int &year)
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RiaDateStringParser::tryParseMonth(const std::string& s, int &month)
|
||||
{
|
||||
if (containsAlphabetic(s))
|
||||
if (RiaStdStringTools::containsAlphabetic(s))
|
||||
{
|
||||
auto sMonth = s;
|
||||
sMonth = trimString(sMonth);
|
||||
@ -190,7 +190,7 @@ bool RiaDateStringParser::tryParseMonth(const std::string& s, int &month)
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RiaDateStringParser::tryParseDay(const std::string& s, int &day)
|
||||
{
|
||||
if (containsAlphabetic(s)) return false;
|
||||
if (RiaStdStringTools::containsAlphabetic(s)) return false;
|
||||
|
||||
int d = RiaStdStringTools::toInt(s);
|
||||
if (d >= 1 && d <= 31)
|
||||
@ -203,14 +203,6 @@ bool RiaDateStringParser::tryParseDay(const std::string& s, int &day)
|
||||
return false;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RiaDateStringParser::containsAlphabetic(const std::string& s)
|
||||
{
|
||||
return std::find_if(s.begin(), s.end(), [](char c) { return isalpha(c); }) != s.end();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
@ -42,7 +42,6 @@ private:
|
||||
static bool tryParseMonth(const std::string& s, int &month);
|
||||
static bool tryParseDay(const std::string& s, int &day);
|
||||
|
||||
static bool containsAlphabetic(const std::string& s);
|
||||
static std::string trimString(const std::string& s);
|
||||
};
|
||||
|
||||
|
@ -76,6 +76,24 @@ double RiaStdStringTools::toDouble(const std::string& s)
|
||||
return doubleValue;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RiaStdStringTools::containsAlphabetic(const std::string& s)
|
||||
{
|
||||
return std::find_if(s.begin(), s.end(), [](char c) { return isalpha(c); }) != s.end();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RiaStdStringTools::startsWithAlphabetic(const std::string& s)
|
||||
{
|
||||
if (s.empty()) return false;
|
||||
|
||||
return isalpha(s[0]);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
@ -35,6 +35,8 @@ public:
|
||||
|
||||
static int toInt(const std::string& s);
|
||||
static double toDouble(const std::string& s);
|
||||
static bool containsAlphabetic(const std::string& s);
|
||||
static bool startsWithAlphabetic(const std::string& s);
|
||||
|
||||
static std::vector<std::string> splitStringBySpace(const std::string& s);
|
||||
|
||||
|
@ -108,14 +108,14 @@ bool RicImportEnsembleFeature::validateEnsembleCases(std::vector<RimSummaryCase*
|
||||
|
||||
for (RimSummaryCase* rimCase : cases)
|
||||
{
|
||||
if (rimCase->caseRealizationParameters().isNull() || rimCase->caseRealizationParameters()->parameters().empty())
|
||||
if (rimCase->caseRealizationParameters() == nullptr || rimCase->caseRealizationParameters()->parameters().empty())
|
||||
{
|
||||
errors.append(QString("The case %1 has no ensemble parameters\n").arg(QFileInfo(rimCase->summaryHeaderFilename()).fileName()));
|
||||
}
|
||||
else
|
||||
{
|
||||
QString paramNames;
|
||||
for (std::pair<QString, double> paramPair : rimCase->caseRealizationParameters()->parameters())
|
||||
for (std::pair<QString, RigCaseRealizationParameters::Value> paramPair : rimCase->caseRealizationParameters()->parameters())
|
||||
{
|
||||
paramNames.append(paramPair.first);
|
||||
}
|
||||
|
@ -38,7 +38,7 @@
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RifCaseRealizationParametersReader::RifCaseRealizationParametersReader(const QString& fileName)
|
||||
{
|
||||
m_parameters = new RigCaseRealizationParameters();
|
||||
m_parameters = std::shared_ptr<RigCaseRealizationParameters>(new RigCaseRealizationParameters());
|
||||
m_fileName = fileName;
|
||||
m_file = nullptr;
|
||||
m_textStream = nullptr;
|
||||
@ -49,7 +49,7 @@ RifCaseRealizationParametersReader::RifCaseRealizationParametersReader(const QSt
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RifCaseRealizationParametersReader::RifCaseRealizationParametersReader()
|
||||
{
|
||||
m_parameters = new RigCaseRealizationParameters();
|
||||
m_parameters = std::shared_ptr<RigCaseRealizationParameters>(new RigCaseRealizationParameters());
|
||||
m_fileName = "";
|
||||
m_file = nullptr;
|
||||
m_textStream = nullptr;
|
||||
@ -100,19 +100,26 @@ void RifCaseRealizationParametersReader::parse()
|
||||
QString& name = cols[0];
|
||||
QString& strValue = cols[1];
|
||||
|
||||
if (!RiaStdStringTools::isNumber(strValue.toStdString(), QLocale::c().decimalPoint().toAscii()))
|
||||
if (RiaStdStringTools::startsWithAlphabetic(strValue.toStdString()))
|
||||
{
|
||||
throw FileParseException(QString("RifEnsembleParametersReader: Invalid number format in line %1").arg(lineNo));
|
||||
m_parameters->addParameter(name, strValue);
|
||||
}
|
||||
|
||||
bool parseOk = true;
|
||||
double value = QLocale::c().toDouble(strValue, &parseOk);
|
||||
if (!parseOk)
|
||||
else
|
||||
{
|
||||
throw FileParseException(QString("RifEnsembleParametersReader: Invalid number format in line %1").arg(lineNo));
|
||||
}
|
||||
if (!RiaStdStringTools::isNumber(strValue.toStdString(), QLocale::c().decimalPoint().toAscii()))
|
||||
{
|
||||
throw FileParseException(QString("RifEnsembleParametersReader: Invalid number format in line %1").arg(lineNo));
|
||||
}
|
||||
|
||||
m_parameters->addParameter(name, value);
|
||||
bool parseOk = true;
|
||||
double value = QLocale::c().toDouble(strValue, &parseOk);
|
||||
if (!parseOk)
|
||||
{
|
||||
throw FileParseException(QString("RifEnsembleParametersReader: Invalid number format in line %1").arg(lineNo));
|
||||
}
|
||||
|
||||
m_parameters->addParameter(name, value);
|
||||
}
|
||||
}
|
||||
|
||||
closeDataStream();
|
||||
@ -182,7 +189,7 @@ void RifCaseRealizationParametersReader::closeFile()
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
const cvf::ref<RigCaseRealizationParameters> RifCaseRealizationParametersReader::parameters() const
|
||||
const std::shared_ptr<RigCaseRealizationParameters> RifCaseRealizationParametersReader::parameters() const
|
||||
{
|
||||
return m_parameters;
|
||||
}
|
||||
|
@ -30,6 +30,7 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
|
||||
class QStringList;
|
||||
class QTextStream;
|
||||
@ -46,9 +47,9 @@ public:
|
||||
RifCaseRealizationParametersReader(const QString& fileName);
|
||||
~RifCaseRealizationParametersReader();
|
||||
|
||||
void setFileName(const QString& fileName);
|
||||
void parse();
|
||||
const cvf::ref<RigCaseRealizationParameters> parameters() const;
|
||||
void setFileName(const QString& fileName);
|
||||
void parse();
|
||||
const std::shared_ptr<RigCaseRealizationParameters> parameters() const;
|
||||
|
||||
private:
|
||||
QTextStream* openDataStream();
|
||||
@ -56,7 +57,7 @@ private:
|
||||
void openFile();
|
||||
void closeFile();
|
||||
private:
|
||||
cvf::ref<RigCaseRealizationParameters> m_parameters;
|
||||
std::shared_ptr<RigCaseRealizationParameters> m_parameters;
|
||||
|
||||
QString m_fileName;
|
||||
QFile* m_file;
|
||||
|
@ -51,7 +51,7 @@
|
||||
#include "cvfqtUtils.h"
|
||||
|
||||
#include <cmath>
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
CAF_PDM_SOURCE_INIT(RimRegularLegendConfig, "Legend");
|
||||
|
||||
@ -153,6 +153,36 @@ RimRegularLegendConfig::~RimRegularLegendConfig()
|
||||
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimRegularLegendConfig::setNamedCategories(const std::vector<QString>& categoryNames, bool inverse)
|
||||
{
|
||||
std::list<int> nameIndices;
|
||||
std::list<cvf::String> names;
|
||||
|
||||
int categoriesCount = static_cast<int>(categoryNames.size());
|
||||
for (int i = 0; i < categoriesCount; i++)
|
||||
{
|
||||
if (!inverse)
|
||||
{
|
||||
nameIndices.push_back(i);
|
||||
names.push_back(cvfqt::Utils::toString(categoryNames[i]));
|
||||
}
|
||||
else
|
||||
{
|
||||
nameIndices.push_front(i);
|
||||
names.push_front(cvfqt::Utils::toString(categoryNames[i]));
|
||||
}
|
||||
}
|
||||
|
||||
m_categories = std::vector<int>(nameIndices.begin(), nameIndices.end());
|
||||
m_categoryNames = std::vector<cvf::String>(names.begin(), names.end());
|
||||
m_categoryColors.clear();
|
||||
|
||||
updateLegend();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@ -582,24 +612,20 @@ void RimRegularLegendConfig::setIntegerCategories(const std::vector<int>& catego
|
||||
updateLegend();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimRegularLegendConfig::setNamedCategories(const std::vector<QString>& categoryNames)
|
||||
{
|
||||
setNamedCategories(categoryNames, false);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimRegularLegendConfig::setNamedCategoriesInverse(const std::vector<QString>& categoryNames)
|
||||
{
|
||||
std::vector<int> nameIndices;
|
||||
std::vector<cvf::String> names;
|
||||
for(int i = static_cast<int>(categoryNames.size()) - 1; i >= 0; --i)
|
||||
{
|
||||
nameIndices.push_back(i);
|
||||
names.push_back(cvfqt::Utils::toString(categoryNames[i]));
|
||||
}
|
||||
|
||||
m_categories = nameIndices;
|
||||
m_categoryNames = names;
|
||||
m_categoryColors.clear();
|
||||
|
||||
updateLegend();
|
||||
setNamedCategories(categoryNames, true);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@ -643,6 +669,21 @@ QString RimRegularLegendConfig::categoryNameFromCategoryValue(double categoryRes
|
||||
return QString("%1").arg(categoryResultValue);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
double RimRegularLegendConfig::categoryValueFromCategoryName(const QString& categoryName) const
|
||||
{
|
||||
for (int i = 0; i < m_categoryNames.size(); i++)
|
||||
{
|
||||
if (cvfqt::Utils::toQString(m_categoryNames[i]).compare(categoryName, Qt::CaseInsensitive) == 0)
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return HUGE_VAL;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@ -797,7 +838,8 @@ QList<caf::PdmOptionItemInfo> RimRegularLegendConfig::calculateValueOptions(cons
|
||||
|
||||
if ( ( eclCellColors && eclCellColors->hasCategoryResult())
|
||||
|| ( gmCellColors && gmCellColors->hasCategoryResult())
|
||||
|| ( eclCellEdgColors && eclCellEdgColors->hasCategoryResult()) )
|
||||
|| ( eclCellEdgColors && eclCellEdgColors->hasCategoryResult())
|
||||
|| ( ensembleCurveSet && ensembleCurveSet->currentEnsembleParameterType() == RimEnsembleCurveSet::TYPE_TEXT) )
|
||||
{
|
||||
isCategoryResult = true;
|
||||
}
|
||||
|
@ -102,9 +102,11 @@ public:
|
||||
void setClosestToZeroValues(double globalPosClosestToZero, double globalNegClosestToZero, double localPosClosestToZero, double localNegClosestToZero);
|
||||
|
||||
void setIntegerCategories(const std::vector<int>& categories);
|
||||
void setNamedCategories(const std::vector<QString>& categoryNames);
|
||||
void setNamedCategoriesInverse(const std::vector<QString>& categoryNames);
|
||||
void setCategoryItems(const std::vector<std::tuple<QString, int, cvf::Color3ub>>& categories);
|
||||
QString categoryNameFromCategoryValue(double categoryResultValue) const;
|
||||
double categoryValueFromCategoryName(const QString& categoryName) const;
|
||||
|
||||
void setTitle(const QString& title);
|
||||
|
||||
@ -117,6 +119,7 @@ public:
|
||||
caf::TitledOverlayFrame* titledOverlayFrame() override;
|
||||
|
||||
private:
|
||||
void setNamedCategories(const std::vector<QString>& categoryNames, bool inverse);
|
||||
void fieldChangedByUi(const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue) override;
|
||||
void initAfterRead() override;
|
||||
caf::PdmFieldHandle* objectToggleField() override;
|
||||
|
@ -336,6 +336,27 @@ RimEnsembleCurveSet::ColorMode RimEnsembleCurveSet::colorMode() const
|
||||
return m_colorMode();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RimEnsembleCurveSet::EnsembleParameterType RimEnsembleCurveSet::currentEnsembleParameterType() const
|
||||
{
|
||||
if (m_colorMode() == BY_ENSEMBLE_PARAM)
|
||||
{
|
||||
RimSummaryCaseCollection* group = m_yValuesSummaryGroup();
|
||||
QString parameterName = m_ensembleParameter();
|
||||
|
||||
if (group && !parameterName.isEmpty() && !group->allSummaryCases().empty())
|
||||
{
|
||||
bool isTextParameter = group->allSummaryCases().front()->caseRealizationParameters() != nullptr ?
|
||||
group->allSummaryCases().front()->caseRealizationParameters()->parameterValue(parameterName).isText() : false;
|
||||
|
||||
return isTextParameter ? TYPE_TEXT : TYPE_NUMERIC;
|
||||
}
|
||||
}
|
||||
return TYPE_NONE;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@ -367,11 +388,15 @@ void RimEnsembleCurveSet::fieldChangedByUi(const caf::PdmFieldHandle* changedFie
|
||||
m_allAddressesCache.clear();
|
||||
updateAllCurves();
|
||||
}
|
||||
else if (changedField == &m_ensembleParameter ||
|
||||
changedField == &m_color)
|
||||
else if (changedField == &m_color)
|
||||
{
|
||||
updateCurveColors();
|
||||
}
|
||||
else if (changedField == &m_ensembleParameter)
|
||||
{
|
||||
updateLegendMappingMode();
|
||||
updateCurveColors();
|
||||
}
|
||||
else if (changedField == &m_colorMode)
|
||||
{
|
||||
if (m_ensembleParameter().isEmpty())
|
||||
@ -615,32 +640,75 @@ void RimEnsembleCurveSet::updateCurveColors()
|
||||
m_legendConfig->setTitle(legendTitle);
|
||||
}
|
||||
|
||||
if (group && !parameterName.isEmpty())
|
||||
if (group && !parameterName.isEmpty() && !group->allSummaryCases().empty())
|
||||
{
|
||||
double minValue = std::numeric_limits<double>::infinity();
|
||||
double maxValue = -std::numeric_limits<double>::infinity();
|
||||
bool isTextParameter = group->allSummaryCases().front()->caseRealizationParameters() != nullptr ?
|
||||
group->allSummaryCases().front()->caseRealizationParameters()->parameterValue(parameterName).isText() : false;
|
||||
|
||||
for (RimSummaryCase* rimCase : group->allSummaryCases())
|
||||
if (isTextParameter)
|
||||
{
|
||||
if (!rimCase->caseRealizationParameters().isNull())
|
||||
std::set<QString> categories;
|
||||
|
||||
for (RimSummaryCase* rimCase : group->allSummaryCases())
|
||||
{
|
||||
double value = rimCase->caseRealizationParameters()->parameterValue(parameterName);
|
||||
if (value != std::numeric_limits<double>::infinity())
|
||||
if (rimCase->caseRealizationParameters() != nullptr)
|
||||
{
|
||||
if (value < minValue) minValue = value;
|
||||
if (value > maxValue) maxValue = value;
|
||||
RigCaseRealizationParameters::Value value = rimCase->caseRealizationParameters()->parameterValue(parameterName);
|
||||
if (value.isText())
|
||||
{
|
||||
categories.insert(value.textValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<QString> categoryNames = std::vector<QString>(categories.begin(), categories.end());
|
||||
m_legendConfig->setNamedCategories(categoryNames);
|
||||
m_legendConfig->setAutomaticRanges(0, categoryNames.size() - 1, 0, categoryNames.size() - 1);
|
||||
|
||||
for (auto& curve : m_curves)
|
||||
{
|
||||
RimSummaryCase* rimCase = curve->summaryCaseY();
|
||||
QString tValue = rimCase->caseRealizationParameters()->parameterValue(parameterName).textValue();
|
||||
double nValue = m_legendConfig->categoryValueFromCategoryName(tValue);
|
||||
if (nValue != HUGE_VAL)
|
||||
{
|
||||
int iValue = static_cast<int>(nValue);
|
||||
curve->setColor(cvf::Color3f(m_legendConfig->scalarMapper()->mapToColor(iValue)));
|
||||
}
|
||||
curve->updateCurveAppearance();
|
||||
}
|
||||
}
|
||||
|
||||
m_legendConfig->setAutomaticRanges(minValue, maxValue, minValue, maxValue);
|
||||
|
||||
for (auto& curve : m_curves)
|
||||
else
|
||||
{
|
||||
RimSummaryCase* rimCase = curve->summaryCaseY();
|
||||
double value = rimCase->caseRealizationParameters()->parameterValue(parameterName);
|
||||
curve->setColor(cvf::Color3f(m_legendConfig->scalarMapper()->mapToColor(value)));
|
||||
curve->updateCurveAppearance();
|
||||
double minValue = std::numeric_limits<double>::infinity();
|
||||
double maxValue = -std::numeric_limits<double>::infinity();
|
||||
|
||||
for (RimSummaryCase* rimCase : group->allSummaryCases())
|
||||
{
|
||||
if (rimCase->caseRealizationParameters() != nullptr)
|
||||
{
|
||||
RigCaseRealizationParameters::Value value = rimCase->caseRealizationParameters()->parameterValue(parameterName);
|
||||
if (value.isNumeric())
|
||||
{
|
||||
double nValue = value.numericValue();
|
||||
if (nValue != std::numeric_limits<double>::infinity())
|
||||
{
|
||||
if (nValue < minValue) minValue = nValue;
|
||||
if (nValue > maxValue) maxValue = nValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
m_legendConfig->setAutomaticRanges(minValue, maxValue, minValue, maxValue);
|
||||
|
||||
for (auto& curve : m_curves)
|
||||
{
|
||||
RimSummaryCase* rimCase = curve->summaryCaseY();
|
||||
double value = rimCase->caseRealizationParameters()->parameterValue(parameterName).numericValue();
|
||||
curve->setColor(cvf::Color3f(m_legendConfig->scalarMapper()->mapToColor(value)));
|
||||
curve->updateCurveAppearance();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -737,7 +805,7 @@ std::vector<QString> RimEnsembleCurveSet::ensembleParameters() const
|
||||
{
|
||||
for (RimSummaryCase* rimCase : group->allSummaryCases())
|
||||
{
|
||||
if (!rimCase->caseRealizationParameters().isNull())
|
||||
if (rimCase->caseRealizationParameters() != nullptr)
|
||||
{
|
||||
auto ps = rimCase->caseRealizationParameters()->parameters();
|
||||
for (auto p : ps) paramSet.insert(p.first);
|
||||
@ -768,3 +836,22 @@ QString RimEnsembleCurveSet::createAutoName() const
|
||||
|
||||
return curveSetName;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimEnsembleCurveSet::updateLegendMappingMode()
|
||||
{
|
||||
switch (currentEnsembleParameterType())
|
||||
{
|
||||
case TYPE_TEXT:
|
||||
if (m_legendConfig->mappingMode() != RimRegularLegendConfig::MappingType::CATEGORY_INTEGER)
|
||||
m_legendConfig->setMappingMode(RimRegularLegendConfig::MappingType::CATEGORY_INTEGER);
|
||||
break;
|
||||
|
||||
case TYPE_NUMERIC:
|
||||
if (m_legendConfig->mappingMode() == RimRegularLegendConfig::MappingType::CATEGORY_INTEGER)
|
||||
m_legendConfig->setMappingMode(RimRegularLegendConfig::MappingType::LINEAR_CONTINUOUS);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -57,6 +57,7 @@ class RimEnsembleCurveSet : public caf::PdmObject
|
||||
|
||||
public:
|
||||
enum ColorMode {SINGLE_COLOR, BY_ENSEMBLE_PARAM};
|
||||
enum EnsembleParameterType {TYPE_NONE, TYPE_NUMERIC, TYPE_TEXT};
|
||||
|
||||
RimEnsembleCurveSet();
|
||||
virtual ~RimEnsembleCurveSet();
|
||||
@ -85,6 +86,7 @@ public:
|
||||
RimSummaryCaseCollection* summaryCaseCollection() const;
|
||||
|
||||
ColorMode colorMode() const;
|
||||
EnsembleParameterType currentEnsembleParameterType() const;
|
||||
|
||||
private:
|
||||
caf::PdmFieldHandle* userDescriptionField() override;
|
||||
@ -113,6 +115,7 @@ private:
|
||||
|
||||
QString createAutoName() const;
|
||||
|
||||
void updateLegendMappingMode();
|
||||
|
||||
private:
|
||||
caf::PdmField<bool> m_showCurves;
|
||||
|
@ -86,7 +86,7 @@ bool RimSummaryCase::isObservedData()
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimSummaryCase::setCaseRealizationParameters(cvf::ref<RigCaseRealizationParameters> crlParameters)
|
||||
void RimSummaryCase::setCaseRealizationParameters(const std::shared_ptr<RigCaseRealizationParameters>& crlParameters)
|
||||
{
|
||||
m_crlParameters = crlParameters;
|
||||
}
|
||||
@ -94,7 +94,7 @@ void RimSummaryCase::setCaseRealizationParameters(cvf::ref<RigCaseRealizationPar
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
cvf::ref<RigCaseRealizationParameters> RimSummaryCase::caseRealizationParameters() const
|
||||
std::shared_ptr<RigCaseRealizationParameters> RimSummaryCase::caseRealizationParameters() const
|
||||
{
|
||||
return m_crlParameters;
|
||||
}
|
||||
|
@ -22,6 +22,8 @@
|
||||
#include "cafPdmField.h"
|
||||
#include "cafPdmObject.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
class RifSummaryReaderInterface;
|
||||
|
||||
//==================================================================================================
|
||||
@ -54,8 +56,8 @@ public:
|
||||
|
||||
bool isObservedData();
|
||||
|
||||
void setCaseRealizationParameters(cvf::ref<RigCaseRealizationParameters> crlParameters);
|
||||
cvf::ref<RigCaseRealizationParameters> caseRealizationParameters() const;
|
||||
void setCaseRealizationParameters(const std::shared_ptr<RigCaseRealizationParameters>& crlParameters);
|
||||
std::shared_ptr<RigCaseRealizationParameters> caseRealizationParameters() const;
|
||||
|
||||
protected:
|
||||
virtual void fieldChangedByUi(const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue);
|
||||
@ -66,7 +68,7 @@ protected:
|
||||
caf::PdmField<QString> m_summaryHeaderFilename;
|
||||
bool m_isObservedData;
|
||||
|
||||
cvf::ref<RigCaseRealizationParameters> m_crlParameters;
|
||||
std::shared_ptr<RigCaseRealizationParameters> m_crlParameters;
|
||||
|
||||
private:
|
||||
virtual void initAfterRead() override;
|
||||
|
@ -22,15 +22,81 @@
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RigCaseRealizationParameters::addParameter(const QString& name, double value)
|
||||
RigCaseRealizationParameters::Value::Value() : m_valueType(TYPE_NONE), m_numericValue(HUGE_VAL)
|
||||
{
|
||||
m_parameters[name] = value;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
double RigCaseRealizationParameters::parameterValue(const QString& name)
|
||||
RigCaseRealizationParameters::Value::Value(double value) : Value()
|
||||
{
|
||||
setValue(value);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RigCaseRealizationParameters::Value::Value(const QString& value) : Value()
|
||||
{
|
||||
setValue(value);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RigCaseRealizationParameters::Value::setValue(double value)
|
||||
{
|
||||
m_valueType = TYPE_NUMERIC;
|
||||
m_numericValue = value;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RigCaseRealizationParameters::Value::setValue(const QString& value)
|
||||
{
|
||||
m_valueType = TYPE_TEXT;
|
||||
m_textValue = value;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
double RigCaseRealizationParameters::Value::numericValue() const
|
||||
{
|
||||
return m_numericValue;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
const QString& RigCaseRealizationParameters::Value::textValue() const
|
||||
{
|
||||
return m_textValue;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RigCaseRealizationParameters::addParameter(const QString& name, double value)
|
||||
{
|
||||
m_parameters[name].setValue(value);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RigCaseRealizationParameters::addParameter(const QString& name, const QString& value)
|
||||
{
|
||||
m_parameters[name].setValue(value);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RigCaseRealizationParameters::Value RigCaseRealizationParameters::parameterValue(const QString& name)
|
||||
{
|
||||
if (m_parameters.count(name) == 0) return HUGE_VAL;
|
||||
return m_parameters[name];
|
||||
@ -39,7 +105,7 @@ double RigCaseRealizationParameters::parameterValue(const QString& name)
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::map<QString, double> RigCaseRealizationParameters::parameters() const
|
||||
std::map<QString, RigCaseRealizationParameters::Value> RigCaseRealizationParameters::parameters() const
|
||||
{
|
||||
return m_parameters;
|
||||
}
|
||||
|
@ -31,14 +31,41 @@
|
||||
//
|
||||
//
|
||||
//==================================================================================================
|
||||
class RigCaseRealizationParameters : public cvf::Object
|
||||
class RigCaseRealizationParameters
|
||||
{
|
||||
public:
|
||||
void addParameter(const QString& name, double value);
|
||||
double parameterValue(const QString& name);
|
||||
// Internal class
|
||||
class Value
|
||||
{
|
||||
enum ValueType { TYPE_NONE, TYPE_NUMERIC, TYPE_TEXT };
|
||||
|
||||
std::map<QString, double> parameters() const;
|
||||
public:
|
||||
Value();
|
||||
Value(double value);
|
||||
Value(const QString& value);
|
||||
|
||||
void setValue(double value);
|
||||
void setValue(const QString& value);
|
||||
|
||||
bool isEmpty() const { return m_valueType == TYPE_NONE; }
|
||||
bool isNumeric() const { return m_valueType == TYPE_NUMERIC; }
|
||||
bool isText() const { return m_valueType == TYPE_TEXT; }
|
||||
|
||||
double numericValue() const;
|
||||
const QString& textValue() const;
|
||||
|
||||
private:
|
||||
ValueType m_valueType;
|
||||
double m_numericValue;
|
||||
QString m_textValue;
|
||||
};
|
||||
|
||||
void addParameter(const QString& name, double value);
|
||||
void addParameter(const QString& name, const QString& value);
|
||||
Value parameterValue(const QString& name);
|
||||
|
||||
std::map<QString, Value> parameters() const;
|
||||
|
||||
private:
|
||||
std::map<QString, double> m_parameters;
|
||||
std::map<QString, Value> m_parameters;
|
||||
};
|
||||
|
@ -42,16 +42,20 @@ TEST(RifCaseRealizationParametersReaderTest, SuccessfulParsing)
|
||||
{
|
||||
reader.parse();
|
||||
|
||||
const cvf::ref<RigCaseRealizationParameters> parameters = reader.parameters();
|
||||
std::map<QString, double> params = parameters->parameters();
|
||||
const std::shared_ptr<RigCaseRealizationParameters> parameters(reader.parameters());
|
||||
std::map<QString, RigCaseRealizationParameters::Value> params = parameters->parameters();
|
||||
|
||||
EXPECT_EQ(1U, params.count("LETSWOF:L_1OW"));
|
||||
EXPECT_EQ(1U, params.count("LETSGOF:KRG1"));
|
||||
EXPECT_EQ(1U, params.count("LOG10_MULTFLT:MULTFLT_F1"));
|
||||
EXPECT_EQ(1U, params.count("TST:TEXT_PARAM"));
|
||||
|
||||
EXPECT_EQ(1.83555, params["LETSWOF:L_1OW"]);
|
||||
EXPECT_EQ(0.97, params["LETSGOF:KRG1"]);
|
||||
EXPECT_EQ(-0.168356, params["LOG10_MULTFLT:MULTFLT_F1"]);
|
||||
EXPECT_TRUE(params["LETSWOF:L_1OW"].isNumeric());
|
||||
EXPECT_EQ(1.83555, params["LETSWOF:L_1OW"].numericValue());
|
||||
EXPECT_TRUE(params["LETSGOF:KRG1"].isNumeric());
|
||||
EXPECT_EQ(0.97, params["LETSGOF:KRG1"].numericValue());
|
||||
EXPECT_TRUE(params["TST:TEXT_PARAM"].isText());
|
||||
EXPECT_EQ(std::string("YES"), params["TST:TEXT_PARAM"].textValue().toStdString());
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
|
@ -26,4 +26,5 @@ LETSGOF:L_1OG 3.90509
|
||||
LETSGOF:E_1OG 4.00383
|
||||
LETSGOF:T_1OG 1.03539
|
||||
LETSGOF:SORG1 0.34
|
||||
TST:TEXT_PARAM YES
|
||||
LETSGOF:KRG1 0.97
|
||||
|
Loading…
Reference in New Issue
Block a user