mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
Create a new ApplicationExe project for the executable
This commit is contained in:
@@ -29,7 +29,6 @@ ${CMAKE_CURRENT_LIST_DIR}/RiaGuiApplication.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaCompletionTypeCalculationScheduler.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaDefines.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaFractureDefines.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaMain.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaPreferences.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaPorosityModel.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaSummaryCurveDefinition.cpp
|
||||
|
||||
@@ -1076,27 +1076,7 @@ QString RiaApplication::pythonPath() const
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QProcessEnvironment RiaApplication::pythonProcessEnvironment() const
|
||||
{
|
||||
QProcessEnvironment penv = QProcessEnvironment::systemEnvironment();
|
||||
#ifdef ENABLE_GRPC
|
||||
penv.insert( "RESINSIGHT_GRPC_PORT", QString( "%1" ).arg( m_grpcServer->portNumber() ) );
|
||||
penv.insert( "RESINSIGHT_EXECUTABLE", QCoreApplication::applicationFilePath() );
|
||||
|
||||
QStringList ripsLocations;
|
||||
QString separator;
|
||||
#ifdef WIN32
|
||||
ripsLocations << QCoreApplication::applicationDirPath() + "\\Python"
|
||||
<< QCoreApplication::applicationDirPath() + "\\..\\..\\Python";
|
||||
separator = ";";
|
||||
|
||||
#else
|
||||
ripsLocations << QCoreApplication::applicationDirPath() + "/Python"
|
||||
<< QCoreApplication::applicationDirPath() + "/../../Python";
|
||||
separator = ":";
|
||||
#endif
|
||||
penv.insert( "PYTHONPATH",
|
||||
QString( "%1%2%3" ).arg( penv.value( "PYTHONPATH" ) ).arg( separator ).arg( ripsLocations.join( separator ) ) );
|
||||
#endif
|
||||
return penv;
|
||||
return QProcessEnvironment::systemEnvironment();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -1500,36 +1480,6 @@ cvf::Font* RiaApplication::defaultWellLabelFont()
|
||||
return m_defaultWellLabelFont.p();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RiaApplication::initializeGrpcServer( const cvf::ProgramOptions& progOpt )
|
||||
{
|
||||
#ifdef ENABLE_GRPC
|
||||
if ( !m_preferences->enableGrpcServer() ) return false;
|
||||
|
||||
int defaultPortNumber = m_preferences->defaultGrpcPortNumber();
|
||||
bool fixedPort = false;
|
||||
if ( cvf::Option o = progOpt.option( "server" ) )
|
||||
{
|
||||
if ( o.valueCount() == 1 )
|
||||
{
|
||||
defaultPortNumber = o.value( 0 ).toInt( defaultPortNumber );
|
||||
fixedPort = true;
|
||||
}
|
||||
}
|
||||
int portNumber = defaultPortNumber;
|
||||
if ( !fixedPort )
|
||||
{
|
||||
portNumber = RiaGrpcServer::findAvailablePortNumber( defaultPortNumber );
|
||||
}
|
||||
m_grpcServer = std::make_unique<RiaGrpcServer>( portNumber );
|
||||
return true;
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
||||
@@ -20,9 +20,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "RiaDefines.h"
|
||||
#ifdef ENABLE_GRPC
|
||||
#include "RiaGrpcServer.h"
|
||||
#endif
|
||||
|
||||
#include "cafPdmField.h"
|
||||
#include "cafPdmObject.h"
|
||||
@@ -47,6 +44,7 @@ class Drawable;
|
||||
|
||||
class RIProcess;
|
||||
|
||||
class RiaGrpcServer;
|
||||
class RiaPreferences;
|
||||
class RiaProjectModifier;
|
||||
class RiaSocketServer;
|
||||
@@ -161,8 +159,8 @@ public:
|
||||
QStringList octaveArguments() const;
|
||||
QProcessEnvironment octaveProcessEnvironment() const;
|
||||
|
||||
QString pythonPath() const;
|
||||
QProcessEnvironment pythonProcessEnvironment() const;
|
||||
QString pythonPath() const;
|
||||
virtual QProcessEnvironment pythonProcessEnvironment() const;
|
||||
|
||||
bool launchProcess( const QString& program, const QStringList& arguments, const QProcessEnvironment& processEnvironment );
|
||||
bool launchProcessForMultipleCases( const QString& program,
|
||||
@@ -198,8 +196,6 @@ public:
|
||||
cvf::Font* defaultAnnotationFont();
|
||||
cvf::Font* defaultWellLabelFont();
|
||||
|
||||
bool initializeGrpcServer( const cvf::ProgramOptions& progOpt );
|
||||
|
||||
// Public implementation specific overrides
|
||||
virtual void initialize();
|
||||
virtual ApplicationStatus handleArguments( gsl::not_null<cvf::ProgramOptions*> progOpt ) = 0;
|
||||
@@ -207,11 +203,6 @@ public:
|
||||
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
|
||||
protected:
|
||||
// Protected implementation specific overrides
|
||||
virtual void invokeProcessEvents( QEventLoop::ProcessEventsFlags flags = QEventLoop::AllEvents ) = 0;
|
||||
@@ -246,10 +237,6 @@ protected:
|
||||
QPointer<RiaSocketServer> m_socketServer;
|
||||
std::unique_ptr<caf::UiProcess> m_workerProcess;
|
||||
|
||||
#ifdef ENABLE_GRPC
|
||||
std::unique_ptr<RiaGrpcServer> m_grpcServer;
|
||||
#endif
|
||||
|
||||
// Execute for all settings
|
||||
std::list<int> m_scriptCaseIds;
|
||||
int m_currentScriptCaseId;
|
||||
|
||||
@@ -377,29 +377,6 @@ void RiaConsoleApplication::showFormattedTextInMessageBoxOrConsole( const QStrin
|
||||
std::cout << errMsg.toStdString();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaConsoleApplication::launchGrpcServer()
|
||||
{
|
||||
#ifdef ENABLE_GRPC
|
||||
m_grpcServer->runInThread();
|
||||
m_idleTimer = new QTimer( this );
|
||||
connect( m_idleTimer, SIGNAL( timeout() ), this, SLOT( runIdleProcessing() ) );
|
||||
m_idleTimer->start( 0 );
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef ENABLE_GRPC
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RiaGrpcServer* RiaConsoleApplication::grpcServer() const
|
||||
{
|
||||
return m_grpcServer.get();
|
||||
}
|
||||
#endif
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -432,21 +409,3 @@ void RiaConsoleApplication::onProjectClosed()
|
||||
{
|
||||
processEvents();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaConsoleApplication::runIdleProcessing()
|
||||
{
|
||||
#ifdef ENABLE_GRPC
|
||||
if ( RiaGrpcServer::receivedExitRequest() )
|
||||
{
|
||||
m_grpcServer->quit();
|
||||
QCoreApplication::quit();
|
||||
}
|
||||
else
|
||||
{
|
||||
m_grpcServer->processAllQueuedRequests();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -43,10 +43,6 @@ public:
|
||||
void initialize() override;
|
||||
ApplicationStatus handleArguments( gsl::not_null<cvf::ProgramOptions*> progOpt ) override;
|
||||
void showFormattedTextInMessageBoxOrConsole( const QString& errMsg ) override;
|
||||
void launchGrpcServer() override;
|
||||
#ifdef ENABLE_GRPC
|
||||
RiaGrpcServer* grpcServer() const override;
|
||||
#endif
|
||||
|
||||
protected:
|
||||
// Protected implementation specific overrides
|
||||
@@ -54,12 +50,4 @@ protected:
|
||||
void onProjectOpeningError( const QString& errMsg ) override;
|
||||
void onProjectOpened() override;
|
||||
void onProjectClosed() override;
|
||||
|
||||
private slots:
|
||||
void runIdleProcessing();
|
||||
|
||||
private:
|
||||
#ifdef ENABLE_GRPC
|
||||
QPointer<QTimer> m_idleTimer;
|
||||
#endif
|
||||
};
|
||||
|
||||
@@ -190,8 +190,6 @@ RiaGuiApplication::RiaGuiApplication( int& argc, char** argv )
|
||||
setWindowIcon( QIcon( ":/AppLogo48x48.png" ) );
|
||||
|
||||
m_recentFileActionProvider = std::make_unique<RiuRecentFileActionProvider>();
|
||||
|
||||
connect( this, SIGNAL( aboutToQuit() ), this, SLOT( onProgramExit() ) );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -1201,29 +1199,6 @@ void RiaGuiApplication::showFormattedTextInMessageBoxOrConsole( const QString& t
|
||||
dlg.exec();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaGuiApplication::launchGrpcServer()
|
||||
{
|
||||
#ifdef ENABLE_GRPC
|
||||
m_grpcServer->runInThread();
|
||||
m_idleTimer = new QTimer( this );
|
||||
connect( m_idleTimer, SIGNAL( timeout() ), this, SLOT( runIdleProcessing() ) );
|
||||
m_idleTimer->start( 5 );
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef ENABLE_GRPC
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RiaGrpcServer* RiaGuiApplication::grpcServer() const
|
||||
{
|
||||
return m_grpcServer.get();
|
||||
}
|
||||
#endif
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -1389,19 +1364,6 @@ void RiaGuiApplication::onProjectSaved()
|
||||
caf::PdmUiModelChangeDetector::instance()->reset();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaGuiApplication::onProgramExit()
|
||||
{
|
||||
#ifdef ENABLE_GRPC
|
||||
if ( m_grpcServer )
|
||||
{
|
||||
m_grpcServer->quit();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -1595,27 +1557,11 @@ void RiaGuiApplication::applyGuiPreferences( const RiaPreferences*
|
||||
}
|
||||
}
|
||||
caf::PdmUiItem::enableExtraDebugText( m_preferences->appendFieldKeywordToToolTipText() );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaGuiApplication::updateGrpcServer()
|
||||
{
|
||||
#ifdef ENABLE_GRPC
|
||||
bool isGrpcRunning = m_grpcServer != nullptr && m_grpcServer->isRunning();
|
||||
bool shouldItBeRunning = m_preferences->enableGrpcServer();
|
||||
if ( isGrpcRunning && !shouldItBeRunning )
|
||||
if ( oldPreferences )
|
||||
{
|
||||
m_grpcServer->quit();
|
||||
onGuiPreferencesChanged();
|
||||
}
|
||||
else if ( !isGrpcRunning && shouldItBeRunning )
|
||||
{
|
||||
int portNumber = RiaGrpcServer::findAvailablePortNumber( m_preferences->defaultGrpcPortNumber() );
|
||||
m_grpcServer = std::make_unique<RiaGrpcServer>( portNumber );
|
||||
m_grpcServer->runInThread();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -1690,43 +1636,6 @@ void RiaGuiApplication::slotWorkerProcessFinished( int exitCode, QProcess::ExitS
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaGuiApplication::runIdleProcessing()
|
||||
{
|
||||
#ifdef ENABLE_GRPC
|
||||
if ( RiaGrpcServer::receivedExitRequest() )
|
||||
{
|
||||
closeProject();
|
||||
m_grpcServer->quit();
|
||||
QCoreApplication::quit();
|
||||
}
|
||||
else if ( !caf::ProgressInfoStatic::isRunning() )
|
||||
{
|
||||
static int idleIterationCount = 0;
|
||||
int iterationInterval = 0;
|
||||
if ( m_grpcServer->processAllQueuedRequests() > 0 )
|
||||
{
|
||||
idleIterationCount = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
++idleIterationCount;
|
||||
idleIterationCount = std::min( idleIterationCount, 500 );
|
||||
if ( idleIterationCount == 500 )
|
||||
{
|
||||
iterationInterval = 5;
|
||||
}
|
||||
}
|
||||
if ( iterationInterval != m_idleTimer->interval() )
|
||||
{
|
||||
m_idleTimer->setInterval( iterationInterval );
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
||||
@@ -131,7 +131,6 @@ public:
|
||||
static void clearAllSelections();
|
||||
void applyGuiPreferences( const RiaPreferences* oldPreferences = nullptr,
|
||||
const std::vector<caf::FontHolderInterface*>& defaultFontObjects = {} );
|
||||
void updateGrpcServer();
|
||||
static int applicationResolution();
|
||||
|
||||
// Public RiaApplication overrides
|
||||
@@ -140,10 +139,7 @@ public:
|
||||
int launchUnitTestsWithConsole() override;
|
||||
void addToRecentFiles( const QString& fileName ) override;
|
||||
void showFormattedTextInMessageBoxOrConsole( const QString& errMsg ) override;
|
||||
void launchGrpcServer() override;
|
||||
#ifdef ENABLE_GRPC
|
||||
RiaGrpcServer* grpcServer() const override;
|
||||
#endif
|
||||
|
||||
protected:
|
||||
// Protected RiaApplication overrides
|
||||
void invokeProcessEvents( QEventLoop::ProcessEventsFlags flags = QEventLoop::AllEvents ) override;
|
||||
@@ -160,6 +156,8 @@ protected:
|
||||
void startMonitoringWorkProgress( caf::UiProcess* uiProcess ) override;
|
||||
void stopMonitoringWorkProgress() override;
|
||||
|
||||
virtual void onGuiPreferencesChanged() {}
|
||||
|
||||
private:
|
||||
void setWindowCaptionFromAppState();
|
||||
|
||||
@@ -175,15 +173,10 @@ private:
|
||||
|
||||
private slots:
|
||||
void slotWorkerProcessFinished( int exitCode, QProcess::ExitStatus exitStatus );
|
||||
void runIdleProcessing();
|
||||
void onProgramExit();
|
||||
|
||||
private:
|
||||
RiuMainWindow* m_mainWindow;
|
||||
RiuPlotMainWindow* m_mainPlotWindow;
|
||||
#ifdef ENABLE_GRPC
|
||||
QPointer<QTimer> m_idleTimer;
|
||||
#endif
|
||||
|
||||
std::unique_ptr<RiuRecentFileActionProvider> m_recentFileActionProvider;
|
||||
|
||||
|
||||
@@ -1,133 +0,0 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2011-2012 Statoil ASA, Ceetron AS
|
||||
//
|
||||
// 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 "RiaArgumentParser.h"
|
||||
#include "RiaConsoleApplication.h"
|
||||
#include "RiaGuiApplication.h"
|
||||
#include "RiaLogging.h"
|
||||
|
||||
#include "cvfProgramOptions.h"
|
||||
#include "cvfqtUtils.h"
|
||||
|
||||
#ifndef WIN32
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
RiaApplication* createApplication( int& argc, char* argv[] )
|
||||
{
|
||||
for ( int i = 1; i < argc; ++i )
|
||||
{
|
||||
if ( !qstrcmp( argv[i], "--console" ) || !qstrcmp( argv[i], "--unittest" ) )
|
||||
{
|
||||
return new RiaConsoleApplication( argc, argv );
|
||||
}
|
||||
}
|
||||
return new RiaGuiApplication( argc, argv );
|
||||
}
|
||||
|
||||
int main( int argc, char* argv[] )
|
||||
{
|
||||
#ifndef WIN32
|
||||
// From Qt 5.3 and onwards Qt has a mechanism for checking this automatically
|
||||
// But it only checks user id not group id, so better to do it ourselves.
|
||||
if ( getuid() != geteuid() || getgid() != getegid() )
|
||||
{
|
||||
std::cerr << "FATAL: The application binary appears to be running setuid or setgid, this is a security hole."
|
||||
<< std::endl;
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
RiaLogging::loggerInstance()->setLevel( int( RILogLevel::RI_LL_DEBUG ) );
|
||||
|
||||
std::unique_ptr<RiaApplication> app( createApplication( argc, argv ) );
|
||||
|
||||
cvf::ProgramOptions progOpt;
|
||||
bool result = RiaArgumentParser::parseArguments( &progOpt );
|
||||
|
||||
const cvf::String usageText = progOpt.usageText( 110, 30 );
|
||||
app->initialize();
|
||||
app->setCommandLineHelpText( cvfqt::Utils::toQString( usageText ) );
|
||||
|
||||
if ( !result )
|
||||
{
|
||||
std::vector<cvf::String> unknownOptions = progOpt.unknownOptions();
|
||||
QString unknownOptionsText;
|
||||
for ( cvf::String option : unknownOptions )
|
||||
{
|
||||
unknownOptionsText += QString( "\tUnknown option: %1\n" ).arg( cvfqt::Utils::toQString( option ) );
|
||||
}
|
||||
|
||||
app->showFormattedTextInMessageBoxOrConsole(
|
||||
"ERROR: Unknown command line options detected ! \n" + unknownOptionsText + "\n\n" +
|
||||
"The current command line options in ResInsight are:\n" + app->commandLineParameterHelp() );
|
||||
|
||||
if ( dynamic_cast<RiaGuiApplication*>( app.get() ) == nullptr )
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
QLocale::setDefault( QLocale( QLocale::English, QLocale::UnitedStates ) );
|
||||
setlocale( LC_NUMERIC, "C" );
|
||||
|
||||
// Handle the command line arguments.
|
||||
// Todo: Move to a one-shot timer, delaying the execution until we are inside the event loop.
|
||||
// The complete handling of the resulting ApplicationStatus must be moved along.
|
||||
// The reason for this is: deleteLater() does not work outside the event loop
|
||||
// Make execution of command line stuff operate in identical conditions as interactive operation.
|
||||
|
||||
RiaApplication::ApplicationStatus status = app->handleArguments( &progOpt );
|
||||
|
||||
if ( status == RiaApplication::ApplicationStatus::EXIT_COMPLETED )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
else if ( status == RiaApplication::ApplicationStatus::EXIT_WITH_ERROR )
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
else if ( status == RiaApplication::ApplicationStatus::KEEP_GOING )
|
||||
{
|
||||
int exitCode = 0;
|
||||
try
|
||||
{
|
||||
if ( app->initializeGrpcServer( progOpt ) )
|
||||
{
|
||||
app->launchGrpcServer();
|
||||
}
|
||||
exitCode = QCoreApplication::instance()->exec();
|
||||
}
|
||||
catch ( std::exception& exep )
|
||||
{
|
||||
std::cout << "A standard c++ exception that terminated ResInsight caught in RiaMain.cpp: " << exep.what()
|
||||
<< std::endl;
|
||||
throw;
|
||||
}
|
||||
catch ( ... )
|
||||
{
|
||||
std::cout << "An unknown exception that terminated ResInsight caught in RiaMain.cpp. " << std::endl;
|
||||
throw;
|
||||
}
|
||||
|
||||
return exitCode;
|
||||
}
|
||||
|
||||
CVF_ASSERT( false && "Unknown ApplicationStatus" );
|
||||
return -1;
|
||||
}
|
||||
Reference in New Issue
Block a user