From 711cb267fde53b97477056af6195073a2591f1b7 Mon Sep 17 00:00:00 2001 From: jonjenssen <69144954+jonjenssen@users.noreply.github.com> Date: Fri, 6 Dec 2024 14:26:30 +0100 Subject: [PATCH] Polygon UI updates (#11975) * Polygon UI updates --- .../CellFilters/RimCellFilterCollection.cpp | 9 ++++++- .../CellFilters/RimPolygonFilter.cpp | 25 +++++++++++++++++++ .../CellFilters/RimPolygonFilter.h | 10 ++++++-- .../ProjectDataModel/Polygons/RimPolygon.cpp | 11 ++++++-- .../ProjectDataModel/Polygons/RimPolygon.h | 2 ++ .../Polygons/RimPolygonAppearance.cpp | 8 ++++++ .../Polygons/RimPolygonAppearance.h | 2 ++ .../Polygons/RimPolygonFile.cpp | 21 +++++++++++++--- .../Polygons/RimPolygonInView.cpp | 17 +++++++++++++ .../Polygons/RimPolygonInView.h | 2 ++ .../Polygons/RimPolygonInViewCollection.cpp | 10 +++++++- .../ProjectDataModel/RimGridView.cpp | 1 + .../UserInterface/RiuMultiPlotPage.cpp | 21 ---------------- .../UserInterface/RiuMultiPlotPage.h | 5 +--- 14 files changed, 109 insertions(+), 35 deletions(-) diff --git a/ApplicationLibCode/ProjectDataModel/CellFilters/RimCellFilterCollection.cpp b/ApplicationLibCode/ProjectDataModel/CellFilters/RimCellFilterCollection.cpp index 276baac65b..693a0dd220 100644 --- a/ApplicationLibCode/ProjectDataModel/CellFilters/RimCellFilterCollection.cpp +++ b/ApplicationLibCode/ProjectDataModel/CellFilters/RimCellFilterCollection.cpp @@ -34,6 +34,7 @@ #include "Polygons/RimPolygon.h" #include "Polygons/RimPolygonCollection.h" +#include "Polygons/RimPolygonInView.h" #include "cafCmdFeatureMenuBuilder.h" #include "cafPdmFieldReorderCapability.h" @@ -619,7 +620,13 @@ std::vector RimCellFilterCollection::enabledCellFilterPolygon if ( auto polygonFilter = dynamic_cast( filter.p() ) ) { - polyInView.push_back( polygonFilter->polygonInView() ); + if ( !polygonFilter->isSelected() ) continue; + + auto piv = polygonFilter->polygonInView(); + if ( piv && piv->showLines() ) + { + polyInView.push_back( piv ); + } } } diff --git a/ApplicationLibCode/ProjectDataModel/CellFilters/RimPolygonFilter.cpp b/ApplicationLibCode/ProjectDataModel/CellFilters/RimPolygonFilter.cpp index 23e8e6e0a1..c3059e13d0 100644 --- a/ApplicationLibCode/ProjectDataModel/CellFilters/RimPolygonFilter.cpp +++ b/ApplicationLibCode/ProjectDataModel/CellFilters/RimPolygonFilter.cpp @@ -43,6 +43,7 @@ #include "WellPathCommands/RicPolylineTargetsPickEventHandler.h" #include "cafPdmUiPushButtonEditor.h" +#include "cafSelectionManager.h" #include @@ -92,6 +93,7 @@ RimPolygonFilter::RimPolygonFilter() : RimCellFilter( RimCellFilter::INDEX ) , m_pickTargetsEventHandler( new RicPolylineTargetsPickEventHandler( this ) ) , m_intervalTool( true ) + , m_isSelected( false ) { CAF_PDM_InitObject( "Polyline Filter", ":/CellFilter_Polygon.png" ); @@ -174,6 +176,14 @@ bool RimPolygonFilter::isFilterEnabled() const return m_isActive() && m_enableFiltering; } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool RimPolygonFilter::isSelected() const +{ + return m_isSelected; +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -1003,6 +1013,21 @@ void RimPolygonFilter::onObjectChanged( const caf::SignalEmitter* emitter ) updateIconState(); } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimPolygonFilter::onSelectionManagerSelectionChanged( const std::set& changedSelectionLevels ) +{ + bool selectedState = m_isSelected; + auto selectedFilter = dynamic_cast( caf::SelectionManager::instance()->selectedItem() ); + m_isSelected = ( selectedFilter == this ); + + if ( selectedState != m_isSelected ) + { + filterChanged.send(); + } +} + //-------------------------------------------------------------------------------------------------- /// Find which K layer we hit, in any of the grids, for any of the selected points //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationLibCode/ProjectDataModel/CellFilters/RimPolygonFilter.h b/ApplicationLibCode/ProjectDataModel/CellFilters/RimPolygonFilter.h index 52e82a064f..1cc997d09f 100644 --- a/ApplicationLibCode/ProjectDataModel/CellFilters/RimPolygonFilter.h +++ b/ApplicationLibCode/ProjectDataModel/CellFilters/RimPolygonFilter.h @@ -27,6 +27,7 @@ #include "cafPdmChildField.h" #include "cafPdmObject.h" #include "cafPdmPtrField.h" +#include "cafSelectionChangedReceiver.h" class RimPolygon; class RimPolylineTarget; @@ -40,7 +41,7 @@ class RicPolylineTargetsPickEventHandler; /// /// //================================================================================================== -class RimPolygonFilter : public RimCellFilter, public RimPolylinePickerInterface +class RimPolygonFilter : public RimCellFilter, public RimPolylinePickerInterface, public caf::SelectionChangedReceiver { CAF_PDM_HEADER_INIT; @@ -77,8 +78,10 @@ public: void setPolygon( RimPolygon* polygon ); bool isFilterEnabled() const override; + bool isSelected() const; void enablePicking( bool enable ); + bool pickingEnabled() const override; void updateCellIndexFilter( cvf::UByteArray* includeVisibility, cvf::UByteArray* excludeVisibility, int gridIndex ) override; void onGridChanged() override; @@ -96,6 +99,8 @@ protected: QString fullName() const override; + void onSelectionManagerSelectionChanged( const std::set& changedSelectionLevels ) override; + private: void updateCells(); void updateCellsForEclipse( const std::vector& points, RimEclipseCase* eCase ); @@ -124,7 +129,6 @@ private: void updateEditorsAndVisualization() override; void updateVisualization() override; std::vector activeTargets() const override; - bool pickingEnabled() const override; caf::PickEventHandler* pickEventHandler() const override; caf::AppEnum geometricalShape() const; @@ -144,6 +148,8 @@ private: RimCellFilterIntervalTool m_intervalTool; + bool m_isSelected; + // Local polygon and polygon editor caf::PdmPtrField m_cellFilterPolygon; caf::PdmChildField m_internalPolygon; diff --git a/ApplicationLibCode/ProjectDataModel/Polygons/RimPolygon.cpp b/ApplicationLibCode/ProjectDataModel/Polygons/RimPolygon.cpp index 5263751c51..725fab5676 100644 --- a/ApplicationLibCode/ProjectDataModel/Polygons/RimPolygon.cpp +++ b/ApplicationLibCode/ProjectDataModel/Polygons/RimPolygon.cpp @@ -159,6 +159,14 @@ void RimPolygon::setColor( const cvf::Color3f& color ) m_appearance->setLineColor( color ); } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool RimPolygon::showLines() const +{ + return m_appearance->showLines(); +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -186,7 +194,6 @@ void RimPolygon::fieldChangedByUi( const caf::PdmFieldHandle* changedField, cons if ( changedField == &m_pointsInDomainCoords ) { coordinatesChanged.send(); - objectChanged.send(); } if ( changedField == &m_editPolygonButton ) @@ -195,9 +202,9 @@ void RimPolygon::fieldChangedByUi( const caf::PdmFieldHandle* changedField, cons RimPolygonTools::activate3dEditOfPolygonInView( this, activeView ); m_editPolygonButton = false; - return; } + objectChanged.send(); } //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationLibCode/ProjectDataModel/Polygons/RimPolygon.h b/ApplicationLibCode/ProjectDataModel/Polygons/RimPolygon.h index 0d607c7424..53c5bcf173 100644 --- a/ApplicationLibCode/ProjectDataModel/Polygons/RimPolygon.h +++ b/ApplicationLibCode/ProjectDataModel/Polygons/RimPolygon.h @@ -58,6 +58,8 @@ public: cvf::Color3f color() const; void setColor( const cvf::Color3f& color ); + bool showLines() const; + cvf::ref polyLinesData() const override; void uiOrderingForLocalPolygon( QString uiConfigName, caf::PdmUiOrdering& uiOrdering ); diff --git a/ApplicationLibCode/ProjectDataModel/Polygons/RimPolygonAppearance.cpp b/ApplicationLibCode/ProjectDataModel/Polygons/RimPolygonAppearance.cpp index 7dbba7429b..67635944ee 100644 --- a/ApplicationLibCode/ProjectDataModel/Polygons/RimPolygonAppearance.cpp +++ b/ApplicationLibCode/ProjectDataModel/Polygons/RimPolygonAppearance.cpp @@ -124,6 +124,14 @@ bool RimPolygonAppearance::isClosed() const return m_isClosed(); } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool RimPolygonAppearance::showLines() const +{ + return m_showLines(); +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationLibCode/ProjectDataModel/Polygons/RimPolygonAppearance.h b/ApplicationLibCode/ProjectDataModel/Polygons/RimPolygonAppearance.h index 0f6fd767d0..da5b6dc753 100644 --- a/ApplicationLibCode/ProjectDataModel/Polygons/RimPolygonAppearance.h +++ b/ApplicationLibCode/ProjectDataModel/Polygons/RimPolygonAppearance.h @@ -40,6 +40,8 @@ public: cvf::Color3f lineColor() const; void setLineColor( const cvf::Color3f& color ); + bool showLines() const; + public: RimPolygonAppearance(); diff --git a/ApplicationLibCode/ProjectDataModel/Polygons/RimPolygonFile.cpp b/ApplicationLibCode/ProjectDataModel/Polygons/RimPolygonFile.cpp index 5ef49eb097..9f8eb17745 100644 --- a/ApplicationLibCode/ProjectDataModel/Polygons/RimPolygonFile.cpp +++ b/ApplicationLibCode/ProjectDataModel/Polygons/RimPolygonFile.cpp @@ -39,7 +39,10 @@ RimPolygonFile::RimPolygonFile() { CAF_PDM_InitObject( "PolygonFile", ":/Folder.png" ); - CAF_PDM_InitFieldNoDefault( &m_fileName, "StimPlanFileName", "File Name" ); + CAF_PDM_InitFieldNoDefault( &m_fileName, "FileName", "File Name" ); + m_fileName.registerKeywordAlias( "StimPlanFileName" ); + m_fileName.uiCapability()->setUiReadOnly( true ); + CAF_PDM_InitFieldNoDefault( &m_polygons, "Polygons", "Polygons" ); setDeletable( true ); @@ -62,12 +65,18 @@ void RimPolygonFile::loadData() { auto polygonsFromFile = importDataFromFile( m_fileName().path() ); + if ( polygonsFromFile.size() == 1 ) + { + polygonsFromFile[0]->setName( name() ); + } + if ( m_polygons.size() == polygonsFromFile.size() ) { for ( size_t i = 0; i < m_polygons.size(); i++ ) { auto projectPoly = m_polygons()[i]; - auto filePoly = polygonsFromFile[i]; + projectPoly->setDeletable( false ); + auto filePoly = polygonsFromFile[i]; projectPoly->setPointsInDomainCoords( filePoly->pointsInDomainCoords() ); projectPoly->coordinatesChanged.send(); // updates editors projectPoly->objectChanged.send(); // updates filters @@ -157,14 +166,18 @@ std::vector RimPolygonFile::importDataFromFile( const QString& file std::vector polygons; + QFileInfo fi( fileName ); + const QString basename = fi.baseName(); + for ( const auto& [polygonId, filePolygon] : filePolygons ) { auto polygon = new RimPolygon(); polygon->disableStorageOfPolygonPoints(); polygon->setReadOnly( true ); + polygon->setDeletable( false ); int id = ( polygonId != -1 ) ? polygonId : static_cast( polygons.size() + 1 ); - polygon->setName( QString( "Polygon %1" ).arg( id ) ); + polygon->setName( QString( "%1 (%2)" ).arg( basename ).arg( id ) ); polygon->setPointsInDomainCoords( filePolygon ); polygons.push_back( polygon ); } @@ -183,7 +196,7 @@ std::vector RimPolygonFile::importDataFromFile( const QString& file void RimPolygonFile::updateName() { QFileInfo fileInfo( m_fileName().path() ); - setName( fileInfo.fileName() ); + setName( fileInfo.baseName() ); } //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationLibCode/ProjectDataModel/Polygons/RimPolygonInView.cpp b/ApplicationLibCode/ProjectDataModel/Polygons/RimPolygonInView.cpp index e3f4776779..f7d1ad7d0e 100644 --- a/ApplicationLibCode/ProjectDataModel/Polygons/RimPolygonInView.cpp +++ b/ApplicationLibCode/ProjectDataModel/Polygons/RimPolygonInView.cpp @@ -165,6 +165,18 @@ void RimPolygonInView::updateVisualization() } } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool RimPolygonInView::showLines() const +{ + if ( auto poly = polygon() ) + { + return poly->showLines() && isChecked(); + } + return false; +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -389,6 +401,11 @@ void RimPolygonInView::appendMenuItems( caf::CmdFeatureMenuBuilder& menuBuilder //-------------------------------------------------------------------------------------------------- void RimPolygonInView::onObjectChanged( const caf::SignalEmitter* emitter ) { + // make sure name is in sync + if ( dynamic_cast( emitter ) ) + { + setName( m_polygon->name() ); + } updateVisualization(); } diff --git a/ApplicationLibCode/ProjectDataModel/Polygons/RimPolygonInView.h b/ApplicationLibCode/ProjectDataModel/Polygons/RimPolygonInView.h index dbe5d07a96..a637e2221d 100644 --- a/ApplicationLibCode/ProjectDataModel/Polygons/RimPolygonInView.h +++ b/ApplicationLibCode/ProjectDataModel/Polygons/RimPolygonInView.h @@ -67,6 +67,8 @@ public: cvf::ref polyLinesData() const override; + bool showLines() const; + void onChildrenUpdated( caf::PdmChildArrayFieldHandle* childArray, std::vector& updatedObjects ) override; void defineObjectEditorAttribute( QString uiConfigName, caf::PdmUiEditorAttribute* attribute ) override; diff --git a/ApplicationLibCode/ProjectDataModel/Polygons/RimPolygonInViewCollection.cpp b/ApplicationLibCode/ProjectDataModel/Polygons/RimPolygonInViewCollection.cpp index 15ba10d72c..531a27e63d 100644 --- a/ApplicationLibCode/ProjectDataModel/Polygons/RimPolygonInViewCollection.cpp +++ b/ApplicationLibCode/ProjectDataModel/Polygons/RimPolygonInViewCollection.cpp @@ -32,7 +32,7 @@ CAF_PDM_SOURCE_INIT( RimPolygonInViewCollection, "RimPolygonInViewCollection" ); //-------------------------------------------------------------------------------------------------- RimPolygonInViewCollection::RimPolygonInViewCollection() { - CAF_PDM_InitObject( "Polygons", ":/PolylinesFromFile16x16.png" ); + CAF_PDM_InitObject( "Polygons", ":/Folder.png" ); CAF_PDM_InitFieldNoDefault( &m_polygonsInView, "Polygons", "Polygons" ); CAF_PDM_InitFieldNoDefault( &m_collectionsInView, "Collections", "Collections" ); @@ -172,6 +172,7 @@ void RimPolygonInViewCollection::syncCollectionsWithView() for ( auto polygonFile : polygonCollection->polygonFiles() ) { if ( polygonFile->polygons().empty() ) continue; + if ( polygonFile->polygons().size() == 1 ) continue; auto viewPolygonFile = getCollectionInViewForPolygonFile( polygonFile ); if ( viewPolygonFile == nullptr ) @@ -217,6 +218,13 @@ void RimPolygonInViewCollection::syncPolygonsWithView() { auto polygonCollection = RimTools::polygonCollection(); polygons = polygonCollection->userDefinedPolygons(); + for ( auto polyfile : polygonCollection->polygonFiles() ) + { + if ( polyfile->polygons().size() == 1 ) + { + polygons.push_back( polyfile->polygons()[0] ); + } + } } std::vector newPolygonsInView; diff --git a/ApplicationLibCode/ProjectDataModel/RimGridView.cpp b/ApplicationLibCode/ProjectDataModel/RimGridView.cpp index 7c2081beda..17f809177e 100644 --- a/ApplicationLibCode/ProjectDataModel/RimGridView.cpp +++ b/ApplicationLibCode/ProjectDataModel/RimGridView.cpp @@ -101,6 +101,7 @@ RimGridView::RimGridView() CAF_PDM_InitFieldNoDefault( &m_polygonInViewCollection, "PolygonInViewCollection", "Polygon Collection Field" ); m_polygonInViewCollection = new RimPolygonInViewCollection(); + m_polygonInViewCollection->uiCapability()->setUiIcon( caf::IconProvider( ":/PolylinesFromFile16x16.png" ) ); CAF_PDM_InitFieldNoDefault( &m_cellFilterCollection, "RangeFilters", "Cell Filter Collection Field" ); m_cellFilterCollection = new RimCellFilterCollection(); diff --git a/ApplicationLibCode/UserInterface/RiuMultiPlotPage.cpp b/ApplicationLibCode/UserInterface/RiuMultiPlotPage.cpp index 4668d2590e..9bbf0269a7 100644 --- a/ApplicationLibCode/UserInterface/RiuMultiPlotPage.cpp +++ b/ApplicationLibCode/UserInterface/RiuMultiPlotPage.cpp @@ -558,27 +558,6 @@ std::pair RiuMultiPlotPage::rowAndColumnCount( int plotWidgetCount ) c return std::make_pair( rowCount, columnCount ); } -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -void RiuMultiPlotPage::onSelectionManagerSelectionChanged( const std::set& changedSelectionLevels ) -{ - if ( !m_plotDefinition ) return; - - for ( RiuPlotWidget* plotWidget : m_plotWidgets ) - { - if ( !plotWidget ) continue; - RimPlot* plot = plotWidget->plotDefinition(); - if ( !plot ) continue; - - bool isSelected = false; - for ( int changedLevel : changedSelectionLevels ) - { - isSelected = isSelected || caf::SelectionManager::instance()->isSelected( plot, changedLevel ); - } - } -} - //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationLibCode/UserInterface/RiuMultiPlotPage.h b/ApplicationLibCode/UserInterface/RiuMultiPlotPage.h index acc231dce2..3b2a1053d4 100644 --- a/ApplicationLibCode/UserInterface/RiuMultiPlotPage.h +++ b/ApplicationLibCode/UserInterface/RiuMultiPlotPage.h @@ -23,7 +23,6 @@ #include "RiaDefines.h" #include "cafPdmPointer.h" -#include "cafSelectionChangedReceiver.h" #include "qwt_axis_id.h" @@ -55,7 +54,7 @@ class QwtPlot; // RiuMultiPlotPage // //================================================================================================== -class RiuMultiPlotPage : public QWidget, public caf::SelectionChangedReceiver, public RiuInterfaceToViewWindow +class RiuMultiPlotPage : public QWidget, public RiuInterfaceToViewWindow { Q_OBJECT @@ -117,8 +116,6 @@ protected: void alignAxes(); void alignAxis( QwtAxisId axis, int row, std::function positionMatcher ); - void onSelectionManagerSelectionChanged( const std::set& changedSelectionLevels ) override; - virtual bool showYAxis( int row, int column ) const; virtual void reinsertPlotWidgets();