From 4cf80e3fe6ca5fc2d161d4b4720783fba1802098 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Jensen?= Date: Fri, 27 Oct 2017 09:11:03 +0200 Subject: [PATCH] #2043 WellPath import. Improve well path name and sim well name matching --- .../ProjectDataModel/RimWellPath.cpp | 38 +++++++++++-------- .../ProjectDataModel/RimWellPath.h | 6 ++- 2 files changed, 27 insertions(+), 17 deletions(-) diff --git a/ApplicationCode/ProjectDataModel/RimWellPath.cpp b/ApplicationCode/ProjectDataModel/RimWellPath.cpp index 35de516eed..0a06c1902f 100644 --- a/ApplicationCode/ProjectDataModel/RimWellPath.cpp +++ b/ApplicationCode/ProjectDataModel/RimWellPath.cpp @@ -710,23 +710,19 @@ bool RimWellPath::tryAssociateWithSimulationWell() QString wellPathName = QString(m_name); + // Try to remove prefix on the format 'xx xxxx/xx-' + std::regex pattern("^.*\\d*[/]\\d*[-_]"); + + wellPathName = QString::fromStdString(std::regex_replace(wellPathName.toStdString(), pattern, "")); + // Try exact name match if (tryMatchName(wellPathName, simWellNames)) return true; - // Try matching ignoring spaces - wellPathName = QString(m_name).remove(' '); - if (tryMatchName(wellPathName, simWellNames)) return true; - - // Try to remove prefix on the format 'xxxx/xx-' - std::regex pattern("^\\d*[/]\\d*-"); - - wellPathName = QString::fromStdString(std::regex_replace(m_name().toStdString(), pattern, "")); - if (tryMatchName(wellPathName, simWellNames)) return true; - - wellPathName = wellPathName.remove(' '); - if (tryMatchName(wellPathName, simWellNames)) return true; - - return false; + // Try matching ignoring spaces, dashes and underscores + return tryMatchName(wellPathName, simWellNames, [](const QString& str) { + QString s = str; + return s.remove(' ').remove('-').remove('_'); + }); } //-------------------------------------------------------------------------------------------------- @@ -740,13 +736,23 @@ bool RimWellPath::isAssociatedWithSimulationWell() const //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -bool RimWellPath::tryMatchName(QString wellPathName, const std::vector& simWellNames) +bool RimWellPath::tryMatchName(QString wellPathName, const std::vector& simWellNames, std::function stringFormatter) { if (wellPathName.isEmpty()) return false; + if (stringFormatter != nullptr) + { + wellPathName = stringFormatter(wellPathName); + } + for (const auto& simWellName : simWellNames) { - if (QString::compare(simWellName, wellPathName, Qt::CaseInsensitive) == 0) + QString simWn = simWellName; + if (stringFormatter != nullptr) + { + simWn = stringFormatter(simWn); + } + if (QString::compare(simWn, wellPathName, Qt::CaseInsensitive) == 0) { m_simWellName = simWellName; return true; diff --git a/ApplicationCode/ProjectDataModel/RimWellPath.h b/ApplicationCode/ProjectDataModel/RimWellPath.h index 37adfea2a3..47c3a69fde 100644 --- a/ApplicationCode/ProjectDataModel/RimWellPath.h +++ b/ApplicationCode/ProjectDataModel/RimWellPath.h @@ -34,6 +34,8 @@ #include "cafPdmChildArrayField.h" #include "cvfObject.h" +#include + class RifWellPathImporter; class RigWellPath; class RimProject; @@ -120,7 +122,9 @@ public: int associatedSimulationWellBranch() const; bool tryAssociateWithSimulationWell(); bool isAssociatedWithSimulationWell() const; - bool tryMatchName(QString wellPathName, const std::vector& simWellNames); + bool tryMatchName(QString wellPathName, + const std::vector& simWellNames, + std::function stringFormatter = nullptr); private: