|
SUMO - Simulation of Urban MObility
|
00001 /****************************************************************************/ 00007 // Main for NETCONVERT 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 <iostream> 00035 #include <string> 00036 #include <netimport/NIFrame.h> 00037 #include <netimport/NILoader.h> 00038 #include <netbuild/NBFrame.h> 00039 #include <netbuild/NBNetBuilder.h> 00040 #include <netbuild/NBDistribution.h> 00041 #include <netwrite/NWFrame.h> 00042 #include <utils/options/OptionsIO.h> 00043 #include <utils/options/OptionsCont.h> 00044 #include <utils/common/UtilExceptions.h> 00045 #include <utils/common/RandHelper.h> 00046 #include <utils/common/SystemFrame.h> 00047 #include <utils/common/MsgHandler.h> 00048 #include <utils/xml/XMLSubSys.h> 00049 #include <utils/iodevices/OutputDevice.h> 00050 #include <utils/geom/GeoConvHelper.h> 00051 00052 #ifdef CHECK_MEMORY_LEAKS 00053 #include <foreign/nvwa/debug_new.h> 00054 #endif // CHECK_MEMORY_LEAKS 00055 00056 00057 // =========================================================================== 00058 // method definitions 00059 // =========================================================================== 00060 void 00061 fillOptions() { 00062 OptionsCont& oc = OptionsCont::getOptions(); 00063 oc.addCallExample("-c <CONFIGURATION>"); 00064 oc.addCallExample("-n ./nodes.xml -e ./edges.xml -v -t ./owntypes.xml"); 00065 00066 // insert options sub-topics 00067 SystemFrame::addConfigurationOptions(oc); // this subtopic is filled here, too 00068 oc.addOptionSubTopic("Input"); 00069 oc.addOptionSubTopic("Output"); 00070 GeoConvHelper::addProjectionOptions(oc); 00071 oc.addOptionSubTopic("TLS Building"); 00072 oc.addOptionSubTopic("Ramp Guessing"); 00073 oc.addOptionSubTopic("Edge Removal"); 00074 oc.addOptionSubTopic("Unregulated Nodes"); 00075 oc.addOptionSubTopic("Processing"); 00076 oc.addOptionSubTopic("Building Defaults"); 00077 SystemFrame::addReportOptions(oc); // this subtopic is filled here, too 00078 00079 NIFrame::fillOptions(); 00080 NBFrame::fillOptions(false); 00081 NWFrame::fillOptions(); 00082 RandHelper::insertRandOptions(); 00083 } 00084 00085 00086 bool 00087 checkOptions() { 00088 bool ok = NIFrame::checkOptions(); 00089 ok &= NBFrame::checkOptions(); 00090 ok &= NWFrame::checkOptions(); 00091 return ok; 00092 } 00093 00094 00095 /* ------------------------------------------------------------------------- 00096 * main 00097 * ----------------------------------------------------------------------- */ 00098 int 00099 main(int argc, char** argv) { 00100 OptionsCont& oc = OptionsCont::getOptions(); 00101 // give some application descriptions 00102 oc.setApplicationDescription("Road network importer / builder for the road traffic simulation SUMO."); 00103 oc.setApplicationName("netconvert", "SUMO netconvert Version " + (std::string)VERSION_STRING); 00104 int ret = 0; 00105 try { 00106 XMLSubSys::init(false); 00107 fillOptions(); 00108 OptionsIO::getOptions(true, argc, argv); 00109 if (oc.processMetaOptions(argc < 2)) { 00110 SystemFrame::close(); 00111 return 0; 00112 } 00113 MsgHandler::initOutputOptions(); 00114 if (!checkOptions()) { 00115 throw ProcessError(); 00116 } 00117 RandHelper::initRandGlobal(); 00118 NBNetBuilder nb; 00119 nb.applyOptions(oc); 00120 // load data 00121 NILoader nl(nb); 00122 nl.load(oc); 00123 if (oc.getBool("ignore-errors")) { 00124 MsgHandler::getErrorInstance()->clear(); 00125 } 00126 // check whether any errors occured 00127 if (MsgHandler::getErrorInstance()->wasInformed()) { 00128 throw ProcessError(); 00129 } 00130 nb.compute(oc); 00131 NWFrame::writeNetwork(oc, nb); 00132 } catch (ProcessError& e) { 00133 if (std::string(e.what())!=std::string("Process Error") && std::string(e.what())!=std::string("")) { 00134 WRITE_ERROR(e.what()); 00135 } 00136 MsgHandler::getErrorInstance()->inform("Quitting (on error).", false); 00137 ret = 1; 00138 #ifndef _DEBUG 00139 } catch (...) { 00140 MsgHandler::getErrorInstance()->inform("Quitting (on unknown error).", false); 00141 ret = 1; 00142 #endif 00143 } 00144 NBDistribution::clear(); 00145 OutputDevice::closeAll(); 00146 SystemFrame::close(); 00147 // report about ending 00148 if (ret==0) { 00149 std::cout << "Success." << std::endl; 00150 } 00151 return ret; 00152 } 00153 00154 00155 00156 /****************************************************************************/ 00157