/****************************************************************************/1// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo2// Copyright (C) 2001-2025 German Aerospace Center (DLR) and others.3// This program and the accompanying materials are made available under the4// terms of the Eclipse Public License 2.0 which is available at5// https://www.eclipse.org/legal/epl-2.0/6// This Source Code may also be made available under the following Secondary7// Licenses when the conditions for such availability set forth in the Eclipse8// Public License 2.0 are satisfied: GNU General Public License, version 29// or later which is available at10// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html11// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later12/****************************************************************************/13/// @file NIImporter_ITSUMO.h14/// @author Daniel Krajzewicz15/// @date 2011-09-1616///17// Importer for networks stored in ITSUMO format18/****************************************************************************/19#pragma once20#include <config.h>2122#include <string>23#include <map>24#include <netbuild/NBCapacity2Lanes.h>25#include <utils/xml/SUMOSAXHandler.h>26#include <utils/common/UtilExceptions.h>272829// ===========================================================================30// class declarations31// ===========================================================================32class NBEdge;33class NBEdgeCont;34class NBNetBuilder;35class NBNode;36class NBNodeCont;37class NBTrafficLightLogicCont;38class NBTypeCont;39class OptionsCont;404142// ===========================================================================43// class definitions44// ===========================================================================45/**46* @class NIImporter_ITSUMO47* @brief Importer for networks stored in ITSUMO format48*49*/50class NIImporter_ITSUMO {51public:52/** @brief Loads content of the optionally given ITSUMO network files53*54* If the option "itsumo-files" is set, the file(s) stored therein is read and55* the network definition stored therein is stored within the given network56* builder.57*58* If the option "itsumo-files" is not set, this method simply returns.59*60* @param[in] oc The options to use61* @param[in] nb The network builder to fill62*/63static void loadNetwork(const OptionsCont& oc, NBNetBuilder& nb);646566private:67/**68* @class NodesHandler69* @brief A class which parses an ITSUMO file70*/71class Handler : public GenericSAXHandler {72public:73/** @brief Contructor74* @param[in] toFill The container to fill75*/76Handler(NBNetBuilder& toFill);777879/// @brief Destructor80~Handler();818283protected:84/// @name inherited from GenericSAXHandler85//@{8687/** @brief Called on the opening of a tag;88*89* @param[in] element ID of the currently opened element90* @param[in] attrs Attributes within the currently opened element91* @exception ProcessError If something fails92* @see GenericSAXHandler::myStartElement93*/94void myStartElement(int element, const SUMOSAXAttributes& attrs);959697/**98* @brief Callback method for characters to implement by derived classes99*100* Called by "endElement" (see there).101* @param[in] element The opened element, given as a int102* @param[in] chars The complete embedded character string103* @exceptions ProcessError These method may throw a ProcessError if something fails104*/105void myCharacters(int element, const std::string& chars);106107108/** @brief Callback method for a closing tag to implement by derived classes109*110* Called by "endElement" (see there).111* @param[in] element The closed element, given as a int112* @exceptions ProcessError These method may throw a ProcessError if something fails113*/114void myEndElement(int element);115//@}116117118private:119/// @brief The container to fill120NBNetBuilder& myNetBuilder;121122/// @brief A temporary parameter map123Parameterised::Map myParameter;124125126struct Lane {127public:128Lane(const std::string& _id, int _idx, double _v)129: id(_id), index(_idx), v(_v) {}130std::string id;131int index;132double v;133};134135std::vector<Lane> myCurrentLanes;136137struct LaneSet {138public:139LaneSet(const std::string& _id, const std::vector<Lane>& _lanes, double _v, int _pos, NBNode* _from, NBNode* _to)140: id(_id), lanes(_lanes), v(_v), position(_pos), from(_from), to(_to) {}141std::string id;142std::vector<Lane> lanes;143double v;144int position;145NBNode* from;146NBNode* to;147};148149std::map<std::string, LaneSet*> myLaneSets;150std::vector<LaneSet*> myCurrentLaneSets;151152struct Section {153public:154Section(const std::string& _id, const std::vector<LaneSet*>& _laneSets)155: id(_id), laneSets(_laneSets) {}156std::string id;157std::vector<LaneSet*> laneSets;158};159160std::vector<Section*> mySections;161162163private:164/** @brief invalidated copy constructor */165Handler(const Handler& s);166167/** @brief invalidated assignment operator */168Handler& operator=(const Handler& s);169170};171172173174/**175* @enum ItsumoXMLTag176* @brief Numbers representing ITSUMO-XML - element names177* @see GenericSAXHandler178*/179enum ItsumoXMLTag {180ITSUMO_TAG_NOTHING = 0,181ITSUMO_TAG_SIMULATION,182ITSUMO_TAG_NETWORK_ID,183ITSUMO_TAG_NETWORK_NAME,184ITSUMO_TAG_NODES,185ITSUMO_TAG_NODE,186ITSUMO_TAG_NODE_ID,187ITSUMO_TAG_NODE_NAME,188ITSUMO_TAG_X_COORD,189ITSUMO_TAG_Y_COORD,190ITSUMO_TAG_SOURCES,191ITSUMO_TAG_SINKS,192ITSUMO_TAG_TRAFFIC_LIGHTS,193ITSUMO_TAG_STREETS,194ITSUMO_TAG_STREET,195ITSUMO_TAG_STREET_ID,196ITSUMO_TAG_STREET_NAME,197ITSUMO_TAG_SECTIONS,198ITSUMO_TAG_SECTION,199ITSUMO_TAG_SECTION_ID,200ITSUMO_TAG_SECTION_NAME,201ITSUMO_TAG_IS_PREFERENCIAL,202ITSUMO_TAG_DELIMITING_NODE,203ITSUMO_TAG_LANESETS,204ITSUMO_TAG_LANESET,205ITSUMO_TAG_LANESET_ID,206ITSUMO_TAG_LANESET_POSITION,207ITSUMO_TAG_START_NODE,208ITSUMO_TAG_END_NODE,209ITSUMO_TAG_TURNING_PROBABILITIES,210ITSUMO_TAG_DIRECTION,211ITSUMO_TAG_DESTINATION_LANESET,212ITSUMO_TAG_PROBABILITY,213ITSUMO_TAG_LANES,214ITSUMO_TAG_LANE,215ITSUMO_TAG_LANE_ID,216ITSUMO_TAG_LANE_POSITION,217ITSUMO_TAG_MAXIMUM_SPEED,218ITSUMO_TAG_DECELERATION_PROB219};220221222/**223* @enum ItsumoXMLAttr224* @brief Numbers representing MATSIM-XML - attributes225* @see GenericSAXHandler226*/227enum ItsumoXMLAttr {228ITSUMO_ATTR_NOTHING = 0229};230231/// The names of MATSIM-XML elements (for passing to GenericSAXHandler)232static SequentialStringBijection::Entry itsumoTags[];233234/// The names of MATSIM-XML attributes (for passing to GenericSAXHandler)235static SequentialStringBijection::Entry itsumoAttrs[];236237238};239240241