mirror of
https://github.com/OPM/ResInsight.git
synced 2026-10-26 07:00:17 -05:00
#14001 Python: Drop hand-written PropertyType, use auto-generated PropertyType
Consolidate the hand-written PropertyType / NNCPropertyType enums in enums.py into the auto-generated StrEnum classes that already exist in generated_classes.py. enums.py and all its imports are removed. The auto-generated class for caf::AppEnum<RiaDefines::ResultCatType> was named "ResultType" because the existing scriptable m_resultType fields used keyword "ResultType". Switch those fields to CAF_PDM_InitScriptableFieldWithScriptKeywordNoDefault, keeping the XML keyword "ResultType" (so project files still load) but exposing the script keyword as "PropertyType". The generator now emits a single PropertyType StrEnum that: - matches the proto PropertyType for setters (FLOAT/INTEGER aside, the members callers actually use are identical), - gains ALLAN_DIAGRAMS that the C++ side already knew about, - loses the proto-only REMOVED/UNDEFINED sentinels (unused in any Python caller). rips.NNCPropertyType was exported but unreferenced anywhere — dropped. Updated Python callers: - rips.ResultType.X -> rips.PropertyType.X across examples and tests. - result_type= kwarg / .result_type attribute -> property_type / .property_type (the script keyword change renamed those everywhere the affected PdmObject fields are accessed from Python). - view.apply_cell_result's hand-written wrapper now takes property_type instead of result_type and forwards via cell_result.property_type. All 271 Python tests pass, ruff and clang-format clean.
This commit is contained in:
1 parent
a6c3ac2d1a
commit
01ceb57323
19 files changed
+126
-71
No files matched your search
@@ -16,6 +16,7 @@ set(PROJECT_FILES
|
||||
cafPdmDataContainerEnum.cpp
|
||||
cafPdmObjectMethod.h
|
||||
cafPdmObjectMethod.cpp
|
||||
cafPdmScriptEnumNameRegistry.h
|
||||
cafPdmObjectScriptingCapabilityRegister.h
|
||||
cafPdmObjectScriptingCapabilityRegister.cpp
|
||||
cafPdmPythonGenerator.h
|
||||
|
||||
@@ -45,6 +45,7 @@
|
||||
#include "cafPdmObjectMethod.h"
|
||||
#include "cafPdmObjectScriptingCapabilityRegister.h"
|
||||
#include "cafPdmProxyValueField.h"
|
||||
#include "cafPdmScriptEnumNameRegistry.h"
|
||||
#include "cafPdmXmlFieldHandle.h"
|
||||
|
||||
#ifndef CAF_EXCLUDE_CVF
|
||||
@@ -216,7 +217,10 @@ QString caf::PdmPythonGenerator::generate( PdmObjectFactory* factory, std::vecto
|
||||
auto cached = enumClassNameByDataTypeName.find( dataTypeName );
|
||||
if ( cached != enumClassNameByDataTypeName.end() ) return cached->second;
|
||||
|
||||
QString baseName = snakeToCamelCase( camelToSnakeCase( scriptability->scriptFieldName() ) );
|
||||
// Prefer an explicit override registered by application code so the Python enum class name
|
||||
// is stable independent of which field the generator visits first.
|
||||
QString baseName = PdmScriptEnumNameRegistry::lookup( dataTypeName );
|
||||
if ( baseName.isEmpty() ) baseName = snakeToCamelCase( camelToSnakeCase( scriptability->scriptFieldName() ) );
|
||||
if ( baseName.isEmpty() ) baseName = "Enum";
|
||||
|
||||
QString candidate = baseName;
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
//##################################################################################################
|
||||
//
|
||||
// Custom Visualization Core library
|
||||
// Copyright (C) 2026- Equinor ASA
|
||||
//
|
||||
// This library may be used under the terms of either the GNU General Public License or
|
||||
// the GNU Lesser General Public License as follows:
|
||||
//
|
||||
// GNU General Public License Usage
|
||||
// This library 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.
|
||||
//
|
||||
// This library 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 <<http://www.gnu.org/licenses/gpl.html>>
|
||||
// for more details.
|
||||
//
|
||||
// GNU Lesser General Public License Usage
|
||||
// This library is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Lesser General Public License as published by
|
||||
// the Free Software Foundation; either version 2.1 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This library 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 Lesser General Public License at <<http://www.gnu.org/licenses/lgpl-2.1.html>>
|
||||
// for more details.
|
||||
//
|
||||
//##################################################################################################
|
||||
#pragma once
|
||||
|
||||
#include "cafAppEnum.h"
|
||||
|
||||
#include <QString>
|
||||
|
||||
#include <map>
|
||||
#include <typeinfo>
|
||||
|
||||
namespace caf
|
||||
{
|
||||
//==================================================================================================
|
||||
/// Optional override for the Python StrEnum class name the code generator emits for a given
|
||||
/// caf::AppEnum<T>. Without an override, the generator derives the class name from the script
|
||||
/// keyword of the first field it visits — which is sensitive to class/iteration order. Use this
|
||||
/// registry to pin a canonical Python name for an AppEnum, independent of any field's script
|
||||
/// keyword.
|
||||
//==================================================================================================
|
||||
class PdmScriptEnumNameRegistry
|
||||
{
|
||||
public:
|
||||
template <typename EnumType>
|
||||
static void registerName( const QString& scriptClassName )
|
||||
{
|
||||
registry()[QString::fromLatin1( typeid( caf::AppEnum<EnumType> ).name() )] = scriptClassName;
|
||||
}
|
||||
|
||||
static QString lookup( const QString& dataTypeName )
|
||||
{
|
||||
const auto& m = registry();
|
||||
auto it = m.find( dataTypeName );
|
||||
if ( it == m.end() ) return QString();
|
||||
return it->second;
|
||||
}
|
||||
|
||||
private:
|
||||
static std::map<QString, QString>& registry()
|
||||
{
|
||||
static std::map<QString, QString> s_map;
|
||||
return s_map;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace caf
|
||||
Reference in new issue
Block a user