diff --git a/ApplicationLibCode/Commands/CellFilterCommands/RicNewPolygonFilter3dviewFeature.cpp b/ApplicationLibCode/Commands/CellFilterCommands/RicNewPolygonFilter3dviewFeature.cpp index 52db3a8110..1c1c6b1082 100644 --- a/ApplicationLibCode/Commands/CellFilterCommands/RicNewPolygonFilter3dviewFeature.cpp +++ b/ApplicationLibCode/Commands/CellFilterCommands/RicNewPolygonFilter3dviewFeature.cpp @@ -18,6 +18,8 @@ #include "RicNewPolygonFilter3dviewFeature.h" +#include "Polygons/RimPolygonInView.h" + #include "RiaApplication.h" #include "RimCase.h" #include "RimCellFilterCollection.h" @@ -49,7 +51,7 @@ void RicNewPolygonFilter3dviewFeature::onActionTriggered( bool isChecked ) RimPolygonFilter* lastCreatedOrUpdated = filtColl->addNewPolygonFilter( sourceCase ); if ( lastCreatedOrUpdated ) { - Riu3DMainWindowTools::selectAsCurrentItem( lastCreatedOrUpdated ); + Riu3DMainWindowTools::selectAsCurrentItem( lastCreatedOrUpdated->polygonEditor() ); } } diff --git a/ApplicationLibCode/Commands/CellFilterCommands/RicNewPolygonFilterFeature.cpp b/ApplicationLibCode/Commands/CellFilterCommands/RicNewPolygonFilterFeature.cpp index 4e8ba926b2..3c40d0dfc8 100644 --- a/ApplicationLibCode/Commands/CellFilterCommands/RicNewPolygonFilterFeature.cpp +++ b/ApplicationLibCode/Commands/CellFilterCommands/RicNewPolygonFilterFeature.cpp @@ -18,9 +18,12 @@ #include "RicNewPolygonFilterFeature.h" +#include "Polygons/RimPolygonInView.h" + #include "RimCase.h" #include "RimCellFilterCollection.h" #include "RimPolygonFilter.h" + #include "Riu3DMainWindowTools.h" #include "cafSelectionManagerTools.h" @@ -46,7 +49,7 @@ void RicNewPolygonFilterFeature::onActionTriggered( bool isChecked ) RimPolygonFilter* lastCreatedOrUpdated = filtColl->addNewPolygonFilter( sourceCase ); if ( lastCreatedOrUpdated ) { - Riu3DMainWindowTools::selectAsCurrentItem( lastCreatedOrUpdated ); + Riu3DMainWindowTools::selectAsCurrentItem( lastCreatedOrUpdated->polygonEditor() ); } } diff --git a/ApplicationLibCode/Commands/PolygonCommands/RicAppendPolygonFeature.cpp b/ApplicationLibCode/Commands/PolygonCommands/RicAppendPolygonFeature.cpp index 5c4bc3dfbc..ea47744fad 100644 --- a/ApplicationLibCode/Commands/PolygonCommands/RicAppendPolygonFeature.cpp +++ b/ApplicationLibCode/Commands/PolygonCommands/RicAppendPolygonFeature.cpp @@ -1,6 +1,6 @@ //////////////////////////////////////////////////////////////////////////////// // -// Copyright (C) 2022 Equinor ASA +// 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 diff --git a/ApplicationLibCode/Commands/PolygonCommands/RicAppendPolygonFeature.h b/ApplicationLibCode/Commands/PolygonCommands/RicAppendPolygonFeature.h index 6773df5e44..2910766326 100644 --- a/ApplicationLibCode/Commands/PolygonCommands/RicAppendPolygonFeature.h +++ b/ApplicationLibCode/Commands/PolygonCommands/RicAppendPolygonFeature.h @@ -1,6 +1,6 @@ //////////////////////////////////////////////////////////////////////////////// // -// Copyright (C) 2022 Equinor ASA +// 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 diff --git a/ApplicationLibCode/Commands/PolygonCommands/RicAppendPolygonFileFeature.cpp b/ApplicationLibCode/Commands/PolygonCommands/RicAppendPolygonFileFeature.cpp index f459516c08..1d92d5cc4a 100644 --- a/ApplicationLibCode/Commands/PolygonCommands/RicAppendPolygonFileFeature.cpp +++ b/ApplicationLibCode/Commands/PolygonCommands/RicAppendPolygonFileFeature.cpp @@ -1,6 +1,6 @@ //////////////////////////////////////////////////////////////////////////////// // -// Copyright (C) 2022 Equinor ASA +// 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 diff --git a/ApplicationLibCode/Commands/PolygonCommands/RicAppendPolygonFileFeature.h b/ApplicationLibCode/Commands/PolygonCommands/RicAppendPolygonFileFeature.h index 2a5333cb76..af13e5745c 100644 --- a/ApplicationLibCode/Commands/PolygonCommands/RicAppendPolygonFileFeature.h +++ b/ApplicationLibCode/Commands/PolygonCommands/RicAppendPolygonFileFeature.h @@ -1,6 +1,6 @@ //////////////////////////////////////////////////////////////////////////////// // -// Copyright (C) 2022 Equinor ASA +// 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 diff --git a/ApplicationLibCode/Commands/WellPathCommands/CMakeLists_files.cmake b/ApplicationLibCode/Commands/WellPathCommands/CMakeLists_files.cmake index 57cb2f675e..e8720d49b1 100644 --- a/ApplicationLibCode/Commands/WellPathCommands/CMakeLists_files.cmake +++ b/ApplicationLibCode/Commands/WellPathCommands/CMakeLists_files.cmake @@ -30,7 +30,6 @@ set(SOURCE_GROUP_HEADER_FILES ${CMAKE_CURRENT_LIST_DIR}/PointTangentManipulator/RicPointTangentManipulatorPartMgr.h ${CMAKE_CURRENT_LIST_DIR}/PointTangentManipulator/RicPolyline3dEditor.h ${CMAKE_CURRENT_LIST_DIR}/PointTangentManipulator/RicPolylineTarget3dEditor.h - ${CMAKE_CURRENT_LIST_DIR}/RicAppendPointsToPolygonFilterFeature.h ${CMAKE_CURRENT_LIST_DIR}/RicDuplicateWellPathFeature.h ) @@ -66,7 +65,6 @@ set(SOURCE_GROUP_SOURCE_FILES ${CMAKE_CURRENT_LIST_DIR}/PointTangentManipulator/RicPointTangentManipulatorPartMgr.cpp ${CMAKE_CURRENT_LIST_DIR}/PointTangentManipulator/RicPolyline3dEditor.cpp ${CMAKE_CURRENT_LIST_DIR}/PointTangentManipulator/RicPolylineTarget3dEditor.cpp - ${CMAKE_CURRENT_LIST_DIR}/RicAppendPointsToPolygonFilterFeature.cpp ${CMAKE_CURRENT_LIST_DIR}/RicDuplicateWellPathFeature.cpp ) diff --git a/ApplicationLibCode/Commands/WellPathCommands/RicAppendPointsToPolygonFilterFeature.cpp b/ApplicationLibCode/Commands/WellPathCommands/RicAppendPointsToPolygonFilterFeature.cpp deleted file mode 100644 index 05908fcacd..0000000000 --- a/ApplicationLibCode/Commands/WellPathCommands/RicAppendPointsToPolygonFilterFeature.cpp +++ /dev/null @@ -1,83 +0,0 @@ -///////////////////////////////////////////////////////////////////////////////// -// -// Copyright (C) 2021- 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 "RicAppendPointsToPolygonFilterFeature.h" - -#include "RiaTextStringTools.h" - -#include "RimPolygonFilter.h" -#include "RimPolylineTarget.h" - -#include "OperationsUsingObjReferences/RicPasteFeatureImpl.h" - -#include "cafSelectionManager.h" -#include "cafSelectionManagerTools.h" - -#include -#include - -CAF_CMD_SOURCE_INIT( RicAppendPointsToPolygonFilterFeature, "RicAppendPointsToPolygonFilterFeature" ); - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -bool RicAppendPointsToPolygonFilterFeature::isCommandEnabled() const -{ - auto obj = caf::firstAncestorOfTypeFromSelectedObject(); - return obj != nullptr; -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -void RicAppendPointsToPolygonFilterFeature::onActionTriggered( bool isChecked ) -{ - auto polygonFilter = caf::firstAncestorOfTypeFromSelectedObject(); - if ( !polygonFilter ) return; - - QStringList listOfThreeDoubles; - - QClipboard* clipboard = QApplication::clipboard(); - if ( clipboard ) - { - QString content = clipboard->text(); - listOfThreeDoubles = RiaTextStringTools::splitSkipEmptyParts( content, "\n" ); - } - - std::vector points; - caf::PdmValueFieldSpecialization>::setFromVariant( listOfThreeDoubles, points ); - - for ( const auto& p : points ) - { - auto newTarget = new RimPolylineTarget; - newTarget->setAsPointTargetXYD( p ); - polygonFilter->insertTarget( nullptr, newTarget ); - } - - polygonFilter->updateEditorsAndVisualization(); -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -void RicAppendPointsToPolygonFilterFeature::setupActionLook( QAction* actionToSetup ) -{ - actionToSetup->setText( "Append Points from Clipboard" ); - - RicPasteFeatureImpl::setIconAndShortcuts( actionToSetup ); -} diff --git a/ApplicationLibCode/Commands/WellPathCommands/RicAppendPointsToPolygonFilterFeature.h b/ApplicationLibCode/Commands/WellPathCommands/RicAppendPointsToPolygonFilterFeature.h deleted file mode 100644 index 35cee0a6c5..0000000000 --- a/ApplicationLibCode/Commands/WellPathCommands/RicAppendPointsToPolygonFilterFeature.h +++ /dev/null @@ -1,34 +0,0 @@ -///////////////////////////////////////////////////////////////////////////////// -// -// Copyright (C) 2021- 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 - -#include "cafCmdFeature.h" - -//================================================================================================== -/// -//================================================================================================== -class RicAppendPointsToPolygonFilterFeature : public caf::CmdFeature -{ - CAF_CMD_HEADER_INIT; - -protected: - bool isCommandEnabled() const override; - void onActionTriggered( bool isChecked ) override; - void setupActionLook( QAction* actionToSetup ) override; -}; diff --git a/ApplicationLibCode/ModelVisualization/RivCellFilterPartMgr.cpp b/ApplicationLibCode/ModelVisualization/RivCellFilterPartMgr.cpp index e8d82cd12f..3e16517cd8 100644 --- a/ApplicationLibCode/ModelVisualization/RivCellFilterPartMgr.cpp +++ b/ApplicationLibCode/ModelVisualization/RivCellFilterPartMgr.cpp @@ -22,8 +22,6 @@ #include "RimCellFilterCollection.h" #include "RimPolygonFilter.h" -#include "RivPolylinePartMgr.h" - #include "cafPdmObject.h" //-------------------------------------------------------------------------------------------------- @@ -34,55 +32,23 @@ RivCellFilterPartMgr::RivCellFilterPartMgr( Rim3dView* view ) { } -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -RivCellFilterPartMgr::~RivCellFilterPartMgr() -{ -} - //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- void RivCellFilterPartMgr::appendGeometryPartsToModel( cvf::ModelBasicList* model, const caf::DisplayCoordTransform* displayCoordTransform, const cvf::BoundingBox& boundingBox ) -{ - createCellFilterPartManagers(); - - for ( auto& partMgr : m_cellFilterPartMgrs ) - { - partMgr->appendDynamicGeometryPartsToModel( model, displayCoordTransform, boundingBox ); - } -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -void RivCellFilterPartMgr::createCellFilterPartManagers() { std::vector colls = m_rimView->descendantsIncludingThisOfType(); if ( colls.empty() ) return; auto coll = colls.front(); - clearGeometryCache(); - for ( auto filter : coll->filters() ) { - RimPolygonFilter* polyFilter = dynamic_cast( filter ); - if ( polyFilter ) + if ( auto polyFilter = dynamic_cast( filter ) ) { - RivPolylinePartMgr* ppm = new RivPolylinePartMgr( m_rimView, polyFilter, coll ); - m_cellFilterPartMgrs.push_back( ppm ); + polyFilter->appendPartsToModel( model, displayCoordTransform, boundingBox ); } } } - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -void RivCellFilterPartMgr::clearGeometryCache() -{ - m_cellFilterPartMgrs.clear(); -} diff --git a/ApplicationLibCode/ModelVisualization/RivCellFilterPartMgr.h b/ApplicationLibCode/ModelVisualization/RivCellFilterPartMgr.h index a58d0d1916..38d4608915 100644 --- a/ApplicationLibCode/ModelVisualization/RivCellFilterPartMgr.h +++ b/ApplicationLibCode/ModelVisualization/RivCellFilterPartMgr.h @@ -19,8 +19,6 @@ #pragma once #include "cafPdmPointer.h" -#include "cvfAssert.h" -#include "cvfCollection.h" #include "cvfObject.h" namespace cvf @@ -37,24 +35,16 @@ class DisplayCoordTransform; } class Rim3dView; -class RivPolylinePartMgr; class RivCellFilterPartMgr : public cvf::Object { public: RivCellFilterPartMgr( Rim3dView* view ); - ~RivCellFilterPartMgr() override; void appendGeometryPartsToModel( cvf::ModelBasicList* model, const caf::DisplayCoordTransform* displayCoordTransform, const cvf::BoundingBox& boundingBox ); - void clearGeometryCache(); - -private: - void createCellFilterPartManagers(); - private: - caf::PdmPointer m_rimView; - cvf::Collection m_cellFilterPartMgrs; + caf::PdmPointer m_rimView; }; diff --git a/ApplicationLibCode/ProjectDataModel/CellFilters/RimCellFilterCollection.cpp b/ApplicationLibCode/ProjectDataModel/CellFilters/RimCellFilterCollection.cpp index debe2ba6f7..0ffae32dba 100644 --- a/ApplicationLibCode/ProjectDataModel/CellFilters/RimCellFilterCollection.cpp +++ b/ApplicationLibCode/ProjectDataModel/CellFilters/RimCellFilterCollection.cpp @@ -260,6 +260,7 @@ RimPolygonFilter* RimCellFilterCollection::addNewPolygonFilter( RimCase* srcCase RimPolygonFilter* pFilter = new RimPolygonFilter(); pFilter->setCase( srcCase ); addFilter( pFilter ); + pFilter->configurePolygonEditor(); pFilter->enablePicking( true ); onFilterUpdated( pFilter ); return pFilter; diff --git a/ApplicationLibCode/ProjectDataModel/CellFilters/RimPolygonFilter.cpp b/ApplicationLibCode/ProjectDataModel/CellFilters/RimPolygonFilter.cpp index 7267dff235..b1a7de9a62 100644 --- a/ApplicationLibCode/ProjectDataModel/CellFilters/RimPolygonFilter.cpp +++ b/ApplicationLibCode/ProjectDataModel/CellFilters/RimPolygonFilter.cpp @@ -25,35 +25,21 @@ #include "RigFemPartGrid.h" #include "RigGeoMechCaseData.h" #include "RigMainGrid.h" -#include "RigPolyLinesData.h" #include "RigReservoirGridTools.h" +#include "Polygons/RimPolygon.h" +#include "Polygons/RimPolygonInView.h" + #include "Rim3dView.h" #include "RimCase.h" #include "RimCellFilterCollection.h" #include "RimEclipseCase.h" #include "RimGeoMechCase.h" -#include "RimPolylineTarget.h" - -#include "WellPathCommands/PointTangentManipulator/RicPolyline3dEditor.h" -#include "WellPathCommands/RicPolylineTargetsPickEventHandler.h" - -#include "RiuViewerCommands.h" +#include "RimTools.h" -#include "RiaStdStringTools.h" - -#include "cafCmdFeatureMenuBuilder.h" -#include "cafPdmUiLineEditor.h" +#include "Riu3DMainWindowTools.h" #include "cafPdmUiPushButtonEditor.h" -#include "cafPdmUiTableViewEditor.h" #include "cafPdmUiTreeOrdering.h" -#include - -#include "cvfBoundingBox.h" -#include "cvfStructGrid.h" - -#include - #include namespace caf @@ -77,42 +63,6 @@ void caf::AppEnum::setUp() } // namespace caf -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -class ThicknessValidator : public QValidator -{ -public: - State validate( QString& input, int& pos ) const override - { - if ( input.isEmpty() ) return State::Intermediate; - - int val = RiaStdStringTools::toInt( input.toStdString() ); - if ( val > 0 && val < 8 ) - return State::Acceptable; - else - return State::Invalid; - } -}; - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -class RadiusValidator : public QValidator -{ -public: - State validate( QString& input, int& pos ) const override - { - if ( input.isEmpty() ) return State::Intermediate; - - double val = RiaStdStringTools::toDouble( input.toStdString() ); - if ( val > 0.001 && val <= 2.0 ) - return State::Acceptable; - else - return State::Invalid; - } -}; - CAF_PDM_SOURCE_INIT( RimPolygonFilter, "PolygonFilter", "PolyLineFilter" ); //-------------------------------------------------------------------------------------------------- @@ -120,7 +70,6 @@ CAF_PDM_SOURCE_INIT( RimPolygonFilter, "PolygonFilter", "PolyLineFilter" ); //-------------------------------------------------------------------------------------------------- RimPolygonFilter::RimPolygonFilter() : RimCellFilter( RimCellFilter::INDEX ) - , m_pickTargetsEventHandler( new RicPolylineTargetsPickEventHandler( this ) ) , m_intervalTool( true ) { CAF_PDM_InitObject( "Polyline Filter", ":/CellFilter_Polygon.png" ); @@ -129,39 +78,25 @@ RimPolygonFilter::RimPolygonFilter() CAF_PDM_InitFieldNoDefault( &m_polyIncludeType, "PolyIncludeType", "Cells to include" ); - CAF_PDM_InitField( &m_enablePicking, "EnablePicking", false, "" ); - caf::PdmUiPushButtonEditor::configureEditorForField( &m_enablePicking ); - m_enablePicking.uiCapability()->setUiLabelPosition( caf::PdmUiItemInfo::LabelPosType::HIDDEN ); - - CAF_PDM_InitFieldNoDefault( &m_targets, "Targets", "Targets" ); - m_targets.uiCapability()->setUiEditorTypeName( caf::PdmUiTableViewEditor::uiEditorTypeName() ); - m_targets.uiCapability()->setUiTreeChildrenHidden( true ); - m_targets.uiCapability()->setUiLabelPosition( caf::PdmUiItemInfo::TOP ); - m_targets.uiCapability()->setCustomContextMenuEnabled( true ); + CAF_PDM_InitFieldNoDefault( &m_internalPolygon, "InternalPolygon", "Polygon For Filter" ); + m_internalPolygon = new RimPolygon; + m_internalPolygon->setName( "Polygon For Filter" ); + m_internalPolygon->uiCapability()->setUiTreeHidden( true ); - CAF_PDM_InitField( &m_showLines, "ShowLines", true, "Show Lines" ); - CAF_PDM_InitField( &m_showSpheres, "ShowSpheres", false, "Show Spheres" ); - CAF_PDM_InitField( &m_closePolygon, "ClosePolygon", true, "Closed Polygon" ); + CAF_PDM_InitFieldNoDefault( &m_cellFilterPolygon, "Polygon", "Polygon" ); + m_cellFilterPolygon = m_internalPolygon; - CAF_PDM_InitField( &m_lineThickness, "LineThickness", 3, "Line Thickness" ); - CAF_PDM_InitField( &m_sphereRadiusFactor, "SphereRadiusFactor", 0.15, "Sphere Radius Factor" ); - - CAF_PDM_InitField( &m_lineColor, "LineColor", cvf::Color3f( cvf::Color3f::WHITE ), "Line Color" ); - CAF_PDM_InitField( &m_sphereColor, "SphereColor", cvf::Color3f( cvf::Color3f::WHITE ), "Sphere Color" ); + CAF_PDM_InitFieldNoDefault( &m_polygonEditor, "PolygonEditor", "Polygon Editor" ); + m_polygonEditor = new RimPolygonInView; CAF_PDM_InitField( &m_enableFiltering, "EnableFiltering", false, "Enable Filter" ); CAF_PDM_InitField( &m_enableKFilter, "EnableKFilter", false, "Enable K Range Filter" ); CAF_PDM_InitFieldNoDefault( &m_kFilterStr, "KRangeFilter", "K Range Filter", "", "Example: 2,4-6,10-20:2", "" ); - CAF_PDM_InitField( &m_polygonPlaneDepth, "PolygonPlaneDepth", 0.0, "Polygon Plane Depth" ); - CAF_PDM_InitField( &m_lockPolygonToPlane, "LockPolygon", false, "Lock Polygon to Plane" ); - - m_polygonPlaneDepth.uiCapability()->setUiEditorTypeName( caf::PdmUiDoubleSliderEditor::uiEditorTypeName() ); - m_polygonPlaneDepth.uiCapability()->setUiLabelPosition( caf::PdmUiItemInfo::LabelPosType::TOP ); - - setUi3dEditorTypeName( RicPolyline3dEditor::uiEditorTypeName() ); - uiCapability()->setUiTreeChildrenHidden( true ); + CAF_PDM_InitField( &m_editPolygonButton, "EditPolygonButton", false, "Edit" ); + m_editPolygonButton.uiCapability()->setUiEditorTypeName( caf::PdmUiPushButtonEditor::uiEditorTypeName() ); + m_editPolygonButton.uiCapability()->setUiLabelPosition( caf::PdmUiItemInfo::HIDDEN ); m_propagateToSubGrids = false; @@ -169,31 +104,6 @@ RimPolygonFilter::RimPolygonFilter() setDeletable( true ); } -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -RimPolygonFilter::~RimPolygonFilter() -{ -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -void RimPolygonFilter::updateVisualization() -{ - updateCells(); - filterChanged.send(); -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -void RimPolygonFilter::updateEditorsAndVisualization() -{ - updateConnectedEditors(); - updateVisualization(); -} - //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -238,32 +148,11 @@ QString RimPolygonFilter::fullName() const //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -std::vector RimPolygonFilter::activeTargets() const +void RimPolygonFilter::initAfterRead() { - return m_targets.childrenByType(); -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -void RimPolygonFilter::insertTarget( const RimPolylineTarget* targetToInsertBefore, RimPolylineTarget* targetToInsert ) -{ - size_t index = m_targets.indexOf( targetToInsertBefore ); - if ( index < m_targets.size() ) - m_targets.insert( index, targetToInsert ); - else - m_targets.push_back( targetToInsert ); - - updateCells(); -} + RimCellFilter::initAfterRead(); -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -void RimPolygonFilter::deleteTarget( RimPolylineTarget* targetToDelete ) -{ - m_targets.removeChild( targetToDelete ); - delete targetToDelete; + configurePolygonEditor(); } //-------------------------------------------------------------------------------------------------- @@ -271,85 +160,15 @@ void RimPolygonFilter::deleteTarget( RimPolylineTarget* targetToDelete ) //-------------------------------------------------------------------------------------------------- void RimPolygonFilter::defineEditorAttribute( const caf::PdmFieldHandle* field, QString uiConfigName, caf::PdmUiEditorAttribute* attribute ) { - if ( field == &m_enablePicking ) - { - auto* pbAttribute = dynamic_cast( attribute ); - if ( pbAttribute ) - { - if ( !m_enablePicking ) - { - pbAttribute->m_buttonText = "Start Picking Points"; - } - else - { - pbAttribute->m_buttonText = "Stop Picking Points"; - } - } - } - else if ( field == &m_targets ) - { - auto tvAttribute = dynamic_cast( attribute ); - if ( tvAttribute ) - { - tvAttribute->resizePolicy = caf::PdmUiTableViewEditorAttribute::RESIZE_TO_FIT_CONTENT; - - if ( m_enablePicking ) - { - tvAttribute->baseColor.setRgb( 255, 220, 255 ); - tvAttribute->alwaysEnforceResizePolicy = true; - } - } - } - else if ( field == &m_lineThickness ) - { - auto myAttr = dynamic_cast( attribute ); - if ( myAttr ) - { - myAttr->validator = new ThicknessValidator(); - } - } - else if ( field == &m_lineThickness ) - { - auto myAttr = dynamic_cast( attribute ); - if ( myAttr ) - { - myAttr->validator = new RadiusValidator(); - } - } - else if ( field == &m_polygonPlaneDepth ) + if ( field == &m_editPolygonButton ) { - auto* attr = dynamic_cast( attribute ); - - if ( attr ) + if ( auto attrib = dynamic_cast( attribute ) ) { - if ( m_srcCase ) - { - auto bb = m_srcCase->allCellsBoundingBox(); - attr->m_minimum = -bb.max().z(); - attr->m_maximum = -bb.min().z(); - } - else - { - attr->m_minimum = 0; - attr->m_maximum = 10000; - } + attrib->m_buttonText = "Edit"; } } } -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -void RimPolygonFilter::defineCustomContextMenu( const caf::PdmFieldHandle* fieldNeedingMenu, QMenu* menu, QWidget* fieldEditorWidget ) -{ - caf::CmdFeatureMenuBuilder menuBuilder; - - menuBuilder << "RicDeletePolylineTargetFeature"; - menuBuilder << "RicAppendPointsToPolygonFilterFeature"; - - menuBuilder.appendToMenu( menu ); -} - //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -360,32 +179,23 @@ void RimPolygonFilter::defineUiOrdering( QString uiConfigName, caf::PdmUiOrderin auto group = uiOrdering.addNewGroup( "General" ); group->add( &m_filterMode ); group->add( &m_enableFiltering ); - group->add( &m_closePolygon ); + + uiOrdering.add( &m_cellFilterPolygon ); + if ( m_cellFilterPolygon() != m_internalPolygon() ) + { + uiOrdering.add( &m_editPolygonButton, { .newRow = false } ); + } auto group1 = uiOrdering.addNewGroup( "Polygon Selection" ); group1->add( &m_polyFilterMode ); - if ( m_closePolygon() ) group1->add( &m_polyIncludeType ); - group1->add( &m_targets ); - group1->add( &m_enablePicking ); - - m_polyIncludeType.uiCapability()->setUiName( "Cells to " + modeString() ); - auto group2 = uiOrdering.addNewGroup( "Appearance" ); - group2->add( &m_showLines ); - group2->add( &m_showSpheres ); - if ( m_showLines ) + bool isPolygonClosed = m_cellFilterPolygon() ? m_cellFilterPolygon->isClosed() : false; + if ( isPolygonClosed ) { - group2->add( &m_lineThickness ); - group2->add( &m_lineColor ); + group1->add( &m_polyIncludeType ); } - if ( m_showSpheres ) - { - group2->add( &m_sphereRadiusFactor ); - group2->add( &m_sphereColor ); - } - group2->add( &m_lockPolygonToPlane ); - if ( m_lockPolygonToPlane ) group2->add( &m_polygonPlaneDepth ); - group2->setCollapsedByDefault(); + + m_polyIncludeType.uiCapability()->setUiName( "Cells to " + modeString() ); auto group3 = uiOrdering.addNewGroup( "Advanced Filter Settings" ); group3->add( &m_enableKFilter ); @@ -402,7 +212,7 @@ void RimPolygonFilter::defineUiOrdering( QString uiConfigName, caf::PdmUiOrderin objField->uiCapability()->setUiReadOnly( readOnlyState ); } - if ( !m_closePolygon() ) + if ( !isPolygonClosed ) { m_polyFilterMode = RimPolygonFilter::PolygonFilterModeType::INDEX_K; m_polyFilterMode.uiCapability()->setUiReadOnly( true ); @@ -416,52 +226,76 @@ void RimPolygonFilter::defineUiOrdering( QString uiConfigName, caf::PdmUiOrderin //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -void RimPolygonFilter::fieldChangedByUi( const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue ) +void RimPolygonFilter::defineUiTreeOrdering( caf::PdmUiTreeOrdering& uiTreeOrdering, QString uiConfigName /*= "" */ ) { - if ( changedField == &m_enablePicking ) - { - updateConnectedEditors(); + RimCellFilter::defineUiTreeOrdering( uiTreeOrdering, uiConfigName ); - enableFilter( !m_enablePicking() ); - filterChanged.send(); - } - else if ( ( changedField == &m_showLines ) || ( changedField == &m_showSpheres ) || ( changedField == &m_sphereColor ) || - ( changedField == &m_sphereRadiusFactor ) || ( changedField == &m_lineThickness ) || ( changedField == &m_lineColor ) || - ( changedField == &m_lockPolygonToPlane ) || ( changedField == &m_polygonPlaneDepth ) ) - { - filterChanged.send(); - } - else if ( changedField != &m_name ) + bool showPolygonEditor = ( m_cellFilterPolygon() == m_internalPolygon() ); + + if ( showPolygonEditor ) { - updateCells(); - filterChanged.send(); - updateIconState(); + uiTreeOrdering.add( m_polygonEditor() ); } + + uiTreeOrdering.skipRemainingChildren(); } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -void RimPolygonFilter::enablePicking( bool enable ) +QList RimPolygonFilter::calculateValueOptions( const caf::PdmFieldHandle* fieldNeedingOptions ) { - m_enablePicking = enable; - updateConnectedEditors(); + QList options; + if ( fieldNeedingOptions == &m_cellFilterPolygon ) + { + RimTools::polygonOptionItems( &options ); + if ( !options.empty() ) + { + options.push_front( caf::PdmOptionItemInfo( "Project Polygons", nullptr ) ); + } + + options.push_front( + caf::PdmOptionItemInfo( m_internalPolygon()->name(), m_internalPolygon(), false, m_internalPolygon->uiIconProvider() ) ); + } + + return options; } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -bool RimPolygonFilter::pickingEnabled() const +void RimPolygonFilter::fieldChangedByUi( const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue ) { - return m_enablePicking(); + if ( changedField == &m_editPolygonButton ) + { + if ( m_cellFilterPolygon() ) Riu3DMainWindowTools::selectAsCurrentItem( m_cellFilterPolygon() ); + + m_editPolygonButton = false; + + return; + } + + if ( changedField == &m_cellFilterPolygon ) + { + configurePolygonEditor(); + updateAllRequiredEditors(); + } + + if ( changedField != &m_name ) + { + updateCells(); + filterChanged.send(); + updateIconState(); + } } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -caf::PickEventHandler* RimPolygonFilter::pickEventHandler() const +void RimPolygonFilter::enablePicking( bool enable ) { - return m_pickTargetsEventHandler.get(); + m_polygonEditor->enablePicking( enable ); + updateConnectedEditors(); } //-------------------------------------------------------------------------------------------------- @@ -583,7 +417,7 @@ void RimPolygonFilter::updateCellsKIndexEclipse( const std::vector& const int gIdx = static_cast( grid->gridIndex() ); std::list foundCells; - const bool closedPolygon = m_closePolygon(); + const bool closedPolygon = isPolygonClosed(); // find all cells in the K layer that matches the polygon #pragma omp parallel for @@ -591,8 +425,8 @@ void RimPolygonFilter::updateCellsKIndexEclipse( const std::vector& { for ( size_t j = 0; j < grid->cellCountJ(); j++ ) { - size_t cellIdx = grid->cellIndexFromIJK( i, j, K ); - RigCell cell = grid->cell( cellIdx ); + size_t cellIdx = grid->cellIndexFromIJK( i, j, K ); + const RigCell& cell = grid->cell( cellIdx ); // valid cell? if ( cell.isInvalid() ) continue; @@ -634,7 +468,7 @@ void RimPolygonFilter::updateCellsKIndexEclipse( const std::vector& // get the cell index size_t newIdx = grid->cellIndexFromIJK( ci, cj, k ); // valid cell? - RigCell cell = grid->cell( newIdx ); + const RigCell& cell = grid->cell( newIdx ); if ( cell.isInvalid() ) continue; m_cells[gIdx].push_back( newIdx ); @@ -652,7 +486,7 @@ void RimPolygonFilter::updateCellsForEclipse( const std::vector& poi if ( m_polyFilterMode == PolygonFilterModeType::DEPTH_Z ) { - if ( !m_closePolygon() ) return; + if ( !isPolygonClosed() ) return; for ( size_t gridIndex = 0; gridIndex < data->gridCount(); gridIndex++ ) { @@ -720,7 +554,7 @@ void RimPolygonFilter::updateCellsDepthGeoMech( const std::vector& p //-------------------------------------------------------------------------------------------------- void RimPolygonFilter::updateCellsKIndexGeoMech( const std::vector& points, const RigFemPartGrid* grid, int partId ) { - const bool closedPolygon = m_closePolygon(); + const bool closedPolygon = isPolygonClosed(); // we need to find the K layer we hit with the first point size_t nk; @@ -839,7 +673,7 @@ void RimPolygonFilter::updateCellsForGeoMech( const std::vector& poi if ( m_polyFilterMode == PolygonFilterModeType::DEPTH_Z ) { - if ( m_closePolygon() ) + if ( isPolygonClosed() ) { updateCellsDepthGeoMech( points, grid, i ); } @@ -865,16 +699,17 @@ void RimPolygonFilter::updateCells() // get polyline as vector std::vector points; - for ( auto& target : m_targets ) + + for ( auto target : m_polygonEditor->activeTargets() ) { - if ( target->isEnabled() ) points.push_back( target->targetPointXYZ() ); + points.push_back( target->targetPointXYZ() ); } // We need at least three points to make a closed polygon, or just 2 for a polyline - if ( ( !m_closePolygon() && ( points.size() < 2 ) ) || ( m_closePolygon() && ( points.size() < 3 ) ) ) return; + if ( ( !isPolygonClosed() && ( points.size() < 2 ) ) || ( isPolygonClosed() && ( points.size() < 3 ) ) ) return; // make sure first and last point is the same (req. by closed polygon methods used later) - if ( m_closePolygon() ) points.push_back( points.front() ); + if ( isPolygonClosed() ) points.push_back( points.front() ); RimEclipseCase* eCase = eclipseCase(); RimGeoMechCase* gCase = geoMechCase(); @@ -892,30 +727,31 @@ void RimPolygonFilter::updateCells() //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -cvf::ref RimPolygonFilter::polyLinesData() const +void RimPolygonFilter::configurePolygonEditor() { - cvf::ref pld = new RigPolyLinesData; - std::vector line; - for ( const RimPolylineTarget* target : m_targets ) - { - if ( target->isEnabled() ) line.push_back( target->targetPointXYZ() ); - } - pld->setPolyLine( line ); + m_polygonEditor->setPolygon( m_cellFilterPolygon() ); - pld->setLineAppearance( m_lineThickness, m_lineColor, m_closePolygon ); - pld->setSphereAppearance( m_sphereRadiusFactor, m_sphereColor ); - pld->setZPlaneLock( m_lockPolygonToPlane, -m_polygonPlaneDepth ); + // Must connect the signals after polygon is assigned to the polygon editor + // When assigning an object to a ptr field, all signals are disconnected + connectObjectSignals( m_cellFilterPolygon() ); +} - if ( isActive() ) - { - pld->setVisibility( m_showLines, m_showSpheres ); - } - else - { - pld->setVisibility( false, false ); - } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimPolygonFilter::appendPartsToModel( cvf::ModelBasicList* model, + const caf::DisplayCoordTransform* scaleTransform, + const cvf::BoundingBox& boundingBox ) +{ + return m_polygonEditor->appendPartsToModel( model, scaleTransform, boundingBox ); +} - return pld; +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RimPolygonInView* RimPolygonFilter::polygonEditor() const +{ + return m_polygonEditor(); } //-------------------------------------------------------------------------------------------------- @@ -932,6 +768,44 @@ void RimPolygonFilter::initializeCellList() } } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool RimPolygonFilter::isPolygonClosed() const +{ + if ( m_polygonEditor->polygon() ) return m_polygonEditor->polygon()->isClosed(); + + return false; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimPolygonFilter::connectObjectSignals( RimPolygon* polygon ) +{ + if ( m_cellFilterPolygon() ) + { + m_cellFilterPolygon()->objectChanged.disconnect( this ); + } + + if ( polygon ) + { + m_cellFilterPolygon = polygon; + + polygon->objectChanged.connect( this, &RimPolygonFilter::onObjectChanged ); + } +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimPolygonFilter::onObjectChanged( const caf::SignalEmitter* emitter ) +{ + updateCells(); + filterChanged.send(); + updateIconState(); +} + //-------------------------------------------------------------------------------------------------- /// 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 94018cf843..52a63e5da1 100644 --- a/ApplicationLibCode/ProjectDataModel/CellFilters/RimPolygonFilter.h +++ b/ApplicationLibCode/ProjectDataModel/CellFilters/RimPolygonFilter.h @@ -20,39 +20,34 @@ #include "RimCellFilter.h" #include "RimCellFilterIntervalTool.h" -#include "RimPolylinePickerInterface.h" -#include "RimPolylinesDataInterface.h" #include "cafAppEnum.h" -#include "cafPdmChildArrayField.h" -#include "cafPdmField.h" -#include "cafPdmFieldCvfColor.h" -#include "cafPdmFieldCvfVec3d.h" +#include "cafPdmChildField.h" #include "cafPdmObject.h" #include "cafPdmPtrField.h" -#include "cafPickEventHandler.h" -#include "cvfColor3.h" - -#include -#include - -class RicPolylineTargetsPickEventHandler; -class RimPolylineTarget; -class RimCase; -class RimEclipseCase; -class RimGeoMechCase; +class RimPolygon; class RigGridBase; -class RigMainGrid; class RigFemPartGrid; -class RigPolylinesData; -class RigEclipseCaseData; +class RimPolygonInView; + +namespace cvf +{ +class ModelBasicList; +class BoundingBox; + +}; // namespace cvf + +namespace caf +{ +class DisplayCoordTransform; +}; //================================================================================================== /// /// //================================================================================================== -class RimPolygonFilter : public RimCellFilter, public RimPolylinePickerInterface, public RimPolylinesDataInterface +class RimPolygonFilter : public RimCellFilter { CAF_PDM_HEADER_INIT; @@ -71,38 +66,33 @@ class RimPolygonFilter : public RimCellFilter, public RimPolylinePickerInterface }; RimPolygonFilter(); - ~RimPolygonFilter() override; void enableFilter( bool bEnable ); void enableKFilter( bool bEnable ); bool isFilterEnabled() const override; - void updateVisualization() override; - void updateEditorsAndVisualization() override; - void insertTarget( const RimPolylineTarget* targetToInsertBefore, RimPolylineTarget* targetToInsert ) override; - void deleteTarget( RimPolylineTarget* targetToDelete ) override; void enablePicking( bool enable ); - std::vector activeTargets() const override; - bool pickingEnabled() const override; - caf::PickEventHandler* pickEventHandler() const override; - void updateCellIndexFilter( cvf::UByteArray* includeVisibility, cvf::UByteArray* excludeVisibility, int gridIndex ) override; void onGridChanged() override; - cvf::ref polyLinesData() const override; + void configurePolygonEditor(); + void appendPartsToModel( cvf::ModelBasicList* model, const caf::DisplayCoordTransform* scaleTransform, const cvf::BoundingBox& boundingBox ); + + RimPolygonInView* polygonEditor() const; protected: void fieldChangedByUi( const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue ) override; void defineUiOrdering( QString uiConfigName, caf::PdmUiOrdering& uiOrdering ) override; + void defineUiTreeOrdering( caf::PdmUiTreeOrdering& uiTreeOrdering, QString uiConfigName = "" ) override; + QList calculateValueOptions( const caf::PdmFieldHandle* fieldNeedingOptions ) override; + void initAfterRead() override; + void defineEditorAttribute( const caf::PdmFieldHandle* field, QString uiConfigName, caf::PdmUiEditorAttribute* attribute ) override; QString fullName() const override; private: - void defineCustomContextMenu( const caf::PdmFieldHandle* fieldNeedingMenu, QMenu* menu, QWidget* fieldEditorWidget ) override; - void defineEditorAttribute( const caf::PdmFieldHandle* field, QString uiConfigName, caf::PdmUiEditorAttribute* attribute ) override; - void updateCells(); void updateCellsForEclipse( const std::vector& points, RimEclipseCase* eCase ); void updateCellsForGeoMech( const std::vector& points, RimGeoMechCase* gCase ); @@ -118,26 +108,25 @@ class RimPolygonFilter : public RimCellFilter, public RimPolylinePickerInterface void initializeCellList(); - caf::PdmField m_enablePicking; - caf::PdmChildArrayField m_targets; + bool isPolygonClosed() const; + + void connectObjectSignals( RimPolygon* polygon ); + void onObjectChanged( const caf::SignalEmitter* emitter ); + +private: caf::PdmField> m_polyFilterMode; caf::PdmField> m_polyIncludeType; caf::PdmField m_enableFiltering; - caf::PdmField m_showLines; - caf::PdmField m_showSpheres; - caf::PdmField m_lineThickness; - caf::PdmField m_sphereRadiusFactor; - caf::PdmField m_lineColor; - caf::PdmField m_sphereColor; - caf::PdmField m_polygonPlaneDepth; - caf::PdmField m_lockPolygonToPlane; caf::PdmField m_enableKFilter; caf::PdmField m_kFilterStr; - caf::PdmField m_closePolygon; - - std::shared_ptr m_pickTargetsEventHandler; std::vector> m_cells; RimCellFilterIntervalTool m_intervalTool; + + // Local polygon and polygon editor + caf::PdmPtrField m_cellFilterPolygon; + caf::PdmChildField m_internalPolygon; + caf::PdmChildField m_polygonEditor; + caf::PdmField m_editPolygonButton; };