#1670 Move commands to ExportCommands folder

This commit is contained in:
Magne Sjaastad
2017-06-28 14:36:32 +02:00
parent 468d5134cb
commit 15e805fba3
22 changed files with 41 additions and 21 deletions

View File

@@ -18,9 +18,6 @@ ${CEE_CURRENT_LIST_DIR}RicEclipsePropertyFilterNewFeature.h
${CEE_CURRENT_LIST_DIR}RicImportEclipseCaseFeature.h
${CEE_CURRENT_LIST_DIR}RicImportInputEclipseCaseFeature.h
${CEE_CURRENT_LIST_DIR}RicNewStatisticsCaseFeature.h
${CEE_CURRENT_LIST_DIR}RicSaveEclipseInputPropertyFeature.h
${CEE_CURRENT_LIST_DIR}RicSaveEclipseResultAsInputPropertyExec.h
${CEE_CURRENT_LIST_DIR}RicSaveEclipseResultAsInputPropertyFeature.h
${CEE_CURRENT_LIST_DIR}RicApplyPropertyFilterAsCellResultFeature.h
)
@@ -38,9 +35,6 @@ ${CEE_CURRENT_LIST_DIR}RicEclipsePropertyFilterNewFeature.cpp
${CEE_CURRENT_LIST_DIR}RicImportEclipseCaseFeature.cpp
${CEE_CURRENT_LIST_DIR}RicImportInputEclipseCaseFeature.cpp
${CEE_CURRENT_LIST_DIR}RicNewStatisticsCaseFeature.cpp
${CEE_CURRENT_LIST_DIR}RicSaveEclipseInputPropertyFeature.cpp
${CEE_CURRENT_LIST_DIR}RicSaveEclipseResultAsInputPropertyExec.cpp
${CEE_CURRENT_LIST_DIR}RicSaveEclipseResultAsInputPropertyFeature.cpp
${CEE_CURRENT_LIST_DIR}RicApplyPropertyFilterAsCellResultFeature.cpp
)

View File

