Skip to content
Snippets Groups Projects
main.cpp 2.93 KiB
Newer Older
//  ************************************************************************************************
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"
#include "GUI/Model/Project/ProjectDocument.h"
#include "GUI/Model/Util/Path.h"
#include "GUI/View/Base/Stylesheet.h"
Wuttke, Joachim's avatar
Wuttke, Joachim committed
#include "GUI/View/Main/MainWindow.h"
#include "GUI/View/Widget/AppConfig.h"
#include "PyCore/Embed/PyInterpreter.h" // PyInterpreter::finalize
#include "config_build.h"
#include <QDir>
#include <QIcon>
#include <QLocale>
David Li's avatar
David Li committed
#include <QMetaType>
#include <cstdlib>
Mikhail Svechnikov's avatar
Mikhail Svechnikov committed
#include <iostream>
pospelov's avatar
pospelov committed

void custom_terminate_handler()
{
    try {
        std::rethrow_exception(std::current_exception());
    } catch (const std::exception& ex) {
        std::cerr << "terminate called after throwing a std exception'\n"
                  << "what():" << std::endl;
        std::cerr << ex.what() << std::endl;

        QMessageBox msgbox(QMessageBox::Critical, "BornAgain: fatal bug",
                           QString("Sorry, you encountered a fatal bug.\n"
                                   "The application will terminate.\n"
                                   "Please note the following and inform the maintainers.\n\n")
                               + ex.what() + "\n",
                           QMessageBox::Ok, nullptr);
        msgbox.exec();
    }
int main(int argc, char* argv[])
{
    std::set_terminate(custom_terminate_handler);

    ApplicationOptions options(argc, argv);
Mohammad Mahadi Hasan's avatar
Mohammad Mahadi Hasan committed

    QLocale::setDefault(QLocale(QLocale::English, QLocale::UnitedStates));
    qRegisterMetaType<QVector<double>>("QVector<double>");
    QApplication app(argc, argv);
    app.setApplicationName("BornAgain");
    app.setApplicationVersion(GUI::Path::getBornAgainVersionString());
    app.setOrganizationName("BornAgain");
    app.setWindowIcon(QIcon(":/images/BornAgain.ico"));
    GUI::Style::setInitialStyle();
    gDoc = std::make_unique<ProjectDocument>();
    MainWindow win;
    gApp->mainWindow = &win;
    if (options.find("geometry"))
        win.resize(options.mainWindowSize());
    if (options.find("project-file"))
        win.loadProject(options.projectFile());
    win.show();
    ret = app.exec();

#ifdef BORNAGAIN_PYTHON
    std::cout << "BornAgain: finalize Python interpreter..." << std::endl;
    PyInterpreter::finalize();
#endif // BORNAGAIN_PYTHON

pospelov's avatar
pospelov committed
}