Whitespace

This commit is contained in:
Magne Sjaastad 2019-01-16 11:52:06 +01:00
parent 4e6add0c37
commit fd133b0d36

View File

@ -30,22 +30,22 @@
#include "RiuMainWindow.h" #include "RiuMainWindow.h"
#include "RiuPlotMainWindow.h" #include "RiuPlotMainWindow.h"
#include "RicfMessages.h"
#include "RicfCommandFileExecutor.h" #include "RicfCommandFileExecutor.h"
#include "RicfMessages.h"
#include "ExportCommands/RicSnapshotViewToFileFeature.h"
#include "ExportCommands/RicSnapshotAllPlotsToFileFeature.h" #include "ExportCommands/RicSnapshotAllPlotsToFileFeature.h"
#include "ExportCommands/RicSnapshotAllViewsToFileFeature.h" #include "ExportCommands/RicSnapshotAllViewsToFileFeature.h"
#include "ExportCommands/RicSnapshotViewToFileFeature.h"
#include "cvfProgramOptions.h" #include "cvfProgramOptions.h"
#include "cvfqtUtils.h" #include "cvfqtUtils.h"
#include "cafUtils.h" #include "cafUtils.h"
#include <QString>
#include <QStringList>
#include <QCoreApplication> #include <QCoreApplication>
#include <QFile> #include <QFile>
#include <QString>
#include <QStringList>
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
@ -53,25 +53,57 @@
bool RiaArgumentParser::parseArguments() bool RiaArgumentParser::parseArguments()
{ {
cvf::ProgramOptions progOpt; cvf::ProgramOptions progOpt;
progOpt.registerOption("last", "", "Open last used project."); progOpt.registerOption("last", "", "Open last used project.");
progOpt.registerOption("project", "<filename>", "Open project file <filename>.", cvf::ProgramOptions::SINGLE_VALUE); progOpt.registerOption("project", "<filename>", "Open project file <filename>.", cvf::ProgramOptions::SINGLE_VALUE);
progOpt.registerOption("case", "<casename>", "Import Eclipse case <casename> (do not include the .GRID/.EGRID extension.)", cvf::ProgramOptions::MULTI_VALUE); progOpt.registerOption("case",
progOpt.registerOption("startdir", "<folder>", "Set startup directory.", cvf::ProgramOptions::SINGLE_VALUE); "<casename>",
progOpt.registerOption("savesnapshots", "all|views|plots", "Save snapshot of all views or plots to project file location sub folder 'snapshots'. Option 'all' will include both views and plots. Application closes after snapshots have been written.", cvf::ProgramOptions::OPTIONAL_MULTI_VALUE); "Import Eclipse case <casename> (do not include the .GRID/.EGRID extension.)",
progOpt.registerOption("size", "<width> <height>", "Set size of the main application window.", cvf::ProgramOptions::MULTI_VALUE); cvf::ProgramOptions::MULTI_VALUE);
progOpt.registerOption("replaceCase", "[<caseId>] <newGridFile>", "Replace grid in <caseId> or first case with <newgridFile>. Repeat parameter for multiple replace operations.", cvf::ProgramOptions::MULTI_VALUE, cvf::ProgramOptions::COMBINE_REPEATED); progOpt.registerOption("startdir", "<folder>", "Set startup directory.", cvf::ProgramOptions::SINGLE_VALUE);
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("savesnapshots",
progOpt.registerOption("replacePropertiesFolder", "[<caseId>] <newPropertiesFolder>", "Replace the folder containing property files for an eclipse input case.", cvf::ProgramOptions::MULTI_VALUE); "all|views|plots",
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); "Save snapshot of all views or plots to project file location sub folder 'snapshots'. Option 'all' "
progOpt.registerOption("commandFile", "<commandfile>", "Execute the command file.", cvf::ProgramOptions::SINGLE_VALUE); "will include both views and plots. Application closes after snapshots have been written.",
progOpt.registerOption("commandFileProject", "<filename>", "Project to use if performing case looping for command file. Used in conjunction with 'commandFileReplaceCases'.", cvf::ProgramOptions::SINGLE_VALUE); cvf::ProgramOptions::OPTIONAL_MULTI_VALUE);
progOpt.registerOption("commandFileReplaceCases", "[<caseId>] <caseListFile>", "Supply list of cases to replace in project, performing command file for each case.", cvf::ProgramOptions::SINGLE_VALUE); progOpt.registerOption(
progOpt.registerOption("help", "", "Displays help text."); "size", "<width> <height>", "Set size of the main application window.", cvf::ProgramOptions::MULTI_VALUE);
progOpt.registerOption("?", "", "Displays help text."); progOpt.registerOption(
progOpt.registerOption("regressiontest", "<folder>", "System command", cvf::ProgramOptions::SINGLE_VALUE); "replaceCase",
progOpt.registerOption("updateregressiontestbase", "<folder>", "System command", cvf::ProgramOptions::SINGLE_VALUE); "[<caseId>] <newGridFile>",
progOpt.registerOption("unittest", "", "System command"); "Replace grid in <caseId> or first case with <newgridFile>. Repeat parameter for multiple replace operations.",
progOpt.registerOption("ignoreArgs", "", "Ignore all arguments. Mostly for testing purposes"); cvf::ProgramOptions::MULTI_VALUE,
cvf::ProgramOptions::COMBINE_REPEATED);
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(
"commandFileProject",
"<filename>",
"Project to use if performing case looping for command file. Used in conjunction with 'commandFileReplaceCases'.",
cvf::ProgramOptions::SINGLE_VALUE);
progOpt.registerOption("commandFileReplaceCases",
"[<caseId>] <caseListFile>",
"Supply list of cases to replace in project, performing command file for each case.",
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);
progOpt.registerOption("updateregressiontestbase", "<folder>", "System command", cvf::ProgramOptions::SINGLE_VALUE);
progOpt.registerOption("unittest", "", "System command");
progOpt.registerOption("ignoreArgs", "", "Ignore all arguments. Mostly for testing purposes");
progOpt.setOptionPrefix(cvf::ProgramOptions::DOUBLE_DASH); progOpt.setOptionPrefix(cvf::ProgramOptions::DOUBLE_DASH);
@ -89,10 +121,7 @@ bool RiaArgumentParser::parseArguments()
// If positional parameter functionality is to be supported, the test for existence of positionalParameters must be removed // If positional parameter functionality is to be supported, the test for existence of positionalParameters must be removed
// This is based on a pull request by @andlaus https://github.com/OPM/ResInsight/pull/162 // This is based on a pull request by @andlaus https://github.com/OPM/ResInsight/pull/162
if (!parseOk || if (!parseOk || progOpt.hasOption("help") || progOpt.hasOption("?") || progOpt.positionalParameters().size() > 0)
progOpt.hasOption("help") ||
progOpt.hasOption("?") ||
progOpt.positionalParameters().size() > 0)
{ {
#if defined(_MSC_VER) && defined(_WIN32) #if defined(_MSC_VER) && defined(_WIN32)
RiaApplication::instance()->showFormattedTextInMessageBox(helpText); RiaApplication::instance()->showFormattedTextInMessageBox(helpText);
@ -103,7 +132,6 @@ bool RiaArgumentParser::parseArguments()
return false; return false;
} }
// Handling of the actual command line options // Handling of the actual command line options
// -------------------------------------------------------- // --------------------------------------------------------
@ -137,15 +165,14 @@ bool RiaArgumentParser::parseArguments()
if (cvf::Option o = progOpt.option("size")) if (cvf::Option o = progOpt.option("size"))
{ {
RiuMainWindow* mainWnd = RiuMainWindow::instance(); RiuMainWindow* mainWnd = RiuMainWindow::instance();
int width = o.safeValue(0).toInt(-1); int width = o.safeValue(0).toInt(-1);
int height = o.safeValue(1).toInt(-1); int height = o.safeValue(1).toInt(-1);
if (mainWnd && width > 0 && height > 0) if (mainWnd && width > 0 && height > 0)
{ {
mainWnd->resize(width, height); mainWnd->resize(width, height);
} }
} }
QString projectFileName; QString projectFileName;
if (progOpt.hasOption("last")) if (progOpt.hasOption("last"))
@ -159,23 +186,21 @@ bool RiaArgumentParser::parseArguments()
projectFileName = cvfqt::Utils::toQString(o.value(0)); projectFileName = cvfqt::Utils::toQString(o.value(0));
} }
if (!projectFileName.isEmpty()) if (!projectFileName.isEmpty())
{ {
if (cvf::Option o = progOpt.option("multiCaseSnapshots")) if (cvf::Option o = progOpt.option("multiCaseSnapshots"))
{ {
QString gridListFile = cvfqt::Utils::toQString(o.safeValue(0)); QString gridListFile = cvfqt::Utils::toQString(o.safeValue(0));
std::vector<QString> gridFiles = RiaApplication::readFileListFromTextFile(gridListFile); std::vector<QString> gridFiles = RiaApplication::readFileListFromTextFile(gridListFile);
RiaApplication::instance()->runMultiCaseSnapshots(projectFileName, gridFiles, "multiCaseSnapshots"); RiaApplication::instance()->runMultiCaseSnapshots(projectFileName, gridFiles, "multiCaseSnapshots");
return false; return false;
} }
} }
if (!projectFileName.isEmpty()) if (!projectFileName.isEmpty())
{ {
cvf::ref<RiaProjectModifier> projectModifier; cvf::ref<RiaProjectModifier> projectModifier;
RiaApplication::ProjectLoadAction projectLoadAction = RiaApplication::PLA_NONE; RiaApplication::ProjectLoadAction projectLoadAction = RiaApplication::PLA_NONE;
if (cvf::Option o = progOpt.option("replaceCase")) if (cvf::Option o = progOpt.option("replaceCase"))
@ -194,8 +219,8 @@ bool RiaArgumentParser::parseArguments()
size_t optionIdx = 0; size_t optionIdx = 0;
while (optionIdx < o.valueCount()) while (optionIdx < o.valueCount())
{ {
const int caseId = o.safeValue(optionIdx++).toInt(-1); const int caseId = o.safeValue(optionIdx++).toInt(-1);
QString gridFileName = cvfqt::Utils::toQString(o.safeValue(optionIdx++)); QString gridFileName = cvfqt::Utils::toQString(o.safeValue(optionIdx++));
if (caseId != -1 && !gridFileName.isEmpty()) if (caseId != -1 && !gridFileName.isEmpty())
{ {
@ -213,7 +238,8 @@ bool RiaArgumentParser::parseArguments()
{ {
// One argument is available, use replace case for first occurrence in the project // One argument is available, use replace case for first occurrence in the project
std::vector<QString> gridFileNames = RiaApplication::readFileListFromTextFile(cvfqt::Utils::toQString(o.safeValue(0))); std::vector<QString> gridFileNames =
RiaApplication::readFileListFromTextFile(cvfqt::Utils::toQString(o.safeValue(0)));
projectModifier->setReplaceSourceCasesFirstOccurrence(gridFileNames); projectModifier->setReplaceSourceCasesFirstOccurrence(gridFileNames);
} }
else else
@ -221,8 +247,9 @@ bool RiaArgumentParser::parseArguments()
size_t optionIdx = 0; size_t optionIdx = 0;
while (optionIdx < o.valueCount()) while (optionIdx < o.valueCount())
{ {
const int groupId = o.safeValue(optionIdx++).toInt(-1); const int groupId = o.safeValue(optionIdx++).toInt(-1);
std::vector<QString> gridFileNames = RiaApplication::readFileListFromTextFile(cvfqt::Utils::toQString(o.safeValue(optionIdx++))); std::vector<QString> gridFileNames =
RiaApplication::readFileListFromTextFile(cvfqt::Utils::toQString(o.safeValue(optionIdx++)));
if (groupId != -1 && gridFileNames.size() > 0) if (groupId != -1 && gridFileNames.size() > 0)
{ {
@ -248,8 +275,8 @@ bool RiaArgumentParser::parseArguments()
size_t optionIdx = 0; size_t optionIdx = 0;
while (optionIdx < o.valueCount()) while (optionIdx < o.valueCount())
{ {
const int caseId = o.safeValue(optionIdx++).toInt(-1); const int caseId = o.safeValue(optionIdx++).toInt(-1);
QString propertiesFolder = cvfqt::Utils::toQString(o.safeValue(optionIdx++)); QString propertiesFolder = cvfqt::Utils::toQString(o.safeValue(optionIdx++));
if (caseId != -1 && !propertiesFolder.isEmpty()) if (caseId != -1 && !propertiesFolder.isEmpty())
{ {
@ -262,38 +289,35 @@ bool RiaArgumentParser::parseArguments()
RiaApplication::instance()->loadProject(projectFileName, projectLoadAction, projectModifier.p()); RiaApplication::instance()->loadProject(projectFileName, projectLoadAction, projectModifier.p());
} }
if (cvf::Option o = progOpt.option("case")) if (cvf::Option o = progOpt.option("case"))
{ {
QStringList caseNames = cvfqt::Utils::toQStringList(o.values()); QStringList caseNames = cvfqt::Utils::toQStringList(o.values());
foreach (QString caseName, caseNames) foreach (QString caseName, caseNames)
{ {
QString fileExtension = caf::Utils::fileExtension(caseName); QString fileExtension = caf::Utils::fileExtension(caseName);
if (caf::Utils::fileExists(caseName) && if (caf::Utils::fileExists(caseName) && (fileExtension == "EGRID" || fileExtension == "GRID"))
(fileExtension == "EGRID" || fileExtension == "GRID"))
{ {
RiaImportEclipseCaseTools::openEclipseCasesFromFile(QStringList({ caseName }), nullptr, true); RiaImportEclipseCaseTools::openEclipseCasesFromFile(QStringList({caseName}), nullptr, true);
} }
else else
{ {
QString caseFileNameWithExt = caseName + ".EGRID"; QString caseFileNameWithExt = caseName + ".EGRID";
if (caf::Utils::fileExists(caseFileNameWithExt)) if (caf::Utils::fileExists(caseFileNameWithExt))
{ {
RiaImportEclipseCaseTools::openEclipseCasesFromFile(QStringList({ caseFileNameWithExt }), nullptr, true); RiaImportEclipseCaseTools::openEclipseCasesFromFile(QStringList({caseFileNameWithExt}), nullptr, true);
} }
else else
{ {
caseFileNameWithExt = caseName + ".GRID"; caseFileNameWithExt = caseName + ".GRID";
if (caf::Utils::fileExists(caseFileNameWithExt)) if (caf::Utils::fileExists(caseFileNameWithExt))
{ {
RiaImportEclipseCaseTools::openEclipseCasesFromFile(QStringList({ caseFileNameWithExt }), nullptr, true); RiaImportEclipseCaseTools::openEclipseCasesFromFile(QStringList({caseFileNameWithExt}), nullptr, true);
} }
} }
} }
} }
} }
if (cvf::Option o = progOpt.option("savesnapshots")) if (cvf::Option o = progOpt.option("savesnapshots"))
{ {
bool snapshotViews = false; bool snapshotViews = false;
@ -333,7 +357,8 @@ bool RiaArgumentParser::parseArguments()
// 2016-11-09 : Location of snapshot folder was previously located in 'snapshot' folder // 2016-11-09 : Location of snapshot folder was previously located in 'snapshot' folder
// relative to current working folder. Now harmonized to behave as RiuMainWindow::slotSnapshotAllViewsToFile() // relative to current working folder. Now harmonized to behave as RiuMainWindow::slotSnapshotAllViewsToFile()
QString absolutePathToSnapshotDir = RiaApplication::instance()->createAbsolutePathFromProjectRelativePath("snapshots"); QString absolutePathToSnapshotDir =
RiaApplication::instance()->createAbsolutePathFromProjectRelativePath("snapshots");
RicSnapshotAllViewsToFileFeature::exportSnapshotOfAllViewsIntoFolder(absolutePathToSnapshotDir); RicSnapshotAllViewsToFileFeature::exportSnapshotOfAllViewsIntoFolder(absolutePathToSnapshotDir);
mainWnd->loadWinGeoAndDockToolBarLayout(); mainWnd->loadWinGeoAndDockToolBarLayout();
@ -362,12 +387,12 @@ bool RiaArgumentParser::parseArguments()
QString commandFile = cvfqt::Utils::toQString(o.safeValue(0)); QString commandFile = cvfqt::Utils::toQString(o.safeValue(0));
cvf::Option projectOption = progOpt.option("commandFileProject"); cvf::Option projectOption = progOpt.option("commandFileProject");
cvf::Option caseOption = progOpt.option("commandFileReplaceCases"); cvf::Option caseOption = progOpt.option("commandFileReplaceCases");
if (projectOption && caseOption) if (projectOption && caseOption)
{ {
projectFileName = cvfqt::Utils::toQString(projectOption.value(0)); projectFileName = cvfqt::Utils::toQString(projectOption.value(0));
std::vector<int> caseIds; std::vector<int> caseIds;
std::vector<QString> caseListFiles; std::vector<QString> caseListFiles;
if (caseOption.valueCount() == 1) if (caseOption.valueCount() == 1)
@ -379,8 +404,8 @@ bool RiaArgumentParser::parseArguments()
size_t optionIdx = 0; size_t optionIdx = 0;
while (optionIdx < caseOption.valueCount()) while (optionIdx < caseOption.valueCount())
{ {
const int caseId = caseOption.safeValue(optionIdx++).toInt(-1); const int caseId = caseOption.safeValue(optionIdx++).toInt(-1);
QString caseListFile = cvfqt::Utils::toQString(caseOption.safeValue(optionIdx++)); QString caseListFile = cvfqt::Utils::toQString(caseOption.safeValue(optionIdx++));
if (caseId != -1 && !caseListFile.isEmpty()) if (caseId != -1 && !caseListFile.isEmpty())
{ {
@ -392,8 +417,8 @@ bool RiaArgumentParser::parseArguments()
if (caseIds.empty() && !caseListFiles.empty()) if (caseIds.empty() && !caseListFiles.empty())
{ {
QString caseListFile = caseListFiles[0]; QString caseListFile = caseListFiles[0];
std::vector<QString> caseFiles = RiaApplication::readFileListFromTextFile(caseListFile); std::vector<QString> caseFiles = RiaApplication::readFileListFromTextFile(caseListFile);
for (const QString& caseFile : caseFiles) for (const QString& caseFile : caseFiles)
{ {
RiaProjectModifier projectModifier; RiaProjectModifier projectModifier;
@ -406,8 +431,8 @@ bool RiaArgumentParser::parseArguments()
{ {
CVF_ASSERT(caseIds.size() == caseListFiles.size()); CVF_ASSERT(caseIds.size() == caseListFiles.size());
std::vector< std::vector<QString> > allCaseFiles; std::vector<std::vector<QString>> allCaseFiles;
size_t maxFiles = 0; size_t maxFiles = 0;
for (size_t i = 0; i < caseIds.size(); ++i) for (size_t i = 0; i < caseIds.size(); ++i)
{ {
@ -447,7 +472,7 @@ bool RiaArgumentParser::parseArguments()
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
void RiaArgumentParser::executeCommandFile(const QString& commandFile) void RiaArgumentParser::executeCommandFile(const QString& commandFile)
{ {
QFile file(commandFile); QFile file(commandFile);
RicfMessages messages; RicfMessages messages;
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
{ {