diff --git a/ApplicationLibCode/ProjectDataModel/Surfaces/RimRegularSurface.cpp b/ApplicationLibCode/ProjectDataModel/Surfaces/RimRegularSurface.cpp index dff95f7e46..0bb235de83 100644 --- a/ApplicationLibCode/ProjectDataModel/Surfaces/RimRegularSurface.cpp +++ b/ApplicationLibCode/ProjectDataModel/Surfaces/RimRegularSurface.cpp @@ -415,6 +415,19 @@ std::vector RimRegularSurface::getProperty( const QString& key ) const return {}; } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +std::vector RimRegularSurface::propertyNames() const +{ + std::vector names; + for ( const auto& [key, value] : m_properties ) + { + names.push_back( key ); + } + return names; +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationLibCode/ProjectDataModel/Surfaces/RimRegularSurface.h b/ApplicationLibCode/ProjectDataModel/Surfaces/RimRegularSurface.h index 9d2a6ca37e..4b3cfa1b29 100644 --- a/ApplicationLibCode/ProjectDataModel/Surfaces/RimRegularSurface.h +++ b/ApplicationLibCode/ProjectDataModel/Surfaces/RimRegularSurface.h @@ -42,7 +42,8 @@ public: void setProperty( const QString& key, const std::vector& values ); void setPropertyAsDepth( const QString& key ); - std::vector getProperty( const QString& key ) const; + std::vector getProperty( const QString& key ) const; + std::vector propertyNames() const; int nx() const; int ny() const; diff --git a/ApplicationLibCode/ProjectDataModelCommands/RimcRegularSurface.cpp b/ApplicationLibCode/ProjectDataModelCommands/RimcRegularSurface.cpp index e07f3875dc..8a388b36cb 100644 --- a/ApplicationLibCode/ProjectDataModelCommands/RimcRegularSurface.cpp +++ b/ApplicationLibCode/ProjectDataModelCommands/RimcRegularSurface.cpp @@ -22,6 +22,7 @@ #include "RimRegularSurface.h" #include "RimSurfaceCollection.h" +#include "RimcDataContainerString.h" #include "RifSurfaceExporter.h" @@ -138,3 +139,36 @@ std::expected RimcRegularSurface_setPropertyAsDe return nullptr; } + +CAF_PDM_OBJECT_METHOD_SOURCE_INIT( RimRegularSurface, RimcRegularSurface_propertyNames, "PropertyNames" ); + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RimcRegularSurface_propertyNames::RimcRegularSurface_propertyNames( caf::PdmObjectHandle* self ) + : PdmObjectMethod( self, PdmObjectMethod::NullPointerType::NULL_IS_INVALID, PdmObjectMethod::ResultType::PERSISTENT_FALSE ) +{ + CAF_PDM_InitObject( "Property Names", "", "", "Property Names." ); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +std::expected RimcRegularSurface_propertyNames::execute() +{ + RimRegularSurface* surface = self(); + if ( !surface ) return std::unexpected( "No surface found" ); + + auto dataObject = new RimcDataContainerString(); + dataObject->m_stringValues = surface->propertyNames(); + + return dataObject; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +QString RimcRegularSurface_propertyNames::classKeywordReturnedType() const +{ + return RimcDataContainerString::classKeywordStatic(); +} diff --git a/ApplicationLibCode/ProjectDataModelCommands/RimcRegularSurface.h b/ApplicationLibCode/ProjectDataModelCommands/RimcRegularSurface.h index 86a993f835..84302d3726 100644 --- a/ApplicationLibCode/ProjectDataModelCommands/RimcRegularSurface.h +++ b/ApplicationLibCode/ProjectDataModelCommands/RimcRegularSurface.h @@ -75,3 +75,17 @@ public: private: caf::PdmField m_name; }; + +//================================================================================================== +/// +//================================================================================================== +class RimcRegularSurface_propertyNames : public caf::PdmObjectMethod +{ + CAF_PDM_HEADER_INIT; + +public: + RimcRegularSurface_propertyNames( caf::PdmObjectHandle* self ); + + std::expected execute() override; + QString classKeywordReturnedType() const override; +}; diff --git a/GrpcInterface/Python/rips/PythonExamples/surfaces_and_visualization/create_regular_surface.py b/GrpcInterface/Python/rips/PythonExamples/surfaces_and_visualization/create_regular_surface.py index 0d46ea98df..ba4c697588 100644 --- a/GrpcInterface/Python/rips/PythonExamples/surfaces_and_visualization/create_regular_surface.py +++ b/GrpcInterface/Python/rips/PythonExamples/surfaces_and_visualization/create_regular_surface.py @@ -83,5 +83,9 @@ if resinsight is not None: f"Retrieved {len(wave_values)} wave property values, min={min(wave_values):.2f}, max={max(wave_values):.2f}" ) + # List available properties + props = s.available_properties() + print(f"Available properties: {props}") + # Use the wave as depth for the surface s.set_property_as_depth("wave") diff --git a/GrpcInterface/Python/rips/surface.py b/GrpcInterface/Python/rips/surface.py index 8e81d2381a..b3584d1836 100644 --- a/GrpcInterface/Python/rips/surface.py +++ b/GrpcInterface/Python/rips/surface.py @@ -25,6 +25,17 @@ def set_property(self: RegularSurface, name: str, values: List[float]) -> None: self.set_property_from_key(name=name, value_key=key) +@add_method(RegularSurface) +def available_properties(self: RegularSurface) -> List[str]: + """Gets the list of available property names on a regular surface. + + Returns: + List[str]: Names of all properties set on this surface. + """ + result = self.property_names() + return result.values + + @add_method(RegularSurface) def get_property(self: RegularSurface, name: str) -> List[float]: """Gets a property from a regular surface. diff --git a/GrpcInterface/Python/rips/tests/test_surfaces.py b/GrpcInterface/Python/rips/tests/test_surfaces.py index 754230de3d..cc57dca69c 100644 --- a/GrpcInterface/Python/rips/tests/test_surfaces.py +++ b/GrpcInterface/Python/rips/tests/test_surfaces.py @@ -106,6 +106,35 @@ def test_get_property(rips_instance, initialize_test): s.get_property("non_existent_property") +def test_available_properties(rips_instance, initialize_test): + case_path = dataroot.PATH + "/Case_with_10_timesteps/Real0/BRUGGE_0000.EGRID" + c = rips_instance.project.load_case(path=case_path) + assert len(c.grids()) == 1 + + surface_collection = rips_instance.project.descendants(rips.SurfaceCollection)[0] + + nx = 5 + ny = 4 + s = surface_collection.new_regular_surface(nx=nx, ny=ny) + + # Empty property list initially + props = s.available_properties() + assert props == [] + + # Property names after setting one property + s.set_property("prop_a", [float(i) for i in range(nx * ny)]) + props = s.available_properties() + assert "prop_a" in props + assert len(props) == 1 + + # Property names persist after setting multiple properties + s.set_property("prop_b", [float(i) for i in range(nx * ny)]) + props = s.available_properties() + assert len(props) == 2 + assert "prop_a" in props + assert "prop_b" in props + + def test_create_regular_surface_invalid_values(rips_instance, initialize_test): case_path = dataroot.PATH + "/Case_with_10_timesteps/Real0/BRUGGE_0000.EGRID" c = rips_instance.project.load_case(path=case_path)