File: main.cpp

package info (click to toggle)
bornagain 23.0-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 103,936 kB
  • sloc: cpp: 423,131; python: 40,997; javascript: 11,167; awk: 630; sh: 318; ruby: 173; xml: 130; makefile: 51; ansic: 24
file content (109 lines) | stat: -rw-r--r-- 3,784 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
//  ************************************************************************************************
//
//  BornAgain: simulate and fit reflection and scattering
//
//! @file      App/main.cpp
//! @brief     Main function of the whole GUI
//!
//! @homepage  http://www.bornagainproject.org
//! @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)
//
//  ************************************************************************************************

#include "App/AppOptions.h"
#include "Base/Util/Assert.h"
#include "GUI/Model/Project/ProjectDocument.h"
#include "GUI/Model/Util/Path.h"
#include "GUI/View/Base/Stylesheet.h"
#include "GUI/View/Main/MainWindow.h"
#include "GUI/View/Widget/AppConfig.h"
#include "config_build.h"

#ifdef BORNAGAIN_PYTHON
#include "PyCore/Embed/PyInterpreter.h" // PyInterpreter::finalize
#endif                                  // BORNAGAIN_PYTHON

#include <QApplication>
#include <QDir>
#include <QIcon>
#include <QLocale>
#include <QMessageBox>
#include <QMetaType>
#include <QtGlobal>
#include <cstdlib>
#include <iostream>


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"
                                   "BornAgain version: ")
                               + GUI::Path::getBornAgainVersionString() + "\n"
                               + QString("Internal error message:\n") + ex.what()
                               + "\n---\n"
                                 "Please help us to fix this bug by reporting the above\n"
                                 "- at https://jugit.fz-juelich.de/mlz/bornagain/-/issues/new\n"
                                 "- or by mail to contact@bornagainproject.org.\n"
                                 "See also\n"
                                 "- https://bornagainproject.org/latest/howto/get-help.",
                           QMessageBox::Ok, nullptr);
        msgbox.exec();
    }
    std::abort();
}

int main(int argc, char* argv[])
{
    std::set_terminate(custom_terminate_handler);

    ApplicationOptions options(argc, argv);

    QLocale::setDefault(QLocale(QLocale::English, QLocale::UnitedStates));
    qRegisterMetaType<QVector<double>>("QVector<double>");

    int ret = -1;
    QApplication app(argc, argv);
    app.setApplicationName("BornAgain");
    app.setApplicationVersion(GUI::Path::getBornAgainVersionString());
    app.setOrganizationName("BornAgain");
#ifndef Q_OS_MAC
    app.setWindowIcon(QIcon(":/images/BornAgain.ico"));
#endif
    GUI::Style::setInitialStyle();

    gApp = std::make_unique<AppConfig>();
    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
#ifdef BA_DEBUG
    std::cout << "BornAgain: finalize Python interpreter..." << std::endl;
#endif // BA_DEBUG
    PyInterpreter::finalize();
#endif // BORNAGAIN_PYTHON

    return ret;
}