mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
#1670 Add command feature "Export CARFIN"
This commit is contained in:
@@ -18,11 +18,23 @@
|
||||
|
||||
#include "RicExportCarfin.h"
|
||||
|
||||
#include "RimCase.h"
|
||||
#include "RiaLogging.h"
|
||||
|
||||
#include "RicCellRangeUi.h"
|
||||
#include "RicExportCarfinUi.h"
|
||||
#include "RicExportFeatureImpl.h"
|
||||
|
||||
#include "RifEclipseDataTableFormatter.h"
|
||||
|
||||
#include "RimEclipseCase.h"
|
||||
|
||||
#include "cafPdmUiPropertyViewDialog.h"
|
||||
#include "cafSelectionManager.h"
|
||||
|
||||
#include <QAction>
|
||||
#include <QFile>
|
||||
|
||||
CAF_CMD_SOURCE_INIT(RicExportCarfin, "RicExportCarfin");
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
@@ -42,9 +54,68 @@ bool RicExportCarfin::isCommandEnabled()
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RicExportCarfin::onActionTriggered(bool isChecked)
|
||||
{
|
||||
RimCase* rimCase = RicExportCarfin::selectedCase();
|
||||
RimEclipseCase* rimCase = RicExportCarfin::selectedCase();
|
||||
CVF_ASSERT(rimCase);
|
||||
|
||||
RicExportCarfinUi carfinUi;
|
||||
carfinUi.setCase(rimCase);
|
||||
|
||||
caf::PdmUiPropertyViewDialog propertyDialog(nullptr, &carfinUi, "Export CARFIN to Eclipse Data", "");
|
||||
RicExportFeatureImpl::configureForExport(&propertyDialog);
|
||||
|
||||
if (propertyDialog.exec() == QDialog::Accepted)
|
||||
{
|
||||
QString filePath = carfinUi.exportFileName();
|
||||
QFile exportFile(filePath);
|
||||
if (!exportFile.open(QIODevice::WriteOnly))
|
||||
{
|
||||
RiaLogging::error(QString("Export CARFIN: Could not open the file: %1").arg(filePath));
|
||||
return;
|
||||
}
|
||||
|
||||
QTextStream stream(&exportFile);
|
||||
RifEclipseDataTableFormatter formatter(stream);
|
||||
|
||||
std::vector<RifEclipseOutputTableColumn> header = {
|
||||
RifEclipseOutputTableColumn("I1"),
|
||||
RifEclipseOutputTableColumn("I2"),
|
||||
RifEclipseOutputTableColumn("J1"),
|
||||
RifEclipseOutputTableColumn("J2"),
|
||||
RifEclipseOutputTableColumn("K1"),
|
||||
RifEclipseOutputTableColumn("K2"),
|
||||
RifEclipseOutputTableColumn("NX"),
|
||||
RifEclipseOutputTableColumn("NY"),
|
||||
RifEclipseOutputTableColumn("NZ"),
|
||||
RifEclipseOutputTableColumn("NWMAX"),
|
||||
RifEclipseOutputTableColumn("Parent LGR")
|
||||
};
|
||||
|
||||
formatter.keyword("CARFIN");
|
||||
formatter.header(header);
|
||||
|
||||
formatter.add(carfinUi.cellRange()->start().i());
|
||||
formatter.add(carfinUi.cellRange()->start().i() + carfinUi.cellRange()->count().i());
|
||||
|
||||
formatter.add(carfinUi.cellRange()->start().j());
|
||||
formatter.add(carfinUi.cellRange()->start().j() + carfinUi.cellRange()->count().j());
|
||||
|
||||
formatter.add(carfinUi.cellRange()->start().k());
|
||||
formatter.add(carfinUi.cellRange()->start().k() + carfinUi.cellRange()->count().k());
|
||||
|
||||
formatter.add(carfinUi.lgrCellCount().i());
|
||||
formatter.add(carfinUi.lgrCellCount().j());
|
||||
formatter.add(carfinUi.lgrCellCount().k());
|
||||
|
||||
formatter.add(carfinUi.maxWellCount());
|
||||
|
||||
if (!carfinUi.gridName().isEmpty())
|
||||
{
|
||||
formatter.add(carfinUi.gridName());
|
||||
}
|
||||
|
||||
formatter.rowCompleted();
|
||||
formatter.tableCompleted();
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -59,9 +130,9 @@ void RicExportCarfin::setupActionLook(QAction* actionToSetup)
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RimCase* RicExportCarfin::selectedCase()
|
||||
RimEclipseCase* RicExportCarfin::selectedCase()
|
||||
{
|
||||
std::vector<RimCase*> selectedObjects;
|
||||
std::vector<RimEclipseCase*> selectedObjects;
|
||||
caf::SelectionManager::instance()->objectsByType(&selectedObjects);
|
||||
|
||||
if (selectedObjects.size() == 1)
|
||||
|
||||
Reference in New Issue
Block a user