1 /****************************************************************************/ 2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo 3 // Copyright (C) 2001-2019 German Aerospace Center (DLR) and others. 4 // This program and the accompanying materials 5 // are made available under the terms of the Eclipse Public License v2.0 6 // which accompanies this distribution, and is available at 7 // http://www.eclipse.org/legal/epl-v20.html 8 // SPDX-License-Identifier: EPL-2.0 9 /****************************************************************************/ 10 /// @file NWWriter_SUMO.h 11 /// @author Daniel Krajzewicz 12 /// @author Jakob Erdmann 13 /// @author Michael Behrisch 14 /// @author Leonhard Luecken 15 /// @date Tue, 04.05.2011 16 /// @version $Id$ 17 /// 18 // Exporter writing networks using the SUMO format 19 /****************************************************************************/ 20 #ifndef NWWriter_SUMO_h 21 #define NWWriter_SUMO_h 22 23 24 // =========================================================================== 25 // included modules 26 // =========================================================================== 27 #include <config.h> 28 29 #include <string> 30 #include <map> 31 #include <netbuild/NBEdge.h> 32 #include <utils/xml/SUMOSAXHandler.h> 33 #include <utils/common/UtilExceptions.h> 34 #include <netbuild/NBConnectionDefs.h> 35 36 37 // =========================================================================== 38 // class declarations 39 // =========================================================================== 40 class OutputDevice; 41 class OptionsCont; 42 class NBNetBuilder; 43 class NBTrafficLightLogicCont; 44 class NBNode; 45 class NBDistrict; 46 class NBEdgeControl; 47 48 49 // =========================================================================== 50 // class definitions 51 // =========================================================================== 52 /** 53 * @class NWWriter_SUMO 54 * @brief Exporter writing networks using the SUMO format 55 * 56 */ 57 class NWWriter_SUMO { 58 public: 59 60 enum ConnectionStyle { 61 SUMONET, // all connection information 62 PLAIN, // only edges and link indices 63 TLL // like plain but include tl information 64 }; 65 66 /** @brief Writes the network into a SUMO-file 67 * 68 * @param[in] oc The options to use 69 * @param[in] nb The network builder to fill 70 */ 71 static void writeNetwork(const OptionsCont& oc, NBNetBuilder& nb); 72 73 74 /** @brief Writes connections outgoing from the given edge (also used in NWWriter_XML) 75 * @param[in] into The device to write the edge into 76 * @param[in] from The edge to write connections for 77 * @param[in] c The connection to write 78 * @param[in] includeInternal Whether information about inner-lanes used to cross the intersection shall be written 79 * @param[in] plain Whether only plain-xml output should be written (omit some attributes) 80 */ 81 static void writeConnection(OutputDevice& into, const NBEdge& from, const NBEdge::Connection& c, 82 bool includeInternal, ConnectionStyle style = SUMONET); 83 84 /// @brief writes the given prohibitions 85 static void writeProhibitions(OutputDevice& into, const NBConnectionProhibits& prohibitions); 86 87 /// @brief writes the traffic light logics to the given device 88 static void writeTrafficLights(OutputDevice& into, const NBTrafficLightLogicCont& tllCont); 89 90 /** @brief Writes roundabouts 91 * @param[in] into The device to write the edge into 92 * @param[in] roundaboutes The roundabouts to write 93 * @param[in] ec The edge control to retrieve named edges from 94 */ 95 static void writeRoundabouts(OutputDevice& into, const std::set<EdgeSet>& roundabouts, 96 const NBEdgeCont& ec); 97 98 99 /** @brief Write a stopOffset element into output device 100 */ 101 static void writeStopOffsets(OutputDevice& into, const std::map<SVCPermissions, double>& stopOffsets); 102 103 104 private: 105 /// @name Methods for writing network parts 106 /// @{ 107 108 /** @brief Writes internal edges (<edge ... with id[0]==':') of the given node 109 * @param[in] into The device to write the edges into 110 * @param[in] n The node to write the edges of 111 * @return Whether an internal edge was written 112 */ 113 static bool writeInternalEdges(OutputDevice& into, const NBEdgeCont& ec, const NBNode& n); 114 115 116 /** @brief Writes an edge (<edge ...) 117 * @param[in] into The device to write the edge into 118 * @param[in] e The edge to write 119 * @param[in] noNames Whether names shall be ignored 120 * @see writeLane() 121 */ 122 static void writeEdge(OutputDevice& into, const NBEdge& e, bool noNames); 123 124 125 /** @brief Writes a lane (<lane ...) of an edge 126 * @param[in] into The device to write the edge into 127 * @param[in] lID The ID of the lane 128 * @param[in] origID The original ID of the edge in the input 129 * @param[in] length Lane's length 130 * @param[in] index The index of the lane within the edge 131 * @param[in] oppositeID The ID of the opposite lane for overtaking 132 * @param[in] accelRamp whether this lane is an acceleration lane 133 * @param[in] customShape whether this lane has a custom shape 134 */ 135 static void writeLane(OutputDevice& into, const std::string& lID, 136 double speed, SVCPermissions permissions, SVCPermissions preferred, 137 double startOffset, double endOffset, 138 std::map<SVCPermissions, double> stopOffsets, double width, PositionVector shape, 139 const Parameterised* params, double length, int index, 140 const std::string& oppositeID, bool accelRamp = false, 141 bool customShape = false); 142 143 144 /** @brief Writes a junction (<junction ...) 145 * @param[in] into The device to write the edge into 146 * @param[in] n The junction/node to write 147 */ 148 static void writeJunction(OutputDevice& into, const NBNode& n); 149 150 151 /** @brief Writes internal junctions (<junction with id[0]==':' ...) of the given node 152 * @param[in] into The device to write the edge into 153 * @param[in] n The junction/node to write internal nodes for 154 */ 155 static bool writeInternalNodes(OutputDevice& into, const NBNode& n); 156 157 158 /** @brief Writes inner connections within the node 159 * @param[in] into The device to write the edge into 160 * @param[in] n The node to write inner links for 161 */ 162 static bool writeInternalConnections(OutputDevice& into, const NBNode& n); 163 164 165 /** @brief Writes a district 166 * @param[in] into The device to write the edge into 167 * @param[in] d The district 168 */ 169 static void writeDistrict(OutputDevice& into, const NBDistrict& d); 170 171 /** @brief Writes a single internal connection 172 * @param[in] from The id of the from-edge 173 * @param[in] to The id of the to-edge 174 * @param[in] toLane The indexd of the to-lane 175 * @param[in] via The (optional) via edge 176 */ 177 static void writeInternalConnection(OutputDevice& into, 178 const std::string& from, const std::string& to, 179 int fromLane, int toLane, const std::string& via, 180 LinkDirection dir = LINKDIR_STRAIGHT, 181 const std::string& tlID = "", 182 int linkIndex = NBConnection::InvalidTlIndex); 183 184 /// @brief writes a SUMOTime as int if possible, otherwise as a float 185 static std::string writeSUMOTime(SUMOTime time); 186 187 188 /// @brief the attribute value for a prohibition 189 static std::string prohibitionConnection(const NBConnection& c); 190 191 /** @brief Writes a roundabout 192 * @param[in] into The device to write the edge into 193 * @param[in] r The roundabout to write 194 * @param[in] ec The edge control to retrieve named edges from 195 */ 196 static void writeRoundabout(OutputDevice& into, const std::vector<std::string>& r, 197 const NBEdgeCont& ec); 198 199 /// @brief retrieve the id of the opposite direction internal lane if it exists 200 static std::string getOppositeInternalID(const NBEdgeCont& ec, const NBEdge* from, const NBEdge::Connection& con, double& oppositeLength); 201 202 }; 203 204 205 #endif 206 207 /****************************************************************************/ 208 209