mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-03 12:10:57 -06:00
Merge branch '2018.01.01-patch' into dev. #2434
This commit is contained in:
commit
0b0e60135c
@ -18,11 +18,14 @@
|
||||
|
||||
#include "RicfCommandFileExecutor.h"
|
||||
|
||||
#include "RifcCommandFileReader.h"
|
||||
#include "RicfCommandObject.h"
|
||||
|
||||
#include "RiaLogging.h"
|
||||
|
||||
#include "RicfCloseProject.h"
|
||||
#include "RicfCommandObject.h"
|
||||
#include "RicfOpenProject.h"
|
||||
#include "RicfReplaceCase.h"
|
||||
#include "RifcCommandFileReader.h"
|
||||
|
||||
namespace caf {
|
||||
template<>
|
||||
void RicfCommandFileExecutor::ExportTypeEnum::setUp()
|
||||
@ -54,22 +57,44 @@ RicfCommandFileExecutor::~RicfCommandFileExecutor()
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RicfCommandFileExecutor::executeCommands(QTextStream& stream)
|
||||
{
|
||||
std::vector<RicfCommandObject*> commands = RicfCommandFileReader::readCommands(stream, caf::PdmDefaultObjectFactory::instance(), &m_messages);
|
||||
for (auto message : m_messages.m_messages)
|
||||
std::vector<RicfCommandObject*> executableCommands;
|
||||
{
|
||||
if (message.first == RicfMessages::MESSAGE_WARNING)
|
||||
std::vector<RicfCommandObject*> fileCommands = RicfCommandFileReader::readCommands(stream, caf::PdmDefaultObjectFactory::instance(), &m_messages);
|
||||
for (auto message : m_messages.m_messages)
|
||||
{
|
||||
RiaLogging::warning(QString("Command file parsing warning: %1").arg(message.second));
|
||||
}
|
||||
else
|
||||
{
|
||||
RiaLogging::error(QString("Command file parsing error: %1").arg(message.second));
|
||||
return;
|
||||
if (message.first == RicfMessages::MESSAGE_WARNING)
|
||||
{
|
||||
RiaLogging::warning(QString("Command file parsing warning: %1").arg(message.second));
|
||||
}
|
||||
else
|
||||
{
|
||||
RiaLogging::error(QString("Command file parsing error: %1").arg(message.second));
|
||||
|
||||
for (auto& command : fileCommands)
|
||||
{
|
||||
delete command;
|
||||
command = nullptr;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
executableCommands = RicfCommandFileExecutor::prepareFileCommandsForExecution(fileCommands);
|
||||
}
|
||||
for (RicfCommandObject* command : commands)
|
||||
|
||||
for (auto& command : executableCommands)
|
||||
{
|
||||
command->execute();
|
||||
|
||||
delete command;
|
||||
command = nullptr;
|
||||
}
|
||||
|
||||
// All command objects should be deleted and grounded at this point
|
||||
for (auto c : executableCommands)
|
||||
{
|
||||
CAF_ASSERT(c == nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
@ -119,3 +144,66 @@ RicfCommandFileExecutor* RicfCommandFileExecutor::instance()
|
||||
static RicfCommandFileExecutor* commandFileExecutorInstance = new RicfCommandFileExecutor();
|
||||
return commandFileExecutorInstance;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::vector<RicfCommandObject*> RicfCommandFileExecutor::prepareFileCommandsForExecution(const std::vector<RicfCommandObject*>& commandsReadFromFile)
|
||||
{
|
||||
// This function will merge multiple RicfSingleCaseReplace object by a single RicfMultiCaseReplace object
|
||||
// A command file version for multi case replace was rejected by @hhgs 2018-02-02
|
||||
//
|
||||
// The reason for this is based on two requirements
|
||||
// 1. Ability to aggregate info from multiple replaceCase() statements in a command file
|
||||
// 2. Improve performance, as a replace case is implemented by reading a project file from XML and replace file paths
|
||||
// during project loading
|
||||
|
||||
std::vector<RicfCommandObject*> executableCommands;
|
||||
{
|
||||
std::vector<RicfSingleCaseReplace*> objectsToBeDeleted;
|
||||
std::vector<RicfSingleCaseReplace*> batchOfReplaceCaseFileObjects;
|
||||
|
||||
std::map<int, QString> aggregatedCasePathPairs;
|
||||
|
||||
for (RicfCommandObject* command : commandsReadFromFile)
|
||||
{
|
||||
RicfSingleCaseReplace* fileReplaceCase = dynamic_cast<RicfSingleCaseReplace*>(command);
|
||||
if (fileReplaceCase)
|
||||
{
|
||||
aggregatedCasePathPairs[fileReplaceCase->caseId()] = fileReplaceCase->filePath();
|
||||
|
||||
batchOfReplaceCaseFileObjects.push_back(fileReplaceCase);
|
||||
objectsToBeDeleted.push_back(fileReplaceCase);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!batchOfReplaceCaseFileObjects.empty())
|
||||
{
|
||||
RicfMultiCaseReplace* multiCaseReplace = new RicfMultiCaseReplace;
|
||||
multiCaseReplace->setCaseReplacePairs(aggregatedCasePathPairs);
|
||||
|
||||
executableCommands.push_back(multiCaseReplace);
|
||||
|
||||
batchOfReplaceCaseFileObjects.clear();
|
||||
}
|
||||
|
||||
if (dynamic_cast<RicfOpenProject*>(command) || dynamic_cast<RicfCloseProject*>(command))
|
||||
{
|
||||
// Reset aggregation when openProject or closeProject is issued
|
||||
aggregatedCasePathPairs.clear();
|
||||
}
|
||||
|
||||
executableCommands.push_back(command);
|
||||
}
|
||||
}
|
||||
|
||||
// Delete RicfSingleCaseReplace objects, as they are replaced by RicfMultiCaseReplace
|
||||
for (auto objToDelete : objectsToBeDeleted)
|
||||
{
|
||||
delete objToDelete;
|
||||
objToDelete = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
return executableCommands;
|
||||
}
|
||||
|
@ -23,6 +23,9 @@
|
||||
#include "cafAppEnum.h"
|
||||
|
||||
#include <map>
|
||||
#include <vector>
|
||||
|
||||
class RicfCommandObject;
|
||||
|
||||
//==================================================================================================
|
||||
//
|
||||
@ -53,6 +56,8 @@ public:
|
||||
|
||||
static RicfCommandFileExecutor* instance();
|
||||
|
||||
static std::vector<RicfCommandObject*> prepareFileCommandsForExecution(const std::vector<RicfCommandObject*>& commandsReadFromFile);
|
||||
|
||||
private:
|
||||
RicfMessages m_messages;
|
||||
|
||||
|
@ -18,18 +18,20 @@
|
||||
|
||||
#include "RicfReplaceCase.h"
|
||||
|
||||
#include "RicfCommandFileExecutor.h"
|
||||
|
||||
#include "RiaApplication.h"
|
||||
#include "RiaLogging.h"
|
||||
#include "RiaProjectModifier.h"
|
||||
|
||||
CAF_PDM_SOURCE_INIT(RicfReplaceCase, "replaceCase");
|
||||
#include "RicfCommandFileExecutor.h"
|
||||
|
||||
#include "RimProject.h"
|
||||
|
||||
CAF_PDM_SOURCE_INIT(RicfSingleCaseReplace, "replaceCase");
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RicfReplaceCase::RicfReplaceCase()
|
||||
RicfSingleCaseReplace::RicfSingleCaseReplace()
|
||||
{
|
||||
RICF_InitField(&m_caseId, "caseId", -1, "Case ID", "", "", "");
|
||||
RICF_InitField(&m_newGridFile, "newGridFile", QString(), "New Grid File", "", "", "");
|
||||
@ -38,11 +40,56 @@ RicfReplaceCase::RicfReplaceCase()
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RicfReplaceCase::execute()
|
||||
int RicfSingleCaseReplace::caseId() const
|
||||
{
|
||||
if (m_newGridFile().isNull())
|
||||
return m_caseId;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RicfSingleCaseReplace::filePath() const
|
||||
{
|
||||
return m_newGridFile;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RicfSingleCaseReplace::execute()
|
||||
{
|
||||
// Never call execute on this object, information is aggregated into RicfMultiCaseReplace
|
||||
CAF_ASSERT(false);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
CAF_PDM_SOURCE_INIT(RicfMultiCaseReplace, "replaceCaseImpl_no_support_for_command_file_text_parsing");
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RicfMultiCaseReplace::RicfMultiCaseReplace()
|
||||
{
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RicfMultiCaseReplace::setCaseReplacePairs(const std::map<int, QString>& caseIdToGridFileNameMap)
|
||||
{
|
||||
m_caseIdToGridFileNameMap = caseIdToGridFileNameMap;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RicfMultiCaseReplace::execute()
|
||||
{
|
||||
if (m_caseIdToGridFileNameMap.empty())
|
||||
{
|
||||
RiaLogging::error("replaceCase: Required parameter newGridFile.");
|
||||
RiaLogging::error("replaceCaseImpl: No replacements available.");
|
||||
return;
|
||||
}
|
||||
|
||||
@ -53,15 +100,19 @@ void RicfReplaceCase::execute()
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
cvf::ref<RiaProjectModifier> projectModifier = new RiaProjectModifier;
|
||||
if (m_caseId() == -1)
|
||||
for (const auto& a : m_caseIdToGridFileNameMap)
|
||||
{
|
||||
projectModifier->setReplaceCaseFirstOccurrence(m_newGridFile());
|
||||
}
|
||||
else
|
||||
{
|
||||
projectModifier->setReplaceCase(m_caseId(), m_newGridFile());
|
||||
const auto caseId = a.first;
|
||||
const auto filePath = a.second;
|
||||
if (caseId < 0)
|
||||
{
|
||||
projectModifier->setReplaceCaseFirstOccurrence(filePath);
|
||||
}
|
||||
else
|
||||
{
|
||||
projectModifier->setReplaceCase(caseId, filePath);
|
||||
}
|
||||
}
|
||||
|
||||
RiaApplication::instance()->loadProject(lastProjectPath, RiaApplication::PLA_NONE, projectModifier.p());
|
||||
|
@ -1,17 +1,17 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2017 Statoil ASA
|
||||
//
|
||||
//
|
||||
// ResInsight is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
//
|
||||
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
// FITNESS FOR A PARTICULAR PURPOSE.
|
||||
//
|
||||
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
||||
//
|
||||
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
||||
// for more details.
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
@ -23,16 +23,22 @@
|
||||
#include "cafPdmField.h"
|
||||
|
||||
//==================================================================================================
|
||||
// RicfSingleCaseReplace represents the parsed command from text file able to replace one case ID with
|
||||
// a new file name
|
||||
//
|
||||
// This is the preferred interface on file, based on discussion with @hhgs 2018-02-02
|
||||
//
|
||||
//
|
||||
// Multiple objects of this type can be aggregated into RicfMultipleReplaceCase
|
||||
//==================================================================================================
|
||||
class RicfReplaceCase : public RicfCommandObject
|
||||
class RicfSingleCaseReplace : public RicfCommandObject
|
||||
{
|
||||
CAF_PDM_HEADER_INIT;
|
||||
|
||||
public:
|
||||
RicfReplaceCase();
|
||||
RicfSingleCaseReplace();
|
||||
|
||||
int caseId() const;
|
||||
QString filePath() const;
|
||||
|
||||
virtual void execute() override;
|
||||
|
||||
@ -40,3 +46,25 @@ private:
|
||||
caf::PdmField<QString> m_newGridFile;
|
||||
caf::PdmField<int> m_caseId;
|
||||
};
|
||||
|
||||
//==================================================================================================
|
||||
// RicfMultipleReplaceCase represents multiple caseId-gridFileName pairs
|
||||
//
|
||||
// NB! This object has no support for parsing a text command. This object is created by aggregating
|
||||
// multiple RicfSingleCaseReplace objects
|
||||
//
|
||||
//==================================================================================================
|
||||
class RicfMultiCaseReplace : public RicfCommandObject
|
||||
{
|
||||
CAF_PDM_HEADER_INIT;
|
||||
|
||||
public:
|
||||
RicfMultiCaseReplace();
|
||||
|
||||
void setCaseReplacePairs(const std::map<int, QString>& caseIdToGridFileNameMap);
|
||||
|
||||
virtual void execute() override;
|
||||
|
||||
private:
|
||||
std::map<int, QString> m_caseIdToGridFileNameMap;
|
||||
};
|
||||
|
@ -440,6 +440,7 @@ const std::vector<QString>& RifEclipseInputFileTools::invalidPropertyDataKeyword
|
||||
keywords.push_back("ZCORN");
|
||||
keywords.push_back("SPECGRID");
|
||||
keywords.push_back("MAPAXES");
|
||||
keywords.push_back("NOECHO");
|
||||
|
||||
keywords.push_back(faultsKeyword);
|
||||
|
||||
|
@ -1,9 +1,11 @@
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
#include "RifcCommandFileReader.h"
|
||||
#include "RicfCommandFileExecutor.h"
|
||||
#include "RicfCommandObject.h"
|
||||
#include "cafPdmField.h"
|
||||
#include "RicfMessages.h"
|
||||
#include "RifcCommandFileReader.h"
|
||||
|
||||
#include "cafPdmField.h"
|
||||
|
||||
class TestCommand1: public RicfCommandObject
|
||||
{
|
||||
@ -165,3 +167,41 @@ TEST(RicfCommands, EmptyArgumentList)
|
||||
delete(obj);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(RicfCommands, TransformFileCommandObjectsToExecutableCommandObjects)
|
||||
{
|
||||
QString commandString = R"(
|
||||
replaceCase(newGridFile="/1.EGRID", caseId=1)
|
||||
replaceCase(newGridFile="/2.EGRID", caseId=2)
|
||||
|
||||
openProject(path="/home/user/ResInsightProject.rsp")
|
||||
replaceCase(newGridFile="/3.EGRID", caseId=3)
|
||||
replaceCase(newGridFile="/4.EGRID", caseId=4)
|
||||
|
||||
exportSnapshots()
|
||||
replaceCase(newGridFile="/6.EGRID", caseId=6)
|
||||
replaceCase(newGridFile="/7.EGRID", caseId=7)
|
||||
|
||||
closeProject()
|
||||
|
||||
)";
|
||||
|
||||
QTextStream inputStream(&commandString);
|
||||
RicfMessages errors;
|
||||
|
||||
auto objects = RicfCommandFileReader::readCommands(inputStream, caf::PdmDefaultObjectFactory::instance(), &errors);
|
||||
EXPECT_TRUE(errors.m_messages.empty());
|
||||
EXPECT_EQ((size_t)9, objects.size());
|
||||
|
||||
auto exeObjects = RicfCommandFileExecutor::prepareFileCommandsForExecution(objects);
|
||||
EXPECT_EQ((size_t)6, exeObjects.size());
|
||||
|
||||
for (auto obj : exeObjects)
|
||||
{
|
||||
delete(obj);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user