From e0e05bcc6de89e4be0bee56c5d43778819cfe2e5 Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Mon, 28 Sep 2026 15:53:32 +0200 Subject: [PATCH] #14797 Polygons: Add sphere display options and view update helpers Add setters for line and sphere appearance on RimPolygon. Add RimPolygonCollection::updateViewsAfterPolygonsChanged(), shared with the contour map polygon tools, and a deferred variant that is safe to call from destructors. --- .../RicCreateContourMapPolygonTools.cpp | 19 +------ .../ProjectDataModel/Polygons/RimPolygon.cpp | 40 ++++++++++++++ .../ProjectDataModel/Polygons/RimPolygon.h | 6 +++ .../Polygons/RimPolygonAppearance.cpp | 40 ++++++++++++++ .../Polygons/RimPolygonAppearance.h | 6 +++ .../Polygons/RimPolygonCollection.cpp | 53 +++++++++++++++++++ .../Polygons/RimPolygonCollection.h | 8 +++ 7 files changed, 154 insertions(+), 18 deletions(-) diff --git a/ApplicationLibCode/Commands/RicCreateContourMapPolygonTools.cpp b/ApplicationLibCode/Commands/RicCreateContourMapPolygonTools.cpp index 77b4b92ed2..2e0e35e8f5 100644 --- a/ApplicationLibCode/Commands/RicCreateContourMapPolygonTools.cpp +++ b/ApplicationLibCode/Commands/RicCreateContourMapPolygonTools.cpp @@ -125,24 +125,7 @@ void createPolygonObjects( const std::vector>& polygons newPolygon->coordinatesChanged.send(); } - polygonCollection->updateAllRequiredEditors(); - - // Update polygon collections in all views so new polygons become visible - if ( auto project = RimProject::current() ) - { - for ( auto* view : project->allViews() ) - { - if ( auto* gridView = dynamic_cast( view ) ) - { - if ( auto* polyCollection = gridView->polygonInViewCollection() ) - { - polyCollection->updateFromPolygonCollection(); - polyCollection->updateConnectedEditors(); - } - gridView->scheduleCreateDisplayModelAndRedraw(); - } - } - } + polygonCollection->updateViewsAfterPolygonsChanged(); } } // namespace internal diff --git a/ApplicationLibCode/ProjectDataModel/Polygons/RimPolygon.cpp b/ApplicationLibCode/ProjectDataModel/Polygons/RimPolygon.cpp index 99700b602d..c64e8401cc 100644 --- a/ApplicationLibCode/ProjectDataModel/Polygons/RimPolygon.cpp +++ b/ApplicationLibCode/ProjectDataModel/Polygons/RimPolygon.cpp @@ -191,6 +191,46 @@ bool RimPolygon::showLines() const return m_appearance->showLines(); } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimPolygon::setShowLines( bool showLines ) +{ + m_appearance->setShowLines( showLines ); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool RimPolygon::showSpheres() const +{ + return m_appearance->showSpheres(); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimPolygon::setShowSpheres( bool showSpheres ) +{ + m_appearance->setShowSpheres( showSpheres ); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimPolygon::setSphereRadiusFactor( double radiusFactor ) +{ + m_appearance->setSphereRadiusFactor( radiusFactor ); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimPolygon::setSphereColor( const cvf::Color3f& color ) +{ + m_appearance->setSphereColor( color ); +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationLibCode/ProjectDataModel/Polygons/RimPolygon.h b/ApplicationLibCode/ProjectDataModel/Polygons/RimPolygon.h index 49781937be..6a03b53190 100644 --- a/ApplicationLibCode/ProjectDataModel/Polygons/RimPolygon.h +++ b/ApplicationLibCode/ProjectDataModel/Polygons/RimPolygon.h @@ -60,6 +60,12 @@ public: void setColor( const cvf::Color3f& color ); bool showLines() const; + void setShowLines( bool showLines ); + + bool showSpheres() const; + void setShowSpheres( bool showSpheres ); + void setSphereRadiusFactor( double radiusFactor ); + void setSphereColor( const cvf::Color3f& color ); cvf::ref polyLinesData() const override; diff --git a/ApplicationLibCode/ProjectDataModel/Polygons/RimPolygonAppearance.cpp b/ApplicationLibCode/ProjectDataModel/Polygons/RimPolygonAppearance.cpp index cdb1994306..ab5bd33b5b 100644 --- a/ApplicationLibCode/ProjectDataModel/Polygons/RimPolygonAppearance.cpp +++ b/ApplicationLibCode/ProjectDataModel/Polygons/RimPolygonAppearance.cpp @@ -151,6 +151,46 @@ void RimPolygonAppearance::setLineColor( const cvf::Color3f& color ) m_lineColor = color; } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimPolygonAppearance::setShowLines( bool showLines ) +{ + m_showLines = showLines; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool RimPolygonAppearance::showSpheres() const +{ + return m_showSpheres(); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimPolygonAppearance::setShowSpheres( bool showSpheres ) +{ + m_showSpheres = showSpheres; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimPolygonAppearance::setSphereRadiusFactor( double radiusFactor ) +{ + m_sphereRadiusFactor = radiusFactor; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimPolygonAppearance::setSphereColor( const cvf::Color3f& color ) +{ + m_sphereColor = color; +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationLibCode/ProjectDataModel/Polygons/RimPolygonAppearance.h b/ApplicationLibCode/ProjectDataModel/Polygons/RimPolygonAppearance.h index 66db315145..a22120db57 100644 --- a/ApplicationLibCode/ProjectDataModel/Polygons/RimPolygonAppearance.h +++ b/ApplicationLibCode/ProjectDataModel/Polygons/RimPolygonAppearance.h @@ -40,6 +40,12 @@ public: void setLineColor( const cvf::Color3f& color ); bool showLines() const; + void setShowLines( bool showLines ); + + bool showSpheres() const; + void setShowSpheres( bool showSpheres ); + void setSphereRadiusFactor( double radiusFactor ); + void setSphereColor( const cvf::Color3f& color ); public: RimPolygonAppearance(); diff --git a/ApplicationLibCode/ProjectDataModel/Polygons/RimPolygonCollection.cpp b/ApplicationLibCode/ProjectDataModel/Polygons/RimPolygonCollection.cpp index e9d05813e3..a4b6c591ae 100644 --- a/ApplicationLibCode/ProjectDataModel/Polygons/RimPolygonCollection.cpp +++ b/ApplicationLibCode/ProjectDataModel/Polygons/RimPolygonCollection.cpp @@ -22,8 +22,11 @@ #include "RiaNameUniquenessTools.h" #include "Rim3dView.h" +#include "RimGridView.h" +#include "RimOilField.h" #include "RimPolygon.h" #include "RimPolygonFile.h" +#include "RimPolygonInViewCollection.h" #include "RimProject.h" #include "cafPdmFieldScriptingCapability.h" @@ -31,6 +34,8 @@ #include "cafCmdFeatureMenuBuilder.h" +#include + CAF_PDM_SOURCE_INIT( RimPolygonCollection, "PolygonCollection", "RimPolygonCollection" ); //-------------------------------------------------------------------------------------------------- @@ -158,6 +163,54 @@ void RimPolygonCollection::appendPolygonMenuItems( caf::CmdFeatureMenuBuilder& m menuBuilder << "RicImportPolygonFileFeature"; } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimPolygonCollection::updateViewsAfterPolygonsChanged() +{ + updateAllRequiredEditors(); + + if ( auto* project = RimProject::current() ) + { + for ( auto* view : project->allViews() ) + { + if ( auto* gridView = dynamic_cast( view ) ) + { + if ( auto* polyCollection = gridView->polygonInViewCollection() ) + { + polyCollection->updateFromPolygonCollection(); + polyCollection->updateConnectedEditors(); + } + gridView->scheduleCreateDisplayModelAndRedraw(); + } + } + } +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimPolygonCollection::scheduleUpdateViewsAfterPolygonsChanged() +{ + static bool isUpdateScheduled = false; + if ( isUpdateScheduled ) return; + + isUpdateScheduled = true; + QTimer::singleShot( 0, + []() + { + isUpdateScheduled = false; + + auto* project = RimProject::current(); + if ( !project ) return; + + auto* oilField = project->activeOilField(); + if ( !oilField || !oilField->polygonCollection() ) return; + + oilField->polygonCollection()->updateViewsAfterPolygonsChanged(); + } ); +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationLibCode/ProjectDataModel/Polygons/RimPolygonCollection.h b/ApplicationLibCode/ProjectDataModel/Polygons/RimPolygonCollection.h index cc07044680..5801c4f093 100644 --- a/ApplicationLibCode/ProjectDataModel/Polygons/RimPolygonCollection.h +++ b/ApplicationLibCode/ProjectDataModel/Polygons/RimPolygonCollection.h @@ -55,6 +55,14 @@ public: static void appendPolygonMenuItems( caf::CmdFeatureMenuBuilder& menuBuilder ); + // Update editors and the polygon-in-view collections of all grid views, so that added or removed + // polygons become visible. Call once after a batch of changes. + void updateViewsAfterPolygonsChanged(); + + // Schedule updateViewsAfterPolygonsChanged() on the active polygon collection from the event loop. + // Safe to call from destructors, also during project teardown. Multiple requests are merged. + static void scheduleUpdateViewsAfterPolygonsChanged(); + private: void onChildDeleted( caf::PdmChildArrayFieldHandle* childArray, std::vector& referringObjects ) override; void childFieldChangedByUi( const caf::PdmFieldHandle* changedChildField ) override;