Skip to content

Commit

Permalink
Merge branch '2018.01.01-patch' into dev. #2434
Browse files Browse the repository at this point in the history
  • Loading branch information
Bjørn Erik Jensen committed Feb 5, 2018
2 parents 8c4cad8 + 0dff40f commit 0b0e601
Show file tree
Hide file tree
Showing 6 changed files with 249 additions and 36 deletions.
114 changes: 101 additions & 13 deletions ApplicationCode/CommandFileInterface/RicfCommandFileExecutor.cpp
Expand Up @@ -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()
Expand Down Expand Up @@ -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)
{
RiaLogging::warning(QString("Command file parsing warning: %1").arg(message.second));
}
else
std::vector<RicfCommandObject*> fileCommands = RicfCommandFileReader::readCommands(stream, caf::PdmDefaultObjectFactory::instance(), &m_messages);
for (auto message : m_messages.m_messages)
{
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);
}
}

Expand Down Expand Up @@ -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;
}
Expand Up @@ -23,6 +23,9 @@
#include "cafAppEnum.h"

#include <map>
#include <vector>

class RicfCommandObject;

//==================================================================================================
//
Expand Down Expand Up @@ -53,6 +56,8 @@ class RicfCommandFileExecutor

static RicfCommandFileExecutor* instance();

static std::vector<RicfCommandObject*> prepareFileCommandsForExecution(const std::vector<RicfCommandObject*>& commandsReadFromFile);

private:
RicfMessages m_messages;

Expand Down
79 changes: 65 additions & 14 deletions ApplicationCode/CommandFileInterface/RicfReplaceCase.cpp
Expand Up @@ -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", "", "", "");
Expand All @@ -38,11 +40,56 @@ RicfReplaceCase::RicfReplaceCase()
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicfReplaceCase::execute()
int RicfSingleCaseReplace::caseId() const
{
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()
{
if (m_newGridFile().isNull())
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
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;
}

Expand All @@ -53,15 +100,19 @@ void RicfReplaceCase::execute()
return;
}


cvf::ref<RiaProjectModifier> projectModifier = new RiaProjectModifier;
if (m_caseId() == -1)
{
projectModifier->setReplaceCaseFirstOccurrence(m_newGridFile());
}
else
for (const auto& a : m_caseIdToGridFileNameMap)
{
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());
Expand Down
42 changes: 35 additions & 7 deletions ApplicationCode/CommandFileInterface/RicfReplaceCase.h
@@ -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.
//
/////////////////////////////////////////////////////////////////////////////////
Expand All @@ -23,20 +23,48 @@
#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;

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;
};
1 change: 1 addition & 0 deletions ApplicationCode/FileInterface/RifEclipseInputFileTools.cpp
Expand Up @@ -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);

Expand Down

0 comments on commit 0b0e601

Please sign in to comment.