#4429 Implement return status handling for command file interface

This commit is contained in:
Gaute Lindkvist
2019-05-23 13:59:19 +02:00
parent e29c7acc03
commit 650af20e06
61 changed files with 639 additions and 276 deletions

View File

@@ -1,6 +1,7 @@
set (SOURCE_GROUP_HEADER_FILES
${CMAKE_CURRENT_LIST_DIR}/RicfCommandObject.h
${CMAKE_CURRENT_LIST_DIR}/RicfCommandResponse.h
${CMAKE_CURRENT_LIST_DIR}/RicfFieldCapability.h
${CMAKE_CURRENT_LIST_DIR}/RicfFieldHandle.h
${CMAKE_CURRENT_LIST_DIR}/RicfObjectCapability.h
@@ -10,6 +11,7 @@ ${CMAKE_CURRENT_LIST_DIR}/RicfMessages.h
set (SOURCE_GROUP_SOURCE_FILES
${CMAKE_CURRENT_LIST_DIR}/RicfCommandObject.cpp
${CMAKE_CURRENT_LIST_DIR}/RicfCommandResponse.cpp
${CMAKE_CURRENT_LIST_DIR}/RicfFieldCapability.cpp
${CMAKE_CURRENT_LIST_DIR}/RicfFieldHandle.cpp
${CMAKE_CURRENT_LIST_DIR}/RicfObjectCapability.cpp

View File

@@ -20,6 +20,7 @@
#include "cafPdmObject.h"
#include "RicfObjectCapability.h"
#include "RicfFieldCapability.h"
#include "RicfCommandResponse.h"
#define RICF_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() override;
virtual void execute() = 0;
virtual RicfCommandResponse execute() = 0;
};

View File

@@ -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 "";
}
}

View File

@@ -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;
};

View File

@@ -32,7 +32,8 @@ RicfCloseProject::RicfCloseProject()
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicfCloseProject::execute()
RicfCommandResponse RicfCloseProject::execute()
{
RiaApplication::instance()->closeProject();
return RicfCommandResponse();
}

View File

@@ -34,7 +34,7 @@ class RicfCloseProject : public RicfCommandObject
public:
RicfCloseProject();
void execute() override;
RicfCommandResponse execute() override;
private:
};

View File

@@ -43,8 +43,10 @@ RicfComputeCaseGroupStatistics::RicfComputeCaseGroupStatistics()
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicfComputeCaseGroupStatistics::execute()
RicfCommandResponse RicfComputeCaseGroupStatistics::execute()
{
RicfCommandResponse response;
for (int caseId : m_caseIds())
{
bool foundCase = false;
@@ -61,7 +63,9 @@ void RicfComputeCaseGroupStatistics::execute()
}
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;
break;
@@ -73,7 +77,11 @@ void RicfComputeCaseGroupStatistics::execute()
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;
}

View File

@@ -34,7 +34,7 @@ class RicfComputeCaseGroupStatistics : public RicfCommandObject
public:
RicfComputeCaseGroupStatistics();
void execute() override;
RicfCommandResponse execute() override;
private:
caf::PdmField< std::vector<int> > m_caseIds;

View File

@@ -59,7 +59,7 @@ RicfCreateLgrForCompletions::RicfCreateLgrForCompletions()
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicfCreateLgrForCompletions::execute()
RicfCommandResponse RicfCreateLgrForCompletions::execute()
{
using TOOLS = RicfApplicationTools;
@@ -71,54 +71,65 @@ void RicfCreateLgrForCompletions::execute()
wellPaths = TOOLS::wellPathsFromNames(TOOLS::toQStringList(m_wellPathNames), &wellsNotFound);
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())
{
caf::CmdFeatureManager* commandManager = caf::CmdFeatureManager::instance();
auto feature = dynamic_cast<RicCreateTemporaryLgrFeature*>(commandManager->getCommandFeature("RicCreateTemporaryLgrFeature"));
QString error("No well paths found");
RiaLogging::error(error);
return RicfCommandResponse(RicfCommandResponse::COMMAND_ERROR, error);
}
RimEclipseCase* eclipseCase = nullptr;
caf::CmdFeatureManager* commandManager = caf::CmdFeatureManager::instance();
auto feature = dynamic_cast<RicCreateTemporaryLgrFeature*>(commandManager->getCommandFeature("RicCreateTemporaryLgrFeature"));
RimEclipseCase* eclipseCase = nullptr;
{
for (RimEclipseCase* c : RiaApplication::instance()->project()->activeOilField()->analysisModels->cases())
{
for (RimEclipseCase* c : RiaApplication::instance()->project()->activeOilField()->analysisModels->cases())
if (c->caseId() == m_caseId())
{
if (c->caseId() == m_caseId())
{
eclipseCase = c;
break;
}
}
if (!eclipseCase)
{
RiaLogging::error(QString("createLgrForCompletions: Could not find case with ID %1").arg(m_caseId()));
return;
eclipseCase = c;
break;
}
}
RicDeleteTemporaryLgrsFeature::deleteAllTemporaryLgrs(eclipseCase);
caf::VecIjk lgrCellCounts(m_refinementI, m_refinementJ, m_refinementK);
QStringList wellsIntersectingOtherLgrs;
feature->createLgrsForWellPaths(
wellPaths,
eclipseCase,
m_timeStep,
lgrCellCounts,
m_splitType(),
{RigCompletionData::PERFORATION, RigCompletionData::FRACTURE, RigCompletionData::FISHBONES},
&wellsIntersectingOtherLgrs);
feature->updateViews(eclipseCase);
if (!wellsIntersectingOtherLgrs.empty())
if (!eclipseCase)
{
auto wellsList = wellsIntersectingOtherLgrs.join(", ");
RiaLogging::error(
"createLgrForCompletions: No LGRs created for some wells due to existing intersecting LGR(s).Affected wells : " +
wellsList);
QString error(QString("createLgrForCompletions: Could not find case with ID %1").arg(m_caseId()));
RiaLogging::error(error);
return RicfCommandResponse(RicfCommandResponse::COMMAND_ERROR, error);
}
}
RicDeleteTemporaryLgrsFeature::deleteAllTemporaryLgrs(eclipseCase);
caf::VecIjk lgrCellCounts(m_refinementI, m_refinementJ, m_refinementK);
QStringList wellsIntersectingOtherLgrs;
feature->createLgrsForWellPaths(
wellPaths,
eclipseCase,
m_timeStep,
lgrCellCounts,
m_splitType(),
{RigCompletionData::PERFORATION, RigCompletionData::FRACTURE, RigCompletionData::FISHBONES},
&wellsIntersectingOtherLgrs);
feature->updateViews(eclipseCase);
RicfCommandResponse response;
if (!wellsIntersectingOtherLgrs.empty())
{
auto wellsList = wellsIntersectingOtherLgrs.join(", ");
QString warning(
"createLgrForCompletions: No LGRs created for some wells due to existing intersecting LGR(s).Affected wells : " +
wellsList);
RiaLogging::warning(warning);
response.updateStatus(RicfCommandResponse::COMMAND_WARNING, warning);
}
return response;
}

