From 212c71123905c3ad22797ceb0d4bd67b4d54cf4a Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Tue, 12 Sep 2023 18:37:32 +0200 Subject: [PATCH] Improvements based on review --- .../RicImportValveTemplatesFeature.cpp | 7 +++ .../RifEclipseInputFileTools.cpp | 55 +++++++---------- .../FileInterface/RifEclipseInputFileTools.h | 14 ++--- .../Completions/RimValveTemplate.cpp | 13 +++- .../Completions/RimValveTemplate.h | 3 + .../ProjectDataModel/RiaOpmParserTools.cpp | 8 +-- .../RifEclipseInputFileTools-Test.cpp | 60 +++++++++---------- 7 files changed, 86 insertions(+), 74 deletions(-) diff --git a/ApplicationLibCode/Commands/CompletionCommands/RicImportValveTemplatesFeature.cpp b/ApplicationLibCode/Commands/CompletionCommands/RicImportValveTemplatesFeature.cpp index 0c26dc2d2c..8aa54abd90 100644 --- a/ApplicationLibCode/Commands/CompletionCommands/RicImportValveTemplatesFeature.cpp +++ b/ApplicationLibCode/Commands/CompletionCommands/RicImportValveTemplatesFeature.cpp @@ -19,6 +19,7 @@ #include "RicImportValveTemplatesFeature.h" #include "RiaApplication.h" +#include "RiaLogging.h" #include "RiaOpmParserTools.h" #include "RimProject.h" @@ -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 ) { diff --git a/ApplicationLibCode/FileInterface/RifEclipseInputFileTools.cpp b/ApplicationLibCode/FileInterface/RifEclipseInputFileTools.cpp index 4c137f8aa9..576aad266d 100644 --- a/ApplicationLibCode/FileInterface/RifEclipseInputFileTools.cpp +++ b/ApplicationLibCode/FileInterface/RifEclipseInputFileTools.cpp @@ -1183,13 +1183,13 @@ bool RifEclipseInputFileTools::readFaultsAndParseIncludeStatementsRecursively( Q //-------------------------------------------------------------------------------------------------- bool RifEclipseInputFileTools::readKeywordAndParseIncludeStatementsRecursively( const QString& keyword, const QString& keywordToStopParsing, - QFile& file, - qint64 startPos, const std::vector>& pathAliasDefinitions, - QStringList* keywordDataContent, - std::vector* filenamesContainingKeyword, - bool* isStopParsingKeywordDetected, - const QString& includeStatementAbsolutePathPrefix ) + const QString& includeStatementAbsolutePathPrefix, + QFile& file, + qint64 startPos, + QStringList& keywordDataContent, + std::vector& filenamesContainingKeyword, + bool& isStopParsingKeywordDetected ) { QString line; @@ -1212,10 +1212,7 @@ bool RifEclipseInputFileTools::readKeywordAndParseIncludeStatementsRecursively( if ( !keywordToStopParsing.isEmpty() && line.startsWith( keywordToStopParsing, Qt::CaseInsensitive ) ) { - if ( isStopParsingKeywordDetected ) - { - *isStopParsingKeywordDetected = true; - } + isStopParsingKeywordDetected = true; return false; } @@ -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; } @@ -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; } @@ -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 ) ) { @@ -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; } @@ -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() ); @@ -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 ) ) @@ -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> pathAliasDefinitions; + const QString includeStatementAbsolutePathPrefix; + const qint64 startPositionInFile = 0; QStringList keywordContent; std::vector 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; } diff --git a/ApplicationLibCode/FileInterface/RifEclipseInputFileTools.h b/ApplicationLibCode/FileInterface/RifEclipseInputFileTools.h index 105207f450..baff69028d 100644 --- a/ApplicationLibCode/FileInterface/RifEclipseInputFileTools.h +++ b/ApplicationLibCode/FileInterface/RifEclipseInputFileTools.h @@ -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>& pathAliasDefinitions, - QStringList* keywordDataContent, - std::vector* filenamesContainingKeyword, - bool* isEditKeywordDetected, - const QString& includeStatementAbsolutePathPrefix ); + const QString& includeStatementAbsolutePathPrefix, + QFile& file, + qint64 startPos, + QStringList& keywordDataContent, + std::vector& filenamesContainingKeyword, + bool& isStopParsingKeywordDetected ); static RiaDefines::EclipseUnitSystem readUnitSystem( QFile& file, qint64 gridunitPos ); @@ -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& keywords, qint64* coordPos, diff --git a/ApplicationLibCode/ProjectDataModel/Completions/RimValveTemplate.cpp b/ApplicationLibCode/ProjectDataModel/Completions/RimValveTemplate.cpp index 25cb2a9738..22bb749ade 100644 --- a/ApplicationLibCode/ProjectDataModel/Completions/RimValveTemplate.cpp +++ b/ApplicationLibCode/ProjectDataModel/Completions/RimValveTemplate.cpp @@ -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 ); + } +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -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 ); } } diff --git a/ApplicationLibCode/ProjectDataModel/Completions/RimValveTemplate.h b/ApplicationLibCode/ProjectDataModel/Completions/RimValveTemplate.h index e5526fd20e..094a3a1636 100644 --- a/ApplicationLibCode/ProjectDataModel/Completions/RimValveTemplate.h +++ b/ApplicationLibCode/ProjectDataModel/Completions/RimValveTemplate.h @@ -22,6 +22,7 @@ #include "RiaOpmParserTools.h" #include "RimCheckableNamedObject.h" +#include "RimWellPathAicdParameters.h" #include "cafPdmChildField.h" @@ -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: diff --git a/ApplicationLibCode/ProjectDataModel/RiaOpmParserTools.cpp b/ApplicationLibCode/ProjectDataModel/RiaOpmParserTools.cpp index d548d5bd62..59ac89bd84 100644 --- a/ApplicationLibCode/ProjectDataModel/RiaOpmParserTools.cpp +++ b/ApplicationLibCode/ProjectDataModel/RiaOpmParserTools.cpp @@ -249,15 +249,15 @@ std::vector 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; diff --git a/ApplicationLibCode/UnitTests/RifEclipseInputFileTools-Test.cpp b/ApplicationLibCode/UnitTests/RifEclipseInputFileTools-Test.cpp index 2751442ece..0204f6a495 100644 --- a/ApplicationLibCode/UnitTests/RifEclipseInputFileTools-Test.cpp +++ b/ApplicationLibCode/UnitTests/RifEclipseInputFileTools-Test.cpp @@ -192,13 +192,13 @@ TEST( RifEclipseInputFileToolsTest, EquilData ) RifEclipseInputFileTools::readKeywordAndParseIncludeStatementsRecursively( keyword, keywordToStopParsing, + pathAliasDefinitions, + includeStatementAbsolutePathPrefix, data, startPositionInFile, - pathAliasDefinitions, - &keywordContent, - &fileNamesContainingKeyword, - &isStopParsingKeywordDetected, - includeStatementAbsolutePathPrefix ); + keywordContent, + fileNamesContainingKeyword, + isStopParsingKeywordDetected ); EXPECT_EQ( (int)10, keywordContent.size() ); } } @@ -232,13 +232,13 @@ TEST( RifEclipseInputFileToolsTest, FaultData ) RifEclipseInputFileTools::readKeywordAndParseIncludeStatementsRecursively( keyword, keywordToStopParsing, + pathAliasDefinitions, + includeStatementAbsolutePathPrefix, data, startPositionInFile, - pathAliasDefinitions, - &keywordContent, - &fileNamesContainingKeyword, - &isStopParsingKeywordDetected, - includeStatementAbsolutePathPrefix ); + keywordContent, + fileNamesContainingKeyword, + isStopParsingKeywordDetected ); EXPECT_EQ( (int)977, keywordContent.size() ); @@ -277,13 +277,13 @@ TEST( RifEclipseInputFileToolsTest, StopAtKeyword ) RifEclipseInputFileTools::readKeywordAndParseIncludeStatementsRecursively( keyword, keywordToStopParsing, + pathAliasDefinitions, + includeStatementAbsolutePathPrefix, data, startPositionInFile, - pathAliasDefinitions, - &keywordContent, - &fileNamesContainingKeyword, - &isStopParsingKeywordDetected, - includeStatementAbsolutePathPrefix ); + keywordContent, + fileNamesContainingKeyword, + isStopParsingKeywordDetected ); EXPECT_TRUE( isStopParsingKeywordDetected ); EXPECT_TRUE( keywordContent.isEmpty() ); @@ -301,13 +301,13 @@ TEST( RifEclipseInputFileToolsTest, StopAtKeyword ) RifEclipseInputFileTools::readKeywordAndParseIncludeStatementsRecursively( keyword, keywordToStopParsing, + pathAliasDefinitions, + includeStatementAbsolutePathPrefix, data, startPositionInFile, - pathAliasDefinitions, - &keywordContent, - &fileNamesContainingKeyword, - &isStopParsingKeywordDetected, - includeStatementAbsolutePathPrefix ); + keywordContent, + fileNamesContainingKeyword, + isStopParsingKeywordDetected ); EXPECT_TRUE( isStopParsingKeywordDetected ); EXPECT_TRUE( keywordContent.isEmpty() ); } @@ -338,13 +338,13 @@ TEST( RifEclipseInputFileToolsTest, DISABLED_FindFilesWithVfp ) RifEclipseInputFileTools::readKeywordAndParseIncludeStatementsRecursively( keyword, keywordToStopParsing, + pathAliasDefinitions, + includeStatementAbsolutePathPrefix, data, startPositionInFile, - pathAliasDefinitions, - &keywordContent, - &fileNamesContainingKeyword, - &isStopParsingKeywordDetected, - includeStatementAbsolutePathPrefix ); + keywordContent, + fileNamesContainingKeyword, + isStopParsingKeywordDetected ); // EXPECT_TRUE( isStopParsingKeywordDetected ); // EXPECT_TRUE( keywordContent.isEmpty() ); @@ -368,13 +368,13 @@ TEST( RifEclipseInputFileToolsTest, DISABLED_FindFilesWithVfp ) RifEclipseInputFileTools::readKeywordAndParseIncludeStatementsRecursively( keyword, keywordToStopParsing, + pathAliasDefinitions, + includeStatementAbsolutePathPrefix, data, startPositionInFile, - pathAliasDefinitions, - &keywordContent, - &fileNamesContainingKeyword, - &isStopParsingKeywordDetected, - includeStatementAbsolutePathPrefix ); + keywordContent, + fileNamesContainingKeyword, + isStopParsingKeywordDetected ); // EXPECT_TRUE( isStopParsingKeywordDetected ); // EXPECT_TRUE( keywordContent.isEmpty() );