mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-10 23:46:00 -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 the project filename has changed, call initAfterRead once more to propagate new location of project
|
||||||
if (m_project->fileName() != projectFileName)
|
if (m_project->fileName() != projectFileName)
|
||||||
{
|
{
|
||||||
m_project->fileName = projectFileName;
|
m_project->setProjectFileNameAndUpdateDependencies(projectFileName);
|
||||||
caf::PdmDocument::initAfterReadTraversal(m_project);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// On error, delete everything, and bail out.
|
// On error, delete everything, and bail out.
|
||||||
|
@ -63,9 +63,11 @@ public:
|
|||||||
void removeResult(const QString& resultName);
|
void removeResult(const QString& resultName);
|
||||||
|
|
||||||
virtual QString locationOnDisc() const { return QString(); }
|
virtual QString locationOnDisc() const { return QString(); }
|
||||||
|
virtual void updateFilePathsFromProjectPath(const QString& projectPath) { };
|
||||||
|
|
||||||
RimCaseCollection* parentCaseCollection();
|
RimCaseCollection* parentCaseCollection();
|
||||||
|
|
||||||
|
|
||||||
// Overridden methods from PdmObject
|
// Overridden methods from PdmObject
|
||||||
public:
|
public:
|
||||||
virtual caf::PdmFieldHandle* userDescriptionField() { return &caseName; }
|
virtual caf::PdmFieldHandle* userDescriptionField() { return &caseName; }
|
||||||
|
@ -420,21 +420,18 @@ QString RimInputCase::locationOnDisc() const
|
|||||||
return fi.absolutePath();
|
return fi.absolutePath();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
///
|
///
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
void RimInputCase::initAfterRead()
|
void RimInputCase::updateFilePathsFromProjectPath(const QString& projectPath)
|
||||||
{
|
{
|
||||||
RimCase::initAfterRead();
|
|
||||||
|
|
||||||
QString projPath = RiaApplication::instance()->project()->projectPath();
|
|
||||||
|
|
||||||
QString candidate;
|
QString candidate;
|
||||||
|
|
||||||
if (!QFile::exists(m_gridFileName))
|
if (!QFile::exists(m_gridFileName))
|
||||||
{
|
{
|
||||||
QString fileNameWithoutPath = QFileInfo(m_gridFileName).fileName();
|
QString fileNameWithoutPath = QFileInfo(m_gridFileName).fileName();
|
||||||
candidate = QDir::fromNativeSeparators(projPath + QDir::separator() + fileNameWithoutPath);
|
candidate = QDir::fromNativeSeparators(projectPath + QDir::separator() + fileNameWithoutPath);
|
||||||
if (QFile::exists(candidate))
|
if (QFile::exists(candidate))
|
||||||
{
|
{
|
||||||
m_gridFileName = candidate;
|
m_gridFileName = candidate;
|
||||||
@ -448,11 +445,12 @@ void RimInputCase::initAfterRead()
|
|||||||
if (!QFile::exists(additionalFileName))
|
if (!QFile::exists(additionalFileName))
|
||||||
{
|
{
|
||||||
QString fileNameWithoutPath = QFileInfo(additionalFileName).fileName();
|
QString fileNameWithoutPath = QFileInfo(additionalFileName).fileName();
|
||||||
candidate = QDir::fromNativeSeparators(projPath + QDir::separator() + fileNameWithoutPath);
|
candidate = QDir::fromNativeSeparators(projectPath + QDir::separator() + fileNameWithoutPath);
|
||||||
if (QFile::exists(candidate))
|
if (QFile::exists(candidate))
|
||||||
{
|
{
|
||||||
m_additionalFileNames.v()[i] = candidate;
|
m_additionalFileNames.v()[i] = candidate;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -62,15 +62,13 @@ public:
|
|||||||
// PdmObject overrides
|
// PdmObject overrides
|
||||||
virtual void fieldChangedByUi(const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue);
|
virtual void fieldChangedByUi(const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue);
|
||||||
|
|
||||||
|
// Overrides from RimCase
|
||||||
virtual QString locationOnDisc() const;
|
virtual QString locationOnDisc() const;
|
||||||
|
virtual void updateFilePathsFromProjectPath(const QString& projectPath);
|
||||||
protected:
|
|
||||||
virtual void initAfterRead();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void addFiles(const QStringList& newFileNames);
|
void addFiles(const QStringList& newFileNames);
|
||||||
void removeFiles(const QStringList& obsoleteFileNames);
|
void removeFiles(const QStringList& obsoleteFileNames);
|
||||||
|
|
||||||
|
|
||||||
cvf::ref<RifReaderInterface> createMockModel(QString modelName);
|
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());
|
this->fileName = fileName;
|
||||||
return fileInfo.path();
|
|
||||||
|
// 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 moveEclipseCaseIntoCaseGroup(RimCase* rimReservoir);
|
||||||
void removeCaseFromAllGroups(RimCase* rimReservoir);
|
void removeCaseFromAllGroups(RimCase* rimReservoir);
|
||||||
|
|
||||||
QString projectPath() const;
|
void setProjectFileNameAndUpdateDependencies(const QString& fileName);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
RigMainGrid* registerCaseInGridCollection(RigCaseData* rigEclipseCase);
|
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
|
// Update filename and folder paths when opening project from a different file location
|
||||||
if (!QFile::exists(caseFileName))
|
if (!QFile::exists(caseFileName))
|
||||||
{
|
{
|
||||||
@ -292,21 +290,19 @@ void RimResultCase::initAfterRead()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString projPath = RiaApplication::instance()->project()->projectPath();
|
candidate = QDir::fromNativeSeparators(projectPath + QDir::separator() + caseName + ".EGRID");
|
||||||
|
|
||||||
candidate = QDir::fromNativeSeparators(projPath + QDir::separator() + caseName + ".EGRID");
|
|
||||||
if (QFile::exists(candidate))
|
if (QFile::exists(candidate))
|
||||||
{
|
{
|
||||||
caseFileName = candidate;
|
caseFileName = candidate;
|
||||||
caseDirectory = projPath;
|
caseDirectory = projectPath;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
candidate = QDir::fromNativeSeparators(projPath + QDir::separator() + caseName + ".GRID");
|
candidate = QDir::fromNativeSeparators(projectPath + QDir::separator() + caseName + ".GRID");
|
||||||
if (QFile::exists(candidate))
|
if (QFile::exists(candidate))
|
||||||
{
|
{
|
||||||
caseFileName = candidate;
|
caseFileName = candidate;
|
||||||
caseDirectory = projPath;
|
caseDirectory = projectPath;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -49,10 +49,9 @@ public:
|
|||||||
bool openAndReadActiveCellData(RigCaseData* mainEclipseCase);
|
bool openAndReadActiveCellData(RigCaseData* mainEclipseCase);
|
||||||
void readGridDimensions(std::vector< std::vector<int> >& gridDimensions);
|
void readGridDimensions(std::vector< std::vector<int> >& gridDimensions);
|
||||||
|
|
||||||
|
// Overrides from RimCase
|
||||||
virtual QString locationOnDisc() const;
|
virtual QString locationOnDisc() const;
|
||||||
|
virtual void updateFilePathsFromProjectPath(const QString& projectPath);
|
||||||
protected:
|
|
||||||
virtual void initAfterRead();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
cvf::ref<RifReaderInterface> createMockModel(QString modelName);
|
cvf::ref<RifReaderInterface> createMockModel(QString modelName);
|
||||||
|
Loading…
Reference in New Issue
Block a user