mirror of
https://github.com/OPM/ResInsight.git
synced 2024-12-29 10:21:54 -06:00
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:
parent
f24543ce56
commit
d3140b6aac
@ -646,6 +646,25 @@ bool RiaApplication::loadProject( const QString& projectFileName )
|
||||
return loadProject( projectFileName, PLA_NONE, nullptr );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RiaApplication::saveProject( QString* errorMessage )
|
||||
{
|
||||
CAF_ASSERT( errorMessage );
|
||||
CAF_ASSERT( m_project.notNull() );
|
||||
|
||||
if ( !isProjectSavedToDisc() )
|
||||
{
|
||||
*errorMessage = "Project hasn't already been saved and no file name has been provided";
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return saveProjectAs( m_project->fileName(), errorMessage );
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@ -654,19 +673,22 @@ bool RiaApplication::saveProjectAs( const QString& fileName, QString* errorMessa
|
||||
// Make sure we always store path with forward slash to avoid issues when opening the project file on Linux
|
||||
m_project->fileName = RiaFilePathTools::toInternalSeparator( fileName );
|
||||
|
||||
onProjectBeingSaved();
|
||||
|
||||
if ( !m_project->writeFile() )
|
||||
{
|
||||
CAF_ASSERT( errorMessage );
|
||||
*errorMessage = QString( "Not possible to save project file. Make sure you have sufficient access "
|
||||
"rights.\n\nProject file location : %1" )
|
||||
.arg( fileName );
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
m_preferences->lastUsedProjectFileName = fileName;
|
||||
caf::PdmSettings::writeFieldsToApplicationStore( m_preferences );
|
||||
|
||||
onProjectSaved();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -126,9 +126,13 @@ public:
|
||||
bool isProjectSavedToDisc() const;
|
||||
QString currentProjectPath() const;
|
||||
QString createAbsolutePathFromProjectRelativePath( QString projectRelativePath );
|
||||
bool loadProject( const QString& projectFileName );
|
||||
|
||||
bool loadProject( const QString& projectFileName );
|
||||
bool loadProject( const QString& projectFileName, ProjectLoadAction loadAction, RiaProjectModifier* projectModifier );
|
||||
bool saveProjectAs( const QString& fileName, QString* errorMessage );
|
||||
|
||||
bool saveProject( QString* errorMessage );
|
||||
bool saveProjectAs( const QString& fileName, QString* errorMessage );
|
||||
|
||||
static bool hasValidProjectFileExtension( const QString& fileName );
|
||||
void closeProject();
|
||||
|
||||
@ -206,11 +210,15 @@ protected:
|
||||
// Protected implementation specific overrides
|
||||
virtual void invokeProcessEvents( QEventLoop::ProcessEventsFlags flags = QEventLoop::AllEvents ) = 0;
|
||||
virtual void onFileSuccessfullyLoaded( const QString& fileName, RiaDefines::ImportFileType fileType ) {}
|
||||
|
||||
virtual void onProjectBeingOpened() {}
|
||||
virtual void onProjectOpened() = 0;
|
||||
virtual void onProjectOpeningError( const QString& errMsg ) = 0;
|
||||
virtual void onProjectBeingClosed() {}
|
||||
virtual void onProjectClosed() = 0;
|
||||
virtual void onProjectBeingSaved() {}
|
||||
virtual void onProjectSaved() {}
|
||||
|
||||
virtual void startMonitoringWorkProgress( caf::UiProcess* uiProcess ) {}
|
||||
virtual void stopMonitoringWorkProgress() {}
|
||||
|
||||
|
@ -209,23 +209,23 @@ bool RiaGuiApplication::saveProject()
|
||||
{
|
||||
CVF_ASSERT( m_project.notNull() );
|
||||
|
||||
QString fileName;
|
||||
if ( !isProjectSavedToDisc() )
|
||||
{
|
||||
return saveProjectPromptForFileName();
|
||||
fileName = promptForProjectSaveAsFileName();
|
||||
}
|
||||
else
|
||||
{
|
||||
return saveProjectAs( m_project->fileName() );
|
||||
fileName = m_project->fileName();
|
||||
}
|
||||
return saveProjectAs( fileName );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RiaGuiApplication::saveProjectPromptForFileName()
|
||||
QString RiaGuiApplication::promptForProjectSaveAsFileName() const
|
||||
{
|
||||
// if (m_project.isNull()) return true;
|
||||
|
||||
RiaGuiApplication* app = RiaGuiApplication::instance();
|
||||
|
||||
QString startPath;
|
||||
@ -243,19 +243,7 @@ bool RiaGuiApplication::saveProjectPromptForFileName()
|
||||
tr( "Save File" ),
|
||||
startPath,
|
||||
tr( "Project Files (*.rsp);;All files(*.*)" ) );
|
||||
if ( fileName.isEmpty() )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Remember the directory to next time
|
||||
app->setLastUsedDialogDirectory( "BINARY_GRID", QFileInfo( fileName ).absolutePath() );
|
||||
|
||||
bool bSaveOk = saveProjectAs( fileName );
|
||||
|
||||
setWindowCaptionFromAppState();
|
||||
|
||||
return bSaveOk;
|
||||
return fileName;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@ -300,7 +288,6 @@ bool RiaGuiApplication::askUserToSaveModifiedProject()
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RiaGuiApplication::saveProjectAs( const QString& fileName )
|
||||
{
|
||||
storeTreeViewState();
|
||||
QString errMsg;
|
||||
if ( !RiaApplication::saveProjectAs( fileName, &errMsg ) )
|
||||
{
|
||||
@ -308,8 +295,6 @@ bool RiaGuiApplication::saveProjectAs( const QString& fileName )
|
||||
return false;
|
||||
}
|
||||
|
||||
m_recentFileActionProvider->addFileName( fileName );
|
||||
caf::PdmUiModelChangeDetector::instance()->reset();
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -1486,6 +1471,25 @@ void RiaGuiApplication::onProjectClosed()
|
||||
processEvents();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaGuiApplication::onProjectBeingSaved()
|
||||
{
|
||||
setLastUsedDialogDirectory( "BINARY_GRID", QFileInfo( m_project->fileName() ).absolutePath() );
|
||||
storeTreeViewState();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaGuiApplication::onProjectSaved()
|
||||
{
|
||||
setWindowCaptionFromAppState();
|
||||
m_recentFileActionProvider->addFileName( m_project->fileName() );
|
||||
caf::PdmUiModelChangeDetector::instance()->reset();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
@ -91,10 +91,10 @@ public:
|
||||
RiaGuiApplication( int& argc, char** argv );
|
||||
~RiaGuiApplication() override;
|
||||
|
||||
bool saveProject();
|
||||
bool saveProjectPromptForFileName();
|
||||
bool askUserToSaveModifiedProject();
|
||||
bool saveProjectAs( const QString& fileName );
|
||||
bool saveProject();
|
||||
QString promptForProjectSaveAsFileName() const;
|
||||
bool askUserToSaveModifiedProject();
|
||||
bool saveProjectAs( const QString& fileName );
|
||||
|
||||
void runMultiCaseSnapshots( const QString& templateProjectFileName,
|
||||
std::vector<QString> gridFileNames,
|
||||
@ -141,11 +141,15 @@ protected:
|
||||
// Protected RiaApplication overrides
|
||||
void invokeProcessEvents( QEventLoop::ProcessEventsFlags flags = QEventLoop::AllEvents ) override;
|
||||
void onFileSuccessfullyLoaded( const QString& fileName, RiaDefines::ImportFileType fileType ) override;
|
||||
|
||||
void onProjectBeingOpened() override;
|
||||
void onProjectOpeningError( const QString& errMsg );
|
||||
void onProjectOpened() override;
|
||||
void onProjectBeingClosed() override;
|
||||
void onProjectClosed() override;
|
||||
void onProjectBeingSaved() override;
|
||||
void onProjectSaved() override;
|
||||
|
||||
void startMonitoringWorkProgress( caf::UiProcess* uiProcess ) override;
|
||||
void stopMonitoringWorkProgress() override;
|
||||
|
||||
|
@ -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
|
||||
|
@ -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 )
|
||||
|
||||
//==================================================================================================
|
||||
//
|
||||
//
|
||||
|
@ -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 "";
|
||||
}
|
||||
|
@ -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 );
|
||||
|
@ -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;
|
||||
}
|
@ -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;
|
||||
};
|
@ -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 );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
};
|
||||
|
@ -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 );
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
@ -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;
|
||||
};
|
||||
|
@ -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 );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
};
|
||||
|
@ -20,6 +20,7 @@
|
||||
|
||||
#include "RiaApplication.h"
|
||||
#include "RiaDefines.h"
|
||||
#include "RiaLogging.h"
|
||||
|
||||
#include "RiaGrpcCallbacks.h"
|
||||
#include "RiaGrpcCaseService.h"
|
||||
|
@ -17,8 +17,6 @@
|
||||
//////////////////////////////////////////////////////////////////////////////////
|
||||
#pragma once
|
||||
|
||||
#include "RiaLogging.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <list>
|
||||
#include <memory>
|
||||
@ -53,4 +51,4 @@ private:
|
||||
private:
|
||||
RiaGrpcServerImpl* m_serverImpl;
|
||||
static bool s_receivedExitRequest;
|
||||
};
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user