#7656 Well Group: Simplify organization of well groups

This commit is contained in:
Magne Sjaastad 2021-05-10 15:12:29 +02:00
parent 5c1b08a05b
commit 1daa598770
15 changed files with 670 additions and 296 deletions

View File

@ -64,7 +64,10 @@ caf::PdmScriptResponse RicAutomaticWellPathGrouping::execute()
if ( oilField )
{
oilField->wellPathCollection->groupWellPaths( wellPaths, true );
// oilField->wellPathCollection->groupWellPaths( wellPaths, true );
oilField->wellPathCollection->rebuildWellPathNodes();
return caf::PdmScriptResponse();
}
}

View File

@ -32,7 +32,6 @@ RicImportGroupedWellPaths::RicImportGroupedWellPaths()
//--------------------------------------------------------------------------------------------------
void RicImportGroupedWellPaths::onActionTriggered( bool isChecked )
{
// Open dialog box to select well path files
RiaApplication* app = RiaApplication::instance();
QString lastUsedGridFolder = app->lastUsedDialogDirectory( "BINARY_GRID" );
QString defaultDir = app->lastUsedDialogDirectoryWithFallback( "WELLPATH_DIR", lastUsedGridFolder );
@ -44,7 +43,7 @@ void RicImportGroupedWellPaths::onActionTriggered( bool isChecked )
defaultDir,
nameList );
if ( wellPathFilePaths.size() >= 1 )
if ( !wellPathFilePaths.empty() )
{
m_importGrouped = true;
m_wellPathFiles.v() = std::vector<QString>( wellPathFilePaths.begin(), wellPathFilePaths.end() );

View File

@ -33,7 +33,6 @@ public:
RicImportGroupedWellPaths();
protected:
// Overrides
void onActionTriggered( bool isChecked ) override;
void setupActionLook( QAction* actionToSetup ) override;
};

View File

