From 6efceea597ae2f5eba0307a62f9a72935c4318b6 Mon Sep 17 00:00:00 2001 From: Kristian Bendiksen Date: Fri, 29 Nov 2019 13:49:43 +0100 Subject: [PATCH] #5125 Make each well measurement a checkable entity. --- .../ModelVisualization/RivWellPathPartMgr.cpp | 98 +++++---- .../ProjectDataModel/CMakeLists_files.cmake | 2 + .../ProjectDataModel/RimEclipseView.cpp | 22 +- .../ProjectDataModel/RimGeoMechView.cpp | 23 +- .../RimWellMeasurementInView.cpp | 201 ++++++++++++++++++ .../RimWellMeasurementInView.h | 62 ++++++ .../RimWellMeasurementInViewCollection.cpp | 138 +++--------- .../RimWellMeasurementInViewCollection.h | 21 +- 8 files changed, 389 insertions(+), 178 deletions(-) create mode 100644 ApplicationCode/ProjectDataModel/RimWellMeasurementInView.cpp create mode 100644 ApplicationCode/ProjectDataModel/RimWellMeasurementInView.h diff --git a/ApplicationCode/ModelVisualization/RivWellPathPartMgr.cpp b/ApplicationCode/ModelVisualization/RivWellPathPartMgr.cpp index a3070c09a8..7ba6639fc0 100644 --- a/ApplicationCode/ModelVisualization/RivWellPathPartMgr.cpp +++ b/ApplicationCode/ModelVisualization/RivWellPathPartMgr.cpp @@ -42,6 +42,7 @@ #include "RimWellMeasurement.h" #include "RimWellMeasurementCollection.h" #include "RimWellMeasurementFilter.h" +#include "RimWellMeasurementInView.h" #include "RimWellMeasurementInViewCollection.h" #include "RimWellPath.h" #include "RimWellPathAttribute.h" @@ -301,54 +302,61 @@ void RivWellPathPartMgr::appendWellMeasurementsToModel( cvf::ModelBasicList* if ( !gridView->measurementCollection()->isChecked() ) return; - std::vector measurementKinds = gridView->measurementCollection()->measurementKinds(); - - RivPipeGeometryGenerator geoGenerator; - std::vector wellMeasurements = - RimWellMeasurementFilter::filterMeasurements( wellMeasurementCollection->measurements(), - *wellPathCollection, - *m_rimWellPath, - measurementKinds ); - - for ( RimWellMeasurement* wellMeasurement : wellMeasurements ) + for ( RimWellMeasurementInView* wellMeasurementInView : gridView->measurementCollection()->measurements() ) { - double wellPathRadius = this->wellPathRadius( characteristicCellSize, this->wellPathCollection() ); - double startMD = wellMeasurement->MD() - wellPathRadius * 0.5; - double endMD = wellMeasurement->MD() + wellPathRadius * 0.5; - - std::vector displayCoords; - displayCoords.push_back( displayCoordTransform->transformToDisplayCoord( - m_rimWellPath->wellPathGeometry()->interpolatedPointAlongWellPath( startMD ) ) ); - displayCoords.push_back( displayCoordTransform->transformToDisplayCoord( - m_rimWellPath->wellPathGeometry()->interpolatedPointAlongWellPath( startMD ) ) ); - displayCoords.push_back( displayCoordTransform->transformToDisplayCoord( - m_rimWellPath->wellPathGeometry()->interpolatedPointAlongWellPath( endMD ) ) ); - displayCoords.push_back( displayCoordTransform->transformToDisplayCoord( - m_rimWellPath->wellPathGeometry()->interpolatedPointAlongWellPath( endMD ) ) ); - - std::vector radii; - radii.push_back( wellPathRadius ); - radii.push_back( wellPathRadius * 2.5 ); - radii.push_back( wellPathRadius * 2.5 ); - radii.push_back( wellPathRadius ); - - cvf::ref objectSourceInfo = new RivObjectSourceInfo( wellMeasurement ); - - cvf::Collection parts; - cvf::Color3f color = mapWellMeasurementToColor( wellMeasurement->kind(), wellMeasurement->value() ); - - // Use the view legend config to find color, if only one type of measurement is selected. - if ( measurementKinds.size() == 1 ) + if ( wellMeasurementInView->isChecked() ) { - color = cvf::Color3f( gridView->measurementCollection()->legendConfig()->scalarMapper()->mapToColor( - wellMeasurement->value() ) ); - } + std::vector measurementKinds; + measurementKinds.push_back( wellMeasurementInView->measurementKind() ); - geoGenerator.tubeWithCenterLinePartsAndVariableWidth( &parts, displayCoords, radii, color ); - for ( auto part : parts ) - { - part->setSourceInfo( objectSourceInfo.p() ); - model->addPart( part.p() ); + RivPipeGeometryGenerator geoGenerator; + std::vector wellMeasurements = + RimWellMeasurementFilter::filterMeasurements( wellMeasurementCollection->measurements(), + *wellPathCollection, + *m_rimWellPath, + measurementKinds ); + + for ( RimWellMeasurement* wellMeasurement : wellMeasurements ) + { + double wellPathRadius = this->wellPathRadius( characteristicCellSize, this->wellPathCollection() ); + double startMD = wellMeasurement->MD() - wellPathRadius * 0.5; + double endMD = wellMeasurement->MD() + wellPathRadius * 0.5; + + std::vector displayCoords; + displayCoords.push_back( displayCoordTransform->transformToDisplayCoord( + m_rimWellPath->wellPathGeometry()->interpolatedPointAlongWellPath( startMD ) ) ); + displayCoords.push_back( displayCoordTransform->transformToDisplayCoord( + m_rimWellPath->wellPathGeometry()->interpolatedPointAlongWellPath( startMD ) ) ); + displayCoords.push_back( displayCoordTransform->transformToDisplayCoord( + m_rimWellPath->wellPathGeometry()->interpolatedPointAlongWellPath( endMD ) ) ); + displayCoords.push_back( displayCoordTransform->transformToDisplayCoord( + m_rimWellPath->wellPathGeometry()->interpolatedPointAlongWellPath( endMD ) ) ); + + std::vector radii; + radii.push_back( wellPathRadius ); + radii.push_back( wellPathRadius * 2.5 ); + radii.push_back( wellPathRadius * 2.5 ); + radii.push_back( wellPathRadius ); + + cvf::ref objectSourceInfo = new RivObjectSourceInfo( wellMeasurement ); + + cvf::Collection parts; + cvf::Color3f color = mapWellMeasurementToColor( wellMeasurement->kind(), wellMeasurement->value() ); + + // Use the view legend config to find color, if only one type of measurement is selected. + if ( measurementKinds.size() == 1 ) + { + color = cvf::Color3f( + wellMeasurementInView->legendConfig()->scalarMapper()->mapToColor( wellMeasurement->value() ) ); + } + + geoGenerator.tubeWithCenterLinePartsAndVariableWidth( &parts, displayCoords, radii, color ); + for ( auto part : parts ) + { + part->setSourceInfo( objectSourceInfo.p() ); + model->addPart( part.p() ); + } + } } } } diff --git a/ApplicationCode/ProjectDataModel/CMakeLists_files.cmake b/ApplicationCode/ProjectDataModel/CMakeLists_files.cmake index e413b23947..7ed4987178 100644 --- a/ApplicationCode/ProjectDataModel/CMakeLists_files.cmake +++ b/ApplicationCode/ProjectDataModel/CMakeLists_files.cmake @@ -146,6 +146,7 @@ ${CMAKE_CURRENT_LIST_DIR}/RimMultiPlotCollection.h ${CMAKE_CURRENT_LIST_DIR}/RimWellMeasurementCurve.h ${CMAKE_CURRENT_LIST_DIR}/RimWellMeasurementFilter.h ${CMAKE_CURRENT_LIST_DIR}/RimWellMeasurementInViewCollection.h +${CMAKE_CURRENT_LIST_DIR}/RimWellMeasurementInView.h ) @@ -296,6 +297,7 @@ ${CMAKE_CURRENT_LIST_DIR}/RimMultiPlotCollection.cpp ${CMAKE_CURRENT_LIST_DIR}/RimWellMeasurementCurve.cpp ${CMAKE_CURRENT_LIST_DIR}/RimWellMeasurementFilter.cpp ${CMAKE_CURRENT_LIST_DIR}/RimWellMeasurementInViewCollection.cpp +${CMAKE_CURRENT_LIST_DIR}/RimWellMeasurementInView.cpp ) list(APPEND CODE_HEADER_FILES diff --git a/ApplicationCode/ProjectDataModel/RimEclipseView.cpp b/ApplicationCode/ProjectDataModel/RimEclipseView.cpp index 42dc04509a..b482ab933d 100644 --- a/ApplicationCode/ProjectDataModel/RimEclipseView.cpp +++ b/ApplicationCode/ProjectDataModel/RimEclipseView.cpp @@ -76,6 +76,7 @@ #include "RimViewLinker.h" #include "RimViewNameConfig.h" #include "RimVirtualPerforationResults.h" +#include "RimWellMeasurementInView.h" #include "RimWellMeasurementInViewCollection.h" #include "RimWellPathCollection.h" @@ -1308,10 +1309,15 @@ void RimEclipseView::onUpdateLegends() isUsingOverrideViewer() ); } - if ( m_wellMeasurementCollection->isChecked() && m_wellMeasurementCollection->legendConfig()->showLegend() ) + if ( m_wellMeasurementCollection->isChecked() ) { - m_wellMeasurementCollection->updateLegendRangesTextAndVisibility( nativeOrOverrideViewer(), - isUsingOverrideViewer() ); + for ( RimWellMeasurementInView* wellMeasurement : m_wellMeasurementCollection->measurements() ) + { + if ( wellMeasurement->legendConfig()->showLegend() ) + { + wellMeasurement->updateLegendRangesTextAndVisibility( nativeOrOverrideViewer(), isUsingOverrideViewer() ); + } + } } } @@ -1859,7 +1865,10 @@ void RimEclipseView::onResetLegendsInViewer() sepInterResDef->ternaryLegendConfig()->recreateLegend(); } - m_wellMeasurementCollection->legendConfig()->recreateLegend(); + for ( RimWellMeasurementInView* wellMeasurement : m_wellMeasurementCollection->measurements() ) + { + wellMeasurement->legendConfig()->recreateLegend(); + } nativeOrOverrideViewer()->removeAllColorLegends(); } @@ -2019,7 +2028,10 @@ std::vector RimEclipseView::legendConfigs() const absLegends.push_back( sepInterResDef->ternaryLegendConfig() ); } - absLegends.push_back( m_wellMeasurementCollection->legendConfig() ); + for ( RimWellMeasurementInView* wellMeasurement : m_wellMeasurementCollection->measurements() ) + { + absLegends.push_back( wellMeasurement->legendConfig() ); + } return absLegends; } diff --git a/ApplicationCode/ProjectDataModel/RimGeoMechView.cpp b/ApplicationCode/ProjectDataModel/RimGeoMechView.cpp index a7c0f92540..5f5660e1b1 100644 --- a/ApplicationCode/ProjectDataModel/RimGeoMechView.cpp +++ b/ApplicationCode/ProjectDataModel/RimGeoMechView.cpp @@ -46,6 +46,7 @@ #include "RimTernaryLegendConfig.h" #include "RimViewLinker.h" #include "RimViewNameConfig.h" +#include "RimWellMeasurementInView.h" #include "RimWellMeasurementInViewCollection.h" #include "Riu3DMainWindowTools.h" @@ -428,7 +429,10 @@ void RimGeoMechView::onResetLegendsInViewer() sepInterResDef->ternaryLegendConfig()->recreateLegend(); } - m_wellMeasurementCollection->legendConfig()->recreateLegend(); + for ( RimWellMeasurementInView* wellMeasurement : m_wellMeasurementCollection->measurements() ) + { + wellMeasurement->legendConfig()->recreateLegend(); + } nativeOrOverrideViewer()->removeAllColorLegends(); } @@ -481,10 +485,16 @@ void RimGeoMechView::onUpdateLegends() } } - if ( m_wellMeasurementCollection->isChecked() && m_wellMeasurementCollection->legendConfig()->showLegend() ) + if ( m_wellMeasurementCollection->isChecked() ) { - m_wellMeasurementCollection->updateLegendRangesTextAndVisibility( nativeOrOverrideViewer(), - isUsingOverrideViewer() ); + for ( RimWellMeasurementInView* wellMeasurement : m_wellMeasurementCollection->measurements() ) + { + if ( wellMeasurement->legendConfig()->showLegend() ) + { + wellMeasurement->updateLegendRangesTextAndVisibility( nativeOrOverrideViewer(), + isUsingOverrideViewer() ); + } + } } } } @@ -587,7 +597,10 @@ std::vector RimGeoMechView::legendConfigs() const absLegendConfigs.push_back( sepInterResDef->regularLegendConfig() ); } - absLegendConfigs.push_back( m_wellMeasurementCollection->legendConfig() ); + for ( RimWellMeasurementInView* wellMeasurement : m_wellMeasurementCollection->measurements() ) + { + absLegendConfigs.push_back( wellMeasurement->legendConfig() ); + } return absLegendConfigs; } diff --git a/ApplicationCode/ProjectDataModel/RimWellMeasurementInView.cpp b/ApplicationCode/ProjectDataModel/RimWellMeasurementInView.cpp new file mode 100644 index 0000000000..3ccab93f9d --- /dev/null +++ b/ApplicationCode/ProjectDataModel/RimWellMeasurementInView.cpp @@ -0,0 +1,201 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2019- 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 "RimWellMeasurementInView.h" + +#include "Rim3dView.h" +#include "RimGridView.h" +#include "RimProject.h" +#include "RimRegularLegendConfig.h" +#include "RimTools.h" +#include "RimWellLogTrack.h" +#include "RimWellMeasurement.h" +#include "RimWellMeasurementCollection.h" +#include "RimWellMeasurementFilter.h" +#include "RimWellPathCollection.h" + +#include "RiuViewer.h" + +#include "cafCmdFeatureMenuBuilder.h" +#include "cafPdmUiTableViewEditor.h" +#include "cafPdmUiTreeOrdering.h" +#include "cafPdmUiTreeSelectionEditor.h" + +#include + +CAF_PDM_SOURCE_INIT( RimWellMeasurementInView, "WellMeasurementInView" ); + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RimWellMeasurementInView::RimWellMeasurementInView() +{ + CAF_PDM_InitObject( "Well Measurement", "", "", "" ); + + CAF_PDM_InitFieldNoDefault( &m_measurementKind, "MeasurementKind", "Measurement Kind", "", "", "" ); + m_measurementKind.uiCapability()->setUiHidden( true ); + + CAF_PDM_InitFieldNoDefault( &m_legendConfig, "LegendDefinition", "Color Legend", "", "", "" ); + m_legendConfig = new RimRegularLegendConfig(); + m_legendConfig.uiCapability()->setUiHidden( true ); + + CAF_PDM_InitFieldNoDefault( &m_wells, "Wells", "Wells", "", "", "" ); + m_wells.uiCapability()->setAutoAddingOptionFromValue( false ); + m_wells.uiCapability()->setUiEditorTypeName( caf::PdmUiTreeSelectionEditor::uiEditorTypeName() ); + m_wells.uiCapability()->setUiLabelPosition( caf::PdmUiItemInfo::HIDDEN ); + m_wells.xmlCapability()->disableIO(); + + this->setName( "Well Measurement" ); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RimWellMeasurementInView::~RimWellMeasurementInView() +{ + delete m_legendConfig; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimWellMeasurementInView::defineUiTreeOrdering( caf::PdmUiTreeOrdering& uiTreeOrdering, + QString uiConfigName /*= ""*/ ) +{ + uiTreeOrdering.add( &m_legendConfig ); + uiTreeOrdering.skipRemainingChildren( true ); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimWellMeasurementInView::fieldChangedByUi( const caf::PdmFieldHandle* changedField, + const QVariant& oldValue, + const QVariant& newValue ) +{ + updateLegendData(); + RimGridView* rimGridView = nullptr; + this->firstAncestorOrThisOfTypeAsserted( rimGridView ); + rimGridView->scheduleCreateDisplayModelAndRedraw(); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RimRegularLegendConfig* RimWellMeasurementInView::legendConfig() +{ + return m_legendConfig; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool RimWellMeasurementInView::updateLegendData() +{ + RimWellPathCollection* wellPathCollection = RimTools::wellPathCollection(); + if ( !wellPathCollection ) return false; + + RimWellMeasurementCollection* wellMeasurementCollection = wellPathCollection->measurementCollection(); + if ( !wellMeasurementCollection ) return false; + + std::vector selectedMeasurementKinds; + selectedMeasurementKinds.push_back( m_measurementKind ); + std::vector wellMeasurements = + RimWellMeasurementFilter::filterMeasurements( wellMeasurementCollection->measurements(), + selectedMeasurementKinds ); + + double minValue = HUGE_VAL; + double maxValue = -HUGE_VAL; + double posClosestToZero = HUGE_VAL; + double negClosestToZero = -HUGE_VAL; + + for ( auto& measurement : wellMeasurements ) + { + minValue = std::min( measurement->value(), minValue ); + maxValue = std::max( measurement->value(), maxValue ); + } + + if ( minValue != HUGE_VAL ) + { + m_legendConfig->setTitle( QString( "Well Measurement: \n" ) + selectedMeasurementKinds[0] ); + m_legendConfig->setAutomaticRanges( minValue, maxValue, minValue, maxValue ); + m_legendConfig->setClosestToZeroValues( posClosestToZero, negClosestToZero, posClosestToZero, negClosestToZero ); + return true; + } + + return false; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimWellMeasurementInView::updateLegendRangesTextAndVisibility( RiuViewer* nativeOrOverrideViewer, + bool isUsingOverrideViewer ) +{ + bool addToViewer = updateLegendData(); + if ( addToViewer ) + { + nativeOrOverrideViewer->addColorLegendToBottomLeftCorner( m_legendConfig->titledOverlayFrame(), + isUsingOverrideViewer ); + } +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +QList + RimWellMeasurementInView::calculateValueOptions( const caf::PdmFieldHandle* fieldNeedingOptions, bool* useOptionsOnly ) +{ + QList options; + if ( fieldNeedingOptions == &m_wells ) + { + RimWellPathCollection* wellPathCollection = RimTools::wellPathCollection(); + if ( wellPathCollection ) + { + // std::vector measurements = wellPathCollection->measurementCollection()->measurements(); + + std::set wellsWithMeasurementKind; + for ( auto well : wellPathCollection->wellPaths ) + { + wellsWithMeasurementKind.insert( well->name() ); + } + + for ( auto wellName : wellsWithMeasurementKind ) + { + options.push_back( caf::PdmOptionItemInfo( wellName, wellName ) ); + } + } + } + + return options; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +QString RimWellMeasurementInView::measurementKind() const +{ + return m_measurementKind; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimWellMeasurementInView::setMeasurementKind( const QString& measurementKind ) +{ + m_measurementKind = measurementKind; +} diff --git a/ApplicationCode/ProjectDataModel/RimWellMeasurementInView.h b/ApplicationCode/ProjectDataModel/RimWellMeasurementInView.h new file mode 100644 index 0000000000..a906380a57 --- /dev/null +++ b/ApplicationCode/ProjectDataModel/RimWellMeasurementInView.h @@ -0,0 +1,62 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2019- 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 "RimCheckableNamedObject.h" + +#include "cafPdmChildArrayField.h" +#include "cafPdmChildField.h" +#include "cafPdmField.h" +#include "cafPdmObject.h" +#include "cafPdmProxyValueField.h" + +#include + +class RimWellMeasurement; +class RimRegularLegendConfig; +class RiuViewer; + +class RimWellMeasurementInView : public RimCheckableNamedObject +{ + CAF_PDM_HEADER_INIT; + +public: + RimWellMeasurementInView(); + ~RimWellMeasurementInView() override; + + RimRegularLegendConfig* legendConfig(); + QString measurementKind() const; + void setMeasurementKind( const QString& measurementKind ); + + void updateLegendRangesTextAndVisibility( RiuViewer* nativeOrOverrideViewer, bool isUsingOverrideViewer ); + +protected: + void defineUiTreeOrdering( caf::PdmUiTreeOrdering& uiTreeOrdering, QString uiConfigName = "" ) override; + void fieldChangedByUi( const caf::PdmFieldHandle* changedField, + const QVariant& oldValue, + const QVariant& newValue ) override; + QList calculateValueOptions( const caf::PdmFieldHandle* fieldNeedingOptions, + bool* useOptionsOnly ); + + bool updateLegendData(); + +private: + caf::PdmChildField m_legendConfig; + caf::PdmField m_measurementKind; + caf::PdmField> m_wells; +}; diff --git a/ApplicationCode/ProjectDataModel/RimWellMeasurementInViewCollection.cpp b/ApplicationCode/ProjectDataModel/RimWellMeasurementInViewCollection.cpp index f89baa4d81..bf150aa9d2 100644 --- a/ApplicationCode/ProjectDataModel/RimWellMeasurementInViewCollection.cpp +++ b/ApplicationCode/ProjectDataModel/RimWellMeasurementInViewCollection.cpp @@ -26,10 +26,9 @@ #include "RimWellMeasurement.h" #include "RimWellMeasurementCollection.h" #include "RimWellMeasurementFilter.h" +#include "RimWellMeasurementInView.h" #include "RimWellPathCollection.h" -#include "RiuViewer.h" - #include "cafCmdFeatureMenuBuilder.h" #include "cafPdmUiTableViewEditor.h" #include "cafPdmUiTreeOrdering.h" @@ -44,17 +43,10 @@ CAF_PDM_SOURCE_INIT( RimWellMeasurementInViewCollection, "WellMeasurementsInView //-------------------------------------------------------------------------------------------------- RimWellMeasurementInViewCollection::RimWellMeasurementInViewCollection() { - CAF_PDM_InitObject( "Well Measurement", "", "", "" ); + CAF_PDM_InitObject( "Well Measurements", "", "", "" ); - CAF_PDM_InitFieldNoDefault( &m_legendConfig, "LegendDefinition", "Color Legend", "", "", "" ); - m_legendConfig = new RimRegularLegendConfig(); - m_legendConfig.uiCapability()->setUiHidden( true ); - - CAF_PDM_InitFieldNoDefault( &m_measurementKinds, "MeasurementKinds", "Measurent Kinds", "", "", "" ); - m_measurementKinds.uiCapability()->setAutoAddingOptionFromValue( false ); - m_measurementKinds.uiCapability()->setUiEditorTypeName( caf::PdmUiTreeSelectionEditor::uiEditorTypeName() ); - m_measurementKinds.uiCapability()->setUiLabelPosition( caf::PdmUiItemInfo::HIDDEN ); - m_measurementKinds.xmlCapability()->disableIO(); + CAF_PDM_InitFieldNoDefault( &m_measurementsInView, "MeasurementKinds", "Measurement Kinds", "", "", "" ); + m_measurementsInView.uiCapability()->setUiHidden( true ); this->setName( "Well Measurements" ); } @@ -62,18 +54,31 @@ RimWellMeasurementInViewCollection::RimWellMeasurementInViewCollection() //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -RimWellMeasurementInViewCollection::~RimWellMeasurementInViewCollection() +RimWellMeasurementInViewCollection::~RimWellMeasurementInViewCollection() {} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +std::vector RimWellMeasurementInViewCollection::measurements() const { - delete m_legendConfig; + std::vector attrs; + + for ( auto attr : m_measurementsInView ) + { + attrs.push_back( attr.p() ); + } + return attrs; } +//-------------------------------------------------------------------------------------------------- + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- void RimWellMeasurementInViewCollection::defineUiTreeOrdering( caf::PdmUiTreeOrdering& uiTreeOrdering, QString uiConfigName /*= ""*/ ) { - uiTreeOrdering.add( &m_legendConfig ); + uiTreeOrdering.add( &m_measurementsInView ); uiTreeOrdering.skipRemainingChildren( true ); } @@ -84,7 +89,6 @@ void RimWellMeasurementInViewCollection::fieldChangedByUi( const caf::PdmFieldHa const QVariant& oldValue, const QVariant& newValue ) { - updateLegendData(); RimGridView* rimGridView = nullptr; this->firstAncestorOrThisOfTypeAsserted( rimGridView ); rimGridView->scheduleCreateDisplayModelAndRedraw(); @@ -93,103 +97,25 @@ void RimWellMeasurementInViewCollection::fieldChangedByUi( const caf::PdmFieldHa //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -RimRegularLegendConfig* RimWellMeasurementInViewCollection::legendConfig() -{ - return m_legendConfig; -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -bool RimWellMeasurementInViewCollection::updateLegendData() +void RimWellMeasurementInViewCollection::initAfterRead() { + // TODO: Need a better solution for this!!! RimWellPathCollection* wellPathCollection = RimTools::wellPathCollection(); - if ( !wellPathCollection ) return false; - - RimWellMeasurementCollection* wellMeasurementCollection = wellPathCollection->measurementCollection(); - if ( !wellMeasurementCollection ) return false; - - std::vector selectedMeasurementKinds = measurementKinds(); - - // Only show legend when only one measurement is selected - if ( selectedMeasurementKinds.size() == 1 ) + if ( wellPathCollection ) { - std::vector wellMeasurements = - RimWellMeasurementFilter::filterMeasurements( wellMeasurementCollection->measurements(), - selectedMeasurementKinds ); - - double minValue = HUGE_VAL; - double maxValue = -HUGE_VAL; - double posClosestToZero = HUGE_VAL; - double negClosestToZero = -HUGE_VAL; - - for ( auto& measurement : wellMeasurements ) + const RimWellMeasurementCollection* measurementCollection = wellPathCollection->measurementCollection(); + std::set measurementKinds; + for ( RimWellMeasurement* wellMeasurement : measurementCollection->measurements() ) { - minValue = std::min( measurement->value(), minValue ); - maxValue = std::max( measurement->value(), maxValue ); + measurementKinds.insert( wellMeasurement->kind() ); } - if ( minValue != HUGE_VAL ) + for ( QString kind : measurementKinds ) { - m_legendConfig->setTitle( QString( "Well Measurement: \n" ) + selectedMeasurementKinds[0] ); - m_legendConfig->setAutomaticRanges( minValue, maxValue, minValue, maxValue ); - m_legendConfig->setClosestToZeroValues( posClosestToZero, negClosestToZero, posClosestToZero, negClosestToZero ); - return true; + RimWellMeasurementInView* measurementInView = new RimWellMeasurementInView; + measurementInView->setName( kind ); + measurementInView->setMeasurementKind( kind ); + m_measurementsInView.push_back( measurementInView ); } } - - return false; -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -void RimWellMeasurementInViewCollection::updateLegendRangesTextAndVisibility( RiuViewer* nativeOrOverrideViewer, - bool isUsingOverrideViewer ) -{ - bool addToViewer = updateLegendData(); - if ( addToViewer ) - { - nativeOrOverrideViewer->addColorLegendToBottomLeftCorner( m_legendConfig->titledOverlayFrame(), - isUsingOverrideViewer ); - } -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -QList - RimWellMeasurementInViewCollection::calculateValueOptions( const caf::PdmFieldHandle* fieldNeedingOptions, - bool* useOptionsOnly ) -{ - QList options; - if ( fieldNeedingOptions == &m_measurementKinds ) - { - RimWellPathCollection* wellPathCollection = RimTools::wellPathCollection(); - if ( wellPathCollection ) - { - std::vector measurements = wellPathCollection->measurementCollection()->measurements(); - - std::set measurementKindsInData; - for ( auto measurement : measurements ) - { - measurementKindsInData.insert( measurement->kind() ); - } - - for ( auto measurementKind : measurementKindsInData ) - { - options.push_back( caf::PdmOptionItemInfo( measurementKind, measurementKind ) ); - } - } - } - - return options; -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -std::vector RimWellMeasurementInViewCollection::measurementKinds() const -{ - return m_measurementKinds; } diff --git a/ApplicationCode/ProjectDataModel/RimWellMeasurementInViewCollection.h b/ApplicationCode/ProjectDataModel/RimWellMeasurementInViewCollection.h index 6468d5f6f0..01c2d9f6ac 100644 --- a/ApplicationCode/ProjectDataModel/RimWellMeasurementInViewCollection.h +++ b/ApplicationCode/ProjectDataModel/RimWellMeasurementInViewCollection.h @@ -20,16 +20,10 @@ #include "RimCheckableNamedObject.h" #include "cafPdmChildArrayField.h" -#include "cafPdmChildField.h" -#include "cafPdmField.h" -#include "cafPdmObject.h" -#include "cafPdmProxyValueField.h" #include -class RimWellMeasurement; -class RimRegularLegendConfig; -class RiuViewer; +class RimWellMeasurementInView; class RimWellMeasurementInViewCollection : public RimCheckableNamedObject { @@ -39,22 +33,15 @@ public: RimWellMeasurementInViewCollection(); ~RimWellMeasurementInViewCollection() override; - RimRegularLegendConfig* legendConfig(); - std::vector measurementKinds() const; - - void updateLegendRangesTextAndVisibility( RiuViewer* nativeOrOverrideViewer, bool isUsingOverrideViewer ); + std::vector measurements() const; protected: void defineUiTreeOrdering( caf::PdmUiTreeOrdering& uiTreeOrdering, QString uiConfigName = "" ) override; void fieldChangedByUi( const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue ) override; - QList calculateValueOptions( const caf::PdmFieldHandle* fieldNeedingOptions, - bool* useOptionsOnly ); - - bool updateLegendData(); + void initAfterRead(); private: - caf::PdmChildField m_legendConfig; - caf::PdmField> m_measurementKinds; + caf::PdmChildArrayField m_measurementsInView; };