diff --git a/ApplicationLibCode/ProjectDataModel/Polygons/RimPolygonInViewCollection.cpp b/ApplicationLibCode/ProjectDataModel/Polygons/RimPolygonInViewCollection.cpp index 679316fa7d..6134598f10 100644 --- a/ApplicationLibCode/ProjectDataModel/Polygons/RimPolygonInViewCollection.cpp +++ b/ApplicationLibCode/ProjectDataModel/Polygons/RimPolygonInViewCollection.cpp @@ -92,6 +92,39 @@ std::vector RimPolygonInViewCollection::allPolygonsInView() c return polys; } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool RimPolygonInViewCollection::setPolygonVisible( RimPolygon* polygon, bool visible ) +{ + updateFromPolygonCollection(); + + auto* polygonInView = findPolygonInView( polygon ); + if ( !polygonInView ) return false; + + polygonInView->setCheckState( visible ); + polygonInView->updateConnectedEditors(); + return true; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RimPolygonInView* RimPolygonInViewCollection::findPolygonInView( const RimPolygon* polygon ) const +{ + for ( auto polygonInView : m_itemsInView ) + { + if ( polygonInView && polygonInView->polygon() == polygon ) return polygonInView; + } + + for ( auto collection : m_collectionsInView ) + { + if ( auto* polygonInView = collection->findPolygonInView( polygon ) ) return polygonInView; + } + + return nullptr; +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationLibCode/ProjectDataModel/Polygons/RimPolygonInViewCollection.h b/ApplicationLibCode/ProjectDataModel/Polygons/RimPolygonInViewCollection.h index f85a6ba3f5..2b1a3e5630 100644 --- a/ApplicationLibCode/ProjectDataModel/Polygons/RimPolygonInViewCollection.h +++ b/ApplicationLibCode/ProjectDataModel/Polygons/RimPolygonInViewCollection.h @@ -40,12 +40,16 @@ class RimPolygonInViewCollection : public RimNestedMirrorCollectionInView visiblePolygonsInView() const; std::vector allPolygonsInView() const; + bool setPolygonVisible( RimPolygon* polygon, bool visible ); + protected: std::vector sourceSubCollections() const override; std::vector sourceItems() const override; RimPolygonInView* createItemInView( RimPolygon* source ) override; private: + RimPolygonInView* findPolygonInView( const RimPolygon* polygon ) const; + void fieldChangedByUi( const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue ) override; void appendMenuItems( caf::CmdFeatureMenuBuilder& menuBuilder ) const override; }; diff --git a/ApplicationLibCode/ProjectDataModel/Surfaces/RimSurfaceInViewCollection.cpp b/ApplicationLibCode/ProjectDataModel/Surfaces/RimSurfaceInViewCollection.cpp index f5ff6ade18..1a647b40a8 100644 --- a/ApplicationLibCode/ProjectDataModel/Surfaces/RimSurfaceInViewCollection.cpp +++ b/ApplicationLibCode/ProjectDataModel/Surfaces/RimSurfaceInViewCollection.cpp @@ -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 + 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 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; +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationLibCode/ProjectDataModel/Surfaces/RimSurfaceInViewCollection.h b/ApplicationLibCode/ProjectDataModel/Surfaces/RimSurfaceInViewCollection.h index a0087a7361..052c05c5d8 100644 --- a/ApplicationLibCode/ProjectDataModel/Surfaces/RimSurfaceInViewCollection.h +++ b/ApplicationLibCode/ProjectDataModel/Surfaces/RimSurfaceInViewCollection.h @@ -26,6 +26,8 @@ #include "cafPdmProxyValueField.h" #include "cafPdmPtrField.h" +#include + namespace cvf { class ModelBasicList; @@ -58,6 +60,12 @@ class RimSurfaceInViewCollection : public RimCheckableNamedObject void setSurfaceCollection( RimSurfaceCollection* surfcoll ); void updateFromSurfaceCollection(); + + bool setSurfaceVisible( RimSurface* surface, bool visible ); + std::expected 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 @@ class RimSurfaceInViewCollection : public RimCheckableNamedObject 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(); diff --git a/ApplicationLibCode/ProjectDataModel/Surfaces/RimSurfaceResultDefinition.cpp b/ApplicationLibCode/ProjectDataModel/Surfaces/RimSurfaceResultDefinition.cpp index 5e4e6a77de..822324aac6 100644 --- a/ApplicationLibCode/ProjectDataModel/Surfaces/RimSurfaceResultDefinition.cpp +++ b/ApplicationLibCode/ProjectDataModel/Surfaces/RimSurfaceResultDefinition.cpp @@ -66,6 +66,17 @@ void RimSurfaceResultDefinition::setSurfaceInView( RimSurfaceInView* surfaceInVi assignDefaultProperty(); } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimSurfaceResultDefinition::setPropertyName( const QString& propertyName ) +{ + m_propertyName = propertyName; + setCheckState( true ); + updateMinMaxValues( -1 ); + updateConnectedEditors(); +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationLibCode/ProjectDataModel/Surfaces/RimSurfaceResultDefinition.h b/ApplicationLibCode/ProjectDataModel/Surfaces/RimSurfaceResultDefinition.h index 7c59e61e71..1455bc13ff 100644 --- a/ApplicationLibCode/ProjectDataModel/Surfaces/RimSurfaceResultDefinition.h +++ b/ApplicationLibCode/ProjectDataModel/Surfaces/RimSurfaceResultDefinition.h @@ -40,6 +40,7 @@ class RimSurfaceResultDefinition : public RimCheckableNamedObject ~RimSurfaceResultDefinition() override; void setSurfaceInView( RimSurfaceInView* surfaceInView ); + void setPropertyName( const QString& propertyName ); QString propertyName() const; RimRegularLegendConfig* legendConfig(); diff --git a/ApplicationLibCode/ProjectDataModelCommands/RimcGridView.cpp b/ApplicationLibCode/ProjectDataModelCommands/RimcGridView.cpp index e42ddad5e6..91e2c95f27 100644 --- a/ApplicationLibCode/ProjectDataModelCommands/RimcGridView.cpp +++ b/ApplicationLibCode/ProjectDataModelCommands/RimcGridView.cpp @@ -21,14 +21,22 @@ #include "RiaApplication.h" #include "RiaKeyValueStoreUtil.h" +#include "Polygons/RimPolygon.h" +#include "Polygons/RimPolygonInViewCollection.h" +#include "Rim3dView.h" #include "RimEclipseView.h" #include "RimGridView.h" +#include "Surfaces/RimSurface.h" +#include "Surfaces/RimSurfaceInViewCollection.h" #include "cafPdmFieldScriptingCapability.h" #include "cvfArray.h" 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" ); //-------------------------------------------------------------------------------------------------- /// @@ -80,3 +88,119 @@ std::expected RimcGridView_visibleCellsInternal: return nullptr; } + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RimcGridView_setPolygonVisible::RimcGridView_setPolygonVisible( caf::PdmObjectHandle* self ) + : caf::PdmVoidObjectMethod( self ) +{ + CAF_PDM_InitObject( "Set Polygon Visible", "", "", "Set polygon visibility in this view" ); + + CAF_PDM_InitScriptableFieldNoDefault( &m_polygon, "Polygon", "Polygon" ); + CAF_PDM_InitScriptableField( &m_visible, "Visible", true, "Visible" ); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +std::expected RimcGridView_setPolygonVisible::execute() +{ + auto* gridView = self(); + if ( !gridView ) + { + return std::unexpected( QString( "Polygon visibility is only supported for grid views." ) ); + } + + if ( !m_polygon() ) + { + return std::unexpected( QString( "Polygon is null." ) ); + } + + if ( !gridView->polygonInViewCollection()->setPolygonVisible( m_polygon(), m_visible() ) ) + { + return std::unexpected( QString( "Polygon '%1' is not available in this view." ).arg( m_polygon()->name() ) ); + } + + 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 RimcGridView_setSurfaceVisible::execute() +{ + auto* gridView = self(); + 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 RimcGridView_setSurfaceProperty::execute() +{ + auto* gridView = self(); + 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; +} diff --git a/ApplicationLibCode/ProjectDataModelCommands/RimcGridView.h b/ApplicationLibCode/ProjectDataModelCommands/RimcGridView.h index 82c6d4e2e3..3ba4a35bd8 100644 --- a/ApplicationLibCode/ProjectDataModelCommands/RimcGridView.h +++ b/ApplicationLibCode/ProjectDataModelCommands/RimcGridView.h @@ -21,9 +21,13 @@ #include "cafPdmField.h" #include "cafPdmObjectHandle.h" #include "cafPdmObjectMethod.h" +#include "cafPdmPtrField.h" #include +class RimPolygon; +class RimSurface; + //================================================================================================== /// //================================================================================================== @@ -40,3 +44,54 @@ class RimcGridView_visibleCellsInternal : public caf::PdmVoidObjectMethod caf::PdmField m_visibilityKey; caf::PdmField m_timeStep; }; + +//================================================================================================== +/// +//================================================================================================== +class RimcGridView_setPolygonVisible : public caf::PdmVoidObjectMethod +{ + CAF_PDM_HEADER_INIT; + +public: + RimcGridView_setPolygonVisible( caf::PdmObjectHandle* self ); + + std::expected execute() override; + +private: + caf::PdmPtrField m_polygon; + caf::PdmField m_visible; +}; + +//================================================================================================== +/// +//================================================================================================== +class RimcGridView_setSurfaceVisible : public caf::PdmVoidObjectMethod +{ + CAF_PDM_HEADER_INIT; + +public: + RimcGridView_setSurfaceVisible( caf::PdmObjectHandle* self ); + + std::expected execute() override; + +private: + caf::PdmPtrField m_surface; + caf::PdmField m_visible; +}; + +//================================================================================================== +/// +//================================================================================================== +class RimcGridView_setSurfaceProperty : public caf::PdmVoidObjectMethod +{ + CAF_PDM_HEADER_INIT; + +public: + RimcGridView_setSurfaceProperty( caf::PdmObjectHandle* self ); + + std::expected execute() override; + +private: + caf::PdmPtrField m_surface; + caf::PdmField m_propertyName; +}; diff --git a/ApplicationLibCode/UnitTests/CMakeLists.txt b/ApplicationLibCode/UnitTests/CMakeLists.txt index 922bab36c9..89ee4e7764 100644 --- a/ApplicationLibCode/UnitTests/CMakeLists.txt +++ b/ApplicationLibCode/UnitTests/CMakeLists.txt @@ -141,6 +141,8 @@ set(SOURCE_UNITTEST_FILES ${CMAKE_CURRENT_LIST_DIR}/RigVfpTables-Test.cpp ${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 diff --git a/ApplicationLibCode/UnitTests/RimPolygonInViewCollection-Test.cpp b/ApplicationLibCode/UnitTests/RimPolygonInViewCollection-Test.cpp new file mode 100644 index 0000000000..df8fdbffff --- /dev/null +++ b/ApplicationLibCode/UnitTests/RimPolygonInViewCollection-Test.cpp @@ -0,0 +1,81 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// 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 +// for more details. +// +///////////////////////////////////////////////////////////////////////////////// + +#include "gtest/gtest.h" + +#include "Polygons/RimPolygon.h" +#include "Polygons/RimPolygonCollection.h" +#include "Polygons/RimPolygonInViewCollection.h" + +#include + +namespace +{ +bool isPolygonVisible( const RimPolygonInViewCollection& collection, const RimPolygon* polygon ) +{ + for ( auto* polygonInView : collection.visiblePolygonsInView() ) + { + if ( polygonInView->polygon() == polygon ) return polygonInView->showLines(); + } + + return false; +} +} // namespace + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +TEST( RimPolygonInViewCollection, PolygonVisibilityIsIndependentPerView ) +{ + auto sourceCollection = std::make_unique(); + + auto* rootPolygon = new RimPolygon(); + rootPolygon->setName( "Root polygon" ); + sourceCollection->addUserDefinedPolygon( rootPolygon ); + + auto* subCollection = new RimPolygonCollection(); + subCollection->setCollectionName( "Folder" ); + sourceCollection->addSubCollection( subCollection ); + + auto* nestedPolygon = new RimPolygon(); + nestedPolygon->setName( "Nested polygon" ); + subCollection->addUserDefinedPolygon( nestedPolygon ); + + RimPolygonInViewCollection firstViewCollection; + firstViewCollection.setSourceCollection( sourceCollection.get() ); + firstViewCollection.updateFromPolygonCollection(); + + RimPolygonInViewCollection secondViewCollection; + secondViewCollection.setSourceCollection( sourceCollection.get() ); + secondViewCollection.updateFromPolygonCollection(); + + EXPECT_TRUE( isPolygonVisible( firstViewCollection, rootPolygon ) ); + EXPECT_TRUE( isPolygonVisible( firstViewCollection, nestedPolygon ) ); + EXPECT_TRUE( isPolygonVisible( secondViewCollection, nestedPolygon ) ); + + EXPECT_TRUE( firstViewCollection.setPolygonVisible( nestedPolygon, false ) ); + EXPECT_TRUE( isPolygonVisible( firstViewCollection, rootPolygon ) ); + EXPECT_FALSE( isPolygonVisible( firstViewCollection, nestedPolygon ) ); + EXPECT_TRUE( isPolygonVisible( secondViewCollection, nestedPolygon ) ); + + EXPECT_TRUE( firstViewCollection.setPolygonVisible( nestedPolygon, true ) ); + EXPECT_TRUE( isPolygonVisible( firstViewCollection, nestedPolygon ) ); + + auto unrelatedPolygon = std::make_unique(); + EXPECT_FALSE( firstViewCollection.setPolygonVisible( unrelatedPolygon.get(), false ) ); + EXPECT_TRUE( isPolygonVisible( firstViewCollection, nestedPolygon ) ); +} diff --git a/ApplicationLibCode/UnitTests/RimSurfaceInViewCollection-Test.cpp b/ApplicationLibCode/UnitTests/RimSurfaceInViewCollection-Test.cpp new file mode 100644 index 0000000000..084a93a640 --- /dev/null +++ b/ApplicationLibCode/UnitTests/RimSurfaceInViewCollection-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 +// for more details. +// +///////////////////////////////////////////////////////////////////////////////// + +#include "gtest/gtest.h" + +#include "RimRegularSurface.h" +#include "RimSurfaceCollection.h" +#include "RimSurfaceInViewCollection.h" + +#include + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +TEST( RimSurfaceInViewCollection, SurfaceSettingsAreIndependentPerView ) +{ + auto sourceCollection = std::make_unique(); + + 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(); + EXPECT_FALSE( firstViewCollection.setSurfaceVisible( unrelatedSurface.get(), false ) ); + EXPECT_FALSE( firstViewCollection.setSurfaceProperty( unrelatedSurface.get(), "Property A" ).has_value() ); +} diff --git a/GrpcInterface/Python/rips/tests/test_polygon.py b/GrpcInterface/Python/rips/tests/test_polygon.py index 8d4ef7d70f..154f72b673 100644 --- a/GrpcInterface/Python/rips/tests/test_polygon.py +++ b/GrpcInterface/Python/rips/tests/test_polygon.py @@ -36,6 +36,33 @@ def test_create_polygon(rips_instance, initialize_test): assert math.isclose(e, a, rel_tol=1e-9, abs_tol=0.0) +def test_set_polygon_visible_in_view(rips_instance, initialize_test): + project = rips_instance.project.open( + dataroot.PATH + "/TEST10K_FLT_LGR_NNC/10KWithWellLog.rsp" + ) + + polygon_collection = project.descendants(rips.PolygonCollection)[0] + polygon = polygon_collection.create_polygon( + name="View polygon", + coordinates=[ + [0.0, 0.0, -1000.0], + [100.0, 0.0, -1000.0], + [100.0, 100.0, -1000.0], + ], + ) + + case = project.cases()[0] + first_view = case.views()[0] + second_view = case.create_view() + + assert first_view.set_polygon_visible(polygon=polygon, visible=False) is None + assert second_view.set_polygon_visible(polygon=polygon, visible=True) is None + assert first_view.set_polygon_visible(polygon=polygon, visible=True) is None + + with pytest.raises(rips.RipsError, match="Polygon is null"): + first_view.set_polygon_visible(polygon=None, visible=True) + + def test_add_folders_and_polygons(rips_instance, initialize_test): rips_instance.project.open( dataroot.PATH + "/TEST10K_FLT_LGR_NNC/10KWithWellLog.rsp" diff --git a/GrpcInterface/Python/rips/tests/test_surfaces.py b/GrpcInterface/Python/rips/tests/test_surfaces.py index acd6752cc4..858bae04ee 100644 --- a/GrpcInterface/Python/rips/tests/test_surfaces.py +++ b/GrpcInterface/Python/rips/tests/test_surfaces.py @@ -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)