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     oc.doRegister("junctions.join-output", new Option_FileName());
00074     oc.addDescription("junctions.join-output", "Output",
00075                       "Writes information about joined junctions to FILE (can be loaded as additional node-file to reproduce joins");
00076 
00077 #ifdef HAVE_PROJ
00078     if (!forNetgen) {
00079         oc.doRegister("proj.plain-geo", new Option_Bool(false));
00080         oc.addDescription("proj.plain-geo", "Projection", "Write geo coordinates in plain-xml");
00081     }
00082 #endif // HAVE_PROJ
00083 
00084     oc.doRegister("map-output", 'M', new Option_FileName());
00085     oc.addDescription("map-output", "Output", "Writes joined edges information to FILE");
00086 
00087     oc.doRegister("matsim-output", new Option_FileName());
00088     oc.addDescription("matsim-output", "Output", "The generated net will be written to FILE using MATsim format.");
00089 
00090     oc.doRegister("opendrive-output", new Option_FileName());
00091     oc.addDescription("opendrive-output", "Output", "The generated net will be written to FILE using openDRIVE format.");
00092 
00093     oc.doRegister("output.street-names", new Option_Bool(false));
00094     oc.addDescription("output.street-names", "Output", "Street names will be included in the output (if available).");
00095 }
00096 
00097 
00098 bool
00099 NWFrame::checkOptions() {
00100     OptionsCont& oc = OptionsCont::getOptions();
00101     bool ok = true;
00102     // check whether the output is valid and can be build
00103     if (!oc.isSet("output-file")&&!oc.isSet("plain-output-prefix")&&!oc.isSet("matsim-output")&&!oc.isSet("opendrive-output")) {
00104         oc.set("output-file", "net.net.xml");
00105     }
00106     // some outputs need internal lanes
00107     if (oc.isSet("opendrive-output")&&oc.getBool("no-internal-links")) {
00108         WRITE_ERROR("openDRIVE export needs internal links computation.");
00109         ok = false;
00110     }
00111     return ok;
00112 }
00113 
00114 
00115 void
00116 NWFrame::writeNetwork(const OptionsCont& oc, NBNetBuilder& nb) {
00117     NWWriter_SUMO::writeNetwork(oc, nb);
00118     NWWriter_MATSim::writeNetwork(oc, nb);
00119     NWWriter_OpenDrive::writeNetwork(oc, nb);
00120     NWWriter_XML::writeNetwork(oc, nb);
00121     // save the mapping information when wished
00122     if (oc.isSet("map-output")) {
00123         OutputDevice& mdevice = OutputDevice::getDevice(oc.getString("map-output"));
00124         mdevice << nb.getJoinedEdgesMap();
00125         mdevice.close();
00126     }
00127 }
00128 
00129 
00130 void
00131 NWFrame::writePositionLong(const Position& pos, OutputDevice& dev) {
00132     dev.writeAttr(SUMO_ATTR_X, pos.x());
00133     dev.writeAttr(SUMO_ATTR_Y, pos.y());
00134     if (pos.z() != 0) {
00135         dev.writeAttr(SUMO_ATTR_Z, pos.z());
00136     }
00137 }
00138 
00139 /****************************************************************************/
00140 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Defines