mirror of
https://github.com/OPM/ResInsight.git
synced 2026-08-26 21:27:15 -05:00
#14366 Python: Add per-view surface controls
This commit is contained in:
committed by
Magne Sjaastad
parent
56fb7a660b
commit
8c3df6076d
@@ -18,6 +18,8 @@
|
||||
|
||||
#include "RimSurfaceInViewCollection.h"
|
||||
|
||||
#include "Surface/RigSurface.h"
|
||||
|
||||
#include "Rim3dView.h"
|
||||
#include "RimEnsembleSurface.h"
|
||||
#include "RimGridView.h"
|
||||
@@ -36,6 +38,8 @@
|
||||
|
||||
#include "cvfModelBasicList.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
CAF_PDM_SOURCE_INIT( RimSurfaceInViewCollection, "SurfaceInViewCollection" );
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -254,6 +258,71 @@ void RimSurfaceInViewCollection::updateFromSurfaceCollection()
|
||||
updateAllViewItems();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RimSurfaceInViewCollection::setSurfaceVisible( RimSurface* surface, bool visible )
|
||||
{
|
||||
updateFromSurfaceCollection();
|
||||
|
||||
auto* surfaceInView = findSurfaceInView( surface );
|
||||
if ( !surfaceInView ) return false;
|
||||
|
||||
surfaceInView->setActive( visible );
|
||||
surfaceInView->updateConnectedEditors();
|
||||
return true;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::expected<void, QString> RimSurfaceInViewCollection::setSurfaceProperty( RimSurface* surface, const QString& propertyName )
|
||||
{
|
||||
updateFromSurfaceCollection();
|
||||
|
||||
auto* surfaceInView = findSurfaceInView( surface );
|
||||
if ( !surfaceInView )
|
||||
{
|
||||
return std::unexpected( QString( "Surface is not available in this view." ) );
|
||||
}
|
||||
|
||||
surface->loadDataIfRequired();
|
||||
auto* surfaceData = surface->surfaceData();
|
||||
if ( !surfaceData )
|
||||
{
|
||||
return std::unexpected( QString( "Surface '%1' has no surface data." ).arg( surface->fullName() ) );
|
||||
}
|
||||
|
||||
const auto propertyNames = surfaceData->propertyNames();
|
||||
if ( std::find( propertyNames.begin(), propertyNames.end(), propertyName ) == propertyNames.end() )
|
||||
{
|
||||
return std::unexpected( QString( "Property '%1' is not available for surface '%2'." ).arg( propertyName, surface->fullName() ) );
|
||||
}
|
||||
|
||||
surfaceInView->surfaceResultDefinition()->setPropertyName( propertyName );
|
||||
return {};
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RimSurfaceInViewCollection::isSurfaceVisible( const RimSurface* surface ) const
|
||||
{
|
||||
auto* surfaceInView = findSurfaceInView( surface );
|
||||
return surfaceInView && surfaceInView->isActive();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RimSurfaceInViewCollection::surfaceProperty( const RimSurface* surface ) const
|
||||
{
|
||||
auto* surfaceInView = findSurfaceInView( surface );
|
||||
if ( !surfaceInView ) return {};
|
||||
|
||||
return surfaceInView->surfaceResultDefinition()->propertyName();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -360,6 +429,21 @@ RimSurfaceInView* RimSurfaceInViewCollection::getSurfaceInViewForSurface( const
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RimSurfaceInView* RimSurfaceInViewCollection::findSurfaceInView( const RimSurface* surface ) const
|
||||
{
|
||||
if ( auto* surfaceInView = getSurfaceInViewForSurface( surface ) ) return surfaceInView;
|
||||
|
||||
for ( auto collection : m_collectionsInView )
|
||||
{
|
||||
if ( auto* surfaceInView = collection->findSurfaceInView( surface ) ) return surfaceInView;
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
||||
@@ -26,6 +26,8 @@
|
||||
#include "cafPdmProxyValueField.h"
|
||||
#include "cafPdmPtrField.h"
|
||||
|
||||
#include <expected>
|
||||
|
||||
namespace cvf
|
||||
{
|
||||
class ModelBasicList;
|
||||
@@ -58,6 +60,12 @@ public:
|
||||
void setSurfaceCollection( RimSurfaceCollection* surfcoll );
|
||||
|
||||
void updateFromSurfaceCollection();
|
||||
|
||||
bool setSurfaceVisible( RimSurface* surface, bool visible );
|
||||
std::expected<void, QString> setSurfaceProperty( RimSurface* surface, const QString& propertyName );
|
||||
bool isSurfaceVisible( const RimSurface* surface ) const;
|
||||
QString surfaceProperty( const RimSurface* surface ) const;
|
||||
|
||||
void loadData( int timeStep );
|
||||
void clearGeometry();
|
||||
|
||||
@@ -82,6 +90,7 @@ private:
|
||||
void fieldChangedByUi( const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue ) override;
|
||||
|
||||
RimSurfaceInView* getSurfaceInViewForSurface( const RimSurface* surf ) const;
|
||||
RimSurfaceInView* findSurfaceInView( const RimSurface* surface ) const;
|
||||
RimSurfaceInViewCollection* getCollectionInViewForCollection( const RimSurfaceCollection* coll ) const;
|
||||
|
||||
void updateAllViewItems();
|
||||
|
||||
@@ -66,6 +66,17 @@ void RimSurfaceResultDefinition::setSurfaceInView( RimSurfaceInView* surfaceInVi
|
||||
assignDefaultProperty();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimSurfaceResultDefinition::setPropertyName( const QString& propertyName )
|
||||
{
|
||||
m_propertyName = propertyName;
|
||||
setCheckState( true );
|
||||
updateMinMaxValues( -1 );
|
||||
updateConnectedEditors();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
||||
@@ -40,6 +40,7 @@ public:
|
||||
~RimSurfaceResultDefinition() override;
|
||||
|
||||
void setSurfaceInView( RimSurfaceInView* surfaceInView );
|
||||
void setPropertyName( const QString& propertyName );
|
||||
QString propertyName() const;
|
||||
|
||||
RimRegularLegendConfig* legendConfig();
|
||||
|
||||
@@ -26,6 +26,8 @@
|
||||
#include "Rim3dView.h"
|
||||
#include "RimEclipseView.h"
|
||||
#include "RimGridView.h"
|
||||
#include "Surfaces/RimSurface.h"
|
||||
#include "Surfaces/RimSurfaceInViewCollection.h"
|
||||
|
||||
#include "cafPdmFieldScriptingCapability.h"
|
||||
|
||||
@@ -33,6 +35,8 @@
|
||||
|
||||
CAF_PDM_OBJECT_METHOD_SOURCE_INIT( RimEclipseView, RimcGridView_visibleCellsInternal, "visible_cells_internal" );
|
||||
CAF_PDM_OBJECT_METHOD_SOURCE_INIT( Rim3dView, RimcGridView_setPolygonVisible, "set_polygon_visible" );
|
||||
CAF_PDM_OBJECT_METHOD_SOURCE_INIT( Rim3dView, RimcGridView_setSurfaceVisible, "set_surface_visible" );
|
||||
CAF_PDM_OBJECT_METHOD_SOURCE_INIT( Rim3dView, RimcGridView_setSurfaceProperty, "set_surface_property" );
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
@@ -121,3 +125,82 @@ std::expected<caf::PdmObjectHandle*, QString> RimcGridView_setPolygonVisible::ex
|
||||
gridView->scheduleCreateDisplayModelAndRedraw();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RimcGridView_setSurfaceVisible::RimcGridView_setSurfaceVisible( caf::PdmObjectHandle* self )
|
||||
: caf::PdmVoidObjectMethod( self )
|
||||
{
|
||||
CAF_PDM_InitObject( "Set Surface Visible", "", "", "Set surface visibility in this view" );
|
||||
|
||||
CAF_PDM_InitScriptableFieldNoDefault( &m_surface, "Surface", "Surface" );
|
||||
CAF_PDM_InitScriptableField( &m_visible, "Visible", true, "Visible" );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::expected<caf::PdmObjectHandle*, QString> RimcGridView_setSurfaceVisible::execute()
|
||||
{
|
||||
auto* gridView = self<RimGridView>();
|
||||
if ( !gridView )
|
||||
{
|
||||
return std::unexpected( QString( "Surface visibility is only supported for grid views." ) );
|
||||
}
|
||||
|
||||
if ( !m_surface() )
|
||||
{
|
||||
return std::unexpected( QString( "Surface is null." ) );
|
||||
}
|
||||
|
||||
auto* collection = gridView->surfaceInViewCollection();
|
||||
if ( !collection || !collection->setSurfaceVisible( m_surface(), m_visible() ) )
|
||||
{
|
||||
return std::unexpected( QString( "Surface '%1' is not available in this view." ).arg( m_surface()->fullName() ) );
|
||||
}
|
||||
|
||||
gridView->scheduleCreateDisplayModelAndRedraw();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RimcGridView_setSurfaceProperty::RimcGridView_setSurfaceProperty( caf::PdmObjectHandle* self )
|
||||
: caf::PdmVoidObjectMethod( self )
|
||||
{
|
||||
CAF_PDM_InitObject( "Set Surface Property", "", "", "Set the surface property shown in this view" );
|
||||
|
||||
CAF_PDM_InitScriptableFieldNoDefault( &m_surface, "Surface", "Surface" );
|
||||
CAF_PDM_InitScriptableFieldNoDefault( &m_propertyName, "PropertyName", "Property Name" );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::expected<caf::PdmObjectHandle*, QString> RimcGridView_setSurfaceProperty::execute()
|
||||
{
|
||||
auto* gridView = self<RimGridView>();
|
||||
if ( !gridView )
|
||||
{
|
||||
return std::unexpected( QString( "Surface properties are only supported for grid views." ) );
|
||||
}
|
||||
|
||||
if ( !m_surface() )
|
||||
{
|
||||
return std::unexpected( QString( "Surface is null." ) );
|
||||
}
|
||||
|
||||
auto* collection = gridView->surfaceInViewCollection();
|
||||
if ( !collection )
|
||||
{
|
||||
return std::unexpected( QString( "Surface '%1' is not available in this view." ).arg( m_surface()->fullName() ) );
|
||||
}
|
||||
|
||||
auto result = collection->setSurfaceProperty( m_surface(), m_propertyName() );
|
||||
if ( !result ) return std::unexpected( result.error() );
|
||||
|
||||
gridView->scheduleCreateDisplayModelAndRedraw();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
#include <QString>
|
||||
|
||||
class RimPolygon;
|
||||
class RimSurface;
|
||||
|
||||
//==================================================================================================
|
||||
///
|
||||
@@ -60,3 +61,37 @@ private:
|
||||
caf::PdmPtrField<RimPolygon*> m_polygon;
|
||||
caf::PdmField<bool> m_visible;
|
||||
};
|
||||
|
||||
//==================================================================================================
|
||||
///
|
||||
//==================================================================================================
|
||||
class RimcGridView_setSurfaceVisible : public caf::PdmVoidObjectMethod
|
||||
{
|
||||
CAF_PDM_HEADER_INIT;
|
||||
|
||||
public:
|
||||
RimcGridView_setSurfaceVisible( caf::PdmObjectHandle* self );
|
||||
|
||||
std::expected<caf::PdmObjectHandle*, QString> execute() override;
|
||||
|
||||
private:
|
||||
caf::PdmPtrField<RimSurface*> m_surface;
|
||||
caf::PdmField<bool> m_visible;
|
||||
};
|
||||
|
||||
//==================================================================================================
|
||||
///
|
||||
//==================================================================================================
|
||||
class RimcGridView_setSurfaceProperty : public caf::PdmVoidObjectMethod
|
||||
{
|
||||
CAF_PDM_HEADER_INIT;
|
||||
|
||||
public:
|
||||
RimcGridView_setSurfaceProperty( caf::PdmObjectHandle* self );
|
||||
|
||||
std::expected<caf::PdmObjectHandle*, QString> execute() override;
|
||||
|
||||
private:
|
||||
caf::PdmPtrField<RimSurface*> m_surface;
|
||||
caf::PdmField<QString> m_propertyName;
|
||||
};
|
||||
|
||||
@@ -143,6 +143,7 @@ set(SOURCE_UNITTEST_FILES
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaResultName-Test.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RigPolygonTools-Test.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RimPolygonInViewCollection-Test.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RimSurfaceInViewCollection-Test.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaNameUniquenessTools-Test.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RifVtkSurfaceImporter-Test.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RifVtkReader-Test.cpp
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2026 Equinor ASA
|
||||
//
|
||||
// ResInsight 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.
|
||||
//
|
||||
// ResInsight 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.
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
#include "RimRegularSurface.h"
|
||||
#include "RimSurfaceCollection.h"
|
||||
#include "RimSurfaceInViewCollection.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST( RimSurfaceInViewCollection, SurfaceSettingsAreIndependentPerView )
|
||||
{
|
||||
auto sourceCollection = std::make_unique<RimSurfaceCollection>();
|
||||
|
||||
auto* subCollection = new RimSurfaceCollection();
|
||||
subCollection->setCollectionName( "Folder" );
|
||||
sourceCollection->addSubCollection( subCollection );
|
||||
|
||||
auto* surface = new RimRegularSurface();
|
||||
surface->setUserDescription( "Surface" );
|
||||
surface->setNx( 2 );
|
||||
surface->setNy( 2 );
|
||||
surface->setProperty( "Property A", { 1.0f, 2.0f, 3.0f, 4.0f } );
|
||||
surface->setProperty( "Property B", { 5.0f, 6.0f, 7.0f, 8.0f } );
|
||||
surface->onLoadData();
|
||||
subCollection->addSurface( surface );
|
||||
|
||||
RimSurfaceInViewCollection firstViewCollection;
|
||||
firstViewCollection.setSurfaceCollection( sourceCollection.get() );
|
||||
firstViewCollection.updateFromSurfaceCollection();
|
||||
|
||||
RimSurfaceInViewCollection secondViewCollection;
|
||||
secondViewCollection.setSurfaceCollection( sourceCollection.get() );
|
||||
secondViewCollection.updateFromSurfaceCollection();
|
||||
|
||||
EXPECT_TRUE( firstViewCollection.isSurfaceVisible( surface ) );
|
||||
EXPECT_TRUE( secondViewCollection.isSurfaceVisible( surface ) );
|
||||
EXPECT_EQ( QString( "Property A" ), firstViewCollection.surfaceProperty( surface ) );
|
||||
EXPECT_EQ( QString( "Property A" ), secondViewCollection.surfaceProperty( surface ) );
|
||||
|
||||
EXPECT_TRUE( firstViewCollection.setSurfaceVisible( surface, false ) );
|
||||
EXPECT_FALSE( firstViewCollection.isSurfaceVisible( surface ) );
|
||||
EXPECT_TRUE( secondViewCollection.isSurfaceVisible( surface ) );
|
||||
|
||||
auto propertyResult = firstViewCollection.setSurfaceProperty( surface, "Property B" );
|
||||
ASSERT_TRUE( propertyResult.has_value() );
|
||||
EXPECT_EQ( QString( "Property B" ), firstViewCollection.surfaceProperty( surface ) );
|
||||
EXPECT_EQ( QString( "Property A" ), secondViewCollection.surfaceProperty( surface ) );
|
||||
|
||||
auto invalidPropertyResult = firstViewCollection.setSurfaceProperty( surface, "Missing" );
|
||||
EXPECT_FALSE( invalidPropertyResult.has_value() );
|
||||
EXPECT_EQ( QString( "Property B" ), firstViewCollection.surfaceProperty( surface ) );
|
||||
|
||||
auto unrelatedSurface = std::make_unique<RimRegularSurface>();
|
||||
EXPECT_FALSE( firstViewCollection.setSurfaceVisible( unrelatedSurface.get(), false ) );
|
||||
EXPECT_FALSE( firstViewCollection.setSurfaceProperty( unrelatedSurface.get(), "Property A" ).has_value() );
|
||||
}
|
||||
@@ -82,6 +82,33 @@ def test_create_regular_surface(rips_instance, initialize_test):
|
||||
s.update()
|
||||
|
||||
|
||||
def test_surface_settings_in_view(rips_instance, initialize_test):
|
||||
case_path = dataroot.PATH + "/Case_with_10_timesteps/Real0/BRUGGE_0000.EGRID"
|
||||
case = rips_instance.project.load_case(path=case_path)
|
||||
|
||||
surface_collection = rips_instance.project.descendants(rips.SurfaceCollection)[0]
|
||||
folder = surface_collection.add_folder(folder_name="View surfaces")
|
||||
surface = folder.new_regular_surface(name="View surface", nx=2, ny=2)
|
||||
surface.set_property("Property A", [1.0, 2.0, 3.0, 4.0])
|
||||
surface.set_property("Property B", [5.0, 6.0, 7.0, 8.0])
|
||||
|
||||
first_view = case.create_view()
|
||||
second_view = case.create_view()
|
||||
|
||||
assert first_view.set_surface_visible(surface=surface, visible=False) is None
|
||||
assert second_view.set_surface_visible(surface=surface, visible=True) is None
|
||||
assert (
|
||||
first_view.set_surface_property(surface=surface, property_name="Property B")
|
||||
is None
|
||||
)
|
||||
|
||||
with pytest.raises(rips.RipsError, match="not available for surface"):
|
||||
first_view.set_surface_property(surface=surface, property_name="Missing")
|
||||
|
||||
with pytest.raises(rips.RipsError, match="Surface is null"):
|
||||
first_view.set_surface_visible(surface=None, visible=True)
|
||||
|
||||
|
||||
def test_get_property(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)
|
||||
|
||||
Reference in New Issue
Block a user