2017-10-27 08:01:55 -05:00
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// Copyright (C) 2017 Statoil ASA
|
2019-09-06 03:40:57 -05:00
|
|
|
//
|
2017-10-27 08:01:55 -05:00
|
|
|
// 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.
|
2019-09-06 03:40:57 -05:00
|
|
|
//
|
2017-10-27 08:01:55 -05:00
|
|
|
// 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.
|
2019-09-06 03:40:57 -05:00
|
|
|
//
|
|
|
|
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
2017-10-27 08:01:55 -05:00
|
|
|
// for more details.
|
|
|
|
//
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#include "RiaWellNameComparer.h"
|
|
|
|
#include "../../ProjectDataModel/RimProject.h"
|
|
|
|
#include "../../ProjectDataModel/RimWellPath.h"
|
2019-09-06 03:40:57 -05:00
|
|
|
#include "../RiaApplication.h"
|
2017-10-27 08:01:55 -05:00
|
|
|
#include <regex>
|
|
|
|
|
|
|
|
//==================================================================================================
|
|
|
|
//
|
|
|
|
//==================================================================================================
|
2019-09-06 03:40:57 -05:00
|
|
|
QString RiaWellNameComparer::tryFindMatchingSimWellName( QString searchName )
|
2017-10-27 08:01:55 -05:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
RimProject* proj = RiaApplication::instance()->project();
|
2017-10-27 08:01:55 -05:00
|
|
|
const std::vector<QString>& simWellNames = proj->simulationWellNames();
|
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( searchName.isEmpty() || simWellNames.empty() ) return QString();
|
2017-10-27 08:01:55 -05:00
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
searchName = removeWellNamePrefix( searchName );
|
|
|
|
return tryMatchNameInList( searchName, simWellNames );
|
2017-10-27 08:01:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
///
|
2017-10-27 08:01:55 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
QString RiaWellNameComparer::tryFindMatchingWellPath( QString wellName )
|
2017-10-27 08:01:55 -05:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
RimProject* proj = RiaApplication::instance()->project();
|
2017-10-27 08:01:55 -05:00
|
|
|
const std::vector<RimWellPath*>& wellPaths = proj->allWellPaths();
|
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( wellName.isEmpty() || wellPaths.empty() ) return QString();
|
2017-10-27 08:01:55 -05:00
|
|
|
|
|
|
|
std::vector<QString> wellPathNames;
|
2019-09-06 03:40:57 -05:00
|
|
|
for ( const RimWellPath* wellPath : wellPaths )
|
2017-10-27 08:01:55 -05:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
wellPathNames.push_back( wellPath->name() );
|
2017-10-27 08:01:55 -05:00
|
|
|
}
|
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
wellName = removeWellNamePrefix( wellName );
|
|
|
|
return tryMatchNameInList( wellName, wellPathNames );
|
2017-10-27 08:01:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
///
|
2017-10-27 08:01:55 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
QString RiaWellNameComparer::tryMatchNameInList( QString searchName, const std::vector<QString>& nameList )
|
2017-10-27 08:01:55 -05:00
|
|
|
{
|
|
|
|
// Try exact name match
|
2019-09-06 03:40:57 -05:00
|
|
|
QString matchedName = tryMatchName( searchName, nameList );
|
|
|
|
if ( !matchedName.isEmpty() )
|
2017-10-27 08:01:55 -05:00
|
|
|
{
|
|
|
|
return matchedName;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Try matching ignoring spaces, dashes and underscores
|
2019-09-06 03:40:57 -05:00
|
|
|
return tryMatchName( searchName, nameList, []( const QString& str ) {
|
|
|
|
QString s = str;
|
|
|
|
s = removeWellNamePrefix( s );
|
|
|
|
return s.remove( ' ' ).remove( '-' ).remove( '_' );
|
|
|
|
} );
|
2017-10-27 08:01:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
///
|
2017-10-27 08:01:55 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
QString RiaWellNameComparer::tryMatchName( QString searchName,
|
|
|
|
const std::vector<QString>& simWellNames,
|
|
|
|
std::function<QString( QString )> stringFormatter )
|
2017-10-27 08:01:55 -05:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( searchName.isEmpty() ) return QString();
|
2017-10-27 08:01:55 -05:00
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( stringFormatter != nullptr )
|
2017-10-27 08:01:55 -05:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
searchName = stringFormatter( searchName );
|
2017-10-27 08:01:55 -05:00
|
|
|
}
|
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
for ( const auto& simWellName : simWellNames )
|
2017-10-27 08:01:55 -05:00
|
|
|
{
|
|
|
|
QString simWn = simWellName;
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( stringFormatter != nullptr )
|
2017-10-27 08:01:55 -05:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
simWn = stringFormatter( simWn );
|
2017-10-27 08:01:55 -05:00
|
|
|
}
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( QString::compare( simWn, searchName, Qt::CaseInsensitive ) == 0 )
|
2017-10-27 08:01:55 -05:00
|
|
|
{
|
|
|
|
return simWellName;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
///
|
2017-10-27 08:01:55 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
QString RiaWellNameComparer::removeWellNamePrefix( const QString& name )
|
2017-10-27 08:01:55 -05:00
|
|
|
{
|
|
|
|
// Try to remove prefix on the format 'xx xxxx/xx-'
|
2019-09-06 03:40:57 -05:00
|
|
|
std::regex pattern( "^.*\\d*[/]\\d*[-_]" );
|
2017-10-27 08:01:55 -05:00
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
return QString::fromStdString( std::regex_replace( name.toStdString(), pattern, "" ) );
|
2017-10-27 08:01:55 -05:00
|
|
|
}
|