mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
#3484 Export Properties : Add new file command for export of properties in all views
This commit is contained in:
@@ -23,6 +23,7 @@ ${CMAKE_CURRENT_LIST_DIR}/RicfSetFractureContainment.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RicfCreateMultipleFractures.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RicfExportWellPaths.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RicfExportVisibleCells.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RicfExportPropertyInViews.h
|
||||
)
|
||||
|
||||
set (SOURCE_GROUP_SOURCE_FILES
|
||||
@@ -49,6 +50,7 @@ ${CMAKE_CURRENT_LIST_DIR}/RicfSetFractureContainment.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RicfCreateMultipleFractures.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RicfExportWellPaths.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RicfExportVisibleCells.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RicfExportPropertyInViews.cpp
|
||||
)
|
||||
|
||||
list(APPEND CODE_HEADER_FILES
|
||||
|
||||
@@ -0,0 +1,149 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2018 Equinor ASA
|
||||
//
|
||||
// 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 "RicfExportProperty.h"
|
||||
|
||||
#include "../Commands/ExportCommands/RicEclipseCellResultToFileImpl.h"
|
||||
|
||||
#include "RiaApplication.h"
|
||||
#include "RiaLogging.h"
|
||||
|
||||
#include "RicfCommandFileExecutor.h"
|
||||
#include "RicfExportPropertyInViews.h"
|
||||
|
||||
#include "RigResultAccessorFactory.h"
|
||||
|
||||
#include "RimEclipseCase.h"
|
||||
#include "RimEclipseCellColors.h"
|
||||
#include "RimEclipseView.h"
|
||||
#include "RimProject.h"
|
||||
|
||||
#include "cafUtils.h"
|
||||
|
||||
#include <limits>
|
||||
|
||||
#include <QDir>
|
||||
|
||||
CAF_PDM_SOURCE_INIT(RicfExportPropertyInViews, "exportPropertyInViews");
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RicfExportPropertyInViews::RicfExportPropertyInViews()
|
||||
{
|
||||
RICF_InitField(&m_caseId, "caseId", -1, "Case ID", "", "", "");
|
||||
RICF_InitField(&m_viewNames, "viewNames", std::vector<QString>(), "View Names", "", "", "");
|
||||
RICF_InitField(&m_undefinedValue, "undefinedValue", 0.0, "Undefined Value", "", "", "");
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RicfExportPropertyInViews::execute()
|
||||
{
|
||||
RimEclipseCase* eclipseCase = nullptr;
|
||||
{
|
||||
std::vector<RimCase*> cases;
|
||||
RiaApplication::instance()->project()->allCases(cases);
|
||||
|
||||
for (auto* c : cases)
|
||||
{
|
||||
RimEclipseCase* eclCase = dynamic_cast<RimEclipseCase*>(c);
|
||||
if (eclCase->caseId == m_caseId)
|
||||
{
|
||||
eclipseCase = eclCase;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!eclipseCase)
|
||||
{
|
||||
RiaLogging::error(QString("exportProperty: Could not find case with ID %1").arg(m_caseId()));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<RimEclipseView*> viewsForExport;
|
||||
|
||||
for (Rim3dView* v : eclipseCase->views())
|
||||
{
|
||||
RimEclipseView* view = dynamic_cast<RimEclipseView*>(v);
|
||||
if (!view) continue;
|
||||
|
||||
if (m_viewNames().empty())
|
||||
{
|
||||
viewsForExport.push_back(view);
|
||||
}
|
||||
else
|
||||
{
|
||||
bool matchingName = false;
|
||||
for (const auto& viewName : m_viewNames())
|
||||
{
|
||||
if (view->name().compare(viewName, Qt::CaseInsensitive) == 0)
|
||||
{
|
||||
matchingName = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (matchingName)
|
||||
{
|
||||
viewsForExport.push_back(view);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (const auto& view : viewsForExport)
|
||||
{
|
||||
cvf::ref<RigResultAccessor> resultAccessor = nullptr;
|
||||
{
|
||||
const int mainGridIndex = 0;
|
||||
|
||||
resultAccessor = RigResultAccessorFactory::createFromResultDefinition(
|
||||
eclipseCase->eclipseCaseData(), mainGridIndex, view->currentTimeStep(), view->cellResult());
|
||||
}
|
||||
|
||||
const QString propertyName = view->cellResult()->resultVariableUiShortName();
|
||||
|
||||
if (resultAccessor.isNull())
|
||||
{
|
||||
RiaLogging::error(QString("exportProperty: Could not find property. Case ID %1, time step %2, property '%3'")
|
||||
.arg(m_caseId)
|
||||
.arg(view->currentTimeStep())
|
||||
.arg(propertyName));
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
QDir propertiesDir(RicfCommandFileExecutor::instance()->getExportPath(RicfCommandFileExecutor::PROPERTIES));
|
||||
|
||||
QString fileName = QString("%1-%2-T%3-%4")
|
||||
.arg(eclipseCase->caseUserDescription())
|
||||
.arg(view->name())
|
||||
.arg(view->currentTimeStep())
|
||||
.arg(propertyName);
|
||||
|
||||
fileName = caf::Utils::makeValidFileBasename(fileName);
|
||||
const QString filePath = propertiesDir.filePath(fileName);
|
||||
|
||||
RicEclipseCellResultToFileImpl::writeResultToTextFile(filePath,
|
||||
eclipseCase->eclipseCaseData(),
|
||||
resultAccessor.p(),
|
||||
propertyName,
|
||||
m_undefinedValue,
|
||||
"exportPropertiesInViews");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2018 Equinor ASA
|
||||
//
|
||||
// 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 "RiaDefines.h"
|
||||
|
||||
#include "RicfCommandObject.h"
|
||||
|
||||
#include "cafPdmField.h"
|
||||
|
||||
#include <QString>
|
||||
|
||||
#include <vector>
|
||||
|
||||
//==================================================================================================
|
||||
//
|
||||
//
|
||||
//
|
||||
//==================================================================================================
|
||||
class RicfExportPropertyInViews : public RicfCommandObject
|
||||
{
|
||||
CAF_PDM_HEADER_INIT;
|
||||
|
||||
public:
|
||||
RicfExportPropertyInViews();
|
||||
|
||||
virtual void execute() override;
|
||||
|
||||
private:
|
||||
caf::PdmField<int> m_caseId;
|
||||
caf::PdmField<std::vector<QString>> m_viewNames;
|
||||
caf::PdmField<double> m_undefinedValue;
|
||||
};
|
||||
Reference in New Issue
Block a user