MainCmd.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "../FCConfig.h"
00025
00026 #ifdef _PreComp_
00027 # undef _PreComp_
00028 #endif
00029
00030 #ifdef FC_OS_LINUX
00031 # include <unistd.h>
00032 #endif
00033
00034 #if HAVE_CONFIG_H
00035 # include <config.h>
00036 #endif // HAVE_CONFIG_H
00037
00038 #include <stdio.h>
00039 #include <sstream>
00040
00041
00042 #include <Base/Console.h>
00043 #include <Base/Interpreter.h>
00044 #include <Base/Parameter.h>
00045 #include <Base/Exception.h>
00046 #include <Base/Factory.h>
00047
00048
00049 #include <App/Application.h>
00050
00051
00052 using Base::Console;
00053 using App::Application;
00054
00055 const char sBanner[] = "(c) Juergen Riegel, Werner Mayer, Yorik van Havre 2001-2011\n"\
00056 " ##### #### ### #### \n" \
00057 " # # # # # # \n" \
00058 " # ## #### #### # # # # # \n" \
00059 " #### # # # # # # # ##### # # \n" \
00060 " # # #### #### # # # # # \n" \
00061 " # # # # # # # # # ## ## ##\n" \
00062 " # # #### #### ### # # #### ## ## ##\n\n" ;
00063
00064
00065
00066 int main( int argc, char ** argv )
00067 {
00068
00069 #if defined(FC_OS_LINUX)
00070 putenv("LANG=C");
00071 putenv("LC_ALL=C");
00072 #else
00073 setlocale(LC_NUMERIC, "C");
00074 #endif
00075
00076
00077 App::Application::Config()["ExeName"] = "FreeCAD";
00078 App::Application::Config()["ExeVendor"] = "FreeCAD";
00079 App::Application::Config()["AppDataSkipVendor"] = "true";
00080
00081
00082 App::Application::Config()["ConsoleBanner"] = sBanner;
00083
00084 try {
00085
00086
00087 App::Application::Config()["RunMode"] = "Exit";
00088
00089
00090 App::Application::init(argc,argv);
00091 }
00092 catch (const Base::Exception& e) {
00093 std::string appName = App::Application::Config()["ExeName"];
00094 std::stringstream msg;
00095 msg << "While initializing " << appName << " the following exception occurred: '" << e.what() << "'\n\n";
00096 msg << "Python is searching for its runtime files in the following directories:\n" << Py_GetPath() << "\n\n";
00097 msg << "Python version information:\n" << Py_GetVersion() << "\n";
00098 const char* pythonhome = getenv("PYTHONHOME");
00099 if ( pythonhome ) {
00100 msg << "\nThe environment variable PYTHONHOME is set to '" << pythonhome << "'.";
00101 msg << "\nSetting this environment variable might cause Python to fail. Please contact your administrator to unset it on your system.\n\n";
00102 }
00103 else {
00104 msg << "\nPlease contact the application's support team for more information.\n\n";
00105 }
00106
00107 printf("Initialization of %s failed:\n%s", appName.c_str(), msg.str().c_str());
00108 exit(100);
00109 }
00110 catch (...) {
00111 std::string appName = App::Application::Config()["ExeName"];
00112 std::stringstream msg;
00113 msg << "Unknown runtime error occurred while initializing " << appName <<".\n\n";
00114 msg << "Please contact the application's support team for more information.\n\n";
00115 printf("Initialization of %s failed:\n%s", appName.c_str(), msg.str().c_str());
00116 exit(101);
00117 }
00118
00119
00120 Application::runApplication();
00121
00122
00123
00124 Console().Log("FreeCAD terminating...\n");
00125
00126
00127 App::GetApplication().closeAllDocuments();
00128
00129
00130 Application::destruct();
00131
00132 Console().Log("FreeCAD completely terminated\n");
00133
00134 return 0;
00135 }
00136