mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-09 23:16:00 -06:00
#1475 Move well path import to own module
This commit is contained in:
parent
338e51bced
commit
bf704caa16
@ -19,6 +19,7 @@ ${CEE_CURRENT_LIST_DIR}RifReaderInterface.h
|
||||
${CEE_CURRENT_LIST_DIR}RifReaderMockModel.h
|
||||
${CEE_CURRENT_LIST_DIR}RifReaderSettings.h
|
||||
${CEE_CURRENT_LIST_DIR}RifEclipseSummaryAddress.h
|
||||
${CEE_CURRENT_LIST_DIR}RifWellPathImporter.h
|
||||
)
|
||||
|
||||
set (SOURCE_GROUP_SOURCE_FILES
|
||||
@ -36,6 +37,7 @@ ${CEE_CURRENT_LIST_DIR}RifReaderInterface.cpp
|
||||
${CEE_CURRENT_LIST_DIR}RifReaderMockModel.cpp
|
||||
${CEE_CURRENT_LIST_DIR}RifReaderSettings.cpp
|
||||
${CEE_CURRENT_LIST_DIR}RifEclipseSummaryAddress.cpp
|
||||
${CEE_CURRENT_LIST_DIR}RifWellPathImporter.cpp
|
||||
)
|
||||
|
||||
list(APPEND CODE_HEADER_FILES
|
||||
|
386
ApplicationCode/FileInterface/RifWellPathImporter.cpp
Normal file
386
ApplicationCode/FileInterface/RifWellPathImporter.cpp
Normal file
@ -0,0 +1,386 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2011- Statoil ASA
|
||||
// Copyright (C) 2013- Ceetron Solutions AS
|
||||
// Copyright (C) 2011-2012 Ceetron AS
|
||||
//
|
||||
// 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 "RifWellPathImporter.h"
|
||||
|
||||
#include "RifJsonEncodeDecode.h"
|
||||
|
||||
#include <fstream>
|
||||
|
||||
#include <QFileInfo>
|
||||
|
||||
#define ASCII_FILE_DEFAULT_START_INDEX 0
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RifWellPathImporter::canReadFile(const QString& filePath)
|
||||
{
|
||||
QFileInfo fileInfo(filePath);
|
||||
if (fileInfo.isFile() && fileInfo.exists())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RifWellPathImporter::WellData RifWellPathImporter::readWellData(const QString& filePath, size_t indexInFile)
|
||||
{
|
||||
CVF_ASSERT(canReadFile(filePath));
|
||||
|
||||
if (isJsonFile(filePath))
|
||||
{
|
||||
return readJsonWellData(filePath);
|
||||
}
|
||||
else
|
||||
{
|
||||
return readAsciiWellData(filePath, indexInFile);
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RifWellPathImporter::WellData RifWellPathImporter::readWellData(const QString& filePath)
|
||||
{
|
||||
return readWellData(filePath, ASCII_FILE_DEFAULT_START_INDEX);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RifWellPathImporter::WellMetaData RifWellPathImporter::readWellMetaData(const QString& filePath, size_t indexInFile)
|
||||
{
|
||||
CVF_ASSERT(canReadFile(filePath));
|
||||
|
||||
if (isJsonFile(filePath))
|
||||
{
|
||||
return readJsonWellMetaData(filePath);
|
||||
}
|
||||
else
|
||||
{
|
||||
return readAsciiWellMetaData(filePath, indexInFile);
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RifWellPathImporter::WellMetaData RifWellPathImporter::readWellMetaData(const QString& filePath)
|
||||
{
|
||||
return readWellMetaData(filePath, ASCII_FILE_DEFAULT_START_INDEX);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
size_t RifWellPathImporter::wellDataCount(const QString& filePath)
|
||||
{
|
||||
if (isJsonFile(filePath))
|
||||
{
|
||||
// Only support JSON files with single well data currently
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::map<QString, std::vector<RifWellPathImporter::WellData> >::iterator it = m_fileNameToWellDataGroupMap.find(filePath);
|
||||
|
||||
// If we have the file in the map, assume it is already read.
|
||||
if (it != m_fileNameToWellDataGroupMap.end())
|
||||
{
|
||||
return it->second.size();
|
||||
}
|
||||
|
||||
readAllAsciiWellData(filePath);
|
||||
it = m_fileNameToWellDataGroupMap.find(filePath);
|
||||
CVF_ASSERT(it != m_fileNameToWellDataGroupMap.end());
|
||||
|
||||
return it->second.size();;
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RifWellPathImporter::isJsonFile(const QString & filePath)
|
||||
{
|
||||
QFileInfo fileInfo(filePath);
|
||||
|
||||
if (fileInfo.suffix().compare("json") == 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RifWellPathImporter::WellMetaData RifWellPathImporter::readJsonWellMetaData(const QString & filePath)
|
||||
{
|
||||
ResInsightInternalJson::JsonReader jsonReader;
|
||||
QMap<QString, QVariant> jsonMap = jsonReader.decodeFile(filePath);
|
||||
WellMetaData metadata;
|
||||
|
||||
metadata.m_id = jsonMap["id"].toString();
|
||||
metadata.m_name = jsonMap["name"].toString();
|
||||
metadata.m_sourceSystem = jsonMap["sourceSystem"].toString();
|
||||
metadata.m_utmZone = jsonMap["utmZone"].toString();
|
||||
metadata.m_updateUser = jsonMap["updateUser"].toString();
|
||||
metadata.m_surveyType = jsonMap["surveyType"].toString();
|
||||
|
||||
// Convert updateDate from the following format:
|
||||
// "Number of milliseconds elapsed since midnight Coordinated Universal Time (UTC)
|
||||
// of January 1, 1970, not counting leap seconds"
|
||||
QString updateDateStr = jsonMap["updateDate"].toString().trimmed();
|
||||
uint updateDateUint = updateDateStr.toULongLong() / 1000; // Should be within 32 bit, maximum number is 4294967295 which corresponds to year 2106
|
||||
metadata.m_updateDate.setTime_t(updateDateUint);
|
||||
|
||||
return metadata;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RifWellPathImporter::WellData RifWellPathImporter::readJsonWellData(const QString& filePath)
|
||||
{
|
||||
ResInsightInternalJson::JsonReader jsonReader;
|
||||
QMap<QString, QVariant> jsonMap = jsonReader.decodeFile(filePath);
|
||||
|
||||
double datumElevation = jsonMap["datumElevation"].toDouble();
|
||||
QList<QVariant> pathList = jsonMap["path"].toList();
|
||||
WellData wellData;
|
||||
wellData.m_wellPathGeometry->setDatumElevation(datumElevation);
|
||||
wellData.m_name = jsonMap["name"].toString();
|
||||
|
||||
foreach(QVariant point, pathList)
|
||||
{
|
||||
QMap<QString, QVariant> coordinateMap = point.toMap();
|
||||
cvf::Vec3d vec3d(coordinateMap["east"].toDouble(), coordinateMap["north"].toDouble(), -(coordinateMap["tvd"].toDouble() - datumElevation));
|
||||
wellData.m_wellPathGeometry->m_wellPathPoints.push_back(vec3d);
|
||||
double measuredDepth = coordinateMap["md"].toDouble();
|
||||
wellData.m_wellPathGeometry->m_measuredDepths.push_back(measuredDepth);
|
||||
}
|
||||
return wellData;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RifWellPathImporter::readAllAsciiWellData(const QString& filePath)
|
||||
{
|
||||
std::map<QString, std::vector<RifWellPathImporter::WellData> >::iterator it = m_fileNameToWellDataGroupMap.find(filePath);
|
||||
|
||||
// If we have the file in the map, assume it is already read.
|
||||
if (it != m_fileNameToWellDataGroupMap.end())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Create the data container
|
||||
std::vector<RifWellPathImporter::WellData>& fileWellDataArray = m_fileNameToWellDataGroupMap[filePath];
|
||||
|
||||
std::ifstream stream(filePath.toLatin1().data());
|
||||
double x(HUGE_VAL), y(HUGE_VAL), tvd(HUGE_VAL), md(HUGE_VAL);
|
||||
|
||||
bool hasReadWellPointInCurrentWell = false;
|
||||
|
||||
while (stream.good())
|
||||
{
|
||||
// First check if we can read a number
|
||||
stream >> x;
|
||||
if (stream.good()) // If we can, assume this line is a well point entry
|
||||
{
|
||||
stream >> y >> tvd >> md;
|
||||
if (!stream.good())
|
||||
{
|
||||
// -999 or otherwise to few numbers before some word
|
||||
if (x != -999)
|
||||
{
|
||||
// Error in file: missing numbers at this line
|
||||
|
||||
}
|
||||
stream.clear();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!fileWellDataArray.size())
|
||||
{
|
||||
fileWellDataArray.push_back(RifWellPathImporter::WellData());
|
||||
fileWellDataArray.back().m_wellPathGeometry = new RigWellPath();
|
||||
}
|
||||
|
||||
cvf::Vec3d wellPoint(x, y, -tvd);
|
||||
fileWellDataArray.back().m_wellPathGeometry->m_wellPathPoints.push_back(wellPoint);
|
||||
fileWellDataArray.back().m_wellPathGeometry->m_measuredDepths.push_back(md);
|
||||
|
||||
x = HUGE_VAL;
|
||||
y = HUGE_VAL;
|
||||
tvd = HUGE_VAL;
|
||||
md = HUGE_VAL;
|
||||
|
||||
hasReadWellPointInCurrentWell = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Could not read one double.
|
||||
// we assume there is a comment line or a well path description
|
||||
stream.clear();
|
||||
|
||||
std::string line;
|
||||
std::getline(stream, line, '\n');
|
||||
// Skip possible comment lines (-- is used in eclipse, so Haakon Høgstøl considered it smart to skip these here as well)
|
||||
// The first "-" is eaten by the stream >> x above
|
||||
if (line.find("-") == 0 || line.find("#") == 0)
|
||||
{
|
||||
// Comment line, just ignore
|
||||
}
|
||||
else
|
||||
{
|
||||
// Find the first and the last position of any quotes (and do not care to match quotes)
|
||||
size_t quoteStartIdx = line.find_first_of("'`´’‘");
|
||||
size_t quoteEndIdx = line.find_last_of("'`´’‘");
|
||||
|
||||
std::string wellName;
|
||||
bool haveAPossibleWellStart = false;
|
||||
|
||||
if (quoteStartIdx < line.size() -1)
|
||||
{
|
||||
// Extract the text between the quotes
|
||||
wellName = line.substr(quoteStartIdx + 1, quoteEndIdx - 1 - quoteStartIdx);
|
||||
haveAPossibleWellStart = true;
|
||||
}
|
||||
else if (quoteStartIdx > line.length())
|
||||
{
|
||||
// We did not find any quotes
|
||||
|
||||
// Supported alternatives are
|
||||
// name <WellNameA>
|
||||
// wellname: <WellNameA>
|
||||
std::string lineLowerCase = line;
|
||||
transform(lineLowerCase.begin(), lineLowerCase.end(), lineLowerCase.begin(), ::tolower);
|
||||
|
||||
std::string tokenName = "name";
|
||||
std::size_t foundNameIdx = lineLowerCase.find(tokenName);
|
||||
if (foundNameIdx != std::string::npos)
|
||||
{
|
||||
std::string tokenColon = ":";
|
||||
std::size_t foundColonIdx = lineLowerCase.find(tokenColon, foundNameIdx);
|
||||
if (foundColonIdx != std::string::npos)
|
||||
{
|
||||
wellName = line.substr(foundColonIdx + tokenColon.length());
|
||||
}
|
||||
else
|
||||
{
|
||||
wellName = line.substr(foundNameIdx + tokenName.length());
|
||||
}
|
||||
|
||||
haveAPossibleWellStart = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Interpret the whole line as the well name.
|
||||
|
||||
QString name = line.c_str();
|
||||
if (!name.trimmed().isEmpty())
|
||||
{
|
||||
wellName = name.trimmed().toStdString();
|
||||
haveAPossibleWellStart = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (haveAPossibleWellStart)
|
||||
{
|
||||
// Create a new Well data if we have read some data into the previous one.
|
||||
// if not, just overwrite the name
|
||||
if (hasReadWellPointInCurrentWell || fileWellDataArray.size() == 0)
|
||||
{
|
||||
fileWellDataArray.push_back(RifWellPathImporter::WellData());
|
||||
fileWellDataArray.back().m_wellPathGeometry = new RigWellPath();
|
||||
}
|
||||
|
||||
QString name = wellName.c_str();
|
||||
if (!name.trimmed().isEmpty())
|
||||
{
|
||||
// Do not overwrite the name aquired from a line above, if this line is empty
|
||||
fileWellDataArray.back().m_name = name.trimmed();
|
||||
}
|
||||
hasReadWellPointInCurrentWell = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RifWellPathImporter::WellData RifWellPathImporter::readAsciiWellData(const QString& filePath, size_t indexInFile)
|
||||
{
|
||||
readAllAsciiWellData(filePath);
|
||||
|
||||
std::map<QString, std::vector<RifWellPathImporter::WellData> >::iterator it = m_fileNameToWellDataGroupMap.find(filePath);
|
||||
|
||||
CVF_ASSERT(it != m_fileNameToWellDataGroupMap.end());
|
||||
|
||||
if (indexInFile < it->second.size())
|
||||
{
|
||||
return it->second[indexInFile];
|
||||
}
|
||||
else
|
||||
{
|
||||
// Error : The ascii well path file does not contain that many well paths
|
||||
return RifWellPathImporter::WellData();
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RifWellPathImporter::WellMetaData RifWellPathImporter::readAsciiWellMetaData(const QString & filePath, size_t indexInFile)
|
||||
{
|
||||
// No metadata in ASCII files
|
||||
return WellMetaData();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RifWellPathImporter::clear()
|
||||
{
|
||||
m_fileNameToWellDataGroupMap.clear();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RifWellPathImporter::removeFilePath(const QString& filePath)
|
||||
{
|
||||
m_fileNameToWellDataGroupMap.erase(filePath);
|
||||
}
|
77
ApplicationCode/FileInterface/RifWellPathImporter.h
Normal file
77
ApplicationCode/FileInterface/RifWellPathImporter.h
Normal file
@ -0,0 +1,77 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2011- Statoil ASA
|
||||
// Copyright (C) 2013- Ceetron Solutions AS
|
||||
// Copyright (C) 2011-2012 Ceetron AS
|
||||
//
|
||||
// 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 "RigWellPath.h"
|
||||
|
||||
#include "cvfObject.h"
|
||||
|
||||
#include <map>
|
||||
#include <vector>
|
||||
#include <QString>
|
||||
#include <QDateTime>
|
||||
|
||||
//==================================================================================================
|
||||
///
|
||||
///
|
||||
//==================================================================================================
|
||||
class RifWellPathImporter
|
||||
{
|
||||
public:
|
||||
struct WellData
|
||||
{
|
||||
QString m_name;
|
||||
cvf::ref<RigWellPath> m_wellPathGeometry;
|
||||
};
|
||||
|
||||
struct WellMetaData
|
||||
{
|
||||
QString m_name;
|
||||
QString m_id;
|
||||
QString m_sourceSystem;
|
||||
QString m_utmZone;
|
||||
QString m_updateUser;
|
||||
QString m_surveyType;
|
||||
QDateTime m_updateDate;
|
||||
};
|
||||
|
||||
WellData readWellData(const QString& filePath, size_t indexInFile);
|
||||
WellData readWellData(const QString& filePath);
|
||||
WellMetaData readWellMetaData(const QString& filePath, size_t indexInFile);
|
||||
WellMetaData readWellMetaData(const QString& filePath);
|
||||
size_t wellDataCount(const QString& filePath);
|
||||
|
||||
static bool canReadFile(const QString& filePath);
|
||||
|
||||
void clear();
|
||||
void removeFilePath(const QString& filePath);
|
||||
|
||||
private:
|
||||
WellData readJsonWellData(const QString& filePath);
|
||||
WellMetaData readJsonWellMetaData(const QString& filePath);
|
||||
WellData readAsciiWellData(const QString& filePath, size_t indexInFile);
|
||||
WellMetaData readAsciiWellMetaData(const QString& filePath, size_t indexInFile);
|
||||
void readAllAsciiWellData(const QString& filePath);
|
||||
|
||||
inline bool isJsonFile(const QString& filePath);
|
||||
|
||||
std::map<QString, std::vector<RifWellPathImporter::WellData> > m_fileNameToWellDataGroupMap;
|
||||
};
|
@ -20,13 +20,12 @@
|
||||
|
||||
#include "RimWellPath.h"
|
||||
|
||||
#include "RifJsonEncodeDecode.h"
|
||||
#include "RifWellPathImporter.h"
|
||||
|
||||
#include "RigWellPath.h"
|
||||
|
||||
#include "RimMainPlotCollection.h"
|
||||
#include "RimProject.h"
|
||||
#include "RimProject.h"
|
||||
#include "RimTools.h"
|
||||
#include "RimWellLogFile.h"
|
||||
#include "RimWellLogPlotCollection.h"
|
||||
@ -203,27 +202,28 @@ caf::PdmFieldHandle* RimWellPath::objectToggleField()
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Read JSON or ascii file containing well path data
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RimWellPath::readWellPathFile(QString* errorMessage, RifWellPathAsciiFileReader* asciiReader)
|
||||
bool RimWellPath::readWellPathFile(QString* errorMessage, RifWellPathImporter* wellPathImporter)
|
||||
{
|
||||
QFileInfo fileInf(filepath());
|
||||
|
||||
if (fileInf.isFile() && fileInf.exists())
|
||||
if (wellPathImporter->canReadFile(filepath()))
|
||||
{
|
||||
if (fileInf.suffix().compare("json") == 0)
|
||||
{
|
||||
this->readJsonWellPathFile();
|
||||
}
|
||||
else
|
||||
{
|
||||
this->readAsciiWellPathFile(asciiReader);
|
||||
}
|
||||
RifWellPathImporter::WellData wellData = wellPathImporter->readWellData(filepath());
|
||||
RifWellPathImporter::WellMetaData wellMetaData = wellPathImporter->readWellMetaData(filepath());
|
||||
// General well info
|
||||
|
||||
name = wellData.m_name;
|
||||
id = wellMetaData.m_id;
|
||||
sourceSystem = wellMetaData.m_sourceSystem;
|
||||
utmZone = wellMetaData.m_utmZone;
|
||||
updateUser = wellMetaData.m_updateUser;
|
||||
setSurveyType(wellMetaData.m_surveyType);
|
||||
updateDate = wellMetaData.m_updateDate.toString("d MMMM yyyy");
|
||||
|
||||
m_wellPath = wellData.m_wellPathGeometry;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (errorMessage) (*errorMessage) = "Could not find the well path file: " + filepath();
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -236,69 +236,6 @@ void RimWellPath::setWellPathGeometry(RigWellPath* wellPathModel)
|
||||
m_wellPath = wellPathModel;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Read JSON file containing well path data
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimWellPath::readJsonWellPathFile()
|
||||
{
|
||||
RigWellPath* wellPathGeom = new RigWellPath();
|
||||
ResInsightInternalJson::JsonReader jsonReader;
|
||||
QMap<QString, QVariant> jsonMap = jsonReader.decodeFile(filepath);
|
||||
|
||||
// General well info
|
||||
|
||||
name = jsonMap["name"].toString();
|
||||
id = jsonMap["id"].toString();
|
||||
sourceSystem = jsonMap["sourceSystem"].toString();
|
||||
utmZone = jsonMap["utmZone"].toString();
|
||||
updateUser = jsonMap["updateUser"].toString();
|
||||
|
||||
setSurveyType(jsonMap["surveyType"].toString());
|
||||
|
||||
// Convert updateDate from the following format:
|
||||
// "Number of milliseconds elapsed since midnight Coordinated Universal Time (UTC)
|
||||
// of January 1, 1970, not counting leap seconds"
|
||||
|
||||
QString updateDateStr = jsonMap["updateDate"].toString().trimmed();
|
||||
uint updateDateUint = updateDateStr.toULongLong() / 1000; // should be within 32 bit, maximum number is 4294967295 which corresponds to year 2106
|
||||
QDateTime updateDateTime;
|
||||
updateDateTime.setTime_t(updateDateUint);
|
||||
|
||||
updateDate = updateDateTime.toString("d MMMM yyyy");
|
||||
|
||||
// Well path points
|
||||
|
||||
double datumElevation = jsonMap["datumElevation"].toDouble();
|
||||
wellPathGeom->setDatumElevation(datumElevation);
|
||||
|
||||
QList<QVariant> pathList = jsonMap["path"].toList();
|
||||
foreach (QVariant point, pathList)
|
||||
{
|
||||
QMap<QString, QVariant> coordinateMap = point.toMap();
|
||||
cvf::Vec3d vec3d(coordinateMap["east"].toDouble(), coordinateMap["north"].toDouble(), -(coordinateMap["tvd"].toDouble() - datumElevation));
|
||||
wellPathGeom->m_wellPathPoints.push_back(vec3d);
|
||||
|
||||
double measuredDepth = coordinateMap["md"].toDouble();
|
||||
wellPathGeom->m_measuredDepths.push_back(measuredDepth);
|
||||
}
|
||||
|
||||
//jsonReader.dumpToFile(wellPathGeom->m_wellPathPoints, "c:\\temp\\jsonpoints.txt");
|
||||
setWellPathGeometry(wellPathGeom);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimWellPath::readAsciiWellPathFile(RifWellPathAsciiFileReader* asciiReader)
|
||||
{
|
||||
CVF_ASSERT(asciiReader);
|
||||
|
||||
RifWellPathAsciiFileReader::WellData wpData = asciiReader->readWellData(filepath(), wellPathIndexInFile());
|
||||
this->name = wpData.m_name;
|
||||
|
||||
setWellPathGeometry(wpData.m_wellPathGeometry.p());
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
@ -32,7 +32,7 @@
|
||||
#include "cafPdmChildArrayField.h"
|
||||
#include "cvfObject.h"
|
||||
|
||||
class RifWellPathAsciiFileReader;
|
||||
class RifWellPathImporter;
|
||||
class RigWellPath;
|
||||
class RimProject;
|
||||
class RimWellLogFile;
|
||||
@ -77,7 +77,7 @@ public:
|
||||
|
||||
RivWellPathPartMgr* partMgr();
|
||||
|
||||
bool readWellPathFile(QString * errorMessage, RifWellPathAsciiFileReader* asciiReader);
|
||||
bool readWellPathFile(QString * errorMessage, RifWellPathImporter* wellPathImporter);
|
||||
void updateFilePathsFromProjectPath(const QString& newProjectPath, const QString& oldProjectPath);
|
||||
|
||||
double combinedScaleFactor() const;
|
||||
@ -85,8 +85,6 @@ public:
|
||||
private:
|
||||
|
||||
void setWellPathGeometry(RigWellPath* wellPathModel);
|
||||
void readJsonWellPathFile();
|
||||
void readAsciiWellPathFile(RifWellPathAsciiFileReader* asciiReader);
|
||||
QString surveyType() { return m_surveyType; }
|
||||
void setSurveyType(QString surveyType);
|
||||
|
||||
|
@ -33,6 +33,8 @@
|
||||
|
||||
#include "RivWellPathCollectionPartMgr.h"
|
||||
|
||||
#include "RifWellPathImporter.h"
|
||||
|
||||
#include "cafPdmUiEditorHandle.h"
|
||||
#include "cafProgressInfo.h"
|
||||
|
||||
@ -87,7 +89,7 @@ RimWellPathCollection::RimWellPathCollection()
|
||||
|
||||
m_wellPathCollectionPartManager = new RivWellPathCollectionPartMgr(this);
|
||||
|
||||
m_asciiFileReader = new RifWellPathAsciiFileReader;
|
||||
m_wellPathImporter = new RifWellPathImporter;
|
||||
}
|
||||
|
||||
|
||||
@ -97,7 +99,7 @@ RimWellPathCollection::RimWellPathCollection()
|
||||
RimWellPathCollection::~RimWellPathCollection()
|
||||
{
|
||||
wellPaths.deleteAllChildObjects();
|
||||
delete m_asciiFileReader;
|
||||
delete m_wellPathImporter;
|
||||
}
|
||||
|
||||
|
||||
@ -122,7 +124,7 @@ void RimWellPathCollection::readWellPathFiles()
|
||||
if (!wellPaths[wpIdx]->filepath().isEmpty())
|
||||
{
|
||||
QString errorMessage;
|
||||
if (!wellPaths[wpIdx]->readWellPathFile(&errorMessage, this->asciiFileReader()))
|
||||
if (!wellPaths[wpIdx]->readWellPathFile(&errorMessage, m_wellPathImporter))
|
||||
{
|
||||
QMessageBox::warning(RiuMainWindow::instance(),
|
||||
"File open error",
|
||||
@ -198,7 +200,7 @@ void RimWellPathCollection::addWellPaths( QStringList filePaths )
|
||||
else
|
||||
{
|
||||
// Create Well path objects for all the paths in the assumed ascii file
|
||||
size_t wellPathCount = this->m_asciiFileReader->wellDataCount(filePath);
|
||||
size_t wellPathCount = m_wellPathImporter->wellDataCount(filePath);
|
||||
for (size_t i = 0; i < wellPathCount; ++i)
|
||||
{
|
||||
RimWellPath* wellPath = new RimWellPath();
|
||||
@ -224,7 +226,7 @@ void RimWellPathCollection::readAndAddWellPaths(std::vector<RimWellPath*>& wellP
|
||||
for (size_t wpIdx = 0; wpIdx < wellPathArray.size(); wpIdx++)
|
||||
{
|
||||
RimWellPath* wellPath = wellPathArray[wpIdx];
|
||||
wellPath->readWellPathFile(NULL, this->asciiFileReader());
|
||||
wellPath->readWellPathFile(NULL, m_wellPathImporter);
|
||||
|
||||
progress.setProgressDescription(QString("Reading file %1").arg(wellPath->name));
|
||||
|
||||
@ -234,7 +236,7 @@ void RimWellPathCollection::readAndAddWellPaths(std::vector<RimWellPath*>& wellP
|
||||
{
|
||||
existingWellPath->filepath = wellPath->filepath;
|
||||
existingWellPath->wellPathIndexInFile = wellPath->wellPathIndexInFile;
|
||||
existingWellPath->readWellPathFile(NULL, this->asciiFileReader());
|
||||
existingWellPath->readWellPathFile(NULL, m_wellPathImporter);
|
||||
|
||||
delete wellPath;
|
||||
}
|
||||
@ -345,7 +347,7 @@ void RimWellPathCollection::deleteAllWellPaths()
|
||||
{
|
||||
wellPaths.deleteAllChildObjects();
|
||||
|
||||
m_asciiFileReader->clear();
|
||||
m_wellPathImporter->clear();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@ -369,7 +371,7 @@ void RimWellPathCollection::removeWellPath(RimWellPath* wellPath)
|
||||
{
|
||||
// One file can have multiple well paths
|
||||
// If no other well paths are referencing the filepath, remove cached data from the file reader
|
||||
m_asciiFileReader->removeFilePath(wellPath->filepath);
|
||||
m_wellPathImporter->removeFilePath(wellPath->filepath);
|
||||
}
|
||||
}
|
||||
|
||||
@ -390,211 +392,3 @@ void RimWellPathCollection::sortWellsByName()
|
||||
{
|
||||
std::sort(wellPaths.begin(), wellPaths.end(), lessWellPath);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RifWellPathAsciiFileReader::readAllWellData(QString filePath)
|
||||
{
|
||||
std::map<QString, std::vector<WellData> >::iterator it = m_fileNameToWellDataGroupMap.find(filePath);
|
||||
|
||||
// If we have the file in the map, assume it is already read.
|
||||
if (it != m_fileNameToWellDataGroupMap.end())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Create the data container
|
||||
std::vector<WellData>& fileWellDataArray = m_fileNameToWellDataGroupMap[filePath];
|
||||
|
||||
std::ifstream stream(filePath.toLatin1().data());
|
||||
double x(HUGE_VAL), y(HUGE_VAL), tvd(HUGE_VAL), md(HUGE_VAL);
|
||||
|
||||
bool hasReadWellPointInCurrentWell = false;
|
||||
|
||||
while (stream.good())
|
||||
{
|
||||
// First check if we can read a number
|
||||
stream >> x;
|
||||
if (stream.good()) // If we can, assume this line is a well point entry
|
||||
{
|
||||
stream >> y >> tvd >> md;
|
||||
if (!stream.good())
|
||||
{
|
||||
// -999 or otherwise to few numbers before some word
|
||||
if (x != -999)
|
||||
{
|
||||
// Error in file: missing numbers at this line
|
||||
|
||||
}
|
||||
stream.clear();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!fileWellDataArray.size())
|
||||
{
|
||||
fileWellDataArray.push_back(WellData());
|
||||
fileWellDataArray.back().m_wellPathGeometry = new RigWellPath();
|
||||
}
|
||||
|
||||
cvf::Vec3d wellPoint(x, y, -tvd);
|
||||
fileWellDataArray.back().m_wellPathGeometry->m_wellPathPoints.push_back(wellPoint);
|
||||
fileWellDataArray.back().m_wellPathGeometry->m_measuredDepths.push_back(md);
|
||||
|
||||
x = HUGE_VAL;
|
||||
y = HUGE_VAL;
|
||||
tvd = HUGE_VAL;
|
||||
md = HUGE_VAL;
|
||||
|
||||
hasReadWellPointInCurrentWell = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Could not read one double.
|
||||
// we assume there is a comment line or a well path description
|
||||
stream.clear();
|
||||
|
||||
std::string line;
|
||||
std::getline(stream, line, '\n');
|
||||
// Skip possible comment lines (-- is used in eclipse, so Haakon Høgstøl considered it smart to skip these here as well)
|
||||
// The first "-" is eaten by the stream >> x above
|
||||
if (line.find("-") == 0 || line.find("#") == 0)
|
||||
{
|
||||
// Comment line, just ignore
|
||||
}
|
||||
else
|
||||
{
|
||||
// Find the first and the last position of any quotes (and do not care to match quotes)
|
||||
size_t quoteStartIdx = line.find_first_of("'`´’‘");
|
||||
size_t quoteEndIdx = line.find_last_of("'`´’‘");
|
||||
|
||||
std::string wellName;
|
||||
bool haveAPossibleWellStart = false;
|
||||
|
||||
if (quoteStartIdx < line.size() -1)
|
||||
{
|
||||
// Extract the text between the quotes
|
||||
wellName = line.substr(quoteStartIdx + 1, quoteEndIdx - 1 - quoteStartIdx);
|
||||
haveAPossibleWellStart = true;
|
||||
}
|
||||
else if (quoteStartIdx > line.length())
|
||||
{
|
||||
// We did not find any quotes
|
||||
|
||||
// Supported alternatives are
|
||||
// name <WellNameA>
|
||||
// wellname: <WellNameA>
|
||||
std::string lineLowerCase = line;
|
||||
transform(lineLowerCase.begin(), lineLowerCase.end(), lineLowerCase.begin(), ::tolower);
|
||||
|
||||
std::string tokenName = "name";
|
||||
std::size_t foundNameIdx = lineLowerCase.find(tokenName);
|
||||
if (foundNameIdx != std::string::npos)
|
||||
{
|
||||
std::string tokenColon = ":";
|
||||
std::size_t foundColonIdx = lineLowerCase.find(tokenColon, foundNameIdx);
|
||||
if (foundColonIdx != std::string::npos)
|
||||
{
|
||||
wellName = line.substr(foundColonIdx + tokenColon.length());
|
||||
}
|
||||
else
|
||||
{
|
||||
wellName = line.substr(foundNameIdx + tokenName.length());
|
||||
}
|
||||
|
||||
haveAPossibleWellStart = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Interpret the whole line as the well name.
|
||||
|
||||
QString name = line.c_str();
|
||||
if (!name.trimmed().isEmpty())
|
||||
{
|
||||
wellName = name.trimmed().toStdString();
|
||||
haveAPossibleWellStart = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (haveAPossibleWellStart)
|
||||
{
|
||||
// Create a new Well data if we have read some data into the previous one.
|
||||
// if not, just overwrite the name
|
||||
if (hasReadWellPointInCurrentWell || fileWellDataArray.size() == 0)
|
||||
{
|
||||
fileWellDataArray.push_back(WellData());
|
||||
fileWellDataArray.back().m_wellPathGeometry = new RigWellPath();
|
||||
}
|
||||
|
||||
QString name = wellName.c_str();
|
||||
if (!name.trimmed().isEmpty())
|
||||
{
|
||||
// Do not overwrite the name aquired from a line above, if this line is empty
|
||||
fileWellDataArray.back().m_name = name.trimmed();
|
||||
}
|
||||
hasReadWellPointInCurrentWell = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RifWellPathAsciiFileReader::WellData RifWellPathAsciiFileReader::readWellData(QString filePath, int indexInFile)
|
||||
{
|
||||
this->readAllWellData(filePath);
|
||||
|
||||
std::map<QString, std::vector<WellData> >::iterator it = m_fileNameToWellDataGroupMap.find(filePath);
|
||||
|
||||
CVF_ASSERT(it != m_fileNameToWellDataGroupMap.end());
|
||||
|
||||
if (indexInFile < static_cast<int>(it->second.size()))
|
||||
{
|
||||
return it->second[indexInFile];
|
||||
}
|
||||
else
|
||||
{
|
||||
// Error : The ascii well path file does not contain that many well paths
|
||||
return WellData();
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
size_t RifWellPathAsciiFileReader::wellDataCount(QString filePath)
|
||||
{
|
||||
std::map<QString, std::vector<WellData> >::iterator it = m_fileNameToWellDataGroupMap.find(filePath);
|
||||
|
||||
// If we have the file in the map, assume it is already read.
|
||||
if (it != m_fileNameToWellDataGroupMap.end())
|
||||
{
|
||||
return it->second.size();
|
||||
}
|
||||
|
||||
this->readAllWellData(filePath);
|
||||
it = m_fileNameToWellDataGroupMap.find(filePath);
|
||||
CVF_ASSERT(it != m_fileNameToWellDataGroupMap.end());
|
||||
|
||||
return it->second.size();;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RifWellPathAsciiFileReader::clear()
|
||||
{
|
||||
m_fileNameToWellDataGroupMap.clear();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RifWellPathAsciiFileReader::removeFilePath(const QString& filePath)
|
||||
{
|
||||
m_fileNameToWellDataGroupMap.erase(filePath);
|
||||
}
|
||||
|
@ -34,7 +34,7 @@
|
||||
#include <QString>
|
||||
|
||||
class RivWellPathCollectionPartMgr;
|
||||
class RifWellPathAsciiFileReader;
|
||||
class RifWellPathImporter;
|
||||
class RimWellPath;
|
||||
class RimProject;
|
||||
class RigWellPath;
|
||||
@ -84,8 +84,6 @@ public:
|
||||
void removeWellPath(RimWellPath* wellPath);
|
||||
void deleteAllWellPaths();
|
||||
|
||||
RifWellPathAsciiFileReader* asciiFileReader() {return m_asciiFileReader;}
|
||||
|
||||
RimWellPath* wellPathByName(const QString& wellPathName) const;
|
||||
void addWellLogs(const QStringList& filePaths);
|
||||
|
||||
@ -104,31 +102,5 @@ private:
|
||||
|
||||
cvf::ref<RivWellPathCollectionPartMgr> m_wellPathCollectionPartManager;
|
||||
|
||||
RifWellPathAsciiFileReader* m_asciiFileReader;
|
||||
};
|
||||
|
||||
|
||||
//==================================================================================================
|
||||
///
|
||||
///
|
||||
//==================================================================================================
|
||||
class RifWellPathAsciiFileReader
|
||||
{
|
||||
public:
|
||||
struct WellData
|
||||
{
|
||||
QString m_name;
|
||||
cvf::ref<RigWellPath> m_wellPathGeometry;
|
||||
};
|
||||
|
||||
WellData readWellData(QString filePath, int indexInFile);
|
||||
size_t wellDataCount(QString filePath);
|
||||
|
||||
void clear();
|
||||
void removeFilePath(const QString& filePath);
|
||||
|
||||
private:
|
||||
void readAllWellData(QString filePath);
|
||||
|
||||
std::map<QString, std::vector<WellData> > m_fileNameToWellDataGroupMap;
|
||||
RifWellPathImporter* m_wellPathImporter;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user