#1670 Add command feature "Export CARFIN"

This commit is contained in:
Magne Sjaastad
2017-06-29 22:36:51 +02:00
parent ec990b5e2c
commit b2b4ab95ba
11 changed files with 488 additions and 86 deletions

View File

@@ -18,6 +18,8 @@
#include "RicCellRangeUi.h"
#include "RicExportCarfinUi.h"
#include "RifReaderInterface.h"
#include "RigActiveCellInfo.h"
@@ -44,22 +46,19 @@ RicCellRangeUi::RicCellRangeUi()
CAF_PDM_InitField(&m_gridIndex, "GridIndex", 0, "Grid", "", "", "");
CAF_PDM_InitField(&m_startIndexI, "StartIndexI", 1, "Start index I", "", "", "");
m_startIndexI.uiCapability()->setUiEditorTypeName(caf::PdmUiSliderEditor::uiEditorTypeName());
CAF_PDM_InitField(&m_cellCountI, "CellCountI", 1, "Cell Count I", "", "", "");
m_cellCountI.uiCapability()->setUiEditorTypeName(caf::PdmUiSliderEditor::uiEditorTypeName());
CAF_PDM_InitField(&m_startIndexJ, "StartIndexJ", 1, "Start index J", "", "", "");
m_startIndexJ.uiCapability()->setUiEditorTypeName(caf::PdmUiSliderEditor::uiEditorTypeName());
CAF_PDM_InitField(&m_cellCountJ, "CellCountJ", 1, "Cell Count J", "", "", "");
m_cellCountJ.uiCapability()->setUiEditorTypeName(caf::PdmUiSliderEditor::uiEditorTypeName());
CAF_PDM_InitField(&m_startIndexK, "StartIndexK", 1, "Start index K", "", "", "");
m_startIndexK.uiCapability()->setUiEditorTypeName(caf::PdmUiSliderEditor::uiEditorTypeName());
CAF_PDM_InitField(&m_cellCountI, "CellCountI", 1, "Cell Count I", "", "", "");
CAF_PDM_InitField(&m_cellCountJ, "CellCountJ", 1, "Cell Count J", "", "", "");
CAF_PDM_InitField(&m_cellCountK, "CellCountK", 1, "Cell Count K", "", "", "");
m_cellCountK.uiCapability()->setUiEditorTypeName(caf::PdmUiSliderEditor::uiEditorTypeName());
m_startIndexI.uiCapability()->setUiEditorTypeName(caf::PdmUiSliderEditor::uiEditorTypeName());
m_startIndexJ.uiCapability()->setUiEditorTypeName(caf::PdmUiSliderEditor::uiEditorTypeName());
m_startIndexK.uiCapability()->setUiEditorTypeName(caf::PdmUiSliderEditor::uiEditorTypeName());
m_cellCountI.uiCapability()->setUiEditorTypeName( caf::PdmUiSliderEditor::uiEditorTypeName());
m_cellCountJ.uiCapability()->setUiEditorTypeName( caf::PdmUiSliderEditor::uiEditorTypeName());
m_cellCountK.uiCapability()->setUiEditorTypeName( caf::PdmUiSliderEditor::uiEditorTypeName());
}
//--------------------------------------------------------------------------------------------------
@@ -68,6 +67,34 @@ RicCellRangeUi::RicCellRangeUi()
void RicCellRangeUi::setCase(RimCase* rimCase)
{
m_case = rimCase;
setDefaultValues();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
caf::VecIjk RicCellRangeUi::start() const
{
return caf::VecIjk{m_startIndexI, m_startIndexJ, m_startIndexK};
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
caf::VecIjk RicCellRangeUi::count() const
{
return caf::VecIjk{ m_cellCountI, m_cellCountJ, m_cellCountK };
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QString RicCellRangeUi::gridName() const
{
if (m_gridIndex() == 0) return "";
return RigReservoirGridTools::gridName(m_case, m_gridIndex());
}
//--------------------------------------------------------------------------------------------------
@@ -82,55 +109,23 @@ void RicCellRangeUi::defineEditorAttribute(const caf::PdmFieldHandle* field, QSt
}
const cvf::StructGridInterface* grid = RigReservoirGridTools::gridByIndex(m_case, m_gridIndex());
if (field == &m_startIndexI || field == &m_cellCountI)
if (grid)
{
myAttr->m_minimum = 1;
myAttr->m_maximum = static_cast<int>(grid->cellCountI());
}
else if (field == &m_startIndexJ || field == &m_cellCountJ)
{
myAttr->m_minimum = 1;
myAttr->m_maximum = static_cast<int>(grid->cellCountJ());
}
else if (field == &m_startIndexK || field == &m_cellCountK)
{
myAttr->m_minimum = 1;
myAttr->m_maximum = static_cast<int>(grid->cellCountK());
}
const cvf::StructGridInterface* mainGrid = RigReservoirGridTools::mainGrid(m_case);
RigActiveCellInfo* actCellInfo = activeCellInfo();
if (grid == mainGrid && actCellInfo)
{
cvf::Vec3st min, max;
actCellInfo->IJKBoundingBox(min, max);
// Adjust to Eclipse indexing
min.x() = min.x() + 1;
min.y() = min.y() + 1;
min.z() = min.z() + 1;
max.x() = max.x() + 1;
max.y() = max.y() + 1;
max.z() = max.z() + 1;
m_startIndexI.uiCapability()->setUiName(QString("I Start (%1)").arg(min.x()));
m_startIndexJ.uiCapability()->setUiName(QString("J Start (%1)").arg(min.y()));
m_startIndexK.uiCapability()->setUiName(QString("K Start (%1)").arg(min.z()));
m_cellCountI.uiCapability()->setUiName( QString(" Width (%1)").arg(max.x() - min.x() + 1));
m_cellCountJ.uiCapability()->setUiName( QString(" Width (%1)").arg(max.y() - min.y() + 1));
m_cellCountK.uiCapability()->setUiName( QString(" Width (%1)").arg(max.z() - min.z() + 1));
}
else
{
m_startIndexI.uiCapability()->setUiName(QString("I Start"));
m_startIndexJ.uiCapability()->setUiName(QString("J Start"));
m_startIndexK.uiCapability()->setUiName(QString("K Start"));
m_cellCountI.uiCapability()->setUiName( QString(" Width"));
m_cellCountJ.uiCapability()->setUiName( QString(" Width"));
m_cellCountK.uiCapability()->setUiName( QString(" Width"));
if (field == &m_startIndexI || field == &m_cellCountI)
{
myAttr->m_minimum = 1;
myAttr->m_maximum = static_cast<int>(grid->cellCountI());
}
else if (field == &m_startIndexJ || field == &m_cellCountJ)
{
myAttr->m_minimum = 1;
myAttr->m_maximum = static_cast<int>(grid->cellCountJ());
}
else if (field == &m_startIndexK || field == &m_cellCountK)
{
myAttr->m_minimum = 1;
myAttr->m_maximum = static_cast<int>(grid->cellCountK());
}
}
}
@@ -165,6 +160,27 @@ QList<caf::PdmOptionItemInfo> RicCellRangeUi::calculateValueOptions(const caf::P
return options;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicCellRangeUi::fieldChangedByUi(const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue)
{
clampValues();
if (changedField == &m_gridIndex)
{
updateLegendText();
}
// If this object is contained in another object, make sure the other object is updated
RicExportCarfinUi* exportCarfin = nullptr;
this->firstAncestorOrThisOfType(exportCarfin);
if (exportCarfin)
{
exportCarfin->uiCapability()->updateConnectedEditors();
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@@ -173,17 +189,16 @@ void RicCellRangeUi::clampValues()
if (!m_case) return;
const cvf::StructGridInterface* grid = RigReservoirGridTools::gridByIndex(m_case, m_gridIndex());
if (grid)
{
m_cellCountI = cvf::Math::clamp(m_cellCountI.v(), 1, static_cast<int>(grid->cellCountI()));
m_startIndexI = cvf::Math::clamp(m_startIndexI.v(), 1, static_cast<int>(grid->cellCountI()));
if (!grid) return;
m_cellCountJ = cvf::Math::clamp(m_cellCountJ.v(), 1, static_cast<int>(grid->cellCountJ()));
m_startIndexJ = cvf::Math::clamp(m_startIndexJ.v(), 1, static_cast<int>(grid->cellCountJ()));
m_cellCountI = cvf::Math::clamp(m_cellCountI.v(), 1, static_cast<int>(grid->cellCountI()));
m_startIndexI = cvf::Math::clamp(m_startIndexI.v(), 1, static_cast<int>(grid->cellCountI()));
m_cellCountK = cvf::Math::clamp(m_cellCountK.v(), 1, static_cast<int>(grid->cellCountK()));
m_startIndexK = cvf::Math::clamp(m_startIndexK.v(), 1, static_cast<int>(grid->cellCountK()));
}
m_cellCountJ = cvf::Math::clamp(m_cellCountJ.v(), 1, static_cast<int>(grid->cellCountJ()));
m_startIndexJ = cvf::Math::clamp(m_startIndexJ.v(), 1, static_cast<int>(grid->cellCountJ()));
m_cellCountK = cvf::Math::clamp(m_cellCountK.v(), 1, static_cast<int>(grid->cellCountK()));
m_startIndexK = cvf::Math::clamp(m_startIndexK.v(), 1, static_cast<int>(grid->cellCountK()));
}
//--------------------------------------------------------------------------------------------------
@@ -192,6 +207,7 @@ void RicCellRangeUi::clampValues()
void RicCellRangeUi::setDefaultValues()
{
const cvf::StructGridInterface* grid = RigReservoirGridTools::gridByIndex(m_case, m_gridIndex());
if (!grid) return;
RigActiveCellInfo* actCellInfo = this->activeCellInfo();
@@ -235,10 +251,70 @@ void RicCellRangeUi::setDefaultValues()
RigActiveCellInfo* RicCellRangeUi::activeCellInfo() const
{
RimEclipseCase* rimEclipeCase = dynamic_cast<RimEclipseCase*>(m_case.p());
if (rimEclipeCase)
if (rimEclipeCase && rimEclipeCase->eclipseCaseData())
{
return rimEclipeCase->eclipseCaseData()->activeCellInfo(RifReaderInterface::MATRIX_RESULTS);
}
return nullptr;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicCellRangeUi::updateLegendText()
{
const cvf::StructGridInterface* grid = RigReservoirGridTools::gridByIndex(m_case, m_gridIndex());
const cvf::StructGridInterface* mainGrid = RigReservoirGridTools::mainGrid(m_case);
RigActiveCellInfo* actCellInfo = activeCellInfo();
if (grid == mainGrid && actCellInfo)
{
cvf::Vec3st min, max;
actCellInfo->IJKBoundingBox(min, max);
// Adjust to Eclipse indexing
min.x() = min.x() + 1;
min.y() = min.y() + 1;
min.z() = min.z() + 1;
max.x() = max.x() + 1;
max.y() = max.y() + 1;
max.z() = max.z() + 1;
m_startIndexI.uiCapability()->setUiName(QString("I Start (%1)").arg(min.x()));
m_startIndexJ.uiCapability()->setUiName(QString("J Start (%1)").arg(min.y()));
m_startIndexK.uiCapability()->setUiName(QString("K Start (%1)").arg(min.z()));
m_cellCountI.uiCapability()->setUiName(QString(" Width (%1)").arg(max.x() - min.x() + 1));
m_cellCountJ.uiCapability()->setUiName(QString(" Width (%1)").arg(max.y() - min.y() + 1));
m_cellCountK.uiCapability()->setUiName(QString(" Width (%1)").arg(max.z() - min.z() + 1));
}
else
{
m_startIndexI.uiCapability()->setUiName(QString("I Start"));
m_startIndexJ.uiCapability()->setUiName(QString("J Start"));
m_startIndexK.uiCapability()->setUiName(QString("K Start"));
m_cellCountI.uiCapability()->setUiName(QString(" Width"));
m_cellCountJ.uiCapability()->setUiName(QString(" Width"));
m_cellCountK.uiCapability()->setUiName(QString(" Width"));
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicCellRangeUi::defineUiOrdering(QString uiConfigName, caf::PdmUiOrdering& uiOrdering)
{
uiOrdering.add(&m_gridIndex);
uiOrdering.add(&m_startIndexI);
uiOrdering.add(&m_cellCountI);
uiOrdering.add(&m_startIndexJ);
uiOrdering.add(&m_cellCountJ);
uiOrdering.add(&m_startIndexK);
uiOrdering.add(&m_cellCountK);
updateLegendText();
}