mirror of
https://github.com/OPM/ResInsight.git
synced 2026-08-27 05:37:21 -05:00
#14001 Python: Use AppEnum fields for property_data_type arguments
Replace QString + setFromText parsing with typed caf::PdmField<caf::AppEnum<...>> for m_propertyType and m_porosityModel on RimcEclipseCase_propertyDataType. The script keywords stay "PropertyType" / "PorosityModel" so the Python parameter names are unchanged (property_type, porosity_model), and the auto-generated StrEnum classes are now PropertyType and PorosityModelType (typed annotations on the call site). Register caf::AppEnum<RiaDefines::PorosityModelType> -> "PorosityModelType" alongside the existing ResultCatType override so PorosityModelType's auto-generated class name is stable regardless of which field the generator visits first. executeEnum() drops the setFromText parsing and the "Invalid property type / porosity model" branches — the values now flow through typed already, so an invalid enum text cannot reach the method body.
This commit is contained in:
@@ -20,6 +20,7 @@
|
||||
|
||||
#include "RiaDefines.h"
|
||||
|
||||
#include "RiaPorosityModel.h"
|
||||
#include "RiaResultNames.h"
|
||||
|
||||
#include "cafAppEnum.h"
|
||||
@@ -182,13 +183,16 @@ void caf::AppEnum<RiaDefines::RowCount>::setUp()
|
||||
|
||||
namespace
|
||||
{
|
||||
// Pin the Python StrEnum class name for caf::AppEnum<RiaDefines::ResultCatType> to "PropertyType".
|
||||
// Without this override the generator derives the class name from the first field's script keyword
|
||||
// ("ResultType"), which both diverges from the proto PropertyType name and shifts whenever class
|
||||
// iteration order changes.
|
||||
// Pin the Python StrEnum class names so the code generator emits stable identifiers regardless of
|
||||
// which field it visits first. Without an override the class name is derived from the field's
|
||||
// script keyword, and adding/removing fields can silently rename existing Python classes.
|
||||
struct RegisterScriptEnumNames
|
||||
{
|
||||
RegisterScriptEnumNames() { caf::PdmScriptEnumNameRegistry::registerName<RiaDefines::ResultCatType>( "PropertyType" ); }
|
||||
RegisterScriptEnumNames()
|
||||
{
|
||||
caf::PdmScriptEnumNameRegistry::registerName<RiaDefines::ResultCatType>( "PropertyType" );
|
||||
caf::PdmScriptEnumNameRegistry::registerName<RiaDefines::PorosityModelType>( "PorosityModelType" );
|
||||
}
|
||||
};
|
||||
const RegisterScriptEnumNames s_registerScriptEnumNames;
|
||||
} // namespace
|
||||
|
||||
@@ -420,7 +420,10 @@ RimcEclipseCase_propertyDataType::RimcEclipseCase_propertyDataType( caf::PdmObje
|
||||
|
||||
CAF_PDM_InitScriptableFieldNoDefault( &m_propertyType, "PropertyType", "" );
|
||||
CAF_PDM_InitScriptableFieldNoDefault( &m_propertyName, "PropertyName", "" );
|
||||
CAF_PDM_InitScriptableField( &m_porosityModel, "PorosityModel", QString( "MATRIX_MODEL" ), "" );
|
||||
CAF_PDM_InitScriptableField( &m_porosityModel,
|
||||
"PorosityModel",
|
||||
caf::AppEnum<RiaDefines::PorosityModelType>( RiaDefines::PorosityModelType::MATRIX_MODEL ),
|
||||
"" );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -431,19 +434,7 @@ std::expected<RiaDefines::ResultDataType, QString> RimcEclipseCase_propertyDataT
|
||||
auto eclipseCase = self<RimEclipseCase>();
|
||||
if ( !eclipseCase ) return std::unexpected( "No eclipse case" );
|
||||
|
||||
caf::AppEnum<RiaDefines::ResultCatType> resultCatTypeEnum;
|
||||
if ( !resultCatTypeEnum.setFromText( m_propertyType ) )
|
||||
{
|
||||
return std::unexpected( "Invalid property type." );
|
||||
}
|
||||
|
||||
caf::AppEnum<RiaDefines::PorosityModelType> porosityModel;
|
||||
if ( !porosityModel.setFromText( m_porosityModel ) )
|
||||
{
|
||||
return std::unexpected( "Invalid porosity model." );
|
||||
}
|
||||
|
||||
auto resultsData = eclipseCase->results( porosityModel );
|
||||
auto resultsData = eclipseCase->results( m_porosityModel() );
|
||||
if ( !resultsData )
|
||||
{
|
||||
return std::unexpected( "Eclipse case has no result data." );
|
||||
@@ -451,7 +442,7 @@ std::expected<RiaDefines::ResultDataType, QString> RimcEclipseCase_propertyDataT
|
||||
|
||||
for ( const auto& address : resultsData->existingResults() )
|
||||
{
|
||||
if ( address.resultCatType() == resultCatTypeEnum && address.resultName() == m_propertyName() )
|
||||
if ( address.resultCatType() == m_propertyType() && address.resultName() == m_propertyName() )
|
||||
{
|
||||
return address.dataType();
|
||||
}
|
||||
|
||||
@@ -19,7 +19,9 @@
|
||||
#pragma once
|
||||
|
||||
#include "RiaDefines.h"
|
||||
#include "RiaPorosityModel.h"
|
||||
|
||||
#include "cafAppEnum.h"
|
||||
#include "cafPdmField.h"
|
||||
#include "cafPdmObjectHandle.h"
|
||||
#include "cafPdmObjectMethod.h"
|
||||
@@ -133,9 +135,9 @@ public:
|
||||
QString returnEnumScriptName() const override { return "PropertyDataType"; }
|
||||
|
||||
private:
|
||||
caf::PdmField<QString> m_propertyType;
|
||||
caf::PdmField<QString> m_propertyName;
|
||||
caf::PdmField<QString> m_porosityModel;
|
||||
caf::PdmField<caf::AppEnum<RiaDefines::ResultCatType>> m_propertyType;
|
||||
caf::PdmField<QString> m_propertyName;
|
||||
caf::PdmField<caf::AppEnum<RiaDefines::PorosityModelType>> m_porosityModel;
|
||||
};
|
||||
|
||||
//==================================================================================================
|
||||
|
||||
Reference in New Issue
Block a user