System command command file merger (#4845)

* Move Import WellPaths command-file functionality into RicImportWellPaths

* Add new RICF_init macros for command file objects

* Make project save commands available in Python

* Fix RiaLogging build errors

* Move RiaLogging include from RiaGrpcServer.h to cpp file
This commit is contained in:
Gaute Lindkvist
2019-10-15 15:46:19 +02:00
committed by GitHub
parent f24543ce56
commit d3140b6aac
18 changed files with 349 additions and 237 deletions

View File

@@ -34,7 +34,6 @@ ${CMAKE_CURRENT_LIST_DIR}/RicfCreateStatisticsCase.h
${CMAKE_CURRENT_LIST_DIR}/RicfCreateView.h
${CMAKE_CURRENT_LIST_DIR}/RicfCloneView.h
${CMAKE_CURRENT_LIST_DIR}/RicfNewWellBoreStabilityPlotFeature.h
${CMAKE_CURRENT_LIST_DIR}/RicfImportWellPaths.h
${CMAKE_CURRENT_LIST_DIR}/RicfImportWellLogFiles.h
${CMAKE_CURRENT_LIST_DIR}/RicfImportFormationNames.h
${CMAKE_CURRENT_LIST_DIR}/RicfExportWellLogPlotData.h
@@ -75,7 +74,6 @@ ${CMAKE_CURRENT_LIST_DIR}/RicfCreateStatisticsCase.cpp
${CMAKE_CURRENT_LIST_DIR}/RicfCreateView.cpp
${CMAKE_CURRENT_LIST_DIR}/RicfCloneView.cpp
${CMAKE_CURRENT_LIST_DIR}/RicfCreateWellBoreStabilityPlotFeature.cpp
${CMAKE_CURRENT_LIST_DIR}/RicfImportWellPaths.cpp
${CMAKE_CURRENT_LIST_DIR}/RicfImportWellLogFiles.cpp
${CMAKE_CURRENT_LIST_DIR}/RicfImportFormationNames.cpp
${CMAKE_CURRENT_LIST_DIR}/RicfExportWellLogPlotData.cpp

View File

@@ -20,6 +20,7 @@
#include "RicfCommandResponse.h"
#include "RicfFieldCapability.h"
#include "RicfObjectCapability.h"
#include "cafCmdFeature.h"
#include "cafPdmObject.h"
#define RICF_InitField( field, keyword, default, uiName, iconResourceName, toolTip, whatsThis ) \
@@ -30,6 +31,20 @@
CAF_PDM_InitFieldNoDefault( field, keyword, uiName, iconResourceName, toolTip, whatsThis ); \
AddRicfCapabilityToField( field )
#define RICF_HEADER_INIT \
CAF_CMD_HEADER_INIT; \
CAF_PDM_HEADER_INIT
// RICF_SOURCE_INIT calls CAF_FACTORY_REGISTER2 to avoid name conflicts with CAF_PDM_SOURCE_INIT
#define RICF_SOURCE_INIT( ClassName, CommandIdName, CommandKeyword ) \
const std::string& ClassName::idNameStatic() \
{ \
static std::string id = CommandIdName; \
return id; \
} \
CAF_FACTORY_REGISTER2( caf::CmdFeature, ClassName, std::string, ClassName::idNameStatic() ); \
CAF_PDM_SOURCE_INIT( ClassName, CommandKeyword )
//==================================================================================================
//
//

View File

@@ -48,7 +48,17 @@ RicfCommandResponse::Status RicfCommandResponse::status() const
//--------------------------------------------------------------------------------------------------
QString RicfCommandResponse::sanitizedResponseMessage() const
{
return m_messages.join( ";;" );
QString completeMessage = m_messages.join( ";;" );
completeMessage.replace( '\n', ";;" );
return completeMessage;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QStringList RicfCommandResponse::messages() const
{
return m_messages;
}
//--------------------------------------------------------------------------------------------------
@@ -72,11 +82,11 @@ void RicfCommandResponse::setResult( caf::PdmObject* result )
//--------------------------------------------------------------------------------------------------
void RicfCommandResponse::updateStatus( Status status, const QString& message )
{
QString cleanedMessage = message;
cleanedMessage.replace( '\n', ";;" );
m_status = std::max( m_status, status );
if ( !message.isEmpty() )
m_messages.push_back( QString( "%1: %2" ).arg( statusLabel( status ) ).arg( cleanedMessage ) );
{
m_messages.push_back( QString( "%1: %2" ).arg( statusLabel( status ) ).arg( message ) );
}
}
//--------------------------------------------------------------------------------------------------
@@ -87,9 +97,9 @@ QString RicfCommandResponse::statusLabel( Status status )
switch ( status )
{
case COMMAND_WARNING:
return "WARNING";
return "Warning";
case COMMAND_ERROR:
return "ERROR";
return "Error";
default:
return "";
}

View File

@@ -47,6 +47,7 @@ public:
Status status() const;
QString sanitizedResponseMessage() const;
QStringList messages() const;
caf::PdmObject* result() const;
void setResult( caf::PdmObject* result );
void updateStatus( Status status, const QString& message );

View File

@@ -1,116 +0,0 @@
/////////////////////////////////////////////////////////////////////////////////
//
// 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 "RicfImportWellPaths.h"
#include "WellPathCommands/RicImportWellPaths.h"
#include "RimFileWellPath.h"
#include <QDir>
#include <QFileInfo>
#include <QStringList>
CAF_PDM_SOURCE_INIT( RicfImportWellPathsResult, "importWellPathsResult" );
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RicfImportWellPathsResult::RicfImportWellPathsResult()
{
CAF_PDM_InitObject( "well_path_result", "", "", "" );
CAF_PDM_InitFieldNoDefault( &wellPathNames, "wellPathNames", "", "", "", "" );
}
CAF_PDM_SOURCE_INIT( RicfImportWellPaths, "importWellPaths" );
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RicfImportWellPaths::RicfImportWellPaths()
{
RICF_InitFieldNoDefault( &m_wellPathFolder, "wellPathFolder", "", "", "", "" );
RICF_InitFieldNoDefault( &m_wellPathFiles, "wellPathFiles", "", "", "", "" );
}
RicfCommandResponse RicfImportWellPaths::execute()
{
QStringList errorMessages, warningMessages;
QStringList wellPathFiles;
QDir wellPathFolder( m_wellPathFolder );
if ( wellPathFolder.exists() )
{
QStringList nameFilters;
nameFilters << RicImportWellPaths::wellPathNameFilters();
QStringList relativePaths = wellPathFolder.entryList( nameFilters, QDir::Files | QDir::NoDotAndDotDot );
for ( QString relativePath : relativePaths )
{
wellPathFiles.push_back( wellPathFolder.absoluteFilePath( relativePath ) );
}
}
else
{
errorMessages << ( m_wellPathFolder() + " does not exist" );
}
for ( QString wellPathFile : m_wellPathFiles() )
{
if ( QFileInfo::exists( wellPathFile ) )
{
wellPathFiles.push_back( wellPathFile );
}
else
{
errorMessages << ( wellPathFile + " does not exist" );
}
}
RicfCommandResponse response;
if ( !wellPathFiles.empty() )
{
std::vector<RimFileWellPath*> importedWellPaths = RicImportWellPaths::importWellPaths( wellPathFiles,
&warningMessages );
if ( !importedWellPaths.empty() )
{
RicfImportWellPathsResult* wellPathsResult = new RicfImportWellPathsResult;
for ( RimFileWellPath* wellPath : importedWellPaths )
{
wellPathsResult->wellPathNames.v().push_back( wellPath->name() );
}
response.setResult( wellPathsResult );
}
}
else
{
warningMessages << "No well paths found";
}
for ( QString warningMessage : warningMessages )
{
response.updateStatus( RicfCommandResponse::COMMAND_WARNING, warningMessage );
}
for ( QString errorMessage : errorMessages )
{
response.updateStatus( RicfCommandResponse::COMMAND_ERROR, errorMessage );
}
return response;
}

View File

@@ -1,58 +0,0 @@
/////////////////////////////////////////////////////////////////////////////////
//
// 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 "RicfCommandObject.h"
#include "cafPdmField.h"
#include <QString>
#include <vector>
//==================================================================================================
///
///
//==================================================================================================
class RicfImportWellPathsResult : public caf::PdmObject
{
CAF_PDM_HEADER_INIT;
public:
RicfImportWellPathsResult();
public:
caf::PdmField<std::vector<QString>> wellPathNames;
};
//==================================================================================================
///
///
//==================================================================================================
class RicfImportWellPaths : public RicfCommandObject
{
CAF_PDM_HEADER_INIT;
public:
RicfImportWellPaths();
RicfCommandResponse execute() override;
private:
caf::PdmField<QString> m_wellPathFolder;
caf::PdmField<std::vector<QString>> m_wellPathFiles;
};