View File

@@ -39,7 +39,7 @@ class RicfCreateLgrForCompletions : public RicfCommandObject
public:
RicfCreateLgrForCompletions();
void execute() override;
RicfCommandResponse execute() override;
private:
caf::PdmField<int> m_caseId;

View File

@@ -74,7 +74,7 @@ RicfCreateMultipleFractures::RicfCreateMultipleFractures()
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicfCreateMultipleFractures::execute()
RicfCommandResponse RicfCreateMultipleFractures::execute()
{
using TOOLS = RicfApplicationTools;
@@ -92,54 +92,71 @@ void RicfCreateMultipleFractures::execute()
wellPaths = TOOLS::wellPathsFromNames(TOOLS::toQStringList(m_wellPathNames), &wellsNotFound);
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)
{
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)
{
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())
{
RicCreateMultipleFracturesOptionItemUi* options = new RicCreateMultipleFracturesOptionItemUi();
caf::CmdFeatureManager* commandManager = caf::CmdFeatureManager::instance();
auto feature = dynamic_cast<RicCreateMultipleFracturesFeature*>(commandManager->getCommandFeature("RicCreateMultipleFracturesFeature"));
// Default layers
int topLayer = m_topLayer;
int baseLayer = m_baseLayer;
if (feature && (topLayer < 0 || baseLayer < 0))
{
auto ijkRange = feature->ijkRangeForGrid(gridCase);
if (topLayer < 0) topLayer = static_cast<int>(ijkRange.first.z());
if (baseLayer < 0) baseLayer = static_cast<int>(ijkRange.second.z());
}
options->setValues(topLayer, baseLayer, fractureTemplate, m_spacing);
settings->clearWellPaths();
for (auto wellPath : wellPaths)
{
settings->addWellPath(wellPath);
}
settings->setValues(gridCase, m_minDistFromWellTd, m_maxFracturesPerWell);
settings->clearOptions();
settings->insertOptionItem(nullptr, options);
if (feature)
{
if (m_action == MultipleFractures::APPEND_FRACTURES) feature->appendFractures();
if (m_action == MultipleFractures::REPLACE_FRACTURES) feature->replaceFractures();
}
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();
caf::CmdFeatureManager* commandManager = caf::CmdFeatureManager::instance();
auto feature = dynamic_cast<RicCreateMultipleFracturesFeature*>(commandManager->getCommandFeature("RicCreateMultipleFracturesFeature"));
// Default layers
int topLayer = m_topLayer;
int baseLayer = m_baseLayer;
if (feature && (topLayer < 0 || baseLayer < 0))
{
auto ijkRange = feature->ijkRangeForGrid(gridCase);
if (topLayer < 0) topLayer = static_cast<int>(ijkRange.first.z());
if (baseLayer < 0) baseLayer = static_cast<int>(ijkRange.second.z());
}
options->setValues(topLayer, baseLayer, fractureTemplate, m_spacing);
settings->clearWellPaths();
for (auto wellPath : wellPaths)
{
settings->addWellPath(wellPath);
}
settings->setValues(gridCase, m_minDistFromWellTd, m_maxFracturesPerWell);
settings->clearOptions();
settings->insertOptionItem(nullptr, options);
if (feature)
{
if (m_action == MultipleFractures::APPEND_FRACTURES) feature->appendFractures();
if (m_action == MultipleFractures::REPLACE_FRACTURES) feature->replaceFractures();
}
return RicfCommandResponse();
}
@@ -154,7 +171,6 @@ bool RicfCreateMultipleFractures::validateArguments() const
if (valid) return true;
RiaLogging::error(QString("createMultipleFractures: Mandatory argument(s) missing"));
return false;
}

View File

@@ -49,7 +49,7 @@ class RicfCreateMultipleFractures : public RicfCommandObject
public:
RicfCreateMultipleFractures();
void execute() override;
RicfCommandResponse execute() override;
private:
bool validateArguments() const;

View File

@@ -42,7 +42,7 @@ RicfCreateSaturationPressurePlots::RicfCreateSaturationPressurePlots()
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicfCreateSaturationPressurePlots::execute()
RicfCommandResponse RicfCreateSaturationPressurePlots::execute()
{
std::vector<int> caseIds = m_caseIds();
if (caseIds.empty())
@@ -58,21 +58,32 @@ void RicfCreateSaturationPressurePlots::execute()
}
}
RimProject* project = RiaApplication::instance()->project();
if (project)
if (caseIds.empty())
{
auto eclipeCases = project->eclipseCases();
for (auto c : eclipeCases)
{
auto eclipseResultCase = dynamic_cast<RimEclipseResultCase*>(c);
if (!eclipseResultCase) continue;
QString error("createSaturationPressurePlots: No cases found");
RiaLogging::error(error);
return RicfCommandResponse(RicfCommandResponse::COMMAND_ERROR, error);
}
for (auto caseId : caseIds)
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();
for (auto c : eclipeCases)
{
auto eclipseResultCase = dynamic_cast<RimEclipseResultCase*>(c);
if (!eclipseResultCase) continue;
for (auto caseId : caseIds)
{
if (c->caseId == caseId)
{
if (c->caseId == caseId)
{
RicCreateSaturationPressurePlotsFeature::createPlots(eclipseResultCase);
}
RicCreateSaturationPressurePlotsFeature::createPlots(eclipseResultCase);
}
}
}
@@ -80,4 +91,6 @@ void RicfCreateSaturationPressurePlots::execute()
RimSaturationPressurePlotCollection* collection = project->mainPlotCollection()->saturationPressurePlotCollection();
collection->updateAllRequiredEditors();
RiaGuiApplication::instance()->getOrCreateAndShowMainPlotWindow();
return RicfCommandResponse();
}

