Skip to content
Snippets Groups Projects
main.cpp 3.05 KiB
Newer Older
  • Learn to ignore specific revisions
  • //  ************************************************************************************************
    
    Pospelov, Gennady's avatar
    Pospelov, Gennady committed
    //
    
    //  BornAgain: simulate and fit reflection and scattering
    
    Pospelov, Gennady's avatar
    Pospelov, Gennady committed
    //
    
    Wuttke, Joachim's avatar
    Wuttke, Joachim committed
    //! @file      App/main.cpp
    
    Pospelov, Gennady's avatar
    Pospelov, Gennady committed
    //! @brief     Main function of the whole GUI
    //!
    
    //! @homepage  http://www.bornagainproject.org
    
    Pospelov, Gennady's avatar
    Pospelov, Gennady committed
    //! @license   GNU General Public License v3 or higher (see COPYING)
    
    //! @copyright Forschungszentrum Jülich GmbH 2018
    //! @authors   Scientific Computing Group at MLZ (see CITATION, AUTHORS)
    
    Pospelov, Gennady's avatar
    Pospelov, Gennady committed
    //
    
    //  ************************************************************************************************
    
    Pospelov, Gennady's avatar
    Pospelov, Gennady committed
    
    
    #include "App/AppOptions.h"
    
    Wuttke, Joachim's avatar
    Wuttke, Joachim committed
    #include "App/MessageHandler.h"
    
    #include "GUI/Application/ApplicationSettings.h"
    
    Wuttke, Joachim's avatar
    Wuttke, Joachim committed
    #include "GUI/Model/Data/SessionData.h"
    
    Wuttke, Joachim's avatar
    Wuttke, Joachim committed
    #include "GUI/Util/Path.h"
    
    Wuttke, Joachim's avatar
    Wuttke, Joachim committed
    #include "GUI/View/Global/Globals.h"
    
    Wuttke, Joachim's avatar
    Wuttke, Joachim committed
    #include "GUI/View/Loaders/DataLoaderUtil.h"
    #include "GUI/View/Main/MainWindow.h"
    
    #include "config_build.h"
    
    #include <QDir>
    
    #include <QIcon>
    
    #include <QLocale>
    
    David Li's avatar
    David Li committed
    #include <QMetaType>
    
    #include <boost/exception/diagnostic_information.hpp>
    
    pospelov's avatar
    pospelov committed
    
    
    void messageHandler(QtMsgType, const QMessageLogContext&, const QString&) {}
    
    int main(int argc, char* argv[])
    {
    
        ApplicationOptions options(argc, argv);
    
        if (!options.isConsistent())
            return 0;
    
    Mohammad Mahadi Hasan's avatar
    Mohammad Mahadi Hasan committed
    
    
        QLocale::setDefault(QLocale(QLocale::English, QLocale::UnitedStates));
    
        qRegisterMetaType<QVector<double>>("QVector<double>");
    
        if (!options.disableHighDPISupport())
    
            QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
    
    
        QApplication app(argc, argv);
    
        QApplication::setApplicationName("BornAgain");
        QApplication::setApplicationVersion(GUI::Util::Path::getBornAgainVersionString());
        QApplication::setOrganizationName("BornAgain");
    
    #ifndef Q_OS_MAC
        QApplication::setWindowIcon(QIcon(":/images/BornAgain.ico"));
    #endif
    
        ApplicationSettings applicationSettings;
    
    Wuttke, Joachim's avatar
    Wuttke, Joachim committed
        int result;
    
    Mohammad Mahadi Hasan's avatar
    Mohammad Mahadi Hasan committed
    
    
    #if !defined(BUILD_DEBUG)
    
            qInstallMessageHandler(MessageHandler);
    
            auto style = applicationSettings.styleToUse();
            applicationSettings.loadStyle(style);
    
            QString dir = GUI::Util::Path::appDataFolder();
    
            GSession.instrumentLibrary.load();
    
            GUI::Global::mainWindow = &win;
    
            if (options.find("geometry"))
                win.resize(options.mainWindowSize());
    
    Wuttke, Joachim's avatar
    Wuttke, Joachim committed
            result = QApplication::exec();
    
            GSession.instrumentLibrary.saveIfModified();
    
    #if !defined(BUILD_DEBUG)
    
        } catch (...) {
            QMessageBox box;
            box.setWindowTitle("Fatal error");
            box.setIcon(QMessageBox::Critical);
            box.setText("BornAgain encountered a fatal error and can't continue execution.\n\n"
                        "Diagnostics of error:\n"
                        + QString::fromStdString(boost::current_exception_diagnostic_information()));
            box.addButton("Acknowledge", QMessageBox::AcceptRole);
            box.exec();
    
    Wuttke, Joachim's avatar
    Wuttke, Joachim committed
            result = EXIT_FAILURE;
    
    Wuttke, Joachim's avatar
    Wuttke, Joachim committed
        return result;
    
    pospelov's avatar
    pospelov committed
    }