Skip to content

Commit

Permalink
Simplify API
Browse files Browse the repository at this point in the history
  • Loading branch information
magnesj committed Sep 8, 2023
1 parent 91f116a commit fb4e38f
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@ void RicImportValveTemplatesFeature::onActionTriggered( bool isChecked )
auto it = std::unique( aicdTemplates.begin(), aicdTemplates.end() );
aicdTemplates.resize( std::distance( aicdTemplates.begin(), it ) );

int number = 1;
for ( const auto& aicdValue : aicdTemplates )
{
int number = static_cast<int>( templateColl->valveTemplates().size() );
auto newTemplate = RimValveTemplate::createAicdTemplate( aicdValue, number );
auto newTemplate = RimValveTemplate::createAicdTemplate( aicdValue, number++ );
templateColl->addValveTemplate( newTemplate );
}
}
Expand Down
48 changes: 36 additions & 12 deletions ApplicationLibCode/FileInterface/RifEclipseInputFileTools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1181,16 +1181,15 @@ bool RifEclipseInputFileTools::readFaultsAndParseIncludeStatementsRecursively( Q
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RifEclipseInputFileTools::readKeywordAndParseIncludeStatementsRecursively(
const QString& keyword,
const QString& keywordToStopParsing,
QFile& file,
qint64 startPos,
const std::vector<std::pair<QString, QString>>& pathAliasDefinitions,
QStringList* keywordDataContent,
std::vector<QString>* filenamesContainingKeyword,
bool* isStopParsingKeywordDetected,
const QString& faultIncludeFileAbsolutePathPrefix /* rename to includeStatementAbsolutePathPrefix */ )
bool RifEclipseInputFileTools::readKeywordAndParseIncludeStatementsRecursively( const QString& keyword,
const QString& keywordToStopParsing,
QFile& file,
qint64 startPos,
const std::vector<std::pair<QString, QString>>& pathAliasDefinitions,
QStringList* keywordDataContent,
std::vector<QString>* filenamesContainingKeyword,
bool* isStopParsingKeywordDetected,
const QString& includeStatementAbsolutePathPrefix )
{
QString line;

Expand Down Expand Up @@ -1256,7 +1255,7 @@ bool RifEclipseInputFileTools::readKeywordAndParseIncludeStatementsRecursively(
if ( includeFilename.startsWith( '/' ) )
{
// Absolute UNIX path, prefix on Windows
includeFilename = faultIncludeFileAbsolutePathPrefix + includeFilename;
includeFilename = includeStatementAbsolutePathPrefix + includeFilename;
}
#endif

Expand All @@ -1277,7 +1276,7 @@ bool RifEclipseInputFileTools::readKeywordAndParseIncludeStatementsRecursively(
keywordDataContent,
filenamesContainingKeyword,
isStopParsingKeywordDetected,
faultIncludeFileAbsolutePathPrefix ) )
includeStatementAbsolutePathPrefix ) )
{
qDebug() << "Error when parsing include file : " << absoluteFilename;
}
Expand Down Expand Up @@ -1437,6 +1436,31 @@ bool RifEclipseInputFileTools::hasGridData( const QString& fileName )
return coordKeywordItr != keywordAndValues.end();
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QStringList RifEclipseInputFileTools::readKeywordContentFromFile( const QString& keyword, const QString& keywordToStopParsing, QFile& file )
{
const qint64 startPositionInFile = 0;
std::vector<std::pair<QString, QString>> pathAliasDefinitions;
QStringList keywordContent;
std::vector<QString> fileNamesContainingKeyword;
bool isStopParsingKeywordDetected = false;
const QString includeStatementAbsolutePathPrefix;

RifEclipseInputFileTools::readKeywordAndParseIncludeStatementsRecursively( keyword,
keywordToStopParsing,
file,
startPositionInFile,
pathAliasDefinitions,
&keywordContent,
&fileNamesContainingKeyword,
&isStopParsingKeywordDetected,
includeStatementAbsolutePathPrefix );

return keywordContent;
}

//--------------------------------------------------------------------------------------------------
/// The file pointer is pointing at the line following the FAULTS keyword.
/// Parse content of this keyword until end of file or
Expand Down
7 changes: 4 additions & 3 deletions ApplicationLibCode/FileInterface/RifEclipseInputFileTools.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ class RifEclipseInputFileTools : public cvf::Object

