(#672) Refactoring and Fix of side effects introduced by 704f4fa

This commit is contained in:
Jacob Støren 2015-12-01 12:27:19 +01:00
parent 704f4fa42b
commit ee11d4fde7
6 changed files with 21 additions and 42 deletions

View File

@ -351,7 +351,6 @@ bool RiaApplication::loadProject(const QString& projectFileName, ProjectLoadActi
{ {
//printf("Create well path collection for oil field %i in loadProject.\n", oilFieldIdx); //printf("Create well path collection for oil field %i in loadProject.\n", oilFieldIdx);
oilField->wellPathCollection = new RimWellPathCollection(); oilField->wellPathCollection = new RimWellPathCollection();
oilField->wellPathCollection->setProject(m_project);
} }
if (oilField->wellPathCollection) oilField->wellPathCollection->readWellPathFiles(); if (oilField->wellPathCollection) oilField->wellPathCollection->readWellPathFiles();
@ -474,7 +473,6 @@ void RiaApplication::addWellPathsToModel(QList<QString> wellPathFilePaths)
{ {
//printf("Create well path collection.\n"); //printf("Create well path collection.\n");
oilField->wellPathCollection = new RimWellPathCollection(); oilField->wellPathCollection = new RimWellPathCollection();
oilField->wellPathCollection->setProject(m_project);
m_project->updateConnectedEditors(); m_project->updateConnectedEditors();
} }
@ -497,7 +495,6 @@ void RiaApplication::addWellLogsToModel(const QList<QString>& wellLogFilePaths)
if (oilField->wellPathCollection == NULL) if (oilField->wellPathCollection == NULL)
{ {
oilField->wellPathCollection = new RimWellPathCollection(); oilField->wellPathCollection = new RimWellPathCollection();
oilField->wellPathCollection->setProject(m_project);
m_project->updateConnectedEditors(); m_project->updateConnectedEditors();
} }

View File

@ -306,7 +306,6 @@ void RimProject::initAfterRead()
{ {
RimOilField* oilField = oilFields[oilFieldIdx]; RimOilField* oilField = oilFields[oilFieldIdx];
if (oilField == NULL || oilField->wellPathCollection == NULL) continue; if (oilField == NULL || oilField->wellPathCollection == NULL) continue;
oilField->wellPathCollection->setProject(this);
} }
} }

View File

