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)
|
bool RiaDateStringParser::tryParseYear(const std::string& s, int &year)
|
||||||
{
|
{
|
||||||
if (containsAlphabetic(s)) return false;
|
if (RiaStdStringTools::containsAlphabetic(s)) return false;
|
||||||
|
|
||||||
auto today = QDate::currentDate();
|
auto today = QDate::currentDate();
|
||||||
int y = RiaStdStringTools::toInt(s);
|
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)
|
bool RiaDateStringParser::tryParseMonth(const std::string& s, int &month)
|
||||||
{
|
{
|
||||||
if (containsAlphabetic(s))
|
if (RiaStdStringTools::containsAlphabetic(s))
|
||||||
{
|
{
|
||||||
auto sMonth = s;
|
auto sMonth = s;
|
||||||
sMonth = trimString(sMonth);
|
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)
|
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);
|
int d = RiaStdStringTools::toInt(s);
|
||||||
if (d >= 1 && d <= 31)
|
if (d >= 1 && d <= 31)
|
||||||
@ -203,14 +203,6 @@ bool RiaDateStringParser::tryParseDay(const std::string& s, int &day)
|
|||||||
return false;
|
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 tryParseMonth(const std::string& s, int &month);
|
||||||
static bool tryParseDay(const std::string& s, int &day);
|
static bool tryParseDay(const std::string& s, int &day);
|
||||||
|
|
||||||
static bool containsAlphabetic(const std::string& s);
|
|
||||||
static std::string trimString(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;
|
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 int toInt(const std::string& s);
|
||||||
static double toDouble(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);
|
static std::vector<std::string> splitStringBySpace(const std::string& s);
|
||||||
|
|
||||||
|
@ -108,14 +108,14 @@ bool RicImportEnsembleFeature::validateEnsembleCases(std::vector<RimSummaryCase*
|
|||||||
|
|
||||||
for (RimSummaryCase* rimCase : cases)
|
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()));
|
errors.append(QString("The case %1 has no ensemble parameters\n").arg(QFileInfo(rimCase->summaryHeaderFilename()).fileName()));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
QString paramNames;
|
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);
|
paramNames.append(paramPair.first);
|
||||||
}
|
}
|
||||||
|
@ -38,7 +38,7 @@
|
|||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
RifCaseRealizationParametersReader::RifCaseRealizationParametersReader(const QString& fileName)
|
RifCaseRealizationParametersReader::RifCaseRealizationParametersReader(const QString& fileName)
|
||||||
{
|
{
|
||||||
m_parameters = new RigCaseRealizationParameters();
|
m_parameters = std::shared_ptr<RigCaseRealizationParameters>(new RigCaseRealizationParameters());
|
||||||
m_fileName = fileName;
|
m_fileName = fileName;
|
||||||
m_file = nullptr;
|
m_file = nullptr;
|
||||||
m_textStream = nullptr;
|
m_textStream = nullptr;
|
||||||
@ -49,7 +49,7 @@ RifCaseRealizationParametersReader::RifCaseRealizationParametersReader(const QSt
|
|||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
RifCaseRealizationParametersReader::RifCaseRealizationParametersReader()
|
RifCaseRealizationParametersReader::RifCaseRealizationParametersReader()
|
||||||
{
|
{
|
||||||
m_parameters = new RigCaseRealizationParameters();
|
m_parameters = std::shared_ptr<RigCaseRealizationParameters>(new RigCaseRealizationParameters());
|
||||||
m_fileName = "";
|
m_fileName = "";
|
||||||
m_file = nullptr;
|
m_file = nullptr;
|
||||||
m_textStream = nullptr;
|
m_textStream = nullptr;
|
||||||
@ -100,19 +100,26 @@ void RifCaseRealizationParametersReader::parse()
|
|||||||
QString& name = cols[0];
|
QString& name = cols[0];
|
||||||
QString& strValue = cols[1];
|
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);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
bool parseOk = true;
|
|
||||||
double value = QLocale::c().toDouble(strValue, &parseOk);
|
|
||||||
if (!parseOk)
|
|
||||||
{
|
{
|
||||||
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();
|
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;
|
return m_parameters;
|
||||||
}
|
}
|
||||||
|
@ -30,6 +30,7 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
class QStringList;
|
class QStringList;
|
||||||
class QTextStream;
|
class QTextStream;
|
||||||
@ -46,9 +47,9 @@ public:
|
|||||||
RifCaseRealizationParametersReader(const QString& fileName);
|
RifCaseRealizationParametersReader(const QString& fileName);
|
||||||
~RifCaseRealizationParametersReader();
|
~RifCaseRealizationParametersReader();
|
||||||
|
|
||||||
void setFileName(const QString& fileName);
|
void setFileName(const QString& fileName);
|
||||||
void parse();
|
void parse();
|
||||||
const cvf::ref<RigCaseRealizationParameters> parameters() const;
|
const std::shared_ptr<RigCaseRealizationParameters> parameters() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QTextStream* openDataStream();
|
QTextStream* openDataStream();
|
||||||
@ -56,7 +57,7 @@ private:
|
|||||||
void openFile();
|
void openFile();
|
||||||
void closeFile();
|
void closeFile();
|
||||||
private:
|
private:
|
||||||
cvf::ref<RigCaseRealizationParameters> m_parameters;
|
std::shared_ptr<RigCaseRealizationParameters> m_parameters;
|
||||||
|
|
||||||
QString m_fileName;
|
QString m_fileName;
|
||||||
QFile* m_file;
|
QFile* m_file;
|
||||||
|
@ -51,7 +51,7 @@
|
|||||||
#include "cvfqtUtils.h"
|
#include "cvfqtUtils.h"
|
||||||
|
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
CAF_PDM_SOURCE_INIT(RimRegularLegendConfig, "Legend");
|
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();
|
updateLegend();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
void RimRegularLegendConfig::setNamedCategories(const std::vector<QString>& categoryNames)
|
||||||
|
{
|
||||||
|
setNamedCategories(categoryNames, false);
|
||||||
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
///
|
///
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
void RimRegularLegendConfig::setNamedCategoriesInverse(const std::vector<QString>& categoryNames)
|
void RimRegularLegendConfig::setNamedCategoriesInverse(const std::vector<QString>& categoryNames)
|
||||||
{
|
{
|
||||||
std::vector<int> nameIndices;
|
setNamedCategories(categoryNames, true);
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
@ -643,6 +669,21 @@ QString RimRegularLegendConfig::categoryNameFromCategoryValue(double categoryRes
|
|||||||
return QString("%1").arg(categoryResultValue);
|
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())
|
if ( ( eclCellColors && eclCellColors->hasCategoryResult())
|
||||||
|| ( gmCellColors && gmCellColors->hasCategoryResult())
|
|| ( gmCellColors && gmCellColors->hasCategoryResult())
|
||||||
|| ( eclCellEdgColors && eclCellEdgColors->hasCategoryResult()) )
|
|| ( eclCellEdgColors && eclCellEdgColors->hasCategoryResult())
|
||||||
|
|| ( ensembleCurveSet && ensembleCurveSet->currentEnsembleParameterType() == RimEnsembleCurveSet::TYPE_TEXT) )
|
||||||
{
|
{
|
||||||
isCategoryResult = true;
|
isCategoryResult = true;
|
||||||
}
|
}
|
||||||
|
@ -102,9 +102,11 @@ public:
|
|||||||
void setClosestToZeroValues(double globalPosClosestToZero, double globalNegClosestToZero, double localPosClosestToZero, double localNegClosestToZero);
|
void setClosestToZeroValues(double globalPosClosestToZero, double globalNegClosestToZero, double localPosClosestToZero, double localNegClosestToZero);
|
||||||
|
|
||||||
void setIntegerCategories(const std::vector<int>& categories);
|
void setIntegerCategories(const std::vector<int>& categories);
|
||||||
|
void setNamedCategories(const std::vector<QString>& categoryNames);
|
||||||
void setNamedCategoriesInverse(const std::vector<QString>& categoryNames);
|
void setNamedCategoriesInverse(const std::vector<QString>& categoryNames);
|
||||||
void setCategoryItems(const std::vector<std::tuple<QString, int, cvf::Color3ub>>& categories);
|
void setCategoryItems(const std::vector<std::tuple<QString, int, cvf::Color3ub>>& categories);
|
||||||
QString categoryNameFromCategoryValue(double categoryResultValue) const;
|
QString categoryNameFromCategoryValue(double categoryResultValue) const;
|
||||||
|
double categoryValueFromCategoryName(const QString& categoryName) const;
|
||||||
|
|
||||||
void setTitle(const QString& title);
|
void setTitle(const QString& title);
|
||||||
|
|
||||||
@ -117,6 +119,7 @@ public:
|
|||||||
caf::TitledOverlayFrame* titledOverlayFrame() override;
|
caf::TitledOverlayFrame* titledOverlayFrame() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void setNamedCategories(const std::vector<QString>& categoryNames, bool inverse);
|
||||||
void fieldChangedByUi(const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue) override;
|
void fieldChangedByUi(const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue) override;
|
||||||
void initAfterRead() override;
|
void initAfterRead() override;
|
||||||
caf::PdmFieldHandle* objectToggleField() override;
|
caf::PdmFieldHandle* objectToggleField() override;
|
||||||
|
@ -336,6 +336,27 @@ RimEnsembleCurveSet::ColorMode RimEnsembleCurveSet::colorMode() const
|
|||||||
return m_colorMode();
|
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();
|
m_allAddressesCache.clear();
|
||||||
updateAllCurves();
|
updateAllCurves();
|
||||||
}
|
}
|
||||||
else if (changedField == &m_ensembleParameter ||
|
else if (changedField == &m_color)
|
||||||
changedField == &m_color)
|
|
||||||
{
|
{
|
||||||
updateCurveColors();
|
updateCurveColors();
|
||||||
}
|
}
|
||||||
|
else if (changedField == &m_ensembleParameter)
|
||||||
|
{
|
||||||
|
updateLegendMappingMode();
|
||||||
|
updateCurveColors();
|
||||||
|
}
|
||||||
else if (changedField == &m_colorMode)
|
else if (changedField == &m_colorMode)
|
||||||
{
|
{
|
||||||
if (m_ensembleParameter().isEmpty())
|
if (m_ensembleParameter().isEmpty())
|
||||||
@ -615,32 +640,75 @@ void RimEnsembleCurveSet::updateCurveColors()
|
|||||||
m_legendConfig->setTitle(legendTitle);
|
m_legendConfig->setTitle(legendTitle);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (group && !parameterName.isEmpty())
|
if (group && !parameterName.isEmpty() && !group->allSummaryCases().empty())
|
||||||
{
|
{
|
||||||
double minValue = std::numeric_limits<double>::infinity();
|
bool isTextParameter = group->allSummaryCases().front()->caseRealizationParameters() != nullptr ?
|
||||||
double maxValue = -std::numeric_limits<double>::infinity();
|
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 (rimCase->caseRealizationParameters() != nullptr)
|
||||||
if (value != std::numeric_limits<double>::infinity())
|
|
||||||
{
|
{
|
||||||
if (value < minValue) minValue = value;
|
RigCaseRealizationParameters::Value value = rimCase->caseRealizationParameters()->parameterValue(parameterName);
|
||||||
if (value > maxValue) maxValue = value;
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
m_legendConfig->setAutomaticRanges(minValue, maxValue, minValue, maxValue);
|
|
||||||
|
|
||||||
for (auto& curve : m_curves)
|
|
||||||
{
|
{
|
||||||
RimSummaryCase* rimCase = curve->summaryCaseY();
|
double minValue = std::numeric_limits<double>::infinity();
|
||||||
double value = rimCase->caseRealizationParameters()->parameterValue(parameterName);
|
double maxValue = -std::numeric_limits<double>::infinity();
|
||||||
curve->setColor(cvf::Color3f(m_legendConfig->scalarMapper()->mapToColor(value)));
|
|
||||||
curve->updateCurveAppearance();
|
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())
|
for (RimSummaryCase* rimCase : group->allSummaryCases())
|
||||||
{
|
{
|
||||||
if (!rimCase->caseRealizationParameters().isNull())
|
if (rimCase->caseRealizationParameters() != nullptr)
|
||||||
{
|
{
|
||||||
auto ps = rimCase->caseRealizationParameters()->parameters();
|
auto ps = rimCase->caseRealizationParameters()->parameters();
|
||||||
for (auto p : ps) paramSet.insert(p.first);
|
for (auto p : ps) paramSet.insert(p.first);
|
||||||
@ -768,3 +836,22 @@ QString RimEnsembleCurveSet::createAutoName() const
|
|||||||
|
|
||||||
return curveSetName;
|
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:
|
public:
|
||||||
enum ColorMode {SINGLE_COLOR, BY_ENSEMBLE_PARAM};
|
enum ColorMode {SINGLE_COLOR, BY_ENSEMBLE_PARAM};
|
||||||
|
enum EnsembleParameterType {TYPE_NONE, TYPE_NUMERIC, TYPE_TEXT};
|
||||||
|
|
||||||
RimEnsembleCurveSet();
|
RimEnsembleCurveSet();
|
||||||
virtual ~RimEnsembleCurveSet();
|
virtual ~RimEnsembleCurveSet();
|
||||||
@ -85,6 +86,7 @@ public:
|
|||||||
RimSummaryCaseCollection* summaryCaseCollection() const;
|
RimSummaryCaseCollection* summaryCaseCollection() const;
|
||||||
|
|
||||||
ColorMode colorMode() const;
|
ColorMode colorMode() const;
|
||||||
|
EnsembleParameterType currentEnsembleParameterType() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
caf::PdmFieldHandle* userDescriptionField() override;
|
caf::PdmFieldHandle* userDescriptionField() override;
|
||||||
@ -113,6 +115,7 @@ private:
|
|||||||
|
|
||||||
QString createAutoName() const;
|
QString createAutoName() const;
|
||||||
|
|
||||||
|
void updateLegendMappingMode();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
caf::PdmField<bool> m_showCurves;
|
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;
|
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;
|
return m_crlParameters;
|
||||||
}
|
}
|
||||||
|
@ -22,6 +22,8 @@
|
|||||||
#include "cafPdmField.h"
|
#include "cafPdmField.h"
|
||||||
#include "cafPdmObject.h"
|
#include "cafPdmObject.h"
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
class RifSummaryReaderInterface;
|
class RifSummaryReaderInterface;
|
||||||
|
|
||||||
//==================================================================================================
|
//==================================================================================================
|
||||||
@ -54,8 +56,8 @@ public:
|
|||||||
|
|
||||||
bool isObservedData();
|
bool isObservedData();
|
||||||
|
|
||||||
void setCaseRealizationParameters(cvf::ref<RigCaseRealizationParameters> crlParameters);
|
void setCaseRealizationParameters(const std::shared_ptr<RigCaseRealizationParameters>& crlParameters);
|
||||||
cvf::ref<RigCaseRealizationParameters> caseRealizationParameters() const;
|
std::shared_ptr<RigCaseRealizationParameters> caseRealizationParameters() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void fieldChangedByUi(const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue);
|
virtual void fieldChangedByUi(const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue);
|
||||||
@ -66,7 +68,7 @@ protected:
|
|||||||
caf::PdmField<QString> m_summaryHeaderFilename;
|
caf::PdmField<QString> m_summaryHeaderFilename;
|
||||||
bool m_isObservedData;
|
bool m_isObservedData;
|
||||||
|
|
||||||
cvf::ref<RigCaseRealizationParameters> m_crlParameters;
|
std::shared_ptr<RigCaseRealizationParameters> m_crlParameters;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
virtual void initAfterRead() override;
|
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;
|
if (m_parameters.count(name) == 0) return HUGE_VAL;
|
||||||
return m_parameters[name];
|
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;
|
return m_parameters;
|
||||||
}
|
}
|
||||||
|
@ -31,14 +31,41 @@
|
|||||||
//
|
//
|
||||||
//
|
//
|
||||||
//==================================================================================================
|
//==================================================================================================
|
||||||
class RigCaseRealizationParameters : public cvf::Object
|
class RigCaseRealizationParameters
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
void addParameter(const QString& name, double value);
|
// Internal class
|
||||||
double parameterValue(const QString& name);
|
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:
|
private:
|
||||||
std::map<QString, double> m_parameters;
|
std::map<QString, Value> m_parameters;
|
||||||
};
|
};
|
||||||
|
@ -42,16 +42,20 @@ TEST(RifCaseRealizationParametersReaderTest, SuccessfulParsing)
|
|||||||
{
|
{
|
||||||
reader.parse();
|
reader.parse();
|
||||||
|
|
||||||
const cvf::ref<RigCaseRealizationParameters> parameters = reader.parameters();
|
const std::shared_ptr<RigCaseRealizationParameters> parameters(reader.parameters());
|
||||||
std::map<QString, double> params = parameters->parameters();
|
std::map<QString, RigCaseRealizationParameters::Value> params = parameters->parameters();
|
||||||
|
|
||||||
EXPECT_EQ(1U, params.count("LETSWOF:L_1OW"));
|
EXPECT_EQ(1U, params.count("LETSWOF:L_1OW"));
|
||||||
EXPECT_EQ(1U, params.count("LETSGOF:KRG1"));
|
EXPECT_EQ(1U, params.count("LETSGOF:KRG1"));
|
||||||
EXPECT_EQ(1U, params.count("LOG10_MULTFLT:MULTFLT_F1"));
|
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_TRUE(params["LETSWOF:L_1OW"].isNumeric());
|
||||||
EXPECT_EQ(0.97, params["LETSGOF:KRG1"]);
|
EXPECT_EQ(1.83555, params["LETSWOF:L_1OW"].numericValue());
|
||||||
EXPECT_EQ(-0.168356, params["LOG10_MULTFLT:MULTFLT_F1"]);
|
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 (...)
|
catch (...)
|
||||||
{
|
{
|
||||||
|
@ -26,4 +26,5 @@ LETSGOF:L_1OG 3.90509
|
|||||||
LETSGOF:E_1OG 4.00383
|
LETSGOF:E_1OG 4.00383
|
||||||
LETSGOF:T_1OG 1.03539
|
LETSGOF:T_1OG 1.03539
|
||||||
LETSGOF:SORG1 0.34
|
LETSGOF:SORG1 0.34
|
||||||
|
TST:TEXT_PARAM YES
|
||||||
LETSGOF:KRG1 0.97
|
LETSGOF:KRG1 0.97
|
||||||
|
Loading…
Reference in New Issue
Block a user