FreeCAD

Форк
0
/
MainCmd.cpp 
163 строки · 6.5 Кб
1
/***************************************************************************
2
 *   Copyright (c) 2008 Jürgen Riegel <juergen.riegel@web.de>              *
3
 *                                                                         *
4
 *   This file is part of the FreeCAD CAx development system.              *
5
 *                                                                         *
6
 *   This program is free software; you can redistribute it and/or modify  *
7
 *   it under the terms of the GNU Library General Public License (LGPL)   *
8
 *   as published by the Free Software Foundation; either version 2 of     *
9
 *   the License, or (at your option) any later version.                   *
10
 *   for detail see the LICENCE text file.                                 *
11
 *                                                                         *
12
 *   FreeCAD is distributed in the hope that it will be useful,            *
13
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
14
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
15
 *   GNU Library General Public License for more details.                  *
16
 *                                                                         *
17
 *   You should have received a copy of the GNU Library General Public     *
18
 *   License along with FreeCAD; if not, write to the Free Software        *
19
 *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  *
20
 *   USA                                                                   *
21
 *                                                                         *
22
 ***************************************************************************/
23

24
#include "../FCConfig.h"
25

26
#ifdef _PreComp_
27
# undef _PreComp_
28
#endif
29

30
#ifdef FC_OS_LINUX
31
# include <unistd.h>
32
#endif
33

34
#if HAVE_CONFIG_H
35
# include <config.h>
36
#endif // HAVE_CONFIG_H
37

38
#include <cstdio>
39
#include <sstream>
40

41
// FreeCAD Base header
42
#include <Base/Console.h>
43
#include <Base/Exception.h>
44
#include <Base/Interpreter.h>
45

46
// FreeCAD doc header
47
#include <App/Application.h>
48

49

50
using Base::Console;
51
using App::Application;
52

53
const char sBanner[] = "(c) Juergen Riegel, Werner Mayer, Yorik van Havre and others 2001-2024\n"\
54
                       "FreeCAD is free and open-source software licensed under the terms of LGPL2+ license.\n"\
55
                       "FreeCAD wouldn't be possible without FreeCAD community.\n"\
56
                       "  #####                 ####  ###   ####  \n" \
57
                       "  #                    #      # #   #   # \n" \
58
                       "  #     ##  #### ####  #     #   #  #   # \n" \
59
                       "  ####  # # #  # #  #  #     #####  #   # \n" \
60
                       "  #     #   #### ####  #    #     # #   # \n" \
61
                       "  #     #   #    #     #    #     # #   #  ##  ##  ##\n" \
62
                       "  #     #   #### ####   ### #     # ####   ##  ##  ##\n\n" ;
63

64

65

66
int main( int argc, char ** argv )
67
{
68
    // Make sure that we use '.' as decimal point
69
    setlocale(LC_ALL, "");
70
    setlocale(LC_NUMERIC, "C");
71

72
#if defined(__MINGW32__)
73
    const char* mingw_prefix = getenv("MINGW_PREFIX");
74
    const char* py_home = getenv("PYTHONHOME");
75
    if (!py_home && mingw_prefix)
76
        _putenv_s("PYTHONHOME", mingw_prefix);
77
#endif
78

79
    // Name and Version of the Application
80
    App::Application::Config()["ExeName"] = "FreeCAD";
81
    App::Application::Config()["ExeVendor"] = "FreeCAD";
82
    App::Application::Config()["AppDataSkipVendor"] = "true";
83

84
    // set the banner (for logging and console)
85
    App::Application::Config()["CopyrightInfo"] = sBanner;
86

87
    try {
88
        // Init phase ===========================================================
89
        // sets the default run mode for FC, starts with command prompt if not overridden in InitConfig...
90
        App::Application::Config()["RunMode"] = "Exit";
91
        App::Application::Config()["LoggingConsole"] = "1";
92

93
        // Inits the Application
94
        App::Application::init(argc,argv);
95
    }
96
    catch (const Base::UnknownProgramOption& e) {
97
        std::cerr << e.what();
98
        exit(1);
99
    }
100
    catch (const Base::ProgramInformation& e) {
101
        std::cout << e.what();
102
        exit(0);
103
    }
104
    catch (const Base::Exception& e) {
105
        std::string appName = App::Application::Config()["ExeName"];
106
        std::stringstream msg;
107
        msg << "While initializing " << appName << " the following exception occurred: '" << e.what() << "'\n\n";
108
        msg << "Python is searching for its runtime files in the following directories:\n" << Py_EncodeLocale(Py_GetPath(),nullptr) << "\n\n";
109
        msg << "Python version information:\n" << Py_GetVersion() << "\n";
110
        const char* pythonhome = getenv("PYTHONHOME");
111
        if ( pythonhome ) {
112
            msg << "\nThe environment variable PYTHONHOME is set to '" << pythonhome << "'.";
113
            msg << "\nSetting this environment variable might cause Python to fail. Please contact your administrator to unset it on your system.\n\n";
114
        }
115
        else {
116
            msg << "\nPlease contact the application's support team for more information.\n\n";
117
        }
118

119
        printf("Initialization of %s failed:\n%s", appName.c_str(), msg.str().c_str());
120
        exit(100);
121
    }
122
    catch (...) {
123
        std::string appName = App::Application::Config()["ExeName"];
124
        std::stringstream msg;
125
        msg << "Unknown runtime error occurred while initializing " << appName <<".\n\n";
126
        msg << "Please contact the application's support team for more information.\n\n";
127
        printf("Initialization of %s failed:\n%s", appName.c_str(), msg.str().c_str());
128
        exit(101);
129
    }
130

131
    // Run phase ===========================================================
132
    try {
133
        Application::runApplication();
134
    }
135
    catch (const Base::SystemExitException &e) {
136
        exit(e.getExitCode());
137
    }
138
    catch (const Base::Exception& e) {
139
        e.ReportException();
140
        exit(1);
141
    }
142
    catch (...) {
143
        Console().Error("Application unexpectedly terminated\n");
144
        exit(1);
145
    }
146

147
    // Destruction phase ===========================================================
148
    Console().Log("FreeCAD terminating...\n");
149

150
    try {
151
        // close open documents
152
        App::GetApplication().closeAllDocuments();
153
    }
154
    catch(...) {
155
    }
156

157
    // cleans up
158
    Application::destruct();
159

160
    Console().Log("FreeCAD completely terminated\n");
161

162
    return 0;
163
}
164

165

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.