@@ -1,140 +0,0 @@
/////////////////////////////////////////////////////////////////////////////////
//
// 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 "RicSaveEclipseInputPropertyFeature.h"
#include "RiaApplication.h"
#include "RicExportFeatureImpl.h"
#include "RifEclipseInputFileTools.h"
#include "RimEclipseInputCase.h"
#include "RimEclipseInputProperty.h"
#include "RimEclipseInputPropertyCollection.h"
#include "RimExportInputPropertySettings.h"
#include "RiuMainWindow.h"
#include "cafPdmUiPropertyViewDialog.h"
#include "cafSelectionManager.h"
#include <QAction>
#include <QFileInfo>
#include <QMessageBox>
CAF_CMD_SOURCE_INIT(RicSaveEclipseInputPropertyFeature, "RicSaveEclipseInputPropertyFeature");
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RicSaveEclipseInputPropertyFeature::isCommandEnabled()
{
return selectedInputProperty() != NULL;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicSaveEclipseInputPropertyFeature::onActionTriggered(bool isChecked)
{
this->disableModelChangeContribution();
RimEclipseInputProperty* inputProperty = selectedInputProperty();
if (!inputProperty) return;
{
bool isResolved = false;
if (inputProperty->resolvedState == RimEclipseInputProperty::RESOLVED || inputProperty->resolvedState == RimEclipseInputProperty::RESOLVED_NOT_SAVED)
{
isResolved = true;
}
if (!isResolved)
{
QMessageBox::warning(RiuMainWindow::instance(), "Export failure", "Property is not resolved, and then it is not possible to export the property.");
return;
}
}
RimExportInputSettings exportSettings;
exportSettings.eclipseKeyword = inputProperty->eclipseKeyword;
// Find input reservoir for this property
RimEclipseInputCase* inputReservoir = NULL;
{
RimEclipseInputPropertyCollection* inputPropertyCollection = dynamic_cast<RimEclipseInputPropertyCollection*>(inputProperty->parentField()->ownerObject());
if (!inputPropertyCollection) return;
inputReservoir = dynamic_cast<RimEclipseInputCase*>(inputPropertyCollection->parentField()->ownerObject());
}
if (!inputReservoir) return;
{
RiaApplication* app = RiaApplication::instance();
QString projectFolder = app->currentProjectPath();
if (projectFolder.isEmpty())
{
projectFolder = inputReservoir->locationOnDisc();
}
QString outputFileName = projectFolder + "/" + inputProperty->eclipseKeyword;
exportSettings.fileName = outputFileName;
}
caf::PdmUiPropertyViewDialog propertyDialog(RiuMainWindow::instance(), &exportSettings, "Export Eclipse Property to Text File", "");
RicExportFeatureImpl::configureForExport(&propertyDialog);
if (propertyDialog.exec() == QDialog::Accepted)
{
bool isOk = RifEclipseInputFileTools::writePropertyToTextFile(exportSettings.fileName, inputReservoir->eclipseCaseData(), 0, inputProperty->resultName, exportSettings.eclipseKeyword);
if (isOk)
{
inputProperty->fileName = exportSettings.fileName;
inputProperty->eclipseKeyword = exportSettings.eclipseKeyword;
inputProperty->resolvedState = RimEclipseInputProperty::RESOLVED;
inputProperty->updateConnectedEditors();
}
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicSaveEclipseInputPropertyFeature::setupActionLook(QAction* actionToSetup)
{
actionToSetup->setText("Export Property To File");
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimEclipseInputProperty* RicSaveEclipseInputPropertyFeature::selectedInputProperty() const
{
std::vector<RimEclipseInputProperty*> selection;
caf::SelectionManager::instance()->objectsByType(&selection);
return selection.size() > 0 ? selection[0] : NULL;
}

View File

@@ -1,43 +0,0 @@
/////////////////////////////////////////////////////////////////////////////////
//
// 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 "cafCmdFeature.h"
class RimEclipseInputProperty;
//==================================================================================================
///
//==================================================================================================
class RicSaveEclipseInputPropertyFeature : public caf::CmdFeature
{
CAF_CMD_HEADER_INIT;
protected:
// Overrides
virtual bool isCommandEnabled();
virtual void onActionTriggered( bool isChecked );
virtual void setupActionLook( QAction* actionToSetup );
private:
RimEclipseInputProperty* selectedInputProperty() const;
};

View File

@@ -1,116 +0,0 @@
/////////////////////////////////////////////////////////////////////////////////
//
// 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 "RicSaveEclipseResultAsInputPropertyExec.h"
#include "RiaApplication.h"
#include "RicExportFeatureImpl.h"
#include "RifEclipseInputFileTools.h"
#include "RifReaderInterface.h"
#include "RigCaseCellResultsData.h"
#include "RimBinaryExportSettings.h"
#include "RimEclipseCase.h"
#include "RimEclipseCellColors.h"
#include "RimEclipseView.h"
#include "RiuMainWindow.h"
#include "cafPdmUiPropertyViewDialog.h"
#include "cafUtils.h"
#include <QMessageBox>
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RicSaveEclipseResultAsInputPropertyExec::RicSaveEclipseResultAsInputPropertyExec(RimEclipseCellColors* cellColors)
: CmdExecuteCommand(NULL)
{
CVF_ASSERT(cellColors);
m_cellColors = cellColors;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RicSaveEclipseResultAsInputPropertyExec::~RicSaveEclipseResultAsInputPropertyExec()
{
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QString RicSaveEclipseResultAsInputPropertyExec::name()
{
return "Export Property To File";
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicSaveEclipseResultAsInputPropertyExec::redo()
{
CVF_ASSERT(m_cellColors);
if (!m_cellColors->reservoirView()) return;
if (!m_cellColors->reservoirView()->eclipseCase()) return;
if (!m_cellColors->reservoirView()->eclipseCase()->eclipseCaseData()) return;
RimBinaryExportSettings exportSettings;
exportSettings.eclipseKeyword = m_cellColors->resultVariable();
{
RiaApplication* app = RiaApplication::instance();
QString projectFolder = app->currentProjectPath();
if (projectFolder.isEmpty())
{
projectFolder = m_cellColors->reservoirView()->eclipseCase()->locationOnDisc();
}
QString outputFileName = projectFolder + "/" + caf::Utils::makeValidFileBasename( m_cellColors->resultVariableUiShortName());
exportSettings.fileName = outputFileName;
}
caf::PdmUiPropertyViewDialog propertyDialog(RiuMainWindow::instance(), &exportSettings, "Export Binary Eclipse Data to Text File", "");
RicExportFeatureImpl::configureForExport(&propertyDialog);
if (propertyDialog.exec() == QDialog::Accepted)
{
size_t timeStep = m_cellColors->reservoirView()->currentTimeStep();
bool isOk = RifEclipseInputFileTools::writeBinaryResultToTextFile(exportSettings.fileName, m_cellColors->reservoirView()->eclipseCase()->eclipseCaseData(), timeStep, m_cellColors, exportSettings.eclipseKeyword, exportSettings.undefinedValue);
if (!isOk)
{
QMessageBox::critical(NULL, "File export", "Failed to exported current result to " + exportSettings.fileName);
}
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicSaveEclipseResultAsInputPropertyExec::undo()
{
// TODO
CVF_ASSERT(0);
}

View File

@@ -1,43 +0,0 @@
/////////////////////////////////////////////////////////////////////////////////
//
// 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 RicSaveEclipseResultAsInputPropertyExec : public caf::CmdExecuteCommand
{
public:
explicit RicSaveEclipseResultAsInputPropertyExec(RimEclipseCellColors* cellColors);
virtual ~RicSaveEclipseResultAsInputPropertyExec();
virtual QString name();
virtual void redo();
virtual void undo();
private:
caf::PdmPointer<RimEclipseCellColors> m_cellColors;
};

View File

@@ -1,69 +0,0 @@
/////////////////////////////////////////////////////////////////////////////////
//
// 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 "RicSaveEclipseResultAsInputPropertyFeature.h"
#include "RicSaveEclipseResultAsInputPropertyExec.h"
#include "RimEclipseCellColors.h"
#include "RimView.h"
#include "cafSelectionManager.h"
#include "cafCmdExecCommandManager.h"
#include <QAction>
CAF_CMD_SOURCE_INIT(RicSaveEclipseResultAsInputPropertyFeature, "RicSaveEclipseResultAsInputPropertyFeature");
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RicSaveEclipseResultAsInputPropertyFeature::isCommandEnabled()
{
std::vector<RimEclipseCellColors*> selection;
caf::SelectionManager::instance()->objectsByType(&selection);
return selection.size() == 1;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicSaveEclipseResultAsInputPropertyFeature::onActionTriggered(bool isChecked)
{
this->disableModelChangeContribution();
std::vector<RimEclipseCellColors*> selection;
caf::SelectionManager::instance()->objectsByType(&selection);
if (selection.size() == 1)
{
RicSaveEclipseResultAsInputPropertyExec* cellResultSaveExec = new RicSaveEclipseResultAsInputPropertyExec(selection[0]);
caf::CmdExecCommandManager::instance()->processExecuteCommand(cellResultSaveExec);
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicSaveEclipseResultAsInputPropertyFeature::setupActionLook(QAction* actionToSetup)
{
actionToSetup->setText("Export Property To File");
}

View File

@@ -1,39 +0,0 @@
/////////////////////////////////////////////////////////////////////////////////
//
// 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 "cafCmdFeature.h"
//==================================================================================================
///
//==================================================================================================
class RicSaveEclipseResultAsInputPropertyFeature : public caf::CmdFeature
{
CAF_CMD_HEADER_INIT;
protected:
// Overrides
virtual bool isCommandEnabled();
virtual void onActionTriggered( bool isChecked );
virtual void setupActionLook( QAction* actionToSetup );
};