SUMO - Simulation of Urban MObility

netconvert_main.cpp

Go to the documentation of this file.
00001 /****************************************************************************/
00009 // Main for NETCONVERT
00010 /****************************************************************************/
00011 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/
00012 // Copyright (C) 2001-2012 DLR (http://www.dlr.de/) and contributors
00013 /****************************************************************************/
00014 //
00015 //   This file is part of SUMO.
00016 //   SUMO is free software: you can redistribute it and/or modify
00017 //   it under the terms of the GNU General Public License as published by
00018 //   the Free Software Foundation, either version 3 of the License, or
00019 //   (at your option) any later version.
00020 //
00021 /****************************************************************************/
00022 
00023 
00024 // ===========================================================================
00025 // included modules
00026 // ===========================================================================
00027 #ifdef _MSC_VER
00028 #include <windows_config.h>
00029 #else
00030 #include <config.h>
00031 #endif
00032 
00033 #ifdef HAVE_VERSION_H
00034 #include <version.h>
00035 #endif
00036 
00037 #include <iostream>
00038 #include <string>
00039 #include <netimport/NIFrame.h>
00040 #include <netimport/NILoader.h>
00041 #include <netbuild/NBFrame.h>
00042 #include <netbuild/NBNetBuilder.h>
00043 #include <netbuild/NBDistribution.h>
00044 #include <netwrite/NWFrame.h>
00045 #include <utils/options/OptionsIO.h>
00046 #include <utils/options/OptionsCont.h>
00047 #include <utils/common/UtilExceptions.h>
00048 #include <utils/common/RandHelper.h>
00049 #include <utils/common/SystemFrame.h>
00050 #include <utils/common/MsgHandler.h>
00051 #include <utils/xml/XMLSubSys.h>
00052 #include <utils/iodevices/OutputDevice.h>
00053 #include <utils/geom/GeoConvHelper.h>
00054 
00055 #ifdef CHECK_MEMORY_LEAKS
00056 #include <foreign/nvwa/debug_new.h>
00057 #endif // CHECK_MEMORY_LEAKS
00058 
00059 
00060 // ===========================================================================
00061 // method definitions
00062 // ===========================================================================
00063 void
00064 fillOptions() {
00065     OptionsCont& oc = OptionsCont::getOptions();
00066     oc.addCallExample("-c <CONFIGURATION>");
00067     oc.addCallExample("-n ./nodes.xml -e ./edges.xml -v -t ./owntypes.xml");
00068 
00069     // insert options sub-topics
00070     SystemFrame::addConfigurationOptions(oc); // this subtopic is filled here, too
00071     oc.addOptionSubTopic("Input");
00072     oc.addOptionSubTopic("Output");
00073     GeoConvHelper::addProjectionOptions(oc);
00074     oc.addOptionSubTopic("TLS Building");
00075     oc.addOptionSubTopic("Ramp Guessing");
00076     oc.addOptionSubTopic("Edge Removal");
00077     oc.addOptionSubTopic("Unregulated Nodes");
00078     oc.addOptionSubTopic("Processing");
00079     oc.addOptionSubTopic("Building Defaults");
00080     SystemFrame::addReportOptions(oc); // this subtopic is filled here, too
00081 
00082     NIFrame::fillOptions();
00083     NBFrame::fillOptions(false);
00084     NWFrame::fillOptions(false);
00085     RandHelper::insertRandOptions();
00086 }
00087 
00088 
00089 bool
00090 checkOptions() {
00091     bool ok = NIFrame::checkOptions();
00092     ok &= NBFrame::checkOptions();
00093     ok &= NWFrame::checkOptions();
00094     return ok;
00095 }
00096 
00097 
00098 /* -------------------------------------------------------------------------
00099  * main
00100  * ----------------------------------------------------------------------- */
00101 int
00102 main(int argc, char** argv) {
00103     OptionsCont& oc = OptionsCont::getOptions();
00104     // give some application descriptions
00105     oc.setApplicationDescription("Road network importer / builder for the road traffic simulation SUMO.");
00106     oc.setApplicationName("netconvert", "SUMO netconvert Version " + (std::string)VERSION_STRING);
00107     int ret = 0;
00108     try {
00109         XMLSubSys::init(false);
00110         fillOptions();
00111         OptionsIO::getOptions(true, argc, argv);
00112         if (oc.processMetaOptions(argc < 2)) {
00113             SystemFrame::close();
00114             return 0;
00115         }
00116         MsgHandler::initOutputOptions();
00117         if (!checkOptions()) {
00118             throw ProcessError();
00119         }
00120         RandHelper::initRandGlobal();
00121         NBNetBuilder nb;
00122         nb.applyOptions(oc);
00123         // load data
00124         NILoader nl(nb);
00125         nl.load(oc);
00126         if (oc.getBool("ignore-errors")) {
00127             MsgHandler::getErrorInstance()->clear();
00128         }
00129         // check whether any errors occured
00130         if (MsgHandler::getErrorInstance()->wasInformed()) {
00131             throw ProcessError();
00132         }
00133         nb.compute(oc);
00134         NWFrame::writeNetwork(oc, nb);
00135     } catch (ProcessError& e) {
00136         if (std::string(e.what()) != std::string("Process Error") && std::string(e.what()) != std::string("")) {
00137             WRITE_ERROR(e.what());
00138         }
00139         MsgHandler::getErrorInstance()->inform("Quitting (on error).", false);
00140         ret = 1;
00141 #ifndef _DEBUG
00142     } catch (...) {
00143         MsgHandler::getErrorInstance()->inform("Quitting (on unknown error).", false);
00144         ret = 1;
00145 #endif
00146     }
00147     NBDistribution::clear();
00148     OutputDevice::closeAll();
00149     SystemFrame::close();
00150     // report about ending
00151     if (ret == 0) {
00152         std::cout << "Success." << std::endl;
00153     }
00154     return ret;
00155 }
00156 
00157 
00158 
00159 /****************************************************************************/
00160 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Defines