mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
#4480 Add code for import of layer_zone_table.txt and enable manual import.
This commit is contained in:
@@ -56,7 +56,7 @@ void RicImportFormationNamesFeature::onActionTriggered(bool isChecked)
|
||||
{
|
||||
RiaApplication* app = RiaApplication::instance();
|
||||
QString defaultDir = app->lastUsedDialogDirectory("BINARY_GRID");
|
||||
QStringList fileNames = QFileDialog::getOpenFileNames(Riu3DMainWindowTools::mainWindowWidget(), "Import Formation Names", defaultDir, "Formation Names description File (*.lyr);;All Files (*.*)");
|
||||
QStringList fileNames = QFileDialog::getOpenFileNames(Riu3DMainWindowTools::mainWindowWidget(), "Import Formation Names", defaultDir, "Formation Names description File (*.lyr);;FMU Layer Zone Table(layer_zone_table.txt);;All Files (*.*)");
|
||||
|
||||
if (fileNames.isEmpty()) return;
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
#include "Rim3dView.h"
|
||||
#include "RimWellLogTrack.h"
|
||||
|
||||
#include "cafAssert.h"
|
||||
#include "cafPdmUiFilePathEditor.h"
|
||||
|
||||
#include <QFile>
|
||||
@@ -79,14 +80,6 @@ void RimFormationNames::initAfterRead()
|
||||
updateUiTreeName();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimFormationNames::updateUiTreeName()
|
||||
{
|
||||
this->uiCapability()->setUiName(fileNameWoPath());
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -156,8 +149,43 @@ void RimFormationNames::readFormationNamesFile(QString * errorMessage)
|
||||
}
|
||||
|
||||
m_formationNamesData = new RigFormationNames;
|
||||
|
||||
QTextStream stream(&dataFile);
|
||||
|
||||
QFileInfo fileInfo(m_formationNamesFileName());
|
||||
|
||||
if (fileInfo.fileName() == "layer_zone_table.txt")
|
||||
{
|
||||
readFmuFormationNameFile(stream, errorMessage);
|
||||
}
|
||||
else
|
||||
{
|
||||
CAF_ASSERT(fileInfo.suffix() == "lyr");
|
||||
readLyrFormationNameFile(stream, errorMessage);
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimFormationNames::updateFilePathsFromProjectPath(const QString& newProjectPath, const QString& oldProjectPath)
|
||||
{
|
||||
m_formationNamesFileName = RimTools::relocateFile(m_formationNamesFileName(), newProjectPath, oldProjectPath, nullptr, nullptr);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimFormationNames::updateUiTreeName()
|
||||
{
|
||||
this->uiCapability()->setUiName(fileNameWoPath());
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimFormationNames::readLyrFormationNameFile(QTextStream& stream, QString* errorMessage)
|
||||
{
|
||||
int lineNumber = 1;
|
||||
while (!stream.atEnd())
|
||||
{
|
||||
@@ -194,7 +222,8 @@ void RimFormationNames::readFormationNamesFile(QString * errorMessage)
|
||||
continue;
|
||||
}
|
||||
|
||||
int tmp = startK; startK = tmp < endK ? tmp : endK;
|
||||
int tmp = startK;
|
||||
startK = tmp < endK ? tmp : endK;
|
||||
endK = tmp > endK ? tmp : endK;
|
||||
|
||||
m_formationNamesData->appendFormationRange(formationName, startK - 1, endK - 1);
|
||||
@@ -225,8 +254,58 @@ void RimFormationNames::readFormationNamesFile(QString * errorMessage)
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimFormationNames::updateFilePathsFromProjectPath(const QString& newProjectPath, const QString& oldProjectPath)
|
||||
void RimFormationNames::readFmuFormationNameFile(QTextStream& stream, QString* errorMessage)
|
||||
{
|
||||
m_formationNamesFileName = RimTools::relocateFile(m_formationNamesFileName(), newProjectPath, oldProjectPath, nullptr, nullptr);
|
||||
int lineNumber = 1;
|
||||
|
||||
QString currentFormationName;
|
||||
int startK = -1;
|
||||
int endK = -1;
|
||||
|
||||
while (!stream.atEnd())
|
||||
{
|
||||
QString line = stream.readLine();
|
||||
if (line.isNull())
|
||||
{
|
||||
// Make sure we append the last formation
|
||||
if (!currentFormationName.isEmpty())
|
||||
{
|
||||
m_formationNamesData->appendFormationRange(currentFormationName, startK - 1, endK - 1);
|
||||
}
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
QTextStream lineStream(&line);
|
||||
|
||||
double kLayer;
|
||||
QString formationName;
|
||||
|
||||
lineStream >> kLayer >> formationName;
|
||||
|
||||
if (lineStream.status() != QTextStream::Ok)
|
||||
{
|
||||
*errorMessage = QString("Failed to parse line %1 of '%2'").arg(lineNumber).arg(m_formationNamesFileName());
|
||||
return;
|
||||
}
|
||||
|
||||
if (formationName != currentFormationName)
|
||||
{
|
||||
// Append previous formation
|
||||
if (!currentFormationName.isEmpty())
|
||||
{
|
||||
m_formationNamesData->appendFormationRange(currentFormationName, startK - 1, endK - 1);
|
||||
}
|
||||
|
||||
// Start new formation
|
||||
currentFormationName = formationName;
|
||||
startK = kLayer;
|
||||
endK = kLayer;
|
||||
}
|
||||
else
|
||||
{
|
||||
endK = kLayer;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -23,6 +23,8 @@
|
||||
|
||||
class RigFormationNames;
|
||||
|
||||
class QTextStream;
|
||||
|
||||
//==================================================================================================
|
||||
///
|
||||
//==================================================================================================
|
||||
@@ -50,7 +52,10 @@ protected:
|
||||
|
||||
private:
|
||||
void updateUiTreeName();
|
||||
void readLyrFormationNameFile(QTextStream& stream, QString* errorMessage);
|
||||
void readFmuFormationNameFile(QTextStream& stream, QString* errorMessage);
|
||||
|
||||
private:
|
||||
caf::PdmField<QString> m_formationNamesFileName;
|
||||
|
||||
cvf::ref<RigFormationNames> m_formationNamesData;
|
||||
|
||||
Reference in New Issue
Block a user