View File

@@ -34,7 +34,7 @@ class RicfCreateSaturationPressurePlots : public RicfCommandObject
public:
RicfCreateSaturationPressurePlots();
void execute() override;
RicfCommandResponse execute() override;
private:
caf::PdmField< std::vector<int> > m_caseIds;

View File

@@ -59,7 +59,7 @@ RicfExportLgrForCompletions::RicfExportLgrForCompletions()
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicfExportLgrForCompletions::execute()
RicfCommandResponse RicfExportLgrForCompletions::execute()
{
using TOOLS = RicfApplicationTools;
@@ -71,38 +71,49 @@ void RicfExportLgrForCompletions::execute()
wellPaths = TOOLS::wellPathsFromNames(TOOLS::toQStringList(m_wellPathNames), &wellsNotFound);
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 exportFolder = RicfCommandFileExecutor::instance()->getExportPath(RicfCommandFileExecutor::LGRS);
if (exportFolder.isNull())
{
exportFolder = RiaApplication::instance()->createAbsolutePathFromProjectRelativePath("LGR");
}
caf::CmdFeatureManager* commandManager = caf::CmdFeatureManager::instance();
auto feature = dynamic_cast<RicExportLgrFeature*>(commandManager->getCommandFeature("RicExportLgrFeature"));
RimEclipseCase* eclipseCase = TOOLS::caseFromId(m_caseId());
if (!eclipseCase)
{
RiaLogging::error(QString("exportLgrForCompletions: Could not find case with ID %1").arg(m_caseId()));
return;
}
caf::VecIjk lgrCellCounts(m_refinementI, m_refinementJ, m_refinementK);
QStringList wellsIntersectingOtherLgrs;
feature->exportLgrsForWellPaths(exportFolder, wellPaths, eclipseCase, m_timeStep, lgrCellCounts, m_splitType(),
{RigCompletionData::PERFORATION, RigCompletionData::FRACTURE, RigCompletionData::FISHBONES}, &wellsIntersectingOtherLgrs);
if (!wellsIntersectingOtherLgrs.empty())
{
auto wellsList = wellsIntersectingOtherLgrs.join(", ");
RiaLogging::error("exportLgrForCompletions: No export for some wells due to existing intersecting LGR(s).Affected wells : " + wellsList);
}
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);
if (exportFolder.isNull())
{
exportFolder = RiaApplication::instance()->createAbsolutePathFromProjectRelativePath("LGR");
}
caf::CmdFeatureManager* commandManager = caf::CmdFeatureManager::instance();
auto feature = dynamic_cast<RicExportLgrFeature*>(commandManager->getCommandFeature("RicExportLgrFeature"));
RimEclipseCase* eclipseCase = TOOLS::caseFromId(m_caseId());
if (!eclipseCase)
{
QString error(QString("exportLgrForCompletions: Could not find case with ID %1").arg(m_caseId()));
RiaLogging::error(error);
return RicfCommandResponse(RicfCommandResponse::COMMAND_ERROR, error);
}
caf::VecIjk lgrCellCounts(m_refinementI, m_refinementJ, m_refinementK);
QStringList wellsIntersectingOtherLgrs;
feature->exportLgrsForWellPaths(exportFolder, wellPaths, eclipseCase, m_timeStep, lgrCellCounts, m_splitType(),
{RigCompletionData::PERFORATION, RigCompletionData::FRACTURE, RigCompletionData::FISHBONES}, &wellsIntersectingOtherLgrs);
RicfCommandResponse response;
if (!wellsIntersectingOtherLgrs.empty())
{
auto wellsList = wellsIntersectingOtherLgrs.join(", ");
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;
}

View File

@@ -42,7 +42,7 @@ class RicfExportLgrForCompletions : public RicfCommandObject
public:
RicfExportLgrForCompletions();
void execute() override;
RicfCommandResponse execute() override;
private:
caf::PdmField<int> m_caseId;

View File

@@ -55,7 +55,7 @@ RicfExportMsw::RicfExportMsw()
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicfExportMsw::execute()
RicfCommandResponse RicfExportMsw::execute()
{
using TOOLS = RicfApplicationTools;
@@ -64,8 +64,9 @@ void RicfExportMsw::execute()
auto eclipseCase = TOOLS::caseFromId(m_caseId());
if (!eclipseCase)
{
RiaLogging::error(QString("exportMsw: Could not find case with ID %1.").arg(m_caseId()));
return;
QString error = QString("exportMsw: Could not find case with ID %1.").arg(m_caseId());
RiaLogging::error(error);
return RicfCommandResponse(RicfCommandResponse::COMMAND_ERROR, error);
}
QString exportFolder = RicfCommandFileExecutor::instance()->getExportPath(RicfCommandFileExecutor::COMPLETIONS);
@@ -83,9 +84,12 @@ void RicfExportMsw::execute()
RimWellPath* wellPath = RiaApplication::instance()->project()->wellPathByName(m_wellPathName);
if (!wellPath)
{
RiaLogging::error(QString("exportMsw: Could not find well path with name %1").arg(m_wellPathName()));
return;
QString error = QString("exportMsw: Could not find well path with name %1").arg(m_wellPathName());
RiaLogging::error(error);
return RicfCommandResponse(RicfCommandResponse::COMMAND_ERROR, error);
}
RicWellPathExportMswCompletionsImpl::exportWellSegmentsForAllCompletions(exportSettings, { wellPath });
return RicfCommandResponse();
}

View File

@@ -36,7 +36,7 @@ class RicfExportMsw : public RicfCommandObject
public:
RicfExportMsw();
void execute() override;
RicfCommandResponse execute() override;
private:
caf::PdmField<int> m_caseId;

View File

