Added class used to build text strings from picked objects in 3D scene

This commit is contained in:
Magne Sjaastad 2014-09-05 08:25:38 +02:00
parent 2906027429
commit 787d44e446
3 changed files with 391 additions and 0 deletions

View File

@ -42,6 +42,7 @@ set( APPLICATION_FILES
set( USER_INTERFACE_FILES
UserInterface/RiuCursors.cpp
UserInterface/RiuResultTextBuilder.cpp
UserInterface/RiuMainWindow.cpp
UserInterface/RiuResultInfoPanel.cpp
UserInterface/RiuViewer.cpp
@ -166,6 +167,7 @@ list( REMOVE_ITEM RAW_SOURCES
UserInterface/RiuSimpleHistogramWidget.cpp
UserInterface/RiuMultiCaseImportDialog.cpp
UserInterface/RiuResultTextBuilder.cpp
)
include( CustomPCH.cmake )

View File

@ -0,0 +1,316 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) Statoil ASA, Ceetron Solutions AS
//
// ResInsight is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE.
//
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
#include "RiuResultTextBuilder.h"
#include "RigCaseCellResultsData.h"
#include "RigCaseData.h"
#include "RigMainGrid.h"
#include "RigResultAccessor.h"
#include "RigResultAccessorFactory.h"
#include "RimCase.h"
#include "RimCellEdgeResultSlot.h"
#include "RimFaultResultSlot.h"
#include "RimReservoirCellResultsStorage.h"
#include "RimReservoirView.h"
#include "RimResultSlot.h"
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RiuResultTextBuilder::RiuResultTextBuilder(RimReservoirView* reservoirView, size_t gridIndex, size_t cellIndex, size_t timeStepIndex)
{
CVF_ASSERT(reservoirView);
m_reservoirView = reservoirView;
m_gridIndex = gridIndex;
m_cellIndex = cellIndex;
m_timeStepIndex = timeStepIndex;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QString RiuResultTextBuilder::mainResultText()
{
QString text;
QString nncText = nncResultText();
if (!nncText.isEmpty())
{
text = nncText;
}
else
{
text = gridResultText();
}
return text;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QString RiuResultTextBuilder::gridResultDetails()
{
QString text;
if (m_reservoirView->eclipseCase() && m_reservoirView->eclipseCase()->reservoirData())
{
RigCaseData* eclipseCaseData = m_reservoirView->eclipseCase()->reservoirData();
RigGridBase* grid = eclipseCaseData->grid(m_gridIndex);
this->appendTextFromResultSlot(eclipseCaseData, m_gridIndex, m_cellIndex, m_timeStepIndex, m_reservoirView->cellResult(), &text);
}
return text;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QString RiuResultTextBuilder::faultResultDetails()
{
QString text;
if (m_reservoirView->eclipseCase() && m_reservoirView->eclipseCase()->reservoirData())
{
RigCaseData* eclipseCaseData = m_reservoirView->eclipseCase()->reservoirData();
RigGridBase* grid = eclipseCaseData->grid(m_gridIndex);
RigMainGrid* mainGrid = grid->mainGrid();
const RigFault* fault = mainGrid->findFaultFromCellIndexAndCellFace(m_cellIndex, m_face);
if (fault)
{
text.append(QString("Fault Name: %1\n").arg(fault->name()));
cvf::StructGridInterface::FaceEnum faceHelper(m_face);
text.append("Fault Face : " + faceHelper.text() + "\n");
if (m_reservoirView->faultResultSettings()->hasValidCustomResult())
{
text.append("Fault result data:\n");
this->appendTextFromResultSlot(eclipseCaseData, m_gridIndex, m_cellIndex, m_timeStepIndex, m_reservoirView->currentFaultResultSlot(), &text);
}
}
}
return text;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QString RiuResultTextBuilder::gridResultText()
{
QString text;
return text;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QString RiuResultTextBuilder::nncResultText()
{
QString text;
return text;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuResultTextBuilder::appendTextFromResultSlot(RigCaseData* eclipseCase, size_t gridIndex, size_t cellIndex, size_t timeStepIndex, RimResultSlot* resultSlot, QString* resultInfoText)
{
if (!resultSlot)
{
return;
}
RifReaderInterface::PorosityModelResultType porosityModel = RigCaseCellResultsData::convertFromProjectModelPorosityModel(resultSlot->porosityModel());
if (resultSlot->isTernarySaturationSelected())
{
RimReservoirCellResultsStorage* gridCellResults = resultSlot->currentGridCellResults();
if (gridCellResults)
{
size_t soilScalarSetIndex = gridCellResults->findOrLoadScalarResult(RimDefines::DYNAMIC_NATIVE, "SOIL");
size_t sgasScalarSetIndex = gridCellResults->findOrLoadScalarResult(RimDefines::DYNAMIC_NATIVE, "SGAS");
size_t swatScalarSetIndex = gridCellResults->findOrLoadScalarResult(RimDefines::DYNAMIC_NATIVE, "SWAT");
cvf::ref<RigResultAccessor> dataAccessObjectX = RigResultAccessorFactory::createResultAccessor(eclipseCase, gridIndex, porosityModel, timeStepIndex, soilScalarSetIndex);
cvf::ref<RigResultAccessor> dataAccessObjectY = RigResultAccessorFactory::createResultAccessor(eclipseCase, gridIndex, porosityModel, timeStepIndex, sgasScalarSetIndex);
cvf::ref<RigResultAccessor> dataAccessObjectZ = RigResultAccessorFactory::createResultAccessor(eclipseCase, gridIndex, porosityModel, timeStepIndex, swatScalarSetIndex);
double scalarValue = 0.0;
if (dataAccessObjectX.notNull()) scalarValue = dataAccessObjectX->cellScalar(cellIndex);
else scalarValue = 0.0;
resultInfoText->append(QString("SOIL : %1\n").arg(scalarValue));
if (dataAccessObjectY.notNull()) scalarValue = dataAccessObjectY->cellScalar(cellIndex);
else scalarValue = 0.0;
resultInfoText->append(QString("SGAS : %1\n").arg(scalarValue));
if (dataAccessObjectZ.notNull()) scalarValue = dataAccessObjectZ->cellScalar(cellIndex);
else scalarValue = 0.0;
resultInfoText->append(QString("SWAT : %1\n").arg(scalarValue));
}
}
else if (resultSlot->hasResult())
{
RifReaderInterface::PorosityModelResultType porosityModel = RigCaseCellResultsData::convertFromProjectModelPorosityModel(resultSlot->porosityModel());
cvf::ref<RigResultAccessor> resultAccessor;
if (resultSlot->hasStaticResult())
{
if (resultSlot->resultVariable().compare(RimDefines::combinedTransmissibilityResultName(), Qt::CaseInsensitive) == 0)
{
cvf::ref<RigResultAccessor> transResultAccessor = RigResultAccessorFactory::createResultAccessor(eclipseCase, gridIndex, porosityModel, 0, RimDefines::combinedTransmissibilityResultName());
{
double scalarValue = transResultAccessor->cellFaceScalar(cellIndex, cvf::StructGridInterface::POS_I);
resultInfoText->append(QString("Tran X : %1\n").arg(scalarValue));
scalarValue = transResultAccessor->cellFaceScalar(cellIndex, cvf::StructGridInterface::POS_J);
resultInfoText->append(QString("Tran Y : %1\n").arg(scalarValue));
scalarValue = transResultAccessor->cellFaceScalar(cellIndex, cvf::StructGridInterface::POS_K);
resultInfoText->append(QString("Tran Z : %1\n").arg(scalarValue));
}
}
else if (resultSlot->resultVariable().compare(RimDefines::combinedMultResultName(), Qt::CaseInsensitive) == 0)
{
cvf::ref<RigResultAccessor> multResultAccessor = RigResultAccessorFactory::createResultAccessor(eclipseCase, gridIndex, porosityModel, 0, RimDefines::combinedMultResultName());
{
double scalarValue = 0.0;
scalarValue = multResultAccessor->cellFaceScalar(cellIndex, cvf::StructGridInterface::POS_I);
resultInfoText->append(QString("MULTX : %1\n").arg(scalarValue));
scalarValue = multResultAccessor->cellFaceScalar(cellIndex, cvf::StructGridInterface::NEG_I);
resultInfoText->append(QString("MULTX- : %1\n").arg(scalarValue));
scalarValue = multResultAccessor->cellFaceScalar(cellIndex, cvf::StructGridInterface::POS_J);
resultInfoText->append(QString("MULTY : %1\n").arg(scalarValue));
scalarValue = multResultAccessor->cellFaceScalar(cellIndex, cvf::StructGridInterface::NEG_J);
resultInfoText->append(QString("MULTY- : %1\n").arg(scalarValue));
scalarValue = multResultAccessor->cellFaceScalar(cellIndex, cvf::StructGridInterface::POS_K);
resultInfoText->append(QString("MULTZ : %1\n").arg(scalarValue));
scalarValue = multResultAccessor->cellFaceScalar(cellIndex, cvf::StructGridInterface::NEG_K);
resultInfoText->append(QString("MULTZ- : %1\n").arg(scalarValue));
}
}
else if (resultSlot->resultVariable().compare(RimDefines::combinedRiTransResultName(), Qt::CaseInsensitive) == 0)
{
cvf::ref<RigResultAccessor> transResultAccessor = RigResultAccessorFactory::createResultAccessor(eclipseCase, gridIndex, porosityModel, 0, RimDefines::combinedRiTransResultName());
{
double scalarValue = transResultAccessor->cellFaceScalar(cellIndex, cvf::StructGridInterface::POS_I);
resultInfoText->append(QString("riTran X : %1\n").arg(scalarValue));
scalarValue = transResultAccessor->cellFaceScalar(cellIndex, cvf::StructGridInterface::POS_J);
resultInfoText->append(QString("riTran Y : %1\n").arg(scalarValue));
scalarValue = transResultAccessor->cellFaceScalar(cellIndex, cvf::StructGridInterface::POS_K);
resultInfoText->append(QString("riTran Z : %1\n").arg(scalarValue));
}
}
else if (resultSlot->resultVariable().compare(RimDefines::combinedRiMultResultName(), Qt::CaseInsensitive) == 0)
{
cvf::ref<RigResultAccessor> resultAccessor = RigResultAccessorFactory::createResultAccessor(eclipseCase, gridIndex, porosityModel, 0, RimDefines::combinedRiMultResultName());
{
double scalarValue = resultAccessor->cellFaceScalar(cellIndex, cvf::StructGridInterface::POS_I);
resultInfoText->append(QString("riMult X : %1\n").arg(scalarValue));
scalarValue = resultAccessor->cellFaceScalar(cellIndex, cvf::StructGridInterface::POS_J);
resultInfoText->append(QString("riMult Y : %1\n").arg(scalarValue));
scalarValue = resultAccessor->cellFaceScalar(cellIndex, cvf::StructGridInterface::POS_K);
resultInfoText->append(QString("riMult Z : %1\n").arg(scalarValue));
}
}
else if (resultSlot->resultVariable().compare(RimDefines::combinedRiAreaNormTransResultName(), Qt::CaseInsensitive) == 0)
{
cvf::ref<RigResultAccessor> resultAccessor = RigResultAccessorFactory::createResultAccessor(eclipseCase, gridIndex, porosityModel, 0, RimDefines::combinedRiAreaNormTransResultName());
{
double scalarValue = resultAccessor->cellFaceScalar(cellIndex, cvf::StructGridInterface::POS_I);
resultInfoText->append(QString("riTransByArea X : %1\n").arg(scalarValue));
scalarValue = resultAccessor->cellFaceScalar(cellIndex, cvf::StructGridInterface::POS_J);
resultInfoText->append(QString("riTransByArea Y : %1\n").arg(scalarValue));
scalarValue = resultAccessor->cellFaceScalar(cellIndex, cvf::StructGridInterface::POS_K);
resultInfoText->append(QString("riTransByArea Z : %1\n").arg(scalarValue));
}
}
else
{
resultAccessor = RigResultAccessorFactory::createResultAccessor(eclipseCase, gridIndex, porosityModel, 0, resultSlot->scalarResultIndex());
}
}
else
{
resultAccessor = RigResultAccessorFactory::createResultAccessor(eclipseCase, gridIndex, porosityModel, timeStepIndex, resultSlot->scalarResultIndex());
}
if (resultAccessor.notNull())
{
double scalarValue = resultAccessor->cellScalar(cellIndex);
resultInfoText->append(resultSlot->resultVariable());
resultInfoText->append(QString(" : %1\n").arg(scalarValue));
}
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QString RiuResultTextBuilder::cellEdgeResultDetails()
{
QString text;
//if (m_reservoirView->eclipseCase() && m_reservoirView->eclipseCase()->reservoirData())
if (m_reservoirView->cellEdgeResult()->hasResult())
{
size_t resultIndices[6];
QStringList resultNames;
m_reservoirView->cellEdgeResult()->gridScalarIndices(resultIndices);
m_reservoirView->cellEdgeResult()->gridScalarResultNames(&resultNames);
text.push_back("\nCell edge result data:\n");
for (int idx = 0; idx < 6; idx++)
{
if (resultIndices[idx] == cvf::UNDEFINED_SIZE_T) continue;
// Cell edge results are static, results are loaded for first time step only
RifReaderInterface::PorosityModelResultType porosityModel = RigCaseCellResultsData::convertFromProjectModelPorosityModel(m_reservoirView->cellResult()->porosityModel());
cvf::ref<RigResultAccessor> resultAccessor = RigResultAccessorFactory::createResultAccessor(m_reservoirView->eclipseCase()->reservoirData(), m_gridIndex, porosityModel, 0, resultIndices[idx]);
if (resultAccessor.notNull())
{
double scalarValue = resultAccessor->cellScalar(m_cellIndex);
text.append(QString("%1 : %2\n").arg(resultNames[idx]).arg(scalarValue));
}
}
}
return text;
}

View File

@ -0,0 +1,73 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2011-2012 Statoil ASA, Ceetron AS
//
// ResInsight is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE.
//
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
#pragma once
#include "cvfBase.h"
#include "cafPdmPointer.h"
#include "cvfStructGrid.h"
class RimReservoirView;
class RimResultSlot;
class QString;
class RigCaseData;
namespace cvf {
class Part;
}
//==================================================================================================
//
//
//==================================================================================================
class RiuResultTextBuilder
{
public:
RiuResultTextBuilder(RimReservoirView* reservoirView, size_t gridIndex, size_t cellIndex, size_t timeStepIndex);
void setPickInfo(cvf::Part* part, cvf::uint partFaceHit, cvf::Part* nncPart, cvf::uint nncFaceHit, cvf::Vec3d intersectionPoint);
QString mainResultText();
QString gridResultDetails();
QString faultResultDetails();
QString cellEdgeResultDetails();
private:
QString gridResultText();
QString nncResultText();
void appendTextFromResultSlot(RigCaseData* eclipseCase, size_t gridIndex, size_t cellIndex, size_t timeStepIndex, RimResultSlot* resultSlot, QString* resultInfoText);
private:
caf::PdmPointer<RimReservoirView> m_reservoirView;
size_t m_gridIndex;
size_t m_cellIndex;
size_t m_timeStepIndex;
cvf::StructGridInterface::FaceType m_face;
cvf::Part* m_part;
uint m_partFaceIndex;
cvf::Part* m_nncPart;
uint m_nncPartFaceIndex;
cvf::Vec3d m_intersectionPoint;
};