mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-10 15:36:09 -06:00
Detect when project path has changed, and do a explicit update of file path for RimCases.
Do not use initAfterRead p4#: 21165
This commit is contained in:
parent
775b9e5bee
commit
64899f62c2
@ -239,8 +239,7 @@ bool RiaApplication::loadProject(const QString& projectFileName)
|
||||
// If the project filename has changed, call initAfterRead once more to propagate new location of project
|
||||
if (m_project->fileName() != projectFileName)
|
||||
{
|
||||
m_project->fileName = projectFileName;
|
||||
caf::PdmDocument::initAfterReadTraversal(m_project);
|
||||
m_project->setProjectFileNameAndUpdateDependencies(projectFileName);
|
||||
}
|
||||
|
||||
// On error, delete everything, and bail out.
|
||||
|
@ -63,9 +63,11 @@ public:
|
||||
void removeResult(const QString& resultName);
|
||||
|
||||
virtual QString locationOnDisc() const { return QString(); }
|
||||
virtual void updateFilePathsFromProjectPath(const QString& projectPath) { };
|
||||
|
||||
RimCaseCollection* parentCaseCollection();
|
||||
|
||||
|
||||
// Overridden methods from PdmObject
|
||||
public:
|
||||
virtual caf::PdmFieldHandle* userDescriptionField() { return &caseName; }
|
||||
|
@ -420,21 +420,18 @@ QString RimInputCase::locationOnDisc() const
|
||||
return fi.absolutePath();
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimInputCase::initAfterRead()
|
||||
void RimInputCase::updateFilePathsFromProjectPath(const QString& projectPath)
|
||||
{
|
||||
RimCase::initAfterRead();
|
||||
|
||||
QString projPath = RiaApplication::instance()->project()->projectPath();
|
||||
|
||||
QString candidate;
|
||||
|
||||
if (!QFile::exists(m_gridFileName))
|
||||
{
|
||||
QString fileNameWithoutPath = QFileInfo(m_gridFileName).fileName();
|
||||
candidate = QDir::fromNativeSeparators(projPath + QDir::separator() + fileNameWithoutPath);
|
||||
candidate = QDir::fromNativeSeparators(projectPath + QDir::separator() + fileNameWithoutPath);
|
||||
if (QFile::exists(candidate))
|
||||
{
|
||||
m_gridFileName = candidate;
|
||||
@ -448,11 +445,12 @@ void RimInputCase::initAfterRead()
|
||||
if (!QFile::exists(additionalFileName))
|
||||
{
|
||||
QString fileNameWithoutPath = QFileInfo(additionalFileName).fileName();
|
||||
candidate = QDir::fromNativeSeparators(projPath + QDir::separator() + fileNameWithoutPath);
|
||||
candidate = QDir::fromNativeSeparators(projectPath + QDir::separator() + fileNameWithoutPath);
|
||||
if (QFile::exists(candidate))
|
||||
{
|
||||
m_additionalFileNames.v()[i] = candidate;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -62,15 +62,13 @@ public:
|
||||
// PdmObject overrides
|
||||
virtual void fieldChangedByUi(const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue);
|
||||
|
||||
// Overrides from RimCase
|
||||
virtual QString locationOnDisc() const;
|
||||
|
||||
protected:
|
||||
virtual void initAfterRead();
|
||||
virtual void updateFilePathsFromProjectPath(const QString& projectPath);
|
||||
|
||||
private:
|
||||
void addFiles(const QStringList& newFileNames);
|
||||
void removeFiles(const QStringList& obsoleteFileNames);
|
||||
|
||||
|
||||
cvf::ref<RifReaderInterface> createMockModel(QString modelName);
|
||||
};
|
||||
|
@ -234,9 +234,30 @@ void RimProject::insertCaseInCaseGroup(RimIdenticalGridCaseGroup* caseGroup, Rim
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RimProject::projectPath() const
|
||||
void RimProject::setProjectFileNameAndUpdateDependencies(const QString& fileName)
|
||||
{
|
||||
QFileInfo fileInfo(fileName());
|
||||
return fileInfo.path();
|
||||
this->fileName = fileName;
|
||||
|
||||
// Loop over all reservoirs and update file path
|
||||
|
||||
QFileInfo fileInfo(fileName);
|
||||
QString projectPath = fileInfo.path();
|
||||
|
||||
for (size_t i = 0; i < reservoirs.size(); i++)
|
||||
{
|
||||
reservoirs[i]->updateFilePathsFromProjectPath(projectPath);
|
||||
}
|
||||
|
||||
// Case groups : Loop over all reservoirs in and update file path
|
||||
|
||||
for (size_t i = 0; i < caseGroups.size(); i++)
|
||||
{
|
||||
RimIdenticalGridCaseGroup* cg = caseGroups()[i];
|
||||
|
||||
for (size_t j = 0; j < cg->caseCollection()->reservoirs().size(); j++)
|
||||
{
|
||||
cg->caseCollection()->reservoirs()[j]->updateFilePathsFromProjectPath(projectPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -52,7 +52,7 @@ public:
|
||||
void moveEclipseCaseIntoCaseGroup(RimCase* rimReservoir);
|
||||
void removeCaseFromAllGroups(RimCase* rimReservoir);
|
||||
|
||||
QString projectPath() const;
|
||||
void setProjectFileNameAndUpdateDependencies(const QString& fileName);
|
||||
|
||||
private:
|
||||
RigMainGrid* registerCaseInGridCollection(RigCaseData* rigEclipseCase);
|
||||
|
@ -269,10 +269,8 @@ void RimResultCase::readGridDimensions(std::vector< std::vector<int> >& gridDime
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimResultCase::initAfterRead()
|
||||
void RimResultCase::updateFilePathsFromProjectPath(const QString& projectPath)
|
||||
{
|
||||
RimCase::initAfterRead();
|
||||
|
||||
// Update filename and folder paths when opening project from a different file location
|
||||
if (!QFile::exists(caseFileName))
|
||||
{
|
||||
@ -292,21 +290,19 @@ void RimResultCase::initAfterRead()
|
||||
return;
|
||||
}
|
||||
|
||||
QString projPath = RiaApplication::instance()->project()->projectPath();
|
||||
|
||||
candidate = QDir::fromNativeSeparators(projPath + QDir::separator() + caseName + ".EGRID");
|
||||
candidate = QDir::fromNativeSeparators(projectPath + QDir::separator() + caseName + ".EGRID");
|
||||
if (QFile::exists(candidate))
|
||||
{
|
||||
caseFileName = candidate;
|
||||
caseDirectory = projPath;
|
||||
caseDirectory = projectPath;
|
||||
return;
|
||||
}
|
||||
|
||||
candidate = QDir::fromNativeSeparators(projPath + QDir::separator() + caseName + ".GRID");
|
||||
candidate = QDir::fromNativeSeparators(projectPath + QDir::separator() + caseName + ".GRID");
|
||||
if (QFile::exists(candidate))
|
||||
{
|
||||
caseFileName = candidate;
|
||||
caseDirectory = projPath;
|
||||
caseDirectory = projectPath;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -49,10 +49,9 @@ public:
|
||||
bool openAndReadActiveCellData(RigCaseData* mainEclipseCase);
|
||||
void readGridDimensions(std::vector< std::vector<int> >& gridDimensions);
|
||||
|
||||
// Overrides from RimCase
|
||||
virtual QString locationOnDisc() const;
|
||||
|
||||
protected:
|
||||
virtual void initAfterRead();
|
||||
virtual void updateFilePathsFromProjectPath(const QString& projectPath);
|
||||
|
||||
private:
|
||||
cvf::ref<RifReaderInterface> createMockModel(QString modelName);
|
||||
|
Loading…
Reference in New Issue
Block a user