Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ set(SOURCE_GROUP_SOURCE_FILES
${CMAKE_CURRENT_LIST_DIR}/RicEclipsePropertyFilterNewInViewFeature.cpp
${CMAKE_CURRENT_LIST_DIR}/RicEclipseHideFaultFeature.cpp
${CMAKE_CURRENT_LIST_DIR}/RicEclipseShowOnlyFaultFeature.cpp
${CMAKE_CURRENT_LIST_DIR}/RicNewFaultDistanceResultFeature.cpp
${CMAKE_CURRENT_LIST_DIR}/RicRenameCaseFeature.cpp
${CMAKE_CURRENT_LIST_DIR}/RicImportRoffCaseFeature.cpp
${CMAKE_CURRENT_LIST_DIR}/RicAddGridCalculationFeature.cpp
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2026- 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 <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////

#include "RicNewFaultDistanceResultFeature.h"

#include "RimFaultDistanceResult.h"
#include "RimFaultDistanceResultCollection.h"
#include "RimFaultInView.h"
#include "RimFaultInViewCollection.h"

#include "Riu3DMainWindowTools.h"

#include "cafSelectionManager.h"

#include <QAction>

CAF_CMD_SOURCE_INIT( RicNewFaultDistanceResultFeature, "RicNewFaultDistanceResultFeature" );

namespace
{
RimFaultInViewCollection* findHostCollection()
{
const auto faultCollections = caf::SelectionManager::instance()->objectsByType<RimFaultInViewCollection>();
if ( !faultCollections.empty() ) return faultCollections.front();

const auto distanceCollections = caf::SelectionManager::instance()->objectsByType<RimFaultDistanceResultCollection>();
if ( !distanceCollections.empty() )
{
return distanceCollections.front()->firstAncestorOrThisOfType<RimFaultInViewCollection>();
}

const auto distanceResults = caf::SelectionManager::instance()->objectsByType<RimFaultDistanceResult>();
if ( !distanceResults.empty() )
{
return distanceResults.front()->firstAncestorOrThisOfType<RimFaultInViewCollection>();
}

const auto faults = caf::SelectionManager::instance()->objectsByType<RimFaultInView>();
if ( !faults.empty() )
{
return faults.front()->firstAncestorOrThisOfType<RimFaultInViewCollection>();
}

return nullptr;
}
} // namespace

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RicNewFaultDistanceResultFeature::isCommandEnabled() const
{
return findHostCollection() != nullptr;
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicNewFaultDistanceResultFeature::onActionTriggered( bool isChecked )
{
RimFaultInViewCollection* hostCollection = findHostCollection();
if ( !hostCollection ) return;

RimFaultDistanceResultCollection* distanceCollection = hostCollection->faultDistanceResults();
if ( !distanceCollection ) return;

const auto selectedFaultPointers = caf::SelectionManager::instance()->objectsByType<RimFaultInView>();
std::vector<RimFaultInView*> selectedFaults( selectedFaultPointers.begin(), selectedFaultPointers.end() );

RimFaultDistanceResult* newResult = distanceCollection->addResult();
if ( !newResult ) return;

if ( !selectedFaults.empty() )
{
newResult->setSelectedFaults( selectedFaults );
}
else
{
newResult->setSelectedFaults( hostCollection->faults() );
}

hostCollection->updateConnectedEditors();
distanceCollection->updateConnectedEditors();
Riu3DMainWindowTools::selectAsCurrentItem( newResult );
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicNewFaultDistanceResultFeature::setupActionLook( QAction* actionToSetup )
{
actionToSetup->setText( "New Fault Distance Result" );
actionToSetup->setIcon( QIcon( ":/draw_style_faults_24x24.png" ) );
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2026- 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 <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////

#pragma once

#include "cafCmdFeature.h"

//==================================================================================================
///
//==================================================================================================
class RicNewFaultDistanceResultFeature : public caf::CmdFeature
{
CAF_CMD_HEADER_INIT;

protected:
bool isCommandEnabled() const override;
void onActionTriggered( bool isChecked ) override;
void setupActionLook( QAction* actionToSetup ) override;
};
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
set(SOURCE_GROUP_SOURCE_FILES
${CMAKE_CURRENT_LIST_DIR}/RimFaultDistanceResult.cpp
${CMAKE_CURRENT_LIST_DIR}/RimFaultDistanceResultCollection.cpp
${CMAKE_CURRENT_LIST_DIR}/RimFaultInView.cpp
${CMAKE_CURRENT_LIST_DIR}/RimFaultInViewCollection.cpp
${CMAKE_CURRENT_LIST_DIR}/RimFaultReactivationModel.cpp
Expand Down
197 changes: 197 additions & 0 deletions ApplicationLibCode/ProjectDataModel/Faults/RimFaultDistanceResult.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,197 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2026- 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 <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////

#include "RimFaultDistanceResult.h"

#include "RiaDefines.h"

#include "RigCaseCellResultsData.h"
#include "RigEclipseCaseData.h"
#include "RigEclipseResultAddress.h"
#include "RigFault.h"
#include "RigSelectedFaultDistanceResultCalculator.h"

#include "RimEclipseCase.h"
#include "RimEclipseView.h"
#include "RimFaultInView.h"
#include "RimFaultInViewCollection.h"

#include "cafPdmFieldScriptingCapability.h"
#include "cafPdmObjectScriptingCapability.h"
#include "cafPdmUiTreeSelectionEditor.h"

CAF_PDM_SOURCE_INIT( RimFaultDistanceResult, "RimFaultDistanceResult" );

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimFaultDistanceResult::RimFaultDistanceResult()
{
CAF_PDM_InitScriptableObjectWithNameAndComment( "Fault Distance Result",
":/draw_style_faults_24x24.png",
"",
"",
"FaultDistanceResult",
"Per-cell distance to a selected subset of faults" );

CAF_PDM_InitScriptableFieldNoDefault( &m_resultName, "ResultName", "Name" );

CAF_PDM_InitScriptableFieldNoDefault( &m_faults, "SelectedFaults", "Faults" );
m_faults.uiCapability()->setUiEditorTypeName( caf::PdmUiTreeSelectionEditor::uiEditorTypeName() );
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QString RimFaultDistanceResult::resultName() const
{
return m_resultName();
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimFaultDistanceResult::setResultName( const QString& name )
{
m_resultName = name;
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimFaultDistanceResult::setSelectedFaults( const std::vector<RimFaultInView*>& faults )
{
m_faults.setValue( faults );
compute();
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::vector<const RigFault*> RimFaultDistanceResult::selectedRigFaults() const
{
std::vector<const RigFault*> rigFaults;
for ( RimFaultInView* fault : m_faults )
{
if ( fault && fault->faultGeometry() ) rigFaults.push_back( fault->faultGeometry() );
}
return rigFaults;
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimFaultDistanceResult::compute()
{
if ( m_resultName().isEmpty() ) return;

auto eclipseView = firstAncestorOrThisOfType<RimEclipseView>();
if ( !eclipseView ) return;

RimEclipseCase* eclipseCase = eclipseView->eclipseCase();
if ( !eclipseCase ) return;

RigEclipseCaseData* caseData = eclipseCase->eclipseCaseData();
if ( !caseData ) return;

RigSelectedFaultDistanceResultCalculator::compute( caseData, m_resultName(), selectedRigFaults() );

eclipseView->scheduleCreateDisplayModelAndRedraw();
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimFaultDistanceResult::fieldChangedByUi( const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue )
{
if ( changedField == &m_resultName )
{
const QString previousName = oldValue.toString();
if ( !previousName.isEmpty() && previousName != m_resultName() )
{
removeGeneratedResult( previousName );
}
compute();
}
else if ( changedField == &m_faults )
{
compute();
}
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QList<caf::PdmOptionItemInfo> RimFaultDistanceResult::calculateValueOptions( const caf::PdmFieldHandle* fieldNeedingOptions )
{
QList<caf::PdmOptionItemInfo> options;

if ( fieldNeedingOptions == &m_faults )
{
auto faultCollection = firstAncestorOrThisOfType<RimFaultInViewCollection>();
if ( faultCollection )
{
for ( RimFaultInView* fault : faultCollection->faults() )
{
if ( fault ) options.push_back( caf::PdmOptionItemInfo( fault->name(), fault ) );
}
}
}

return options;
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
caf::PdmFieldHandle* RimFaultDistanceResult::userDescriptionField()
{
return &m_resultName;
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimFaultDistanceResult::defineUiOrdering( QString uiConfigName, caf::PdmUiOrdering& uiOrdering )
{
uiOrdering.add( &m_resultName );
uiOrdering.add( &m_faults );
uiOrdering.skipRemainingFields( true );
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimFaultDistanceResult::removeGeneratedResult( const QString& name )
{
if ( name.isEmpty() ) return;

auto eclipseView = firstAncestorOrThisOfType<RimEclipseView>();
if ( !eclipseView ) return;

RimEclipseCase* eclipseCase = eclipseView->eclipseCase();
if ( !eclipseCase ) return;

RigEclipseCaseData* caseData = eclipseCase->eclipseCaseData();
if ( !caseData ) return;

RigCaseCellResultsData* resultsData = caseData->results( RiaDefines::PorosityModelType::MATRIX_MODEL );
if ( !resultsData ) return;

resultsData->clearScalarResult( RiaDefines::ResultCatType::GENERATED, name );
}
Loading
Loading