Path: blob/main/src/netimport/vissim/NIImporter_Vissim.h
169678 views
/****************************************************************************/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_Vissim.h14/// @author Daniel Krajzewicz15/// @author Michael Behrisch16/// @author Lukas Grohmann (AIT)17/// @author Gerald Richter (AIT)18/// @date Sept 200219///20// Importer for networks stored in Vissim format21/****************************************************************************/22#pragma once23#include <config.h>2425#include <string>26#include <map>27#include <vector>28#include <utils/common/RGBColor.h>29#include <utils/geom/Position.h>30#include "tempstructs/NIVissimExtendedEdgePoint.h"31#include "NIVissimElements.h"32#include <utils/xml/SUMOSAXHandler.h>33#include "tempstructs/NIVissimEdge.h"34#include "tempstructs/NIVissimConnection.h"35#include "tempstructs/NIVissimConflictArea.h"3637#include <utils/common/SequentialStringBijection.h>38#include <utils/common/StringTokenizer.h>39#include <list>4041// ===========================================================================42// class declarations43// ===========================================================================44class OptionsCont;45class NBNetBuilder;464748// ===========================================================================49// class definitions50// ===========================================================================51/**52* @class NIImporter_Vissim53* @brief Importer for networks stored in Vissim format54*/55class NIImporter_Vissim {56public:57/** @brief Loads network definition from the assigned option and stores it in the given network builder58*59* If the option "vissim-file" is set, the file stored therein is read and60* the network definition stored therein is stored within the given network61* builder.62*63* If the option "vissim-file" is not set, this method simply returns.64*65* @param[in] oc The options to use66* @param[in] nb The network builder to fill67*/68static void loadNetwork(const OptionsCont& oc, NBNetBuilder& nb);69707172private:7374typedef std::map<std::string, std::list<std::string> > nodeMap;75nodeMap elementData;7677/**78* @class NIVissimSingleTypeXMLHandler_Streckendefinition79* @brief A class which extracts VISSIM-Strecken from a parsed VISSIM-file80*/81class NIVissimXMLHandler_Streckendefinition : public GenericSAXHandler {82public:83/** @brief Constructor84* @param[in] strecken_dic The strecken dictionary to fill85*/86//NIVissimXMLHandler_Streckendefinition(std::map<int, VissimXMLEdge>& toFill);87NIVissimXMLHandler_Streckendefinition(nodeMap& elemData);888990/// @brief Destructor91~NIVissimXMLHandler_Streckendefinition();9293protected:94/// @name inherited from GenericSAXHandler95//@{9697/** @brief Called on the opening of a tag;98*99* @param[in] element ID of the currently opened element100* @param[in] attrs Attributes within the currently opened element101* @exception ProcessError If something fails102* @see GenericSAXHandler::myStartElement103*/104void myStartElement(int element, const SUMOSAXAttributes& attrs);105//@}106107void myEndElement(int element);108//@}109110private:111112//std::map<int, VissimXMLEdge> myToFill;113nodeMap& myElemData;114115/// @brief The current hierarchy level116int myHierarchyLevel;117118/// @brief check if the link is a connector119bool isConnector;120121/// @brief ID of the currently parsed node, for reporting mainly122int myLastNodeID;123124/** @brief invalidated copy constructor */125NIVissimXMLHandler_Streckendefinition(const NIVissimXMLHandler_Streckendefinition& s);126127/** @brief invalidated assignment operator */128NIVissimXMLHandler_Streckendefinition& operator=(const NIVissimXMLHandler_Streckendefinition& s);129};130131132private:133/**134* @class NIVissimSingleTypeXMLHandler_Zuflussdefinition135* @brief A class which extracts VISSIM-Zuflüsse from a parsed VISSIM-file136*/137class NIVissimXMLHandler_Zuflussdefinition : public GenericSAXHandler {138public:139/** @brief Constructor140*/141NIVissimXMLHandler_Zuflussdefinition();142143144/// @brief Destructor145~NIVissimXMLHandler_Zuflussdefinition();146147protected:148/// @name inherited from GenericSAXHandler149//@{150151/** @brief Called on the opening of a tag;152*153* @param[in] element ID of the currently opened element154* @param[in] attrs Attributes within the currently opened element155* @exception ProcessError If something fails156* @see GenericSAXHandler::myStartElement157*/158void myStartElement(int element, const SUMOSAXAttributes& attrs);159//@}160161162private:163164165166/** @brief invalidated copy constructor */167NIVissimXMLHandler_Zuflussdefinition(const NIVissimXMLHandler_Zuflussdefinition& z);168169/** @brief invalidated assignment operator */170NIVissimXMLHandler_Zuflussdefinition& operator=(const NIVissimXMLHandler_Zuflussdefinition& z);171};172173174private:175/**176* @class NIVissimSingleTypeXMLHandler_Parkplatzdefinition177* @brief A class which extracts VISSIM-Parkplätze from a parsed VISSIM-file178*/179class NIVissimXMLHandler_Parkplatzdefinition : public GenericSAXHandler {180public:181/** @brief Constructor182*/183NIVissimXMLHandler_Parkplatzdefinition();184185186/// @brief Destructor187~NIVissimXMLHandler_Parkplatzdefinition();188189protected:190/// @name inherited from GenericSAXHandler191//@{192193/** @brief Called on the opening of a tag;194*195* @param[in] element ID of the currently opened element196* @param[in] attrs Attributes within the currently opened element197* @exception ProcessError If something fails198* @see GenericSAXHandler::myStartElement199*/200void myStartElement(int element, const SUMOSAXAttributes& attrs);201//@}202203204private:205206207208/** @brief invalidated copy constructor */209NIVissimXMLHandler_Parkplatzdefinition(const NIVissimXMLHandler_Parkplatzdefinition& z);210211/** @brief invalidated assignment operator */212NIVissimXMLHandler_Parkplatzdefinition& operator=(const NIVissimXMLHandler_Parkplatzdefinition& z);213};214215216private:217/**218* @class NIVissimSingleTypeXMLHandler_Fahrzeugklassendefinition219* @brief A class which extracts VISSIM-Fahrzeugklassen from a parsed VISSIM-file220*/221class NIVissimXMLHandler_Fahrzeugklassendefinition : public GenericSAXHandler {222public:223/** @brief Constructor224* @param[in] elemData The string container to fill225*/226227NIVissimXMLHandler_Fahrzeugklassendefinition(nodeMap& elemData);228229230/// @brief Destructor231~NIVissimXMLHandler_Fahrzeugklassendefinition();232233protected:234/// @name inherited from GenericSAXHandler235//@{236237/** @brief Called on the opening of a tag;238*239* @param[in] element ID of the currently opened element240* @param[in] attrs Attributes within the currently opened element241* @exception ProcessError If something fails242* @see GenericSAXHandler::myStartElement243*/244void myStartElement(int element, const SUMOSAXAttributes& attrs);245//@}246247void myEndElement(int element);248//@}249250private:251252//std::map<int, VissimXMLEdge> myToFill;253nodeMap& myElemData;254255/// @brief The current hierarchy level256int myHierarchyLevel;257258/// @brief ID of the currently parsed node, for reporting mainly259int myLastNodeID;260261/** @brief invalidated copy constructor */262NIVissimXMLHandler_Fahrzeugklassendefinition(const NIVissimXMLHandler_Fahrzeugklassendefinition& f);263264/** @brief invalidated assignment operator */265NIVissimXMLHandler_Fahrzeugklassendefinition& operator=(const NIVissimXMLHandler_Fahrzeugklassendefinition& f);266};267268private:269/**270* @class NIVissimSingleTypeXMLHandler_VWunschentscheidungsdefinition271* @brief A class which extracts VISSIM-VWunschentscheidungen from a parsed VISSIM-file272*/273class NIVissimXMLHandler_VWunschentscheidungsdefinition : public GenericSAXHandler {274public:275/** @brief Constructor276* @param[in] elemData The string container to fill277*/278279NIVissimXMLHandler_VWunschentscheidungsdefinition(nodeMap& elemData);280281282/// @brief Destructor283~NIVissimXMLHandler_VWunschentscheidungsdefinition();284285protected:286/// @name inherited from GenericSAXHandler287//@{288289/** @brief Called on the opening of a tag;290*291* @param[in] element ID of the currently opened element292* @param[in] attrs Attributes within the currently opened element293* @exception ProcessError If something fails294* @see GenericSAXHandler::myStartElement295*/296void myStartElement(int element, const SUMOSAXAttributes& attrs);297//@}298299void myEndElement(int element);300//@}301302private:303304//std::map<int, VissimXMLEdge> myToFill;305nodeMap& myElemData;306307/// @brief The current hierarchy level308int myHierarchyLevel;309310/// @brief ID of the currently parsed node, for reporting mainly311int myLastNodeID;312313/** @brief invalidated copy constructor */314NIVissimXMLHandler_VWunschentscheidungsdefinition(const NIVissimXMLHandler_VWunschentscheidungsdefinition& vW);315316/** @brief invalidated assignment operator */317NIVissimXMLHandler_VWunschentscheidungsdefinition& operator=(const NIVissimXMLHandler_VWunschentscheidungsdefinition& vW);318};319320321322323private:324/**325* @class NIVissimSingleTypeXMLHandler_Geschwindigkeitsverteilungsdefinition326* @brief A class which extracts VISSIM-Geschwindigkeitsverteilung from a parsed VISSIM-file327*/328class NIVissimXMLHandler_Geschwindigkeitsverteilungsdefinition : public GenericSAXHandler {329public:330/** @brief Constructor331* @param[in] elemData The string container to fill332*/333334NIVissimXMLHandler_Geschwindigkeitsverteilungsdefinition(nodeMap& elemData);335336337/// @brief Destructor338~NIVissimXMLHandler_Geschwindigkeitsverteilungsdefinition();339340protected:341/// @name inherited from GenericSAXHandler342//@{343344/** @brief Called on the opening of a tag;345*346* @param[in] element ID of the currently opened element347* @param[in] attrs Attributes within the currently opened element348* @exception ProcessError If something fails349* @see GenericSAXHandler::myStartElement350*/351void myStartElement(int element, const SUMOSAXAttributes& attrs);352//@}353354void myEndElement(int element);355//@}356357private:358359//std::map<int, VissimXMLEdge> myToFill;360nodeMap& myElemData;361362/// @brief The current hierarchy level363int myHierarchyLevel;364365/// @brief ID of the currently parsed node, for reporting mainly366int myLastNodeID;367368/** @brief invalidated copy constructor */369NIVissimXMLHandler_Geschwindigkeitsverteilungsdefinition(const NIVissimXMLHandler_Geschwindigkeitsverteilungsdefinition& vW);370371/** @brief invalidated assignment operator */372NIVissimXMLHandler_Geschwindigkeitsverteilungsdefinition& operator=(const NIVissimXMLHandler_Geschwindigkeitsverteilungsdefinition& vW);373};374375376private:377/**378* @class NIVissimXMLHandler_Routenentscheidungsdefinition379* @brief A class which extracts VISSIM-Routes from a parsed VISSIM-file380*/381class NIVissimXMLHandler_Routenentscheidungsdefinition : public GenericSAXHandler {382public:383/** @brief Constructor384* @param[in] elemData The string container to fill385*/386387NIVissimXMLHandler_Routenentscheidungsdefinition(nodeMap& elemData);388389390/// @brief Destructor391~NIVissimXMLHandler_Routenentscheidungsdefinition();392393protected:394/// @name inherited from GenericSAXHandler395//@{396397/** @brief Called on the opening of a tag;398*399* @param[in] element ID of the currently opened element400* @param[in] attrs Attributes within the currently opened element401* @exception ProcessError If something fails402* @see GenericSAXHandler::myStartElement403*/404void myStartElement(int element, const SUMOSAXAttributes& attrs);405//@}406407void myEndElement(int element);408//@}409410private:411412//std::map<int, VissimXMLEdge> myToFill;413nodeMap& myElemData;414415/// @brief The current hierarchy level416int myHierarchyLevel;417418/// @brief ID of the currently parsed node, for reporting mainly419int myLastNodeID;420421/** @brief invalidated copy constructor */422NIVissimXMLHandler_Routenentscheidungsdefinition(const NIVissimXMLHandler_Routenentscheidungsdefinition& r);423424/** @brief invalidated assignment operator */425NIVissimXMLHandler_Routenentscheidungsdefinition& operator=(const NIVissimXMLHandler_Routenentscheidungsdefinition& r);426};427428429private:430/**431* @class NIVissimSingleTypeXMLHandler_ConflictArea432* @brief A class which extracts VISSIM-ConflictAreas from a parsed VISSIM-file433*/434class NIVissimXMLHandler_ConflictArea : public GenericSAXHandler {435public:436/** @brief Constructor437*/438NIVissimXMLHandler_ConflictArea();439440441/// @brief Destructor442~NIVissimXMLHandler_ConflictArea();443444445protected:446/// @name inherited from GenericSAXHandler447//@{448449/** @brief Called on the opening of a tag;450*451* @param[in] element ID of the currently opened element452* @param[in] attrs Attributes within the currently opened element453* @exception ProcessError If something fails454* @see GenericSAXHandler::myStartElement455*/456void myStartElement(int element, const SUMOSAXAttributes& attrs);457//@}458459460private:461462463/** @brief invalidated copy constructor */464NIVissimXMLHandler_ConflictArea(const NIVissimXMLHandler_ConflictArea& c);465466/** @brief invalidated assignment operator */467NIVissimXMLHandler_ConflictArea& operator=(const NIVissimXMLHandler_ConflictArea& c);468};469470471protected:472/// constructor473NIImporter_Vissim(NBNetBuilder& nb);474475/// destructor476~NIImporter_Vissim();477478/// loads the vissim file479void load(const OptionsCont& options);480481bool admitContinue(const std::string& tag);482483public:484class VissimSingleTypeParser {485public:486/// Constructor487VissimSingleTypeParser(NIImporter_Vissim& parent);488489/// Destructor490virtual ~VissimSingleTypeParser();491492/** @brief Parses a single data type.493Returns whether no error occurred */494virtual bool parse(std::istream& from) = 0;495496protected:497/// reads from the stream and returns the lower case version of the read value498std::string myRead(std::istream& from);499500/// as myRead, but returns "DATAEND" when the current field has ended501std::string readEndSecure(std::istream& from,502const std::string& excl = "");503504std::string readEndSecure(std::istream& from,505const std::vector<std::string>& excl);506507/// overrides the optional label definition; returns the next tag as done by readEndSecure508std::string overrideOptionalLabel(std::istream& from,509const std::string& tag = "");510511/// returns the 2d-position saved as next within the stream512Position getPosition(std::istream& from);513514/** @brief parses a listof vehicle types assigned to the current data field515One should remeber, that -1 means "all" vehicle types */516std::vector<int> parseAssignedVehicleTypes(std::istream& from,517const std::string& next);518519NIVissimExtendedEdgePoint readExtEdgePointDef(std::istream& from);520521/** @brief Reads the structures name522We cannot use the "<<" operator, as names may contain more than one word523which are joined using '"'. */524std::string readName(std::istream& from);525526/** @brief Overreads the named parameter (if) given and skips the rest until "DATAEND"527*/528bool skipOverreading(std::istream& from, const std::string& name = "");529530/// Reads from the stream until the keywor occurs531void readUntil(std::istream& from, const std::string& name);532533private:534NIImporter_Vissim& myVissimParent;535536private:537/// @brief Invalidated assignment operator.538VissimSingleTypeParser& operator=(const VissimSingleTypeParser&);539540};541542543/// definition of a map from color names to color definitions544typedef std::map<std::string, RGBColor> ColorMap;545546private:547bool readContents(std::istream& strm);548void postLoadBuild(double offset);549550551/// adds name-to-id - relationships of known elements into myKnownElements552void insertKnownElements();553554/// adds id-to-parser - relationships of elements to parse into myParsers555void buildParsers();556557private:558/// Definition of a map from element names to their numerical representation559typedef std::map<std::string, NIVissimElement> ToElemIDMap;560561/// Map from element names to their numerical representation562ToElemIDMap myKnownElements;563564/// Definition of a map from an element's numerical id to his parser565typedef std::map<NIVissimElement, VissimSingleTypeParser*> ToParserMap;566567/// Parsers by element id568ToParserMap myParsers;569570/// a map from color names to color definitions571ColorMap myColorMap;572573std::string myLastSecure;574575NBNetBuilder& myNetBuilder;576577private:578/// @brief Invalidated copy constructor.579NIImporter_Vissim(const NIImporter_Vissim&);580581/// @brief Invalidated assignment operator.582NIImporter_Vissim& operator=(const NIImporter_Vissim&);583584585586/**587* @enum VissimXMLTag588* @brief Numbers representing VISSIM-XML - element names589* @see GenericSAXHandler590*/591enum VissimXMLTag {592VISSIM_TAG_NOTHING = 0,593VISSIM_TAG_NETWORK,594VISSIM_TAG_LANES,595VISSIM_TAG_LANE,596VISSIM_TAG_LINK,597VISSIM_TAG_LINKS,598VISSIM_TAG_POINTS3D,599VISSIM_TAG_POINT3D,600VISSIM_TAG_LINKPOLYPOINT,601VISSIM_TAG_LINKPOLYPTS,602VISSIM_TAG_FROM,603VISSIM_TAG_TO,604VISSIM_TAG_VEHICLE_INPUT,605VISSIM_TAG_PARKINGLOT,606VISSIM_TAG_VEHICLE_CLASS,607VISSIM_TAG_INTOBJECTREF,608VISSIM_TAG_SPEED_DECISION,609VISSIM_TAG_SPEED_DIST,610VISSIM_TAG_DATAPOINT,611VISSIM_TAG_DECISION_STATIC,612VISSIM_TAG_ROUTE_STATIC,613VISSIM_TAG_CA614};615616617/**618* @enum VissimXMLAttr619* @brief Numbers representing VISSIM-XML - attributes620* @see GenericSAXHandler621*/622enum VissimXMLAttr {623VISSIM_ATTR_NOTHING = 0,624VISSIM_ATTR_NO,625VISSIM_ATTR_NAME,626VISSIM_ATTR_X,627VISSIM_ATTR_Y,628VISSIM_ATTR_ZOFFSET,629VISSIM_ATTR_ZUSCHLAG1,630VISSIM_ATTR_ZUSCHLAG2,631VISSIM_ATTR_WIDTH,632VISSIM_ATTR_LINKBEHAVETYPE,633VISSIM_ATTR_LANE,634VISSIM_ATTR_POS,635VISSIM_ATTR_LINK,636VISSIM_ATTR_INTLINK,637VISSIM_ATTR_PERCENTAGE,638VISSIM_ATTR_DISTRICT,639VISSIM_ATTR_COLOR,640VISSIM_ATTR_KEY,641VISSIM_ATTR_FX,642VISSIM_ATTR_DESTLINK,643VISSIM_ATTR_DESTPOS,644VISSIM_ATTR_LINK1,645VISSIM_ATTR_LINK2,646VISSIM_ATTR_STATUS647};648649/// The names of VISSIM-XML elements (for passing to GenericSAXHandler)650static SequentialStringBijection::Entry vissimTags[];651652/// The names of VISSIM-XML attributes (for passing to GenericSAXHandler)653static SequentialStringBijection::Entry vissimAttrs[];654655656};657658659