mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
#963 Batch : Parse multiple entries of replaceCase and replaceSourceCases
This commit is contained in:
parent
cf223f8043
commit
29f766edc7
@ -1182,8 +1182,8 @@ bool RiaApplication::parseArguments()
|
||||
progOpt.registerOption("startdir", "<folder>", "Set startup directory.", cvf::ProgramOptions::SINGLE_VALUE);
|
||||
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);
|
||||
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 the grid files listed in the <gridListFile> file.", cvf::ProgramOptions::MULTI_VALUE);
|
||||
progOpt.registerOption("replaceCase", "[<caseId>] <newGridFile>", "Replace grid in <caseId> or first case with <newgridFile>. Repeat option for multiple replace operations.", 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 option for multiple replace operations.", cvf::ProgramOptions::MULTI_VALUE, cvf::ProgramOptions::COMBINE_REPEATED);
|
||||
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("help", "", "Displays help text.");
|
||||
progOpt.registerOption("?", "", "Displays help text.");
|
||||
@ -1294,16 +1294,26 @@ bool RiaApplication::parseArguments()
|
||||
{
|
||||
if (projectModifier.isNull()) projectModifier = new RiaProjectModifier;
|
||||
|
||||
const int caseId = o.safeValue(0).toInt(-1);
|
||||
if (caseId != -1 && o.valueCount() > 1)
|
||||
if (o.valueCount() == 1)
|
||||
{
|
||||
QString gridFileName = cvfqt::Utils::toQString(o.value(1));
|
||||
projectModifier->setReplaceCase(caseId, gridFileName);
|
||||
// One argument is available, use replace case for first occurrence in the project
|
||||
|
||||
QString gridFileName = cvfqt::Utils::toQString(o.safeValue(0));
|
||||
projectModifier->setReplaceCaseFirstOccurrence(gridFileName);
|
||||
}
|
||||
else
|
||||
{
|
||||
QString gridFileName = cvfqt::Utils::toQString(o.safeValue(0));
|
||||
projectModifier->setReplaceCaseFirstOccurence(gridFileName);
|
||||
size_t optionIdx = 0;
|
||||
while (optionIdx < o.valueCount())
|
||||
{
|
||||
const int caseId = o.safeValue(optionIdx++).toInt(-1);
|
||||
QString gridFileName = cvfqt::Utils::toQString(o.safeValue(optionIdx++));
|
||||
|
||||
if (caseId != -1 && !gridFileName.isEmpty())
|
||||
{
|
||||
projectModifier->setReplaceCase(caseId, gridFileName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1311,16 +1321,26 @@ bool RiaApplication::parseArguments()
|
||||
{
|
||||
if (projectModifier.isNull()) projectModifier = new RiaProjectModifier;
|
||||
|
||||
const int caseGroupId = o.safeValue(0).toInt(-1);
|
||||
if (caseGroupId != -1 && o.valueCount() > 1)
|
||||
if (o.valueCount() == 1)
|
||||
{
|
||||
std::vector<QString> gridFileNames = readFileListFromTextFile(cvfqt::Utils::toQString(o.value(1)));
|
||||
projectModifier->setReplaceSourceCasesById(caseGroupId, gridFileNames);
|
||||
// One argument is available, use replace case for first occurrence in the project
|
||||
|
||||
std::vector<QString> gridFileNames = readFileListFromTextFile(cvfqt::Utils::toQString(o.safeValue(0)));
|
||||
projectModifier->setReplaceSourceCasesFirstOccurrence(gridFileNames);
|
||||
}
|
||||
else
|
||||
{
|
||||
std::vector<QString> gridFileNames = readFileListFromTextFile(cvfqt::Utils::toQString(o.safeValue(0)));
|
||||
projectModifier->setReplaceSourceCasesFirstOccurence(gridFileNames);
|
||||
size_t optionIdx = 0;
|
||||
while (optionIdx < o.valueCount())
|
||||
{
|
||||
const int groupId = o.safeValue(optionIdx++).toInt(-1);
|
||||
std::vector<QString> gridFileNames = readFileListFromTextFile(cvfqt::Utils::toQString(o.safeValue(optionIdx++)));
|
||||
|
||||
if (groupId != -1 && gridFileNames.size() > 0)
|
||||
{
|
||||
projectModifier->setReplaceSourceCasesById(groupId, gridFileNames);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
projectLoadAction = PLA_CALCULATE_STATISTICS;
|
||||
@ -2083,7 +2103,7 @@ void RiaApplication::runMultiCaseSnapshots(const QString& templateProjectFileNam
|
||||
QString gridFn = gridFileNames[i];
|
||||
|
||||
RiaProjectModifier modifier;
|
||||
modifier.setReplaceCaseFirstOccurence(gridFn);
|
||||
modifier.setReplaceCaseFirstOccurrence(gridFn);
|
||||
|
||||
bool loadOk = loadProject(templateProjectFileName, PLA_NONE, &modifier);
|
||||
if (loadOk)
|
||||
|
@ -19,58 +19,32 @@
|
||||
|
||||
#include "RiaProjectModifier.h"
|
||||
|
||||
#include "RimProject.h"
|
||||
#include "RimEclipseCaseCollection.h"
|
||||
#include "RimOilField.h"
|
||||
#include "RimIdenticalGridCaseGroup.h"
|
||||
#include "RimCaseCollection.h"
|
||||
#include "RimEclipseCaseCollection.h"
|
||||
#include "RimEclipseResultCase.h"
|
||||
|
||||
#include "RimEclipseView.h"
|
||||
#include "RimWellPathCollection.h"
|
||||
#include "RimScriptCollection.h"
|
||||
#include "RimEclipsePropertyFilterCollection.h"
|
||||
#include "RimEclipsePropertyFilter.h"
|
||||
#include "RimReservoirCellResultsStorage.h"
|
||||
#include "RimEclipseCellColors.h"
|
||||
#include "RimCellEdgeColors.h"
|
||||
#include "RimCellRangeFilterCollection.h"
|
||||
#include "RimEclipseWellCollection.h"
|
||||
#include "Rim3dOverlayInfoConfig.h"
|
||||
#include "RimIdenticalGridCaseGroup.h"
|
||||
#include "RimOilField.h"
|
||||
#include "RimProject.h"
|
||||
|
||||
#include <QFileInfo>
|
||||
#include <QDir>
|
||||
|
||||
|
||||
|
||||
|
||||
//==================================================================================================
|
||||
//
|
||||
//
|
||||
//
|
||||
//==================================================================================================
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RiaProjectModifier::RiaProjectModifier()
|
||||
: m_replaceCase_caseId(UNDEFINED),
|
||||
m_replaceSourceCases_caseGroupId(UNDEFINED)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaProjectModifier::setReplaceCaseFirstOccurence(QString newGridFileName)
|
||||
void RiaProjectModifier::setReplaceCaseFirstOccurrence(QString newGridFileName)
|
||||
{
|
||||
m_replaceCase_caseId = FIRST_OCCURENCE;
|
||||
m_replaceCase_gridFileName = makeFilePathAbsolute(newGridFileName);
|
||||
m_caseIdToGridFileNameMap[FIRST_OCCURENCE] = makeFilePathAbsolute(newGridFileName);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@ -78,27 +52,18 @@ void RiaProjectModifier::setReplaceCase(int caseIdToReplace, QString newGridFile
|
||||
{
|
||||
if (caseIdToReplace >= 0)
|
||||
{
|
||||
m_replaceCase_caseId = caseIdToReplace;
|
||||
m_replaceCase_gridFileName = makeFilePathAbsolute(newGridFileName);
|
||||
m_caseIdToGridFileNameMap[caseIdToReplace] = makeFilePathAbsolute(newGridFileName);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaProjectModifier::setReplaceSourceCasesFirstOccurence(std::vector<QString> newGridFileNames)
|
||||
void RiaProjectModifier::setReplaceSourceCasesFirstOccurrence(std::vector<QString> newGridFileNames)
|
||||
{
|
||||
m_replaceSourceCases_caseGroupId = FIRST_OCCURENCE;
|
||||
|
||||
m_replaceSourceCases_gridFileNames.clear();
|
||||
foreach (QString fn, newGridFileNames)
|
||||
{
|
||||
m_replaceSourceCases_gridFileNames.push_back(makeFilePathAbsolute(fn));
|
||||
}
|
||||
m_groupIdToGridFileNamesMap[FIRST_OCCURENCE] = newGridFileNames;
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@ -106,28 +71,21 @@ void RiaProjectModifier::setReplaceSourceCasesById(int caseGroupIdToReplace, std
|
||||
{
|
||||
if (caseGroupIdToReplace >= 0)
|
||||
{
|
||||
m_replaceSourceCases_caseGroupId = caseGroupIdToReplace;
|
||||
|
||||
m_replaceSourceCases_gridFileNames.clear();
|
||||
foreach (QString fn, newGridFileNames)
|
||||
{
|
||||
m_replaceSourceCases_gridFileNames.push_back(makeFilePathAbsolute(fn));
|
||||
}
|
||||
m_groupIdToGridFileNamesMap[caseGroupIdToReplace] = newGridFileNames;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RiaProjectModifier::applyModificationsToProject(RimProject* project)
|
||||
{
|
||||
if (m_replaceCase_caseId != UNDEFINED && !m_replaceCase_gridFileName.isEmpty())
|
||||
if (m_caseIdToGridFileNameMap.size() > 0)
|
||||
{
|
||||
replaceCase(project);
|
||||
}
|
||||
|
||||
if (m_replaceSourceCases_caseGroupId != UNDEFINED && m_replaceSourceCases_gridFileNames.size() > 0)
|
||||
if (m_groupIdToGridFileNamesMap.size() > 0)
|
||||
{
|
||||
replaceSourceCases(project);
|
||||
}
|
||||
@ -135,90 +93,80 @@ bool RiaProjectModifier::applyModificationsToProject(RimProject* project)
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RiaProjectModifier::replaceSourceCases(RimProject* project)
|
||||
void RiaProjectModifier::replaceSourceCases(RimProject* project)
|
||||
{
|
||||
bool didReplacement = false;
|
||||
|
||||
for (size_t oilFieldIdx = 0; oilFieldIdx < project->oilFields().size(); oilFieldIdx++)
|
||||
for (RimOilField* oilField : project->oilFields())
|
||||
{
|
||||
RimOilField* oilField = project->oilFields[oilFieldIdx];
|
||||
RimEclipseCaseCollection* analysisModels = oilField ? oilField->analysisModels() : NULL;
|
||||
if (analysisModels)
|
||||
{
|
||||
const size_t numCaseGroups = analysisModels->caseGroups.size();
|
||||
for (size_t caseGrpIdx = 0; caseGrpIdx < numCaseGroups; ++caseGrpIdx)
|
||||
for (RimIdenticalGridCaseGroup* caseGroup : analysisModels->caseGroups)
|
||||
{
|
||||
RimIdenticalGridCaseGroup* caseGroup = analysisModels->caseGroups[caseGrpIdx];
|
||||
if (m_replaceSourceCases_caseGroupId == FIRST_OCCURENCE ||
|
||||
m_replaceSourceCases_caseGroupId == caseGroup->groupId)
|
||||
for (auto item : m_groupIdToGridFileNamesMap)
|
||||
{
|
||||
RimCaseCollection* caseCollection = caseGroup->caseCollection;
|
||||
caseCollection->reservoirs.deleteAllChildObjects();
|
||||
|
||||
for (size_t i = 0; i < m_replaceSourceCases_gridFileNames.size(); i++)
|
||||
int groupIdToReplace = item.first;
|
||||
if (groupIdToReplace == FIRST_OCCURENCE)
|
||||
{
|
||||
QString fileName = m_replaceSourceCases_gridFileNames[i];
|
||||
QString caseName = caseNameFromGridFileName(fileName);
|
||||
|
||||
// Use this slightly hackish method in order to get a new unique ID
|
||||
RimEclipseResultCase* resCase = new RimEclipseResultCase;
|
||||
resCase->setCaseInfo(caseName, fileName);
|
||||
|
||||
caseCollection->reservoirs.push_back(resCase);
|
||||
groupIdToReplace = firstGroupId(project);
|
||||
}
|
||||
|
||||
didReplacement = true;
|
||||
|
||||
if (m_replaceSourceCases_caseGroupId == FIRST_OCCURENCE)
|
||||
if (groupIdToReplace == caseGroup->groupId())
|
||||
{
|
||||
return true;
|
||||
RimCaseCollection* caseCollection = caseGroup->caseCollection;
|
||||
caseCollection->reservoirs.deleteAllChildObjects();
|
||||
|
||||
for (QString fileName : item.second)
|
||||
{
|
||||
QString caseName = caseNameFromGridFileName(fileName);
|
||||
|
||||
// Use this slightly hackish method in order to get a new unique ID
|
||||
RimEclipseResultCase* resCase = new RimEclipseResultCase;
|
||||
resCase->setCaseInfo(caseName, fileName);
|
||||
|
||||
caseCollection->reservoirs.push_back(resCase);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return didReplacement;
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RiaProjectModifier::replaceCase(RimProject* project)
|
||||
void RiaProjectModifier::replaceCase(RimProject* project)
|
||||
{
|
||||
bool didReplacement = false;
|
||||
std::vector<RimCase*> allCases;
|
||||
project->allCases(allCases);
|
||||
|
||||
for (size_t caseIdx = 0; caseIdx < allCases.size(); ++caseIdx)
|
||||
|
||||
for (RimCase* rimCase : allCases)
|
||||
{
|
||||
RimEclipseResultCase* resultCase = dynamic_cast<RimEclipseResultCase*>(allCases[caseIdx]);
|
||||
RimEclipseResultCase* resultCase = dynamic_cast<RimEclipseResultCase*>(rimCase);
|
||||
if (resultCase)
|
||||
{
|
||||
if (m_replaceCase_caseId == FIRST_OCCURENCE ||
|
||||
m_replaceCase_caseId == resultCase->caseId())
|
||||
for (auto item : m_caseIdToGridFileNameMap)
|
||||
{
|
||||
resultCase->setGridFileName(m_replaceCase_gridFileName);
|
||||
resultCase->caseUserDescription = caseNameFromGridFileName(m_replaceCase_gridFileName);
|
||||
didReplacement = true;
|
||||
|
||||
if (m_replaceCase_caseId == FIRST_OCCURENCE)
|
||||
int caseIdToReplace = item.first;
|
||||
if (caseIdToReplace == FIRST_OCCURENCE)
|
||||
{
|
||||
return true;
|
||||
caseIdToReplace = firstCaseId(project);
|
||||
}
|
||||
|
||||
if (caseIdToReplace == resultCase->caseId())
|
||||
{
|
||||
QString replaceFileName = item.second;
|
||||
resultCase->setGridFileName(replaceFileName);
|
||||
resultCase->caseUserDescription = caseNameFromGridFileName(replaceFileName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return didReplacement;
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Returns absolute path name to the specified file.
|
||||
///
|
||||
@ -232,7 +180,6 @@ QString RiaProjectModifier::makeFilePathAbsolute(QString relOrAbsolutePath)
|
||||
return theFile.filePath();
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@ -248,4 +195,44 @@ QString RiaProjectModifier::caseNameFromGridFileName(QString fullGridFilePathNam
|
||||
return deepestDirPlusFileName;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
int RiaProjectModifier::firstCaseId(RimProject* project)
|
||||
{
|
||||
std::vector<RimCase*> allCases;
|
||||
project->allCases(allCases);
|
||||
|
||||
for (RimCase* rimCase : allCases)
|
||||
{
|
||||
RimEclipseResultCase* resultCase = dynamic_cast<RimEclipseResultCase*>(rimCase);
|
||||
if (resultCase)
|
||||
{
|
||||
return resultCase->caseId();
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
int RiaProjectModifier::firstGroupId(RimProject* project)
|
||||
{
|
||||
for (size_t oilFieldIdx = 0; oilFieldIdx < project->oilFields().size(); oilFieldIdx++)
|
||||
{
|
||||
RimOilField* oilField = project->oilFields[oilFieldIdx];
|
||||
RimEclipseCaseCollection* analysisModels = oilField ? oilField->analysisModels() : NULL;
|
||||
if (analysisModels)
|
||||
{
|
||||
if (analysisModels->caseGroups.size() > 0)
|
||||
{
|
||||
return analysisModels->caseGroups[0]->groupId();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -25,6 +25,7 @@
|
||||
#include <QString>
|
||||
|
||||
#include <vector>
|
||||
#include <map>
|
||||
|
||||
class RimProject;
|
||||
|
||||
@ -40,32 +41,27 @@ class RiaProjectModifier : public cvf::Object
|
||||
public:
|
||||
RiaProjectModifier();
|
||||
|
||||
void setReplaceCaseFirstOccurence(QString newGridFileName);
|
||||
void setReplaceCaseFirstOccurrence(QString newGridFileName);
|
||||
void setReplaceCase(int caseIdToReplace, QString newGridFileName);
|
||||
|
||||
void setReplaceSourceCasesFirstOccurence(std::vector<QString> newGridFileNames);
|
||||
void setReplaceSourceCasesFirstOccurrence(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);
|
||||
void replaceSourceCases(RimProject* project);
|
||||
void replaceCase(RimProject* project);
|
||||
static QString makeFilePathAbsolute(QString relOrAbsolutePath);
|
||||
static QString caseNameFromGridFileName(QString fullGridFilePathName);
|
||||
|
||||
static int firstCaseId(RimProject* project);
|
||||
static int firstGroupId(RimProject* project);
|
||||
|
||||
private:
|
||||
int m_replaceCase_caseId;
|
||||
QString m_replaceCase_gridFileName;
|
||||
std::map<int, QString> m_caseIdToGridFileNameMap;
|
||||
std::map<int, std::vector<QString> > m_groupIdToGridFileNamesMap;
|
||||
|
||||
int m_replaceSourceCases_caseGroupId;
|
||||
std::vector<QString> m_replaceSourceCases_gridFileNames;
|
||||
|
||||
static const int UNDEFINED = -1;
|
||||
static const int FIRST_OCCURENCE = -999;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user