mirror of
https://github.com/OPM/ResInsight.git
synced 2025-01-07 14:43:10 -06:00
#1665 Add parameter and basic framework for executing command file
This commit is contained in:
parent
1a4e1135a2
commit
bf23529b55
@ -91,6 +91,8 @@
|
||||
#include "ExportCommands/RicSnapshotViewToClipboardFeature.h"
|
||||
#include "SummaryPlotCommands/RicNewSummaryPlotFeature.h"
|
||||
|
||||
#include "RicfCommandFileExecutor.h"
|
||||
|
||||
#include "cafFixedAtlasFont.h"
|
||||
|
||||
#include "cafAppEnum.h"
|
||||
@ -1307,6 +1309,7 @@ bool RiaApplication::parseArguments()
|
||||
progOpt.registerOption("replaceSourceCases", "[<caseGroupId>] <gridListFile>", "Replace source cases in <caseGroupId> or first grid case group with the grid files listed in the <gridListFile> file. Repeat parameter for multiple replace operations.", cvf::ProgramOptions::MULTI_VALUE, cvf::ProgramOptions::COMBINE_REPEATED);
|
||||
progOpt.registerOption("replacePropertiesFolder", "[<caseId>] <newPropertiesFolder>", "Replace the folder containing property files for an eclipse input case.", cvf::ProgramOptions::MULTI_VALUE);
|
||||
progOpt.registerOption("multiCaseSnapshots", "<gridListFile>", "For each grid file listed in the <gridListFile> file, replace the first case in the project and save snapshot of all views.", cvf::ProgramOptions::SINGLE_VALUE);
|
||||
progOpt.registerOption("commandFile", "<commandfile>", "Execute the command file.", cvf::ProgramOptions::SINGLE_VALUE);
|
||||
progOpt.registerOption("help", "", "Displays help text.");
|
||||
progOpt.registerOption("?", "", "Displays help text.");
|
||||
progOpt.registerOption("regressiontest", "<folder>", "System command", cvf::ProgramOptions::SINGLE_VALUE);
|
||||
@ -1595,6 +1598,24 @@ bool RiaApplication::parseArguments()
|
||||
return false;
|
||||
}
|
||||
|
||||
if (cvf::Option o = progOpt.option("commandFile"))
|
||||
{
|
||||
QString commandFile = cvfqt::Utils::toQString(o.safeValue(0));
|
||||
QFile file(commandFile);
|
||||
RicfMessages messages;
|
||||
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
|
||||
{
|
||||
// TODO : Error logging?
|
||||
return false;
|
||||
}
|
||||
|
||||
QTextStream in(&file);
|
||||
RicfCommandFileExecutor::instance()->executeCommands(in);
|
||||
closeAllWindows();
|
||||
processEvents();
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -46,6 +46,7 @@ include_directories(
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/ModelVisualization/GridBox
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/ModelVisualization/Intersections
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/UserInterface
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/CommandFileInterface
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/CommandFileInterface/Core
|
||||
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/ProjectDataModel
|
||||
@ -125,6 +126,7 @@ list( APPEND REFERENCED_CMAKE_FILES
|
||||
Commands/WellLogCommands/CMakeLists_files.cmake
|
||||
Commands/WellPathCommands/CMakeLists_files.cmake
|
||||
|
||||
CommandFileInterface/CMakeLists_files.cmake
|
||||
CommandFileInterface/Core/CMakeLists_files.cmake
|
||||
)
|
||||
|
||||
|
18
ApplicationCode/CommandFileInterface/CMakeLists_files.cmake
Normal file
18
ApplicationCode/CommandFileInterface/CMakeLists_files.cmake
Normal file
@ -0,0 +1,18 @@
|
||||
|
||||
set (SOURCE_GROUP_HEADER_FILES
|
||||
${CMAKE_CURRENT_LIST_DIR}/RicfCommandFileExecutor.h
|
||||
)
|
||||
|
||||
set (SOURCE_GROUP_SOURCE_FILES
|
||||
${CMAKE_CURRENT_LIST_DIR}/RicfCommandFileExecutor.cpp
|
||||
)
|
||||
|
||||
list(APPEND CODE_HEADER_FILES
|
||||
${SOURCE_GROUP_HEADER_FILES}
|
||||
)
|
||||
|
||||
list(APPEND CODE_SOURCE_FILES
|
||||
${SOURCE_GROUP_SOURCE_FILES}
|
||||
)
|
||||
|
||||
source_group( "CommandFileInterface" FILES ${SOURCE_GROUP_HEADER_FILES} ${SOURCE_GROUP_SOURCE_FILES} ${CMAKE_CURRENT_LIST_DIR}/CMakeLists_files.cmake )
|
@ -0,0 +1,95 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// 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>
|
||||
// for more details.
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "RicfCommandFileExecutor.h"
|
||||
|
||||
#include "RifcCommandFileReader.h"
|
||||
#include "RicfCommandObject.h"
|
||||
|
||||
namespace caf {
|
||||
template<>
|
||||
void RicfCommandFileExecutor::ExportTypeEnum::setUp()
|
||||
{
|
||||
addItem(RicfCommandFileExecutor::COMPLETIONS, "COMPLETIONS", "Completions");
|
||||
addItem(RicfCommandFileExecutor::PROPERTIES, "PROPERTIES", "Properties");
|
||||
addItem(RicfCommandFileExecutor::SNAPSHOTS, "SNAPSHOTS", "Snapshots");
|
||||
addItem(RicfCommandFileExecutor::STATISTICS, "STATISTICS", "Statistics");
|
||||
setDefault(RicfCommandFileExecutor::COMPLETIONS);
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RicfCommandFileExecutor::RicfCommandFileExecutor()
|
||||
{
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
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::cout << message.second.toUtf8().constData();
|
||||
}
|
||||
for (RicfCommandObject* command : commands)
|
||||
{
|
||||
command->execute();
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RicfCommandFileExecutor::setExportPath(ExportType type, QString path)
|
||||
{
|
||||
m_exportPaths[type] = path;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RicfCommandFileExecutor::getExportPath(ExportType type)
|
||||
{
|
||||
auto it = m_exportPaths.find(type);
|
||||
QString path;
|
||||
if (it != m_exportPaths.end())
|
||||
{
|
||||
path = it->second;
|
||||
}
|
||||
return path;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RicfCommandFileExecutor* RicfCommandFileExecutor::instance()
|
||||
{
|
||||
static RicfCommandFileExecutor* commandFileExecutorInstance = new RicfCommandFileExecutor();
|
||||
return commandFileExecutorInstance;
|
||||
}
|
@ -0,0 +1,50 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// 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>
|
||||
// for more details.
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
#pragma once
|
||||
|
||||
#include "RicfMessages.h"
|
||||
|
||||
#include "cafAppEnum.h"
|
||||
|
||||
class RicfCommandFileExecutor
|
||||
{
|
||||
public:
|
||||
enum ExportType {
|
||||
COMPLETIONS,
|
||||
SNAPSHOTS,
|
||||
PROPERTIES,
|
||||
STATISTICS
|
||||
};
|
||||
|
||||
typedef caf::AppEnum<ExportType> ExportTypeEnum;
|
||||
|
||||
public:
|
||||
RicfCommandFileExecutor();
|
||||
~RicfCommandFileExecutor();
|
||||
|
||||
void executeCommands(QTextStream& stream);
|
||||
void setExportPath(ExportType type, QString path);
|
||||
QString getExportPath(ExportType type);
|
||||
|
||||
static RicfCommandFileExecutor* instance();
|
||||
|
||||
private:
|
||||
RicfMessages m_messages;
|
||||
|
||||
std::map<ExportType, QString> m_exportPaths;
|
||||
};
|
Loading…
Reference in New Issue
Block a user