@@ -37,27 +37,32 @@ RicfExportMultiCaseSnapshots::RicfExportMultiCaseSnapshots()
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicfExportMultiCaseSnapshots::execute()
RicfCommandResponse RicfExportMultiCaseSnapshots::execute()
{
RiaGuiApplication* app = RiaGuiApplication::instance();
if (!app)
{
RiaLogging::error("exportMultiCaseSnapshots: Requires GUI Application");
return;
QString error("exportMultiCaseSnapshots: Requires GUI Application");
RiaLogging::error(error);
return RicfCommandResponse(RicfCommandResponse::COMMAND_ERROR, error);
}
if (m_gridListFile().isNull())
{
RiaLogging::error("exportMultiCaseSnapshots: Required parameter gridListFile.");
return;
QString error("exportMultiCaseSnapshots: Required parameter gridListFile.");
RiaLogging::error(error);
return RicfCommandResponse(RicfCommandResponse::COMMAND_ERROR, error);
}
QString lastProjectPath = RicfCommandFileExecutor::instance()->getLastProjectPath();
if (lastProjectPath.isNull())
{
RiaLogging::error("exportMultiCaseSnapshots: 'openProject' must be called before 'exportMultiCaseSnapshots' to specify project file to replace cases in.");
return;
QString error("exportMultiCaseSnapshots: 'openProject' must be called before 'exportMultiCaseSnapshots' to specify project file to replace cases in.");
RiaLogging::error(error);
return RicfCommandResponse(RicfCommandResponse::COMMAND_ERROR, error);
}
std::vector<QString> listFileNames = RiaApplication::readFileListFromTextFile(m_gridListFile());
app->runMultiCaseSnapshots(lastProjectPath, listFileNames, RicfCommandFileExecutor::instance()->getExportPath(RicfCommandFileExecutor::SNAPSHOTS));
return RicfCommandResponse();
}

View File

@@ -34,7 +34,7 @@ class RicfExportMultiCaseSnapshots : public RicfCommandObject
public:
RicfExportMultiCaseSnapshots();
void execute() override;
RicfCommandResponse execute() override;
private:
caf::PdmField<QString> m_gridListFile;

View File

@@ -59,7 +59,7 @@ RicfExportProperty::RicfExportProperty()
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicfExportProperty::execute()
RicfCommandResponse RicfExportProperty::execute()
{
using TOOLS = RicfApplicationTools;
@@ -67,16 +67,18 @@ void RicfExportProperty::execute()
{
if (!eclipseCase)
{
RiaLogging::error(QString("exportProperty: Could not find case with ID %1").arg(m_caseId()));
return;
QString error = QString("exportProperty: Could not find case with ID %1").arg(m_caseId());
RiaLogging::error(error);
return RicfCommandResponse(RicfCommandResponse::COMMAND_ERROR, error);
}
if (!eclipseCase->eclipseCaseData())
{
if (!eclipseCase->openReserviorCase())
{
RiaLogging::error(QString("exportProperty: Could not find eclipseCaseData with ID %1").arg(m_caseId()));
return;
QString error = QString("exportProperty: Could not find eclipseCaseData with ID %1").arg(m_caseId());
RiaLogging::error(error);
return RicfCommandResponse(RicfCommandResponse::COMMAND_ERROR, error);
}
}
}
@@ -87,8 +89,9 @@ void RicfExportProperty::execute()
if (!cellResultsData->ensureKnownResultLoaded(RigEclipseResultAddress(m_propertyName)))
{
RiaLogging::error(QString("exportProperty: Could not find result property : %1").arg(m_propertyName()));
return;
QString error = QString("exportProperty: Could not find result property : %1").arg(m_propertyName());
RiaLogging::error(error);
return RicfCommandResponse(RicfCommandResponse::COMMAND_ERROR, error);
}
QString filePath = m_exportFileName;
@@ -106,6 +109,13 @@ void RicfExportProperty::execute()
eclipseKeyword = m_propertyName;
}
RicEclipseCellResultToFileImpl::writePropertyToTextFile(
filePath, eclipseCase->eclipseCaseData(), m_timeStepIndex, m_propertyName, eclipseKeyword, m_undefinedValue);
QString errMsg;
if (!RicEclipseCellResultToFileImpl::writePropertyToTextFile(
filePath, eclipseCase->eclipseCaseData(), m_timeStepIndex, m_propertyName, eclipseKeyword, m_undefinedValue,
&errMsg))
{
return RicfCommandResponse(RicfCommandResponse::COMMAND_ERROR, errMsg);
}
return RicfCommandResponse();
}

View File

@@ -38,7 +38,7 @@ class RicfExportProperty : public RicfCommandObject
public:
RicfExportProperty();
void execute() override;
RicfCommandResponse execute() override;
private:
caf::PdmField<int> m_caseId;

View File

@@ -55,15 +55,16 @@ RicfExportPropertyInViews::RicfExportPropertyInViews()
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicfExportPropertyInViews::execute()
RicfCommandResponse RicfExportPropertyInViews::execute()
{
using TOOLS = RicfApplicationTools;
RimEclipseCase* eclipseCase = TOOLS::caseFromId(m_caseId());
if (!eclipseCase)
{
RiaLogging::error(QString("exportProperty: Could not find case with ID %1").arg(m_caseId()));
return;
QString error(QString("exportProperty: Could not find case with ID %1").arg(m_caseId()));
RiaLogging::error(error);
return RicfCommandResponse(RicfCommandResponse::COMMAND_ERROR, error);
}
std::vector<RimEclipseView*> viewsForExport;
@@ -95,6 +96,8 @@ void RicfExportPropertyInViews::execute()
}
}
RicfCommandResponse response;
for (const auto& view : viewsForExport)
{
cvf::ref<RigResultAccessor> resultAccessor = nullptr;
@@ -109,11 +112,12 @@ void RicfExportPropertyInViews::execute()
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(view->currentTimeStep())
.arg(propertyName));
.arg(propertyName);
RiaLogging::warning(warning);
response.updateStatus(RicfCommandResponse::COMMAND_WARNING, warning);
continue;
}
@@ -128,11 +132,19 @@ void RicfExportPropertyInViews::execute()
fileName = caf::Utils::makeValidFileBasename(fileName);
const QString filePath = propertiesDir.filePath(fileName);
RicEclipseCellResultToFileImpl::writeResultToTextFile(filePath,
eclipseCase->eclipseCaseData(),
resultAccessor.p(),
propertyName,
m_undefinedValue,
"exportPropertiesInViews");
QString errorMsg;
bool worked = RicEclipseCellResultToFileImpl::writeResultToTextFile(filePath,
eclipseCase->eclipseCaseData(),
resultAccessor.p(),
propertyName,
m_undefinedValue,
"exportPropertiesInViews",
&errorMsg);
if (!worked)
{
return RicfCommandResponse(RicfCommandResponse::COMMAND_ERROR, errorMsg);
}
}
return response;
}

