MainCmd.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   (c) Jürgen Riegel (juergen.riegel@web.de) 2008                        *
00003  *                                                                         *
00004  *   This file is part of the FreeCAD CAx development system.              *
00005  *                                                                         *
00006  *   This program is free software; you can redistribute it and/or modify  *
00007  *   it under the terms of the GNU Library General Public License (LGPL)   *
00008  *   as published by the Free Software Foundation; either version 2 of     *
00009  *   the License, or (at your option) any later version.                   *
00010  *   for detail see the LICENCE text file.                                 *
00011  *                                                                         *
00012  *   FreeCAD is distributed in the hope that it will be useful,            *
00013  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00014  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00015  *   GNU Library General Public License for more details.                  *
00016  *                                                                         *
00017  *   You should have received a copy of the GNU Library General Public     *
00018  *   License along with FreeCAD; if not, write to the Free Software        *
00019  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  *
00020  *   USA                                                                   *
00021  *                                                                         *
00022  *   Juergen Riegel 2002                                                   *
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 // FreeCAD Base header
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 // FreeCAD doc header
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     // Make sure that we use '.' as decimal point
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     // Name and Version of the Application
00077     App::Application::Config()["ExeName"] = "FreeCAD";
00078     App::Application::Config()["ExeVendor"] = "FreeCAD";
00079     App::Application::Config()["AppDataSkipVendor"] = "true";
00080 
00081     // set the banner (for logging and console)
00082     App::Application::Config()["ConsoleBanner"] = sBanner;
00083 
00084     try {
00085         // Init phase ===========================================================
00086         // sets the default run mode for FC, starts with command prompt if not overridden in InitConfig...
00087         App::Application::Config()["RunMode"] = "Exit";
00088 
00089         // Inits the Application
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     // Run phase ===========================================================
00120     Application::runApplication();
00121 
00122 
00123     // Destruction phase ===========================================================
00124     Console().Log("FreeCAD terminating...\n");
00125 
00126     // close open documents
00127     App::GetApplication().closeAllDocuments();
00128 
00129     // cleans up
00130     Application::destruct();
00131 
00132     Console().Log("FreeCAD completely terminated\n");
00133 
00134     return 0;
00135 }
00136 

Generated on Wed Nov 23 19:00:21 2011 for FreeCAD by  doxygen 1.6.1