#810, #813, #808 Display formation name when picking

This commit is contained in:
Jacob Støren 2016-08-24 15:19:39 +02:00
parent 1a3d8a13af
commit f03e6de1f2
9 changed files with 227 additions and 2 deletions

View File

@ -25,6 +25,11 @@
#include <QFileInfo>
#include <QDir>
#include <QDebug>
#include "RimProject.h"
#include "RiaApplication.h"
#include "RimOilField.h"
#include "RimFormationNamesCollection.h"
#include "RimFormationNames.h"
CAF_PDM_XML_ABSTRACT_SOURCE_INIT(RimCase, "RimCase");
@ -39,6 +44,8 @@ RimCase::RimCase()
CAF_PDM_InitField(&caseId, "CaseId", -1, "Case ID", "", "" ,"");
caseId.uiCapability()->setUiReadOnly(true);
CAF_PDM_InitFieldNoDefault(&activeFormationNames, "DefaultFormationNames", "Formation Names File", "", "", "");
}
//--------------------------------------------------------------------------------------------------
@ -56,3 +63,33 @@ cvf::Vec3d RimCase::displayModelOffset() const
{
return cvf::Vec3d::ZERO;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QList<caf::PdmOptionItemInfo> RimCase::calculateValueOptions(const caf::PdmFieldHandle* fieldNeedingOptions, bool * useOptionsOnly)
{
QList<caf::PdmOptionItemInfo> optionList;
if(fieldNeedingOptions == &activeFormationNames)
{
RimProject* proj = RiaApplication::instance()->project();
if (proj && proj->activeOilField() && proj->activeOilField()->formationNamesCollection())
{
for(RimFormationNames* fnames : proj->activeOilField()->formationNamesCollection()->formationNamesList())
{
optionList.push_back(caf::PdmOptionItemInfo(fnames->uiCapability()->uiName(),
QVariant::fromValue(caf::PdmPointer<caf::PdmObjectHandle>(fnames)),
false,
fnames->uiCapability()->uiIcon()));
}
}
if(optionList.size() > 0)
{
optionList.push_front(caf::PdmOptionItemInfo("None", QVariant::fromValue(caf::PdmPointer<caf::PdmObjectHandle>(NULL))));
}
}
return optionList;
}

View File

@ -19,6 +19,7 @@
#pragma once
#include "cafPdmPtrField.h"
#include "cafPdmField.h"
#include "cafPdmObject.h"
@ -28,6 +29,7 @@
#include <vector>
class RimView;
class RimFormationNames;
namespace cvf {
class BoundingBox;
@ -43,6 +45,8 @@ public:
caf::PdmField<int> caseId;
caf::PdmField<QString> caseUserDescription;
caf::PdmPtrField<RimFormationNames*> activeFormationNames;
virtual std::vector<RimView*> views() = 0;
virtual void updateFilePathsFromProjectPath(const QString& projectPath, const QString& oldProjectPath) = 0;
@ -56,6 +60,7 @@ public:
virtual cvf::Vec3d displayModelOffset() const;
private:
virtual QList<caf::PdmOptionItemInfo> calculateValueOptions(const caf::PdmFieldHandle* fieldNeedingOptions, bool * useOptionsOnly) override;
virtual caf::PdmFieldHandle* userDescriptionField() override { return &caseUserDescription; }
};

View File

@ -21,6 +21,7 @@
#include "RimTools.h"
#include "cafPdmUiFilePathEditor.h"
#include "QFile"
CAF_PDM_SOURCE_INIT(RimFormationNames, "FormationNames");
@ -34,6 +35,7 @@ RimFormationNames::RimFormationNames()
CAF_PDM_InitField(&m_formationNamesFileName, "FormationNamesFileName", QString(""), "File Name", "", "", "");
m_formationNamesFileName.uiCapability()->setUiEditorTypeName(caf::PdmUiFilePathEditor::uiEditorTypeName());
}
//--------------------------------------------------------------------------------------------------
@ -96,7 +98,61 @@ const QString& RimFormationNames::fileName()
//--------------------------------------------------------------------------------------------------
void RimFormationNames::readFormationNamesFile(QString * errorMessage)
{
QFile dataFile(m_formationNamesFileName());
if (!dataFile.open(QFile::ReadOnly)){ if (errorMessage) (*errorMessage) += "Could not open the File: " + (m_formationNamesFileName()) + "\n"; return;}
m_formationNamesData = new RigFormationNames;
QTextStream stream(&dataFile);
int lineNumber = 1;
while (!stream.atEnd())
{
QString line = stream.readLine();
QStringList lineSegs = line.split("'", QString::KeepEmptyParts);
if(lineSegs.size() == 0) continue; // Empty line
if(lineSegs.size() == 1) continue; // No name present. Comment line ?
if(lineSegs.size() == 2)
{
if (errorMessage) (*errorMessage) += "Missing quote on line : " + QString::number(lineNumber) + "\n";
continue; // One quote present
}
if (lineSegs.size() == 3) // Normal case
{
if ( lineSegs[0].contains("--")) continue; // Comment line
QString formationName = lineSegs[1];
int commentMarkPos = lineSegs[2].indexOf("--");
QString numberString = lineSegs[2];
if (commentMarkPos >= 0) numberString.truncate(commentMarkPos);
QStringList numberWords = numberString.split(QRegExp("\\s+"), QString::SkipEmptyParts);
if (numberWords.size() == 3)
{
bool isNumber1 = false;
bool isNumber2 = false;
int startK = numberWords[0].toInt(&isNumber1);
int endK = numberWords[2].toInt(&isNumber2);
if (!(isNumber2 && isNumber1))
{
if (errorMessage) (*errorMessage) += "Format error on line: " + QString::number(lineNumber) + "\n";
continue;
}
int tmp = startK; startK = tmp < endK ? tmp : endK;
endK = tmp > endK ? tmp: endK;
m_formationNamesData->appendFormationRange(formationName, startK-1, endK-1);
}
else
{
if (errorMessage) (*errorMessage) += "Format error on line: " + QString::number(lineNumber) + "\n";
}
}
++lineNumber;
}
}
//--------------------------------------------------------------------------------------------------

