Use rock type colors when "Facies" is imported

This commit is contained in:
Magne Sjaastad
2023-05-26 11:26:22 +02:00
committed by GitHub
parent f17c02ce86
commit b7420ebc70
7 changed files with 120 additions and 79 deletions

View File

@@ -21,6 +21,8 @@
#include "RiaApplication.h"
#include "RiaLogging.h"
#include "RicFaciesPropertiesImportTools.h"
#include "RigActiveCellInfo.h"
#include "RigCaseCellResultsData.h"
#include "RigEclipseCaseData.h"
@@ -504,6 +506,29 @@ std::pair<bool, std::map<QString, QString>> RifRoffFileTools::createInputPropert
return std::make_pair( false, keywordMapping );
}
auto codeNamesAndValuesForKeyword = []( const std::string& keyword, roff::Reader& reader ) -> std::map<int, QString>
{
const std::string codeNamesKeyword = keyword + roff::Parser::postFixCodeNames();
const std::string codeValuesKeyword = keyword + roff::Parser::postFixCodeValues();
if ( reader.getArrayLength( codeNamesKeyword ) > 0 &&
reader.getArrayLength( codeNamesKeyword ) == reader.getArrayLength( codeValuesKeyword ) )
{
const auto fileCodeNames = reader.getStringArray( codeNamesKeyword );
const auto fileCodeValues = reader.getIntArray( codeValuesKeyword );
std::map<int, QString> codeNamesAndValues;
for ( size_t i = 0; i < fileCodeNames.size(); i++ )
{
codeNamesAndValues[fileCodeValues[i]] = QString::fromStdString( fileCodeNames[i] ).trimmed();
}
return codeNamesAndValues;
};
return {};
};
try
{
roff::Reader reader( stream );
@@ -521,6 +546,9 @@ std::pair<bool, std::map<QString, QString>> RifRoffFileTools::createInputPropert
.arg( QString::fromStdString( roff::Token::kindToString( kind ) ) )
.arg( keywordLength ) );
}
QString keywordUpperCase = QString::fromStdString( keyword ).toUpper();
if ( eclipseCaseData->mainGrid()->cellCount() == keywordLength )
{
QString newResultName = eclipseCaseData->results( RiaDefines::PorosityModelType::MATRIX_MODEL )
@@ -538,61 +566,51 @@ std::pair<bool, std::map<QString, QString>> RifRoffFileTools::createInputPropert
return std::make_pair( false, keywordMapping );
}
// Create color legend
const auto codeNames = codeNamesAndValuesForKeyword( keyword, reader );
bool anyValidCategoryName = false;
for ( const auto& codeName : codeNames )
{
const std::string codeNamesKeyword = keyword + roff::Parser::postFixCodeNames();
const std::string codeValuesKeyword = keyword + roff::Parser::postFixCodeValues();
auto codeNamesSize = reader.getArrayLength( codeNamesKeyword );
auto codeValuesSize = reader.getArrayLength( codeValuesKeyword );
if ( codeNamesSize != 0 && codeNamesSize == codeValuesSize )
if ( !codeName.second.isEmpty() )
{
const auto fileCodeNames = reader.getStringArray( codeNamesKeyword );
const auto fileCodeValues = reader.getIntArray( codeValuesKeyword );
QStringList trimmedCodeNames;
bool anyValidName = false;
for ( const std::string& codeName : fileCodeNames )
{
QString trimmedCodeName = QString::fromStdString( codeName ).trimmed();
trimmedCodeNames.push_back( trimmedCodeName );
if ( !trimmedCodeName.isEmpty() )
{
anyValidName = true;
}
}
if ( anyValidName )
{
std::vector<std::pair<int, QString>> valuesAndNames;
for ( int i = 0; i < static_cast<int>( trimmedCodeNames.size() ); i++ )
{
const auto& codeName = trimmedCodeNames[i];
valuesAndNames.emplace_back( fileCodeValues[i], codeName );
}
RimColorLegendCollection* colorLegendCollection = RimProject::current()->colorLegendCollection;
int caseId = 0;
auto rimCase = eclipseCaseData->ownerCase();
if ( rimCase ) caseId = rimCase->caseId();
// Delete existing color legend, as new legend will be populated by values from file
colorLegendCollection->deleteColorLegend( caseId, newResultName );
auto colorLegend = colorLegendCollection->createColorLegend( newResultName, valuesAndNames );
colorLegendCollection->setDefaultColorLegendForResult( caseId, newResultName, colorLegend );
colorLegendCollection->updateAllRequiredEditors();
}
anyValidCategoryName = true;
}
}
if ( anyValidCategoryName )
{
RimColorLegendCollection* colorLegendCollection = RimProject::current()->colorLegendCollection;
int caseId = 0;
auto rimCase = eclipseCaseData->ownerCase();
if ( rimCase ) caseId = rimCase->caseId();
// Delete existing color legend, as new legend will be populated by values from file
colorLegendCollection->deleteColorLegend( caseId, newResultName );
RimColorLegend* colorLegend = nullptr;
if ( keywordUpperCase == RiaResultNames::facies() )
{
colorLegend = RicFaciesPropertiesImportTools::createColorLegendMatchDefaultRockColors( codeNames );
}
else
{
colorLegend = colorLegendCollection->createColorLegend( newResultName, codeNames );
}
colorLegendCollection->setDefaultColorLegendForResult( caseId, newResultName, colorLegend );
colorLegendCollection->updateAllRequiredEditors();
}
keywordMapping[QString::fromStdString( keyword )] = newResultName;
}
else if ( keywordUpperCase == RiaResultNames::facies() )
{
// We have the definition of facies name and value, but we do not have values for cells. Create color legend and get values
// from other sources, i.e. Eclipse result files
const auto codeNames = codeNamesAndValuesForKeyword( keyword, reader );
RicFaciesPropertiesImportTools::createColorLegendMatchDefaultRockColors( codeNames );
}
}
}
catch ( std::runtime_error& err )