Files
ResInsight/ApplicationLibCode/ProjectDataModel/Completions/RimValveCollection.cpp
T
Magne Sjaastad 211ae24241 Auto-update MSW segments on UI changes (opt-in)
Adds an 'Auto Update Segments' toggle (default: on) to the MSW Segment
Visualization group in WellPathCollection. When enabled, MSW segments
are automatically recomputed and redrawn whenever the user modifies:
- Well path geometry or targets
- Perforation intervals
- Fishbone laterals
- Fractures
- Well path fields

The update is triggered via a new updateMswSegmentsForObject()
method, which resolves the top-level well from the changed object, clears
existing segments for all lateral wells in that group, recomputes segments
using updateSegments(), and schedules a full redraw.

When auto-update is disabled, an 'Update Segments' button is shown
instead, allowing manual control.
2026-03-17 20:15:07 +01:00

170 lines
5.9 KiB
C++

/////////////////////////////////////////////////////////////////////////////////
//
// 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 "RimValveCollection.h"
#include "WellPath/RimWellPathCollection.h"
#include "RimProject.h"
#include "RimValveTemplate.h"
#include "RimValveTemplateCollection.h"
#include "RimWellPathValve.h"
#include "Riu3DMainWindowTools.h"
#include "cafPdmFieldScriptingCapability.h"
#include "cafPdmObjectScriptingCapability.h"
CAF_PDM_SOURCE_INIT( RimValveCollection, "ValveCollection" );
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimValveCollection::RimValveCollection()
{
CAF_PDM_InitScriptableObject( "Valves", ":/ICVValve16x16.png" );
nameField()->uiCapability()->setUiHidden( true );
setName( "Valves" );
CAF_PDM_InitScriptableFieldNoDefault( &m_valves, "Valves", "Valves" );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimValveCollection::initAfterRead()
{
for ( auto& valve : m_valves() )
{
valve->setComponentTypeFilter( { RiaDefines::WellPathComponentType::ICV } );
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RimValveCollection::hasValves() const
{
return !m_valves.empty();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimWellPathValve* RimValveCollection::addIcvValve( double valveMd )
{
RimWellPathValve* valve = new RimWellPathValve();
auto templateCollections = RimProject::current()->allValveTemplateCollections();
if ( templateCollections.empty() ) return nullptr;
auto tempColl = templateCollections.front();
auto icvTemplate = tempColl->getOrCreateIcvTemplate();
valve->setValveTemplate( icvTemplate );
m_valves.push_back( valve );
valve->setComponentTypeFilter( { RiaDefines::WellPathComponentType::ICV } );
valve->setMeasuredDepthAndCount( valveMd, 1.0, 1 );
return valve;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::vector<RimWellPathValve*> RimValveCollection::valves() const
{
std::vector<RimWellPathValve*> valvesToReturn;
for ( const auto& v : m_valves() )
{
valvesToReturn.push_back( v );
}
return valvesToReturn;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::vector<RimWellPathValve*> RimValveCollection::activeValves() const
{
std::vector<RimWellPathValve*> valvesToReturn;
if ( !isChecked() ) return valvesToReturn;
for ( const auto& v : m_valves() )
{
if ( v->isChecked() )
{
valvesToReturn.push_back( v );
}
}
return valvesToReturn;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimValveCollection::defineUiOrdering( QString uiConfigName, caf::PdmUiOrdering& uiOrdering )
{
uiOrdering.skipRemainingFields( true );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimValveCollection::fieldChangedByUi( const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue )
{
RimProject* proj = RimProject::current();
if ( changedField == &m_isChecked )
{
proj->reloadCompletionTypeResultsInAllViews();
}
else
{
proj->scheduleCreateDisplayModelAndRedrawAllViews();
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimValveCollection::childFieldChangedByUi( const caf::PdmFieldHandle* changedChildField )
{
if ( auto wellPathCollection = RimWellPathCollection::instance() )
{
wellPathCollection->updateMswSegmentsForObject( this );
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimValveCollection::onChildDeleted( caf::PdmChildArrayFieldHandle* childArray, std::vector<caf::PdmObjectHandle*>& referringObjects )
{
RimProject* proj = RimProject::current();
proj->reloadCompletionTypeResultsInAllViews();
updateConnectedEditors();
}