#3477 Export Property : Updates after code has moved to exportPropertyInViews

This commit is contained in:
Magne Sjaastad 2018-10-11 07:31:15 +02:00
parent c74637c0cc
commit e1e515b659
5 changed files with 87 additions and 137 deletions

View File

@ -18,25 +18,21 @@
#include "RicfExportProperty.h"
#include "RicfCommandFileExecutor.h"
#include "../Commands/ExportCommands/RicEclipseCellResultToFileImpl.h"
#include "RiaApplication.h"
#include "RiaLogging.h"
#include "../Commands/ExportCommands/RicEclipseCellResultToFileImpl.h"
#include "RicfCommandFileExecutor.h"
#include "RifEclipseInputFileTools.h"
#include "RigCaseCellResultsData.h"
#include "RigEclipseCaseData.h"
#include "RigMainGrid.h"
#include "RigResultAccessor.h"
#include "RigResultAccessorFactory.h"
#include "RimProject.h"
#include "RimOilField.h"
#include "RimEclipseCaseCollection.h"
#include "RimEclipseCase.h"
#include "RimEclipseView.h"
#include "RimEclipseCaseCollection.h"
#include "RimEclipseCellColors.h"
#include "RimEclipseView.h"
#include "RimProject.h"
#include "cafUtils.h"
@ -49,12 +45,15 @@ CAF_PDM_SOURCE_INIT(RicfExportProperty, "exportProperty");
//--------------------------------------------------------------------------------------------------
RicfExportProperty::RicfExportProperty()
{
// clang-format off
RICF_InitField(&m_caseId, "caseId", -1, "Case ID", "", "", "");
RICF_InitField(&m_timeStepIndex, "timeStep", -1, "Time Step Index", "", "", "");
RICF_InitField(&m_propertyName, "property", QString(), "Property Name", "", "", "");
RICF_InitField(&m_type, "type", caf::AppEnum<RiaDefines::ResultCatType>(RiaDefines::UNDEFINED), "Property type", "", "", "");
RICF_InitField(&m_type, "type", caf::AppEnum<RiaDefines::ResultCatType>(RiaDefines::DYNAMIC_NATIVE), "Property type", "", "", "");
RICF_InitField(&m_eclipseKeyword, "eclipseKeyword", QString(), "Eclipse Keyword", "", "", "");
RICF_InitField(&m_undefinedValue, "undefinedValue", 0.0, "Undefined Value", "", "", "");
RICF_InitField(&m_path, "exportFile", QString(), "Export File", "", "", "");
// clang-format on
}
//--------------------------------------------------------------------------------------------------
@ -62,108 +61,63 @@ RicfExportProperty::RicfExportProperty()
//--------------------------------------------------------------------------------------------------
void RicfExportProperty::execute()
{
RimEclipseCase* eclipseCase = nullptr;
{
bool foundCase = false;
for (RimEclipseCase* c : RiaApplication::instance()->project()->activeOilField()->analysisModels()->cases)
std::vector<RimCase*> cases;
RiaApplication::instance()->project()->allCases(cases);
for (auto* c : cases)
{
if (c->caseId == m_caseId)
RimEclipseCase* eclCase = dynamic_cast<RimEclipseCase*>(c);
if (eclCase->caseId == m_caseId)
{
eclipseCase = c;
foundCase = true;
eclipseCase = eclCase;
break;
}
}
if (!foundCase)
if (!eclipseCase)
{
RiaLogging::error(QString("exportProperty: Could not find case with ID %1").arg(m_caseId()));
return;
}
if (!eclipseCase->eclipseCaseData())
{
if (!eclipseCase->openReserviorCase())
{
RiaLogging::error(QString("exportProperty: Could not find eclipseCaseData with ID %1").arg(m_caseId()));
return;
}
}
}
bool fullySpecified = m_caseId >= 0 && m_timeStepIndex >= 0 && !m_propertyName().isEmpty();
bool anyViewsFound = false;
for (Rim3dView* v : eclipseCase->views())
{
RimEclipseView* view = dynamic_cast<RimEclipseView*>(v);
if (!view) continue;
anyViewsFound = true;
RigEclipseCaseData* eclipseCaseData = eclipseCase->eclipseCaseData();
auto timeStepIndex = m_timeStepIndex >= 0 ? m_timeStepIndex : view->currentTimeStep();
auto propertyName = !m_propertyName().isEmpty() ? m_propertyName : view->cellResult()->resultVariable();
RiaDefines::ResultCatType propertyType;
if (!m_propertyName().isEmpty()) propertyType = m_type();
else propertyType = view->cellResult()->resultType();
RigCaseCellResultsData* cellResultsData = eclipseCaseData->results(RiaDefines::MATRIX_MODEL);
size_t resultIdx = cellResultsData->findOrLoadScalarResult(m_propertyName);
if (resultIdx == cvf::UNDEFINED_SIZE_T)
{
RiaLogging::error(QString("exportProperty: Could not find result property : %1").arg(m_propertyName()));
return;
}
QString filePath = m_path;
if (filePath.isNull())
{
QDir propertiesDir(RicfCommandFileExecutor::instance()->getExportPath(RicfCommandFileExecutor::PROPERTIES));
QString fileName;
if (fullySpecified) fileName = QString("%1-T%2-%3").arg(eclipseCase->caseUserDescription()).arg(timeStepIndex).arg(propertyName);
else fileName = QString("%1-%2-T%3-%4").arg(eclipseCase->caseUserDescription()).arg(view->name()).arg(timeStepIndex).arg(propertyName);
QString fileName = QString("%1-%2").arg(eclipseCase->caseUserDescription()).arg(m_propertyName);
fileName = caf::Utils::makeValidFileBasename(fileName);
filePath = propertiesDir.filePath(fileName);
}
auto eclipseKeyword = m_eclipseKeyword();
if (m_eclipseKeyword().isNull())
QString eclipseKeyword = m_eclipseKeyword;
if (eclipseKeyword.isNull())
{
eclipseKeyword = propertyName;
eclipseKeyword = m_propertyName;
}
auto resultAccessor = findResult(view, timeStepIndex, propertyType, propertyName);
if (!resultAccessor.isNull())
{
RicEclipseCellResultToFileImpl::writeResultToTextFile(filePath, eclipseCase->eclipseCaseData(), resultAccessor.p(), eclipseKeyword, m_undefinedValue, "exportProperty");
}
else
{
RiaLogging::error(QString("exportProperty: Could not find property. Case ID %1, time step %2, property '%3'")
.arg(m_caseId).arg(timeStepIndex).arg(propertyName));
}
if (fullySpecified) break;
}
if (!anyViewsFound)
{
RiaLogging::error(QString("exportProperty: Could not find any views for case ID %1").arg(m_caseId()));
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
cvf::ref<RigResultAccessor> RicfExportProperty::findResult(RimEclipseView* view,
size_t timeStep,
RiaDefines::ResultCatType resultType,
const QString& property)
{
auto eclipseCase = view->eclipseCase();
size_t resultIndex = cvf::UNDEFINED_SIZE_T;
if (resultType == RiaDefines::UNDEFINED)
{
resultIndex = eclipseCase->results(RiaDefines::MATRIX_MODEL)->findOrLoadScalarResult(property);
}
else
{
resultIndex = eclipseCase->results(RiaDefines::MATRIX_MODEL)->findOrLoadScalarResult(resultType, property);
}
cvf::ref<RigResultAccessor> resultAccessor = nullptr;
if (resultIndex != cvf::UNDEFINED_SIZE_T)
{
resultAccessor = RigResultAccessorFactory::createFromResultIdx(eclipseCase->eclipseCaseData(),
0,
RiaDefines::MATRIX_MODEL,
timeStep,
resultIndex);
}
return resultAccessor;
RicEclipseCellResultToFileImpl::writePropertyToTextFile(
filePath, eclipseCase->eclipseCaseData(), m_timeStepIndex, m_propertyName, eclipseKeyword, m_undefinedValue);
}

View File

@ -26,12 +26,6 @@
#include "cafPdmField.h"
#include <cvfObject.h>
class RigResultAccessor;
class RimEclipseCase;
class RimEclipseView;
//==================================================================================================
//
//
@ -46,11 +40,6 @@ public:
virtual void execute() override;
cvf::ref<RigResultAccessor> findResult(RimEclipseView* view,
size_t timeStep,
RiaDefines::ResultCatType resultType,
const QString& property);
private:
caf::PdmField<int> m_caseId;
caf::PdmField<int> m_timeStepIndex;

View File

@ -38,7 +38,8 @@ bool RicEclipseCellResultToFileImpl::writePropertyToTextFile(const QString&
RigEclipseCaseData* eclipseCase,
size_t timeStep,
const QString& resultName,
const QString& eclipseKeyword)
const QString& eclipseKeyword,
const double undefinedValue)
{
CVF_TIGHT_ASSERT(eclipseCase);
if (!eclipseCase) return false;
@ -50,8 +51,6 @@ bool RicEclipseCellResultToFileImpl::writePropertyToTextFile(const QString&
return false;
}
const double undefinedValue = 0.0;
return writeResultToTextFile(
fileName, eclipseCase, resultAccessor.p(), eclipseKeyword, undefinedValue, "writePropertyToTextFile");
}

View File

@ -38,7 +38,8 @@ public:
RigEclipseCaseData* eclipseCase,
size_t timeStep,
const QString& resultName,
const QString& eclipseKeyword);
const QString& eclipseKeyword,
const double undefinedValue);
static bool writeBinaryResultToTextFile(const QString& fileName,
RigEclipseCaseData* eclipseCase,

View File

@ -105,7 +105,14 @@ void RicSaveEclipseInputPropertyFeature::onActionTriggered(bool isChecked)
if (propertyDialog.exec() == QDialog::Accepted)
{
bool isOk = RicEclipseCellResultToFileImpl::writePropertyToTextFile(exportSettings.fileName, inputReservoir->eclipseCaseData(), 0, inputProperty->resultName, exportSettings.eclipseKeyword);
const double undefinedValue = 0.0;
bool isOk = RicEclipseCellResultToFileImpl::writePropertyToTextFile(exportSettings.fileName,
inputReservoir->eclipseCaseData(),
0,
inputProperty->resultName,
exportSettings.eclipseKeyword,
undefinedValue);
if (isOk)
{
inputProperty->fileName = exportSettings.fileName;