@ -69,6 +69,9 @@ RicImportWellPaths::RicImportWellPaths()
CAF_PDM_InitScriptableField( &m_importGrouped, "importGrouped", false, "", "", "", "" );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
caf::PdmScriptResponse RicImportWellPaths::execute()
{
QStringList errorMessages, warningMessages;
@ -91,7 +94,7 @@ caf::PdmScriptResponse RicImportWellPaths::execute()
QStringList nameFilters;
nameFilters << RicImportWellPaths::wellPathNameFilters();
QStringList relativePaths = wellPathDir.entryList( nameFilters, QDir::Files | QDir::NoDotAndDotDot );
for ( QString relativePath : relativePaths )
for ( const QString& relativePath : relativePaths )
{
wellPathFiles.push_back( wellPathDir.absoluteFilePath( relativePath ) );
}
@ -102,7 +105,7 @@ caf::PdmScriptResponse RicImportWellPaths::execute()
}
}
for ( QString wellPathFile : m_wellPathFiles() )
for ( const QString& wellPathFile : m_wellPathFiles() )
{
if ( QFileInfo::exists( wellPathFile ) )
{
@ -138,12 +141,12 @@ caf::PdmScriptResponse RicImportWellPaths::execute()
warningMessages << "No well paths found";
}
for ( QString warningMessage : warningMessages )
for ( const QString& warningMessage : warningMessages )
{
response.updateStatus( caf::PdmScriptResponse::COMMAND_WARNING, warningMessage );
}
for ( QString errorMessage : errorMessages )
for ( const QString& errorMessage : errorMessages )
{
response.updateStatus( caf::PdmScriptResponse::COMMAND_ERROR, errorMessage );
}
@ -172,7 +175,7 @@ std::vector<RimWellPath*> RicImportWellPaths::importWellPaths( const QStringList
project->scheduleCreateDisplayModelAndRedrawAllViews();
RimOilField* oilField = project->activeOilField();
if ( oilField && oilField->wellPathCollection->topLevelWellPaths().size() > 0 )
if ( oilField && !oilField->wellPathCollection->topLevelWellPaths().empty() )
{
RimWellPath* wellPath = oilField->wellPathCollection->mostRecentlyUpdatedWellPath();
if ( wellPath )
@ -223,7 +226,7 @@ void RicImportWellPaths::onActionTriggered( bool isChecked )
defaultDir,
nameList );
if ( wellPathFilePaths.size() >= 1 )
if ( !wellPathFilePaths.empty() )
{
m_wellPathFiles.v() = std::vector<QString>( wellPathFilePaths.begin(), wellPathFilePaths.end() );
caf::PdmScriptResponse response = execute();

View File

@ -19,7 +19,7 @@
#pragma once
#include "CommandFileInterface/Core/RicfCommandObject.h"
#include "RicfCommandObject.h"
#include "cafCmdFeature.h"
#include "cafPdmField.h"
@ -47,7 +47,6 @@ protected:
importWellPaths( const QStringList& wellPathFilePaths, bool importGrouped, QStringList* errorMessages );
static QStringList wellPathNameFilters();
// Overrides
bool isCommandEnabled() override;
void onActionTriggered( bool isChecked ) override;
void setupActionLook( QAction* actionToSetup ) override;

View File

@ -65,12 +65,12 @@ caf::PdmScriptResponse RicToggleWellPathGrouping::execute()
{
if ( m_groupWellPaths() )
{
oilField->wellPathCollection->groupWellPaths( wellPaths );
// oilField->wellPathCollection->groupWellPaths( wellPaths );
return caf::PdmScriptResponse();
}
else
{
oilField->wellPathCollection->ungroupWellPaths( wellPaths );
// oilField->wellPathCollection->ungroupWellPaths( wellPaths );
return caf::PdmScriptResponse();
}
}

View File

@ -153,6 +153,7 @@ ${CMAKE_CURRENT_LIST_DIR}/RimEquilibriumAxisAnnotation.h
${CMAKE_CURRENT_LIST_DIR}/RimTimeAxisAnnotation.h
${CMAKE_CURRENT_LIST_DIR}/RimPolylinesDataInterface.h
${CMAKE_CURRENT_LIST_DIR}/RimWellPathTieIn.h
${CMAKE_CURRENT_LIST_DIR}/cafTreeNode.h
)
@ -306,6 +307,7 @@ ${CMAKE_CURRENT_LIST_DIR}/RimCustomObjectiveFunctionWeight.cpp
${CMAKE_CURRENT_LIST_DIR}/RimEquilibriumAxisAnnotation.cpp
${CMAKE_CURRENT_LIST_DIR}/RimTimeAxisAnnotation.cpp
${CMAKE_CURRENT_LIST_DIR}/RimWellPathTieIn.cpp
${CMAKE_CURRENT_LIST_DIR}/cafTreeNode.cpp
)
if(Qt5Charts_FOUND)

View File

@ -57,6 +57,7 @@
#include "cafPdmFieldScriptingCapability.h"
#include "cafPdmUiTreeOrdering.h"
#include "cafPdmUiTreeViewEditor.h"
#include "cafUtils.h"
#include <QDateTime>
@ -134,6 +135,8 @@ RimWellPath::RimWellPath()
m_wellPathAttributes->uiCapability()->setUiTreeHidden( true );
CAF_PDM_InitFieldNoDefault( &m_wellPathTieIn, "WellPathTieIn", "well Path Tie-In", "", "", "" );
m_wellPathTieIn = new RimWellPathTieIn;
m_wellPathTieIn->connectWellPaths( nullptr, this, 0.0 );
this->setDeletable( true );
}
@ -757,6 +760,21 @@ void RimWellPath::copyCompletionSettings( RimWellPath* from, RimWellPath* to )
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimWellPath::defineObjectEditorAttribute( QString uiConfigName, caf::PdmUiEditorAttribute* attribute )
{
auto myAttr = dynamic_cast<caf::PdmUiTreeViewEditorAttribute*>( attribute );
if ( myAttr )
{
// The nodes for well paths are created by the well path collection object. When a well path object is asked to
// be updated in the project tree, always rebuild the tree from the well path collection object.
myAttr->objectForUpdateOfUiTree = RimTools::wellPathCollection();
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@ -774,20 +792,6 @@ size_t RimWellPath::simulationWellBranchCount( const QString& simWellName )
//--------------------------------------------------------------------------------------------------
void RimWellPath::updateFilePathsFromProjectPath( const QString& newProjectPath, const QString& oldProjectPath )
{
//{
// bool foundFile = false;
// std::vector<QString> searchedPaths;
//
// QString fileNameCandidate = RimTools::relocateFile( m_wellPathFormationFilePath,
// newProjectPath,
// oldProjectPath,
// &foundFile,
// &searchedPaths );
// if ( foundFile )
// {
// m_wellPathFormationFilePath = fileNameCandidate;
// }
//}
}
//--------------------------------------------------------------------------------------------------
@ -1105,6 +1109,8 @@ RimWellPath* RimWellPath::topLevelWellPath()
{
if ( m_wellPathTieIn() && m_wellPathTieIn->parentWell() )
{
if ( m_wellPathTieIn->parentWell() == this ) return this;
return m_wellPathTieIn()->parentWell()->topLevelWellPath();
}
@ -1168,8 +1174,13 @@ RimWellPathTieIn* RimWellPath::wellPathTieIn() const
//--------------------------------------------------------------------------------------------------
void RimWellPath::connectWellPaths( RimWellPath* parentWell, double parentTieInMeasuredDepth )
{
if ( !m_wellPathTieIn() ) m_wellPathTieIn = new RimWellPathTieIn;
CVF_ASSERT( parentWell != this );
m_wellPathTieIn->connectWellPaths( parentWell, this, parentTieInMeasuredDepth );
m_wellPathTieIn->updateFirstTargetFromParentWell();
if ( parentWell != this )
{
if ( !m_wellPathTieIn() ) m_wellPathTieIn = new RimWellPathTieIn;
m_wellPathTieIn->connectWellPaths( parentWell, this, parentTieInMeasuredDepth );
m_wellPathTieIn->updateFirstTargetFromParentWell();
}
}

View File

@ -179,6 +179,7 @@ protected:
void initAfterRead() override;
void defineUiOrdering( QString uiConfigName, caf::PdmUiOrdering& uiOrdering ) override;
void defineUiTreeOrdering( caf::PdmUiTreeOrdering& uiTreeOrdering, QString uiConfigName ) override;
void defineObjectEditorAttribute( QString uiConfigName, caf::PdmUiEditorAttribute* attribute ) override;
static void copyCompletionSettings( RimWellPath* from, RimWellPath* to );

View File

@ -48,7 +48,9 @@
#include "RimWellMeasurementCollection.h"
#include "RimWellPath.h"
#include "RimWellPathCompletionSettings.h"
#include "RimWellPathGroup.h"
#include "RimWellPathTieIn.h"
#include "cafTreeNode.h" // TODO: Move to caf
#include "Riu3DMainWindowTools.h"
@ -109,11 +111,16 @@ RimWellPathCollection::RimWellPathCollection()
CAF_PDM_InitFieldNoDefault( &m_wellPaths, "WellPaths", "Well Paths", "", "", "" );
m_wellPaths.uiCapability()->setUiHidden( true );
m_wellPaths.uiCapability()->setUiTreeHidden( true );
m_wellPaths.uiCapability()->setUiTreeChildrenHidden( true );
CAF_PDM_InitFieldNoDefault( &m_wellMeasurements, "WellMeasurements", "Measurements", "", "", "" );
m_wellMeasurements = new RimWellMeasurementCollection;
m_wellMeasurements.uiCapability()->setUiTreeHidden( true );
CAF_PDM_InitFieldNoDefault( &m_wellPathNodes, "WellPathNodes", "Well Path Nodes", "", "", "" );
m_wellPathNodes.xmlCapability()->disableIO();
m_wellPathImporter = std::make_unique<RifWellPathImporter>();
m_wellPathFormationsImporter = std::make_unique<RifWellPathFormationsImporter>();
}
@ -135,76 +142,6 @@ void RimWellPathCollection::fieldChangedByUi( const caf::PdmFieldHandle* changed
scheduleRedrawAffectedViews();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::vector<RimWellPath*> RimWellPathCollection::detachWellPaths( const std::vector<RimWellPath*> wellPathsToDetach )
{
std::set<RimWellPath*> regularWellPathsToDetach;
std::set<RimWellPathGroup*> wellPathGroupsToRemove;
for ( auto wellPath : wellPathsToDetach )
{
std::vector<RimWellPath*> descendants;
wellPath->descendantsIncludingThisOfType( descendants );
for ( auto descendant : descendants )
{
auto group = dynamic_cast<RimWellPathGroup*>( descendant );
if ( group )
{
wellPathGroupsToRemove.insert( group );
}
else
{
regularWellPathsToDetach.insert( descendant );
}
}
}
std::vector<RimWellPath*> detachedWellPaths;
for ( auto wellPath : regularWellPathsToDetach )
{
if ( detachWellPath( wellPath ) )
{
detachedWellPaths.push_back( wellPath );
}
}
for ( auto group : wellPathGroupsToRemove )
{
detachWellPath( group );
}
for ( auto group : wellPathGroupsToRemove )
{
delete group;
}
return detachedWellPaths;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RimWellPathCollection::detachWellPath( gsl::not_null<RimWellPath*> wellPath )
{
if ( m_wellPaths.count( wellPath ) != 0u )
{
m_wellPaths.removeChildObject( wellPath );
return true;
}
else
{
RimWellPathGroup* group = nullptr;
wellPath->firstAncestorOfType( group );
if ( group )
{
group->removeChildWellPath( wellPath );
return true;
}
}
return false;
}
//--------------------------------------------------------------------------------------------------
/// Read files containing well path data, or create geometry based on the targets
//--------------------------------------------------------------------------------------------------
@ -262,11 +199,7 @@ void RimWellPathCollection::loadDataAndUpdate()
progress.incrementProgress();
}
for ( auto group : topLevelGroups() )
{
group->createWellPathGeometry();
group->completionSettings()->setWellNameForExport( group->createGroupName() );
}
rebuildWellPathNodes();
this->sortWellsByName();
}
@ -345,16 +278,10 @@ std::vector<RimWellPath*>
//--------------------------------------------------------------------------------------------------
void RimWellPathCollection::addWellPath( gsl::not_null<RimWellPath*> wellPath, bool importGrouped )
{
RimWellPathGroup* parentWellPathGroup = nullptr;
if ( importGrouped )
{
parentWellPathGroup = findOrCreateWellPathGroup( wellPath, allWellPaths() );
}
m_wellPaths.push_back( wellPath );
rebuildWellPathNodes();
if ( !parentWellPathGroup )
{
m_wellPaths.push_back( wellPath );
}
m_mostRecentlyUpdatedWellPath = wellPath;
}
@ -383,6 +310,7 @@ void RimWellPathCollection::readAndAddWellPaths( std::vector<RimFileWellPath*>&
{
caf::ProgressInfo progress( wellPathArray.size(), "Reading well paths from file" );
std::vector<RimWellPath*> wellPathsToGroup;
for ( size_t wpIdx = 0; wpIdx < wellPathArray.size(); wpIdx++ )
{
RimFileWellPath* wellPath = wellPathArray[wpIdx];
@ -410,14 +338,17 @@ void RimWellPathCollection::readAndAddWellPaths( std::vector<RimFileWellPath*>&
wellPath->setWellPathColor( RiaColorTables::wellPathsPaletteColors().cycledColor3f( m_wellPaths.size() ) );
wellPath->setUnitSystem( findUnitSystemForWellPath( wellPath ) );
addWellPath( wellPath, false );
wellPathsToGroup.push_back( wellPath );
}
progress.incrementProgress();
}
groupWellPaths( allWellPaths(), true );
wellPathArray.clear(); // This should not be used again. We may have deleted items
this->sortWellsByName();
groupWellPaths( wellPathsToGroup );
sortWellsByName();
rebuildWellPathNodes();
}
//--------------------------------------------------------------------------------------------------
@ -429,7 +360,10 @@ void RimWellPathCollection::addWellPaths( const std::vector<RimWellPath*> incomi
{
addWellPath( wellPath, importGrouped );
}
this->sortWellsByName();
groupWellPaths( incomingWellPaths );
sortWellsByName();
rebuildWellPathNodes();
updateAllRequiredEditors();
}
@ -549,9 +483,9 @@ void RimWellPathCollection::defineUiTreeOrdering( caf::PdmUiTreeOrdering& uiTree
uiTreeOrdering.add( &m_wellMeasurements );
}
if ( !m_wellPaths.empty() )
for ( const auto& wellPathNode : m_wellPathNodes() )
{
uiTreeOrdering.add( &m_wellPaths );
RimWellPathCollection::buildUiTreeOrdering( wellPathNode, &uiTreeOrdering, uiConfigName );
}
uiTreeOrdering.skipRemainingChildren( true );
@ -645,6 +579,7 @@ RimWellPath* RimWellPathCollection::tryFindMatchingWellPath( const QString& well
void RimWellPathCollection::deleteAllWellPaths()
{
m_wellPaths.deleteAllChildObjects();
m_wellPathNodes.deleteAllChildObjects();
m_wellPathImporter->clear();
updateAllRequiredEditors();
@ -653,90 +588,62 @@ void RimWellPathCollection::deleteAllWellPaths()
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimWellPathCollection::groupWellPaths( const std::vector<RimWellPath*>& wellPaths, bool automaticGrouping )
void RimWellPathCollection::groupWellPaths( const std::vector<RimWellPath*>& wellPaths )
{
auto detachedWellPaths = detachWellPaths( wellPaths );
auto rootWells = wellPathsForWellNameStem( wellPaths );
if ( automaticGrouping )
for ( auto [groupName, wellPathCommonName] : rootWells )
{
bool detachedGroup = true;
while ( detachedGroup )
{
detachedGroup = false;
if ( groupName == unGroupedText() ) continue;
// Detach may end up removing multiple groups, which could interfere with iteration of this loop
// So do only one and break
for ( auto wellPath : allWellPaths() )
for ( auto wellPath : wellPathCommonName )
{
auto wellPathGeometry = wellPath->wellPathGeometry();
if ( wellPathGeometry )
{
if ( dynamic_cast<RimWellPathGroup*>( wellPath ) )
const double eps = 1.0e-2;
std::map<RimWellPath*, double> wellPathsWithCommonGeometry;
for ( auto existingWellPath : wellPathCommonName )
{
auto newlyDetachedPaths = detachWellPaths( { wellPath } );
detachedWellPaths.insert( detachedWellPaths.end(), newlyDetachedPaths.begin(), newlyDetachedPaths.end() );
detachedGroup = true;
break;
if ( existingWellPath == wellPath ) continue;
if ( wellPath->name() < existingWellPath->name() ) continue;
double identicalTubeLength =
existingWellPath->wellPathGeometry()->identicalTubeLength( *wellPathGeometry );
if ( identicalTubeLength > eps )
{
wellPathsWithCommonGeometry[existingWellPath] = identicalTubeLength;
}
}
RimWellPath* mostSimilarWellPath = nullptr;
double longestIdenticalTubeLength = 0.0;
for ( auto [existingWellPath, identicalTubeLength] : wellPathsWithCommonGeometry )
{
if ( existingWellPath && ( existingWellPath != wellPath ) &&
identicalTubeLength > longestIdenticalTubeLength )
{
mostSimilarWellPath = existingWellPath;
longestIdenticalTubeLength = identicalTubeLength;
}
}
if ( mostSimilarWellPath )
{
if ( wellPath->name() > mostSimilarWellPath->name() )
{
wellPath->connectWellPaths( mostSimilarWellPath, longestIdenticalTubeLength );
}
else
{
mostSimilarWellPath->connectWellPaths( wellPath, longestIdenticalTubeLength );
}
}
}
}
}
QString multiLateralWellPathPattern = RiaPreferences::current()->multiLateralWellNamePattern();
QRegExp re( multiLateralWellPathPattern, Qt::CaseInsensitive, QRegExp::Wildcard );
std::vector<RimWellPath*> wellPathsToGroup;
for ( auto wellPath : detachedWellPaths )
{
caf::PdmObject* parent = nullptr;
wellPath->firstAncestorOfType( parent );
CAF_ASSERT( !parent );
if ( !automaticGrouping || re.exactMatch( wellPath->name() ) )
{
wellPathsToGroup.push_back( wellPath );
}
else
{
m_wellPaths.push_back( wellPath );
}
}
std::vector<RimWellPath*> wellPathsToGroupWith = wellPathsToGroup;
for ( auto wellPath : wellPathsToGroup )
{
RimWellPathGroup* parentGroup = findOrCreateWellPathGroup( wellPath, wellPathsToGroupWith );
if ( parentGroup )
{
auto groupIsNew = std::find( wellPathsToGroupWith.begin(), wellPathsToGroupWith.end(), parentGroup ) ==
wellPathsToGroupWith.end();
if ( groupIsNew )
{
wellPathsToGroupWith.push_back( parentGroup );
}
}
else if ( std::find( m_wellPaths.begin(), m_wellPaths.end(), wellPath ) == m_wellPaths.end() )
{
m_wellPaths.push_back( wellPath );
}
}
this->sortWellsByName();
this->updateAllRequiredEditors();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimWellPathCollection::ungroupWellPaths( const std::vector<RimWellPath*>& wellPaths )
{
auto detachedWellPaths = detachWellPaths( wellPaths );
for ( auto wellPath : detachedWellPaths )
{
m_wellPaths.push_back( wellPath );
}
this->sortWellsByName();
this->updateAllRequiredEditors();
}
//--------------------------------------------------------------------------------------------------
@ -792,8 +699,6 @@ void RimWellPathCollection::reloadAllWellPathFormations()
//--------------------------------------------------------------------------------------------------
void RimWellPathCollection::removeWellPath( gsl::not_null<RimWellPath*> wellPath )
{
detachWellPath( wellPath );
RimFileWellPath* fileWellPath = dynamic_cast<RimFileWellPath*>( wellPath.get() );
if ( fileWellPath )
{
@ -839,82 +744,6 @@ void RimWellPathCollection::sortWellsByName()
std::sort( m_wellPaths.begin(), m_wellPaths.end(), lessWellPath );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::vector<RimWellPathGroup*> RimWellPathCollection::topLevelGroups() const
{
std::vector<RimWellPathGroup*> groups;
for ( auto wellPath : m_wellPaths )
{
if ( auto group = dynamic_cast<RimWellPathGroup*>( wellPath.p() ); group )
{
groups.push_back( group );
}
}
return groups;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimWellPathGroup* RimWellPathCollection::findOrCreateWellPathGroup( gsl::not_null<RimWellPath*> wellPath,
const std::vector<RimWellPath*>& wellPathsToGroup )
{
RimWellPathGroup* existingParent = nullptr;
wellPath->firstAncestorOfType( existingParent );
if ( existingParent ) return existingParent;
auto wellPathGeometry = wellPath->wellPathGeometry();
if ( !wellPathGeometry ) return nullptr;
const double eps = 1.0e-2;
std::map<RimWellPath*, double> wellPathsWithCommonGeometry;
for ( auto existingWellPath : wellPathsToGroup )
{
double identicalTubeLength = existingWellPath->wellPathGeometry()->identicalTubeLength( *wellPathGeometry );
if ( identicalTubeLength > eps )
{
wellPathsWithCommonGeometry[existingWellPath] = identicalTubeLength;
}
}
// See if we have a well path group
RimWellPathGroup* mostSimilarWellPathGroup = nullptr;
double longestIdenticalTubeLength = 0.0;
for ( auto [existingWellPath, identicalTubeLength] : wellPathsWithCommonGeometry )
{
auto wellPathGroup = dynamic_cast<RimWellPathGroup*>( existingWellPath );
if ( wellPathGroup && identicalTubeLength > longestIdenticalTubeLength )
{
mostSimilarWellPathGroup = wellPathGroup;
longestIdenticalTubeLength = identicalTubeLength;
}
}
if ( mostSimilarWellPathGroup )
{
detachWellPath( wellPath );
mostSimilarWellPathGroup->addChildWellPath( wellPath.get() );
}
else if ( wellPathsWithCommonGeometry.size() > 1u )
{
RimWellPathGroup* group = new RimWellPathGroup;
m_wellPaths.push_back( group );
for ( auto wellPathAndTubeLength : wellPathsWithCommonGeometry )
{
auto existingWellPath = wellPathAndTubeLength.first;
detachWellPath( existingWellPath );
group->addChildWellPath( existingWellPath );
}
mostSimilarWellPathGroup = group;
}
return mostSimilarWellPathGroup;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@ -942,6 +771,191 @@ caf::AppEnum<RiaDefines::EclipseUnitSystem> RimWellPathCollection::findUnitSyste
return RiaDefines::EclipseUnitSystem::UNITS_UNKNOWN;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimWellPathCollection::rebuildWellPathNodes()
{
m_wellPathNodes.deleteAllChildObjects();
std::map<QString, std::vector<RimWellPath*>> rootWells = wellPathsForWellNameStem( m_wellPaths.childObjects() );
for ( auto [groupName, wellPathGroup] : rootWells )
{
if ( groupName == unGroupedText() )
{
// For single wells, create well paths directly in the well collection folder
for ( auto wellPath : wellPathGroup )
{
if ( !wellPath ) continue;
if ( !wellPath->isTopLevelWellPath() ) continue;
auto node = addWellToWellNode( nullptr, wellPath );
m_wellPathNodes.push_back( node );
}
}
else
{
// Create a group node with group name and put related wells into this group
auto rootNode = new cafNamedTreeNode;
rootNode->setName( groupName );
rootNode->setIcon( ":/WellPathGroup.svg" );
m_wellPathNodes.push_back( rootNode );
for ( auto wellPath : wellPathsWithNoParent( wellPathGroup ) )
{
if ( !wellPath ) continue;
addWellToWellNode( rootNode, wellPath );
}
}
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
cafTreeNode* RimWellPathCollection::addWellToWellNode( cafTreeNode* parent, RimWellPath* wellPath )
{
if ( wellPath == nullptr ) return nullptr;
std::vector<RimWellPath*> wellPaths = connectedWellPathLaterals( wellPath );
auto node = new cafObjectReferenceTreeNode;
node->setReferencedObject( wellPath );
if ( parent ) parent->addChild( node );
for ( auto w : wellPaths )
{
addWellToWellNode( node, w );
}
return node;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::vector<RimWellPath*> RimWellPathCollection::wellPathsWithNoParent( const std::vector<RimWellPath*>& sourceWellPaths ) const
{
std::vector<RimWellPath*> wellPaths;
for ( const auto& w : sourceWellPaths )
{
if ( !w ) continue;
if ( w->isTopLevelWellPath() )
{
wellPaths.push_back( w );
}
}
return wellPaths;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::vector<RimWellPath*> RimWellPathCollection::connectedWellPathLaterals( const RimWellPath* parentWellPath ) const
{
if ( !parentWellPath ) return {};
std::vector<RimWellPath*> wellPaths;
for ( const auto& w : m_wellPaths )
{
if ( !w ) continue;
if ( w->wellPathTieIn() && ( w->wellPathTieIn()->parentWell() == parentWellPath ) )
{
wellPaths.push_back( w );
}
}
return wellPaths;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::map<QString, std::vector<RimWellPath*>>
RimWellPathCollection::wellPathsForWellNameStem( const std::vector<RimWellPath*>& sourceWellPaths ) const
{
std::map<QString, std::vector<RimWellPath*>> rootWells;
QString multiLateralWellPathPattern = RiaPreferences::current()->multiLateralWellNamePattern();
QRegExp re( multiLateralWellPathPattern, Qt::CaseInsensitive, QRegExp::Wildcard );
for ( auto wellPath : sourceWellPaths )
{
QString name = wellPath->name();
if ( re.exactMatch( name ) )
{
int indexOfLateralStart = name.indexOf( 'Y' );
if ( indexOfLateralStart > 0 )
{
QString rootWellName = wellPath->name().left( indexOfLateralStart );
rootWells[rootWellName].push_back( wellPath );
}
}
else
{
rootWells[RimWellPathCollection::unGroupedText()].push_back( wellPath );
}
}
return rootWells;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimWellPathCollection::buildUiTreeOrdering( cafTreeNode* treeNode,
caf::PdmUiTreeOrdering* parentUiTreeNode,
const QString& uiConfigName )
{
CAF_ASSERT( treeNode );
CAF_ASSERT( parentUiTreeNode );
if ( auto obj = treeNode->referencedObject() )
{
// Create the standard uiTreeOrdering with no relationship to parent using the helper function in
// PdmUiObjectHandle. This will ensure that any child objects will be created correctly including any
// recursive children. If a PdmUiTreeOrdering is created directly based on the PdmObject, andy child objects
// must be added manually.
auto uiTreeNode = obj->uiCapability()->uiTreeOrdering( uiConfigName );
parentUiTreeNode->appendChild( uiTreeNode );
// Build additional child nodes recursively
for ( auto childNode : treeNode->childNodes() )
{
buildUiTreeOrdering( childNode, uiTreeNode, uiConfigName );
}
}
else
{
// If no referenced object is attached, fallback to the node. Not sure if this is the best solution
auto uiTreeNode = parentUiTreeNode->add( treeNode );
// Build additional child nodes recursively
for ( auto childNode : treeNode->childNodes() )
{
buildUiTreeOrdering( childNode, uiTreeNode, uiConfigName );
}
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QString RimWellPathCollection::unGroupedText()
{
return "UnGrouped";
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@ -964,6 +978,8 @@ const RimWellMeasurementCollection* RimWellPathCollection::measurementCollection
void RimWellPathCollection::onChildDeleted( caf::PdmChildArrayFieldHandle* childArray,
std::vector<caf::PdmObjectHandle*>& referringObjects )
{
rebuildWellPathNodes();
scheduleRedrawAffectedViews();
uiCapability()->updateConnectedEditors();
}

View File

@ -45,9 +45,9 @@ class RimEclipseView;
class RimProject;
class RimWellLogFile;
class RimWellPath;
class RimWellPathGroup;
class RifWellPathFormationsImporter;
class RimWellMeasurementCollection;
class cafTreeNode;
class QString;
namespace cvf
@ -99,8 +99,9 @@ public:
void removeWellPath( gsl::not_null<RimWellPath*> wellPath );
void deleteAllWellPaths();
void groupWellPaths( const std::vector<RimWellPath*>& wellPaths, bool automaticGrouping = false );
void ungroupWellPaths( const std::vector<RimWellPath*>& wellPaths );
void groupWellPaths( const std::vector<RimWellPath*>& wellPaths );
void rebuildWellPathNodes();
RimWellPath* mostRecentlyUpdatedWellPath();
@ -130,9 +131,6 @@ public:
protected:
void fieldChangedByUi( const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue ) override;
std::vector<RimWellPath*> detachWellPaths( const std::vector<RimWellPath*> wellPathsToDetach );
bool detachWellPath( gsl::not_null<RimWellPath*> wellPath );
private:
void defineUiOrdering( QString uiConfigName, caf::PdmUiOrdering& uiOrdering ) override;
void defineUiTreeOrdering( caf::PdmUiTreeOrdering& uiTreeOrdering, QString uiConfigName ) override;
@ -142,16 +140,29 @@ private:
void readAndAddWellPaths( std::vector<RimFileWellPath*>& wellPathArray, bool importGrouped );
void sortWellsByName();
std::vector<RimWellPathGroup*> topLevelGroups() const;
RimWellPathGroup* findOrCreateWellPathGroup( gsl::not_null<RimWellPath*> wellPath,
const std::vector<RimWellPath*>& wellPathsToGroupWith );
caf::AppEnum<RiaDefines::EclipseUnitSystem> findUnitSystemForWellPath( const RimWellPath* wellPath );
cafTreeNode* addWellToWellNode( cafTreeNode* parent, RimWellPath* wellPath );
std::vector<RimWellPath*> wellPathsWithNoParent( const std::vector<RimWellPath*>& sourceWellPaths ) const;
std::vector<RimWellPath*> connectedWellPathLaterals( const RimWellPath* parentWellPath ) const;
std::map<QString, std::vector<RimWellPath*>>
wellPathsForWellNameStem( const std::vector<RimWellPath*>& sourceWellPaths ) const;
static void buildUiTreeOrdering( cafTreeNode* treeNode,
caf::PdmUiTreeOrdering* parentUiTreeNode,
const QString& uiConfigName );
static QString unGroupedText();
private:
std::unique_ptr<RifWellPathImporter> m_wellPathImporter;
std::unique_ptr<RifWellPathFormationsImporter> m_wellPathFormationsImporter;
caf::PdmPointer<RimWellPath> m_mostRecentlyUpdatedWellPath;
caf::PdmChildField<RimWellMeasurementCollection*> m_wellMeasurements;
caf::PdmChildArrayField<RimWellPath*> m_wellPaths;
caf::PdmChildArrayField<cafTreeNode*> m_wellPathNodes;
};

View File

@ -20,6 +20,7 @@
#include "RigWellPath.h"
#include "RimFileWellPath.h"
#include "RimModeledWellPath.h"
#include "RimTools.h"
#include "RimWellPathCollection.h"
@ -40,9 +41,9 @@ RimWellPathTieIn::RimWellPathTieIn()
{
CAF_PDM_InitObject( "Well Path Tie In", ":/NotDefined.png", "", "Well Path Tie In description" );
CAF_PDM_InitFieldNoDefault( &m_parentWell, "ParentWellPath", "ParentWellPath", "", "", "" );
CAF_PDM_InitFieldNoDefault( &m_parentWell, "ParentWellPath", "Parent Well Path", "", "", "" );
CAF_PDM_InitFieldNoDefault( &m_childWell, "ChildWellPath", "ChildWellPath", "", "", "" );
CAF_PDM_InitFieldNoDefault( &m_tieInMeasuredDepth, "TieInMeasuredDepth", "TieInMeasuredDepth", "", "", "" );
CAF_PDM_InitFieldNoDefault( &m_tieInMeasuredDepth, "TieInMeasuredDepth", "Tie In Measured Depth", "", "", "" );
m_tieInMeasuredDepth.uiCapability()->setUiEditorTypeName( caf::PdmUiDoubleValueEditor::uiEditorTypeName() );
CAF_PDM_InitScriptableField( &m_addValveAtConnection,
@ -153,15 +154,21 @@ void RimWellPathTieIn::defineUiOrdering( QString uiConfigName, caf::PdmUiOrderin
{
auto tieInGroup = uiOrdering.addNewGroup( "Tie In Settings" );
tieInGroup->add( &m_parentWell );
tieInGroup->add( &m_tieInMeasuredDepth );
tieInGroup->add( &m_addValveAtConnection );
// Display only ICV valves
m_valve->setComponentTypeFilter( { RiaDefines::WellPathComponentType::ICV } );
if ( m_addValveAtConnection )
if ( m_parentWell() != nullptr )
{
m_valve->uiOrdering( "TemplateOnly", *tieInGroup );
tieInGroup->add( &m_tieInMeasuredDepth );
tieInGroup->add( &m_addValveAtConnection );
bool isFileWellPath = dynamic_cast<RimFileWellPath*>( m_childWell() );
m_tieInMeasuredDepth.uiCapability()->setUiReadOnly( isFileWellPath );
// Display only ICV valves
m_valve->setComponentTypeFilter( { RiaDefines::WellPathComponentType::ICV } );
if ( m_addValveAtConnection )
{
m_valve->uiOrdering( "TemplateOnly", *tieInGroup );
}
}
uiOrdering.skipRemainingFields();
@ -177,6 +184,8 @@ void RimWellPathTieIn::fieldChangedByUi( const caf::PdmFieldHandle* changedField
if ( changedField == &m_parentWell )
{
updateFirstTargetFromParentWell();
RimTools::wellPathCollection()->rebuildWellPathNodes();
}
updateChildWellGeometry();

View File

@ -0,0 +1,214 @@
/////////////////////////////////////////////////////////////////////////////////
//
// 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 <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
#include "cafTreeNode.h"
#include "cafPdmUiTreeOrdering.h"
CAF_PDM_SOURCE_INIT( cafTreeNode, "cafTreeNode" );
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
cafTreeNode::cafTreeNode()
{
CAF_PDM_InitObject( "WellPath", ":/Folder.svg", "", "" );
CAF_PDM_InitFieldNoDefault( &m_childNodes, "ChildNodes", "ChildNodes", "", "", "" );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void cafTreeNode::addChild( cafTreeNode* treeNode )
{
m_childNodes.push_back( treeNode );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::vector<cafTreeNode*> cafTreeNode::childNodes() const
{
return m_childNodes.childObjects();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
caf::PdmObject* cafTreeNode::referencedObject() const
{
return nullptr;
}
//--------------------------------------------------------------------------------------------------
///
///
///
///
///
///
///
///
/// cafNamedTreeNode
//--------------------------------------------------------------------------------------------------
CAF_PDM_SOURCE_INIT( cafNamedTreeNode, "cafNamedTreeNode" );
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
cafNamedTreeNode::cafNamedTreeNode()
: m_showCheckedBox( false )
{
CAF_PDM_InitObject( "Node", ":/Folder.svg", "", "" );
CAF_PDM_InitField( &m_name, "Name", QString(), "Name", "", "", "" );
m_name.uiCapability()->setUiHidden( true );
CAF_PDM_InitField( &m_isChecked, "IsChecked", true, "Active", "", "", "" );
m_isChecked.uiCapability()->setUiHidden( true );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void cafNamedTreeNode::setName( const QString& name )
{
m_name = name;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QString cafNamedTreeNode::name() const
{
return m_name();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void cafNamedTreeNode::setIcon( const QString& iconResourceName )
{
this->setUiIconFromResourceString( iconResourceName );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void cafNamedTreeNode::setCheckedState( bool enable )
{
m_isChecked = enable;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool cafNamedTreeNode::isChecked() const
{
return m_isChecked();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
caf::PdmFieldHandle* cafNamedTreeNode::objectToggleField()
{
if ( m_showCheckedBox ) return &m_isChecked;
return nullptr;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
caf::PdmFieldHandle* cafNamedTreeNode::userDescriptionField()
{
return &m_name;
}
//--------------------------------------------------------------------------------------------------
///
///
///
///
///
///
///
///
/// cafObjectReferenceTreeNode
//--------------------------------------------------------------------------------------------------
CAF_PDM_SOURCE_INIT( cafObjectReferenceTreeNode, "cafObjectReferenceTreeNode" );
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
cafObjectReferenceTreeNode::cafObjectReferenceTreeNode()
{
CAF_PDM_InitObject( "cafObjectReferenceTreeNode", ":/Folder.svg", "", "" );
CAF_PDM_InitFieldNoDefault( &m_referencedObject, "ReferencedObject", "Referenced Object", "", "", "" );
m_childNodes.uiCapability()->setUiTreeHidden( true );
uiCapability()->setUiTreeHidden( true );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void cafObjectReferenceTreeNode::setReferencedObject( caf::PdmObject* object )
{
m_referencedObject = object;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
caf::PdmObject* cafObjectReferenceTreeNode::referencedObject() const
{
return m_referencedObject();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void cafObjectReferenceTreeNode::defineUiTreeOrdering( caf::PdmUiTreeOrdering& uiTreeOrdering,
QString uiConfigName /*= "" */ )
{
if ( m_referencedObject )
{
uiTreeOrdering.add( m_referencedObject() );
}
for ( auto c : m_childNodes.childObjects() )
{
if ( auto obj = c->referencedObject() )
{
uiTreeOrdering.add( obj );
}
else
{
uiTreeOrdering.add( c );
}
}
uiTreeOrdering.skipRemainingChildren();
}

View File

@ -0,0 +1,100 @@
/////////////////////////////////////////////////////////////////////////////////
//
// 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 <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
#pragma once
#include "cafPdmChildArrayField.h"
#include "cafPdmField.h"
#include "cafPdmObject.h"
#include "cafPdmPtrField.h"
namespace caf
{
class PdmUiOrdering;
class PdmUiTreeOrdering;
} // namespace caf
class QString;
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
class cafTreeNode : public caf::PdmObject
{
CAF_PDM_HEADER_INIT;
public:
cafTreeNode();
void addChild( cafTreeNode* treeNode );
std::vector<cafTreeNode*> childNodes() const;
virtual caf::PdmObject* referencedObject() const;
protected:
caf::PdmChildArrayField<cafTreeNode*> m_childNodes;
};
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
class cafNamedTreeNode : public cafTreeNode
{
CAF_PDM_HEADER_INIT;
public:
cafNamedTreeNode();
void setName( const QString& name );
QString name() const;
void setIcon( const QString& iconResourceName );
void setCheckedState( bool enable );
bool isChecked() const;
protected:
caf::PdmFieldHandle* objectToggleField() override;
caf::PdmFieldHandle* userDescriptionField() override;
private:
bool m_showCheckedBox;
caf::PdmField<QString> m_name;
caf::PdmField<bool> m_isChecked;
};
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
class cafObjectReferenceTreeNode : public cafTreeNode
{
CAF_PDM_HEADER_INIT;
public:
cafObjectReferenceTreeNode();
void setReferencedObject( caf::PdmObject* object );
caf::PdmObject* referencedObject() const override;
protected:
void defineUiTreeOrdering( caf::PdmUiTreeOrdering& uiTreeOrdering, QString uiConfigName = "" ) override;
private:
caf::PdmPtrField<caf::PdmObject*> m_referencedObject;
};

View File

@ -494,6 +494,8 @@ size_t RigWellPath::uniqueStartIndex() const
//--------------------------------------------------------------------------------------------------
size_t RigWellPath::uniqueEndIndex() const
{
if ( m_measuredDepths.empty() ) return 0;
return std::clamp( m_uniqueEndIndex, m_uniqueStartIndex, m_measuredDepths.size() - 1u );
}
@ -502,6 +504,8 @@ size_t RigWellPath::uniqueEndIndex() const
//--------------------------------------------------------------------------------------------------
std::vector<cvf::Vec3d> RigWellPath::uniqueWellPathPoints() const
{
if ( m_wellPathPoints.empty() ) return {};
return std::vector<cvf::Vec3d>( m_wellPathPoints.begin() + uniqueStartIndex(),
m_wellPathPoints.begin() + uniqueEndIndex() + 1u );
}
@ -511,6 +515,8 @@ std::vector<cvf::Vec3d> RigWellPath::uniqueWellPathPoints() const
//--------------------------------------------------------------------------------------------------
std::vector<double> RigWellPath::uniqueMeasuredDepths() const
{
if ( m_measuredDepths.empty() ) return {};
return std::vector<double>( m_measuredDepths.begin() + m_uniqueStartIndex,
m_measuredDepths.begin() + uniqueEndIndex() + 1u );
}
@ -521,9 +527,10 @@ std::vector<double> RigWellPath::uniqueMeasuredDepths() const
std::pair<std::vector<cvf::Vec3d>, std::vector<double>>
RigWellPath::clippedPointSubset( double startMD, double endMD, double* horizontalLengthAlongWellToStartClipPoint ) const
{
if ( m_measuredDepths.empty() ) return {};
if ( startMD > endMD ) return {};
std::pair<std::vector<cvf::Vec3d>, std::vector<double>> pointsAndMDs;
if ( m_measuredDepths.empty() ) return pointsAndMDs;
if ( startMD > endMD ) return pointsAndMDs;
pointsAndMDs.first.push_back( interpolatedPointAlongWellPath( startMD, horizontalLengthAlongWellToStartClipPoint ) );
pointsAndMDs.second.push_back( startMD );