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:
sigurdp
2013-12-04 12:04:42 +01:00
parent 192f4bba59
commit 0656b5254f
6 changed files with 759 additions and 104 deletions

View File

@@ -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));

View File

@@ -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);

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

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

View File

@@ -21,7 +21,7 @@ include_directories(
${CMAKE_CURRENT_SOURCE_DIR}/ReservoirDataModel
${CMAKE_CURRENT_SOURCE_DIR}/WellPathImportSsihub
${CMAKE_BINARY_DIR}/Generated
${CMAKE_CURRENT_BINARY_DIR}
${CMAKE_CURRENT_BINARY_DIR}
)
@@ -34,9 +34,10 @@ set( APPLICATION_FILES
Application/RiaApplication.cpp
Application/RiaPreferences.cpp
Application/RiaImageFileCompare.cpp
Application/RiaImageCompareReporter.cpp
Application/RiaRegressionTest.cpp
Application/RiaImageFileCompare.cpp
Application/RiaImageCompareReporter.cpp
Application/RiaProjectModifier.cpp
Application/RiaRegressionTest.cpp
)
set( USER_INTERFACE_FILES
@@ -46,7 +47,7 @@ set( USER_INTERFACE_FILES
UserInterface/RiuResultInfoPanel.cpp
UserInterface/RiuViewer.cpp
UserInterface/RiuSimpleHistogramWidget.cpp
UserInterface/RiuMultiCaseImportDialog.cpp
UserInterface/RiuMultiCaseImportDialog.cpp
UserInterface/RiuProcessMonitor.cpp
)
@@ -56,7 +57,7 @@ set( SOCKET_INTERFACE_FILES
SocketInterface/RiaCaseInfoCommands.cpp
SocketInterface/RiaGeometryCommands.cpp
SocketInterface/RiaPropertyDataCommands.cpp
SocketInterface/RiaWellDataCommands.cpp
SocketInterface/RiaWellDataCommands.cpp
SocketInterface/RiaSocketTools.cpp
)
@@ -101,15 +102,15 @@ set ( QT_MOC_HEADERS
UserInterface/RiuResultInfoPanel.h
UserInterface/RiuViewer.h
UserInterface/RiuProcessMonitor.h
SocketInterface/RiaSocketServer.h
UserInterface/RiuMultiCaseImportDialog.h
SocketInterface/RiaSocketServer.h
UserInterface/RiuMultiCaseImportDialog.h
)
qt4_wrap_cpp( MOC_FILES_CPP ${QT_MOC_HEADERS} )
# Define files for the uic compiler
set ( QT_UI_FILES
UserInterface/RiuMultiCaseImportDialog.ui
UserInterface/RiuMultiCaseImportDialog.ui
)
qt4_wrap_ui( FORM_FILES_CPP ${QT_UI_FILES} )
@@ -141,19 +142,19 @@ endif()
set( RAW_SOURCES ${CPP_SOURCES} )
list( REMOVE_ITEM RAW_SOURCES
RiaStdInclude.cpp
RiaStdInclude.cpp
${CODE_SOURCE_FILES}
${CODE_SOURCE_FILES}
ModelVisualization/RivCellEdgeEffectGenerator.cpp
ModelVisualization/RivPipeGeometryGenerator.cpp
ModelVisualization/RivWellPipesPartMgr.cpp
ModelVisualization/RivWellHeadPartMgr.cpp
Application/RiaImageFileCompare.cpp
Application/RiaImageCompareReporter.cpp
Application/RiaRegressionTest.cpp
ModelVisualization/RivCellEdgeEffectGenerator.cpp
ModelVisualization/RivPipeGeometryGenerator.cpp
ModelVisualization/RivWellPipesPartMgr.cpp
ModelVisualization/RivWellHeadPartMgr.cpp
Application/RiaImageFileCompare.cpp
Application/RiaImageCompareReporter.cpp
Application/RiaRegressionTest.cpp
FileInterface/RifEclipseInputFileTools.cpp
FileInterface/RifEclipseOutputFileTools.cpp
FileInterface/RifEclipseRestartFilesetAccess.cpp
@@ -210,11 +211,11 @@ set( EXE_FILES
${EXE_FILES}
${CPP_SOURCES}
${MOC_FILES_CPP}
${FORM_FILES_CPP}
${FORM_FILES_CPP}
${QRC_FILES_CPP}
${WIN_RESOURCE}
${HEADER_FILES}
${REFERENCED_CMAKE_FILES}
${HEADER_FILES}
${REFERENCED_CMAKE_FILES}
../ResInsightVersion.cmake
)
@@ -249,8 +250,8 @@ set( EXTERNAL_LINK_LIBRARIES ${ERT_LIBRARY_LIST} )
# According to ivarun this is needed on OpenSuse, and Fedora. See: https://github.com/OPM/ResInsight/pull/7
if (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
set ( EXTERNAL_LINK_LIBRARIES
${EXTERNAL_LINK_LIBRARIES}
rt
${EXTERNAL_LINK_LIBRARIES}
rt
)
endif()
@@ -282,70 +283,70 @@ set (RESINSIGHT_LICENSE_FILES
# bundle libraries together with private installation
if (RESINSIGHT_PRIVATE_INSTALL)
if (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
# tell binary to first attempt to load libraries from its own directory
set_target_properties (ResInsight PROPERTIES INSTALL_RPATH "\$ORIGIN")
if (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
# tell binary to first attempt to load libraries from its own directory
set_target_properties (ResInsight PROPERTIES INSTALL_RPATH "\$ORIGIN")
# Find Qt libraries and sym links
file (GLOB RESINSIGHT_FILES
${QT_LIBRARY_DIR}/libQtCore.so*
${QT_LIBRARY_DIR}/libQtGui.so*
${QT_LIBRARY_DIR}/libQtOpenGL.so*
${QT_LIBRARY_DIR}/libQtNetwork.so*
${QT_LIBRARY_DIR}/libQtScript.so*
${QT_LIBRARY_DIR}/libQtScriptTools.so*
)
# Find Qt libraries and sym links
file (GLOB RESINSIGHT_FILES
${QT_LIBRARY_DIR}/libQtCore.so*
${QT_LIBRARY_DIR}/libQtGui.so*
${QT_LIBRARY_DIR}/libQtOpenGL.so*
${QT_LIBRARY_DIR}/libQtNetwork.so*
${QT_LIBRARY_DIR}/libQtScript.so*
${QT_LIBRARY_DIR}/libQtScriptTools.so*
)
endif()
endif()
if (${CMAKE_SYSTEM_NAME} MATCHES "Windows")
# put a .exe.local file in the target directory to pick up DLLs from there
install (CODE "exec_program (${CMAKE_COMMAND} ARGS -E touch \$ENV{DESTDIR}${CMAKE_INSTALL_PREFIX}${RESINSIGHT_FINAL_NAME}/ResInsight${CMAKE_EXECUTABLE_SUFFIX}.local)")
if (${CMAKE_SYSTEM_NAME} MATCHES "Windows")
# put a .exe.local file in the target directory to pick up DLLs from there
install (CODE "exec_program (${CMAKE_COMMAND} ARGS -E touch \$ENV{DESTDIR}${CMAKE_INSTALL_PREFIX}${RESINSIGHT_FINAL_NAME}/ResInsight${CMAKE_EXECUTABLE_SUFFIX}.local)")
set (RESINSIGHT_FILES
${QT_BINARY_DIR}/QtCore4.dll
${QT_BINARY_DIR}/QtGui4.dll
${QT_BINARY_DIR}/QtOpenGL4.dll
${QT_BINARY_DIR}/QtNetwork4.dll
${QT_BINARY_DIR}/QtScript4.dll
${QT_BINARY_DIR}/QtScriptTools4.dll
)
endif()
set (RESINSIGHT_FILES
${QT_BINARY_DIR}/QtCore4.dll
${QT_BINARY_DIR}/QtGui4.dll
${QT_BINARY_DIR}/QtOpenGL4.dll
${QT_BINARY_DIR}/QtNetwork4.dll
${QT_BINARY_DIR}/QtScript4.dll
${QT_BINARY_DIR}/QtScriptTools4.dll
)
endif()
set (RESINSIGHT_FILES ${RESINSIGHT_FILES} ${RESINSIGHT_LICENSE_FILES})
set (RESINSIGHT_FILES ${RESINSIGHT_FILES} ${RESINSIGHT_LICENSE_FILES})
install(TARGETS ResInsight DESTINATION ${RESINSIGHT_FINAL_NAME})
install(TARGETS ResInsight DESTINATION ${RESINSIGHT_FINAL_NAME})
install(FILES ${RESINSIGHT_FILES} DESTINATION ${RESINSIGHT_FINAL_NAME} )
install(FILES ${RESINSIGHT_FILES} DESTINATION ${RESINSIGHT_FINAL_NAME} )
if (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/resinsight DESTINATION ${RESINSIGHT_FINAL_NAME} PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE )
endif()
if (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/resinsight DESTINATION ${RESINSIGHT_FINAL_NAME} PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE )
endif()
else (RESINSIGHT_PRIVATE_INSTALL)
# binaries go in /usr/bin
install (TARGETS ResInsight
DESTINATION bin
)
DESTINATION bin
)
# license go in /usr/share/doc
install (FILES ${RESINSIGHT_LICENSE_FILES}
DESTINATION share/doc/ResInsight
)
DESTINATION share/doc/ResInsight
)
# no bundled libraries for system install
# application icon
install (FILES ${CMAKE_CURRENT_SOURCE_DIR}/Resources/AppLogo48x48.png
DESTINATION share/icons/hicolor/48x48/apps
RENAME ResInsight.png
)
DESTINATION share/icons/hicolor/48x48/apps
RENAME ResInsight.png
)
# desktop environment icon; remember to call `update-desktop-database`
# in package post-install scripts
configure_file (
${CMAKE_CURRENT_SOURCE_DIR}/resinsight.desktop.in
${CMAKE_CURRENT_BINARY_DIR}/resinsight.desktop
@ONLY
)
${CMAKE_CURRENT_SOURCE_DIR}/resinsight.desktop.in
${CMAKE_CURRENT_BINARY_DIR}/resinsight.desktop
@ONLY
)
install (FILES ${CMAKE_CURRENT_BINARY_DIR}/resinsight.desktop
DESTINATION share/applications
)
DESTINATION share/applications
)
endif (RESINSIGHT_PRIVATE_INSTALL)

View File

@@ -805,7 +805,8 @@ void RiuMainWindow::slotOpenProject()
void RiuMainWindow::slotOpenLastUsedProject()
{
RiaApplication* app = RiaApplication::instance();
app->loadLastUsedProject();
QString fileName = app->preferences()->lastUsedProjectFileName;
app->loadProject(fileName);
}
@@ -1395,7 +1396,9 @@ void RiuMainWindow::slotSnapshotAllViewsToFile()
{
RiaApplication* app = RiaApplication::instance();
app->saveSnapshotForAllViews("snapshots");
// Save images in snapshot catalog relative to project directory
QString absolutePathToSnapshotDir = app->createAbsolutePathFromProjectRelativePath("snapshots");
app->saveSnapshotForAllViews(absolutePathToSnapshotDir);
}
//--------------------------------------------------------------------------------------------------