SUMO - Simulation of Urban MObility

NWFrame.cpp

Go to the documentation of this file.
00001 /****************************************************************************/
00009 // Sets and checks options for netwrite
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 #include <string>
00034 #include <utils/options/Option.h>
00035 #include <utils/options/OptionsCont.h>
00036 #include <utils/common/MsgHandler.h>
00037 #include <utils/common/SystemFrame.h>
00038 #include <utils/iodevices/OutputDevice.h>
00039 #include <netbuild/NBNetBuilder.h>
00040 #include "NWFrame.h"
00041 #include "NWWriter_SUMO.h"
00042 #include "NWWriter_MATSim.h"
00043 #include "NWWriter_XML.h"
00044 #include "NWWriter_OpenDrive.h"
00045 
00046 #ifdef CHECK_MEMORY_LEAKS
00047 #include <foreign/nvwa/debug_new.h>
00048 #endif // CHECK_MEMORY_LEAKS
00049 
00050 // ===========================================================================
00051 // static members
00052 // ===========================================================================
00053 const std::string NWFrame::MAJOR_VERSION = "version=\"0.13\"";
00054 
00055 
00056 // ===========================================================================
00057 // method definitions
00058 // ===========================================================================
00059 void
00060 NWFrame::fillOptions(bool forNetgen) {
00061     OptionsCont& oc = OptionsCont::getOptions();
00062     // register options
00063     oc.doRegister("output-file", 'o', new Option_FileName());
00064     oc.addSynonyme("output-file", "sumo-output");
00065     oc.addSynonyme("output-file", "output");
00066     oc.addDescription("output-file", "Output", "The generated net will be written to FILE");
00067 
00068     oc.doRegister("plain-output-prefix", new Option_FileName());
00069     oc.addSynonyme("plain-output-prefix", "plain-output");
00070     oc.addSynonyme("plain-output-prefix", "plain");
00071     oc.addDescription("plain-output-prefix", "Output", "Prefix of files to write plain xml nodes, edges and connections to");
00072 
00073 #ifdef HAVE_PROJ
00074     if (!forNetgen) {
00075         oc.doRegister("proj.plain-geo", new Option_Bool(false));
00076         oc.addDescription("proj.plain-geo", "Projection", "Write geo coordinates in plain-xml");
00077     }
00078 #endif // HAVE_PROJ
00079 
00080     oc.doRegister("map-output", 'M', new Option_FileName());
00081     oc.addDescription("map-output", "Output", "Writes joined edges information to FILE");
00082 
00083     oc.doRegister("matsim-output", new Option_FileName());
00084     oc.addDescription("matsim-output", "Output", "The generated net will be written to FILE using MATsim format.");
00085 
00086     oc.doRegister("opendrive-output", new Option_FileName());
00087     oc.addDescription("opendrive-output", "Output", "The generated net will be written to FILE using openDRIVE format.");
00088 
00089     oc.doRegister("output.street-names", new Option_Bool(false));
00090     oc.addDescription("output.street-names", "Output", "Street names will be included in the output (if available).");
00091 }
00092 
00093 
00094 bool
00095 NWFrame::checkOptions() {
00096     OptionsCont& oc = OptionsCont::getOptions();
00097     bool ok = true;
00098     // check whether the output is valid and can be build
00099     if (!oc.isSet("output-file")&&!oc.isSet("plain-output-prefix")&&!oc.isSet("matsim-output")&&!oc.isSet("opendrive-output")) {
00100         oc.set("output-file", "net.net.xml");
00101     }
00102     // some outputs need internal lanes
00103     if (oc.isSet("opendrive-output")&&oc.getBool("no-internal-links")) {
00104         WRITE_ERROR("openDRIVE export needs internal links computation.");
00105         ok = false;
00106     }
00107     return ok;
00108 }
00109 
00110 
00111 void
00112 NWFrame::writeNetwork(const OptionsCont& oc, NBNetBuilder& nb) {
00113     NWWriter_SUMO::writeNetwork(oc, nb);
00114     NWWriter_MATSim::writeNetwork(oc, nb);
00115     NWWriter_OpenDrive::writeNetwork(oc, nb);
00116     NWWriter_XML::writeNetwork(oc, nb);
00117     // save the mapping information when wished
00118     if (oc.isSet("map-output")) {
00119         OutputDevice& mdevice = OutputDevice::getDevice(oc.getString("map-output"));
00120         mdevice << nb.getJoinedEdgesMap();
00121         mdevice.close();
00122     }
00123 }
00124 
00125 
00126 void
00127 NWFrame::writePositionLong(const Position& pos, OutputDevice& dev) {
00128     dev.writeAttr(SUMO_ATTR_X, pos.x());
00129     dev.writeAttr(SUMO_ATTR_Y, pos.y());
00130     if (pos.z() != 0) {
00131         dev.writeAttr(SUMO_ATTR_Z, pos.z());
00132     }
00133 }
00134 
00135 /****************************************************************************/
00136 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Defines