|
| 1 | +///////////////////////////////////////////////////////////////////////////////// |
| 2 | +// |
| 3 | +// Copyright (C) 2026- Equinor ASA |
| 4 | +// |
| 5 | +// ResInsight is free software: you can redistribute it and/or modify |
| 6 | +// it under the terms of the GNU General Public License as published by |
| 7 | +// the Free Software Foundation, either version 3 of the License, or |
| 8 | +// (at your option) any later version. |
| 9 | +// |
| 10 | +// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY |
| 11 | +// WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 12 | +// FITNESS FOR A PARTICULAR PURPOSE. |
| 13 | +// |
| 14 | +// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html> |
| 15 | +// for more details. |
| 16 | +// |
| 17 | +///////////////////////////////////////////////////////////////////////////////// |
| 18 | + |
| 19 | +#include "RimFaultDistanceResult.h" |
| 20 | + |
| 21 | +#include "RiaDefines.h" |
| 22 | + |
| 23 | +#include "RigCaseCellResultsData.h" |
| 24 | +#include "RigEclipseCaseData.h" |
| 25 | +#include "RigEclipseResultAddress.h" |
| 26 | +#include "RigFault.h" |
| 27 | +#include "RigSelectedFaultDistanceResultCalculator.h" |
| 28 | + |
| 29 | +#include "RimEclipseCase.h" |
| 30 | +#include "RimEclipseView.h" |
| 31 | +#include "RimFaultInView.h" |
| 32 | +#include "RimFaultInViewCollection.h" |
| 33 | + |
| 34 | +#include "cafPdmUiTreeSelectionEditor.h" |
| 35 | + |
| 36 | +CAF_PDM_SOURCE_INIT( RimFaultDistanceResult, "RimFaultDistanceResult" ); |
| 37 | + |
| 38 | +//-------------------------------------------------------------------------------------------------- |
| 39 | +/// |
| 40 | +//-------------------------------------------------------------------------------------------------- |
| 41 | +RimFaultDistanceResult::RimFaultDistanceResult() |
| 42 | +{ |
| 43 | + CAF_PDM_InitObject( "Fault Distance Result", ":/draw_style_faults_24x24.png" ); |
| 44 | + |
| 45 | + CAF_PDM_InitFieldNoDefault( &m_resultName, "ResultName", "Name" ); |
| 46 | + |
| 47 | + CAF_PDM_InitFieldNoDefault( &m_faults, "SelectedFaults", "Faults" ); |
| 48 | + m_faults.uiCapability()->setUiEditorTypeName( caf::PdmUiTreeSelectionEditor::uiEditorTypeName() ); |
| 49 | +} |
| 50 | + |
| 51 | +//-------------------------------------------------------------------------------------------------- |
| 52 | +/// |
| 53 | +//-------------------------------------------------------------------------------------------------- |
| 54 | +QString RimFaultDistanceResult::resultName() const |
| 55 | +{ |
| 56 | + return m_resultName(); |
| 57 | +} |
| 58 | + |
| 59 | +//-------------------------------------------------------------------------------------------------- |
| 60 | +/// |
| 61 | +//-------------------------------------------------------------------------------------------------- |
| 62 | +void RimFaultDistanceResult::setResultName( const QString& name ) |
| 63 | +{ |
| 64 | + m_resultName = name; |
| 65 | +} |
| 66 | + |
| 67 | +//-------------------------------------------------------------------------------------------------- |
| 68 | +/// |
| 69 | +//-------------------------------------------------------------------------------------------------- |
| 70 | +void RimFaultDistanceResult::setSelectedFaults( const std::vector<RimFaultInView*>& faults ) |
| 71 | +{ |
| 72 | + m_faults.setValue( faults ); |
| 73 | + compute(); |
| 74 | +} |
| 75 | + |
| 76 | +//-------------------------------------------------------------------------------------------------- |
| 77 | +/// |
| 78 | +//-------------------------------------------------------------------------------------------------- |
| 79 | +std::vector<const RigFault*> RimFaultDistanceResult::selectedRigFaults() const |
| 80 | +{ |
| 81 | + std::vector<const RigFault*> rigFaults; |
| 82 | + for ( RimFaultInView* fault : m_faults ) |
| 83 | + { |
| 84 | + if ( fault && fault->faultGeometry() ) rigFaults.push_back( fault->faultGeometry() ); |
| 85 | + } |
| 86 | + return rigFaults; |
| 87 | +} |
| 88 | + |
| 89 | +//-------------------------------------------------------------------------------------------------- |
| 90 | +/// |
| 91 | +//-------------------------------------------------------------------------------------------------- |
| 92 | +void RimFaultDistanceResult::compute() |
| 93 | +{ |
| 94 | + if ( m_resultName().isEmpty() ) return; |
| 95 | + |
| 96 | + auto eclipseView = firstAncestorOrThisOfType<RimEclipseView>(); |
| 97 | + if ( !eclipseView ) return; |
| 98 | + |
| 99 | + RimEclipseCase* eclipseCase = eclipseView->eclipseCase(); |
| 100 | + if ( !eclipseCase ) return; |
| 101 | + |
| 102 | + RigEclipseCaseData* caseData = eclipseCase->eclipseCaseData(); |
| 103 | + if ( !caseData ) return; |
| 104 | + |
| 105 | + RigSelectedFaultDistanceResultCalculator::compute( caseData, m_resultName(), selectedRigFaults() ); |
| 106 | + |
| 107 | + eclipseView->scheduleCreateDisplayModelAndRedraw(); |
| 108 | +} |
| 109 | + |
| 110 | +//-------------------------------------------------------------------------------------------------- |
| 111 | +/// |
| 112 | +//-------------------------------------------------------------------------------------------------- |
| 113 | +void RimFaultDistanceResult::fieldChangedByUi( const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue ) |
| 114 | +{ |
| 115 | + if ( changedField == &m_resultName ) |
| 116 | + { |
| 117 | + const QString previousName = oldValue.toString(); |
| 118 | + if ( !previousName.isEmpty() && previousName != m_resultName() ) |
| 119 | + { |
| 120 | + removeGeneratedResult( previousName ); |
| 121 | + } |
| 122 | + compute(); |
| 123 | + } |
| 124 | + else if ( changedField == &m_faults ) |
| 125 | + { |
| 126 | + compute(); |
| 127 | + } |
| 128 | +} |
| 129 | + |
| 130 | +//-------------------------------------------------------------------------------------------------- |
| 131 | +/// |
| 132 | +//-------------------------------------------------------------------------------------------------- |
| 133 | +QList<caf::PdmOptionItemInfo> RimFaultDistanceResult::calculateValueOptions( const caf::PdmFieldHandle* fieldNeedingOptions ) |
| 134 | +{ |
| 135 | + QList<caf::PdmOptionItemInfo> options; |
| 136 | + |
| 137 | + if ( fieldNeedingOptions == &m_faults ) |
| 138 | + { |
| 139 | + auto faultCollection = firstAncestorOrThisOfType<RimFaultInViewCollection>(); |
| 140 | + if ( faultCollection ) |
| 141 | + { |
| 142 | + for ( RimFaultInView* fault : faultCollection->faults() ) |
| 143 | + { |
| 144 | + if ( fault ) options.push_back( caf::PdmOptionItemInfo( fault->name(), fault ) ); |
| 145 | + } |
| 146 | + } |
| 147 | + } |
| 148 | + |
| 149 | + return options; |
| 150 | +} |
| 151 | + |
| 152 | +//-------------------------------------------------------------------------------------------------- |
| 153 | +/// |
| 154 | +//-------------------------------------------------------------------------------------------------- |
| 155 | +caf::PdmFieldHandle* RimFaultDistanceResult::userDescriptionField() |
| 156 | +{ |
| 157 | + return &m_resultName; |
| 158 | +} |
| 159 | + |
| 160 | +//-------------------------------------------------------------------------------------------------- |
| 161 | +/// |
| 162 | +//-------------------------------------------------------------------------------------------------- |
| 163 | +void RimFaultDistanceResult::defineUiOrdering( QString uiConfigName, caf::PdmUiOrdering& uiOrdering ) |
| 164 | +{ |
| 165 | + uiOrdering.add( &m_resultName ); |
| 166 | + uiOrdering.add( &m_faults ); |
| 167 | + uiOrdering.skipRemainingFields( true ); |
| 168 | +} |
| 169 | + |
| 170 | +//-------------------------------------------------------------------------------------------------- |
| 171 | +/// |
| 172 | +//-------------------------------------------------------------------------------------------------- |
| 173 | +void RimFaultDistanceResult::removeGeneratedResult( const QString& name ) |
| 174 | +{ |
| 175 | + if ( name.isEmpty() ) return; |
| 176 | + |
| 177 | + auto eclipseView = firstAncestorOrThisOfType<RimEclipseView>(); |
| 178 | + if ( !eclipseView ) return; |
| 179 | + |
| 180 | + RimEclipseCase* eclipseCase = eclipseView->eclipseCase(); |
| 181 | + if ( !eclipseCase ) return; |
| 182 | + |
| 183 | + RigEclipseCaseData* caseData = eclipseCase->eclipseCaseData(); |
| 184 | + if ( !caseData ) return; |
| 185 | + |
| 186 | + RigCaseCellResultsData* resultsData = caseData->results( RiaDefines::PorosityModelType::MATRIX_MODEL ); |
| 187 | + if ( !resultsData ) return; |
| 188 | + |
| 189 | + resultsData->clearScalarResult( RiaDefines::ResultCatType::GENERATED, name ); |
| 190 | +} |
0 commit comments