mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
WellPaths: Added support for mulitple paths in one ascii file.
p4#: 21980
This commit is contained in:
parent
636fd39c2f
commit
1ea5a49471
@ -85,6 +85,8 @@ RimWellPath::RimWellPath()
|
||||
|
||||
CAF_PDM_InitField(&filepath, "WellPathFilepath", QString(""), "Filepath", "", "", "");
|
||||
filepath.setUiReadOnly(true);
|
||||
CAF_PDM_InitField(&wellPathIndexInFile, "WellPathNumberInFile", -1, "Well Number in file", "", "", "");
|
||||
wellPathIndexInFile.setUiReadOnly(true);
|
||||
|
||||
CAF_PDM_InitField(&showWellPathLabel, "ShowWellPathLabel", true, "Show well path label", "", "", "");
|
||||
|
||||
@ -222,64 +224,12 @@ void RimWellPath::readJsonWellPathFile()
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Read a well path ascii file in the format specified by Lars Hustoft
|
||||
/// Except that we here only handle one well path in one file.
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimWellPath::readAsciiWellPathFile()
|
||||
{
|
||||
RigWellPath* wellPathGeom = new RigWellPath();
|
||||
RimWellPathAsciiFileReader::WellData wpData = m_wellPathCollection->asciiFileReader()->readWellData(filepath(), wellPathIndexInFile());
|
||||
this->name = wpData.m_name;
|
||||
|
||||
std::ifstream stream(filepath().toLatin1().data());
|
||||
double x(HUGE_VAL), y(HUGE_VAL), tvd(HUGE_VAL), md(HUGE_VAL);
|
||||
bool foundWellName = false;
|
||||
while(stream.good())
|
||||
{
|
||||
stream >> x;
|
||||
if (stream.good())
|
||||
{
|
||||
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
|
||||
{
|
||||
cvf::Vec3d wellPoint(x, y, -tvd);
|
||||
wellPathGeom->m_wellPathPoints.push_back(wellPoint);
|
||||
x = HUGE_VAL;
|
||||
y = HUGE_VAL;
|
||||
tvd = HUGE_VAL;
|
||||
md = HUGE_VAL;
|
||||
}
|
||||
}
|
||||
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');
|
||||
size_t quoteStartIdx = line.find_first_of("'`´’‘");
|
||||
size_t quoteEndIdx = line.find_last_of("'`´’‘");
|
||||
if (quoteStartIdx < line.size() -1 )
|
||||
{
|
||||
// If we have already read a well name stop parsing the file,
|
||||
// as the rest is a new well which we cant handle right now.
|
||||
if (foundWellName) break;
|
||||
|
||||
// Extract the text between the quotes
|
||||
std::string wellName = line.substr(quoteStartIdx + 1, quoteEndIdx - 1 - quoteStartIdx);
|
||||
this->name = wellName.c_str();
|
||||
foundWellName = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
setWellPathGeometry(wellPathGeom);
|
||||
setWellPathGeometry(wpData.m_wellPathGeometry.p());
|
||||
}
|
||||
|
@ -52,7 +52,7 @@ public:
|
||||
caf::PdmField<QString> name;
|
||||
|
||||
caf::PdmField<QString> filepath;
|
||||
//caf::PdmField<int> wellPathIndexInFile; // -1 means all, but is not to be used when saving.
|
||||
caf::PdmField<int> wellPathIndexInFile; // -1 means none.
|
||||
|
||||
caf::PdmField<bool> showWellPathLabel;
|
||||
|
||||
@ -74,7 +74,6 @@ private:
|
||||
QString surveyType() { return m_surveyType; }
|
||||
void setSurveyType(QString surveyType);
|
||||
|
||||
//RimWellPath* generateRimWellPathForFilePart(int wellPathNumberOnFile);
|
||||
|
||||
caf::PdmField<QString> id;
|
||||
caf::PdmField<QString> sourceSystem;
|
||||
|
@ -39,6 +39,7 @@
|
||||
#include "RimWellCollection.h"
|
||||
#include "RimOilField.h"
|
||||
#include "RimAnalysisModels.h"
|
||||
#include <fstream>
|
||||
|
||||
namespace caf
|
||||
{
|
||||
@ -77,6 +78,8 @@ RimWellPathCollection::RimWellPathCollection()
|
||||
|
||||
m_wellPathCollectionPartManager = new RivWellPathCollectionPartMgr(this);
|
||||
m_project = NULL;
|
||||
|
||||
m_asciiFileReader = new RimWellPathAsciiFileReader;
|
||||
}
|
||||
|
||||
|
||||
@ -86,6 +89,7 @@ RimWellPathCollection::RimWellPathCollection()
|
||||
RimWellPathCollection::~RimWellPathCollection()
|
||||
{
|
||||
wellPaths.deleteAllChildObjects();
|
||||
delete m_asciiFileReader;
|
||||
}
|
||||
|
||||
|
||||
@ -152,13 +156,149 @@ void RimWellPathCollection::addWellPaths( QStringList filePaths )
|
||||
|
||||
if (!alreadyOpen)
|
||||
{
|
||||
RimWellPath* wellPath = new RimWellPath();
|
||||
wellPath->setProject(m_project);
|
||||
wellPath->setCollection(this);
|
||||
wellPath->filepath = filePath;
|
||||
wellPaths.push_back(wellPath);
|
||||
if (filePath.endsWith(".json"), Qt::CaseInsensitive)
|
||||
{
|
||||
RimWellPath* wellPath = new RimWellPath();
|
||||
wellPath->setProject(m_project);
|
||||
wellPath->setCollection(this);
|
||||
wellPath->filepath = filePath;
|
||||
wellPaths.push_back(wellPath);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Create Well path objects for all the paths in the assumed ascii file
|
||||
size_t wellPathCount = this->m_asciiFileReader->wellDataCount(filePath);
|
||||
for (size_t i = 0; i < wellPathCount; ++i)
|
||||
{
|
||||
RimWellPath* wellPath = new RimWellPath();
|
||||
wellPath->setProject(m_project);
|
||||
wellPath->setCollection(this);
|
||||
wellPath->filepath = filePath;
|
||||
wellPath->wellPathIndexInFile = static_cast<int>(i);
|
||||
wellPaths.push_back(wellPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
readWellPathFiles();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimWellPathAsciiFileReader::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);
|
||||
|
||||
while(stream.good())
|
||||
{
|
||||
stream >> x;
|
||||
if (stream.good())
|
||||
{
|
||||
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);
|
||||
|
||||
x = HUGE_VAL;
|
||||
y = HUGE_VAL;
|
||||
tvd = HUGE_VAL;
|
||||
md = HUGE_VAL;
|
||||
}
|
||||
}
|
||||
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');
|
||||
size_t quoteStartIdx = line.find_first_of("'`´’‘");
|
||||
size_t quoteEndIdx = line.find_last_of("'`´’‘");
|
||||
|
||||
if (quoteStartIdx < line.size() -1 )
|
||||
{
|
||||
// Create a new Well data
|
||||
fileWellDataArray.push_back(WellData());
|
||||
fileWellDataArray.back().m_wellPathGeometry = new RigWellPath();
|
||||
|
||||
// Extract the text between the quotes
|
||||
std::string wellName = line.substr(quoteStartIdx + 1, quoteEndIdx - 1 - quoteStartIdx);
|
||||
fileWellDataArray.back().m_name = wellName.c_str();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RimWellPathAsciiFileReader::WellData RimWellPathAsciiFileReader::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 < it->second.size())
|
||||
{
|
||||
return it->second[indexInFile];
|
||||
}
|
||||
else
|
||||
{
|
||||
// Error : The ascii well path file does not contain that many wellpaths
|
||||
return WellData();
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
size_t RimWellPathAsciiFileReader::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();;
|
||||
}
|
||||
|
@ -27,6 +27,7 @@
|
||||
#include "RimWellPath.h"
|
||||
|
||||
class RivWellPathCollectionPartMgr;
|
||||
class RimWellPathAsciiFileReader;
|
||||
|
||||
//==================================================================================================
|
||||
///
|
||||
@ -60,14 +61,38 @@ public:
|
||||
|
||||
caf::PdmPointersField<RimWellPath*> wellPaths;
|
||||
|
||||
virtual void fieldChangedByUi( const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue );
|
||||
|
||||
|
||||
RivWellPathCollectionPartMgr* wellPathCollectionPartMgr() { return m_wellPathCollectionPartManager.p(); }
|
||||
|
||||
void readWellPathFiles();
|
||||
void addWellPaths(QStringList filePaths);
|
||||
RimWellPathAsciiFileReader* asciiFileReader() {return m_asciiFileReader;}
|
||||
|
||||
virtual void fieldChangedByUi( const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue );
|
||||
|
||||
private:
|
||||
caf::PdmPointer<RimProject> m_project;
|
||||
cvf::ref<RivWellPathCollectionPartMgr> m_wellPathCollectionPartManager;
|
||||
|
||||
RimWellPathAsciiFileReader* m_asciiFileReader;
|
||||
};
|
||||
|
||||
|
||||
class RimWellPathAsciiFileReader
|
||||
{
|
||||
public:
|
||||
struct WellData
|
||||
{
|
||||
QString m_name;
|
||||
cvf::ref<RigWellPath> m_wellPathGeometry;
|
||||
};
|
||||
|
||||
WellData readWellData(QString filePath, int indexInFile);
|
||||
size_t wellDataCount(QString filePath);
|
||||
|
||||
private:
|
||||
|
||||
void readAllWellData(QString filePath);
|
||||
|
||||
std::map<QString, std::vector<WellData> > m_fileNameToWellDataGroupMap;
|
||||
};
|
Loading…
Reference in New Issue
Block a user