static void parseAndReadPathAliasKeyword( const QString& fileName, std::vector<std::pair<QString, QString>>* pathAliasDefinitions );

static QStringList readKeywordContentFromFile( const QString& keyword, const QString& keywordToStopParsing, QFile& file );

// Public for unit testing, use readKeywordContentFromFile()
static bool readKeywordAndParseIncludeStatementsRecursively( const QString& keyword,
const QString& keywordToStopParsing,
QFile& file,
Expand All @@ -114,9 +117,7 @@ class RifEclipseInputFileTools : public cvf::Object
QStringList* keywordDataContent,
std::vector<QString>* filenamesContainingKeyword,
bool* isEditKeywordDetected,
const QString& faultIncludeFileAbsolutePathPrefix // rename to
// includeStatementAbsolutePathPrefix
);
const QString& includeStatementAbsolutePathPrefix );

static RiaDefines::EclipseUnitSystem readUnitSystem( QFile& file, qint64 gridunitPos );

Expand Down
27 changes: 7 additions & 20 deletions ApplicationLibCode/FileInterface/RifReaderEclipseOutput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -648,26 +648,13 @@ void RifReaderEclipseOutput::importEquilData( const QString& deckFileName,
const QString& includeStatementAbsolutePathPrefix,
RigEclipseCaseData* eclipseCase )
{
QFile data( deckFileName );
if ( data.open( QFile::ReadOnly ) )
{
const QString keyword( "EQUIL" );
const QString keywordToStopParsing( "SCHEDULE" );
const qint64 startPositionInFile = 0;
std::vector<std::pair<QString, QString>> pathAliasDefinitions;
QStringList keywordContent;
std::vector<QString> fileNamesContainingKeyword;
bool isStopParsingKeywordDetected = false;

RifEclipseInputFileTools::readKeywordAndParseIncludeStatementsRecursively( keyword,
keywordToStopParsing,
data,
startPositionInFile,
pathAliasDefinitions,
&keywordContent,
&fileNamesContainingKeyword,
&isStopParsingKeywordDetected,
includeStatementAbsolutePathPrefix );
QFile file( deckFileName );
if ( file.open( QFile::ReadOnly ) )
{
const QString keyword( "EQUIL" );
const QString keywordToStopParsing( "SCHEDULE" );
auto keywordContent = RifEclipseInputFileTools::readKeywordContentFromFile( keyword, keywordToStopParsing, file );

std::vector<RigEquil> equilItems;
for ( const auto& s : keywordContent )
{
Expand Down
25 changes: 5 additions & 20 deletions ApplicationLibCode/ProjectDataModel/RiaOpmParserTools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -288,30 +288,15 @@ std::vector<RiaOpmParserTools::AicdTemplateValues> RiaOpmParserTools::extractWse
//--------------------------------------------------------------------------------------------------
std::vector<RiaOpmParserTools::AicdTemplateValues> RiaOpmParserTools::extractWsegAicdCompletor( const std::string& filename )
{
QFile data( QString::fromStdString( filename ) );
if ( !data.open( QFile::ReadOnly ) ) return {};
QFile file( QString::fromStdString( filename ) );
if ( !file.open( QFile::ReadOnly ) ) return {};

std::vector<RiaOpmParserTools::AicdTemplateValues> aicdTemplates;

const QString keyword( "WSEGAICD" );
const QString keywordToStopParsing;
const qint64 startPositionInFile = 0;
std::vector<std::pair<QString, QString>> pathAliasDefinitions;
QStringList keywordContent;
std::vector<QString> fileNamesContainingKeyword;
bool isStopParsingKeywordDetected = false;
const QString includeStatementAbsolutePathPrefix;

RifEclipseInputFileTools::readKeywordAndParseIncludeStatementsRecursively( keyword,
keywordToStopParsing,
data,
startPositionInFile,
pathAliasDefinitions,
&keywordContent,
&fileNamesContainingKeyword,
&isStopParsingKeywordDetected,
includeStatementAbsolutePathPrefix );
const QString keyword( "WSEGAICD" );
const QString keywordToStopParsing;

auto keywordContent = RifEclipseInputFileTools::readKeywordContentFromFile( keyword, keywordToStopParsing, file );
for ( const auto& s : keywordContent )
{
auto wordsInLine = RiaTextStringTools::splitSkipEmptyParts( s );
Expand Down

0 comments on commit fb4e38f

Please sign in to comment.