Fixed issue #6034 - Improve INP import : Add support for columns spanning more than one line.

This commit is contained in:
rubenthoms
2020-08-14 17:48:27 +02:00
committed by rubenthoms
parent 523cdc2b7d
commit 3a5ef7fb86
4 changed files with 97 additions and 11 deletions

View File

@@ -66,17 +66,20 @@ RifElementPropertyMetadata RifElementPropertyTableReader::readMetadata( const QS
metadataBlockFound = true;
continue;
}
else if ( line.toUpper().startsWith( "*DISTRIBUTION" ) )
{
metadata.fileName = fileName;
break;
}
if ( !metadataBlockFound ) continue;
if ( !metadataBlockFound || line.startsWith( "*" ) ) continue;
QStringList cols = RifFileParseTools::splitLineAndTrim( line, "," );
QStringList cols = RifFileParseTools::splitLineAndTrim( line, ",", true );
metadata.fileName = fileName;
for ( QString s : cols )
{
metadata.dataColumns.push_back( s );
}
break;
}
closeFile( file );
@@ -110,6 +113,7 @@ void RifElementPropertyTableReader::readData( const RifElementPropertyMetadata*
QTextStream stream( file );
bool dataBlockFound = false;
int lineNo = 0;
QStringList collectedCols;
// Init data vectors
table->elementIds.clear();
@@ -118,22 +122,39 @@ void RifElementPropertyTableReader::readData( const RifElementPropertyMetadata*
while ( !stream.atEnd() )
{
QString line = stream.readLine();
QStringList cols = RifFileParseTools::splitLineAndTrim( line, "," );
if ( !line.startsWith( "*" ) )
{
if ( collectedCols.size() > 0 && collectedCols.size() != 8 )
{
collectedCols.clear();
}
collectedCols << RifFileParseTools::splitLineAndTrim( line, ",", true );
}
else
{
collectedCols.clear();
}
lineNo++;
if ( !dataBlockFound )
{
if ( !line.startsWith( "*" ) && !line.startsWith( "," ) && cols.size() == expectedColumnCount )
if ( !line.startsWith( "*" ) && !line.startsWith( "," ) && collectedCols.size() == expectedColumnCount )
{
dataBlockFound = true;
}
else if ( collectedCols.size() > expectedColumnCount )
{
throw FileParseException(
QString( "Number of columns mismatch at %1:%2" ).arg( metadata->fileName ).arg( lineNo ) );
}
else
{
continue;
}
}
if ( cols.size() != expectedColumnCount )
{
throw FileParseException(
QString( "Number of columns mismatch at %1:%2" ).arg( metadata->fileName ).arg( lineNo ) );
}
QStringList cols = collectedCols;
for ( int c = 0; c < expectedColumnCount; c++ )
{
@@ -163,6 +184,8 @@ void RifElementPropertyTableReader::readData( const RifElementPropertyMetadata*
table->data[c - 1].push_back( value );
}
}
collectedCols.clear();
dataBlockFound = false;
}
table->hasData = true;