View File

@ -34,6 +34,8 @@ public:
void setFileName(const QString& fileName);
const QString& fileName();
RigFormationNames* formationNamesData() { return m_formationNamesData.p();}
void readFormationNamesFile(QString * errorMessage);
void updateFilePathsFromProjectPath(const QString& newProjectPath, const QString& oldProjectPath);
@ -51,5 +53,37 @@ private:
class RigFormationNames: public cvf::Object
{
};
public:
int formationIndexFromKLayerIdx(size_t Kidx)
{
if(Kidx >= m_nameIndexPrKLayer.size()) return -1;
return m_nameIndexPrKLayer[Kidx];
}
QString formationNameFromKLayerIdx(size_t Kidx)
{
int idx = formationIndexFromKLayerIdx(Kidx);
if (idx >= m_formationNames.size()) return "";
if (idx == -1) return "";
return m_formationNames[idx];
}
void appendFormationRange(const QString& name, int kStartIdx, int kEndIdx)
{
CVF_ASSERT(kStartIdx <= kEndIdx);
int nameIdx = static_cast<int>(m_formationNames.size());
m_formationNames.push_back(name);
if (kEndIdx >= static_cast<int>(m_nameIndexPrKLayer.size())) m_nameIndexPrKLayer.resize(kEndIdx + 1, -1);
for (int kIdx = kStartIdx; kIdx <= kEndIdx; ++kIdx)
{
m_nameIndexPrKLayer[kIdx] = nameIdx;
}
}
private:
std::vector<int> m_nameIndexPrKLayer;
std::vector<QString> m_formationNames;
};

View File

