mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
First cut, command line options for batch processing
First cut implementation of command line oprions for batch proccessing. Added support for the follwoing new command line options: size, replacecase, replaceSourceCase and multiCaseSnapshots Reworked the entire command line processing code.
This commit is contained in:
@@ -48,6 +48,7 @@
|
||||
#include "RimUiTreeModelPdm.h"
|
||||
#include "RiaImageCompareReporter.h"
|
||||
#include "RiaImageFileCompare.h"
|
||||
#include "RiaProjectModifier.h"
|
||||
#include "cafProgressInfo.h"
|
||||
#include "RigGridManager.h"
|
||||
|
||||
@@ -72,8 +73,13 @@
|
||||
#include "RimCellPropertyFilterCollection.h"
|
||||
#include "Rim3dOverlayInfoConfig.h"
|
||||
#include "RimWellCollection.h"
|
||||
#include "RimStatisticsCase.h"
|
||||
#include "cafCeetronPlusNavigation.h"
|
||||
|
||||
#include "cvfProgramOptions.h"
|
||||
#include "cvfqtUtils.h"
|
||||
|
||||
|
||||
namespace caf
|
||||
{
|
||||
template<>
|
||||
@@ -98,6 +104,9 @@ namespace RegTestNames
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//==================================================================================================
|
||||
///
|
||||
/// \class RiaApplication
|
||||
@@ -240,10 +249,11 @@ const char* RiaApplication::getVersionStringApp(bool includeCrtInfo)
|
||||
}
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RiaApplication::loadProject(const QString& projectFileName)
|
||||
bool RiaApplication::loadProject(const QString& projectFileName, ProjectLoadAction loadAction, RiaProjectModifier* projectModifier)
|
||||
{
|
||||
// First Close the current project
|
||||
|
||||
@@ -257,6 +267,12 @@ bool RiaApplication::loadProject(const QString& projectFileName)
|
||||
m_project->fileName = projectFileName;
|
||||
m_project->readFile();
|
||||
|
||||
// Apply any modifiactions to the loaded project before we go ahead and load actual data
|
||||
if (projectModifier)
|
||||
{
|
||||
projectModifier->applyModificationsToProject(m_project);
|
||||
}
|
||||
|
||||
// Propagate possible new location of project
|
||||
|
||||
m_project->setProjectFileNameAndUpdateDependencies(projectFileName);
|
||||
@@ -319,6 +335,23 @@ bool RiaApplication::loadProject(const QString& projectFileName)
|
||||
if (oilField->wellPathCollection) oilField->wellPathCollection->readWellPathFiles();
|
||||
}
|
||||
|
||||
|
||||
// If load action is specified to recalculate statistics, do it now.
|
||||
// Apparently this needs to be done before the views are loaded, lest the number of time steps for statistics will be clamped
|
||||
if (loadAction & PLA_CALCULATE_STATISTICS)
|
||||
{
|
||||
for (size_t oilFieldIdx = 0; oilFieldIdx < m_project->oilFields().size(); oilFieldIdx++)
|
||||
{
|
||||
RimOilField* oilField = m_project->oilFields[oilFieldIdx];
|
||||
RimAnalysisModels* analysisModels = oilField ? oilField->analysisModels() : NULL;
|
||||
if (analysisModels)
|
||||
{
|
||||
analysisModels->recomputeStatisticsForAllCaseGroups();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Now load the ReservoirViews for the cases
|
||||
// Add all "native" cases in the project
|
||||
std::vector<RimCase*> casesToLoad;
|
||||
@@ -351,6 +384,8 @@ bool RiaApplication::loadProject(const QString& projectFileName)
|
||||
caseProgress.incrementProgress();
|
||||
}
|
||||
|
||||
|
||||
|
||||
// NB! This function must be called before executing command objects,
|
||||
// because the tree view state is restored from project file and sets
|
||||
// current active view ( see restoreTreeViewState() )
|
||||
@@ -374,6 +409,15 @@ bool RiaApplication::loadProject(const QString& projectFileName)
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RiaApplication::loadProject(const QString& projectFileName)
|
||||
{
|
||||
return loadProject(projectFileName, PLA_NONE, NULL);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Add a list of well path file paths (JSON files) to the well path collection
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -398,15 +442,6 @@ void RiaApplication::addWellPathsToModel(QList<QString> wellPathFilePaths)
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RiaApplication::loadLastUsedProject()
|
||||
{
|
||||
return loadProject(m_preferences->lastUsedProjectFileName);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -544,6 +579,33 @@ QString RiaApplication::currentProjectFileName() const
|
||||
}
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Create an absolute path from a path that is specified relative to the project directory
|
||||
///
|
||||
/// If the path specified in \a projectRelativePath is already absolute, no changes will be made
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RiaApplication::createAbsolutePathFromProjectRelativePath(QString projectRelativePath)
|
||||
{
|
||||
// Check if path is already absolute
|
||||
if (QDir::isAbsolutePath(projectRelativePath))
|
||||
{
|
||||
return projectRelativePath;
|
||||
}
|
||||
|
||||
if (m_project && !m_project->fileName().isEmpty())
|
||||
{
|
||||
QString absoluteProjectPath = QFileInfo(m_project->fileName()).absolutePath();
|
||||
QDir projectDir(absoluteProjectPath);
|
||||
return projectDir.absoluteFilePath(projectRelativePath);
|
||||
}
|
||||
else
|
||||
{
|
||||
return projectRelativePath;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -743,7 +805,7 @@ bool RiaApplication::showPerformanceInfo() const
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RiaApplication::parseArguments()
|
||||
bool RiaApplication::parseArguments_OLD()
|
||||
{
|
||||
QStringList arguments = QCoreApplication::arguments();
|
||||
|
||||
@@ -767,7 +829,7 @@ bool RiaApplication::parseArguments()
|
||||
bool isSaveSnapshotsForAllViews = false;
|
||||
bool isRunRegressionTest = false;
|
||||
bool isUpdateRegressionTest = false;
|
||||
|
||||
|
||||
int i;
|
||||
for (i = 1; i < arguments.size(); i++)
|
||||
{
|
||||
@@ -825,7 +887,7 @@ bool RiaApplication::parseArguments()
|
||||
|
||||
foundKnownOption = true;
|
||||
}
|
||||
|
||||
|
||||
if (!foundKnownOption)
|
||||
{
|
||||
switch (argumentParsingType)
|
||||
@@ -849,7 +911,7 @@ bool RiaApplication::parseArguments()
|
||||
break;
|
||||
case PARSE_REGRESSION_TEST_PATH:
|
||||
{
|
||||
regressionTestPath = arg;
|
||||
regressionTestPath = arg;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -884,14 +946,14 @@ bool RiaApplication::parseArguments()
|
||||
|
||||
if (openLatestProject)
|
||||
{
|
||||
loadLastUsedProject();
|
||||
loadProject(m_preferences->lastUsedProjectFileName);
|
||||
}
|
||||
|
||||
|
||||
if (!projectFilename.isEmpty())
|
||||
{
|
||||
loadProject(projectFilename);
|
||||
}
|
||||
|
||||
|
||||
if (!caseNames.isEmpty())
|
||||
{
|
||||
QString caseName;
|
||||
@@ -916,6 +978,7 @@ bool RiaApplication::parseArguments()
|
||||
|
||||
if (m_project.notNull() && !m_project->fileName().isEmpty() && isSaveSnapshotsForAllViews)
|
||||
{
|
||||
// Will be saved relative to current directory
|
||||
saveSnapshotForAllViews("snapshots");
|
||||
|
||||
// Returning false will exit the application
|
||||
@@ -926,6 +989,238 @@ bool RiaApplication::parseArguments()
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RiaApplication::parseArguments()
|
||||
{
|
||||
cvf::ProgramOptions progOpt;
|
||||
progOpt.registerOption("help");
|
||||
progOpt.registerOption("?");
|
||||
progOpt.registerOption("last", "", "Open last used project");
|
||||
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("startdir", "<folder>", "Set startup directory", cvf::ProgramOptions::SINGLE_VALUE);
|
||||
progOpt.registerOption("savesnapshots", "", "Save snapshot of all views to 'snapshots' folder");
|
||||
progOpt.registerOption("regressiontest", "<folder>", "", cvf::ProgramOptions::SINGLE_VALUE);
|
||||
progOpt.registerOption("updateregressiontestbase", "<folder>", "", cvf::ProgramOptions::SINGLE_VALUE);
|
||||
progOpt.registerOption("size", "<width> <height>", "Set size of the main application window", cvf::ProgramOptions::MULTI_VALUE);
|
||||
progOpt.registerOption("replaceCase", "[<caseId>] <newGridFile>", "Replace grid in <caseId> or first case with <newgridFile>", cvf::ProgramOptions::MULTI_VALUE);
|
||||
progOpt.registerOption("replaceSourceCases", "[<caseGroupId>] <gridListFile>", "Replace source cases in <caseGroupId> or first grid case group with grid files listed in <gridListFile>", cvf::ProgramOptions::MULTI_VALUE);
|
||||
progOpt.registerOption("multiCaseSnapshots", "<gridListFile>", "For each grid file listed in <gridListFile>, replace the first case in the project and save snapshot of all views", cvf::ProgramOptions::SINGLE_VALUE);
|
||||
|
||||
progOpt.setOptionPrefix(cvf::ProgramOptions::DOUBLE_DASH);
|
||||
|
||||
QStringList arguments = QCoreApplication::arguments();
|
||||
|
||||
bool parseOk = progOpt.parse(cvfqt::Utils::toStringVector(arguments));
|
||||
|
||||
if (!parseOk || progOpt.hasOption("help") || progOpt.hasOption("?"))
|
||||
{
|
||||
{
|
||||
cvf::String usageText = progOpt.usageText(80, 30);
|
||||
cvf::Trace::show(usageText);
|
||||
}
|
||||
|
||||
QString helpText = commandLineParameterHelp();
|
||||
|
||||
#if defined(_MSC_VER) && defined(_WIN32)
|
||||
showFormattedTextInMessageBox(helpText);
|
||||
#else
|
||||
fprintf(stdout, "%s\n", helpText.toAscii().data());
|
||||
fflush(stdout);
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// Handling of the actual command line options
|
||||
// --------------------------------------------------------
|
||||
if (progOpt.hasOption("regressiontest"))
|
||||
{
|
||||
QString regressionTestPath = cvfqt::Utils::toQString(progOpt.firstValue("regressiontest"));
|
||||
executeRegressionTests(regressionTestPath);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (progOpt.hasOption("updateregressiontestbase"))
|
||||
{
|
||||
QString regressionTestPath = cvfqt::Utils::toQString(progOpt.firstValue("updateregressiontestbase"));
|
||||
updateRegressionTest(regressionTestPath);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (progOpt.hasOption("startdir"))
|
||||
{
|
||||
m_startupDefaultDirectory = cvfqt::Utils::toQString(progOpt.firstValue("startdir"));
|
||||
}
|
||||
|
||||
if (progOpt.hasOption("size"))
|
||||
{
|
||||
std::vector<cvf::String> vals = progOpt.values("size");
|
||||
RiuMainWindow* mainWnd = RiuMainWindow::instance();
|
||||
int width = (vals.size() > 0) ? vals[0].toInt(-1) : -1;
|
||||
int height = (vals.size() > 1) ? vals[1].toInt(-1) : -1;
|
||||
if (mainWnd && width > 0 && height > 0)
|
||||
{
|
||||
mainWnd->resize(width, height);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
QString projectFileName;
|
||||
|
||||
if (progOpt.hasOption("last"))
|
||||
{
|
||||
projectFileName = m_preferences->lastUsedProjectFileName;
|
||||
}
|
||||
|
||||
if (progOpt.hasOption("project"))
|
||||
{
|
||||
projectFileName = cvfqt::Utils::toQString(progOpt.firstValue("project"));
|
||||
}
|
||||
|
||||
|
||||
if (progOpt.hasOption("multiCaseSnapshots") && !projectFileName.isEmpty())
|
||||
{
|
||||
QString gridListFile = cvfqt::Utils::toQString(progOpt.firstValue("multiCaseSnapshots"));
|
||||
std::vector<QString> gridFiles = readFileListFromTextFile(gridListFile);
|
||||
runMultiCaseSnapshots(projectFileName, gridFiles, "multiCaseSnapshots");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
if (!projectFileName.isEmpty())
|
||||
{
|
||||
cvf::ref<RiaProjectModifier> projectModifier;
|
||||
ProjectLoadAction projectLoadAction = PLA_NONE;
|
||||
|
||||
if (progOpt.hasOption("replaceCase"))
|
||||
{
|
||||
if (projectModifier.isNull()) projectModifier = new RiaProjectModifier;
|
||||
|
||||
std::vector<cvf::String> vals = progOpt.values("replaceCase");
|
||||
CVF_ASSERT(vals.size() >= 1);
|
||||
if (vals.size() == 1)
|
||||
{
|
||||
QString gridFileName = cvfqt::Utils::toQString(vals[0]);
|
||||
projectModifier->setReplaceCaseFirstOccurence(gridFileName);
|
||||
}
|
||||
else
|
||||
{
|
||||
const int caseId = vals[0].toInt(cvf::UNDEFINED_INT);
|
||||
if (caseId != cvf::UNDEFINED_INT)
|
||||
{
|
||||
QString gridFileName = cvfqt::Utils::toQString(vals[1]);
|
||||
projectModifier->setReplaceCase(caseId, gridFileName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (progOpt.hasOption("replaceSourceCases"))
|
||||
{
|
||||
if (projectModifier.isNull()) projectModifier = new RiaProjectModifier;
|
||||
|
||||
std::vector<cvf::String> vals = progOpt.values("replaceSourceCases");
|
||||
CVF_ASSERT(vals.size() >= 1);
|
||||
if (vals.size() == 1)
|
||||
{
|
||||
std::vector<QString> gridFileNames = readFileListFromTextFile(cvfqt::Utils::toQString(vals[0]));
|
||||
projectModifier->setReplaceSourceCasesFirstOccurence(gridFileNames);
|
||||
}
|
||||
else
|
||||
{
|
||||
const int caseGroupId = vals[0].toInt(cvf::UNDEFINED_INT);
|
||||
if (caseGroupId != cvf::UNDEFINED_INT)
|
||||
{
|
||||
std::vector<QString> gridFileNames = readFileListFromTextFile(cvfqt::Utils::toQString(vals[1]));
|
||||
projectModifier->setReplaceSourceCasesById(caseGroupId, gridFileNames);
|
||||
}
|
||||
}
|
||||
|
||||
projectLoadAction = PLA_CALCULATE_STATISTICS;
|
||||
}
|
||||
|
||||
|
||||
loadProject(projectFileName, projectLoadAction, projectModifier.p());
|
||||
}
|
||||
|
||||
|
||||
if (progOpt.hasOption("case"))
|
||||
{
|
||||
QStringList caseNames = cvfqt::Utils::toQStringList(progOpt.values("case"));
|
||||
foreach (QString caseName, caseNames)
|
||||
{
|
||||
QString caseFileNameWithExt = caseName + ".EGRID";
|
||||
if (QFile::exists(caseFileNameWithExt))
|
||||
{
|
||||
openEclipseCaseFromFile(caseFileNameWithExt);
|
||||
}
|
||||
else
|
||||
{
|
||||
caseFileNameWithExt = caseName + ".GRID";
|
||||
if (QFile::exists(caseFileNameWithExt))
|
||||
{
|
||||
openEclipseCaseFromFile(caseFileNameWithExt);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (progOpt.hasOption("savesnapshots"))
|
||||
{
|
||||
RiuMainWindow* mainWnd = RiuMainWindow::instance();
|
||||
if (m_project.notNull() && !m_project->fileName().isEmpty() && mainWnd)
|
||||
{
|
||||
mainWnd->hideAllDockWindows();
|
||||
|
||||
// Will be saved relative to current directory
|
||||
saveSnapshotForAllViews("snapshots");
|
||||
|
||||
mainWnd->loadWinGeoAndDockToolBarLayout();
|
||||
}
|
||||
|
||||
// Returning false will exit the application
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::vector<QString> RiaApplication::readFileListFromTextFile(QString listFileName)
|
||||
{
|
||||
std::vector<QString> fileList;
|
||||
|
||||
QFile file(listFileName);
|
||||
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
|
||||
{
|
||||
return fileList;
|
||||
}
|
||||
|
||||
QTextStream in(&file);
|
||||
QString line = in.readLine();
|
||||
while (!line.isNull())
|
||||
{
|
||||
line = line.trimmed();
|
||||
if (!line.isEmpty())
|
||||
{
|
||||
fileList.push_back(line);
|
||||
}
|
||||
|
||||
line = in.readLine();
|
||||
}
|
||||
|
||||
return fileList;
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -1195,6 +1490,7 @@ void RiaApplication::setDefaultFileDialogDirectory(const QString& dialogName, co
|
||||
m_fileDialogDefaultDirectories[dialogName] = defaultDirectory;
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -1270,18 +1566,14 @@ void RiaApplication::saveSnapshotForAllViews(const QString& snapshotFolderName)
|
||||
|
||||
if (m_project.isNull()) return;
|
||||
|
||||
if (m_project->fileName().isEmpty()) return;
|
||||
|
||||
QFileInfo fi(m_project->fileName());
|
||||
QDir projectDir(fi.absolutePath());
|
||||
|
||||
if (!projectDir.exists(snapshotFolderName))
|
||||
QDir snapshotPath(snapshotFolderName);
|
||||
if (!snapshotPath.exists())
|
||||
{
|
||||
if (!projectDir.mkdir(snapshotFolderName)) return;
|
||||
if (!snapshotPath.mkpath(".")) return;
|
||||
}
|
||||
|
||||
QString snapshotPath = projectDir.absolutePath();
|
||||
snapshotPath += "/" + snapshotFolderName;
|
||||
const QString absSnapshotPath = snapshotPath.absolutePath();
|
||||
|
||||
std::vector<RimCase*> projectCases;
|
||||
m_project->allCases(projectCases);
|
||||
@@ -1307,13 +1599,43 @@ void RiaApplication::saveSnapshotForAllViews(const QString& snapshotFolderName)
|
||||
|
||||
QString fileName = ri->caseUserDescription() + "-" + riv->name();
|
||||
|
||||
QString absoluteFileName = caf::Utils::constructFullFileName(snapshotPath, fileName, ".png");
|
||||
QString absoluteFileName = caf::Utils::constructFullFileName(absSnapshotPath, fileName, ".png");
|
||||
saveSnapshotAs(absoluteFileName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaApplication::runMultiCaseSnapshots(const QString& templateProjectFileName, std::vector<QString> gridFileNames, const QString& snapshotFolderName)
|
||||
{
|
||||
RiuMainWindow* mainWnd = RiuMainWindow::instance();
|
||||
if (!mainWnd) return;
|
||||
|
||||
mainWnd->hideAllDockWindows();
|
||||
|
||||
const size_t numGridFiles = gridFileNames.size();
|
||||
for (size_t i = 0; i < numGridFiles; i++)
|
||||
{
|
||||
QString gridFn = gridFileNames[i];
|
||||
|
||||
RiaProjectModifier modifier;
|
||||
modifier.setReplaceCaseFirstOccurence(gridFn);
|
||||
|
||||
bool loadOk = loadProject(templateProjectFileName, PLA_NONE, &modifier);
|
||||
if (loadOk)
|
||||
{
|
||||
saveSnapshotForAllViews(snapshotFolderName);
|
||||
}
|
||||
}
|
||||
|
||||
mainWnd->loadWinGeoAndDockToolBarLayout();
|
||||
}
|
||||
|
||||
|
||||
void removeDirectoryWithContent(QDir dirToDelete )
|
||||
{
|
||||
QStringList files = dirToDelete.entryList();
|
||||
@@ -1403,7 +1725,8 @@ void RiaApplication::runRegressionTest(const QString& testRootPath)
|
||||
|
||||
regressionTestSetFixedSizeForAllViews();
|
||||
|
||||
saveSnapshotForAllViews(generatedFolderName);
|
||||
QString fullPathGeneratedFolder = testCaseFolder.absoluteFilePath(generatedFolderName);
|
||||
saveSnapshotForAllViews(fullPathGeneratedFolder);
|
||||
|
||||
QDir baseDir(testCaseFolder.filePath(baseFolderName));
|
||||
QDir genDir(testCaseFolder.filePath(generatedFolderName));
|
||||
|
||||
@@ -38,6 +38,7 @@ class RiaPreferences;
|
||||
class RimReservoirView;
|
||||
class RimProject;
|
||||
class RimCommandObject;
|
||||
class RiaProjectModifier;
|
||||
|
||||
namespace caf
|
||||
{
|
||||
@@ -65,6 +66,7 @@ public:
|
||||
~RiaApplication();
|
||||
static RiaApplication* instance();
|
||||
|
||||
bool parseArguments_OLD();
|
||||
bool parseArguments();
|
||||
|
||||
void executeRegressionTests(const QString& regressionTestPath);
|
||||
@@ -90,9 +92,9 @@ public:
|
||||
bool addEclipseCases(const QStringList& fileNames);
|
||||
bool openInputEclipseCaseFromFileNames(const QStringList& fileNames);
|
||||
|
||||
bool loadLastUsedProject();
|
||||
QString currentProjectFileName() const;
|
||||
bool loadProject(const QString& fileName);
|
||||
QString createAbsolutePathFromProjectRelativePath(QString projectRelativePath);
|
||||
bool loadProject(const QString& projectFileName);
|
||||
bool saveProject();
|
||||
bool saveProjectAs(const QString& fileName);
|
||||
bool saveProjectPromptForFileName();
|
||||
@@ -103,13 +105,14 @@ public:
|
||||
void saveSnapshotPromtpForFilename();
|
||||
void saveSnapshotAs(const QString& fileName);
|
||||
void saveSnapshotForAllViews(const QString& snapshotFolderName);
|
||||
void runMultiCaseSnapshots(const QString& templateProjectFileName, std::vector<QString> gridFileNames, const QString& snapshotFolderName);
|
||||
void runRegressionTest(const QString& testRootPath);
|
||||
void updateRegressionTest(const QString& testRootPath );
|
||||
void regressionTestSetFixedSizeForAllViews();
|
||||
|
||||
void processNonGuiEvents();
|
||||
|
||||
static const char* getVersionStringApp(bool includeCrtInfo);
|
||||
static const char* getVersionStringApp(bool includeCrtInfo);
|
||||
|
||||
void setUseShaders(bool enable);
|
||||
bool useShaders() const;
|
||||
@@ -143,10 +146,18 @@ public:
|
||||
void executeCommandObjects();
|
||||
|
||||
private:
|
||||
void onProjectOpenedOrClosed();
|
||||
void setWindowCaptionFromAppState();
|
||||
enum ProjectLoadAction
|
||||
{
|
||||
PLA_NONE = 0,
|
||||
PLA_CALCULATE_STATISTICS = 1
|
||||
};
|
||||
|
||||
bool loadProject(const QString& projectFileName, ProjectLoadAction loadAction, RiaProjectModifier* projectModifier);
|
||||
void onProjectOpenedOrClosed();
|
||||
std::vector<QString> readFileListFromTextFile(QString listFileName);
|
||||
void setWindowCaptionFromAppState();
|
||||
|
||||
QImage grabFrameBufferImage();
|
||||
QImage grabFrameBufferImage();
|
||||
|
||||
private slots:
|
||||
void slotWorkerProcessFinished(int exitCode, QProcess::ExitStatus exitStatus);
|
||||
|
||||
255
ApplicationCode/Application/RiaProjectModifier.cpp
Normal file
255
ApplicationCode/Application/RiaProjectModifier.cpp
Normal file
@@ -0,0 +1,255 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) Statoil ASA, Ceetron Solutions AS
|
||||
//
|
||||
// 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 "RiaStdInclude.h"
|
||||
|
||||
#include "RiaProjectModifier.h"
|
||||
|
||||
#include "RimProject.h"
|
||||
#include "RimAnalysisModels.h"
|
||||
#include "RimOilField.h"
|
||||
#include "RimIdenticalGridCaseGroup.h"
|
||||
#include "RimCaseCollection.h"
|
||||
#include "RimResultCase.h"
|
||||
|
||||
#include "RimReservoirView.h"
|
||||
#include "RimWellPathCollection.h"
|
||||
#include "RimScriptCollection.h"
|
||||
#include "RimCellPropertyFilterCollection.h"
|
||||
#include "RimCellPropertyFilter.h"
|
||||
#include "RimReservoirCellResultsCacher.h"
|
||||
#include "RimResultSlot.h"
|
||||
#include "RimCellEdgeResultSlot.h"
|
||||
#include "RimCellRangeFilterCollection.h"
|
||||
#include "RimWellCollection.h"
|
||||
#include "Rim3dOverlayInfoConfig.h"
|
||||
|
||||
|
||||
|
||||
|
||||
//==================================================================================================
|
||||
//
|
||||
//
|
||||
//
|
||||
//==================================================================================================
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RiaProjectModifier::RiaProjectModifier()
|
||||
: m_replaceCase_caseId(UNDEFINED),
|
||||
m_replaceSourceCases_caseGroupId(UNDEFINED)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaProjectModifier::setReplaceCaseFirstOccurence(QString newGridFileName)
|
||||
{
|
||||
m_replaceCase_caseId = FIRST_OCCURENCE;
|
||||
m_replaceCase_gridFileName = makeFilePathAbsolute(newGridFileName);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaProjectModifier::setReplaceCase(int caseIdToReplace, QString newGridFileName)
|
||||
{
|
||||
if (caseIdToReplace >= 0)
|
||||
{
|
||||
m_replaceCase_caseId = caseIdToReplace;
|
||||
m_replaceCase_gridFileName = makeFilePathAbsolute(newGridFileName);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaProjectModifier::setReplaceSourceCasesFirstOccurence(std::vector<QString> newGridFileNames)
|
||||
{
|
||||
m_replaceSourceCases_caseGroupId = FIRST_OCCURENCE;
|
||||
|
||||
m_replaceSourceCases_gridFileNames.clear();
|
||||
foreach (QString fn, newGridFileNames)
|
||||
{
|
||||
m_replaceSourceCases_gridFileNames.push_back(makeFilePathAbsolute(fn));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaProjectModifier::setReplaceSourceCasesById(int caseGroupIdToReplace, std::vector<QString> newGridFileNames)
|
||||
{
|
||||
if (caseGroupIdToReplace >= 0)
|
||||
{
|
||||
m_replaceSourceCases_caseGroupId = caseGroupIdToReplace;
|
||||
|
||||
m_replaceSourceCases_gridFileNames.clear();
|
||||
foreach (QString fn, newGridFileNames)
|
||||
{
|
||||
m_replaceSourceCases_gridFileNames.push_back(makeFilePathAbsolute(fn));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RiaProjectModifier::applyModificationsToProject(RimProject* project)
|
||||
{
|
||||
if (m_replaceCase_caseId != UNDEFINED && !m_replaceCase_gridFileName.isEmpty())
|
||||
{
|
||||
replaceCase(project);
|
||||
}
|
||||
|
||||
if (m_replaceSourceCases_caseGroupId != UNDEFINED && m_replaceSourceCases_gridFileNames.size() > 0)
|
||||
{
|
||||
replaceSourceCases(project);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RiaProjectModifier::replaceSourceCases(RimProject* project)
|
||||
{
|
||||
bool didReplacement = false;
|
||||
|
||||
for (size_t oilFieldIdx = 0; oilFieldIdx < project->oilFields().size(); oilFieldIdx++)
|
||||
{
|
||||
RimOilField* oilField = project->oilFields[oilFieldIdx];
|
||||
RimAnalysisModels* analysisModels = oilField ? oilField->analysisModels() : NULL;
|
||||
if (analysisModels)
|
||||
{
|
||||
const size_t numCaseGroups = analysisModels->caseGroups.size();
|
||||
for (size_t caseGrpIdx = 0; caseGrpIdx < numCaseGroups; ++caseGrpIdx)
|
||||
{
|
||||
RimIdenticalGridCaseGroup* caseGroup = analysisModels->caseGroups[caseGrpIdx];
|
||||
if (m_replaceSourceCases_caseGroupId == FIRST_OCCURENCE ||
|
||||
m_replaceSourceCases_caseGroupId == caseGroup->groupId)
|
||||
{
|
||||
RimCaseCollection* caseCollection = caseGroup->caseCollection;
|
||||
caseCollection->reservoirs.deleteAllChildObjects();
|
||||
|
||||
for (size_t i = 0; i < m_replaceSourceCases_gridFileNames.size(); i++)
|
||||
{
|
||||
QString fileName = m_replaceSourceCases_gridFileNames[i];
|
||||
QString caseName = caseNameFromGridFileName(fileName);
|
||||
|
||||
// Use this slightly hackish method in order to get a new unique ID
|
||||
RimResultCase* resCase = new RimResultCase;
|
||||
resCase->setCaseInfo(caseName, fileName);
|
||||
|
||||
caseCollection->reservoirs.push_back(resCase);
|
||||
}
|
||||
|
||||
didReplacement = true;
|
||||
|
||||
if (m_replaceSourceCases_caseGroupId == FIRST_OCCURENCE)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return didReplacement;
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RiaProjectModifier::replaceCase(RimProject* project)
|
||||
{
|
||||
bool didReplacement = false;
|
||||
|
||||
for (size_t oilFieldIdx = 0; oilFieldIdx < project->oilFields().size(); oilFieldIdx++)
|
||||
{
|
||||
RimOilField* oilField = project->oilFields[oilFieldIdx];
|
||||
RimAnalysisModels* analysisModels = oilField ? oilField->analysisModels() : NULL;
|
||||
if (analysisModels)
|
||||
{
|
||||
for (size_t caseIdx = 0; caseIdx < analysisModels->cases.size(); ++caseIdx)
|
||||
{
|
||||
RimResultCase* resultCase = dynamic_cast<RimResultCase*>(analysisModels->cases[caseIdx]);
|
||||
if (resultCase)
|
||||
{
|
||||
if (m_replaceCase_caseId == FIRST_OCCURENCE ||
|
||||
m_replaceCase_caseId == resultCase->caseId())
|
||||
{
|
||||
resultCase->setGridFileName(m_replaceCase_gridFileName);
|
||||
resultCase->caseUserDescription = caseNameFromGridFileName(m_replaceCase_gridFileName);
|
||||
didReplacement = true;
|
||||
|
||||
if (m_replaceCase_caseId == FIRST_OCCURENCE)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return didReplacement;
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Returns absolute path name to the specified file.
|
||||
///
|
||||
/// If \a relOrAbsolutePath is a relative, the current working directory for the process will be
|
||||
/// used in order to make the path absolute.
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RiaProjectModifier::makeFilePathAbsolute(QString relOrAbsolutePath)
|
||||
{
|
||||
QFileInfo theFile(relOrAbsolutePath);
|
||||
theFile.makeAbsolute();
|
||||
return theFile.filePath();
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RiaProjectModifier::caseNameFromGridFileName(QString fullGridFilePathName)
|
||||
{
|
||||
QString fn = QDir::fromNativeSeparators(fullGridFilePathName);
|
||||
|
||||
// Extract file name plus the 'deepest' directory
|
||||
QString deepestDirPlusFileName = fn.section('/', -2, -1);
|
||||
|
||||
deepestDirPlusFileName.replace("/", "--");
|
||||
|
||||
return deepestDirPlusFileName;
|
||||
}
|
||||
|
||||
|
||||
62
ApplicationCode/Application/RiaProjectModifier.h
Normal file
62
ApplicationCode/Application/RiaProjectModifier.h
Normal file
@@ -0,0 +1,62 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) Statoil ASA, Ceetron Solutions AS
|
||||
//
|
||||
// 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
|
||||
class RimProject;
|
||||
|
||||
|
||||
|
||||
//==================================================================================================
|
||||
//
|
||||
//
|
||||
//
|
||||
//==================================================================================================
|
||||
class RiaProjectModifier : public cvf::Object
|
||||
{
|
||||
public:
|
||||
RiaProjectModifier();
|
||||
|
||||
void setReplaceCaseFirstOccurence(QString newGridFileName);
|
||||
void setReplaceCase(int caseIdToReplace, QString newGridFileName);
|
||||
|
||||
void setReplaceSourceCasesFirstOccurence(std::vector<QString> newGridFileNames);
|
||||
void setReplaceSourceCasesById(int caseGroupIdToReplace, std::vector<QString> newGridFileNames);
|
||||
|
||||
bool applyModificationsToProject(RimProject* project);
|
||||
|
||||
private:
|
||||
bool replaceSourceCases(RimProject* project);
|
||||
bool replaceCase(RimProject* project);
|
||||
static QString makeFilePathAbsolute(QString relOrAbsolutePath);
|
||||
static QString caseNameFromGridFileName(QString fullGridFilePathName);
|
||||
|
||||
private:
|
||||
int m_replaceCase_caseId;
|
||||
QString m_replaceCase_gridFileName;
|
||||
|
||||
int m_replaceSourceCases_caseGroupId;
|
||||
std::vector<QString> m_replaceSourceCases_gridFileNames;
|
||||
|
||||
static const int UNDEFINED = -1;
|
||||
static const int FIRST_OCCURENCE = -999;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user