Added command exec class for saving of Eclipse result as input property

This commit is contained in:
Pål Hagen 2015-08-11 13:45:00 +02:00
parent 85a76f591f
commit 41d321b8b8
4 changed files with 179 additions and 9 deletions

View File

@ -12,7 +12,9 @@ ${CEE_CURRENT_LIST_DIR}RicEclipseCaseNewGroup.h
${CEE_CURRENT_LIST_DIR}RicEclipseCaseNewView.h
${CEE_CURRENT_LIST_DIR}RicEclipseCasePaste.h
${CEE_CURRENT_LIST_DIR}RicEclipseCellResultSave.h
${CEE_CURRENT_LIST_DIR}RicEclipseCellResultSaveExec.h
${CEE_CURRENT_LIST_DIR}RicEclipseFaultResultSave.h
${CEE_CURRENT_LIST_DIR}RicEclipseFaultResultSaveExec.h
${CEE_CURRENT_LIST_DIR}RicEclipsePropertyFilter.h
${CEE_CURRENT_LIST_DIR}RicEclipsePropertyFilterDelete.h
${CEE_CURRENT_LIST_DIR}RicEclipsePropertyFilterDeleteExec.h
@ -46,7 +48,9 @@ ${CEE_CURRENT_LIST_DIR}RicEclipseCaseNewGroup.cpp
${CEE_CURRENT_LIST_DIR}RicEclipseCaseNewView.cpp
${CEE_CURRENT_LIST_DIR}RicEclipseCasePaste.cpp
${CEE_CURRENT_LIST_DIR}RicEclipseCellResultSave.cpp
${CEE_CURRENT_LIST_DIR}RicEclipseCellResultSaveExec.cpp
${CEE_CURRENT_LIST_DIR}RicEclipseFaultResultSave.cpp
${CEE_CURRENT_LIST_DIR}RicEclipseFaultResultSaveExec.cpp
${CEE_CURRENT_LIST_DIR}RicEclipsePropertyFilter.cpp
${CEE_CURRENT_LIST_DIR}RicEclipsePropertyFilterDelete.cpp
${CEE_CURRENT_LIST_DIR}RicEclipsePropertyFilterDeleteExec.cpp

View File

@ -19,10 +19,13 @@
#include "RicEclipseCellResultSave.h"
#include "RimView.h"
#include "RicEclipseCellResultSaveExec.h"
#include "RimEclipseCellColors.h"
#include "RimView.h"
#include "cafSelectionManager.h"
#include "cafCmdExecCommandManager.h"
#include <QAction>
@ -36,14 +39,7 @@ bool RicEclipseCellResultSave::isCommandEnabled()
std::vector<RimEclipseCellColors*> selection;
caf::SelectionManager::instance()->objectsByType(&selection);
if (selection.size() > 0)
{
return true;
}
else
{
return false;
}
return selection.size() == 1;
}
//--------------------------------------------------------------------------------------------------
@ -51,6 +47,13 @@ bool RicEclipseCellResultSave::isCommandEnabled()
//--------------------------------------------------------------------------------------------------
void RicEclipseCellResultSave::onActionTriggered(bool isChecked)
{
std::vector<RimEclipseCellColors*> selection;
caf::SelectionManager::instance()->objectsByType(&selection);
if (selection.size() == 1)
{
RicEclipseCellResultSaveExec* cellResultSaveExec = new RicEclipseCellResultSaveExec(selection[0]);
caf::CmdExecCommandManager::instance()->processExecuteCommand(cellResultSaveExec);
}
}
//--------------------------------------------------------------------------------------------------

View File

@ -0,0 +1,120 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2015- Statoil ASA
// Copyright (C) 2015- 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 "RicEclipseCellResultSaveExec.h"
#include "RimEclipseCellColors.h"
#include "RimBinaryExportSettings.h"
#include "RimEclipseView.h"
#include "RimEclipseCase.h"
#include "RigCaseData.h"
#include "RigCaseCellResultsData.h"
#include "RifEclipseInputFileTools.h"
#include "RifReaderInterface.h"
#include "RiaApplication.h"
#include "RiuMainWindow.h"
#include "cafPdmUiPropertyViewDialog.h"
#include <QFileInfo>
#include <QMessageBox>
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RicEclipseCellResultSaveExec::RicEclipseCellResultSaveExec(RimEclipseCellColors* cellColors)
: CmdExecuteCommand(NULL)
{
CVF_ASSERT(cellColors);
m_cellColors = cellColors;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RicEclipseCellResultSaveExec::~RicEclipseCellResultSaveExec()
{
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QString RicEclipseCellResultSaveExec::name()
{
return "Save Property To File";
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicEclipseCellResultSaveExec::redo()
{
CVF_ASSERT(m_cellColors);
if (!m_cellColors->reservoirView()) return;
if (!m_cellColors->reservoirView()->eclipseCase()) return;
if (!m_cellColors->reservoirView()->eclipseCase()->reservoirData()) return;
RimBinaryExportSettings exportSettings;
exportSettings.eclipseKeyword = m_cellColors->resultVariable();
{
QString projectFolder;
RiaApplication* app = RiaApplication::instance();
QString projectFileName = app->currentProjectFileName();
if (!projectFileName.isEmpty())
{
QFileInfo fi(projectFileName);
projectFolder = fi.absolutePath();
}
else
{
projectFolder = m_cellColors->reservoirView()->eclipseCase()->locationOnDisc();
}
QString outputFileName = projectFolder + "/" + m_cellColors->resultVariable();
exportSettings.fileName = outputFileName;
}
caf::PdmUiPropertyViewDialog propertyDialog(RiuMainWindow::instance(), &exportSettings, "Export Binary Eclipse Data to Text File", "");
if (propertyDialog.exec() == QDialog::Accepted)
{
size_t timeStep = m_cellColors->reservoirView()->currentTimeStep();
RifReaderInterface::PorosityModelResultType porosityModel = RigCaseCellResultsData::convertFromProjectModelPorosityModel(m_cellColors->porosityModel());
bool isOk = RifEclipseInputFileTools::writeBinaryResultToTextFile(exportSettings.fileName, m_cellColors->reservoirView()->eclipseCase()->reservoirData(), porosityModel, timeStep, m_cellColors->resultVariable(), exportSettings.eclipseKeyword, exportSettings.undefinedValue);
if (!isOk)
{
QMessageBox::critical(NULL, "File export", "Failed to exported current result to " + exportSettings.fileName);
}
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicEclipseCellResultSaveExec::undo()
{
// TODO
CVF_ASSERT(0);
}

View File

@ -0,0 +1,43 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2015- Statoil ASA
// Copyright (C) 2015- 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.
//
/////////////////////////////////////////////////////////////////////////////////
#pragma once
#include "cafCmdExecuteCommand.h"
#include "cafPdmPointer.h"
class RimEclipseCellColors;
//==================================================================================================
///
//==================================================================================================
class RicEclipseCellResultSaveExec : public caf::CmdExecuteCommand
{
public:
RicEclipseCellResultSaveExec(RimEclipseCellColors* cellColors);
virtual ~RicEclipseCellResultSaveExec();
virtual QString name();
virtual void redo();
virtual void undo();
private:
caf::PdmPointer<RimEclipseCellColors> m_cellColors;
};