#4429 Implement return status handling for command file interface

This commit is contained in:
Gaute Lindkvist
2019-05-23 16:47:02 +02:00
parent e29c7acc03
commit 650af20e06
61 changed files with 639 additions and 276 deletions
@@ -1,6 +1,7 @@
set (SOURCE_GROUP_HEADER_FILES set (SOURCE_GROUP_HEADER_FILES
${CMAKE_CURRENT_LIST_DIR}/RicfCommandObject.h ${CMAKE_CURRENT_LIST_DIR}/RicfCommandObject.h
${CMAKE_CURRENT_LIST_DIR}/RicfCommandResponse.h
${CMAKE_CURRENT_LIST_DIR}/RicfFieldCapability.h ${CMAKE_CURRENT_LIST_DIR}/RicfFieldCapability.h
${CMAKE_CURRENT_LIST_DIR}/RicfFieldHandle.h ${CMAKE_CURRENT_LIST_DIR}/RicfFieldHandle.h
${CMAKE_CURRENT_LIST_DIR}/RicfObjectCapability.h ${CMAKE_CURRENT_LIST_DIR}/RicfObjectCapability.h
@@ -10,6 +11,7 @@ ${CMAKE_CURRENT_LIST_DIR}/RicfMessages.h
set (SOURCE_GROUP_SOURCE_FILES set (SOURCE_GROUP_SOURCE_FILES
${CMAKE_CURRENT_LIST_DIR}/RicfCommandObject.cpp ${CMAKE_CURRENT_LIST_DIR}/RicfCommandObject.cpp
${CMAKE_CURRENT_LIST_DIR}/RicfCommandResponse.cpp
${CMAKE_CURRENT_LIST_DIR}/RicfFieldCapability.cpp ${CMAKE_CURRENT_LIST_DIR}/RicfFieldCapability.cpp
${CMAKE_CURRENT_LIST_DIR}/RicfFieldHandle.cpp ${CMAKE_CURRENT_LIST_DIR}/RicfFieldHandle.cpp
${CMAKE_CURRENT_LIST_DIR}/RicfObjectCapability.cpp ${CMAKE_CURRENT_LIST_DIR}/RicfObjectCapability.cpp
@@ -20,6 +20,7 @@
#include "cafPdmObject.h" #include "cafPdmObject.h"
#include "RicfObjectCapability.h" #include "RicfObjectCapability.h"
#include "RicfFieldCapability.h" #include "RicfFieldCapability.h"
#include "RicfCommandResponse.h"
#define RICF_InitField(field, keyword, default, uiName, iconResourceName, toolTip, whatsThis) \ #define RICF_InitField(field, keyword, default, uiName, iconResourceName, toolTip, whatsThis) \
CAF_PDM_InitField(field, keyword, default, uiName, iconResourceName, toolTip, whatsThis); \ CAF_PDM_InitField(field, keyword, default, uiName, iconResourceName, toolTip, whatsThis); \
@@ -37,7 +38,7 @@ public:
RicfCommandObject(); RicfCommandObject();
~RicfCommandObject() override; ~RicfCommandObject() override;
virtual void execute() = 0; virtual RicfCommandResponse execute() = 0;
}; };
@@ -0,0 +1,86 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2019- 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 "RicfCommandResponse.h"
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RicfCommandResponse::RicfCommandResponse(Status status, const QString& message)
{
updateStatus(status, message);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RicfCommandResponse::Status RicfCommandResponse::status() const
{
return m_status;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QString RicfCommandResponse::message() const
{
return m_messages.join("\n");
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
caf::PdmObject* RicfCommandResponse::result() const
{
return m_result.p();
}
//--------------------------------------------------------------------------------------------------
/// Takes ownership of the result object
//--------------------------------------------------------------------------------------------------
void RicfCommandResponse::setResult(caf::PdmObject* result)
{
m_result = result;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicfCommandResponse::updateStatus(Status status, const QString& message)
{
m_status = std::max(m_status, status);
if (!message.isEmpty())
m_messages.push_back(QString("%1:%2").arg(statusLabel(status)).arg(message));
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QString RicfCommandResponse::statusLabel(Status status)
{
switch (status)
{
case COMMAND_WARNING:
return "WARNING";
case COMMAND_ERROR:
return "ERROR";
default:
return "";
}
}
@@ -0,0 +1,59 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2019- 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 "cafPdmObject.h"
#include "cafPdmPointer.h"
#include <QString>
#include <QStringList>
#include <memory>
//==================================================================================================
//
// Command response which contains status and possibly a result
//
//==================================================================================================
class RicfCommandResponse
{
public:
// Status in order of severity from ok to critical
enum Status
{
COMMAND_OK,
COMMAND_WARNING,
COMMAND_ERROR
};
public:
RicfCommandResponse(Status status = COMMAND_OK, const QString& message="");
Status status() const;
QString message() const;
caf::PdmObject* result() const;
void setResult(caf::PdmObject* result);
void updateStatus(Status status, const QString& message);
private:
static QString statusLabel(Status status);
private:
Status m_status;
QStringList m_messages;
caf::PdmPointer<caf::PdmObject> m_result;
};
@@ -32,7 +32,8 @@ RicfCloseProject::RicfCloseProject()
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
void RicfCloseProject::execute() RicfCommandResponse RicfCloseProject::execute()
{ {
RiaApplication::instance()->closeProject(); RiaApplication::instance()->closeProject();
return RicfCommandResponse();
} }
@@ -34,7 +34,7 @@ class RicfCloseProject : public RicfCommandObject
public: public:
RicfCloseProject(); RicfCloseProject();
void execute() override; RicfCommandResponse execute() override;
private: private:
}; };
@@ -43,8 +43,10 @@ RicfComputeCaseGroupStatistics::RicfComputeCaseGroupStatistics()
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
void RicfComputeCaseGroupStatistics::execute() RicfCommandResponse RicfComputeCaseGroupStatistics::execute()
{ {
RicfCommandResponse response;
for (int caseId : m_caseIds()) for (int caseId : m_caseIds())
{ {
bool foundCase = false; bool foundCase = false;
@@ -61,7 +63,9 @@ void RicfComputeCaseGroupStatistics::execute()
} }
else else
{ {
RiaLogging::warning(QString("computeCaseGroupStatistics: Found case with ID %1, but it is not a statistics case, cannot compute statistics.").arg(caseId)); QString warning = QString("computeCaseGroupStatistics: Found case with ID %1, but it is not a statistics case, cannot compute statistics.").arg(caseId);
RiaLogging::warning(warning);
response.updateStatus(RicfCommandResponse::COMMAND_WARNING, warning);
} }
foundCase = true; foundCase = true;
break; break;
@@ -73,7 +77,11 @@ void RicfComputeCaseGroupStatistics::execute()
if (!foundCase) if (!foundCase)
{ {
RiaLogging::warning(QString("computeCaseGroupStatistics: Could not find statistics case with ID %1.").arg(caseId)); QString warning = QString("computeCaseGroupStatistics: Could not find statistics case with ID %1.").arg(caseId);
RiaLogging::warning(warning);
response.updateStatus(RicfCommandResponse::COMMAND_WARNING, warning);
} }
} }
return response;
} }
@@ -34,7 +34,7 @@ class RicfComputeCaseGroupStatistics : public RicfCommandObject
public: public:
RicfComputeCaseGroupStatistics(); RicfComputeCaseGroupStatistics();
void execute() override; RicfCommandResponse execute() override;
private: private:
caf::PdmField< std::vector<int> > m_caseIds; caf::PdmField< std::vector<int> > m_caseIds;
@@ -59,7 +59,7 @@ RicfCreateLgrForCompletions::RicfCreateLgrForCompletions()
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
void RicfCreateLgrForCompletions::execute() RicfCommandResponse RicfCreateLgrForCompletions::execute()
{ {
using TOOLS = RicfApplicationTools; using TOOLS = RicfApplicationTools;
@@ -71,12 +71,19 @@ void RicfCreateLgrForCompletions::execute()
wellPaths = TOOLS::wellPathsFromNames(TOOLS::toQStringList(m_wellPathNames), &wellsNotFound); wellPaths = TOOLS::wellPathsFromNames(TOOLS::toQStringList(m_wellPathNames), &wellsNotFound);
if (!wellsNotFound.empty()) if (!wellsNotFound.empty())
{ {
RiaLogging::error(QString("createLgrForCompletions: These well paths were not found: ") + wellsNotFound.join(", ")); QString error = QString("createLgrForCompletions: These well paths were not found: ") + wellsNotFound.join(", ");
RiaLogging::error(error);
return RicfCommandResponse(RicfCommandResponse::COMMAND_ERROR, error);
} }
} }
if (!wellPaths.empty()) if (wellPaths.empty())
{ {
QString error("No well paths found");
RiaLogging::error(error);
return RicfCommandResponse(RicfCommandResponse::COMMAND_ERROR, error);
}
caf::CmdFeatureManager* commandManager = caf::CmdFeatureManager::instance(); caf::CmdFeatureManager* commandManager = caf::CmdFeatureManager::instance();
auto feature = dynamic_cast<RicCreateTemporaryLgrFeature*>(commandManager->getCommandFeature("RicCreateTemporaryLgrFeature")); auto feature = dynamic_cast<RicCreateTemporaryLgrFeature*>(commandManager->getCommandFeature("RicCreateTemporaryLgrFeature"));
@@ -92,8 +99,9 @@ void RicfCreateLgrForCompletions::execute()
} }
if (!eclipseCase) if (!eclipseCase)
{ {
RiaLogging::error(QString("createLgrForCompletions: Could not find case with ID %1").arg(m_caseId())); QString error(QString("createLgrForCompletions: Could not find case with ID %1").arg(m_caseId()));
return; RiaLogging::error(error);
return RicfCommandResponse(RicfCommandResponse::COMMAND_ERROR, error);
} }
} }
@@ -113,12 +121,15 @@ void RicfCreateLgrForCompletions::execute()
feature->updateViews(eclipseCase); feature->updateViews(eclipseCase);
RicfCommandResponse response;
if (!wellsIntersectingOtherLgrs.empty()) if (!wellsIntersectingOtherLgrs.empty())
{ {
auto wellsList = wellsIntersectingOtherLgrs.join(", "); auto wellsList = wellsIntersectingOtherLgrs.join(", ");
RiaLogging::error( QString warning(
"createLgrForCompletions: No LGRs created for some wells due to existing intersecting LGR(s).Affected wells : " + "createLgrForCompletions: No LGRs created for some wells due to existing intersecting LGR(s).Affected wells : " +
wellsList); wellsList);
RiaLogging::warning(warning);
response.updateStatus(RicfCommandResponse::COMMAND_WARNING, warning);
} }
} return response;
} }
@@ -39,7 +39,7 @@ class RicfCreateLgrForCompletions : public RicfCommandObject
public: public:
RicfCreateLgrForCompletions(); RicfCreateLgrForCompletions();
void execute() override; RicfCommandResponse execute() override;
private: private:
caf::PdmField<int> m_caseId; caf::PdmField<int> m_caseId;
@@ -74,7 +74,7 @@ RicfCreateMultipleFractures::RicfCreateMultipleFractures()
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
void RicfCreateMultipleFractures::execute() RicfCommandResponse RicfCreateMultipleFractures::execute()
{ {
using TOOLS = RicfApplicationTools; using TOOLS = RicfApplicationTools;
@@ -92,22 +92,40 @@ void RicfCreateMultipleFractures::execute()
wellPaths = TOOLS::wellPathsFromNames(TOOLS::toQStringList(m_wellPathNames), &wellsNotFound); wellPaths = TOOLS::wellPathsFromNames(TOOLS::toQStringList(m_wellPathNames), &wellsNotFound);
if (!wellsNotFound.empty()) if (!wellsNotFound.empty())
{ {
RiaLogging::error(QString("createMultipleFractures: These well paths were not found: ") + wellsNotFound.join(", ")); QString error = QString("createMultipleFractures: These well paths were not found: %1").arg(wellsNotFound.join(", "));
RiaLogging::error(error);
return RicfCommandResponse(RicfCommandResponse::COMMAND_ERROR, error);
} }
} }
if (!gridCase) if (!gridCase)
{ {
RiaLogging::error(QString("createMultipleFractures: Could not find case with ID %1").arg(m_caseId)); QString error = QString("createMultipleFractures: Could not find case with ID %1").arg(m_caseId);
RiaLogging::error(error);
return RicfCommandResponse(RicfCommandResponse::COMMAND_ERROR, error);
} }
if (!fractureTemplate) if (!fractureTemplate)
{ {
RiaLogging::error(QString("createMultipleFractures: Could not find fracture template with ID %1").arg(m_templateId)); QString error = QString("createMultipleFractures: Could not find fracture template with ID %1").arg(m_templateId);
RiaLogging::error(error);
return RicfCommandResponse(RicfCommandResponse::COMMAND_ERROR, error);
} }
if (gridCase && fractureTemplate && !wellPaths.empty() && validateArguments()) if (wellPaths.empty())
{ {
QString error("createMultipleFractures: No wellpaths found");
RiaLogging::error(error);
return RicfCommandResponse(RicfCommandResponse::COMMAND_ERROR, error);
}
if (!validateArguments())
{
QString error("createMultipleFractures: Mandatory argument(s) missing");
RiaLogging::error(error);
return RicfCommandResponse(RicfCommandResponse::COMMAND_ERROR, error);
}
RicCreateMultipleFracturesOptionItemUi* options = new RicCreateMultipleFracturesOptionItemUi(); RicCreateMultipleFracturesOptionItemUi* options = new RicCreateMultipleFracturesOptionItemUi();
caf::CmdFeatureManager* commandManager = caf::CmdFeatureManager::instance(); caf::CmdFeatureManager* commandManager = caf::CmdFeatureManager::instance();
auto feature = dynamic_cast<RicCreateMultipleFracturesFeature*>(commandManager->getCommandFeature("RicCreateMultipleFracturesFeature")); auto feature = dynamic_cast<RicCreateMultipleFracturesFeature*>(commandManager->getCommandFeature("RicCreateMultipleFracturesFeature"));
@@ -133,13 +151,12 @@ void RicfCreateMultipleFractures::execute()
settings->clearOptions(); settings->clearOptions();
settings->insertOptionItem(nullptr, options); settings->insertOptionItem(nullptr, options);
if (feature) if (feature)
{ {
if (m_action == MultipleFractures::APPEND_FRACTURES) feature->appendFractures(); if (m_action == MultipleFractures::APPEND_FRACTURES) feature->appendFractures();
if (m_action == MultipleFractures::REPLACE_FRACTURES) feature->replaceFractures(); if (m_action == MultipleFractures::REPLACE_FRACTURES) feature->replaceFractures();
} }
} return RicfCommandResponse();
} }
@@ -154,7 +171,6 @@ bool RicfCreateMultipleFractures::validateArguments() const
if (valid) return true; if (valid) return true;
RiaLogging::error(QString("createMultipleFractures: Mandatory argument(s) missing"));
return false; return false;
} }
@@ -49,7 +49,7 @@ class RicfCreateMultipleFractures : public RicfCommandObject
public: public:
RicfCreateMultipleFractures(); RicfCreateMultipleFractures();
void execute() override; RicfCommandResponse execute() override;
private: private:
bool validateArguments() const; bool validateArguments() const;
@@ -42,7 +42,7 @@ RicfCreateSaturationPressurePlots::RicfCreateSaturationPressurePlots()
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
void RicfCreateSaturationPressurePlots::execute() RicfCommandResponse RicfCreateSaturationPressurePlots::execute()
{ {
std::vector<int> caseIds = m_caseIds(); std::vector<int> caseIds = m_caseIds();
if (caseIds.empty()) if (caseIds.empty())
@@ -58,9 +58,21 @@ void RicfCreateSaturationPressurePlots::execute()
} }
} }
RimProject* project = RiaApplication::instance()->project(); if (caseIds.empty())
if (project)
{ {
QString error("createSaturationPressurePlots: No cases found");
RiaLogging::error(error);
return RicfCommandResponse(RicfCommandResponse::COMMAND_ERROR, error);
}
RimProject* project = RiaApplication::instance()->project();
if (!project)
{
QString error("No project loaded");
RiaLogging::error(error);
return RicfCommandResponse(RicfCommandResponse::COMMAND_ERROR, error);
}
auto eclipeCases = project->eclipseCases(); auto eclipeCases = project->eclipseCases();
for (auto c : eclipeCases) for (auto c : eclipeCases)
{ {
@@ -75,9 +87,10 @@ void RicfCreateSaturationPressurePlots::execute()
} }
} }
} }
}
RimSaturationPressurePlotCollection* collection = project->mainPlotCollection()->saturationPressurePlotCollection(); RimSaturationPressurePlotCollection* collection = project->mainPlotCollection()->saturationPressurePlotCollection();
collection->updateAllRequiredEditors(); collection->updateAllRequiredEditors();
RiaGuiApplication::instance()->getOrCreateAndShowMainPlotWindow(); RiaGuiApplication::instance()->getOrCreateAndShowMainPlotWindow();
return RicfCommandResponse();
} }
@@ -34,7 +34,7 @@ class RicfCreateSaturationPressurePlots : public RicfCommandObject
public: public:
RicfCreateSaturationPressurePlots(); RicfCreateSaturationPressurePlots();
void execute() override; RicfCommandResponse execute() override;
private: private:
caf::PdmField< std::vector<int> > m_caseIds; caf::PdmField< std::vector<int> > m_caseIds;
@@ -59,7 +59,7 @@ RicfExportLgrForCompletions::RicfExportLgrForCompletions()
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
void RicfExportLgrForCompletions::execute() RicfCommandResponse RicfExportLgrForCompletions::execute()
{ {
using TOOLS = RicfApplicationTools; using TOOLS = RicfApplicationTools;
@@ -71,12 +71,19 @@ void RicfExportLgrForCompletions::execute()
wellPaths = TOOLS::wellPathsFromNames(TOOLS::toQStringList(m_wellPathNames), &wellsNotFound); wellPaths = TOOLS::wellPathsFromNames(TOOLS::toQStringList(m_wellPathNames), &wellsNotFound);
if (!wellsNotFound.empty()) if (!wellsNotFound.empty())
{ {
RiaLogging::error(QString("exportLgrForCompletions: These well paths were not found: ") + wellsNotFound.join(", ")); QString error(QString("exportLgrForCompletions: These well paths were not found: ") + wellsNotFound.join(", "));
RiaLogging::error(error);
return RicfCommandResponse(RicfCommandResponse::COMMAND_ERROR, error);
} }
} }
if (!wellPaths.empty()) if (wellPaths.empty())
{ {
QString error("exportLgrForCompletions: Could not find any well paths");
RiaLogging::error(error);
return RicfCommandResponse(RicfCommandResponse::COMMAND_ERROR, error);
}
QString exportFolder = RicfCommandFileExecutor::instance()->getExportPath(RicfCommandFileExecutor::LGRS); QString exportFolder = RicfCommandFileExecutor::instance()->getExportPath(RicfCommandFileExecutor::LGRS);
if (exportFolder.isNull()) if (exportFolder.isNull())
{ {
@@ -89,8 +96,9 @@ void RicfExportLgrForCompletions::execute()
RimEclipseCase* eclipseCase = TOOLS::caseFromId(m_caseId()); RimEclipseCase* eclipseCase = TOOLS::caseFromId(m_caseId());
if (!eclipseCase) if (!eclipseCase)
{ {
RiaLogging::error(QString("exportLgrForCompletions: Could not find case with ID %1").arg(m_caseId())); QString error(QString("exportLgrForCompletions: Could not find case with ID %1").arg(m_caseId()));
return; RiaLogging::error(error);
return RicfCommandResponse(RicfCommandResponse::COMMAND_ERROR, error);
} }
caf::VecIjk lgrCellCounts(m_refinementI, m_refinementJ, m_refinementK); caf::VecIjk lgrCellCounts(m_refinementI, m_refinementJ, m_refinementK);
@@ -99,10 +107,13 @@ void RicfExportLgrForCompletions::execute()
feature->exportLgrsForWellPaths(exportFolder, wellPaths, eclipseCase, m_timeStep, lgrCellCounts, m_splitType(), feature->exportLgrsForWellPaths(exportFolder, wellPaths, eclipseCase, m_timeStep, lgrCellCounts, m_splitType(),
{RigCompletionData::PERFORATION, RigCompletionData::FRACTURE, RigCompletionData::FISHBONES}, &wellsIntersectingOtherLgrs); {RigCompletionData::PERFORATION, RigCompletionData::FRACTURE, RigCompletionData::FISHBONES}, &wellsIntersectingOtherLgrs);
RicfCommandResponse response;
if (!wellsIntersectingOtherLgrs.empty()) if (!wellsIntersectingOtherLgrs.empty())
{ {
auto wellsList = wellsIntersectingOtherLgrs.join(", "); auto wellsList = wellsIntersectingOtherLgrs.join(", ");
RiaLogging::error("exportLgrForCompletions: No export for some wells due to existing intersecting LGR(s).Affected wells : " + wellsList); QString warning("exportLgrForCompletions: No export for some wells due to existing intersecting LGR(s).Affected wells : " + wellsList);
} RiaLogging::warning(warning);
response.updateStatus(RicfCommandResponse::COMMAND_WARNING, warning);
} }
return response;
} }
@@ -42,7 +42,7 @@ class RicfExportLgrForCompletions : public RicfCommandObject
public: public:
RicfExportLgrForCompletions(); RicfExportLgrForCompletions();
void execute() override; RicfCommandResponse execute() override;
private: private:
caf::PdmField<int> m_caseId; caf::PdmField<int> m_caseId;
@@ -55,7 +55,7 @@ RicfExportMsw::RicfExportMsw()
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
void RicfExportMsw::execute() RicfCommandResponse RicfExportMsw::execute()
{ {
using TOOLS = RicfApplicationTools; using TOOLS = RicfApplicationTools;
@@ -64,8 +64,9 @@ void RicfExportMsw::execute()
auto eclipseCase = TOOLS::caseFromId(m_caseId()); auto eclipseCase = TOOLS::caseFromId(m_caseId());
if (!eclipseCase) if (!eclipseCase)
{ {
RiaLogging::error(QString("exportMsw: Could not find case with ID %1.").arg(m_caseId())); QString error = QString("exportMsw: Could not find case with ID %1.").arg(m_caseId());
return; RiaLogging::error(error);
return RicfCommandResponse(RicfCommandResponse::COMMAND_ERROR, error);
} }
QString exportFolder = RicfCommandFileExecutor::instance()->getExportPath(RicfCommandFileExecutor::COMPLETIONS); QString exportFolder = RicfCommandFileExecutor::instance()->getExportPath(RicfCommandFileExecutor::COMPLETIONS);
@@ -83,9 +84,12 @@ void RicfExportMsw::execute()
RimWellPath* wellPath = RiaApplication::instance()->project()->wellPathByName(m_wellPathName); RimWellPath* wellPath = RiaApplication::instance()->project()->wellPathByName(m_wellPathName);
if (!wellPath) if (!wellPath)
{ {
RiaLogging::error(QString("exportMsw: Could not find well path with name %1").arg(m_wellPathName())); QString error = QString("exportMsw: Could not find well path with name %1").arg(m_wellPathName());
return; RiaLogging::error(error);
return RicfCommandResponse(RicfCommandResponse::COMMAND_ERROR, error);
} }
RicWellPathExportMswCompletionsImpl::exportWellSegmentsForAllCompletions(exportSettings, { wellPath }); RicWellPathExportMswCompletionsImpl::exportWellSegmentsForAllCompletions(exportSettings, { wellPath });
return RicfCommandResponse();
} }
@@ -36,7 +36,7 @@ class RicfExportMsw : public RicfCommandObject
public: public:
RicfExportMsw(); RicfExportMsw();
void execute() override; RicfCommandResponse execute() override;
private: private:
caf::PdmField<int> m_caseId; caf::PdmField<int> m_caseId;
@@ -37,27 +37,32 @@ RicfExportMultiCaseSnapshots::RicfExportMultiCaseSnapshots()
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
void RicfExportMultiCaseSnapshots::execute() RicfCommandResponse RicfExportMultiCaseSnapshots::execute()
{ {
RiaGuiApplication* app = RiaGuiApplication::instance(); RiaGuiApplication* app = RiaGuiApplication::instance();
if (!app) if (!app)
{ {
RiaLogging::error("exportMultiCaseSnapshots: Requires GUI Application"); QString error("exportMultiCaseSnapshots: Requires GUI Application");
return; RiaLogging::error(error);
return RicfCommandResponse(RicfCommandResponse::COMMAND_ERROR, error);
} }
if (m_gridListFile().isNull()) if (m_gridListFile().isNull())
{ {
RiaLogging::error("exportMultiCaseSnapshots: Required parameter gridListFile."); QString error("exportMultiCaseSnapshots: Required parameter gridListFile.");
return; RiaLogging::error(error);
return RicfCommandResponse(RicfCommandResponse::COMMAND_ERROR, error);
} }
QString lastProjectPath = RicfCommandFileExecutor::instance()->getLastProjectPath(); QString lastProjectPath = RicfCommandFileExecutor::instance()->getLastProjectPath();
if (lastProjectPath.isNull()) if (lastProjectPath.isNull())
{ {
RiaLogging::error("exportMultiCaseSnapshots: 'openProject' must be called before 'exportMultiCaseSnapshots' to specify project file to replace cases in."); QString error("exportMultiCaseSnapshots: 'openProject' must be called before 'exportMultiCaseSnapshots' to specify project file to replace cases in.");
return; RiaLogging::error(error);
return RicfCommandResponse(RicfCommandResponse::COMMAND_ERROR, error);
} }
std::vector<QString> listFileNames = RiaApplication::readFileListFromTextFile(m_gridListFile()); std::vector<QString> listFileNames = RiaApplication::readFileListFromTextFile(m_gridListFile());
app->runMultiCaseSnapshots(lastProjectPath, listFileNames, RicfCommandFileExecutor::instance()->getExportPath(RicfCommandFileExecutor::SNAPSHOTS)); app->runMultiCaseSnapshots(lastProjectPath, listFileNames, RicfCommandFileExecutor::instance()->getExportPath(RicfCommandFileExecutor::SNAPSHOTS));
return RicfCommandResponse();
} }
@@ -34,7 +34,7 @@ class RicfExportMultiCaseSnapshots : public RicfCommandObject
public: public:
RicfExportMultiCaseSnapshots(); RicfExportMultiCaseSnapshots();
void execute() override; RicfCommandResponse execute() override;
private: private:
caf::PdmField<QString> m_gridListFile; caf::PdmField<QString> m_gridListFile;
@@ -59,7 +59,7 @@ RicfExportProperty::RicfExportProperty()
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
void RicfExportProperty::execute() RicfCommandResponse RicfExportProperty::execute()
{ {
using TOOLS = RicfApplicationTools; using TOOLS = RicfApplicationTools;
@@ -67,16 +67,18 @@ void RicfExportProperty::execute()
{ {
if (!eclipseCase) if (!eclipseCase)
{ {
RiaLogging::error(QString("exportProperty: Could not find case with ID %1").arg(m_caseId())); QString error = QString("exportProperty: Could not find case with ID %1").arg(m_caseId());
return; RiaLogging::error(error);
return RicfCommandResponse(RicfCommandResponse::COMMAND_ERROR, error);
} }
if (!eclipseCase->eclipseCaseData()) if (!eclipseCase->eclipseCaseData())
{ {
if (!eclipseCase->openReserviorCase()) if (!eclipseCase->openReserviorCase())
{ {
RiaLogging::error(QString("exportProperty: Could not find eclipseCaseData with ID %1").arg(m_caseId())); QString error = QString("exportProperty: Could not find eclipseCaseData with ID %1").arg(m_caseId());
return; RiaLogging::error(error);
return RicfCommandResponse(RicfCommandResponse::COMMAND_ERROR, error);
} }
} }
} }
@@ -87,8 +89,9 @@ void RicfExportProperty::execute()
if (!cellResultsData->ensureKnownResultLoaded(RigEclipseResultAddress(m_propertyName))) if (!cellResultsData->ensureKnownResultLoaded(RigEclipseResultAddress(m_propertyName)))
{ {
RiaLogging::error(QString("exportProperty: Could not find result property : %1").arg(m_propertyName())); QString error = QString("exportProperty: Could not find result property : %1").arg(m_propertyName());
return; RiaLogging::error(error);
return RicfCommandResponse(RicfCommandResponse::COMMAND_ERROR, error);
} }
QString filePath = m_exportFileName; QString filePath = m_exportFileName;
@@ -106,6 +109,13 @@ void RicfExportProperty::execute()
eclipseKeyword = m_propertyName; eclipseKeyword = m_propertyName;
} }
RicEclipseCellResultToFileImpl::writePropertyToTextFile( QString errMsg;
filePath, eclipseCase->eclipseCaseData(), m_timeStepIndex, m_propertyName, eclipseKeyword, m_undefinedValue); if (!RicEclipseCellResultToFileImpl::writePropertyToTextFile(
filePath, eclipseCase->eclipseCaseData(), m_timeStepIndex, m_propertyName, eclipseKeyword, m_undefinedValue,
&errMsg))
{
return RicfCommandResponse(RicfCommandResponse::COMMAND_ERROR, errMsg);
}
return RicfCommandResponse();
} }
@@ -38,7 +38,7 @@ class RicfExportProperty : public RicfCommandObject
public: public:
RicfExportProperty(); RicfExportProperty();
void execute() override; RicfCommandResponse execute() override;
private: private:
caf::PdmField<int> m_caseId; caf::PdmField<int> m_caseId;
@@ -55,15 +55,16 @@ RicfExportPropertyInViews::RicfExportPropertyInViews()
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
void RicfExportPropertyInViews::execute() RicfCommandResponse RicfExportPropertyInViews::execute()
{ {
using TOOLS = RicfApplicationTools; using TOOLS = RicfApplicationTools;
RimEclipseCase* eclipseCase = TOOLS::caseFromId(m_caseId()); RimEclipseCase* eclipseCase = TOOLS::caseFromId(m_caseId());
if (!eclipseCase) if (!eclipseCase)
{ {
RiaLogging::error(QString("exportProperty: Could not find case with ID %1").arg(m_caseId())); QString error(QString("exportProperty: Could not find case with ID %1").arg(m_caseId()));
return; RiaLogging::error(error);
return RicfCommandResponse(RicfCommandResponse::COMMAND_ERROR, error);
} }
std::vector<RimEclipseView*> viewsForExport; std::vector<RimEclipseView*> viewsForExport;
@@ -95,6 +96,8 @@ void RicfExportPropertyInViews::execute()
} }
} }
RicfCommandResponse response;
for (const auto& view : viewsForExport) for (const auto& view : viewsForExport)
{ {
cvf::ref<RigResultAccessor> resultAccessor = nullptr; cvf::ref<RigResultAccessor> resultAccessor = nullptr;
@@ -109,11 +112,12 @@ void RicfExportPropertyInViews::execute()
if (resultAccessor.isNull()) if (resultAccessor.isNull())
{ {
RiaLogging::error(QString("exportProperty: Could not find property. Case ID %1, time step %2, property '%3'") QString warning = QString("exportProperty: Could not find property. Case ID %1, time step %2, property '%3'")
.arg(m_caseId) .arg(m_caseId)
.arg(view->currentTimeStep()) .arg(view->currentTimeStep())
.arg(propertyName)); .arg(propertyName);
RiaLogging::warning(warning);
response.updateStatus(RicfCommandResponse::COMMAND_WARNING, warning);
continue; continue;
} }
@@ -128,11 +132,19 @@ void RicfExportPropertyInViews::execute()
fileName = caf::Utils::makeValidFileBasename(fileName); fileName = caf::Utils::makeValidFileBasename(fileName);
const QString filePath = propertiesDir.filePath(fileName); const QString filePath = propertiesDir.filePath(fileName);
RicEclipseCellResultToFileImpl::writeResultToTextFile(filePath, QString errorMsg;
bool worked = RicEclipseCellResultToFileImpl::writeResultToTextFile(filePath,
eclipseCase->eclipseCaseData(), eclipseCase->eclipseCaseData(),
resultAccessor.p(), resultAccessor.p(),
propertyName, propertyName,
m_undefinedValue, m_undefinedValue,
"exportPropertiesInViews"); "exportPropertiesInViews",
&errorMsg);
if (!worked)
{
return RicfCommandResponse(RicfCommandResponse::COMMAND_ERROR, errorMsg);
} }
} }
return response;
}
@@ -40,7 +40,7 @@ class RicfExportPropertyInViews : public RicfCommandObject
public: public:
RicfExportPropertyInViews(); RicfExportPropertyInViews();
void execute() override; RicfCommandResponse execute() override;
private: private:
caf::PdmField<int> m_caseId; caf::PdmField<int> m_caseId;
@@ -56,7 +56,7 @@ RicfExportSimWellFractureCompletions::RicfExportSimWellFractureCompletions()
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
void RicfExportSimWellFractureCompletions::execute() RicfCommandResponse RicfExportSimWellFractureCompletions::execute()
{ {
using TOOLS = RicfApplicationTools; using TOOLS = RicfApplicationTools;
@@ -71,8 +71,9 @@ void RicfExportSimWellFractureCompletions::execute()
auto eclipseCase = TOOLS::caseFromId(m_caseId()); auto eclipseCase = TOOLS::caseFromId(m_caseId());
if (!eclipseCase) if (!eclipseCase)
{ {
RiaLogging::error(QString("exportSimWellCompletions: Could not find case with ID %1").arg(m_caseId())); QString error = QString("exportSimWellCompletions: Could not find case with ID %1").arg(m_caseId());
return; RiaLogging::error(error);
return RicfCommandResponse(RicfCommandResponse::COMMAND_ERROR, error);
} }
exportSettings->caseToApply = eclipseCase; exportSettings->caseToApply = eclipseCase;
} }
@@ -95,10 +96,13 @@ void RicfExportSimWellFractureCompletions::execute()
} }
if (views.empty()) if (views.empty())
{ {
RiaLogging::error(QString("exportSimWellCompletions: Could not find any views named \"%1\" in the case with ID %2").arg(m_viewName).arg(m_caseId())); QString error = QString("exportSimWellCompletions: Could not find any views named \"%1\" in the case with ID %2").arg(m_viewName).arg(m_caseId());
return; RiaLogging::error(error);
return RicfCommandResponse(RicfCommandResponse::COMMAND_ERROR, error);
} }
RicfCommandResponse response;
std::vector<RimSimWellInView*> simWells; std::vector<RimSimWellInView*> simWells;
if (m_simWellNames().empty()) if (m_simWellNames().empty())
{ {
@@ -126,7 +130,9 @@ void RicfExportSimWellFractureCompletions::execute()
} }
else else
{ {
RiaLogging::warning(QString("exportSimWellCompletions: Could not find well with name %1 in view \"%2\" on case with ID %2").arg(wellPathName).arg(m_viewName).arg(m_caseId())); QString warning = QString("exportSimWellCompletions: Could not find well with name %1 in view \"%2\" on case with ID %2").arg(wellPathName).arg(m_viewName).arg(m_caseId());
RiaLogging::warning(warning);
response.updateStatus(RicfCommandResponse::COMMAND_WARNING, warning);
} }
} }
} }
@@ -135,4 +141,6 @@ void RicfExportSimWellFractureCompletions::execute()
std::vector<RimWellPath*> wellPaths; std::vector<RimWellPath*> wellPaths;
RicWellPathExportCompletionDataFeatureImpl::exportCompletions(wellPaths, simWells, *exportSettings); RicWellPathExportCompletionDataFeatureImpl::exportCompletions(wellPaths, simWells, *exportSettings);
return response;
} }
@@ -37,7 +37,7 @@ class RicfExportSimWellFractureCompletions : public RicfCommandObject
public: public:
RicfExportSimWellFractureCompletions(); RicfExportSimWellFractureCompletions();
void execute() override; RicfCommandResponse execute() override;
private: private:
caf::PdmField<int> m_caseId; caf::PdmField<int> m_caseId;
@@ -56,12 +56,13 @@ RicfExportSnapshots::RicfExportSnapshots()
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
void RicfExportSnapshots::execute() RicfCommandResponse RicfExportSnapshots::execute()
{ {
if (!RiaGuiApplication::isRunning()) if (!RiaGuiApplication::isRunning())
{ {
RiaLogging::error(QString("RicfExportSnapshot: Command cannot run without a GUI")); QString error("RicfExportSnapshot: Command cannot run without a GUI");
return; RiaLogging::error(error);
return RicfCommandResponse(RicfCommandResponse::COMMAND_ERROR, error);
} }
RiuMainWindow* mainWnd = RiuMainWindow::instance(); RiuMainWindow* mainWnd = RiuMainWindow::instance();
@@ -85,4 +86,6 @@ void RicfExportSnapshots::execute()
mainWnd->loadWinGeoAndDockToolBarLayout(); mainWnd->loadWinGeoAndDockToolBarLayout();
RiaGuiApplication::instance()->processEvents(); RiaGuiApplication::instance()->processEvents();
return RicfCommandResponse();
} }
@@ -44,7 +44,7 @@ public:
public: public:
RicfExportSnapshots(); RicfExportSnapshots();
void execute() override; RicfCommandResponse execute() override;
private: private:
caf::PdmField<SnapshotsTypeEnum> m_type; caf::PdmField<SnapshotsTypeEnum> m_type;
@@ -75,19 +75,21 @@ RicfExportVisibleCells::RicfExportVisibleCells()
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
void RicfExportVisibleCells::execute() RicfCommandResponse RicfExportVisibleCells::execute()
{ {
if (m_caseId < 0 || m_viewName().isEmpty()) if (m_caseId < 0 || m_viewName().isEmpty())
{ {
RiaLogging::error("exportVisibleCells: CaseId or view name not specified"); QString error("exportVisibleCells: CaseId or view name not specified");
return; RiaLogging::error(error);
return RicfCommandResponse(RicfCommandResponse::COMMAND_ERROR, error);
} }
auto eclipseView = RicfApplicationTools::viewFromCaseIdAndViewName(m_caseId, m_viewName); auto eclipseView = RicfApplicationTools::viewFromCaseIdAndViewName(m_caseId, m_viewName);
if (!eclipseView) if (!eclipseView)
{ {
RiaLogging::error(QString("exportVisibleCells: Could not find view '%1' in case ID %2").arg(m_viewName).arg(m_caseId)); QString error(QString("exportVisibleCells: Could not find view '%1' in case ID %2").arg(m_viewName).arg(m_caseId));
return; RiaLogging::error(error);
return RicfCommandResponse(RicfCommandResponse::COMMAND_ERROR, error);
} }
QString exportFolder = RicfCommandFileExecutor::instance()->getExportPath(RicfCommandFileExecutor::CELLS); QString exportFolder = RicfCommandFileExecutor::instance()->getExportPath(RicfCommandFileExecutor::CELLS);
@@ -101,6 +103,8 @@ void RicfExportVisibleCells::execute()
RicSaveEclipseInputVisibleCellsUi exportSettings; RicSaveEclipseInputVisibleCellsUi exportSettings;
buildExportSettings(exportFolder, &exportSettings); buildExportSettings(exportFolder, &exportSettings);
RicSaveEclipseInputVisibleCellsFeature::executeCommand(eclipseView, exportSettings, "exportVisibleCells"); RicSaveEclipseInputVisibleCellsFeature::executeCommand(eclipseView, exportSettings, "exportVisibleCells");
return RicfCommandResponse();
} }
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
@@ -45,7 +45,7 @@ class RicfExportVisibleCells : public RicfCommandObject
public: public:
RicfExportVisibleCells(); RicfExportVisibleCells();
void execute() override; RicfCommandResponse execute() override;
private: private:
void buildExportSettings(const QString& exportFolder, RicSaveEclipseInputVisibleCellsUi* exportSettings); void buildExportSettings(const QString& exportFolder, RicSaveEclipseInputVisibleCellsUi* exportSettings);
@@ -65,7 +65,7 @@ RicfExportWellPathCompletions::RicfExportWellPathCompletions()
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
void RicfExportWellPathCompletions::execute() RicfCommandResponse RicfExportWellPathCompletions::execute()
{ {
using TOOLS = RicfApplicationTools; using TOOLS = RicfApplicationTools;
@@ -101,8 +101,9 @@ void RicfExportWellPathCompletions::execute()
auto eclipseCase = TOOLS::caseFromId(m_caseId()); auto eclipseCase = TOOLS::caseFromId(m_caseId());
if (!eclipseCase) if (!eclipseCase)
{ {
RiaLogging::error(QString("exportWellPathCompletions: Could not find case with ID %1").arg(m_caseId())); QString error = QString("exportWellPathCompletions: Could not find case with ID %1").arg(m_caseId());
return; RiaLogging::error(error);
return RicfCommandResponse(RicfCommandResponse::COMMAND_ERROR, error);
} }
exportSettings->caseToApply = eclipseCase; exportSettings->caseToApply = eclipseCase;
} }
@@ -114,6 +115,8 @@ void RicfExportWellPathCompletions::execute()
} }
exportSettings->folder = exportFolder; exportSettings->folder = exportFolder;
RicfCommandResponse response;
std::vector<RimWellPath*> wellPaths; std::vector<RimWellPath*> wellPaths;
if (m_wellPathNames().empty()) if (m_wellPathNames().empty())
{ {
@@ -136,7 +139,9 @@ void RicfExportWellPathCompletions::execute()
} }
else else
{ {
RiaLogging::warning(QString("exportWellPathCompletions: Could not find well path with name %1").arg(wellPathName)); QString warning = QString("exportWellPathCompletions: Could not find well path with name %1").arg(wellPathName);
RiaLogging::warning(warning);
response.updateStatus(RicfCommandResponse::COMMAND_WARNING, warning);
} }
} }
} }
@@ -144,4 +149,6 @@ void RicfExportWellPathCompletions::execute()
std::vector<RimSimWellInView*> simWells; std::vector<RimSimWellInView*> simWells;
RicWellPathExportCompletionDataFeatureImpl::exportCompletions(wellPaths, simWells, *exportSettings); RicWellPathExportCompletionDataFeatureImpl::exportCompletions(wellPaths, simWells, *exportSettings);
return response;
} }
@@ -37,7 +37,7 @@ class RicfExportWellPathCompletions : public RicfCommandObject
public: public:
RicfExportWellPathCompletions(); RicfExportWellPathCompletions();
void execute() override; RicfCommandResponse execute() override;
private: private:
caf::PdmField<int> m_caseId; caf::PdmField<int> m_caseId;
@@ -52,7 +52,7 @@ RicfExportWellPaths::RicfExportWellPaths()
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
void RicfExportWellPaths::execute() RicfCommandResponse RicfExportWellPaths::execute()
{ {
using TOOLS = RicfApplicationTools; using TOOLS = RicfApplicationTools;
@@ -64,12 +64,19 @@ void RicfExportWellPaths::execute()
wellPaths = TOOLS::wellPathsFromNames(TOOLS::toQStringList(m_wellPathNames), &wellsNotFound); wellPaths = TOOLS::wellPathsFromNames(TOOLS::toQStringList(m_wellPathNames), &wellsNotFound);
if (!wellsNotFound.empty()) if (!wellsNotFound.empty())
{ {
RiaLogging::error(QString("exportWellPaths: These well paths were not found: ") + wellsNotFound.join(", ")); QString error(QString("exportWellPaths: These well paths were not found: ") + wellsNotFound.join(", "));
RiaLogging::error(error);
return RicfCommandResponse(RicfCommandResponse::COMMAND_ERROR, error);
} }
} }
if (!wellPaths.empty()) if (wellPaths.empty())
{ {
QString error("No well paths found");
RiaLogging::error(error);
return RicfCommandResponse(RicfCommandResponse::COMMAND_ERROR, error);
}
QString exportFolder = RicfCommandFileExecutor::instance()->getExportPath(RicfCommandFileExecutor::WELLPATHS); QString exportFolder = RicfCommandFileExecutor::instance()->getExportPath(RicfCommandFileExecutor::WELLPATHS);
if (exportFolder.isNull()) if (exportFolder.isNull())
{ {
@@ -86,5 +93,5 @@ void RicfExportWellPaths::execute()
feature->exportWellPath(wellPath, m_mdStepSize, exportFolder, false); feature->exportWellPath(wellPath, m_mdStepSize, exportFolder, false);
} }
} }
} return RicfCommandResponse();
} }
@@ -37,7 +37,7 @@ class RicfExportWellPaths : public RicfCommandObject
public: public:
RicfExportWellPaths(); RicfExportWellPaths();
void execute() override; RicfCommandResponse execute() override;
private: private:
caf::PdmField<std::vector<QString>> m_wellPathNames; caf::PdmField<std::vector<QString>> m_wellPathNames;
@@ -37,11 +37,14 @@ RicfLoadCase::RicfLoadCase()
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
void RicfLoadCase::execute() RicfCommandResponse RicfLoadCase::execute()
{ {
bool ok = RiaImportEclipseCaseTools::openEclipseCasesFromFile(QStringList({m_path()}), nullptr, true); bool ok = RiaImportEclipseCaseTools::openEclipseCasesFromFile(QStringList({m_path()}), nullptr, true);
if (!ok) if (!ok)
{ {
RiaLogging::error(QString("loadCase: Unable to load case from %1").arg(m_path())); QString error = QString("loadCase: Unable to load case from %1").arg(m_path());
RiaLogging::error(error);
return RicfCommandResponse(RicfCommandResponse::COMMAND_ERROR, error);
} }
return RicfCommandResponse();
} }
@@ -34,7 +34,7 @@ class RicfLoadCase : public RicfCommandObject
public: public:
RicfLoadCase(); RicfLoadCase();
void execute() override; RicfCommandResponse execute() override;
private: private:
caf::PdmField<QString> m_path; caf::PdmField<QString> m_path;
@@ -40,7 +40,7 @@ RicfOpenProject::RicfOpenProject()
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
void RicfOpenProject::execute() RicfCommandResponse RicfOpenProject::execute()
{ {
QString projectPath = m_path; QString projectPath = m_path;
QFileInfo projectPathInfo(projectPath); QFileInfo projectPathInfo(projectPath);
@@ -52,8 +52,9 @@ void RicfOpenProject::execute()
bool ok = RiaApplication::instance()->loadProject(projectPath); bool ok = RiaApplication::instance()->loadProject(projectPath);
if (!ok) if (!ok)
{ {
RiaLogging::error(QString("openProject: Unable to open project at %1").arg(m_path())); QString errMsg = QString("openProject: Unable to open project at %1").arg(m_path());
return; RiaLogging::error(errMsg);
return RicfCommandResponse(RicfCommandResponse::COMMAND_ERROR, errMsg);
} }
if (RiaRegressionTestRunner::instance()->isRunningRegressionTests()) if (RiaRegressionTestRunner::instance()->isRunningRegressionTests())
@@ -62,4 +63,6 @@ void RicfOpenProject::execute()
} }
RicfCommandFileExecutor::instance()->setLastProjectPath(projectPath); RicfCommandFileExecutor::instance()->setLastProjectPath(projectPath);
return RicfCommandResponse();
} }
@@ -34,7 +34,7 @@ class RicfOpenProject : public RicfCommandObject
public: public:
RicfOpenProject(); RicfOpenProject();
void execute() override; RicfCommandResponse execute() override;
private: private:
caf::PdmField<QString> m_path; caf::PdmField<QString> m_path;
@@ -56,10 +56,11 @@ QString RicfSingleCaseReplace::filePath() const
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
void RicfSingleCaseReplace::execute() RicfCommandResponse RicfSingleCaseReplace::execute()
{ {
// Never call execute on this object, information is aggregated into RicfMultiCaseReplace // Never call execute on this object, information is aggregated into RicfMultiCaseReplace
CAF_ASSERT(false); CAF_ASSERT(false);
return RicfCommandResponse(RicfCommandResponse::COMMAND_ERROR, "Never call execute on a RicfSingleCaseReplace object");
} }
@@ -85,19 +86,21 @@ void RicfMultiCaseReplace::setCaseReplacePairs(const std::map<int, QString>& cas
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
void RicfMultiCaseReplace::execute() RicfCommandResponse RicfMultiCaseReplace::execute()
{ {
if (m_caseIdToGridFileNameMap.empty()) if (m_caseIdToGridFileNameMap.empty())
{ {
RiaLogging::error("replaceCaseImpl: No replacements available."); QString errMsg("replaceCaseImpl: No replacements available.");
return; RiaLogging::error(errMsg);
return RicfCommandResponse(RicfCommandResponse::COMMAND_ERROR, errMsg);
} }
QString lastProjectPath = RicfCommandFileExecutor::instance()->getLastProjectPath(); QString lastProjectPath = RicfCommandFileExecutor::instance()->getLastProjectPath();
if (lastProjectPath.isNull()) if (lastProjectPath.isNull())
{ {
RiaLogging::error("replaceCase: 'openProject' must be called before 'replaceCase' to specify project file to replace case in."); QString errMsg("replaceCase: 'openProject' must be called before 'replaceCase' to specify project file to replace case in.");
return; RiaLogging::error(errMsg);
return RicfCommandResponse(RicfCommandResponse::COMMAND_ERROR, errMsg);
} }
cvf::ref<RiaProjectModifier> projectModifier = new RiaProjectModifier; cvf::ref<RiaProjectModifier> projectModifier = new RiaProjectModifier;
@@ -115,5 +118,12 @@ void RicfMultiCaseReplace::execute()
} }
} }
RiaApplication::instance()->loadProject(lastProjectPath, RiaApplication::PLA_NONE, projectModifier.p()); if (!RiaApplication::instance()->loadProject(lastProjectPath, RiaApplication::PLA_NONE, projectModifier.p()))
{
QString errMsg("Could not reload project");
RiaLogging::error(errMsg);
return RicfCommandResponse(RicfCommandResponse::COMMAND_ERROR, errMsg);
}
return RicfCommandResponse();
} }
@@ -40,7 +40,7 @@ public:
int caseId() const; int caseId() const;
QString filePath() const; QString filePath() const;
void execute() override; RicfCommandResponse execute() override;
private: private:
caf::PdmField<QString> m_newGridFile; caf::PdmField<QString> m_newGridFile;
@@ -63,7 +63,7 @@ public:
void setCaseReplacePairs(const std::map<int, QString>& caseIdToGridFileNameMap); void setCaseReplacePairs(const std::map<int, QString>& caseIdToGridFileNameMap);
void execute() override; RicfCommandResponse execute() override;
private: private:
std::map<int, QString> m_caseIdToGridFileNameMap; std::map<int, QString> m_caseIdToGridFileNameMap;
@@ -38,19 +38,21 @@ RicfReplaceSourceCases::RicfReplaceSourceCases()
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
void RicfReplaceSourceCases::execute() RicfCommandResponse RicfReplaceSourceCases::execute()
{ {
if (m_gridListFile().isNull()) if (m_gridListFile().isNull())
{ {
RiaLogging::error("replaceSourceCases: Required parameter gridListFile."); QString error("replaceSourceCases: Required parameter gridListFile.");
return; RiaLogging::error(error);
return RicfCommandResponse(RicfCommandResponse::COMMAND_ERROR, error);
} }
QString lastProjectPath = RicfCommandFileExecutor::instance()->getLastProjectPath(); QString lastProjectPath = RicfCommandFileExecutor::instance()->getLastProjectPath();
if (lastProjectPath.isNull()) if (lastProjectPath.isNull())
{ {
RiaLogging::error("replaceSourceCases: 'openProject' must be called before 'replaceSourceCases' to specify project file to replace cases in."); QString error("replaceSourceCases: 'openProject' must be called before 'replaceSourceCases' to specify project file to replace cases in.");
return; RiaLogging::error(error);
return RicfCommandResponse(RicfCommandResponse::COMMAND_ERROR, error);
} }
cvf::ref<RiaProjectModifier> projectModifier = new RiaProjectModifier; cvf::ref<RiaProjectModifier> projectModifier = new RiaProjectModifier;
@@ -65,5 +67,11 @@ void RicfReplaceSourceCases::execute()
projectModifier->setReplaceSourceCasesById(m_caseGroupId(), listFileNames); projectModifier->setReplaceSourceCasesById(m_caseGroupId(), listFileNames);
} }
RiaApplication::instance()->loadProject(lastProjectPath, RiaApplication::PLA_CALCULATE_STATISTICS, projectModifier.p()); if (!RiaApplication::instance()->loadProject(lastProjectPath, RiaApplication::PLA_CALCULATE_STATISTICS, projectModifier.p()))
{
QString error("Could not reload project");
RiaLogging::error(error);
return RicfCommandResponse(RicfCommandResponse::COMMAND_ERROR, error);
}
return RicfCommandResponse();
} }
@@ -34,7 +34,7 @@ class RicfReplaceSourceCases : public RicfCommandObject
public: public:
RicfReplaceSourceCases(); RicfReplaceSourceCases();
void execute() override; RicfCommandResponse execute() override;
private: private:
caf::PdmField<QString> m_gridListFile; caf::PdmField<QString> m_gridListFile;
@@ -42,7 +42,7 @@ RicfRunOctaveScript::RicfRunOctaveScript()
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
void RicfRunOctaveScript::execute() RicfCommandResponse RicfRunOctaveScript::execute()
{ {
QString octavePath = RiaApplication::instance()->octavePath(); QString octavePath = RiaApplication::instance()->octavePath();
@@ -71,12 +71,17 @@ void RicfRunOctaveScript::execute()
{ {
ok = RiaApplication::instance()->launchProcessForMultipleCases(octavePath, processArguments, caseIds); ok = RiaApplication::instance()->launchProcessForMultipleCases(octavePath, processArguments, caseIds);
} }
RicfCommandResponse response;
if (!ok) if (!ok)
{ {
RiaLogging::error(QString("runOctaveScript: Could not execute script %1").arg(m_path())); QString error = QString("runOctaveScript: Could not execute script %1").arg(m_path());
RiaLogging::error(error);
response.updateStatus(RicfCommandResponse::COMMAND_ERROR, error);
} }
else else
{ {
RiaApplication::instance()->waitForProcess(); RiaApplication::instance()->waitForProcess();
} }
return response;
} }
@@ -34,7 +34,7 @@ class RicfRunOctaveScript : public RicfCommandObject
public: public:
RicfRunOctaveScript(); RicfRunOctaveScript();
void execute() override; RicfCommandResponse execute() override;
private: private:
caf::PdmField<QString> m_path; caf::PdmField<QString> m_path;
@@ -49,20 +49,22 @@ RicfScaleFractureTemplate::RicfScaleFractureTemplate()
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
void RicfScaleFractureTemplate::execute() RicfCommandResponse RicfScaleFractureTemplate::execute()
{ {
if (m_id < 0) if (m_id < 0)
{ {
RiaLogging::error("scaleFractureTemplate: Fracture template id not specified"); QString error("scaleFractureTemplate: Fracture template id not specified");
return; RiaLogging::error(error);
return RicfCommandResponse(RicfCommandResponse::COMMAND_ERROR, error);
} }
RimProject* project = RiaApplication::instance()->project(); RimProject* project = RiaApplication::instance()->project();
if (!project) if (!project)
{ {
RiaLogging::error("scaleFractureTemplate: Project not found"); QString error("scaleFractureTemplate: Project not found");
return; RiaLogging::error(error);
return RicfCommandResponse(RicfCommandResponse::COMMAND_ERROR, error);
} }
RimFractureTemplateCollection* templColl = RimFractureTemplateCollection* templColl =
@@ -71,12 +73,14 @@ void RicfScaleFractureTemplate::execute()
if (!templ) if (!templ)
{ {
RiaLogging::error(QString("scaleFractureTemplate: Fracture template not found. Id=%1").arg(m_id)); QString error = QString("scaleFractureTemplate: Fracture template not found. Id=%1").arg(m_id);
return; RiaLogging::error(error);
return RicfCommandResponse(RicfCommandResponse::COMMAND_ERROR, error);
} }
templ->setScaleFactors(m_halfLengthScaleFactor, m_heightScaleFactor, m_dFactorScaleFactor, m_conductivityScaleFactor); templ->setScaleFactors(m_halfLengthScaleFactor, m_heightScaleFactor, m_dFactorScaleFactor, m_conductivityScaleFactor);
templ->loadDataAndUpdateGeometryHasChanged(); templ->loadDataAndUpdateGeometryHasChanged();
return RicfCommandResponse();
} }
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
@@ -36,7 +36,7 @@ class RicfScaleFractureTemplate : public RicfCommandObject
public: public:
RicfScaleFractureTemplate(); RicfScaleFractureTemplate();
void execute() override; RicfCommandResponse execute() override;
private: private:
void initAfterRead() override; void initAfterRead() override;
@@ -40,7 +40,7 @@ RicfSetExportFolder::RicfSetExportFolder()
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
void RicfSetExportFolder::execute() RicfCommandResponse RicfSetExportFolder::execute()
{ {
if (m_createFolder) if (m_createFolder)
{ {
@@ -52,11 +52,14 @@ void RicfSetExportFolder::execute()
if (!dir.exists(m_path)) if (!dir.exists(m_path))
{ {
RiaLogging::error("Could not create folder : " + m_path); QString error = QString("Could not create folder : %1").arg(m_path);
RiaLogging::error(error);
return RicfCommandResponse(RicfCommandResponse::COMMAND_ERROR, error);
} }
} }
} }
RicfCommandFileExecutor* executor = RicfCommandFileExecutor::instance(); RicfCommandFileExecutor* executor = RicfCommandFileExecutor::instance();
executor->setExportPath(m_type(), m_path); executor->setExportPath(m_type(), m_path);
return RicfCommandResponse();
} }
@@ -36,7 +36,7 @@ class RicfSetExportFolder : public RicfCommandObject
public: public:
RicfSetExportFolder(); RicfSetExportFolder();
void execute() override; RicfCommandResponse execute() override;
private: private:
caf::PdmField<RicfCommandFileExecutor::ExportTypeEnum> m_type; caf::PdmField<RicfCommandFileExecutor::ExportTypeEnum> m_type;
@@ -41,20 +41,22 @@ RicfSetFractureContainment::RicfSetFractureContainment()
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
void RicfSetFractureContainment::execute() RicfCommandResponse RicfSetFractureContainment::execute()
{ {
if (m_id < 0 || m_topLayer < 0 || m_baseLayer < 0) if (m_id < 0 || m_topLayer < 0 || m_baseLayer < 0)
{ {
RiaLogging::error("setFractureContainment: Required argument missing"); QString error("setFractureContainment: Required argument missing");
return; RiaLogging::error(error);
return RicfCommandResponse(RicfCommandResponse::COMMAND_ERROR, error);
} }
RimProject* project = RiaApplication::instance()->project(); RimProject* project = RiaApplication::instance()->project();
if (!project) if (!project)
{ {
RiaLogging::error("setFractureContainment: Project not found"); QString error("setFractureContainment: Project not found");
return; RiaLogging::error(error);
return RicfCommandResponse(RicfCommandResponse::COMMAND_ERROR, error);
} }
RimFractureTemplateCollection* templColl = !project->allFractureTemplateCollections().empty() ? project->allFractureTemplateCollections()[0] : nullptr; RimFractureTemplateCollection* templColl = !project->allFractureTemplateCollections().empty() ? project->allFractureTemplateCollections()[0] : nullptr;
@@ -62,11 +64,13 @@ void RicfSetFractureContainment::execute()
if (!templ) if (!templ)
{ {
RiaLogging::error(QString("setFractureContainment: Fracture template not found. Id=%1").arg(m_id)); QString error = QString("setFractureContainment: Fracture template not found. Id=%1").arg(m_id);
return; RiaLogging::error(error);
return RicfCommandResponse(RicfCommandResponse::COMMAND_ERROR, error);
} }
templ->setContainmentTopKLayer(m_topLayer); templ->setContainmentTopKLayer(m_topLayer);
templ->setContainmentBaseKLayer(m_baseLayer); templ->setContainmentBaseKLayer(m_baseLayer);
templ->loadDataAndUpdateGeometryHasChanged(); templ->loadDataAndUpdateGeometryHasChanged();
return RicfCommandResponse();
} }
@@ -36,7 +36,7 @@ class RicfSetFractureContainment : public RicfCommandObject
public: public:
RicfSetFractureContainment(); RicfSetFractureContainment();
void execute() override; RicfCommandResponse execute() override;
private: private:
caf::PdmField<int> m_id; caf::PdmField<int> m_id;
@@ -35,7 +35,8 @@ RicfSetMainWindowSize::RicfSetMainWindowSize()
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
void RicfSetMainWindowSize::execute() RicfCommandResponse RicfSetMainWindowSize::execute()
{ {
RiuMainWindow::instance()->resize(m_width, m_height); RiuMainWindow::instance()->resize(m_width, m_height);
return RicfCommandResponse();
} }
@@ -34,7 +34,7 @@ class RicfSetMainWindowSize : public RicfCommandObject
public: public:
RicfSetMainWindowSize(); RicfSetMainWindowSize();
void execute() override; RicfCommandResponse execute() override;
private: private:
caf::PdmField<int> m_height; caf::PdmField<int> m_height;
@@ -20,6 +20,8 @@
#include "RiaApplication.h" #include "RiaApplication.h"
#include <QDir>
CAF_PDM_SOURCE_INIT(RicfSetStartDir, "setStartDir"); CAF_PDM_SOURCE_INIT(RicfSetStartDir, "setStartDir");
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
@@ -33,7 +35,22 @@ RicfSetStartDir::RicfSetStartDir()
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
void RicfSetStartDir::execute() RicfCommandResponse RicfSetStartDir::execute()
{ {
RiaApplication::instance()->setStartDir(m_path); QDir directory(m_path);
if (!directory.exists())
{
QString error = QString("Path does not exist: %1").arg(m_path);
RiaLogging::error(error);
return RicfCommandResponse(RicfCommandResponse::COMMAND_ERROR, error);
}
if (!directory.isReadable())
{
QString error = QString("Path does not exist: %1").arg(m_path);
RiaLogging::error(error);
return RicfCommandResponse(RicfCommandResponse::COMMAND_ERROR, error);
}
RiaApplication::instance()->setStartDir(m_path);
return RicfCommandResponse();
} }
@@ -34,7 +34,7 @@ class RicfSetStartDir : public RicfCommandObject
public: public:
RicfSetStartDir(); RicfSetStartDir();
void execute() override; RicfCommandResponse execute() override;
private: private:
caf::PdmField<QString> m_path; caf::PdmField<QString> m_path;
@@ -57,7 +57,7 @@ void RicfSetTimeStep::setTimeStepIndex(int timeStepIndex)
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
void RicfSetTimeStep::execute() RicfCommandResponse RicfSetTimeStep::execute()
{ {
RimEclipseCase* eclipseCase = nullptr; RimEclipseCase* eclipseCase = nullptr;
@@ -74,14 +74,28 @@ void RicfSetTimeStep::execute()
} }
if (!foundCase) if (!foundCase)
{ {
RiaLogging::error(QString("setTimeStep: Could not find case with ID %1").arg(m_caseId())); QString error = QString("setTimeStep: Could not find case with ID %1").arg(m_caseId());
return; RiaLogging::error(error);
return RicfCommandResponse(RicfCommandResponse::COMMAND_ERROR, error);
} }
} }
int maxTimeStep = eclipseCase->timeStepStrings().size() - 1;
if (m_timeStepIndex() > maxTimeStep)
{
QString error = QString("setTimeStep: Step %1 is larger than the maximum of %2 for case %3")
.arg(m_timeStepIndex())
.arg(maxTimeStep)
.arg(m_caseId());
RiaLogging::error(error);
return RicfCommandResponse(RicfCommandResponse::COMMAND_ERROR, error);
}
for (Rim3dView* view : eclipseCase->views()) for (Rim3dView* view : eclipseCase->views())
{ {
view->setCurrentTimeStepAndUpdate(m_timeStepIndex); view->setCurrentTimeStepAndUpdate(m_timeStepIndex);
view->createDisplayModelAndRedraw(); view->createDisplayModelAndRedraw();
} }
return RicfCommandResponse();
} }
@@ -37,7 +37,7 @@ public:
void setCaseId(int caseId); void setCaseId(int caseId);
void setTimeStepIndex(int timeStepIndex); void setTimeStepIndex(int timeStepIndex);
void execute() override; RicfCommandResponse execute() override;
private: private:
@@ -39,7 +39,8 @@ bool RicEclipseCellResultToFileImpl::writePropertyToTextFile(const QString&
size_t timeStep, size_t timeStep,
const QString& resultName, const QString& resultName,
const QString& eclipseKeyword, const QString& eclipseKeyword,
const double undefinedValue) const double undefinedValue,
QString* errorMsg)
{ {
CVF_TIGHT_ASSERT(eclipseCase); CVF_TIGHT_ASSERT(eclipseCase);
if (!eclipseCase) return false; if (!eclipseCase) return false;
@@ -52,7 +53,7 @@ bool RicEclipseCellResultToFileImpl::writePropertyToTextFile(const QString&
} }
return writeResultToTextFile( return writeResultToTextFile(
fileName, eclipseCase, resultAccessor.p(), eclipseKeyword, undefinedValue, "writePropertyToTextFile"); fileName, eclipseCase, resultAccessor.p(), eclipseKeyword, undefinedValue, "writePropertyToTextFile", errorMsg);
} }
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
@@ -64,7 +65,8 @@ bool RicEclipseCellResultToFileImpl::writeBinaryResultToTextFile(const QString&
RimEclipseResultDefinition* resultDefinition, RimEclipseResultDefinition* resultDefinition,
const QString& eclipseKeyword, const QString& eclipseKeyword,
const double undefinedValue, const double undefinedValue,
const QString& logPrefix) const QString& logPrefix,
QString* errorMsg)
{ {
CVF_TIGHT_ASSERT(eclipseCase); CVF_TIGHT_ASSERT(eclipseCase);
@@ -75,7 +77,7 @@ bool RicEclipseCellResultToFileImpl::writeBinaryResultToTextFile(const QString&
return false; return false;
} }
return writeResultToTextFile(fileName, eclipseCase, resultAccessor.p(), eclipseKeyword, undefinedValue, logPrefix); return writeResultToTextFile(fileName, eclipseCase, resultAccessor.p(), eclipseKeyword, undefinedValue, logPrefix, errorMsg);
} }
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
@@ -86,18 +88,21 @@ bool RicEclipseCellResultToFileImpl::writeResultToTextFile(const QString& f
RigResultAccessor* resultAccessor, RigResultAccessor* resultAccessor,
const QString& eclipseKeyword, const QString& eclipseKeyword,
const double undefinedValue, const double undefinedValue,
const QString& logPrefix) const QString& logPrefix,
QString* errorMsg)
{ {
CAF_ASSERT(errorMsg != nullptr);
if (!resultAccessor) if (!resultAccessor)
{ {
RiaLogging::error(logPrefix + QString(" : : Could not access result data for '%1'").arg(fileName)); *errorMsg = QString(logPrefix + QString(" : : Could not access result data for '%1'").arg(fileName));
return false; return false;
} }
QFile file(fileName); QFile file(fileName);
if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
{ {
RiaLogging::error(logPrefix + QString(" : Could not open file '%1'. Do the folder exist?").arg(fileName)); *errorMsg = QString(logPrefix + QString(" : Could not open file '%1'. Do the folder exist?").arg(fileName));
return false; return false;
} }
@@ -39,7 +39,8 @@ public:
size_t timeStep, size_t timeStep,
const QString& resultName, const QString& resultName,
const QString& eclipseKeyword, const QString& eclipseKeyword,
const double undefinedValue); const double undefinedValue,
QString* errorMsg);
static bool writeBinaryResultToTextFile(const QString& fileName, static bool writeBinaryResultToTextFile(const QString& fileName,
RigEclipseCaseData* eclipseCase, RigEclipseCaseData* eclipseCase,
@@ -47,14 +48,16 @@ public:
RimEclipseResultDefinition* resultDefinition, RimEclipseResultDefinition* resultDefinition,
const QString& eclipseKeyword, const QString& eclipseKeyword,
const double undefinedValue, const double undefinedValue,
const QString& logPrefix); const QString& logPrefix,
QString* errorMsg);
static bool writeResultToTextFile(const QString& fileName, static bool writeResultToTextFile(const QString& fileName,
RigEclipseCaseData* eclipseCase, RigEclipseCaseData* eclipseCase,
RigResultAccessor* resultAccessor, RigResultAccessor* resultAccessor,
const QString& eclipseKeyword, const QString& eclipseKeyword,
const double undefinedValue, const double undefinedValue,
const QString& logPrefix); const QString& logPrefix,
QString* errorMsg);
static void writeDataToTextFile(QFile* file, const QString& eclipseKeyword, const std::vector<double>& resultData); static void writeDataToTextFile(QFile* file, const QString& eclipseKeyword, const std::vector<double>& resultData);
}; };
@@ -107,12 +107,14 @@ void RicSaveEclipseInputPropertyFeature::onActionTriggered(bool isChecked)
{ {
const double undefinedValue = 0.0; const double undefinedValue = 0.0;
QString errorMsg;
bool isOk = RicEclipseCellResultToFileImpl::writePropertyToTextFile(exportSettings.fileName, bool isOk = RicEclipseCellResultToFileImpl::writePropertyToTextFile(exportSettings.fileName,
inputReservoir->eclipseCaseData(), inputReservoir->eclipseCaseData(),
0, 0,
inputProperty->resultName, inputProperty->resultName,
exportSettings.eclipseKeyword, exportSettings.eclipseKeyword,
undefinedValue); undefinedValue,
&errorMsg);
if (isOk) if (isOk)
{ {
inputProperty->fileName = exportSettings.fileName; inputProperty->fileName = exportSettings.fileName;
@@ -121,6 +123,10 @@ void RicSaveEclipseInputPropertyFeature::onActionTriggered(bool isChecked)
inputProperty->updateConnectedEditors(); inputProperty->updateConnectedEditors();
} }
else
{
RiaLogging::error(errorMsg);
}
} }
} }
@@ -97,10 +97,12 @@ void RicSaveEclipseResultAsInputPropertyExec::redo()
{ {
size_t timeStep = m_cellColors->reservoirView()->currentTimeStep(); size_t timeStep = m_cellColors->reservoirView()->currentTimeStep();
bool isOk = RicEclipseCellResultToFileImpl::writeBinaryResultToTextFile(exportSettings.fileName, m_cellColors->reservoirView()->eclipseCase()->eclipseCaseData(), timeStep, m_cellColors, exportSettings.eclipseKeyword, exportSettings.undefinedValue, "saveEclipseResultAsInputPropertyExec"); QString errMsg;
bool isOk = RicEclipseCellResultToFileImpl::writeBinaryResultToTextFile(exportSettings.fileName, m_cellColors->reservoirView()->eclipseCase()->eclipseCaseData(), timeStep, m_cellColors, exportSettings.eclipseKeyword, exportSettings.undefinedValue, "saveEclipseResultAsInputPropertyExec", &errMsg);
if (!isOk) if (!isOk)
{ {
RiaLogging::error("Failed to exported current result to " + exportSettings.fileName); QString fullError = QString("Failed to exported current result to %1. Error was: %2").arg(exportSettings.fileName).arg(errMsg);
RiaLogging::error(fullError);
} }
} }
} }
@@ -73,8 +73,15 @@ grpc::Status RiaGrpcCommandService::Execute(grpc::ServerContext* context, const
} }
} }
} }
commandHandle->execute(); RicfCommandResponse response = commandHandle->execute();
if (response.status() == RicfCommandResponse::COMMAND_ERROR)
{
return grpc::Status(grpc::FAILED_PRECONDITION, response.message().toStdString());
}
else if (response.status() == RicfCommandResponse::COMMAND_WARNING)
{
context->AddInitialMetadata("warning", response.message().toStdString());
}
return Status::OK; return Status::OK;
} }
} }