View File

@@ -40,7 +40,7 @@ class RicfExportPropertyInViews : public RicfCommandObject
public:
RicfExportPropertyInViews();
void execute() override;
RicfCommandResponse execute() override;
private:
caf::PdmField<int> m_caseId;

View File

@@ -56,7 +56,7 @@ RicfExportSimWellFractureCompletions::RicfExportSimWellFractureCompletions()
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicfExportSimWellFractureCompletions::execute()
RicfCommandResponse RicfExportSimWellFractureCompletions::execute()
{
using TOOLS = RicfApplicationTools;
@@ -71,8 +71,9 @@ void RicfExportSimWellFractureCompletions::execute()
auto eclipseCase = TOOLS::caseFromId(m_caseId());
if (!eclipseCase)
{
RiaLogging::error(QString("exportSimWellCompletions: Could not find case with ID %1").arg(m_caseId()));
return;
QString error = QString("exportSimWellCompletions: Could not find case with ID %1").arg(m_caseId());
RiaLogging::error(error);
return RicfCommandResponse(RicfCommandResponse::COMMAND_ERROR, error);
}
exportSettings->caseToApply = eclipseCase;
}
@@ -95,10 +96,13 @@ void RicfExportSimWellFractureCompletions::execute()
}
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()));
return;
QString error = QString("exportSimWellCompletions: Could not find any views named \"%1\" in the case with ID %2").arg(m_viewName).arg(m_caseId());
RiaLogging::error(error);
return RicfCommandResponse(RicfCommandResponse::COMMAND_ERROR, error);
}
RicfCommandResponse response;
std::vector<RimSimWellInView*> simWells;
if (m_simWellNames().empty())
{
@@ -126,7 +130,9 @@ void RicfExportSimWellFractureCompletions::execute()
}
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;
RicWellPathExportCompletionDataFeatureImpl::exportCompletions(wellPaths, simWells, *exportSettings);
return response;
}

View File

@@ -37,7 +37,7 @@ class RicfExportSimWellFractureCompletions : public RicfCommandObject
public:
RicfExportSimWellFractureCompletions();
void execute() override;
RicfCommandResponse execute() override;
private:
caf::PdmField<int> m_caseId;

View File

@@ -56,12 +56,13 @@ RicfExportSnapshots::RicfExportSnapshots()
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicfExportSnapshots::execute()
RicfCommandResponse RicfExportSnapshots::execute()
{
if (!RiaGuiApplication::isRunning())
{
RiaLogging::error(QString("RicfExportSnapshot: Command cannot run without a GUI"));
return;
QString error("RicfExportSnapshot: Command cannot run without a GUI");
RiaLogging::error(error);
return RicfCommandResponse(RicfCommandResponse::COMMAND_ERROR, error);
}
RiuMainWindow* mainWnd = RiuMainWindow::instance();
@@ -85,4 +86,6 @@ void RicfExportSnapshots::execute()
mainWnd->loadWinGeoAndDockToolBarLayout();
RiaGuiApplication::instance()->processEvents();
return RicfCommandResponse();
}

View File

@@ -44,7 +44,7 @@ public:
public:
RicfExportSnapshots();
void execute() override;
RicfCommandResponse execute() override;
private:
caf::PdmField<SnapshotsTypeEnum> m_type;

View File

@@ -75,19 +75,21 @@ RicfExportVisibleCells::RicfExportVisibleCells()
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicfExportVisibleCells::execute()
RicfCommandResponse RicfExportVisibleCells::execute()
{
if (m_caseId < 0 || m_viewName().isEmpty())
{
RiaLogging::error("exportVisibleCells: CaseId or view name not specified");
return;
QString error("exportVisibleCells: CaseId or view name not specified");
RiaLogging::error(error);
return RicfCommandResponse(RicfCommandResponse::COMMAND_ERROR, error);
}
auto eclipseView = RicfApplicationTools::viewFromCaseIdAndViewName(m_caseId, m_viewName);
if (!eclipseView)
{
RiaLogging::error(QString("exportVisibleCells: Could not find view '%1' in case ID %2").arg(m_viewName).arg(m_caseId));
return;
QString error(QString("exportVisibleCells: Could not find view '%1' in case ID %2").arg(m_viewName).arg(m_caseId));
RiaLogging::error(error);
return RicfCommandResponse(RicfCommandResponse::COMMAND_ERROR, error);
}
QString exportFolder = RicfCommandFileExecutor::instance()->getExportPath(RicfCommandFileExecutor::CELLS);
@@ -101,6 +103,8 @@ void RicfExportVisibleCells::execute()
RicSaveEclipseInputVisibleCellsUi exportSettings;
buildExportSettings(exportFolder, &exportSettings);
RicSaveEclipseInputVisibleCellsFeature::executeCommand(eclipseView, exportSettings, "exportVisibleCells");
return RicfCommandResponse();
}
//--------------------------------------------------------------------------------------------------

View File

@@ -45,7 +45,7 @@ class RicfExportVisibleCells : public RicfCommandObject
public:
RicfExportVisibleCells();
void execute() override;
RicfCommandResponse execute() override;
private:
void buildExportSettings(const QString& exportFolder, RicSaveEclipseInputVisibleCellsUi* exportSettings);

View File

