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 NIImporter_Vissim.h 11 /// @author Daniel Krajzewicz 12 /// @author Michael Behrisch 13 /// @author Lukas Grohmann (AIT) 14 /// @author Gerald Richter (AIT) 15 /// @date Sept 2002 16 /// @version $Id$ 17 /// 18 // Importer for networks stored in Vissim format 19 /****************************************************************************/ 20 #ifndef NIImporter_Vissim_h 21 #define NIImporter_Vissim_h 22 23 24 // =========================================================================== 25 // included modules 26 // =========================================================================== 27 #include <config.h> 28 29 #include <string> 30 #include <map> 31 #include <vector> 32 #include <utils/common/RGBColor.h> 33 #include <utils/geom/Position.h> 34 #include "tempstructs/NIVissimExtendedEdgePoint.h" 35 #include "NIVissimElements.h" 36 #include <utils/xml/SUMOSAXHandler.h> 37 #include "tempstructs/NIVissimEdge.h" 38 #include "tempstructs/NIVissimConnection.h" 39 #include "tempstructs/NIVissimConflictArea.h" 40 41 #include <utils/common/StringBijection.h> 42 #include <utils/common/StringTokenizer.h> 43 #include <list> 44 45 // =========================================================================== 46 // class declarations 47 // =========================================================================== 48 class OptionsCont; 49 class NBNetBuilder; 50 51 52 // =========================================================================== 53 // class definitions 54 // =========================================================================== 55 /** 56 * @class NIImporter_Vissim 57 * @brief Importer for networks stored in Vissim format 58 */ 59 class NIImporter_Vissim { 60 public: 61 /** @brief Loads network definition from the assigned option and stores it in the given network builder 62 * 63 * If the option "vissim-file" is set, the file stored therein is read and 64 * the network definition stored therein is stored within the given network 65 * builder. 66 * 67 * If the option "vissim-file" is not set, this method simply returns. 68 * 69 * @param[in] oc The options to use 70 * @param[in] nb The network builder to fill 71 */ 72 static void loadNetwork(const OptionsCont& oc, NBNetBuilder& nb); 73 74 75 76 private: 77 78 typedef std::map<std::string, std::list<std::string> > nodeMap; 79 nodeMap elementData; 80 81 /** 82 * @class NIVissimSingleTypeXMLHandler_Streckendefinition 83 * @brief A class which extracts VISSIM-Strecken from a parsed VISSIM-file 84 */ 85 class NIVissimXMLHandler_Streckendefinition : public GenericSAXHandler { 86 public: 87 /** @brief Constructor 88 * @param[in] strecken_dic The strecken dictionary to fill 89 */ 90 //NIVissimXMLHandler_Streckendefinition(std::map<int, VissimXMLEdge>& toFill); 91 NIVissimXMLHandler_Streckendefinition(nodeMap& elemData); 92 93 94 /// @brief Destructor 95 ~NIVissimXMLHandler_Streckendefinition(); 96 97 protected: 98 /// @name inherited from GenericSAXHandler 99 //@{ 100 101 /** @brief Called on the opening of a tag; 102 * 103 * @param[in] element ID of the currently opened element 104 * @param[in] attrs Attributes within the currently opened element 105 * @exception ProcessError If something fails 106 * @see GenericSAXHandler::myStartElement 107 */ 108 void myStartElement(int element, const SUMOSAXAttributes& attrs); 109 //@} 110 111 void myEndElement(int element); 112 //@} 113 114 private: 115 116 //std::map<int, VissimXMLEdge> myToFill; 117 nodeMap& myElemData; 118 119 /// @brief The current hierarchy level 120 int myHierarchyLevel; 121 122 /// @brief check if the link is a connector 123 bool isConnector; 124 125 /// @brief ID of the currently parsed node, for reporting mainly 126 int myLastNodeID; 127 128 /** @brief invalidated copy constructor */ 129 NIVissimXMLHandler_Streckendefinition(const NIVissimXMLHandler_Streckendefinition& s); 130 131 /** @brief invalidated assignment operator */ 132 NIVissimXMLHandler_Streckendefinition& operator=(const NIVissimXMLHandler_Streckendefinition& s); 133 }; 134 135 136 private: 137 /** 138 * @class NIVissimSingleTypeXMLHandler_Zuflussdefinition 139 * @brief A class which extracts VISSIM-Zuflüsse from a parsed VISSIM-file 140 */ 141 class NIVissimXMLHandler_Zuflussdefinition : public GenericSAXHandler { 142 public: 143 /** @brief Constructor 144 */ 145 NIVissimXMLHandler_Zuflussdefinition(); 146 147 148 /// @brief Destructor 149 ~NIVissimXMLHandler_Zuflussdefinition(); 150 151 protected: 152 /// @name inherited from GenericSAXHandler 153 //@{ 154 155 /** @brief Called on the opening of a tag; 156 * 157 * @param[in] element ID of the currently opened element 158 * @param[in] attrs Attributes within the currently opened element 159 * @exception ProcessError If something fails 160 * @see GenericSAXHandler::myStartElement 161 */ 162 void myStartElement(int element, const SUMOSAXAttributes& attrs); 163 //@} 164 165 166 private: 167 168 169 170 /** @brief invalidated copy constructor */ 171 NIVissimXMLHandler_Zuflussdefinition(const NIVissimXMLHandler_Zuflussdefinition& z); 172 173 /** @brief invalidated assignment operator */ 174 NIVissimXMLHandler_Zuflussdefinition& operator=(const NIVissimXMLHandler_Zuflussdefinition& z); 175 }; 176 177 178 private: 179 /** 180 * @class NIVissimSingleTypeXMLHandler_Parkplatzdefinition 181 * @brief A class which extracts VISSIM-Parkplätze from a parsed VISSIM-file 182 */ 183 class NIVissimXMLHandler_Parkplatzdefinition : public GenericSAXHandler { 184 public: 185 /** @brief Constructor 186 */ 187 NIVissimXMLHandler_Parkplatzdefinition(); 188 189 190 /// @brief Destructor 191 ~NIVissimXMLHandler_Parkplatzdefinition(); 192 193 protected: 194 /// @name inherited from GenericSAXHandler 195 //@{ 196 197 /** @brief Called on the opening of a tag; 198 * 199 * @param[in] element ID of the currently opened element 200 * @param[in] attrs Attributes within the currently opened element 201 * @exception ProcessError If something fails 202 * @see GenericSAXHandler::myStartElement 203 */ 204 void myStartElement(int element, const SUMOSAXAttributes& attrs); 205 //@} 206 207 208 private: 209 210 211 212 /** @brief invalidated copy constructor */ 213 NIVissimXMLHandler_Parkplatzdefinition(const NIVissimXMLHandler_Parkplatzdefinition& z); 214 215 /** @brief invalidated assignment operator */ 216 NIVissimXMLHandler_Parkplatzdefinition& operator=(const NIVissimXMLHandler_Parkplatzdefinition& z); 217 }; 218 219 220 private: 221 /** 222 * @class NIVissimSingleTypeXMLHandler_Fahrzeugklassendefinition 223 * @brief A class which extracts VISSIM-Fahrzeugklassen from a parsed VISSIM-file 224 */ 225 class NIVissimXMLHandler_Fahrzeugklassendefinition : public GenericSAXHandler { 226 public: 227 /** @brief Constructor 228 * @param[in] elemData The string container to fill 229 */ 230 231 NIVissimXMLHandler_Fahrzeugklassendefinition(nodeMap& elemData); 232 233 234 /// @brief Destructor 235 ~NIVissimXMLHandler_Fahrzeugklassendefinition(); 236 237 protected: 238 /// @name inherited from GenericSAXHandler 239 //@{ 240 241 /** @brief Called on the opening of a tag; 242 * 243 * @param[in] element ID of the currently opened element 244 * @param[in] attrs Attributes within the currently opened element 245 * @exception ProcessError If something fails 246 * @see GenericSAXHandler::myStartElement 247 */ 248 void myStartElement(int element, const SUMOSAXAttributes& attrs); 249 //@} 250 251 void myEndElement(int element); 252 //@} 253 254 private: 255 256 //std::map<int, VissimXMLEdge> myToFill; 257 nodeMap& myElemData; 258 259 /// @brief The current hierarchy level 260 int myHierarchyLevel; 261 262 /// @brief ID of the currently parsed node, for reporting mainly 263 int myLastNodeID; 264 265 /** @brief invalidated copy constructor */ 266 NIVissimXMLHandler_Fahrzeugklassendefinition(const NIVissimXMLHandler_Fahrzeugklassendefinition& f); 267 268 /** @brief invalidated assignment operator */ 269 NIVissimXMLHandler_Fahrzeugklassendefinition& operator=(const NIVissimXMLHandler_Fahrzeugklassendefinition& f); 270 }; 271 272 private: 273 /** 274 * @class NIVissimSingleTypeXMLHandler_VWunschentscheidungsdefinition 275 * @brief A class which extracts VISSIM-VWunschentscheidungen from a parsed VISSIM-file 276 */ 277 class NIVissimXMLHandler_VWunschentscheidungsdefinition : public GenericSAXHandler { 278 public: 279 /** @brief Constructor 280 * @param[in] elemData The string container to fill 281 */ 282 283 NIVissimXMLHandler_VWunschentscheidungsdefinition(nodeMap& elemData); 284 285 286 /// @brief Destructor 287 ~NIVissimXMLHandler_VWunschentscheidungsdefinition(); 288 289 protected: 290 /// @name inherited from GenericSAXHandler 291 //@{ 292 293 /** @brief Called on the opening of a tag; 294 * 295 * @param[in] element ID of the currently opened element 296 * @param[in] attrs Attributes within the currently opened element 297 * @exception ProcessError If something fails 298 * @see GenericSAXHandler::myStartElement 299 */ 300 void myStartElement(int element, const SUMOSAXAttributes& attrs); 301 //@} 302 303 void myEndElement(int element); 304 //@} 305 306 private: 307 308 //std::map<int, VissimXMLEdge> myToFill; 309 nodeMap& myElemData; 310 311 /// @brief The current hierarchy level 312 int myHierarchyLevel; 313 314 /// @brief ID of the currently parsed node, for reporting mainly 315 int myLastNodeID; 316 317 /** @brief invalidated copy constructor */ 318 NIVissimXMLHandler_VWunschentscheidungsdefinition(const NIVissimXMLHandler_VWunschentscheidungsdefinition& vW); 319 320 /** @brief invalidated assignment operator */ 321 NIVissimXMLHandler_VWunschentscheidungsdefinition& operator=(const NIVissimXMLHandler_VWunschentscheidungsdefinition& vW); 322 }; 323 324 325 326 327 private: 328 /** 329 * @class NIVissimSingleTypeXMLHandler_Geschwindigkeitsverteilungsdefinition 330 * @brief A class which extracts VISSIM-Geschwindigkeitsverteilung from a parsed VISSIM-file 331 */ 332 class NIVissimXMLHandler_Geschwindigkeitsverteilungsdefinition : public GenericSAXHandler { 333 public: 334 /** @brief Constructor 335 * @param[in] elemData The string container to fill 336 */ 337 338 NIVissimXMLHandler_Geschwindigkeitsverteilungsdefinition(nodeMap& elemData); 339 340 341 /// @brief Destructor 342 ~NIVissimXMLHandler_Geschwindigkeitsverteilungsdefinition(); 343 344 protected: 345 /// @name inherited from GenericSAXHandler 346 //@{ 347 348 /** @brief Called on the opening of a tag; 349 * 350 * @param[in] element ID of the currently opened element 351 * @param[in] attrs Attributes within the currently opened element 352 * @exception ProcessError If something fails 353 * @see GenericSAXHandler::myStartElement 354 */ 355 void myStartElement(int element, const SUMOSAXAttributes& attrs); 356 //@} 357 358 void myEndElement(int element); 359 //@} 360 361 private: 362 363 //std::map<int, VissimXMLEdge> myToFill; 364 nodeMap& myElemData; 365 366 /// @brief The current hierarchy level 367 int myHierarchyLevel; 368 369 /// @brief ID of the currently parsed node, for reporting mainly 370 int myLastNodeID; 371 372 /** @brief invalidated copy constructor */ 373 NIVissimXMLHandler_Geschwindigkeitsverteilungsdefinition(const NIVissimXMLHandler_Geschwindigkeitsverteilungsdefinition& vW); 374 375 /** @brief invalidated assignment operator */ 376 NIVissimXMLHandler_Geschwindigkeitsverteilungsdefinition& operator=(const NIVissimXMLHandler_Geschwindigkeitsverteilungsdefinition& vW); 377 }; 378 379 380 private: 381 /** 382 * @class NIVissimXMLHandler_Routenentscheidungsdefinition 383 * @brief A class which extracts VISSIM-Routes from a parsed VISSIM-file 384 */ 385 class NIVissimXMLHandler_Routenentscheidungsdefinition : public GenericSAXHandler { 386 public: 387 /** @brief Constructor 388 * @param[in] elemData The string container to fill 389 */ 390 391 NIVissimXMLHandler_Routenentscheidungsdefinition(nodeMap& elemData); 392 393 394 /// @brief Destructor 395 ~NIVissimXMLHandler_Routenentscheidungsdefinition(); 396 397 protected: 398 /// @name inherited from GenericSAXHandler 399 //@{ 400 401 /** @brief Called on the opening of a tag; 402 * 403 * @param[in] element ID of the currently opened element 404 * @param[in] attrs Attributes within the currently opened element 405 * @exception ProcessError If something fails 406 * @see GenericSAXHandler::myStartElement 407 */ 408 void myStartElement(int element, const SUMOSAXAttributes& attrs); 409 //@} 410 411 void myEndElement(int element); 412 //@} 413 414 private: 415 416 //std::map<int, VissimXMLEdge> myToFill; 417 nodeMap& myElemData; 418 419 /// @brief The current hierarchy level 420 int myHierarchyLevel; 421 422 /// @brief ID of the currently parsed node, for reporting mainly 423 int myLastNodeID; 424 425 /** @brief invalidated copy constructor */ 426 NIVissimXMLHandler_Routenentscheidungsdefinition(const NIVissimXMLHandler_Routenentscheidungsdefinition& r); 427 428 /** @brief invalidated assignment operator */ 429 NIVissimXMLHandler_Routenentscheidungsdefinition& operator=(const NIVissimXMLHandler_Routenentscheidungsdefinition& r); 430 }; 431 432 433 private: 434 /** 435 * @class NIVissimSingleTypeXMLHandler_ConflictArea 436 * @brief A class which extracts VISSIM-ConflictAreas from a parsed VISSIM-file 437 */ 438 class NIVissimXMLHandler_ConflictArea : public GenericSAXHandler { 439 public: 440 /** @brief Constructor 441 */ 442 NIVissimXMLHandler_ConflictArea(); 443 444 445 /// @brief Destructor 446 ~NIVissimXMLHandler_ConflictArea(); 447 448 449 protected: 450 /// @name inherited from GenericSAXHandler 451 //@{ 452 453 /** @brief Called on the opening of a tag; 454 * 455 * @param[in] element ID of the currently opened element 456 * @param[in] attrs Attributes within the currently opened element 457 * @exception ProcessError If something fails 458 * @see GenericSAXHandler::myStartElement 459 */ 460 void myStartElement(int element, const SUMOSAXAttributes& attrs); 461 //@} 462 463 464 private: 465 466 467 /** @brief invalidated copy constructor */ 468 NIVissimXMLHandler_ConflictArea(const NIVissimXMLHandler_ConflictArea& c); 469 470 /** @brief invalidated assignment operator */ 471 NIVissimXMLHandler_ConflictArea& operator=(const NIVissimXMLHandler_ConflictArea& c); 472 }; 473 474 475 protected: 476 /// constructor 477 NIImporter_Vissim(NBNetBuilder& nb, const std::string& file); 478 479 /// destructor 480 ~NIImporter_Vissim(); 481 482 /// loads the vissim file 483 void load(const OptionsCont& options); 484 485 void loadXML(const OptionsCont& options, NBNetBuilder& nb); 486 487 bool admitContinue(const std::string& tag); 488 489 public: 490 class VissimSingleTypeParser { 491 public: 492 /// Constructor 493 VissimSingleTypeParser(NIImporter_Vissim& parent); 494 495 /// Destructor 496 virtual ~VissimSingleTypeParser(); 497 498 /** @brief Parses a single data type. 499 Returns whether no error occurred */ 500 virtual bool parse(std::istream& from) = 0; 501 502 protected: 503 /// reads from the stream and returns the lower case version of the read value 504 std::string myRead(std::istream& from); 505 506 /// as myRead, but returns "DATAEND" when the current field has ended 507 std::string readEndSecure(std::istream& from, 508 const std::string& excl = ""); 509 510 std::string readEndSecure(std::istream& from, 511 const std::vector<std::string>& excl); 512 513 /// overrides the optional label definition; returns the next tag as done by readEndSecure 514 std::string overrideOptionalLabel(std::istream& from, 515 const std::string& tag = ""); 516 517 /// returns the 2d-position saved as next within the stream 518 Position getPosition(std::istream& from); 519 520 /** @brief parses a listof vehicle types assigned to the current data field 521 One should remeber, that -1 means "all" vehicle types */ 522 std::vector<int> parseAssignedVehicleTypes(std::istream& from, 523 const std::string& next); 524 525 NIVissimExtendedEdgePoint readExtEdgePointDef(std::istream& from); 526 527 /** @brief Reads the structures name 528 We cannot use the "<<" operator, as names may contain more than one word 529 which are joined using '"'. */ 530 std::string readName(std::istream& from); 531 532 /** @brief Overreads the named parameter (if) given and skips the rest until "DATAEND" 533 */ 534 bool skipOverreading(std::istream& from, const std::string& name = ""); 535 536 /// Reads from the stream until the keywor occurs 537 void readUntil(std::istream& from, const std::string& name); 538 539 private: 540 NIImporter_Vissim& myVissimParent; 541 542 private: 543 /// @brief Invalidated assignment operator. 544 VissimSingleTypeParser& operator=(const VissimSingleTypeParser&); 545 546 }; 547 548 549 /// definition of a map from color names to color definitions 550 typedef std::map<std::string, RGBColor> ColorMap; 551 552 private: 553 bool readContents(std::istream& strm); 554 void postLoadBuild(double offset); 555 556 557 /// adds name-to-id - relationships of known elements into myKnownElements 558 void insertKnownElements(); 559 560 /// adds id-to-parser - relationships of elements to parse into myParsers 561 void buildParsers(); 562 563 private: 564 /// Definition of a map from element names to their numerical representation 565 typedef std::map<std::string, NIVissimElement> ToElemIDMap; 566 567 /// Map from element names to their numerical representation 568 ToElemIDMap myKnownElements; 569 570 /// Definition of a map from an element's numerical id to his parser 571 typedef std::map<NIVissimElement, VissimSingleTypeParser*> ToParserMap; 572 573 /// Parsers by element id 574 ToParserMap myParsers; 575 576 /// a map from color names to color definitions 577 ColorMap myColorMap; 578 579 std::string myLastSecure; 580 581 NBNetBuilder& myNetBuilder; 582 583 bool myInputIsLegacyFormat; 584 585 private: 586 /// @brief Invalidated copy constructor. 587 NIImporter_Vissim(const NIImporter_Vissim&); 588 589 /// @brief Invalidated assignment operator. 590 NIImporter_Vissim& operator=(const NIImporter_Vissim&); 591 592 593 594 /** 595 * @enum VissimXMLTag 596 * @brief Numbers representing VISSIM-XML - element names 597 * @see GenericSAXHandler 598 */ 599 enum VissimXMLTag { 600 VISSIM_TAG_NOTHING = 0, 601 VISSIM_TAG_NETWORK, 602 VISSIM_TAG_LANES, 603 VISSIM_TAG_LANE, 604 VISSIM_TAG_LINK, 605 VISSIM_TAG_LINKS, 606 VISSIM_TAG_POINTS3D, 607 VISSIM_TAG_POINT3D, 608 VISSIM_TAG_FROM, 609 VISSIM_TAG_TO, 610 VISSIM_TAG_VEHICLE_INPUT, 611 VISSIM_TAG_PARKINGLOT, 612 VISSIM_TAG_VEHICLE_CLASS, 613 VISSIM_TAG_INTOBJECTREF, 614 VISSIM_TAG_SPEED_DECISION, 615 VISSIM_TAG_SPEED_DIST, 616 VISSIM_TAG_DATAPOINT, 617 VISSIM_TAG_DECISION_STATIC, 618 VISSIM_TAG_ROUTE_STATIC, 619 VISSIM_TAG_CA 620 }; 621 622 623 /** 624 * @enum VissimXMLAttr 625 * @brief Numbers representing VISSIM-XML - attributes 626 * @see GenericSAXHandler 627 */ 628 enum VissimXMLAttr { 629 VISSIM_ATTR_NOTHING = 0, 630 VISSIM_ATTR_NO, 631 VISSIM_ATTR_NAME, 632 VISSIM_ATTR_X, 633 VISSIM_ATTR_Y, 634 VISSIM_ATTR_ZOFFSET, 635 VISSIM_ATTR_ZUSCHLAG1, 636 VISSIM_ATTR_ZUSCHLAG2, 637 VISSIM_ATTR_WIDTH, 638 VISSIM_ATTR_LINKBEHAVETYPE, 639 VISSIM_ATTR_LANE, 640 VISSIM_ATTR_POS, 641 VISSIM_ATTR_LINK, 642 VISSIM_ATTR_INTLINK, 643 VISSIM_ATTR_PERCENTAGE, 644 VISSIM_ATTR_DISTRICT, 645 VISSIM_ATTR_COLOR, 646 VISSIM_ATTR_KEY, 647 VISSIM_ATTR_FX, 648 VISSIM_ATTR_DESTLINK, 649 VISSIM_ATTR_DESTPOS, 650 VISSIM_ATTR_LINK1, 651 VISSIM_ATTR_LINK2, 652 VISSIM_ATTR_STATUS 653 }; 654 655 /// The names of VISSIM-XML elements (for passing to GenericSAXHandler) 656 static StringBijection<int>::Entry vissimTags[]; 657 658 /// The names of VISSIM-XML attributes (for passing to GenericSAXHandler) 659 static StringBijection<int>::Entry vissimAttrs[]; 660 661 662 }; 663 664 665 #endif 666 667 /****************************************************************************/ 668 669