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