@@ -65,7 +65,7 @@ RicfExportWellPathCompletions::RicfExportWellPathCompletions()
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicfExportWellPathCompletions::execute()
RicfCommandResponse RicfExportWellPathCompletions::execute()
{
using TOOLS = RicfApplicationTools;
@@ -101,8 +101,9 @@ void RicfExportWellPathCompletions::execute()
auto eclipseCase = TOOLS::caseFromId(m_caseId());
if (!eclipseCase)
{
RiaLogging::error(QString("exportWellPathCompletions: Could not find case with ID %1").arg(m_caseId()));
return;
QString error = QString("exportWellPathCompletions: Could not find case with ID %1").arg(m_caseId());
RiaLogging::error(error);
return RicfCommandResponse(RicfCommandResponse::COMMAND_ERROR, error);
}
exportSettings->caseToApply = eclipseCase;
}
@@ -114,6 +115,8 @@ void RicfExportWellPathCompletions::execute()
}
exportSettings->folder = exportFolder;
RicfCommandResponse response;
std::vector<RimWellPath*> wellPaths;
if (m_wellPathNames().empty())
{
@@ -136,7 +139,9 @@ void RicfExportWellPathCompletions::execute()
}
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;
RicWellPathExportCompletionDataFeatureImpl::exportCompletions(wellPaths, simWells, *exportSettings);
return response;
}

View File

@@ -37,7 +37,7 @@ class RicfExportWellPathCompletions : public RicfCommandObject
public:
RicfExportWellPathCompletions();
void execute() override;
RicfCommandResponse execute() override;
private:
caf::PdmField<int> m_caseId;

View File

@@ -52,7 +52,7 @@ RicfExportWellPaths::RicfExportWellPaths()
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicfExportWellPaths::execute()
RicfCommandResponse RicfExportWellPaths::execute()
{
using TOOLS = RicfApplicationTools;
@@ -64,27 +64,34 @@ void RicfExportWellPaths::execute()
wellPaths = TOOLS::wellPathsFromNames(TOOLS::toQStringList(m_wellPathNames), &wellsNotFound);
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 exportFolder = RicfCommandFileExecutor::instance()->getExportPath(RicfCommandFileExecutor::WELLPATHS);
if (exportFolder.isNull())
{
exportFolder = RiaApplication::instance()->createAbsolutePathFromProjectRelativePath("wellpaths");
}
QString error("No well paths found");
RiaLogging::error(error);
return RicfCommandResponse(RicfCommandResponse::COMMAND_ERROR, error);
}
caf::CmdFeatureManager* commandManager = caf::CmdFeatureManager::instance();
auto feature = dynamic_cast<RicExportSelectedWellPathsFeature*>(commandManager->getCommandFeature("RicExportSelectedWellPathsFeature"));
QString exportFolder = RicfCommandFileExecutor::instance()->getExportPath(RicfCommandFileExecutor::WELLPATHS);
if (exportFolder.isNull())
{
exportFolder = RiaApplication::instance()->createAbsolutePathFromProjectRelativePath("wellpaths");
}
for (const auto wellPath : wellPaths)
caf::CmdFeatureManager* commandManager = caf::CmdFeatureManager::instance();
auto feature = dynamic_cast<RicExportSelectedWellPathsFeature*>(commandManager->getCommandFeature("RicExportSelectedWellPathsFeature"));
for (const auto wellPath : wellPaths)
{
if (wellPath)
{
if (wellPath)
{
feature->exportWellPath(wellPath, m_mdStepSize, exportFolder, false);
}
feature->exportWellPath(wellPath, m_mdStepSize, exportFolder, false);
}
}
return RicfCommandResponse();
}

View File

@@ -37,7 +37,7 @@ class RicfExportWellPaths : public RicfCommandObject
public:
RicfExportWellPaths();
void execute() override;
RicfCommandResponse execute() override;
private:
caf::PdmField<std::vector<QString>> m_wellPathNames;

View File

@@ -37,11 +37,14 @@ RicfLoadCase::RicfLoadCase()
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicfLoadCase::execute()
RicfCommandResponse RicfLoadCase::execute()
{
bool ok = RiaImportEclipseCaseTools::openEclipseCasesFromFile(QStringList({m_path()}), nullptr, true);
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();
}

View File

@@ -34,7 +34,7 @@ class RicfLoadCase : public RicfCommandObject
public:
RicfLoadCase();
void execute() override;
RicfCommandResponse execute() override;
private:
caf::PdmField<QString> m_path;

View File

@@ -40,7 +40,7 @@ RicfOpenProject::RicfOpenProject()
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicfOpenProject::execute()
RicfCommandResponse RicfOpenProject::execute()
{
QString projectPath = m_path;
QFileInfo projectPathInfo(projectPath);
@@ -52,8 +52,9 @@ void RicfOpenProject::execute()
bool ok = RiaApplication::instance()->loadProject(projectPath);
if (!ok)
{
RiaLogging::error(QString("openProject: Unable to open project at %1").arg(m_path()));
return;
QString errMsg = QString("openProject: Unable to open project at %1").arg(m_path());
RiaLogging::error(errMsg);
return RicfCommandResponse(RicfCommandResponse::COMMAND_ERROR, errMsg);
}
if (RiaRegressionTestRunner::instance()->isRunningRegressionTests())
@@ -62,4 +63,6 @@ void RicfOpenProject::execute()
}
RicfCommandFileExecutor::instance()->setLastProjectPath(projectPath);
return RicfCommandResponse();
}

View File

@@ -34,7 +34,7 @@ class RicfOpenProject : public RicfCommandObject
public:
RicfOpenProject();
void execute() override;
RicfCommandResponse execute() override;
private:
caf::PdmField<QString> m_path;

View File

@@ -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
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())
{
RiaLogging::error("replaceCaseImpl: No replacements available.");
return;
QString errMsg("replaceCaseImpl: No replacements available.");
RiaLogging::error(errMsg);
return RicfCommandResponse(RicfCommandResponse::COMMAND_ERROR, errMsg);
}
QString lastProjectPath = RicfCommandFileExecutor::instance()->getLastProjectPath();
if (lastProjectPath.isNull())
{
RiaLogging::error("replaceCase: 'openProject' must be called before 'replaceCase' to specify project file to replace case in.");
return;
QString errMsg("replaceCase: 'openProject' must be called before 'replaceCase' to specify project file to replace case in.");
RiaLogging::error(errMsg);
return RicfCommandResponse(RicfCommandResponse::COMMAND_ERROR, errMsg);
}
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();
}

View File

@@ -40,7 +40,7 @@ public:
int caseId() const;
QString filePath() const;
void execute() override;
RicfCommandResponse execute() override;
private:
caf::PdmField<QString> m_newGridFile;
@@ -63,7 +63,7 @@ public:
void setCaseReplacePairs(const std::map<int, QString>& caseIdToGridFileNameMap);
void execute() override;
RicfCommandResponse execute() override;
private:
std::map<int, QString> m_caseIdToGridFileNameMap;