@ -91,7 +91,6 @@ RimWellPath::RimWellPath()
m_wellLogFile.uiCapability()->setUiHidden(true); m_wellLogFile.uiCapability()->setUiHidden(true);
m_wellPath = NULL; m_wellPath = NULL;
m_project = NULL;
} }
@ -148,7 +147,9 @@ RivWellPathPartMgr* RimWellPath::partMgr()
{ {
if (m_wellPathPartMgr.isNull()) if (m_wellPathPartMgr.isNull())
{ {
m_wellPathPartMgr = new RivWellPathPartMgr(m_wellPathCollection, this); RimWellPathCollection* wpColl;
this->firstAnchestorOrThisOfType(wpColl);
if (wpColl) m_wellPathPartMgr = new RivWellPathPartMgr(wpColl, this);
} }
return m_wellPathPartMgr.p(); return m_wellPathPartMgr.p();
@ -161,7 +162,10 @@ RivWellPathPartMgr* RimWellPath::partMgr()
void RimWellPath::fieldChangedByUi(const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue) void RimWellPath::fieldChangedByUi(const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue)
{ {
partMgr()->scheduleGeometryRegen(); partMgr()->scheduleGeometryRegen();
if (m_project) m_project->createDisplayModelAndRedrawAllViews();
RimProject* proj;
this->firstAnchestorOrThisOfType(proj);
if (proj) proj->createDisplayModelAndRedrawAllViews();
} }
@ -177,7 +181,7 @@ caf::PdmFieldHandle* RimWellPath::objectToggleField()
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// Read JSON or ascii file containing well path data /// Read JSON or ascii file containing well path data
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
bool RimWellPath::readWellPathFile(QString* errorMessage) bool RimWellPath::readWellPathFile(QString* errorMessage, RifWellPathAsciiFileReader* asciiReader)
{ {
QFileInfo fileInf(filepath()); QFileInfo fileInf(filepath());
@ -189,7 +193,7 @@ bool RimWellPath::readWellPathFile(QString* errorMessage)
} }
else else
{ {
this->readAsciiWellPathFile(); this->readAsciiWellPathFile(asciiReader);
} }
return true; return true;
@ -254,9 +258,11 @@ void RimWellPath::readJsonWellPathFile()
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
void RimWellPath::readAsciiWellPathFile() void RimWellPath::readAsciiWellPathFile(RifWellPathAsciiFileReader* asciiReader)
{ {
RifWellPathAsciiFileReader::WellData wpData = m_wellPathCollection->asciiFileReader()->readWellData(filepath(), wellPathIndexInFile()); CVF_ASSERT(asciiReader);
RifWellPathAsciiFileReader::WellData wpData = asciiReader->readWellData(filepath(), wellPathIndexInFile());
this->name = wpData.m_name; this->name = wpData.m_name;
setWellPathGeometry(wpData.m_wellPathGeometry.p()); setWellPathGeometry(wpData.m_wellPathGeometry.p());

View File

@ -49,8 +49,6 @@ public:
RimWellPath(); RimWellPath();
virtual ~RimWellPath(); virtual ~RimWellPath();
void setProject(RimProject* project) { m_project = project; }
void setCollection(RimWellPathCollection* collection) { m_wellPathCollection = collection; }
void setLogFileInfo(RimWellLogFile* logFileInfo); void setLogFileInfo(RimWellLogFile* logFileInfo);
virtual caf::PdmFieldHandle* userDescriptionField(); virtual caf::PdmFieldHandle* userDescriptionField();
@ -74,7 +72,7 @@ public:
RigWellPath* wellPathGeometry() { return m_wellPath.p(); } RigWellPath* wellPathGeometry() { return m_wellPath.p(); }
RivWellPathPartMgr* partMgr(); RivWellPathPartMgr* partMgr();
bool readWellPathFile(QString * errorMessage); bool readWellPathFile(QString * errorMessage, RifWellPathAsciiFileReader* asciiReader);
void updateFilePathsFromProjectPath(); void updateFilePathsFromProjectPath();
@ -83,7 +81,7 @@ private:
void setWellPathGeometry(RigWellPath* wellPathModel) { m_wellPath = wellPathModel; } void setWellPathGeometry(RigWellPath* wellPathModel) { m_wellPath = wellPathModel; }
void readJsonWellPathFile(); void readJsonWellPathFile();
void readAsciiWellPathFile(); void readAsciiWellPathFile(RifWellPathAsciiFileReader* asciiReader);
QString surveyType() { return m_surveyType; } QString surveyType() { return m_surveyType; }
void setSurveyType(QString surveyType); void setSurveyType(QString surveyType);
@ -104,6 +102,4 @@ private:
cvf::ref<RigWellPath> m_wellPath; cvf::ref<RigWellPath> m_wellPath;
cvf::ref<RivWellPathPartMgr> m_wellPathPartMgr; cvf::ref<RivWellPathPartMgr> m_wellPathPartMgr;
caf::PdmPointer<RimWellPathCollection> m_wellPathCollection;
RimProject* m_project;
}; };

View File

@ -82,7 +82,6 @@ RimWellPathCollection::RimWellPathCollection()
wellPaths.uiCapability()->setUiHidden(true); wellPaths.uiCapability()->setUiHidden(true);
m_wellPathCollectionPartManager = new RivWellPathCollectionPartMgr(this); m_wellPathCollectionPartManager = new RivWellPathCollectionPartMgr(this);
m_project = NULL;
m_asciiFileReader = new RifWellPathAsciiFileReader; m_asciiFileReader = new RifWellPathAsciiFileReader;
} }
@ -107,20 +106,6 @@ void RimWellPathCollection::fieldChangedByUi(const caf::PdmFieldHandle* changedF
} }
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimWellPathCollection::setProject( RimProject* project )
{
m_project = project;
for (size_t wellPathIdx = 0; wellPathIdx < wellPaths.size(); wellPathIdx++)
{
wellPaths[wellPathIdx]->setProject(m_project);
wellPaths[wellPathIdx]->setCollection(this);
}
}
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// Read JSON files containing well path data /// Read JSON files containing well path data
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
@ -133,7 +118,7 @@ void RimWellPathCollection::readWellPathFiles()
if (!wellPaths[wpIdx]->filepath().isEmpty()) if (!wellPaths[wpIdx]->filepath().isEmpty())
{ {
QString errorMessage; QString errorMessage;
if (!wellPaths[wpIdx]->readWellPathFile(&errorMessage)) if (!wellPaths[wpIdx]->readWellPathFile(&errorMessage, this->asciiFileReader()))
{ {
QMessageBox::warning(RiuMainWindow::instance(), QMessageBox::warning(RiuMainWindow::instance(),
"File open error", "File open error",
@ -203,8 +188,6 @@ void RimWellPathCollection::addWellPaths( QStringList filePaths )
if (fi.suffix().compare("json") == 0) if (fi.suffix().compare("json") == 0)
{ {
RimWellPath* wellPath = new RimWellPath(); RimWellPath* wellPath = new RimWellPath();
wellPath->setProject(m_project);
wellPath->setCollection(this);
wellPath->filepath = filePath; wellPath->filepath = filePath;
wellPathArray.push_back(wellPath); wellPathArray.push_back(wellPath);
} }
@ -215,8 +198,6 @@ void RimWellPathCollection::addWellPaths( QStringList filePaths )
for (size_t i = 0; i < wellPathCount; ++i) for (size_t i = 0; i < wellPathCount; ++i)
{ {
RimWellPath* wellPath = new RimWellPath(); RimWellPath* wellPath = new RimWellPath();
wellPath->setProject(m_project);
wellPath->setCollection(this);
wellPath->filepath = filePath; wellPath->filepath = filePath;
wellPath->wellPathIndexInFile = static_cast<int>(i); wellPath->wellPathIndexInFile = static_cast<int>(i);
wellPathArray.push_back(wellPath); wellPathArray.push_back(wellPath);
@ -239,7 +220,7 @@ void RimWellPathCollection::readAndAddWellPaths(std::vector<RimWellPath*>& wellP
for (size_t wpIdx = 0; wpIdx < wellPathArray.size(); wpIdx++) for (size_t wpIdx = 0; wpIdx < wellPathArray.size(); wpIdx++)
{ {
RimWellPath* wellPath = wellPathArray[wpIdx]; RimWellPath* wellPath = wellPathArray[wpIdx];
wellPath->readWellPathFile(NULL); wellPath->readWellPathFile(NULL, this->asciiFileReader());
progress.setProgressDescription(QString("Reading file %1").arg(wellPath->name)); progress.setProgressDescription(QString("Reading file %1").arg(wellPath->name));
@ -249,7 +230,7 @@ void RimWellPathCollection::readAndAddWellPaths(std::vector<RimWellPath*>& wellP
{ {
existingWellPath->filepath = wellPath->filepath; existingWellPath->filepath = wellPath->filepath;
existingWellPath->wellPathIndexInFile = wellPath->wellPathIndexInFile; existingWellPath->wellPathIndexInFile = wellPath->wellPathIndexInFile;
existingWellPath->readWellPathFile(NULL); existingWellPath->readWellPathFile(NULL, this->asciiFileReader());
delete wellPath; delete wellPath;
} }
@ -279,7 +260,6 @@ void RimWellPathCollection::addWellLogs(const QStringList& filePaths)
if (!wellPath) if (!wellPath)
{ {
wellPath = new RimWellPath(); wellPath = new RimWellPath();
wellPath->setCollection(this);
wellPaths.push_back(wellPath); wellPaths.push_back(wellPath);
} }
@ -322,7 +302,9 @@ caf::PdmFieldHandle* RimWellPathCollection::objectToggleField()
void RimWellPathCollection::scheduleGeometryRegenAndRedrawViews() void RimWellPathCollection::scheduleGeometryRegenAndRedrawViews()
{ {
m_wellPathCollectionPartManager->scheduleGeometryRegen(); m_wellPathCollectionPartManager->scheduleGeometryRegen();
if (m_project) m_project->createDisplayModelAndRedrawAllViews(); RimProject* proj;
this->firstAnchestorOrThisOfType(proj);
if (proj) proj->createDisplayModelAndRedrawAllViews();
} }
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------

View File

@ -102,7 +102,6 @@ private:
void readAndAddWellPaths(std::vector<RimWellPath*>& wellPathArray); void readAndAddWellPaths(std::vector<RimWellPath*>& wellPathArray);
void sortWellsByName(); void sortWellsByName();
caf::PdmPointer<RimProject> m_project;
cvf::ref<RivWellPathCollectionPartMgr> m_wellPathCollectionPartManager; cvf::ref<RivWellPathCollectionPartMgr> m_wellPathCollectionPartManager;
RifWellPathAsciiFileReader* m_asciiFileReader; RifWellPathAsciiFileReader* m_asciiFileReader;