Skip to content

Commit

Permalink
Improvements based on review
Browse files Browse the repository at this point in the history
  • Loading branch information
magnesj committed Sep 12, 2023
1 parent 53da5d9 commit 212c711
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 74 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "RicImportValveTemplatesFeature.h"

#include "RiaApplication.h"
#include "RiaLogging.h"
#include "RiaOpmParserTools.h"

#include "RimProject.h"
Expand Down Expand Up @@ -53,6 +54,12 @@ void RicImportValveTemplatesFeature::onActionTriggered( bool isChecked )
defaultDir,
"Valve Files (*.sch *.case);;All Files (*.*)" );

if ( RimProject::current()->allValveTemplateCollections().empty() )
{
RiaLogging::error( "No valve template collection found, failed to import valves." );
return;
}

RimValveTemplateCollection* templateColl = RimProject::current()->allValveTemplateCollections().front();
for ( const auto& fileName : fileNames )
{
Expand Down
55 changes: 23 additions & 32 deletions ApplicationLibCode/FileInterface/RifEclipseInputFileTools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1183,13 +1183,13 @@ 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& includeStatementAbsolutePathPrefix )
const QString& includeStatementAbsolutePathPrefix,
QFile& file,
qint64 startPos,
QStringList& keywordDataContent,
std::vector<QString>& filenamesContainingKeyword,
bool& isStopParsingKeywordDetected )
{
QString line;

Expand All @@ -1212,10 +1212,7 @@ bool RifEclipseInputFileTools::readKeywordAndParseIncludeStatementsRecursively(

if ( !keywordToStopParsing.isEmpty() && line.startsWith( keywordToStopParsing, Qt::CaseInsensitive ) )
{
if ( isStopParsingKeywordDetected )
{
*isStopParsingKeywordDetected = true;
}
isStopParsingKeywordDetected = true;

return false;
}
Expand Down Expand Up @@ -1266,17 +1263,15 @@ bool RifEclipseInputFileTools::readKeywordAndParseIncludeStatementsRecursively(
QFile includeFile( absoluteFilename );
if ( includeFile.open( QFile::ReadOnly ) )
{
// qDebug() << "Found include statement, and start parsing of\n " << absoluteFilename;

if ( !readKeywordAndParseIncludeStatementsRecursively( keyword,
keywordToStopParsing,
pathAliasDefinitions,
includeStatementAbsolutePathPrefix,
includeFile,
0,
pathAliasDefinitions,
keywordDataContent,
filenamesContainingKeyword,
isStopParsingKeywordDetected,
includeStatementAbsolutePathPrefix ) )
isStopParsingKeywordDetected ) )
{
qDebug() << "Error when parsing include file : " << absoluteFilename;
}
Expand All @@ -1289,11 +1284,11 @@ bool RifEclipseInputFileTools::readKeywordAndParseIncludeStatementsRecursively(
if ( !line.contains( "/" ) )
{
readKeywordDataContent( file, file.pos(), keywordDataContent, isStopParsingKeywordDetected );
filenamesContainingKeyword->push_back( file.fileName() );
filenamesContainingKeyword.push_back( file.fileName() );
}
}

if ( isStopParsingKeywordDetected && *isStopParsingKeywordDetected )
if ( isStopParsingKeywordDetected )
{
continueParsing = false;
}
Expand All @@ -1311,7 +1306,7 @@ bool RifEclipseInputFileTools::readKeywordAndParseIncludeStatementsRecursively(
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RifEclipseInputFileTools::readKeywordDataContent( QFile& data, qint64 filePos, QStringList* textContent, bool* isEditKeywordDetected )
void RifEclipseInputFileTools::readKeywordDataContent( QFile& data, qint64 filePos, QStringList& textContent, bool& isStopParsingKeywordDetected )
{
if ( !data.seek( filePos ) )
{
Expand Down Expand Up @@ -1339,11 +1334,7 @@ void RifEclipseInputFileTools::readKeywordDataContent( QFile& data, qint64 fileP
else if ( line.startsWith( editKeyword, Qt::CaseInsensitive ) )
{
// End parsing when edit keyword is detected

if ( isEditKeywordDetected )
{
*isEditKeywordDetected = true;
}
isStopParsingKeywordDetected = true;

return;
}
Expand All @@ -1355,7 +1346,7 @@ void RifEclipseInputFileTools::readKeywordDataContent( QFile& data, qint64 fileP

if ( !line.isEmpty() )
{
textContent->push_back( line );
textContent.push_back( line );
}

} while ( !data.atEnd() );
Expand All @@ -1368,7 +1359,7 @@ RiaDefines::EclipseUnitSystem RifEclipseInputFileTools::readUnitSystem( QFile& f
{
bool stopParsing = false;
QStringList unitText;
readKeywordDataContent( file, gridunitPos, &unitText, &stopParsing );
readKeywordDataContent( file, gridunitPos, unitText, stopParsing );
for ( QString unitString : unitText )
{
if ( unitString.contains( "FEET", Qt::CaseInsensitive ) )
Expand Down Expand Up @@ -1441,22 +1432,22 @@ bool RifEclipseInputFileTools::hasGridData( const QString& fileName )
//--------------------------------------------------------------------------------------------------
QStringList RifEclipseInputFileTools::readKeywordContentFromFile( const QString& keyword, const QString& keywordToStopParsing, QFile& file )
{
const qint64 startPositionInFile = 0;
std::vector<std::pair<QString, QString>> pathAliasDefinitions;
const QString includeStatementAbsolutePathPrefix;
const qint64 startPositionInFile = 0;
QStringList keywordContent;
std::vector<QString> fileNamesContainingKeyword;
bool isStopParsingKeywordDetected = false;
const QString includeStatementAbsolutePathPrefix;

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

return keywordContent;
}
Expand Down
14 changes: 7 additions & 7 deletions ApplicationLibCode/FileInterface/RifEclipseInputFileTools.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,13 @@ class RifEclipseInputFileTools : public cvf::Object
// Public for unit testing, use readKeywordContentFromFile()
static bool 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* isEditKeywordDetected,
const QString& includeStatementAbsolutePathPrefix );
const QString& includeStatementAbsolutePathPrefix,
QFile& file,
qint64 startPos,
QStringList& keywordDataContent,
std::vector<QString>& filenamesContainingKeyword,
bool& isStopParsingKeywordDetected );

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

Expand All @@ -137,7 +137,7 @@ class RifEclipseInputFileTools : public cvf::Object
bool* isEditKeywordDetected,
const QString& faultIncludeFileAbsolutePathPrefix );

static void readKeywordDataContent( QFile& data, qint64 filePos, QStringList* textContent, bool* isEditKeywordDetected );
static void readKeywordDataContent( QFile& data, qint64 filePos, QStringList& textContent, bool& isStopParsingKeywordDetected );

static void findGridKeywordPositions( const std::vector<RifKeywordAndFilePos>& keywords,
qint64* coordPos,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,17 @@ void RimValveTemplate::setUserLabel( const QString& userLabel )
m_userLabel = userLabel;
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimValveTemplate::setAicdParameter( AICDParameters parameter, double value )
{
if ( m_aicdParameters() )
{
m_aicdParameters()->setValue( parameter, value );
}
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -209,7 +220,7 @@ RimValveTemplate* RimValveTemplate::createAicdTemplate( const RiaOpmParserTools:
if ( aicdParameters.contains( parameter.first ) )
{
auto incomingValue = aicdParameters.at( parameter.first );
aicdTemplate->m_aicdParameters()->setValue( parameter.second, incomingValue );
aicdTemplate->setAicdParameter( parameter.second, incomingValue );
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "RiaOpmParserTools.h"

#include "RimCheckableNamedObject.h"
#include "RimWellPathAicdParameters.h"

#include "cafPdmChildField.h"

Expand Down Expand Up @@ -49,6 +50,8 @@ class RimValveTemplate : public RimNamedObject
QString fullLabel() const;
void setUserLabel( const QString& userLabel );

void setAicdParameter( AICDParameters parameter, double value );

static RimValveTemplate* createAicdTemplate( const RiaOpmParserTools::AicdTemplateValues& aicdParameters, int templateNumber );

protected:
Expand Down
8 changes: 4 additions & 4 deletions ApplicationLibCode/ProjectDataModel/RiaOpmParserTools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,15 +249,15 @@ std::vector<RiaOpmParserTools::AicdTemplateValues> RiaOpmParserTools::extractWse
{
auto name = kw->name();

for ( size_t i = 0; i < kw->size(); i++ )
for ( size_t kwIndex = 0; kwIndex < kw->size(); kwIndex++ )
{
RiaOpmParserTools::AicdTemplateValues aicdTemplate;

auto deckRecord = kw->getRecord( i );
auto deckRecord = kw->getRecord( kwIndex );
auto numItems = deckRecord.size();
for ( size_t i = 0; i < numItems; i++ )
for ( size_t deckIndex = 0; deckIndex < numItems; deckIndex++ )
{
auto deckItem = deckRecord.getItem( i );
auto deckItem = deckRecord.getItem( deckIndex );
if ( !deckItem.hasValue( 0 ) ) continue;
if ( !keywordsToExtract.contains( deckItem.name() ) ) continue;

Expand Down
Loading

0 comments on commit 212c711

Please sign in to comment.