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

@@ -18,13 +18,37 @@
#include "RicSaveProjectAsFeature.h"
#include "RicSaveProjectFeature.h"
#include "RiaGuiApplication.h"
#include "RiaLogging.h"
#include "RicSaveProjectFeature.h"
#include "Riu3DMainWindowTools.h"
#include <QAction>
#include <QMessageBox>
CAF_CMD_SOURCE_INIT( RicSaveProjectAsFeature, "RicSaveProjectAsFeature" );
RICF_SOURCE_INIT( RicSaveProjectAsFeature, "RicSaveProjectAsFeature", "saveProjectAs" );
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RicSaveProjectAsFeature::RicSaveProjectAsFeature()
{
RICF_InitFieldNoDefault( &m_filePath, "filePath", "", "", "", "" );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RicfCommandResponse RicSaveProjectAsFeature::execute()
{
this->disableModelChangeContribution();
QString errorMessage;
if ( !RiaApplication::instance()->saveProjectAs( m_filePath(), &errorMessage ) )
{
return RicfCommandResponse( RicfCommandResponse::COMMAND_ERROR, errorMessage );
}
return RicfCommandResponse();
}
//--------------------------------------------------------------------------------------------------
///
@@ -39,12 +63,25 @@ bool RicSaveProjectAsFeature::isCommandEnabled()
//--------------------------------------------------------------------------------------------------
void RicSaveProjectAsFeature::onActionTriggered( bool isChecked )
{
this->disableModelChangeContribution();
RiaGuiApplication* app = RiaGuiApplication::instance();
if ( app )
{
app->saveProjectPromptForFileName();
m_filePath = app->promptForProjectSaveAsFileName();
if ( m_filePath().isEmpty() )
{
return;
}
auto response = execute();
if ( response.status() != RicfCommandResponse::COMMAND_OK )
{
QString displayMessage = response.messages().join( "\n" );
if ( RiaGuiApplication::isRunning() )
{
QMessageBox::warning( nullptr, "Error when saving project file", displayMessage );
}
RiaLogging::error( displayMessage );
}
}
}

View File

@@ -18,18 +18,28 @@
#pragma once
#include "CommandFileInterface/Core/RicfCommandObject.h"
#include "cafCmdFeature.h"
#include "cafPdmField.h"
//==================================================================================================
///
//==================================================================================================
class RicSaveProjectAsFeature : public caf::CmdFeature
class RicSaveProjectAsFeature : public caf::CmdFeature, public RicfCommandObject
{
CAF_CMD_HEADER_INIT;
RICF_HEADER_INIT;
public:
RicSaveProjectAsFeature();
RicfCommandResponse execute() override;
protected:
// Overrides
bool isCommandEnabled() override;
void onActionTriggered( bool isChecked ) override;
void setupActionLook( QAction* actionToSetup ) override;
private:
caf::PdmField<QString> m_filePath;
};

View File

@@ -18,11 +18,48 @@
#include "RicSaveProjectFeature.h"
#include "RiaApplication.h"
#include "RiaGuiApplication.h"
#include "RiaLogging.h"
#include <QAction>
#include <QMessageBox>
CAF_CMD_SOURCE_INIT( RicSaveProjectFeature, "RicSaveProjectFeature" );
RICF_SOURCE_INIT( RicSaveProjectFeature, "RicSaveProjectFeature", "saveProject" );
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RicSaveProjectFeature::RicSaveProjectFeature()
{
CAF_PDM_InitFieldNoDefault( &m_filePath, "filePath", "", "", "", "" );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RicfCommandResponse RicSaveProjectFeature::execute()
{
this->disableModelChangeContribution();
bool worked = false;
QString errorMessage;
if ( !m_filePath().isEmpty() )
{
worked = RiaApplication::instance()->saveProjectAs( m_filePath(), &errorMessage );
}
else
{
worked = RiaApplication::instance()->saveProject( &errorMessage );
}
if ( !worked )
{
return RicfCommandResponse( RicfCommandResponse::COMMAND_ERROR, errorMessage );
}
return RicfCommandResponse();
}
//--------------------------------------------------------------------------------------------------
///
@@ -37,11 +74,24 @@ bool RicSaveProjectFeature::isCommandEnabled()
//--------------------------------------------------------------------------------------------------
void RicSaveProjectFeature::onActionTriggered( bool isChecked )
{
this->disableModelChangeContribution();
RiaApplication* app = RiaApplication::instance();
RiaGuiApplication* guiApp = dynamic_cast<RiaGuiApplication*>( app );
RiaGuiApplication* app = RiaGuiApplication::instance();
if ( guiApp && !guiApp->isProjectSavedToDisc() )
{
m_filePath = guiApp->promptForProjectSaveAsFileName();
}
app->saveProject();
auto response = execute();
if ( response.status() != RicfCommandResponse::COMMAND_OK )
{
QString displayMessage = response.messages().join( "\n" );
if ( RiaGuiApplication::isRunning() )
{
QMessageBox::warning( nullptr, "Error when saving project file", displayMessage );
}
RiaLogging::error( displayMessage );
}
}
//--------------------------------------------------------------------------------------------------

View File

@@ -18,18 +18,28 @@
#pragma once
#include "CommandFileInterface/Core/RicfCommandObject.h"
#include "cafCmdFeature.h"
#include "cafPdmField.h"
//==================================================================================================
///
//==================================================================================================
class RicSaveProjectFeature : public caf::CmdFeature
class RicSaveProjectFeature : public caf::CmdFeature, public RicfCommandObject
{
CAF_CMD_HEADER_INIT;
RICF_HEADER_INIT;
public:
RicSaveProjectFeature();
RicfCommandResponse execute() override;
protected:
// Overrides
bool isCommandEnabled() override;
void onActionTriggered( bool isChecked ) override;
void setupActionLook( QAction* actionToSetup ) override;
private:
caf::PdmField<QString> m_filePath;
};

View File

@@ -23,6 +23,7 @@
#include "RiaGuiApplication.h"
#include "RiaLogging.h"
#include "RimFileWellPath.h"
#include "RimOilField.h"
#include "RimProject.h"
#include "RimWellPath.h"
@@ -34,7 +35,103 @@
#include <QFileDialog>
#include <QMessageBox>
CAF_CMD_SOURCE_INIT( RicImportWellPaths, "RicWellPathsImportFileFeature" );
//==================================================================================================
///
///
//==================================================================================================
class RicImportWellPathsResult : public caf::PdmObject
{
CAF_PDM_HEADER_INIT;
public:
RicImportWellPathsResult()
{
CAF_PDM_InitObject( "well_path_result", "", "", "" );
CAF_PDM_InitFieldNoDefault( &wellPathNames, "wellPathNames", "", "", "", "" );
}
public:
caf::PdmField<std::vector<QString>> wellPathNames;
};
CAF_PDM_SOURCE_INIT( RicImportWellPathsResult, "importWellPathsResult" );
RICF_SOURCE_INIT( RicImportWellPaths, "RicWellPathsImportFileFeature", "importWellPaths" );
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RicImportWellPaths::RicImportWellPaths()
{
RICF_InitFieldNoDefault( &m_wellPathFolder, "wellPathFolder", "", "", "", "" );
RICF_InitFieldNoDefault( &m_wellPathFiles, "wellPathFiles", "", "", "", "" );
}
RicfCommandResponse RicImportWellPaths::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 = importWellPaths( wellPathFiles, &warningMessages );
if ( !importedWellPaths.empty() )
{
RicImportWellPathsResult* wellPathsResult = new RicImportWellPathsResult;
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;
}
//--------------------------------------------------------------------------------------------------
///
@@ -109,18 +206,26 @@ void RicImportWellPaths::onActionTriggered( bool isChecked )
if ( wellPathFilePaths.size() >= 1 )
{
QStringList errorMessages;
importWellPaths( wellPathFilePaths, &errorMessages );
m_wellPathFiles.v() = std::vector<QString>( wellPathFilePaths.begin(), wellPathFilePaths.end() );
RicfCommandResponse response = execute();
QStringList messages = response.messages();
if ( !errorMessages.empty() )
if ( !messages.empty() )
{
QString displayMessage = "Errors loading well path files: \n" + errorMessages.join( "\n" );
QString displayMessage = QString( "Problem loading well path files:\n%2" ).arg( messages.join( "\n" ) );
if ( RiaGuiApplication::isRunning() )
{
QMessageBox::warning( Riu3DMainWindowTools::mainWindowWidget(), "File open error", displayMessage );
QMessageBox::warning( Riu3DMainWindowTools::mainWindowWidget(), "Well Path Loading", displayMessage );
}
if ( response.status() == RicfCommandResponse::COMMAND_ERROR )
{
RiaLogging::error( displayMessage );
}
else
{
RiaLogging::warning( displayMessage );
}
RiaLogging::warning( displayMessage );
}
}
}

View File

@@ -19,7 +19,13 @@
#pragma once
#include "CommandFileInterface/Core/RicfCommandObject.h"
#include "cafCmdFeature.h"
#include "cafPdmField.h"
#include <QString>
#include <QStringList>
#include <vector>
@@ -28,18 +34,25 @@ class RimFileWellPath;
//==================================================================================================
///
//==================================================================================================
class RicImportWellPaths : public caf::CmdFeature
class RicImportWellPaths : public caf::CmdFeature, public RicfCommandObject
{
CAF_CMD_HEADER_INIT;
RICF_HEADER_INIT;
public:
RicImportWellPaths();
RicfCommandResponse execute() override;
protected:
static std::vector<RimFileWellPath*> importWellPaths( const QStringList& wellPathFilePaths,
QStringList* errorMessages );
static QStringList wellPathNameFilters();
protected:
// Overrides
bool isCommandEnabled() override;
void onActionTriggered( bool isChecked ) override;
void setupActionLook( QAction* actionToSetup ) override;
private:
caf::PdmField<QString> m_wellPathFolder;
caf::PdmField<std::vector<QString>> m_wellPathFiles;
};