mirror of
https://github.com/OPM/ResInsight.git
synced 2026-10-25 22:50:25 -05:00
#14001 Python: Auto-generate StrEnum return types for scriptable methods
Replace the hand-written PropertyDataType wrapper with first-class enum return support in the code generator. Scriptable methods that derive from the new caf::PdmEnumObjectMethod<T> template return a typed enum value across the gRPC boundary; the Python generator emits a StrEnum class with the texts pulled from the underlying caf::AppEnum<T> and wraps the call site so callers receive `EnumClass(value)` directly. caf::PdmDataContainerEnum is the small PdmObject the framework uses to carry the enum text on the wire (single scriptable QString field). RimcEclipseCase_propertyDataType becomes declarative: implement executeEnum() returning the typed RiaDefines::ResultDataType and pick a returnEnumScriptName() — the base handles serialization and reports the four AppEnum members (UNKNOWN, FLOAT, DOUBLE, INTEGER) to the generator. Drop the hand-written PropertyDataType in enums.py — the generated one in resinsight_classes is wire-equivalent and now the single source of truth.
This commit is contained in:
1 parent
740b59702b
commit
8971ebfc9c
10 files changed
+248
-68
No files matched your search
@@ -414,7 +414,7 @@ CAF_PDM_OBJECT_METHOD_SOURCE_INIT( RimEclipseCase, RimcEclipseCase_propertyDataT
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RimcEclipseCase_propertyDataType::RimcEclipseCase_propertyDataType( caf::PdmObjectHandle* self )
|
||||
: caf::PdmObjectMethod( self, PdmObjectMethod::NullPointerType::NULL_IS_INVALID, PdmObjectMethod::ResultType::PERSISTENT_FALSE )
|
||||
: caf::PdmEnumObjectMethod<RiaDefines::ResultDataType>( self )
|
||||
{
|
||||
CAF_PDM_InitObject( "Property Data Type", "", "", "Get the data type (FLOAT or INTEGER) of a grid property" );
|
||||
|
||||
@@ -426,7 +426,7 @@ RimcEclipseCase_propertyDataType::RimcEclipseCase_propertyDataType( caf::PdmObje
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::expected<caf::PdmObjectHandle*, QString> RimcEclipseCase_propertyDataType::execute()
|
||||
std::expected<RiaDefines::ResultDataType, QString> RimcEclipseCase_propertyDataType::executeEnum()
|
||||
{
|
||||
auto eclipseCase = self<RimEclipseCase>();
|
||||
if ( !eclipseCase ) return std::unexpected( "No eclipse case" );
|
||||
@@ -453,20 +453,9 @@ std::expected<caf::PdmObjectHandle*, QString> RimcEclipseCase_propertyDataType::
|
||||
{
|
||||
if ( address.resultCatType() == resultCatTypeEnum && address.resultName() == m_propertyName() )
|
||||
{
|
||||
auto* dataObject = new RimcDataContainerString();
|
||||
const bool isInteger = address.dataType() == RiaDefines::ResultDataType::INTEGER;
|
||||
dataObject->m_stringValues = { isInteger ? QString( "INTEGER" ) : QString( "FLOAT" ) };
|
||||
return dataObject;
|
||||
return address.dataType();
|
||||
}
|
||||
}
|
||||
|
||||
return std::unexpected( QString( "Property not found: %1" ).arg( m_propertyName() ) );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RimcEclipseCase_propertyDataType::classKeywordReturnedType() const
|
||||
{
|
||||
return RimcDataContainerString::classKeywordStatic();
|
||||
}
|
||||
Reference in new issue
Block a user