@ -30,6 +30,8 @@ public:
RimFormationNamesCollection();
~RimFormationNamesCollection();
const caf::PdmChildArrayField<RimFormationNames*>& formationNamesList() const { return m_formationNamesList;}
void readAllFormationNames();
void importFiles(const QStringList& fileNames);

View File

@ -27,6 +27,7 @@
#include "RigFemPartGrid.h"
#include "RimGeoMechCellColors.h"
#include "RigFemPartResultsCollection.h"
#include "RimFormationNames.h"
@ -75,6 +76,7 @@ QString RiuFemResultTextBuilder::mainResultText()
QString topoText = this->topologyText("\n");
text += topoText;
appendDetails(text, formationDetails());
text += "\n";
appendDetails(text, gridResultDetails());
@ -153,6 +155,46 @@ QString RiuFemResultTextBuilder::gridResultDetails()
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QString RiuFemResultTextBuilder::formationDetails()
{
QString text;
RimCase* rimCase = m_reservoirView->ownerCase();
if(rimCase)
{
if(rimCase->activeFormationNames() && rimCase->activeFormationNames()->formationNamesData())
{
RigFormationNames* formNames = rimCase->activeFormationNames()->formationNamesData();
size_t k = cvf::UNDEFINED_SIZE_T;
{
RigGeoMechCaseData* geomData = m_reservoirView->geoMechCase()->geoMechData();
if(geomData)
{
size_t i = 0;
size_t j = 0;
geomData->femParts()->part(m_gridIndex)->structGrid()->ijkFromCellIndex(m_cellIndex, &i, &j, &k);
}
}
if(k != cvf::UNDEFINED_SIZE_T)
{
QString formName = formNames->formationNameFromKLayerIdx(k);
if(!formName.isEmpty())
{
//text += "-- Formation details --\n";
text += QString("Formation Name: %1\n").arg(formName);
}
}
}
}
return text;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------

View File

@ -52,6 +52,7 @@ private:
void appendDetails(QString& text, const QString& details);
QString gridResultDetails();
QString formationDetails();
QString closestNodeResultText(RimGeoMechCellColors* resultColors);

View File

@ -31,6 +31,7 @@
#include "RimReservoirCellResultsStorage.h"
#include "RimEclipseView.h"
#include "RimEclipseCellColors.h"
#include "RimFormationNames.h"
@ -109,6 +110,7 @@ QString RiuResultTextBuilder::mainResultText()
QString topoText = this->topologyText("\n");
text += topoText;
appendDetails(text, formationDetails());
text += "\n";
appendDetails(text, nncDetails());
@ -228,6 +230,51 @@ QString RiuResultTextBuilder::faultResultDetails()
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QString RiuResultTextBuilder::formationDetails()
{
QString text;
RimCase* rimCase = m_reservoirView->eclipseCase();
if(rimCase)
{
if(rimCase->activeFormationNames() && rimCase->activeFormationNames()->formationNamesData())
{
RigFormationNames* formNames = rimCase->activeFormationNames()->formationNamesData();
size_t k = cvf::UNDEFINED_SIZE_T;
{
const RigCaseData* eclipseData = m_reservoirView->eclipseCase()->reservoirData();
if(eclipseData)
{
if(m_cellIndex != cvf::UNDEFINED_SIZE_T)
{
size_t i = cvf::UNDEFINED_SIZE_T;
size_t j = cvf::UNDEFINED_SIZE_T;
eclipseData->grid(m_gridIndex)->ijkFromCellIndex(m_cellIndex, &i, &j, &k);
}
}
}
if (k != cvf::UNDEFINED_SIZE_T)
{
QString formName = formNames->formationNameFromKLayerIdx(k);
if(!formName.isEmpty())
{
//text += "-- Formation details --\n";
text += QString("Formation Name: %1\n").arg(formName);
}
}
}
}
return text;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------

View File

@ -54,6 +54,7 @@ private:
QString gridResultDetails();
QString faultResultDetails();
QString formationDetails();
QString cellEdgeResultDetails();
QString nncDetails();