diff --git a/ApplicationCode/Commands/CMakeLists_files.cmake b/ApplicationCode/Commands/CMakeLists_files.cmake index c0d9125d9b..bd7a27d104 100644 --- a/ApplicationCode/Commands/CMakeLists_files.cmake +++ b/ApplicationCode/Commands/CMakeLists_files.cmake @@ -64,6 +64,7 @@ ${CMAKE_CURRENT_LIST_DIR}/RicReloadWellMeasurementsFeature.h ${CMAKE_CURRENT_LIST_DIR}/RicWellMeasurementImportTools.h ${CMAKE_CURRENT_LIST_DIR}/RicImportElasticPropertiesFeature.h ${CMAKE_CURRENT_LIST_DIR}/RicElasticPropertiesImportTools.h +${CMAKE_CURRENT_LIST_DIR}/RicFaciesPropertiesImportTools.h ${CMAKE_CURRENT_LIST_DIR}/RicCloseSourSimDataFeature.h @@ -159,6 +160,7 @@ ${CMAKE_CURRENT_LIST_DIR}/RicReloadWellMeasurementsFeature.cpp ${CMAKE_CURRENT_LIST_DIR}/RicWellMeasurementImportTools.cpp ${CMAKE_CURRENT_LIST_DIR}/RicImportElasticPropertiesFeature.cpp ${CMAKE_CURRENT_LIST_DIR}/RicElasticPropertiesImportTools.cpp +${CMAKE_CURRENT_LIST_DIR}/RicFaciesPropertiesImportTools.cpp ${CMAKE_CURRENT_LIST_DIR}/RicCloseSourSimDataFeature.cpp diff --git a/ApplicationCode/Commands/RicFaciesPropertiesImportTools.cpp b/ApplicationCode/Commands/RicFaciesPropertiesImportTools.cpp new file mode 100644 index 0000000000..21e81be567 --- /dev/null +++ b/ApplicationCode/Commands/RicFaciesPropertiesImportTools.cpp @@ -0,0 +1,179 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2020 Equinor 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 "RicFaciesPropertiesImportTools.h" + +#include "RiaApplication.h" +#include "RiaColorTables.h" +#include "RiaFractureDefines.h" +#include "RiaLogging.h" +#include "RiaStdStringTools.h" + +#include "RimColorLegend.h" +#include "RimColorLegendCollection.h" +#include "RimColorLegendItem.h" +#include "RimFaciesProperties.h" +#include "RimFractureModel.h" +#include "RimProject.h" + +#include "RifColorLegendData.h" +#include "RifRoffReader.h" + +#include "cafColorTable.h" + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RicFaciesPropertiesImportTools::importFaciesPropertiesFromFile( const QString& filePath, + RimFractureModel* fractureModel, + bool createColorLegend ) +{ + if ( filePath.isEmpty() ) return; + + std::map codeNames; + try + { + RifRoffReader::readCodeNames( filePath, codeNames ); + } + catch ( RifRoffReaderException& ex ) + { + RiaLogging::error( QString::fromStdString( ex.message ) ); + return; + } + + RimFaciesProperties* faciesProperties = fractureModel->faciesProperties(); + if ( !faciesProperties ) + { + faciesProperties = new RimFaciesProperties; + } + + for ( auto it : codeNames ) + { + faciesProperties->setFaciesCodeName( it.first, it.second ); + } + + if ( createColorLegend ) + { + const caf::ColorTable& colorTable = RiaColorTables::contrastCategoryPaletteColors(); + RimColorLegendCollection* colorLegendCollection = RimProject::current()->colorLegendCollection; + RimColorLegend* rockTypeColorLegend = colorLegendCollection->findByName( RiaDefines::rockTypeColorLegendName() ); + + RimColorLegend* colorLegend = new RimColorLegend; + colorLegend->setColorLegendName( RiaDefines::faciesColorLegendName() ); + + for ( auto it : codeNames ) + { + RimColorLegendItem* colorLegendItem = new RimColorLegendItem; + + // Try to find a color from the rock type color legend by fuzzy matching names + cvf::Color3f color; + if ( !predefinedColorMatch( it.second, rockTypeColorLegend, color ) && + !matchByName( it.second, rockTypeColorLegend, color ) ) + { + // No match use a random color + color = colorTable.cycledColor3f( it.first ); + } + + colorLegendItem->setValues( it.second, it.first, color ); + colorLegend->appendColorLegendItem( colorLegendItem ); + } + + colorLegendCollection->appendCustomColorLegend( colorLegend ); + colorLegendCollection->updateConnectedEditors(); + } + + faciesProperties->setFilePath( filePath ); + + fractureModel->setFaciesProperties( faciesProperties ); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool RicFaciesPropertiesImportTools::matchByName( const QString& name, RimColorLegend* colorLegend, cvf::Color3f& color ) +{ + // No match if color legend does not exist + if ( !colorLegend ) return false; + + // Find the best matching name from the legend + int bestScore = std::numeric_limits::max(); + RimColorLegendItem* bestItem = nullptr; + for ( RimColorLegendItem* item : colorLegend->colorLegendItems() ) + { + int score = computeEditDistance( name, item->categoryName() ); + if ( score < bestScore ) + { + bestScore = score; + bestItem = item; + } + } + + // Allow only small difference when determining if something matches + const int maximumScoreToMatch = 1; + if ( bestScore <= maximumScoreToMatch ) + { + color = bestItem->color(); + return true; + } + + return false; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +int RicFaciesPropertiesImportTools::computeEditDistance( const QString& a, const QString& b ) +{ + // Remove common words from the domain which does not help in the matching + std::vector stopWords = {"rocks", "rock", "stones", "stone"}; + QString aSimplified = a.toLower(); + QString bSimplified = b.toLower(); + for ( auto r : stopWords ) + { + aSimplified.remove( r ); + bSimplified.remove( r ); + } + + aSimplified = aSimplified.trimmed(); + bSimplified = bSimplified.trimmed(); + + return RiaStdStringTools::computeEditDistance( aSimplified.toStdString(), bSimplified.toStdString() ); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool RicFaciesPropertiesImportTools::predefinedColorMatch( const QString& name, + RimColorLegend* colorLegend, + cvf::Color3f& color ) +{ + // Calcite should use limestone color + if ( name.toLower().trimmed() == QString( "calcite" ) ) + { + for ( auto i : colorLegend->colorLegendItems() ) + { + if ( i->categoryName() == QString( "Limestone" ) ) + { + color = i->color(); + return true; + } + } + } + + return false; +} diff --git a/ApplicationCode/Commands/RicFaciesPropertiesImportTools.h b/ApplicationCode/Commands/RicFaciesPropertiesImportTools.h new file mode 100644 index 0000000000..665cfa5c31 --- /dev/null +++ b/ApplicationCode/Commands/RicFaciesPropertiesImportTools.h @@ -0,0 +1,45 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2020 Equinor 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 + +class RimColorLegend; +class RimFractureModel; + +namespace cvf +{ +class Color3f; +} + +class QString; + +//================================================================================================== +/// +//================================================================================================== +class RicFaciesPropertiesImportTools +{ +public: + static void importFaciesPropertiesFromFile( const QString& filePath, + RimFractureModel* fractureModel, + bool createColorLegend = false ); + +private: + static int computeEditDistance( const QString& a, const QString& b ); + static bool matchByName( const QString& name, RimColorLegend* colorLegend, cvf::Color3f& color ); + static bool predefinedColorMatch( const QString& name, RimColorLegend* colorLegend, cvf::Color3f& color ); +}; diff --git a/ApplicationCode/Commands/RicImportFaciesFeature.cpp b/ApplicationCode/Commands/RicImportFaciesFeature.cpp index d2c52ab57d..09cf0502be 100644 --- a/ApplicationCode/Commands/RicImportFaciesFeature.cpp +++ b/ApplicationCode/Commands/RicImportFaciesFeature.cpp @@ -19,23 +19,15 @@ #include "RicImportFaciesFeature.h" #include "RiaApplication.h" -#include "RiaColorTables.h" -#include "RiaFractureDefines.h" -#include "RiaLogging.h" -#include "RiaStdStringTools.h" - -#include "RimColorLegend.h" -#include "RimColorLegendCollection.h" -#include "RimColorLegendItem.h" -#include "RimProject.h" - -#include "RifColorLegendData.h" -#include "RifRoffReader.h" #include "Riu3DMainWindowTools.h" #include "RiuFileDialogTools.h" -#include "cafColorTable.h" +#include "RicFaciesPropertiesImportTools.h" + +#include "RimFractureModel.h" + +#include "cafSelectionManager.h" #include #include @@ -55,6 +47,9 @@ bool RicImportFaciesFeature::isCommandEnabled() //-------------------------------------------------------------------------------------------------- void RicImportFaciesFeature::onActionTriggered( bool isChecked ) { + RimFractureModel* fractureModel = caf::SelectionManager::instance()->selectedItemAncestorOfType(); + if ( !fractureModel ) return; + RiaApplication* app = RiaApplication::instance(); QString defaultDir = app->lastUsedDialogDirectoryWithFallbackToProjectFolder( "STIMPLAN_DIR" ); @@ -70,43 +65,8 @@ void RicImportFaciesFeature::onActionTriggered( bool isChecked ) // Remember the path to next time app->setLastUsedDialogDirectory( "STIMPLAN_DIR", QFileInfo( fileName ).absolutePath() ); - std::map codeNames; - try - { - RifRoffReader::readCodeNames( fileName, codeNames ); - } - catch ( RifRoffReaderException& ex ) - { - RiaLogging::error( QString::fromStdString( ex.message ) ); - return; - } - - const caf::ColorTable& colorTable = RiaColorTables::contrastCategoryPaletteColors(); - RimColorLegendCollection* colorLegendCollection = RimProject::current()->colorLegendCollection; - RimColorLegend* rockTypeColorLegend = colorLegendCollection->findByName( RiaDefines::rockTypeColorLegendName() ); - - RimColorLegend* colorLegend = new RimColorLegend; - colorLegend->setColorLegendName( RiaDefines::faciesColorLegendName() ); - - for ( auto it : codeNames ) - { - RimColorLegendItem* colorLegendItem = new RimColorLegendItem; - - // Try to find a color from the rock type color legend by fuzzy matching names - cvf::Color3f color; - if ( !predefinedColorMatch( it.second, rockTypeColorLegend, color ) && - !matchByName( it.second, rockTypeColorLegend, color ) ) - { - // No match use a random color - color = colorTable.cycledColor3f( it.first ); - } - - colorLegendItem->setValues( it.second, it.first, color ); - colorLegend->appendColorLegendItem( colorLegendItem ); - } - - colorLegendCollection->appendCustomColorLegend( colorLegend ); - colorLegendCollection->updateConnectedEditors(); + bool createColorLegend = true; + RicFaciesPropertiesImportTools::importFaciesPropertiesFromFile( fileName, fractureModel, createColorLegend ); } //-------------------------------------------------------------------------------------------------- @@ -118,77 +78,3 @@ void RicImportFaciesFeature::setupActionLook( QAction* actionToSetup ) // actionToSetup->setIcon( QIcon( ":/Formations16x16.png" ) ); actionToSetup->setText( "Import Facies" ); } - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -bool RicImportFaciesFeature::matchByName( const QString& name, RimColorLegend* colorLegend, cvf::Color3f& color ) -{ - // No match if color legend does not exist - if ( !colorLegend ) return false; - - // Find the best matching name from the legend - int bestScore = std::numeric_limits::max(); - RimColorLegendItem* bestItem = nullptr; - for ( RimColorLegendItem* item : colorLegend->colorLegendItems() ) - { - int score = computeEditDistance( name, item->categoryName() ); - if ( score < bestScore ) - { - bestScore = score; - bestItem = item; - } - } - - // Allow only small difference when determining if something matches - const int maximumScoreToMatch = 1; - if ( bestScore <= maximumScoreToMatch ) - { - color = bestItem->color(); - return true; - } - - return false; -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -int RicImportFaciesFeature::computeEditDistance( const QString& a, const QString& b ) -{ - // Remove common words from the domain which does not help in the matching - std::vector stopWords = {"rocks", "rock", "stones", "stone"}; - QString aSimplified = a.toLower(); - QString bSimplified = b.toLower(); - for ( auto r : stopWords ) - { - aSimplified.remove( r ); - bSimplified.remove( r ); - } - - aSimplified = aSimplified.trimmed(); - bSimplified = bSimplified.trimmed(); - - return RiaStdStringTools::computeEditDistance( aSimplified.toStdString(), bSimplified.toStdString() ); -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -bool RicImportFaciesFeature::predefinedColorMatch( const QString& name, RimColorLegend* colorLegend, cvf::Color3f& color ) -{ - // Calcite should use limestone color - if ( name.toLower().trimmed() == QString( "calcite" ) ) - { - for ( auto i : colorLegend->colorLegendItems() ) - { - if ( i->categoryName() == QString( "Limestone" ) ) - { - color = i->color(); - return true; - } - } - } - - return false; -} diff --git a/ApplicationCode/ProjectDataModel/CMakeLists_files.cmake b/ApplicationCode/ProjectDataModel/CMakeLists_files.cmake index 6242635682..c694218bac 100644 --- a/ApplicationCode/ProjectDataModel/CMakeLists_files.cmake +++ b/ApplicationCode/ProjectDataModel/CMakeLists_files.cmake @@ -166,6 +166,7 @@ ${CMAKE_CURRENT_LIST_DIR}/RimLayerCurve.h ${CMAKE_CURRENT_LIST_DIR}/RimFractureModelStressCurve.h ${CMAKE_CURRENT_LIST_DIR}/RimAbstractPlotCollection.h ${CMAKE_CURRENT_LIST_DIR}/RimFractureModelPropertyCurve.h +${CMAKE_CURRENT_LIST_DIR}/RimFaciesProperties.h ) @@ -334,6 +335,7 @@ ${CMAKE_CURRENT_LIST_DIR}/RimElasticProperties.cpp ${CMAKE_CURRENT_LIST_DIR}/RimElasticPropertiesCurve.cpp ${CMAKE_CURRENT_LIST_DIR}/RimLayerCurve.cpp ${CMAKE_CURRENT_LIST_DIR}/RimFractureModelStressCurve.cpp +${CMAKE_CURRENT_LIST_DIR}/RimFaciesProperties.cpp ) list(APPEND CODE_HEADER_FILES diff --git a/ApplicationCode/ProjectDataModel/Completions/RimFractureModel.cpp b/ApplicationCode/ProjectDataModel/Completions/RimFractureModel.cpp index 8d0009aeca..07022f958b 100644 --- a/ApplicationCode/ProjectDataModel/Completions/RimFractureModel.cpp +++ b/ApplicationCode/ProjectDataModel/Completions/RimFractureModel.cpp @@ -39,6 +39,8 @@ #include "RimEclipseCase.h" #include "RimEclipseView.h" #include "RimElasticProperties.h" +#include "RimEllipseFractureTemplate.h" +#include "RimFaciesProperties.h" #include "RimFractureModelPlot.h" #include "RimModeledWellPath.h" #include "RimOilField.h" @@ -68,7 +70,7 @@ #include -CAF_PDM_SOURCE_INIT( RimFractureModel, "RimFractureModel" ); + CAF_PDM_SOURCE_INIT( RimFractureModel, "RimFractureModel" ); namespace caf { @@ -249,6 +251,9 @@ RimFractureModel::RimFractureModel() m_elasticProperties.uiCapability()->setUiTreeHidden( true ); CAF_PDM_InitScriptableFieldNoDefault( &m_barrierAnnotation, "BarrierAnnotation", "Barrier Annotation", "", "", "" ); + CAF_PDM_InitScriptableFieldNoDefault( &m_faciesProperties, "FaciesProperties", "Facies Properties", "", "", "" ); + m_faciesProperties.uiCapability()->setUiHidden( true ); + m_faciesProperties.uiCapability()->setUiTreeHidden( true ); setDeletable( true ); } @@ -957,6 +962,22 @@ void RimFractureModel::setElasticProperties( RimElasticProperties* elasticProper m_elasticProperties = elasticProperties; } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RimFaciesProperties* RimFractureModel::faciesProperties() const +{ + return m_faciesProperties; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimFractureModel::setFaciesProperties( RimFaciesProperties* faciesProperties ) +{ + m_faciesProperties = faciesProperties; +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -966,6 +987,11 @@ void RimFractureModel::loadDataAndUpdate() { m_elasticProperties->loadDataAndUpdate(); } + + if ( m_faciesProperties ) + { + m_faciesProperties->loadDataAndUpdate(); + } } //-------------------------------------------------------------------------------------------------- @@ -1119,9 +1145,9 @@ double RimFractureModel::getDefaultValueForProperty( RiaDefines::CurveProperty c //-------------------------------------------------------------------------------------------------- bool RimFractureModel::hasDefaultValueForProperty( RiaDefines::CurveProperty curveProperty ) const { - auto withDefaults = {RiaDefines::CurveProperty::RELATIVE_PERMEABILITY_FACTOR, - RiaDefines::CurveProperty::PORO_ELASTIC_CONSTANT, - RiaDefines::CurveProperty::THERMAL_EXPANSION_COEFFICIENT}; + auto withDefaults = { RiaDefines::CurveProperty::RELATIVE_PERMEABILITY_FACTOR, + RiaDefines::CurveProperty::PORO_ELASTIC_CONSTANT, + RiaDefines::CurveProperty::THERMAL_EXPANSION_COEFFICIENT }; return std::find( withDefaults.begin(), withDefaults.end(), curveProperty ) != withDefaults.end(); } diff --git a/ApplicationCode/ProjectDataModel/Completions/RimFractureModel.h b/ApplicationCode/ProjectDataModel/Completions/RimFractureModel.h index 8f068cb0f6..f705ba77f4 100644 --- a/ApplicationCode/ProjectDataModel/Completions/RimFractureModel.h +++ b/ApplicationCode/ProjectDataModel/Completions/RimFractureModel.h @@ -38,6 +38,7 @@ class RimElasticProperties; class RigEclipseCaseData; class RimAnnotationCollection; class RimUserDefinedPolylinesAnnotation; +class RimFaciesProperties; //================================================================================================== /// @@ -136,6 +137,9 @@ public: double getOverburdenGradient( const QString& keyword ) const; double getUnderburdenGradient( const QString& keyword ) const; + void setFaciesProperties( RimFaciesProperties* faciesProperties ); + RimFaciesProperties* faciesProperties() const; + void updateReferringPlots(); protected: @@ -183,6 +187,7 @@ protected: caf::PdmField m_boundingBoxHorizontal; caf::PdmPtrField m_thicknessDirectionWellPath; caf::PdmChildField m_elasticProperties; + caf::PdmChildField m_faciesProperties; caf::PdmField m_defaultPorosity; caf::PdmField m_defaultPermeability; caf::PdmField m_verticalStress; diff --git a/ApplicationCode/ProjectDataModel/RimFaciesProperties.cpp b/ApplicationCode/ProjectDataModel/RimFaciesProperties.cpp new file mode 100644 index 0000000000..c15706bb3f --- /dev/null +++ b/ApplicationCode/ProjectDataModel/RimFaciesProperties.cpp @@ -0,0 +1,172 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2020- Equinor 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 "RimFaciesProperties.h" + +#include "RimColorLegend.h" +#include "RimEclipseResultDefinition.h" +#include "RimFractureModel.h" +#include "RimRegularLegendConfig.h" + +#include "RicFaciesPropertiesImportTools.h" + +#include "cafPdmFieldScriptingCapability.h" +#include "cafPdmObjectScriptingCapability.h" +#include "cafPdmUiLineEditor.h" +#include "cafPdmUiTextEditor.h" + +CAF_PDM_SOURCE_INIT( RimFaciesProperties, "FaciesProperties" ); + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RimFaciesProperties::RimFaciesProperties() +{ + CAF_PDM_InitScriptableObject( "RimFaciesProperties", "", "", "" ); + + CAF_PDM_InitScriptableFieldNoDefault( &m_filePath, "FilePath", "File Path", "", "", "" ); + m_filePath.uiCapability()->setUiReadOnly( true ); + m_filePath.uiCapability()->setUiEditorTypeName( caf::PdmUiLineEditor::uiEditorTypeName() ); + + CAF_PDM_InitScriptableFieldNoDefault( &m_propertiesTable, "PropertiesTable", "Properties Table", "", "", "" ); + m_propertiesTable.uiCapability()->setUiEditorTypeName( caf::PdmUiTextEditor::uiEditorTypeName() ); + m_propertiesTable.uiCapability()->setUiLabelPosition( caf::PdmUiItemInfo::HIDDEN ); + m_propertiesTable.uiCapability()->setUiReadOnly( true ); + m_propertiesTable.xmlCapability()->disableIO(); + + CAF_PDM_InitFieldNoDefault( &m_faciesDefinition, "FaciesDefinition", "", "", "", "" ); + m_faciesDefinition.uiCapability()->setUiHidden( true ); + m_faciesDefinition.uiCapability()->setUiTreeChildrenHidden( true ); + m_faciesDefinition = new RimEclipseResultDefinition; + m_faciesDefinition->findField( "MResultType" )->uiCapability()->setUiName( "Facies Definiton" ); + + CAF_PDM_InitFieldNoDefault( &m_colorLegend, "ColorLegend", "Colors", "", "", "" ); + m_colorLegend = RimRegularLegendConfig::mapToColorLegend( RimRegularLegendConfig::ColorRangesType::NORMAL ); + + setUiName( "Facies Properties" ); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RimFaciesProperties::~RimFaciesProperties() +{ +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +QString RimFaciesProperties::filePath() const +{ + return m_filePath.v().path(); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimFaciesProperties::setFilePath( const QString& filePath ) +{ + m_filePath = filePath; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimFaciesProperties::setFaciesCodeName( int code, const QString& name ) +{ + m_faciesCodeNames[code] = name; + m_propertiesTable = generatePropertiesTable(); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimFaciesProperties::defineUiOrdering( QString uiConfigName, caf::PdmUiOrdering& uiOrdering ) +{ + uiOrdering.add( &m_filePath ); + uiOrdering.add( &m_propertiesTable ); + uiOrdering.add( &m_colorLegend ); + + caf::PdmUiGroup* faciesDefinitionGroup = uiOrdering.addNewGroup( "Facies Definition" ); + m_faciesDefinition->uiOrdering( uiConfigName, *faciesDefinitionGroup ); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimFaciesProperties::defineEditorAttribute( const caf::PdmFieldHandle* field, + QString uiConfigName, + caf::PdmUiEditorAttribute* attribute ) +{ + if ( field == &m_propertiesTable ) + { + auto myAttr = dynamic_cast( attribute ); + if ( myAttr ) + { + myAttr->wrapMode = caf::PdmUiTextEditorAttribute::NoWrap; + myAttr->textMode = caf::PdmUiTextEditorAttribute::HTML; + } + } +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +QString RimFaciesProperties::generatePropertiesTable() +{ + QString header( "" + " " + " " + " " + " " + " " + " " + " " ); + + QString body; + for ( auto prop : m_faciesCodeNames ) + { + int index = prop.first; + const QString& name = prop.second; + + QString format( "" + " " + " " + "" ); + + QString line = format.arg( name ).arg( index ); + body.append( line ); + } + + QString footer( "
NameIndex
%1%2
" ); + + return header + body + footer; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimFaciesProperties::loadDataAndUpdate() +{ + if ( !m_filePath().path().isEmpty() ) + { + RimFractureModel* fractureModel; + firstAncestorOrThisOfType( fractureModel ); + RicFaciesPropertiesImportTools::importFaciesPropertiesFromFile( m_filePath().path(), fractureModel ); + } +} diff --git a/ApplicationCode/ProjectDataModel/RimFaciesProperties.h b/ApplicationCode/ProjectDataModel/RimFaciesProperties.h new file mode 100644 index 0000000000..67d04c9496 --- /dev/null +++ b/ApplicationCode/ProjectDataModel/RimFaciesProperties.h @@ -0,0 +1,65 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2020- Equinor 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 "cafFilePath.h" +#include "cafPdmChildField.h" +#include "cafPdmField.h" +#include "cafPdmObject.h" +#include "cafPdmPtrField.h" + +#include + +class RimEclipseResultDefinition; +class RimColorLegend; + +//================================================================================================== +/// +//================================================================================================== +class RimFaciesProperties : public caf::PdmObject +{ + CAF_PDM_HEADER_INIT; + +public: + RimFaciesProperties(); + ~RimFaciesProperties() override; + + QString filePath() const; + void setFilePath( const QString& filePath ); + + void setFaciesCodeName( int code, const QString& name ); + + void loadDataAndUpdate(); + +protected: + void defineEditorAttribute( const caf::PdmFieldHandle* field, + QString uiConfigName, + caf::PdmUiEditorAttribute* attribute ) override; + void defineUiOrdering( QString uiConfigName, caf::PdmUiOrdering& uiOrdering ); + +private: + QString generatePropertiesTable(); + + caf::PdmField m_filePath; + caf::PdmField m_propertiesTable; + caf::PdmChildField m_faciesDefinition; + caf::PdmPtrField m_colorLegend; + + std::map m_faciesCodeNames; +};