SUMO - Simulation of Urban MObility

guisim_main.cpp

Go to the documentation of this file.
00001 /****************************************************************************/
00007 // Main for GUISIM
00008 /****************************************************************************/
00009 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/
00010 // Copyright (C) 2001-2011 DLR (http://www.dlr.de/) and contributors
00011 /****************************************************************************/
00012 //
00013 //   This program is free software; you can redistribute it and/or modify
00014 //   it under the terms of the GNU General Public License as published by
00015 //   the Free Software Foundation; either version 2 of the License, or
00016 //   (at your option) any later version.
00017 //
00018 /****************************************************************************/
00019 
00020 
00021 // ===========================================================================
00022 // included modules
00023 // ===========================================================================
00024 #ifdef _MSC_VER
00025 #include <windows_config.h>
00026 #else
00027 #include <config.h>
00028 #endif
00029 
00030 #ifdef HAVE_VERSION_H
00031 #include <version.h>
00032 #endif
00033 
00034 #include <ctime>
00035 #include <signal.h>
00036 #include <iostream>
00037 #include <fx.h>
00038 #include <fx3d.h>
00039 #include <microsim/MSNet.h>
00040 #include <utils/options/Option.h>
00041 #include <utils/options/OptionsCont.h>
00042 #include <utils/options/OptionsIO.h>
00043 #include <utils/common/UtilExceptions.h>
00044 #include <utils/common/FileHelpers.h>
00045 #include <utils/common/MsgHandler.h>
00046 #include <utils/common/SystemFrame.h>
00047 #include <utils/xml/XMLSubSys.h>
00048 #include <gui/GUIApplicationWindow.h>
00049 #include <utils/gui/windows/GUIAppEnum.h>
00050 #include <gui/GUIGlobals.h>
00051 #include <guisim/GUIEdge.h>
00052 #include <utils/gui/windows/GUIAppGlobals.h>
00053 #include <utils/gui/images/GUITexturesHelper.h>
00054 #include <utils/gui/settings/GUICompleteSchemeStorage.h>
00055 #include <gui/GUIViewTraffic.h>
00056 #include <guisim/GUIVehicle.h>
00057 
00058 #ifdef CHECK_MEMORY_LEAKS
00059 #include <foreign/nvwa/debug_new.h>
00060 #endif
00061 
00062 
00063 // ===========================================================================
00064 // methods
00065 // ===========================================================================
00066 /* -------------------------------------------------------------------------
00067  * options initialisation
00068  * ----------------------------------------------------------------------- */
00069 void
00070 fillOptions() {
00071     OptionsCont& oc = OptionsCont::getOptions();
00072     oc.addCallExample("");
00073     oc.addCallExample("-c <CONFIGURATION>");
00074 
00075     // insert options sub-topics
00076     oc.addOptionSubTopic("Process");
00077     oc.addOptionSubTopic("Visualisation");
00078 
00079     oc.doRegister("configuration-file", 'c', new Option_FileName());
00080     oc.addSynonyme("configuration-file", "configuration");
00081     oc.addDescription("configuration-file", "Process", "Loads the named config on startup");
00082 
00083     oc.doRegister("help", '?', new Option_Bool(false));
00084     oc.addDescription("help", "Process", "Prints this screen");
00085 
00086     oc.doRegister("version", 'V', new Option_Bool(false));
00087     oc.addDescription("version", "Process", "Prints the current version");
00088 
00089     oc.doRegister("quit-on-end", 'Q', new Option_Bool(false));
00090     oc.addDescription("quit-on-end", "Process", "Quits the gui when the simulation stops");
00091 
00092     oc.doRegister("game", 'G', new Option_Bool(false));
00093     oc.addDescription("game", "Process", "Start the GUI in gaming mode");
00094 
00095     oc.doRegister("no-start", 'N', new Option_Bool(false));
00096     oc.addDescription("no-start", "Process", "Does not start the simulation after loading");
00097 
00098     oc.doRegister("disable-textures", 'T', new Option_Bool(false)); // !!!
00099     oc.addDescription("disable-textures", "Visualisation", "");
00100 }
00101 
00102 
00103 /* -------------------------------------------------------------------------
00104  * main
00105  * ----------------------------------------------------------------------- */
00106 int
00107 main(int argc, char** argv) {
00108     // make the output aware of threading
00109     MFXMutex lock;
00110     MsgHandler::assignLock(&lock);
00111     // get the options
00112     OptionsCont& oc = OptionsCont::getOptions();
00113     // give some application descriptions
00114     oc.setApplicationDescription("GUI version of the simulation SUMO.");
00115     oc.setApplicationName("sumo-gui.exe", "SUMO gui Version " + (std::string)VERSION_STRING);
00116     int ret = 0;
00117 #ifndef _DEBUG
00118     try {
00119 #else
00120     {
00121 #endif
00122         // initialise subsystems
00123         XMLSubSys::init(false);
00124         fillOptions();
00125         OptionsIO::getOptions(false, argc, argv);
00126         if (oc.processMetaOptions(false)) {
00127             SystemFrame::close();
00128             return 0;
00129         }
00130         // within gui-based applications, nothing is reported to the console
00131         MsgHandler::getErrorInstance()->report2cout(false);
00132         MsgHandler::getErrorInstance()->report2cerr(false);
00133         MsgHandler::getWarningInstance()->report2cout(false);
00134         MsgHandler::getWarningInstance()->report2cerr(false);
00135         MsgHandler::getMessageInstance()->report2cout(false);
00136         MsgHandler::getMessageInstance()->report2cerr(false);
00137         // Make application
00138         FXApp application("SUMO GUISimulation", "DLR");
00139         gFXApp = &application;
00140         // Open display
00141         application.init(argc,argv);
00142         int minor, major;
00143         if (!FXGLVisual::supported(&application, major, minor)) {
00144             throw ProcessError("This system has no OpenGL support. Exiting.");
00145         }
00146         // initialise global settings
00147         gQuitOnEnd = oc.getBool("quit-on-end");
00148         gAllowTextures = !oc.getBool("disable-textures");
00149 
00150         // build the main window
00151         GUIApplicationWindow* window =
00152         new GUIApplicationWindow(&application, "*.sumo.cfg");
00153         window->dependentBuild(oc.getBool("game"));
00154         gSchemeStorage.init(&application);
00155         // Create app
00156         application.addSignal(SIGINT,window, MID_QUIT);
00157         application.create();
00158         // Load configuration given on command line
00159         if (oc.isSet("configuration-file")) {
00160             window->loadOnStartup(oc.getString("configuration-file"),
00161             !oc.getBool("no-start"));
00162         }
00163         // Run
00164         ret = application.run();
00165 #ifndef _DEBUG
00166     } catch (...) {
00167         MsgHandler::getErrorInstance()->inform("Quitting (on error).", false);
00168         ret = 1;
00169     }
00170 #else
00171     }
00172 #endif
00173     SystemFrame::close();
00174     return ret;
00175 }
00176 
00177 
00178 
00179 /****************************************************************************/
00180 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Defines