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>", "generate net with options read from file");
00067     oc.addCallExample("-n ./nodes.xml -e ./edges.xml -v -t ./owntypes.xml",
00068                       "generate net with given nodes, edges, and edge types doing verbose output");
00069 
00070     // insert options sub-topics
00071     SystemFrame::addConfigurationOptions(oc); // this subtopic is filled here, too
00072     oc.addOptionSubTopic("Input");
00073     oc.addOptionSubTopic("Output");
00074     GeoConvHelper::addProjectionOptions(oc);
00075     oc.addOptionSubTopic("TLS Building");
00076     oc.addOptionSubTopic("Ramp Guessing");
00077     oc.addOptionSubTopic("Edge Removal");
00078     oc.addOptionSubTopic("Unregulated Nodes");
00079     oc.addOptionSubTopic("Processing");
00080     oc.addOptionSubTopic("Building Defaults");
00081     SystemFrame::addReportOptions(oc); // this subtopic is filled here, too
00082 
00083     NIFrame::fillOptions();
00084     NBFrame::fillOptions(false);
00085     NWFrame::fillOptions(false);
00086     RandHelper::insertRandOptions();
00087 }
00088 
00089 
00090 bool
00091 checkOptions() {
00092     bool ok = NIFrame::checkOptions();
00093     ok &= NBFrame::checkOptions();
00094     ok &= NWFrame::checkOptions();
00095     return ok;
00096 }
00097 
00098 
00099 /* -------------------------------------------------------------------------
00100  * main
00101  * ----------------------------------------------------------------------- */
00102 int
00103 main(int argc, char** argv) {
00104     OptionsCont& oc = OptionsCont::getOptions();
00105     // give some application descriptions
00106     oc.setApplicationDescription("Road network importer / builder for the road traffic simulation SUMO.");
00107     oc.setApplicationName("netconvert", "SUMO netconvert Version " + (std::string)VERSION_STRING);
00108     int ret = 0;
00109     try {
00110         XMLSubSys::init(false);
00111         fillOptions();
00112         OptionsIO::getOptions(true, argc, argv);
00113         if (oc.processMetaOptions(argc < 2)) {
00114             OutputDevice::closeAll();
00115             SystemFrame::close();
00116             return 0;
00117         }
00118         MsgHandler::initOutputOptions();
00119         if (!checkOptions()) {
00120             throw ProcessError();
00121         }
00122         RandHelper::initRandGlobal();
00123         NBNetBuilder nb;
00124         nb.applyOptions(oc);
00125         // load data
00126         NILoader nl(nb);
00127         nl.load(oc);
00128         if (oc.getBool("ignore-errors")) {
00129             MsgHandler::getErrorInstance()->clear();
00130         }
00131         // check whether any errors occured
00132         if (MsgHandler::getErrorInstance()->wasInformed()) {
00133             throw ProcessError();
00134         }
00135         nb.compute(oc);
00136         NWFrame::writeNetwork(oc, nb);
00137     } catch (ProcessError& e) {
00138         if (std::string(e.what()) != std::string("Process Error") && std::string(e.what()) != std::string("")) {
00139             WRITE_ERROR(e.what());
00140         }
00141         MsgHandler::getErrorInstance()->inform("Quitting (on error).", false);
00142         ret = 1;
00143 #ifndef _DEBUG
00144     } catch (...) {
00145         MsgHandler::getErrorInstance()->inform("Quitting (on unknown error).", false);
00146         ret = 1;
00147 #endif
00148     }
00149     NBDistribution::clear();
00150     OutputDevice::closeAll();
00151     SystemFrame::close();
00152     // report about ending
00153     if (ret == 0) {
00154         std::cout << "Success." << std::endl;
00155     }
00156     return ret;
00157 }
00158 
00159 
00160 
00161 /****************************************************************************/
00162 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Defines