SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
NWFrame.cpp
Go to the documentation of this file.
1 /****************************************************************************/
9 // Sets and checks options for netwrite
10 /****************************************************************************/
11 // SUMO, Simulation of Urban MObility; see http://sumo-sim.org/
12 // Copyright (C) 2001-2013 DLR (http://www.dlr.de/) and contributors
13 /****************************************************************************/
14 //
15 // This file is part of SUMO.
16 // SUMO is free software: you can redistribute it and/or modify
17 // it under the terms of the GNU General Public License as published by
18 // the Free Software Foundation, either version 3 of the License, or
19 // (at your option) any later version.
20 //
21 /****************************************************************************/
22 
23 
24 // ===========================================================================
25 // included modules
26 // ===========================================================================
27 #ifdef _MSC_VER
28 #include <windows_config.h>
29 #else
30 #include <config.h>
31 #endif
32 
33 #include <string>
34 #include <utils/options/Option.h>
39 #include <netbuild/NBNetBuilder.h>
40 #include "NWFrame.h"
41 #include "NWWriter_SUMO.h"
42 #include "NWWriter_MATSim.h"
43 #include "NWWriter_XML.h"
44 #include "NWWriter_OpenDrive.h"
45 #include "NWWriter_DlrNavteq.h"
46 
47 #ifdef CHECK_MEMORY_LEAKS
48 #include <foreign/nvwa/debug_new.h>
49 #endif // CHECK_MEMORY_LEAKS
50 
51 // ===========================================================================
52 // static members
53 // ===========================================================================
54 const std::string NWFrame::MAJOR_VERSION = "version=\"0.13\"";
55 
56 
57 // ===========================================================================
58 // method definitions
59 // ===========================================================================
60 void
61 NWFrame::fillOptions(bool forNetgen) {
63  // register options
64  oc.doRegister("output-file", 'o', new Option_FileName());
65  oc.addSynonyme("output-file", "sumo-output");
66  oc.addSynonyme("output-file", "output");
67  oc.addDescription("output-file", "Output", "The generated net will be written to FILE");
68 
69  oc.doRegister("plain-output-prefix", new Option_FileName());
70  oc.addSynonyme("plain-output-prefix", "plain-output");
71  oc.addSynonyme("plain-output-prefix", "plain");
72  oc.addDescription("plain-output-prefix", "Output", "Prefix of files to write plain xml nodes, edges and connections to");
73 
74  oc.doRegister("junctions.join-output", new Option_FileName());
75  oc.addDescription("junctions.join-output", "Output",
76  "Writes information about joined junctions to FILE (can be loaded as additional node-file to reproduce joins");
77 
78 #ifdef HAVE_PROJ
79  if (!forNetgen) {
80  oc.doRegister("proj.plain-geo", new Option_Bool(false));
81  oc.addDescription("proj.plain-geo", "Projection", "Write geo coordinates in plain-xml");
82  }
83 #endif // HAVE_PROJ
84 
85  oc.doRegister("map-output", 'M', new Option_FileName());
86  oc.addDescription("map-output", "Output", "Writes joined edges information to FILE");
87 
88  oc.doRegister("matsim-output", new Option_FileName());
89  oc.addDescription("matsim-output", "Output", "The generated net will be written to FILE using MATsim format");
90 
91  oc.doRegister("opendrive-output", new Option_FileName());
92  oc.addDescription("opendrive-output", "Output", "The generated net will be written to FILE using OpenDRIVE format");
93 
94  oc.doRegister("dlr-navteq-output", new Option_FileName());
95  oc.addDescription("dlr-navteq-output", "Output", "The generated net will be written to dlr-navteq files with the given PREFIX");
96 
97  oc.doRegister("output.street-names", new Option_Bool(false));
98  oc.addDescription("output.street-names", "Output", "Street names will be included in the output (if available)");
99 
100  oc.doRegister("output.original-names", new Option_Bool(false));
101  oc.addDescription("output.original-names", "Output", "Writes original names, if given, as parameter");
102 
103  oc.doRegister("street-sign-output", new Option_FileName());
104  oc.addDescription("street-sign-output", "Output", "Writes street signs as POIs to FILE");
105 }
106 
107 
108 bool
111  bool ok = true;
112  // check whether the output is valid and can be build
113  if (!oc.isSet("output-file")
114  && !oc.isSet("plain-output-prefix")
115  && !oc.isSet("matsim-output")
116  && !oc.isSet("opendrive-output")
117  && !oc.isSet("dlr-navteq-output")) {
118  oc.set("output-file", "net.net.xml");
119  }
120  // some outputs need internal lanes
121  if (oc.isSet("opendrive-output") && oc.getBool("no-internal-links")) {
122  WRITE_ERROR("OpenDRIVE export needs internal links computation.");
123  ok = false;
124  }
125  return ok;
126 }
127 
128 
129 void
136  // save the mapping information when wished
137  if (oc.isSet("map-output")) {
138  OutputDevice& mdevice = OutputDevice::getDevice(oc.getString("map-output"));
139  mdevice << nb.getJoinedEdgesMap();
140  mdevice.close();
141  }
142 }
143 
144 
145 void
147  dev.writeAttr(SUMO_ATTR_X, pos.x());
148  dev.writeAttr(SUMO_ATTR_Y, pos.y());
149  if (pos.z() != 0) {
150  dev.writeAttr(SUMO_ATTR_Z, pos.z());
151  }
152 }
153 
154 /****************************************************************************/
155 
void doRegister(const std::string &name, Option *v)
Adds an option under the given name.
Definition: OptionsCont.cpp:84
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:254
void close()
Closes the device and removes it from the dictionary.
static bool checkOptions()
Checks set options from the OptionsCont-singleton for being valid.
Definition: NWFrame.cpp:109
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
SUMOReal x() const
Returns the x-position.
Definition: Position.h:63
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:67
void addSynonyme(const std::string &name1, const std::string &name2, bool isDeprecated=false)
Adds a synonyme for an options name (any order)
std::string getString(const std::string &name) const
Returns the string-value of the named option (only for Option_String)
static void writeNetwork(const OptionsCont &oc, NBNetBuilder &nb)
Writes the network into a SUMO-file.
static void writeNetwork(const OptionsCont &oc, NBNetBuilder &nb)
Writes the network into a openDRIVE-file.
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:46
SUMOReal z() const
Returns the z-position.
Definition: Position.h:73
static void writeNetwork(const OptionsCont &oc, NBNetBuilder &nb)
Writes the network into XML-files (nodes, edges, connections, traffic lights)
static void writePositionLong(const Position &pos, OutputDevice &dev)
Writes the given position to device in long format (one attribute per dimension)
Definition: NWFrame.cpp:146
static void writeNetwork(const OptionsCont &oc, NBNetBuilder &nb)
Writes the network into XML-files (nodes, edges, connections, traffic lights)
static void writeNetwork(const OptionsCont &oc, NBNetBuilder &nb)
Writes the network stored in the given net builder.
Definition: NWFrame.cpp:130
#define WRITE_ERROR(msg)
Definition: MsgHandler.h:201
const NBJoinedEdgesMap & getJoinedEdgesMap() const
Returns the joined edges map.
Definition: NBNetBuilder.h:202
bool set(const std::string &name, const std::string &value)
Sets the given value for the named option.
Instance responsible for building networks.
Definition: NBNetBuilder.h:113
static OutputDevice & getDevice(const std::string &name)
Returns the described OutputDevice.
SUMOReal y() const
Returns the y-position.
Definition: Position.h:68
A storage for options typed value containers)
Definition: OptionsCont.h:108
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:70
void addDescription(const std::string &name, const std::string &subtopic, const std::string &description)
Adds a description for an option.
static void fillOptions(bool forNetgen)
Inserts options used by the network writer.
Definition: NWFrame.cpp:61
static const std::string MAJOR_VERSION
The version number for written files.
Definition: NWFrame.h:77
static void writeNetwork(const OptionsCont &oc, NBNetBuilder &nb)
Writes the network into a MATSim-file.
bool isSet(const std::string &name, bool failOnNonExistant=true) const
Returns the information whether the named option is set.