View File

@@ -38,19 +38,21 @@ RicfReplaceSourceCases::RicfReplaceSourceCases()
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicfReplaceSourceCases::execute()
RicfCommandResponse RicfReplaceSourceCases::execute()
{
if (m_gridListFile().isNull())
{
RiaLogging::error("replaceSourceCases: Required parameter gridListFile.");
return;
QString error("replaceSourceCases: Required parameter gridListFile.");
RiaLogging::error(error);
return RicfCommandResponse(RicfCommandResponse::COMMAND_ERROR, error);
}
QString lastProjectPath = RicfCommandFileExecutor::instance()->getLastProjectPath();
if (lastProjectPath.isNull())
{
RiaLogging::error("replaceSourceCases: 'openProject' must be called before 'replaceSourceCases' to specify project file to replace cases in.");
return;
QString error("replaceSourceCases: 'openProject' must be called before 'replaceSourceCases' to specify project file to replace cases in.");
RiaLogging::error(error);
return RicfCommandResponse(RicfCommandResponse::COMMAND_ERROR, error);
}
cvf::ref<RiaProjectModifier> projectModifier = new RiaProjectModifier;
@@ -65,5 +67,11 @@ void RicfReplaceSourceCases::execute()
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();
}

View File

@@ -34,7 +34,7 @@ class RicfReplaceSourceCases : public RicfCommandObject
public:
RicfReplaceSourceCases();
void execute() override;
RicfCommandResponse execute() override;
private:
caf::PdmField<QString> m_gridListFile;

View File

@@ -42,7 +42,7 @@ RicfRunOctaveScript::RicfRunOctaveScript()
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicfRunOctaveScript::execute()
RicfCommandResponse RicfRunOctaveScript::execute()
{
QString octavePath = RiaApplication::instance()->octavePath();
@@ -71,12 +71,17 @@ void RicfRunOctaveScript::execute()
{
ok = RiaApplication::instance()->launchProcessForMultipleCases(octavePath, processArguments, caseIds);
}
RicfCommandResponse response;
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
{
RiaApplication::instance()->waitForProcess();
}
return response;
}

View File

@@ -34,7 +34,7 @@ class RicfRunOctaveScript : public RicfCommandObject
public:
RicfRunOctaveScript();
void execute() override;
RicfCommandResponse execute() override;
private:
caf::PdmField<QString> m_path;

View File

@@ -49,20 +49,22 @@ RicfScaleFractureTemplate::RicfScaleFractureTemplate()
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicfScaleFractureTemplate::execute()
RicfCommandResponse RicfScaleFractureTemplate::execute()
{
if (m_id < 0)
{
RiaLogging::error("scaleFractureTemplate: Fracture template id not specified");
return;
QString error("scaleFractureTemplate: Fracture template id not specified");
RiaLogging::error(error);
return RicfCommandResponse(RicfCommandResponse::COMMAND_ERROR, error);
}
RimProject* project = RiaApplication::instance()->project();
if (!project)
{
RiaLogging::error("scaleFractureTemplate: Project not found");
return;
QString error("scaleFractureTemplate: Project not found");
RiaLogging::error(error);
return RicfCommandResponse(RicfCommandResponse::COMMAND_ERROR, error);
}
RimFractureTemplateCollection* templColl =
@@ -71,12 +73,14 @@ void RicfScaleFractureTemplate::execute()
if (!templ)
{
RiaLogging::error(QString("scaleFractureTemplate: Fracture template not found. Id=%1").arg(m_id));
return;
QString error = QString("scaleFractureTemplate: Fracture template not found. Id=%1").arg(m_id);
RiaLogging::error(error);
return RicfCommandResponse(RicfCommandResponse::COMMAND_ERROR, error);
}
templ->setScaleFactors(m_halfLengthScaleFactor, m_heightScaleFactor, m_dFactorScaleFactor, m_conductivityScaleFactor);
templ->loadDataAndUpdateGeometryHasChanged();
return RicfCommandResponse();
}
//--------------------------------------------------------------------------------------------------

View File

@@ -36,7 +36,7 @@ class RicfScaleFractureTemplate : public RicfCommandObject
public:
RicfScaleFractureTemplate();
void execute() override;
RicfCommandResponse execute() override;
private:
void initAfterRead() override;

View File

