mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
If project is moved on disk, execute initAfterRead() to propagate project file name changes to underlying objects
p4#: 21159
This commit is contained in:
parent
e89b88e47e
commit
b9ed45af2c
@ -235,7 +235,13 @@ bool RiaApplication::loadProject(const QString& projectFileName)
|
|||||||
|
|
||||||
m_project->fileName = projectFileName;
|
m_project->fileName = projectFileName;
|
||||||
m_project->readFile();
|
m_project->readFile();
|
||||||
m_project->fileName = projectFileName; // Make sure we overwrite the old filename read from the project file
|
|
||||||
|
// 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);
|
||||||
|
}
|
||||||
|
|
||||||
// On error, delete everything, and bail out.
|
// On error, delete everything, and bail out.
|
||||||
|
|
||||||
|
@ -27,6 +27,7 @@
|
|||||||
#include "cafProgressInfo.h"
|
#include "cafProgressInfo.h"
|
||||||
#include "RimProject.h"
|
#include "RimProject.h"
|
||||||
#include "RifEclipseOutputFileTools.h"
|
#include "RifEclipseOutputFileTools.h"
|
||||||
|
#include "RiaApplication.h"
|
||||||
|
|
||||||
|
|
||||||
CAF_PDM_SOURCE_INIT(RimResultCase, "EclipseCase");
|
CAF_PDM_SOURCE_INIT(RimResultCase, "EclipseCase");
|
||||||
@ -76,15 +77,14 @@ bool RimResultCase::openEclipseGridFile()
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
QString fname = createAbsoluteFilenameFromCase(caseName);
|
if (!QFile::exists(caseFileName()))
|
||||||
if (fname.isEmpty())
|
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
cvf::ref<RigCaseData> eclipseCase = new RigCaseData;
|
cvf::ref<RigCaseData> eclipseCase = new RigCaseData;
|
||||||
readerInterface = new RifReaderEclipseOutput;
|
readerInterface = new RifReaderEclipseOutput;
|
||||||
if (!readerInterface->open(fname, eclipseCase.p()))
|
if (!readerInterface->open(caseFileName(), eclipseCase.p()))
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -119,8 +119,7 @@ bool RimResultCase::openAndReadActiveCellData(RigCaseData* mainEclipseCase)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
QString fname = createAbsoluteFilenameFromCase(caseName);
|
if (!QFile::exists(caseFileName()))
|
||||||
if (fname.isEmpty())
|
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -140,7 +139,7 @@ bool RimResultCase::openAndReadActiveCellData(RigCaseData* mainEclipseCase)
|
|||||||
std::vector<QDateTime> timeStepDates = mainEclipseCase->results(RifReaderInterface::MATRIX_RESULTS)->timeStepDates(scalarIndexWithMaxTimeStepCount);
|
std::vector<QDateTime> timeStepDates = mainEclipseCase->results(RifReaderInterface::MATRIX_RESULTS)->timeStepDates(scalarIndexWithMaxTimeStepCount);
|
||||||
|
|
||||||
cvf::ref<RifReaderEclipseOutput> readerEclipseOutput = new RifReaderEclipseOutput;
|
cvf::ref<RifReaderEclipseOutput> readerEclipseOutput = new RifReaderEclipseOutput;
|
||||||
if (!readerEclipseOutput->openAndReadActiveCellData(fname, timeStepDates, eclipseCase.p()))
|
if (!readerEclipseOutput->openAndReadActiveCellData(caseFileName(), timeStepDates, eclipseCase.p()))
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -262,50 +261,64 @@ QString RimResultCase::locationOnDisc() const
|
|||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
///
|
///
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
QString RimResultCase::createAbsoluteFilenameFromCase(const QString& caseName)
|
void RimResultCase::readGridDimensions(std::vector< std::vector<int> >& gridDimensions)
|
||||||
{
|
{
|
||||||
QString candidate;
|
RifEclipseOutputFileTools::readGridDimensions(caseFileName, gridDimensions);
|
||||||
|
|
||||||
candidate = QDir::fromNativeSeparators(caseDirectory.v() + QDir::separator() + caseName + ".EGRID");
|
|
||||||
if (QFile::exists(candidate)) return candidate;
|
|
||||||
|
|
||||||
candidate = QDir::fromNativeSeparators(caseDirectory.v() + QDir::separator() + caseName + ".GRID");
|
|
||||||
if (QFile::exists(candidate)) return candidate;
|
|
||||||
|
|
||||||
std::vector<caf::PdmObject*> parentObjects;
|
|
||||||
this->parentObjects(parentObjects);
|
|
||||||
|
|
||||||
QString projectPath;
|
|
||||||
for (size_t i = 0; i < parentObjects.size(); i++)
|
|
||||||
{
|
|
||||||
caf::PdmObject* obj = parentObjects[i];
|
|
||||||
RimProject* proj = dynamic_cast<RimProject*>(obj);
|
|
||||||
if (proj)
|
|
||||||
{
|
|
||||||
QFileInfo fi(proj->fileName);
|
|
||||||
projectPath = fi.path();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!projectPath.isEmpty())
|
|
||||||
{
|
|
||||||
candidate = QDir::fromNativeSeparators(projectPath + QDir::separator() + caseName + ".EGRID");
|
|
||||||
if (QFile::exists(candidate)) return candidate;
|
|
||||||
|
|
||||||
candidate = QDir::fromNativeSeparators(projectPath + QDir::separator() + caseName + ".GRID");
|
|
||||||
if (QFile::exists(candidate)) return candidate;
|
|
||||||
}
|
|
||||||
|
|
||||||
return QString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
///
|
///
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
void RimResultCase::readGridDimensions(std::vector< std::vector<int> >& gridDimensions)
|
void RimResultCase::initAfterRead()
|
||||||
{
|
{
|
||||||
QString fname = createAbsoluteFilenameFromCase(caseName);
|
RimCase::initAfterRead();
|
||||||
|
|
||||||
RifEclipseOutputFileTools::readGridDimensions(fname, gridDimensions);
|
// Update filename and folder paths when opening project from a different file location
|
||||||
|
if (!QFile::exists(caseFileName))
|
||||||
|
{
|
||||||
|
QString candidate;
|
||||||
|
|
||||||
|
candidate = QDir::fromNativeSeparators(caseDirectory.v() + QDir::separator() + caseName + ".EGRID");
|
||||||
|
if (QFile::exists(candidate))
|
||||||
|
{
|
||||||
|
caseFileName = candidate;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
candidate = QDir::fromNativeSeparators(caseDirectory.v() + QDir::separator() + caseName + ".GRID");
|
||||||
|
if (QFile::exists(candidate))
|
||||||
|
{
|
||||||
|
caseFileName = candidate;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString projPath = projectPath();
|
||||||
|
|
||||||
|
candidate = QDir::fromNativeSeparators(projPath + QDir::separator() + caseName + ".EGRID");
|
||||||
|
if (QFile::exists(candidate))
|
||||||
|
{
|
||||||
|
caseFileName = candidate;
|
||||||
|
caseDirectory = projectPath;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
candidate = QDir::fromNativeSeparators(projPath + QDir::separator() + caseName + ".GRID");
|
||||||
|
if (QFile::exists(candidate))
|
||||||
|
{
|
||||||
|
caseFileName = candidate;
|
||||||
|
caseDirectory = projPath;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
QString RimResultCase::projectPath() const
|
||||||
|
{
|
||||||
|
QString projectFileName = RiaApplication::instance()->project()->fileName();
|
||||||
|
QFileInfo fileInfo(projectFileName);
|
||||||
|
return fileInfo.path();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,7 +41,6 @@ public:
|
|||||||
RimResultCase(const QString& caseName, const QString& caseFileName, const QString& caseDirectory);
|
RimResultCase(const QString& caseName, const QString& caseFileName, const QString& caseDirectory);
|
||||||
virtual ~RimResultCase();
|
virtual ~RimResultCase();
|
||||||
|
|
||||||
|
|
||||||
// Fields:
|
// Fields:
|
||||||
caf::PdmField<QString> caseFileName;
|
caf::PdmField<QString> caseFileName;
|
||||||
caf::PdmField<QString> caseDirectory;
|
caf::PdmField<QString> caseDirectory;
|
||||||
@ -50,13 +49,13 @@ 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);
|
||||||
|
|
||||||
//virtual caf::PdmFieldHandle* userDescriptionField() { return &caseName;}
|
virtual QString locationOnDisc() const;
|
||||||
|
|
||||||
virtual QString locationOnDisc() const;
|
protected:
|
||||||
|
virtual void initAfterRead();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
QString projectPath() const;
|
||||||
|
|
||||||
cvf::ref<RifReaderInterface> createMockModel(QString modelName);
|
cvf::ref<RifReaderInterface> createMockModel(QString modelName);
|
||||||
|
|
||||||
QString createAbsoluteFilenameFromCase(const QString& caseName);
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user