mirror of
https://github.com/OPM/ResInsight.git
synced 2026-10-26 07:00:17 -05:00
Refactor depth property handling for regular surfaces
- Introduce RimRegularFileSurface::propertyName() as canonical property key for file-based surfaces. - Change RimRegularSurface::setPropertyAsDepth() to void and remove existence check; error handling is now in updateSurfaceData(). - Update all usages to match new setPropertyAsDepth() behavior. - Log and handle missing depth property in updateSurfaceData(). - Update tests to reflect new error handling approach. - Minor includes and logging improvements.
This commit is contained in:
1 parent
a6ce2b3a65
commit
4b9f94efb8
7 files changed
+25
-16
No files matched your search
@@ -26,6 +26,14 @@
|
||||
|
||||
CAF_PDM_SOURCE_INIT( RimRegularFileSurface, "RegularFileSurface" );
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RimRegularFileSurface::propertyName()
|
||||
{
|
||||
return "Property Values in File";
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -72,8 +80,7 @@ bool RimRegularFileSurface::onLoadData()
|
||||
|
||||
if ( !values.empty() )
|
||||
{
|
||||
const QString propertyName = "File Property Values";
|
||||
setProperty( propertyName, values );
|
||||
setProperty( RimRegularFileSurface::propertyName(), values );
|
||||
}
|
||||
|
||||
RimRegularSurface::onLoadData();
|
||||
|
||||
@@ -29,6 +29,8 @@ public:
|
||||
|
||||
bool onLoadData() override;
|
||||
|
||||
static QString propertyName();
|
||||
|
||||
// File-based surface interface (from RimSurface)
|
||||
bool isFileBased() const override { return true; }
|
||||
QString filePath() const override;
|
||||
|
||||
@@ -18,6 +18,8 @@
|
||||
|
||||
#include "RimRegularSurface.h"
|
||||
|
||||
#include "RiaLogging.h"
|
||||
|
||||
#include "Surface/RigSurface.h"
|
||||
|
||||
#include "RimSurfaceCollection.h"
|
||||
@@ -208,6 +210,14 @@ void RimRegularSurface::clearCachedNativeData()
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RimRegularSurface::updateSurfaceData()
|
||||
{
|
||||
if ( m_depthProperty() != internal::fixedDepth() && !m_properties.contains( m_depthProperty() ) )
|
||||
{
|
||||
RiaLogging::warning( QString( "Surface '%1': Depth property '%2' not found." ).arg( userDescription(), m_depthProperty() ) );
|
||||
setSurfaceData( nullptr );
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// Adapted from xtgeo surf_xyz_from_ij
|
||||
auto computeXyzFromIj =
|
||||
[]( int i, int j, double depth, double xori, double yori, double xinc, double yinc, double rotationDegrees ) -> cvf::Vec3d
|
||||
@@ -390,12 +400,9 @@ void RimRegularSurface::setProperty( const QString& key, const std::vector<float
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RimRegularSurface::setPropertyAsDepth( const QString& key )
|
||||
void RimRegularSurface::setPropertyAsDepth( const QString& key )
|
||||
{
|
||||
if ( !m_properties.contains( key ) ) return false;
|
||||
|
||||
m_depthProperty = key;
|
||||
return true;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
||||
@@ -40,7 +40,7 @@ public:
|
||||
void setRotation( double rotation );
|
||||
|
||||
void setProperty( const QString& key, const std::vector<float>& values );
|
||||
bool setPropertyAsDepth( const QString& key );
|
||||
void setPropertyAsDepth( const QString& key );
|
||||
|
||||
int nx() const;
|
||||
int ny() const;
|
||||
|
||||
@@ -151,6 +151,7 @@ RimSurface* RimSurfaceCollection::createSurfaceFromFile( const QString& fileName
|
||||
{
|
||||
auto regularFileSurface = new RimRegularFileSurface;
|
||||
regularFileSurface->setFilePath( fileName );
|
||||
regularFileSurface->setPropertyAsDepth( RimRegularFileSurface::propertyName() );
|
||||
newSurface = regularFileSurface;
|
||||
}
|
||||
else
|
||||
|
||||
@@ -94,8 +94,7 @@ std::expected<caf::PdmObjectHandle*, QString> RimcRegularSurface_setPropertyAsDe
|
||||
RimRegularSurface* surface = self<RimRegularSurface>();
|
||||
if ( !surface ) return std::unexpected( "No surface found" );
|
||||
|
||||
if ( !surface->setPropertyAsDepth( m_name ) ) return std::unexpected( "Failed to set depth property." );
|
||||
|
||||
surface->setPropertyAsDepth( m_name );
|
||||
surface->onLoadData();
|
||||
|
||||
if ( auto coll = surface->firstAncestorOrThisOfType<RimSurfaceCollection>() )
|
||||
|
||||
@@ -68,9 +68,6 @@ def test_create_regular_surface(rips_instance, initialize_test):
|
||||
assert s.nx == nx
|
||||
assert s.ny == ny
|
||||
|
||||
with pytest.raises(rips.RipsError, match="Failed to set depth property."):
|
||||
s.set_property_as_depth(name="non_existing_property")
|
||||
|
||||
with pytest.raises(
|
||||
rips.RipsError, match="Failed to set property: incorrect dimensions."
|
||||
):
|
||||
@@ -84,10 +81,6 @@ def test_create_regular_surface(rips_instance, initialize_test):
|
||||
s.nx = 30
|
||||
s.update()
|
||||
|
||||
# 'depth' property is now gone
|
||||
with pytest.raises(rips.RipsError, match="Failed to set depth property."):
|
||||
s.set_property_as_depth(name="depth")
|
||||
|
||||
|
||||
def test_create_regular_surface_invalid_values(rips_instance, initialize_test):
|
||||
case_path = dataroot.PATH + "/Case_with_10_timesteps/Real0/BRUGGE_0000.EGRID"
|
||||
|
||||
Reference in new issue
Block a user