@@ -40,7 +40,7 @@ RicfSetExportFolder::RicfSetExportFolder()
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicfSetExportFolder::execute()
RicfCommandResponse RicfSetExportFolder::execute()
{
if (m_createFolder)
{
@@ -52,11 +52,14 @@ void RicfSetExportFolder::execute()
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();
executor->setExportPath(m_type(), m_path);
return RicfCommandResponse();
}

View File

@@ -36,7 +36,7 @@ class RicfSetExportFolder : public RicfCommandObject
public:
RicfSetExportFolder();
void execute() override;
RicfCommandResponse execute() override;
private:
caf::PdmField<RicfCommandFileExecutor::ExportTypeEnum> m_type;

View File

@@ -41,20 +41,22 @@ RicfSetFractureContainment::RicfSetFractureContainment()
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicfSetFractureContainment::execute()
RicfCommandResponse RicfSetFractureContainment::execute()
{
if (m_id < 0 || m_topLayer < 0 || m_baseLayer < 0)
{
RiaLogging::error("setFractureContainment: Required argument missing");
return;
QString error("setFractureContainment: Required argument missing");
RiaLogging::error(error);
return RicfCommandResponse(RicfCommandResponse::COMMAND_ERROR, error);
}
RimProject* project = RiaApplication::instance()->project();
if (!project)
{
RiaLogging::error("setFractureContainment: Project not found");
return;
QString error("setFractureContainment: Project not found");
RiaLogging::error(error);
return RicfCommandResponse(RicfCommandResponse::COMMAND_ERROR, error);
}
RimFractureTemplateCollection* templColl = !project->allFractureTemplateCollections().empty() ? project->allFractureTemplateCollections()[0] : nullptr;
@@ -62,11 +64,13 @@ void RicfSetFractureContainment::execute()
if (!templ)
{
RiaLogging::error(QString("setFractureContainment: Fracture template not found. Id=%1").arg(m_id));
return;
QString error = QString("setFractureContainment: Fracture template not found. Id=%1").arg(m_id);
RiaLogging::error(error);
return RicfCommandResponse(RicfCommandResponse::COMMAND_ERROR, error);
}
templ->setContainmentTopKLayer(m_topLayer);
templ->setContainmentBaseKLayer(m_baseLayer);
templ->loadDataAndUpdateGeometryHasChanged();
return RicfCommandResponse();
}

View File

@@ -36,7 +36,7 @@ class RicfSetFractureContainment : public RicfCommandObject
public:
RicfSetFractureContainment();
void execute() override;
RicfCommandResponse execute() override;
private:
caf::PdmField<int> m_id;

View File

@@ -35,7 +35,8 @@ RicfSetMainWindowSize::RicfSetMainWindowSize()
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicfSetMainWindowSize::execute()
RicfCommandResponse RicfSetMainWindowSize::execute()
{
RiuMainWindow::instance()->resize(m_width, m_height);
return RicfCommandResponse();
}

View File

@@ -34,7 +34,7 @@ class RicfSetMainWindowSize : public RicfCommandObject
public:
RicfSetMainWindowSize();
void execute() override;
RicfCommandResponse execute() override;
private:
caf::PdmField<int> m_height;

View File

@@ -20,6 +20,8 @@
#include "RiaApplication.h"
#include <QDir>
CAF_PDM_SOURCE_INIT(RicfSetStartDir, "setStartDir");
//--------------------------------------------------------------------------------------------------
@@ -33,7 +35,22 @@ RicfSetStartDir::RicfSetStartDir()
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicfSetStartDir::execute()
RicfCommandResponse RicfSetStartDir::execute()
{
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();
}

View File

@@ -34,7 +34,7 @@ class RicfSetStartDir : public RicfCommandObject
public:
RicfSetStartDir();
void execute() override;
RicfCommandResponse execute() override;
private:
caf::PdmField<QString> m_path;

View File

@@ -57,7 +57,7 @@ void RicfSetTimeStep::setTimeStepIndex(int timeStepIndex)
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicfSetTimeStep::execute()
RicfCommandResponse RicfSetTimeStep::execute()
{
RimEclipseCase* eclipseCase = nullptr;
@@ -74,14 +74,28 @@ void RicfSetTimeStep::execute()
}
if (!foundCase)
{
RiaLogging::error(QString("setTimeStep: Could not find case with ID %1").arg(m_caseId()));
return;
QString error = QString("setTimeStep: Could not find case with ID %1").arg(m_caseId());
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())
{
view->setCurrentTimeStepAndUpdate(m_timeStepIndex);
view->createDisplayModelAndRedraw();
}
return RicfCommandResponse();
}

View File

@@ -37,7 +37,7 @@ public:
void setCaseId(int caseId);
void setTimeStepIndex(int timeStepIndex);
void execute() override;
RicfCommandResponse execute() override;
private:

View File

@@ -39,7 +39,8 @@ bool RicEclipseCellResultToFileImpl::writePropertyToTextFile(const QString&
size_t timeStep,
const QString& resultName,
const QString& eclipseKeyword,
const double undefinedValue)
const double undefinedValue,
QString* errorMsg)
{
CVF_TIGHT_ASSERT(eclipseCase);
if (!eclipseCase) return false;
@@ -52,7 +53,7 @@ bool RicEclipseCellResultToFileImpl::writePropertyToTextFile(const QString&
}
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,
const QString& eclipseKeyword,
const double undefinedValue,
const QString& logPrefix)
const QString& logPrefix,
QString* errorMsg)
{
CVF_TIGHT_ASSERT(eclipseCase);
@@ -75,7 +77,7 @@ bool RicEclipseCellResultToFileImpl::writeBinaryResultToTextFile(const QString&
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,
const QString& eclipseKeyword,
const double undefinedValue,
const QString& logPrefix)
const QString& logPrefix,
QString* errorMsg)
{
CAF_ASSERT(errorMsg != nullptr);
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;
}
QFile file(fileName);
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;
}

View File

@@ -39,7 +39,8 @@ public:
size_t timeStep,
const QString& resultName,
const QString& eclipseKeyword,
const double undefinedValue);
const double undefinedValue,
QString* errorMsg);
static bool writeBinaryResultToTextFile(const QString& fileName,
RigEclipseCaseData* eclipseCase,
@@ -47,14 +48,16 @@ public:
RimEclipseResultDefinition* resultDefinition,
const QString& eclipseKeyword,
const double undefinedValue,
const QString& logPrefix);
const QString& logPrefix,
QString* errorMsg);
static bool writeResultToTextFile(const QString& fileName,
RigEclipseCaseData* eclipseCase,
RigResultAccessor* resultAccessor,
const QString& eclipseKeyword,
const double undefinedValue,
const QString& logPrefix);
const QString& logPrefix,
QString* errorMsg);
static void writeDataToTextFile(QFile* file, const QString& eclipseKeyword, const std::vector<double>& resultData);
};

View File

@@ -107,20 +107,26 @@ void RicSaveEclipseInputPropertyFeature::onActionTriggered(bool isChecked)
{
const double undefinedValue = 0.0;
bool isOk = RicEclipseCellResultToFileImpl::writePropertyToTextFile(exportSettings.fileName,
QString errorMsg;
bool isOk = RicEclipseCellResultToFileImpl::writePropertyToTextFile(exportSettings.fileName,
inputReservoir->eclipseCaseData(),
0,
inputProperty->resultName,
exportSettings.eclipseKeyword,
undefinedValue);
undefinedValue,
&errorMsg);
if (isOk)
{
inputProperty->fileName = exportSettings.fileName;
inputProperty->fileName = exportSettings.fileName;
inputProperty->eclipseKeyword = exportSettings.eclipseKeyword;
inputProperty->resolvedState = RimEclipseInputProperty::RESOLVED;
inputProperty->resolvedState = RimEclipseInputProperty::RESOLVED;
inputProperty->updateConnectedEditors();
}
else
{
RiaLogging::error(errorMsg);
}
}
}

View File

@@ -97,10 +97,12 @@ void RicSaveEclipseResultAsInputPropertyExec::redo()
{
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)
{
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);
}
}
}

View File

@@ -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;
}
}