From e20f91b3d53deabd31ab32b6186671350a0efc48 Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Wed, 21 Feb 2024 13:14:37 +0100 Subject: [PATCH] Make well targets obsolete --- .../CellFilters/RimPolygonFilter.cpp | 21 +++++- .../CellFilters/RimPolygonFilter.h | 4 ++ .../Polygons/CMakeLists_files.cmake | 2 + .../Polygons/RimPolygonTools.cpp | 64 +++++++++++++++++++ .../Polygons/RimPolygonTools.h | 36 +++++++++++ 5 files changed, 126 insertions(+), 1 deletion(-) create mode 100644 ApplicationLibCode/ProjectDataModel/Polygons/RimPolygonTools.cpp create mode 100644 ApplicationLibCode/ProjectDataModel/Polygons/RimPolygonTools.h diff --git a/ApplicationLibCode/ProjectDataModel/CellFilters/RimPolygonFilter.cpp b/ApplicationLibCode/ProjectDataModel/CellFilters/RimPolygonFilter.cpp index c24f1e62ec..8473461797 100644 --- a/ApplicationLibCode/ProjectDataModel/CellFilters/RimPolygonFilter.cpp +++ b/ApplicationLibCode/ProjectDataModel/CellFilters/RimPolygonFilter.cpp @@ -34,6 +34,7 @@ #include "Polygons/RimPolygon.h" #include "Polygons/RimPolygonCollection.h" #include "Polygons/RimPolygonInView.h" +#include "Polygons/RimPolygonTools.h" #include "Riu3DMainWindowTools.h" @@ -123,6 +124,12 @@ RimPolygonFilter::RimPolygonFilter() m_editPolygonButton.uiCapability()->setUiEditorTypeName( caf::PdmUiPushButtonEditor::uiEditorTypeName() ); m_editPolygonButton.uiCapability()->setUiLabelPosition( caf::PdmUiItemInfo::HIDDEN ); + CAF_PDM_InitFieldNoDefault( &m_OBSOLETE_targets, "Targets", "Targets" ); + m_OBSOLETE_targets.uiCapability()->setUiTreeChildrenHidden( true ); + m_OBSOLETE_targets.uiCapability()->setUiTreeHidden( true ); + m_OBSOLETE_targets.uiCapability()->setUiHidden( true ); + m_OBSOLETE_targets.xmlCapability()->setIOWritable( false ); + m_propagateToSubGrids = false; updateIconState(); @@ -179,6 +186,18 @@ void RimPolygonFilter::initAfterRead() { RimCellFilter::initAfterRead(); + // Move existing polygons to global polygon + if ( !m_OBSOLETE_targets.empty() ) + { + std::vector points; + for ( const auto& target : m_OBSOLETE_targets ) + { + points.push_back( target->targetPointXYZ() ); + } + + m_internalPolygon->setPointsInDomainCoords( points ); + } + configurePolygonEditor(); } @@ -297,7 +316,7 @@ void RimPolygonFilter::fieldChangedByUi( const caf::PdmFieldHandle* changedField { if ( changedField == &m_editPolygonButton ) { - if ( m_cellFilterPolygon() ) Riu3DMainWindowTools::selectAsCurrentItem( m_cellFilterPolygon() ); + RimPolygonTools::selectPolygonInView( m_cellFilterPolygon(), this ); m_editPolygonButton = false; diff --git a/ApplicationLibCode/ProjectDataModel/CellFilters/RimPolygonFilter.h b/ApplicationLibCode/ProjectDataModel/CellFilters/RimPolygonFilter.h index 72d71a5978..ec9acefa91 100644 --- a/ApplicationLibCode/ProjectDataModel/CellFilters/RimPolygonFilter.h +++ b/ApplicationLibCode/ProjectDataModel/CellFilters/RimPolygonFilter.h @@ -23,11 +23,13 @@ #include "RimPolylinePickerInterface.h" #include "cafAppEnum.h" +#include "cafPdmChildArrayField.h" #include "cafPdmChildField.h" #include "cafPdmObject.h" #include "cafPdmPtrField.h" class RimPolygon; +class RimPolylineTarget; class RigGridBase; class RigFemPartGrid; class RimPolygonInView; @@ -148,4 +150,6 @@ class RimPolygonFilter : public RimCellFilter, public RimPolylinePickerInterface caf::PdmField m_editPolygonButton; std::shared_ptr m_pickTargetsEventHandler; + + caf::PdmChildArrayField m_OBSOLETE_targets; }; diff --git a/ApplicationLibCode/ProjectDataModel/Polygons/CMakeLists_files.cmake b/ApplicationLibCode/ProjectDataModel/Polygons/CMakeLists_files.cmake index af99df45c7..ace8580f7d 100644 --- a/ApplicationLibCode/ProjectDataModel/Polygons/CMakeLists_files.cmake +++ b/ApplicationLibCode/ProjectDataModel/Polygons/CMakeLists_files.cmake @@ -5,6 +5,7 @@ set(SOURCE_GROUP_HEADER_FILES ${CMAKE_CURRENT_LIST_DIR}/RimPolygonInView.h ${CMAKE_CURRENT_LIST_DIR}/RimPolygonInViewCollection.h ${CMAKE_CURRENT_LIST_DIR}/RimPolygonAppearance.h + ${CMAKE_CURRENT_LIST_DIR}/RimPolygonTools.h ) set(SOURCE_GROUP_SOURCE_FILES @@ -14,6 +15,7 @@ set(SOURCE_GROUP_SOURCE_FILES ${CMAKE_CURRENT_LIST_DIR}/RimPolygonInView.cpp ${CMAKE_CURRENT_LIST_DIR}/RimPolygonInViewCollection.cpp ${CMAKE_CURRENT_LIST_DIR}/RimPolygonAppearance.cpp + ${CMAKE_CURRENT_LIST_DIR}/RimPolygonTools.cpp ) list(APPEND CODE_HEADER_FILES ${SOURCE_GROUP_HEADER_FILES}) diff --git a/ApplicationLibCode/ProjectDataModel/Polygons/RimPolygonTools.cpp b/ApplicationLibCode/ProjectDataModel/Polygons/RimPolygonTools.cpp new file mode 100644 index 0000000000..544f343edd --- /dev/null +++ b/ApplicationLibCode/ProjectDataModel/Polygons/RimPolygonTools.cpp @@ -0,0 +1,64 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2024 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 "RimPolygonTools.h" + +#include "RimGridView.h" +#include "RimOilField.h" +#include "RimPolygon.h" +#include "RimPolygonCollection.h" +#include "RimPolygonInView.h" +#include "RimPolygonInViewCollection.h" +#include "RimProject.h" + +#include "Riu3DMainWindowTools.h" + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimPolygonTools::selectPolygonInView( RimPolygon* polygon, caf::PdmObject* sourceObject ) +{ + auto polygonInView = findPolygonInView( polygon, sourceObject ); + if ( polygonInView ) + { + polygonInView->enablePicking( true ); + Riu3DMainWindowTools::selectAsCurrentItem( polygonInView ); + } +} + + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RimPolygonInView* RimPolygonTools::findPolygonInView( RimPolygon* polygon, caf::PdmObject* sourceObject ) +{ + if ( auto gridView = sourceObject->firstAncestorOfType() ) + { + auto polyCollection = gridView->polygonInViewCollection(); + + for ( auto polygonInView : polyCollection->polygonsInView() ) + { + if ( polygonInView && polygonInView->polygon() == polygon ) + { + return polygonInView; + } + } + } + + return nullptr; +} diff --git a/ApplicationLibCode/ProjectDataModel/Polygons/RimPolygonTools.h b/ApplicationLibCode/ProjectDataModel/Polygons/RimPolygonTools.h new file mode 100644 index 0000000000..e45826e4e8 --- /dev/null +++ b/ApplicationLibCode/ProjectDataModel/Polygons/RimPolygonTools.h @@ -0,0 +1,36 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2024 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. +// +///////////////////////////////////////////////////////////////////////////////// + +#pragma once + +class RimPolygon; +class RimPolygonInView; + +namespace caf +{ +class PdmObject; +} + +class RimPolygonTools +{ +public: + static void selectPolygonInView( RimPolygon* polygon, caf::PdmObject* sourceObject ); + +private: + static RimPolygonInView* findPolygonInView( RimPolygon* polygon, caf::PdmObject* sourceObject ); +};