mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
#5875 Remove duplicated code: import formation names using RifColorLegendData.
This commit is contained in:
parent
6cb86d4792
commit
20eff6f5d3
ApplicationCode/ProjectDataModel
@ -24,6 +24,9 @@
|
||||
#include "RimCase.h"
|
||||
#include "RimTools.h"
|
||||
#include "RimWellLogTrack.h"
|
||||
|
||||
#include "RifColorLegendData.h"
|
||||
|
||||
#include "RiuPlotMainWindowTools.h"
|
||||
|
||||
#include "cafAssert.h"
|
||||
@ -145,28 +148,7 @@ void RimFormationNames::updateConnectedViews()
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimFormationNames::readFormationNamesFile( QString* errorMessage )
|
||||
{
|
||||
QFile dataFile( m_formationNamesFileName().path() );
|
||||
|
||||
if ( !dataFile.open( QFile::ReadOnly ) )
|
||||
{
|
||||
if ( errorMessage )
|
||||
( *errorMessage ) += "Could not open the File: " + ( m_formationNamesFileName().path() ) + "\n";
|
||||
return;
|
||||
}
|
||||
|
||||
m_formationNamesData = new RigFormationNames;
|
||||
QTextStream stream( &dataFile );
|
||||
|
||||
QFileInfo fileInfo( m_formationNamesFileName().path() );
|
||||
|
||||
if ( fileInfo.fileName() == RimFormationNames::layerZoneTableFileName() )
|
||||
{
|
||||
readFmuFormationNameFile( stream, errorMessage );
|
||||
}
|
||||
else
|
||||
{
|
||||
readLyrFormationNameFile( stream, errorMessage );
|
||||
}
|
||||
m_formationNamesData = RifColorLegendData::readFormationNamesFile( m_formationNamesFileName().path(), errorMessage );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@ -193,142 +175,3 @@ void RimFormationNames::updateUiTreeName()
|
||||
{
|
||||
this->uiCapability()->setUiName( fileNameWoPath() );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimFormationNames::readLyrFormationNameFile( QTextStream& stream, QString* errorMessage )
|
||||
{
|
||||
int lineNumber = 1;
|
||||
while ( !stream.atEnd() )
|
||||
{
|
||||
QString line = stream.readLine();
|
||||
QStringList lineSegs = line.split( "'", QString::KeepEmptyParts );
|
||||
|
||||
if ( lineSegs.size() == 0 ) continue; // Empty line
|
||||
if ( lineSegs.size() == 1 ) continue; // No name present. Comment line ?
|
||||
if ( lineSegs.size() == 2 )
|
||||
{
|
||||
if ( errorMessage ) ( *errorMessage ) += "Missing quote on line : " + QString::number( lineNumber ) + "\n";
|
||||
continue; // One quote present
|
||||
}
|
||||
|
||||
if ( lineSegs.size() == 3 ) // Normal case
|
||||
{
|
||||
if ( lineSegs[0].contains( "--" ) ) continue; // Comment line
|
||||
QString formationName = lineSegs[1];
|
||||
int commentMarkPos = lineSegs[2].indexOf( "--" );
|
||||
QString numberString = lineSegs[2];
|
||||
if ( commentMarkPos >= 0 ) numberString.truncate( commentMarkPos );
|
||||
|
||||
QStringList numberWords = numberString.split( QRegExp( "-" ), QString::SkipEmptyParts );
|
||||
if ( numberWords.size() == 2 )
|
||||
{
|
||||
bool isNumber1 = false;
|
||||
bool isNumber2 = false;
|
||||
int startK = numberWords[0].toInt( &isNumber1 );
|
||||
int endK = numberWords[1].toInt( &isNumber2 );
|
||||
|
||||
if ( !( isNumber2 && isNumber1 ) )
|
||||
{
|
||||
if ( errorMessage )
|
||||
( *errorMessage ) += "Format error on line: " + QString::number( lineNumber ) + "\n";
|
||||
continue;
|
||||
}
|
||||
|
||||
int tmp = startK;
|
||||
startK = tmp < endK ? tmp : endK;
|
||||
endK = tmp > endK ? tmp : endK;
|
||||
|
||||
m_formationNamesData->appendFormationRange( formationName, startK - 1, endK - 1 );
|
||||
}
|
||||
else if ( numberWords.size() == 1 )
|
||||
{
|
||||
bool isNumber1 = false;
|
||||
int kLayerCount = numberWords[0].toInt( &isNumber1 );
|
||||
|
||||
if ( !isNumber1 )
|
||||
{
|
||||
if ( errorMessage )
|
||||
( *errorMessage ) += "Format error on line: " + QString::number( lineNumber ) + "\n";
|
||||
continue;
|
||||
}
|
||||
|
||||
m_formationNamesData->appendFormationRangeHeight( formationName, kLayerCount );
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( errorMessage )
|
||||
( *errorMessage ) += "Format error on line: " + QString::number( lineNumber ) + "\n";
|
||||
}
|
||||
}
|
||||
|
||||
++lineNumber;
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimFormationNames::readFmuFormationNameFile( QTextStream& stream, QString* errorMessage )
|
||||
{
|
||||
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().path() );
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Append previous formation at the end of the stream
|
||||
if ( !currentFormationName.isEmpty() )
|
||||
{
|
||||
m_formationNamesData->appendFormationRange( currentFormationName, startK - 1, endK - 1 );
|
||||
}
|
||||
}
|
||||
|
@ -55,8 +55,6 @@ protected:
|
||||
|
||||
private:
|
||||
void updateUiTreeName();
|
||||
void readLyrFormationNameFile( QTextStream& stream, QString* errorMessage );
|
||||
void readFmuFormationNameFile( QTextStream& stream, QString* errorMessage );
|
||||
|
||||
private:
|
||||
caf::PdmField<caf::FilePath> m_formationNamesFileName;
|
||||
|
Loading…
Reference in New Issue
Block a user