Files
ResInsight/ApplicationCode/Application/RiaApplication.h
T

266 lines
8.6 KiB
C++
Raw Normal View History

2012-05-18 09:45:23 +02:00
/////////////////////////////////////////////////////////////////////////////////
//
2014-09-23 15:04:57 +02:00
// Copyright (C) 2011- Statoil ASA
// Copyright (C) 2013- Ceetron Solutions AS
// Copyright (C) 2011-2012 Ceetron AS
2019-05-06 10:36:05 +02:00
//
2012-05-18 09:45:23 +02:00
// 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.
2019-05-06 10:36:05 +02:00
//
2012-05-18 09:45:23 +02:00
// 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.
2019-05-06 10:36:05 +02:00
//
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
2012-05-18 09:45:23 +02:00
// for more details.
//
2019-05-06 10:36:05 +02:00
//////////////////////////////////////////////////////////////////////////////////
2012-05-18 09:45:23 +02:00
#pragma once
2019-05-06 10:36:05 +02:00
#include "RiaDefines.h"
#ifdef ENABLE_GRPC
#include "RiaGrpcServer.h"
#endif
#include "cafPdmField.h"
2019-05-06 10:36:05 +02:00
#include "cafPdmObject.h"
#include "cvfFont.h"
2019-05-06 10:36:05 +02:00
#include "cvfObject.h"
2012-05-18 09:45:23 +02:00
2019-05-06 10:36:05 +02:00
#include <QApplication>
#include <QMutex>
#include <QProcess>
#include <QProcessEnvironment>
2019-05-06 10:36:05 +02:00
#include <QString>
2012-05-18 09:45:23 +02:00
#include <iostream>
#include <memory>
class QAction;
2012-05-18 09:45:23 +02:00
class Drawable;
2012-05-18 09:45:23 +02:00
class RIProcess;
class RiaPreferences;
class RiaProjectModifier;
class RiaSocketServer;
2017-01-10 09:51:39 +01:00
class RigEclipseCaseData;
class RimCommandObject;
class RimEclipseCase;
class RimEclipseView;
class RimWellPath;
class RimGridView;
class RimProject;
class RimSummaryPlot;
2018-01-09 10:11:28 +01:00
class Rim3dView;
class RimViewWindow;
class RimWellLogFile;
class RimWellLogPlot;
class RimWellAllocationPlot;
class RiuMainWindow;
class RiuMainWindowBase;
2018-04-27 06:28:08 +02:00
class RiuPlotMainWindow;
class RiuRecentFileActionProvider;
class RiaArgumentParser;
2012-05-18 09:45:23 +02:00
namespace caf
{
2019-05-06 10:36:05 +02:00
class UiProcess;
}
namespace cvf
{
class ProgramOptions;
2012-05-18 09:45:23 +02:00
}
//==================================================================================================
2019-05-06 10:36:05 +02:00
/// Base class for all ResInsight applications. I.e. console and GUI
///
2012-05-18 09:45:23 +02:00
//==================================================================================================
2019-05-06 10:36:05 +02:00
class RiaApplication
2012-05-18 09:45:23 +02:00
{
public:
2020-04-23 23:08:14 +02:00
enum class ProjectLoadAction
{
2019-05-06 10:36:05 +02:00
PLA_NONE = 0,
PLA_CALCULATE_STATISTICS = 1
};
2020-04-23 23:08:14 +02:00
enum class ApplicationStatus
2019-05-06 10:36:05 +02:00
{
KEEP_GOING = 0,
EXIT_COMPLETED,
EXIT_WITH_ERROR
};
2012-05-18 09:45:23 +02:00
public:
static RiaApplication* instance();
2019-05-06 10:36:05 +02:00
RiaApplication();
virtual ~RiaApplication();
2012-05-18 09:45:23 +02:00
static const char* getVersionStringApp( bool includeCrtInfo );
2019-05-06 10:36:05 +02:00
static bool enableDevelopmentFeatures();
void setActiveReservoirView( Rim3dView* );
2019-05-06 10:36:05 +02:00
Rim3dView* activeReservoirView();
const Rim3dView* activeReservoirView() const;
RimGridView* activeGridView();
RimGridView* activeMainOrComparisonGridView();
2019-05-06 10:36:05 +02:00
RimProject* project();
2012-05-18 09:45:23 +02:00
2019-05-06 10:36:05 +02:00
void createMockModel();
void createResultsMockModel();
void createLargeResultsMockModel();
void createMockModelCustomized();
void createInputMockModel();
2012-05-18 09:45:23 +02:00
bool openFile( const QString& fileName );
2012-05-18 09:45:23 +02:00
bool isProjectSavedToDisc() const;
QString currentProjectPath() const;
QString createAbsolutePathFromProjectRelativePath( QString projectRelativePath );
2019-10-15 15:46:19 +02:00
bool loadProject( const QString& projectFileName );
bool loadProject( const QString& projectFileName, ProjectLoadAction loadAction, RiaProjectModifier* projectModifier );
2019-10-15 15:46:19 +02:00
bool saveProject( QString* errorMessage );
bool saveProjectAs( const QString& fileName, QString* errorMessage );
static bool hasValidProjectFileExtension( const QString& fileName );
2019-05-06 10:36:05 +02:00
void closeProject();
2012-05-18 09:45:23 +02:00
QString lastUsedDialogDirectory( const QString& dialogName );
QString lastUsedDialogDirectoryWithFallbackToProjectFolder( const QString& dialogName );
QString lastUsedDialogDirectoryWithFallback( const QString& dialogName, const QString& fallbackDirectory );
void setLastUsedDialogDirectory( const QString& dialogName, const QString& directory );
2012-05-18 09:45:23 +02:00
bool openOdbCaseFromFile( const QString& fileName, bool applyTimeStepFilter = false );
2012-05-18 09:45:23 +02:00
std::vector<RimWellPath*> addWellPathsToModel( QList<QString> wellPathFilePaths, QStringList* errorMessages );
void addWellPathFormationsToModel( QList<QString> wellPathFilePaths );
std::vector<RimWellLogFile*> addWellLogsToModel( const QList<QString>& wellLogFilePaths, QStringList* errorMessages );
2013-09-08 10:53:25 +02:00
2019-05-06 10:36:05 +02:00
QString scriptDirectories() const;
QString scriptEditorPath() const;
QString octavePath() const;
QStringList octaveArguments() const;
QProcessEnvironment octaveProcessEnvironment() const;
2015-10-05 16:09:51 +02:00
QString pythonPath() const;
QProcessEnvironment pythonProcessEnvironment() const;
2020-02-12 11:43:15 +01:00
bool launchProcess( const QString& program, const QStringList& arguments, const QProcessEnvironment& processEnvironment );
bool launchProcessForMultipleCases( const QString& program,
const QStringList& arguments,
const std::vector<int>& caseIds,
const QProcessEnvironment& processEnvironment );
2019-05-06 10:36:05 +02:00
void terminateProcess();
void waitForProcess() const;
2019-05-06 10:36:05 +02:00
RiaPreferences* preferences();
2019-09-05 19:37:52 +02:00
void applyPreferences();
QString commandLineParameterHelp();
void setCommandLineHelpText( const QString& commandLineHelpText );
void setCacheDataObject( const QString& key, const QVariant& dataObject );
QVariant cacheDataObject( const QString& key ) const;
void executeCommandFile( const QString& commandFile );
void addCommandObject( RimCommandObject* commandObject );
2019-05-06 10:36:05 +02:00
void executeCommandObjects();
void waitUntilCommandObjectsHasBeenProcessed();
2019-05-06 10:36:05 +02:00
int launchUnitTests();
2019-05-06 10:36:05 +02:00
const QString startDir() const;
void setStartDir( const QString& startDir );
static std::vector<QString> readFileListFromTextFile( QString listFileName );
2019-05-06 10:36:05 +02:00
cvf::Font* defaultSceneFont();
2020-06-08 09:09:11 +00:00
cvf::Font* sceneFont( int fontSize );
2019-05-06 10:36:05 +02:00
cvf::Font* defaultAnnotationFont();
cvf::Font* defaultWellLabelFont();
bool initializeGrpcServer( const cvf::ProgramOptions& progOpt );
2019-05-06 10:36:05 +02:00
// Public implementation specific overrides
virtual void initialize();
virtual ApplicationStatus handleArguments( cvf::ProgramOptions* progOpt ) = 0;
virtual int launchUnitTestsWithConsole();
virtual void addToRecentFiles( const QString& fileName ) {}
virtual void showFormattedTextInMessageBoxOrConsole( const QString& errMsg ) = 0;
virtual void launchGrpcServer() = 0;
#ifdef ENABLE_GRPC
virtual RiaGrpcServer* grpcServer() const = 0;
#endif
2019-05-06 10:36:05 +02:00
protected:
// Protected implementation specific overrides
virtual void invokeProcessEvents( QEventLoop::ProcessEventsFlags flags = QEventLoop::AllEvents ) = 0;
virtual void onFileSuccessfullyLoaded( const QString& fileName, RiaDefines::ImportFileType fileType ) {}
2019-10-15 15:46:19 +02:00
2019-05-06 10:36:05 +02:00
virtual void onProjectBeingOpened() {}
virtual void onProjectOpened() = 0;
virtual void onProjectOpeningError( const QString& errMsg ) = 0;
2019-05-06 10:36:05 +02:00
virtual void onProjectBeingClosed() {}
virtual void onProjectClosed() = 0;
2019-10-15 15:46:19 +02:00
virtual void onProjectBeingSaved() {}
virtual void onProjectSaved() {}
virtual void startMonitoringWorkProgress( caf::UiProcess* uiProcess ) {}
2019-05-06 10:36:05 +02:00
virtual void stopMonitoringWorkProgress() {}
void loadAndUpdatePlotData();
friend class RiaRegressionTestRunner;
void resetProject();
2020-03-03 10:43:07 +01:00
bool generateCode( const QString& outputPath, QString* errMsg );
2020-02-21 11:35:14 +01:00
2019-05-06 10:36:05 +02:00
protected:
cvf::ref<cvf::Font> m_defaultSceneFont;
cvf::ref<cvf::Font> m_defaultAnnotationFont;
cvf::ref<cvf::Font> m_defaultWellLabelFont;
caf::PdmPointer<Rim3dView> m_activeReservoirView;
caf::PdmPointer<RimProject> m_project;
RiaSocketServer* m_socketServer;
caf::UiProcess* m_workerProcess;
#ifdef ENABLE_GRPC
std::unique_ptr<RiaGrpcServer> m_grpcServer;
#endif
2019-05-06 10:36:05 +02:00
// Execute for all settings
std::list<int> m_currentCaseIds;
QString m_currentProgram;
QStringList m_currentArguments;
2019-05-06 10:36:05 +02:00
RiaPreferences* m_preferences;
2012-05-18 09:45:23 +02:00
2019-05-06 10:36:05 +02:00
std::map<QString, QString> m_fileDialogDefaultDirectories;
QString m_startupDefaultDirectory;
QString m_commandLineHelpText;
QMap<QString, QVariant> m_sessionCache; // Session cache used to store username/passwords per session
2019-05-06 10:36:05 +02:00
std::list<RimCommandObject*> m_commandQueue;
QMutex m_commandQueueLock;
2019-05-06 10:36:05 +02:00
bool m_runningWorkerProcess;
2012-05-18 09:45:23 +02:00
private:
2019-05-06 10:36:05 +02:00
static RiaApplication* s_riaApplication;
};