SUMO - Simulation of Urban MObility
NIImporter_Vissim.cpp
Go to the documentation of this file.
1 /****************************************************************************/
11 // -------------------
12 /****************************************************************************/
13 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
14 // Copyright (C) 2001-2017 DLR (http://www.dlr.de/) and contributors
15 /****************************************************************************/
16 //
17 // This file is part of SUMO.
18 // SUMO is free software: you can redistribute it and/or modify
19 // it under the terms of the GNU General Public License as published by
20 // the Free Software Foundation, either version 3 of the License, or
21 // (at your option) any later version.
22 //
23 /****************************************************************************/
24 
25 
26 // ===========================================================================
27 // included modules
28 // ===========================================================================
29 #ifdef _MSC_VER
30 #include <windows_config.h>
31 #else
32 #include <config.h>
33 #endif
34 
35 
36 #include <string>
37 #include <fstream>
42 #include <netbuild/NBNetBuilder.h>
43 #include "NIImporter_Vissim.h"
99 
100 
101 #include "tempstructs/NIVissimTL.h"
114 
116 #include <utils/xml/XMLSubSys.h>
121 
122 #include <netbuild/NBEdgeCont.h> // !!! only for debugging purposes
123 
124 
125 // ===========================================================================
126 // static variables
127 // ===========================================================================
136  { "fromLinkEndPt", NIImporter_Vissim::VISSIM_TAG_FROM },
137  { "toLinkEndPt", NIImporter_Vissim::VISSIM_TAG_TO },
141  { "intObjectRef", NIImporter_Vissim::VISSIM_TAG_INTOBJECTREF },
142  { "desSpeedDecision", NIImporter_Vissim::VISSIM_TAG_SPEED_DECISION },
143  {
144  "desSpeedDistribution",
146  },
147  {
148  "speedDistributionDataPoint",
150  },
151  {
152  "vehicleRoutingDecisionStatic",
154  },
155  {
156  "vehicleRouteStatic",
158  },
159  { "conflictArea", NIImporter_Vissim::VISSIM_TAG_CA },
161 };
162 
163 
165  { "no", NIImporter_Vissim::VISSIM_ATTR_NO }, //id
177  { "intLink", NIImporter_Vissim::VISSIM_ATTR_INTLINK }, //edgeID
189 };
190 
191 
192 // ===========================================================================
193 // method definitions
194 // ===========================================================================
195 // ---------------------------------------------------------------------------
196 // static methods (interface in this case)
197 // ---------------------------------------------------------------------------
198 void
200  if (!oc.isSet("vissim-file")) {
201  return;
202  }
203  NIImporter_Vissim loader(nb, oc.getString("vissim-file"));
204  // check if legacy format file or newer XML file
205  // file name extension check
206  if ((oc.getString("vissim-file").find(".inpx") != std::string::npos))
207  //TODO: check if the given position of .inpx is at the end
208  {
209  // load the XML vissim network
210  loader.loadXML(oc, nb);
211  loader.myInputIsLegacyFormat = false;
212  } else {
213  // load the legacy vissim network
214  loader.load(oc);
215  loader.myInputIsLegacyFormat = true;
216  }
217 }
218 
219 
220 // ---------------------------------------------------------------------------
221 // definitions of NIVissimXMLHandler_Streckendefinition-methods
222 // ---------------------------------------------------------------------------
224  //std::map<int, VissimXMLEdge>& toFill)
225  nodeMap& elemData)
228  "vissim - file"),
229  myElemData(elemData),
230  myHierarchyLevel(0),
231  isConnector(false) {
232  myElemData.clear();
233 }
234 
236 
237 void
240 
241  // finding an actual LINK
242  if (element == VISSIM_TAG_LINK) {
243  //parse all links
244  bool ok = true;
245  int id = attrs.get<int>(VISSIM_ATTR_NO, 0, ok);
246  myLastNodeID = id;
247 
248  // !!! assuming empty myElemData
249  myElemData["id"].push_back(attrs.get<std::string>(VISSIM_ATTR_NO, 0, ok));
250  // error ignored if name is empty
251  myElemData["name"].push_back(attrs.get<std::string>(VISSIM_ATTR_NAME, 0, ok, false));
252  myElemData["type"].push_back(attrs.get<std::string>(VISSIM_ATTR_LINKBEHAVETYPE, 0, ok));
253  myElemData["zuschlag1"].push_back(attrs.get<std::string>(VISSIM_ATTR_ZUSCHLAG1, 0, ok));
254  myElemData["zuschlag2"].push_back(attrs.get<std::string>(VISSIM_ATTR_ZUSCHLAG2, 0, ok));
255  }
256 
257  if (element == VISSIM_TAG_LANE) {
258  bool ok = true;
259  // appends empty element if no width found
260  // error ignored if name is empty
261  myElemData["width"].push_back(attrs.get<std::string>(VISSIM_ATTR_WIDTH, 0, ok, false));
262  }
263 
264  if (element == VISSIM_TAG_FROM) {
265  if (isConnector != true) {
266  isConnector = true;
267  }
268  bool ok = true;
269  std::vector<std::string> from(StringTokenizer(attrs.get<std::string>(
270  VISSIM_ATTR_LANE, 0, ok), " ").getVector());
271  myElemData["from_pos"].push_back(attrs.get<std::string>(VISSIM_ATTR_POS, 0, ok));
272  myElemData["from_id"].push_back(from[0]);
273  myElemData["from_lane"].push_back(from[1]);
274  }
275 
276  if (element == VISSIM_TAG_TO) {
277  bool ok = true;
278  std::vector<std::string> to(StringTokenizer(attrs.get<std::string>(
279  VISSIM_ATTR_LANE, 0, ok), " ").getVector());
280  myElemData["to_pos"].push_back(attrs.get<std::string>(VISSIM_ATTR_POS, 0, ok));
281  myElemData["to_id"].push_back(to[0]);
282  myElemData["to_lane"].push_back(to[1]);
283  }
284 
285  if (element == VISSIM_TAG_POINT3D) {
286  bool ok = true;
287  // create a <sep> separated string of coordinate data
288  std::string sep(" ");
289 
290  std::string posS(attrs.get<std::string>(VISSIM_ATTR_X, 0, ok));
291  posS += sep;
292  posS.append(attrs.get<std::string>(VISSIM_ATTR_Y, 0, ok));
293  // allow for no Z
294  std::string z(attrs.get<std::string>(VISSIM_ATTR_ZOFFSET, 0, ok, false));
295  if (z.length() > 0) {
296  posS += sep;
297  posS.append(z);
298  }
299  myElemData["pos"].push_back(posS);
300  }
301 
302 
303 }
304 
305 void
307  if (element == VISSIM_TAG_LINK && myHierarchyLevel == 3) {
308  //std::cout << "elemData len:" << myElemData.size() << std::endl;
309 
310  NIVissimClosedLanesVector clv; //FIXME -> clv einlesen
311  std::vector<int> assignedVehicles; //FIXME -> assignedVehicles einlesen
312  int id(TplConvert::_str2int(myElemData["id"].front()));
313 
314  PositionVector geom;
315  // convert all position coordinate strings to PositionVectors
316  while (!myElemData["pos"].empty()) {
317  std::vector<std::string> sPos_v(StringTokenizer(
318  myElemData["pos"].front(), " ").getVector());
319  myElemData["pos"].pop_front();
320  std::vector<double> pos_v(3);
321 
322  // doing a transform with explicit hint on function signature
323  std::transform(sPos_v.begin(), sPos_v.end(), pos_v.begin(),
325  geom.push_back_noDoublePos(Position(pos_v[0], pos_v[1], pos_v[2]));
326  }
327  // FIXME: a length = 0 PosVec seems fatal -> segfault
328  double length(geom.length());
329 
330  if (isConnector == false) {
331  // Add Edge
332  NIVissimEdge* edge = new NIVissimEdge(id,
333  myElemData["name"].front(),
334  myElemData["type"].front(),
335  (int)myElemData["width"].size(), // numLanes,
336  TplConvert::_str2double(myElemData["zuschlag1"].front()),
337  TplConvert::_str2double(myElemData["zuschlag2"].front()),
338  length, geom, clv);
339  NIVissimEdge::dictionary(id, edge);
340  if (id == 85 || id == 91) {
341  std::cout << id << "\n";
342  std::cout << myElemData["width"].size() << "\n";
343  std::cout << length << "\n";
344  std::cout << geom << "\n";
345  }
346  } else {
347  int numLanes = (int)myElemData["width"].size();
348  std::vector<int> laneVec(numLanes);
349  // Add Connector
350 
351  //NOTE: there should be only 1 lane number in XML
352  // subtraction of 1 as in readExtEdgePointDef()
353  laneVec[0] = TplConvert::_str2int(myElemData["from_lane"].front()) - 1;
354  // then count up, building lane number vector
355  for (std::vector<int>::iterator each = ++laneVec.begin(); each != laneVec.end(); ++each) {
356  *each = *(each - 1) + 1;
357  }
358 
359  NIVissimExtendedEdgePoint from_def(
360  TplConvert::_str2int(myElemData["from_id"].front()),
361  laneVec,
362  TplConvert::_str2double(myElemData["from_pos"].front()),
363  assignedVehicles);
364 
365  //NOTE: there should be only 1 lane number in XML
366  // subtraction of 1 as in readExtEdgePointDef()
367  laneVec[0] = TplConvert::_str2int(myElemData["to_lane"].front()) - 1;
368  // then count up, building lane number vector
369  for (std::vector<int>::iterator each = ++laneVec.begin(); each != laneVec.end(); ++each) {
370  *each = *(each - 1) + 1;
371  }
372 
374  TplConvert::_str2int(myElemData["to_id"].front()),
375  laneVec,
376  TplConvert::_str2double(myElemData["to_pos"].front()),
377  assignedVehicles);
378 
379  NIVissimConnection* connector = new
381  myElemData["name"].front(),
382  from_def, to_def,
383  geom, assignedVehicles, clv);
384 
385  NIVissimConnection::dictionary(id, connector);
386  }
387  // clear the element data
388  myElemData.clear();
389  //std::cout << "elemData len (clear):" << myElemData.size() << std::endl;
390  //std::cout.flush();
391  }
393 }
394 
395 
396 // ---------------------------------------------------------------------------
397 // definitions of NIVissimXMLHandler_Zuflussdefinition-methods
398 // ---------------------------------------------------------------------------
402  "vissim - file") {
403 }
404 
406 
407 void
409  // finding an actual flow
410  if (element == VISSIM_TAG_VEHICLE_INPUT) {
411  //parse all flows
412  bool ok = true;
413  std::string id = attrs.get<std::string>(VISSIM_ATTR_NO, 0, ok);
414  std::string edgeid = attrs.get<std::string>(VISSIM_ATTR_LINK, 0, ok);
415  std::string name = attrs.get<std::string>(VISSIM_ATTR_NAME, 0, ok, false);
416 
418  name,
419  edgeid);
420  }
421 }
422 
423 // ---------------------------------------------------------------------------
424 // definitions of NIVissimXMLHandler_Parkplatzdefinition-methods
425 // ---------------------------------------------------------------------------
429  "vissim - file") {
430 }
431 
433 
434 void
436  // finding an actual parkinglot
437  if (element == VISSIM_TAG_PARKINGLOT) {
438  //parse all parkinglots
439  bool ok = true;
440  int id = attrs.get<int>(VISSIM_ATTR_NO, 0, ok);
441  int edgeid = attrs.get<int>(VISSIM_ATTR_INTLINK, 0, ok);
442  std::string name = attrs.get<std::string>(VISSIM_ATTR_NAME, 0, ok, false);
443  double position = attrs.get<double>(VISSIM_ATTR_POS, 0, ok);
444  std::vector<std::pair<int, int> > assignedVehicles; // (vclass, vwunsch)
445  //FIXME: vWunsch + Fahzeugklassen einlesen
446  // There can be s
447  std::vector<int> districts;
448  //FIXME: Parkplatzdefinition für mehrere Zonen implementieren
449  std::vector<double> percentages;
450  districts.push_back(attrs.get<int>(VISSIM_ATTR_DISTRICT, 0, ok));
451  percentages.push_back(attrs.get<double>(VISSIM_ATTR_PERCENTAGE, 0, ok));
452 
454  name,
455  districts,
456  percentages,
457  edgeid,
458  position,
459  assignedVehicles);
460  }
461 }
462 
463 
464 // ---------------------------------------------------------------------------
465 // definitions of NIVissimXMLHandler_Fahrzeugklassendefinition-methods
466 // ---------------------------------------------------------------------------
470  "vissim - file"),
471  myElemData(elemData),
472  myHierarchyLevel(0) {
473  myElemData.clear();
474 }
475 
477 
478 void
481 
482  if (element == VISSIM_TAG_VEHICLE_CLASS) {
483  bool ok = true;
484  myElemData["id"].push_back(attrs.get<std::string>(VISSIM_ATTR_NO, 0, ok));
485  myElemData["name"].push_back(attrs.get<std::string>(VISSIM_ATTR_NAME, 0, ok, false));
486  std::string colorStr(attrs.get<std::string>(VISSIM_ATTR_COLOR, 0, ok));
487  for (int pos = (int)colorStr.size() - 2; pos > 0; pos -= 2) {
488  colorStr.insert(pos, " ");
489  }
490  myElemData["color"].push_back(colorStr);
491  }
492  if (element == VISSIM_TAG_INTOBJECTREF) {
493  bool ok = true;
494  myElemData["types"].push_back(attrs.get<std::string>(VISSIM_ATTR_KEY, 0, ok));
495 
496 
497  }
498 }
499 
500 void
502  if (element == VISSIM_TAG_VEHICLE_CLASS && myHierarchyLevel == 3) {
503  RGBColor color;
504  std::istringstream iss(myElemData["color"].front());
505  std::vector<std::string> sCol_v(StringTokenizer(
506  myElemData["color"].front(), " ").getVector());
507  std::vector<int> myColorVector(sCol_v.size());
508  std::transform(sCol_v.begin(), sCol_v.end(), myColorVector.begin(),
510 
511  color = RGBColor((unsigned char)myColorVector[0],
512  (unsigned char)myColorVector[1],
513  (unsigned char)myColorVector[2],
514  (unsigned char)myColorVector[3]);
515  std::vector<int> types;
516  while (!myElemData["types"].empty()) {
517  types.push_back(TplConvert::_str2int(myElemData["types"].front()));
518  myElemData["types"].pop_front();
519  }
520 
522  myElemData["name"].front(),
523  color,
524  types);
525  myElemData.clear();
526  }
528 }
529 
530 // ---------------------------------------------------------------------------
531 // definitions of NIVissimXMLHandler_Geschwindigkeitsverteilungsdefinition-methods
532 // ---------------------------------------------------------------------------
536  "vissim - file"),
537  myElemData(elemData),
538  myHierarchyLevel(0) {
539  myElemData.clear();
540 }
541 
543 
544 void
547  if (element == VISSIM_TAG_SPEED_DIST) {
548  bool ok = true;
549  myElemData["id"].push_back(attrs.get<std::string>(VISSIM_ATTR_NO, 0, ok));
550  }
551 
552  if (element == VISSIM_TAG_DATAPOINT) {
553  bool ok = true;
554  std::string sep(" ");
555  std::string posS(attrs.get<std::string>(VISSIM_ATTR_X, 0, ok));
556  posS += sep;
557  posS.append(attrs.get<std::string>(VISSIM_ATTR_FX, 0, ok));
558  myElemData["points"].push_back(posS);
559 
560  }
561 
562 }
563 
564 void
566  if (element == VISSIM_TAG_SPEED_DIST && myHierarchyLevel == 3) {
567  Distribution_Points* points = new Distribution_Points(myElemData["id"].front());
568  while (!myElemData["points"].empty()) {
569  std::vector<std::string> sPos_v(StringTokenizer(
570  myElemData["points"].front(), " ").getVector());
571  myElemData["points"].pop_front();
572  points->add(TplConvert::_str2double(sPos_v[0]), TplConvert::_str2double(sPos_v[1]));
573  }
574  DistributionCont::dictionary("speed", myElemData["id"].front(), points);
575  myElemData.clear();
576  }
578 }
579 
580 // ---------------------------------------------------------------------------
581 // definitions of NIVissimXMLHandler_VWunschentscheidungsdefinition-methods
582 // ---------------------------------------------------------------------------
586  "vissim - file"),
587  myElemData(elemData),
588  myHierarchyLevel(0) {
589  myElemData.clear();
590 }
591 
593 
594 void
597  if (element == VISSIM_TAG_SPEED_DECISION) {
598  bool ok = true;
599  myElemData["name"].push_back(attrs.get<std::string>(VISSIM_ATTR_NAME, 0, ok, false));
600  //FIXME: 2 vWunsch in the xml file, but only 1 of them is set???
601  }
602 
603 }
604 
605 void
608 }
609 
610 
611 // ---------------------------------------------------------------------------
612 // definitions of NIVissimXMLHandler_Routenentscheidungsdefinition-methods
613 // ---------------------------------------------------------------------------
617  "vissim - file"),
618  myElemData(elemData),
619  myHierarchyLevel(0) {
620  myElemData.clear();
621 }
622 
624 
625 void
628  if (element == VISSIM_TAG_DECISION_STATIC) {
629  bool ok = true;
630  myElemData["startLink"].push_back(attrs.get<std::string>(VISSIM_ATTR_LINK, 0, ok));
631  myElemData["startPos"].push_back(attrs.get<std::string>(VISSIM_ATTR_POS, 0, ok));
632  }
633  if (element == VISSIM_TAG_ROUTE_STATIC) {
634  bool ok = true;
635  myElemData["destLink"].push_back(attrs.get<std::string>(VISSIM_ATTR_DESTLINK, 0, ok));
636  myElemData["destPos"].push_back(attrs.get<std::string>(VISSIM_ATTR_DESTPOS, 0, ok));
637  myElemData["id"].push_back(attrs.get<std::string>(VISSIM_ATTR_NO, 0, ok));
638  }
639  if (element == VISSIM_TAG_INTOBJECTREF) {
640  // bool ok = true;
641  }
642 
643 }
644 
645 void
648 }
649 
650 // ---------------------------------------------------------------------------
651 // definitions of NIVissimXMLHandler_ConflictArea-methods
652 // ---------------------------------------------------------------------------
656  "vissim - file") {}
657 
659 
660 void
662  // finding an actual flow
663  if (element == VISSIM_TAG_CA) {
664  //parse all flows
665  bool ok = true;
666  std::string status = attrs.get<std::string>(VISSIM_ATTR_STATUS, 0, ok);
667  //get only the conflict areas which were set in VISSIM
668  if (status != "PASSIVE") {
670  attrs.get<std::string>(VISSIM_ATTR_LINK1, 0, ok),
671  attrs.get<std::string>(VISSIM_ATTR_LINK2, 0, ok),
672  status);
673  }
674 
675  }
676 }
677 
678 
679 /* -------------------------------------------------------------------------
680  * NIImporter_Vissim::VissimSingleTypeParser-methods
681  * ----------------------------------------------------------------------- */
683  : myVissimParent(parent) {}
684 
685 
687 
688 
689 std::string
691  std::string tmp;
692  from >> tmp;
693  return StringUtils::to_lower_case(tmp);
694 }
695 
696 
697 
698 std::string
700  const std::string& excl) {
701  std::string myExcl = StringUtils::to_lower_case(excl);
702  std::string tmp = myRead(from);
703  if (tmp == "") {
704  return "DATAEND";
705  }
706  if (tmp != myExcl
707  &&
708  (tmp.substr(0, 2) == "--" || !myVissimParent.admitContinue(tmp))
709  ) {
710  return "DATAEND";
711  }
712  return StringUtils::to_lower_case(tmp);
713 }
714 
715 
716 std::string
718  const std::vector<std::string>& excl) {
719  std::vector<std::string> myExcl;
720  std::vector<std::string>::const_iterator i;
721  for (i = excl.begin(); i != excl.end(); i++) {
722  std::string mes = StringUtils::to_lower_case(*i);
723  myExcl.push_back(mes);
724  }
725  std::string tmp = myRead(from);
726  if (tmp == "") {
727  return "DATAEND";
728  }
729 
730  bool equals = false;
731  for (i = myExcl.begin(); i != myExcl.end() && !equals; i++) {
732  if ((*i) == tmp) {
733  equals = true;
734  }
735  }
736  if (!equals
737  &&
738  (tmp.substr(0, 2) == "--" || !myVissimParent.admitContinue(tmp))
739  ) {
740  return "DATAEND";
741  }
742  return StringUtils::to_lower_case(tmp);
743 }
744 
745 
746 std::string
748  const std::string& tag) {
749  std::string tmp;
750  if (tag == "") {
751  tmp = myRead(from);
752  } else {
753  tmp = tag;
754  }
755  if (tmp == "beschriftung") {
756  tmp = myRead(from);
757  if (tmp == "keine") {
758  from >> tmp;
759  }
760  tmp = myRead(from);
761  tmp = myRead(from);
762  }
763  return tmp;
764 }
765 
766 
767 Position
769  double x, y;
770  from >> x; // type-checking is missing!
771  from >> y; // type-checking is missing!
772  return Position(x, y);
773 }
774 
775 
776 std::vector<int>
778  std::istream& from, const std::string& next) {
779  std::string tmp = readEndSecure(from);
780  std::vector<int> ret;
781  if (tmp == "alle") {
782  ret.push_back(-1);
783  return ret;
784  }
785  while (tmp != "DATAEND" && tmp != next) {
786  ret.push_back(TplConvert::_2int(tmp.c_str()));
787  tmp = readEndSecure(from);
788  }
789  return ret;
790 }
791 
792 
795  std::istream& from) {
796  std::string tag;
797  from >> tag; // "Strecke"
798  int edgeid;
799  from >> edgeid; // type-checking is missing!
800  from >> tag; // "Spuren"
801  std::vector<int> lanes;
802  while (tag != "bei") {
803  tag = readEndSecure(from);
804  if (tag != "bei") {
805  int lane = TplConvert::_2int(tag.c_str());
806  lanes.push_back(lane - 1);
807  }
808  }
809  double position;
810  from >> position;
811  std::vector<int> dummy;
812  return NIVissimExtendedEdgePoint(edgeid, lanes, position, dummy);
813 }
814 
815 
816 std::string
818  std::string name;
819  from >> name;
820  if (name[0] == '"') {
821  while (name[name.length() - 1] != '"') {
822  std::string tmp;
823  from >> tmp;
824  name = name + " " + tmp;
825  }
826  name = name.substr(1, name.length() - 2);
827  }
828  return StringUtils::convertUmlaute(name);
829 }
830 
831 
832 void
834  const std::string& name) {
835  std::string tag;
836  while (tag != name) {
837  tag = myRead(from);
838  }
839 }
840 
841 bool
843  const std::string& name) {
844  std::string tag;
845  while (tag != name) {
846  tag = myRead(from);
847  }
848  while (tag != "DATAEND") {
849  tag = readEndSecure(from);
850  }
851  return true;
852 }
853 
854 
855 
856 /* -------------------------------------------------------------------------
857  * NIImporter_Vissim-methods
858  * ----------------------------------------------------------------------- */
860  : myNetBuilder(nb), myInputIsLegacyFormat(false) {
861  UNUSED_PARAMETER(file);
863  buildParsers();
864  myColorMap["blau"] = RGBColor(77, 77, 255, 255);
865  myColorMap["gelb"] = RGBColor::YELLOW;
866  myColorMap["grau"] = RGBColor::GREY;
867  myColorMap["lila"] = RGBColor::MAGENTA;
868  myColorMap["gruen"] = RGBColor::GREEN;
869  myColorMap["rot"] = RGBColor::RED;
870  myColorMap["schwarz"] = RGBColor::BLACK;
871  myColorMap["tuerkis"] = RGBColor::CYAN;
872  myColorMap["weiss"] = RGBColor::WHITE;
873  myColorMap["keine"] = RGBColor::WHITE;
874 }
875 
876 
877 
878 
898  for (ToParserMap::iterator i = myParsers.begin(); i != myParsers.end(); i++) {
899  delete(*i).second;
900  }
901 }
902 
903 
904 void
906  // load file contents
907  // try to open the file
908  std::ifstream strm(options.getString("vissim-file").c_str());
909  if (!strm.good()) {
910  WRITE_ERROR("The vissim-file '" + options.getString("vissim-file") + "' was not found.");
911  return;
912  }
913  if (!readContents(strm)) {
914  return;
915  }
916  postLoadBuild(options.getFloat("vissim.join-distance"));
917 }
918 
919 void
921  // Parse file
922  std::string file = options.getString("vissim-file");
923  // Create NIVissimXMLHandlers
924  NIVissimXMLHandler_Streckendefinition XMLHandler_Streckendefinition(elementData);
925  NIVissimXMLHandler_Zuflussdefinition XMLHandler_Zuflussdefinition;
926  //NIVissimXMLHandler_Parkplatzdefinition XMLHandler_Parkplatzdefinition;
927  NIVissimXMLHandler_Fahrzeugklassendefinition XMLHandler_Fahrzeugklassendefinition(elementData);
928  NIVissimXMLHandler_Geschwindigkeitsverteilungsdefinition XMLHandler_Geschwindigkeitsverteilung(elementData);
929  NIVissimXMLHandler_ConflictArea XMLHandler_ConflictAreas;
930  if (!FileHelpers::isReadable(file)) {
931  WRITE_ERROR("Could not open vissim-file '" + file + "'.");
932  return;
933  }
934 
935  // Strecken + Verbinder
936  XMLHandler_Streckendefinition.setFileName(file);
937  PROGRESS_BEGIN_MESSAGE("Parsing strecken+verbinder from vissim-file '" + file + "'");
938  if (!XMLSubSys::runParser(XMLHandler_Streckendefinition, file)) {
939  return;
940  }
942 
943  // Zuflüsse
944  XMLHandler_Zuflussdefinition.setFileName(file);
945  PROGRESS_BEGIN_MESSAGE("Parsing zuflüsse from vissim-file '" + file + "'");
946  if (!XMLSubSys::runParser(XMLHandler_Zuflussdefinition, file)) {
947  return;
948  }
950 
951  //Geschwindigkeitsverteilungen
952  XMLHandler_Geschwindigkeitsverteilung.setFileName(file);
953  PROGRESS_BEGIN_MESSAGE("Parsing parkplätze from vissim-file '" + file + "'");
954  if (!XMLSubSys::runParser(XMLHandler_Geschwindigkeitsverteilung, file)) {
955  return;
956  }
958 
959 
960  //Fahrzeugklassen
961  XMLHandler_Fahrzeugklassendefinition.setFileName(file);
962  PROGRESS_BEGIN_MESSAGE("Parsing parkplätze from vissim-file '" + file + "'");
963  if (!XMLSubSys::runParser(XMLHandler_Fahrzeugklassendefinition, file)) {
964  return;
965  }
967 
968  //Parkplätze
969  /*XMLHandler_Parkplatzdefinition.setFileName(file);
970  PROGRESS_BEGIN_MESSAGE("Parsing parkplätze from vissim-file '" + file + "'");
971  if (!XMLSubSys::runParser(XMLHandler_Parkplatzdefinition, file)) {
972  return;
973  }
974  PROGRESS_DONE_MESSAGE();*/
975 
976 
977  //Konfliktflächen
978  XMLHandler_ConflictAreas.setFileName(file);
979  PROGRESS_BEGIN_MESSAGE("Parsing conflict areas from vissim-file '" + file + "'");
980  if (!XMLSubSys::runParser(XMLHandler_ConflictAreas, file)) {
981  return;
982  }
984 
985  postLoadBuild(options.getFloat("vissim.join-distance"));
986 }
987 
988 bool
989 NIImporter_Vissim::admitContinue(const std::string& tag) {
990  ToElemIDMap::const_iterator i = myKnownElements.find(tag);
991  if (i == myKnownElements.end()) {
992  return true;
993  }
994  myLastSecure = tag;
995  return false;
996 }
997 
998 
999 bool
1000 NIImporter_Vissim::readContents(std::istream& strm) {
1001  // read contents
1002  bool ok = true;
1003  while (strm.good() && ok) {
1004  std::string tag;
1005  if (myLastSecure != "") {
1006  tag = myLastSecure;
1007  } else {
1008  strm >> tag;
1009  }
1010  myLastSecure = "";
1011  bool parsed = false;
1012  while (!parsed && strm.good() && ok) {
1013  ToElemIDMap::iterator i = myKnownElements.find(StringUtils::to_lower_case(tag));
1014  if (i != myKnownElements.end()) {
1015  ToParserMap::iterator j = myParsers.find((*i).second);
1016  if (j != myParsers.end()) {
1017  VissimSingleTypeParser* parser = (*j).second;
1018  ok = parser->parse(strm);
1019  parsed = true;
1020  }
1021  }
1022  if (!parsed) {
1023  std::string line;
1024  std::streamoff pos;
1025  do {
1026  pos = strm.tellg();
1027  getline(strm, line);
1028  } while (strm.good() && (line == "" || line[0] == ' ' || line[0] == '-'));
1029  if (!strm.good()) {
1030  return true;
1031  }
1032  strm.seekg(pos);
1033  strm >> tag;
1034  }
1035  }
1036  }
1037  return ok;
1038 }
1039 
1040 
1041 void
1043  // close the loading process
1047  // build district->connections map
1049  // build clusters around nodes
1050 // NIVissimNodeDef::buildNodeClusters();
1051  // build node clusters around traffic lights
1052 // NIVissimTL::buildNodeClusters();
1053 
1054  // when connections or disturbances are left, build nodes around them
1055 
1056  // try to assign connection clusters to nodes
1057  // only left connections will be processed in
1058  // buildConnectionClusters & join
1059 //30.4. brauchen wir noch! NIVissimNodeDef::dict_assignConnectionsToNodes();
1060 
1061  // build clusters of connections with the same direction and a similar position along the streets
1063  // check whether further nodes (connection clusters by now) must be added
1065 
1066  // join clusters when overlapping (different streets are possible)
1069 // NIVissimConnectionCluster::joinByDisturbances(offset);
1070 
1071 // NIVissimConnectionCluster::addTLs(offset);
1072 
1073  // build nodes from clusters
1076 
1077 // NIVissimNodeCluster::dict_recheckEdgeChanges();
1083  if (OptionsCont::getOptions().getBool("vissim.report-unset-speeds")) {
1085  }
1091 }
1092 
1093 
1094 void
1096  myKnownElements["kennung"] = VE_Kennungszeile;
1097  myKnownElements["zufallszahl"] = VE_Startzufallszahl;
1098  myKnownElements["simulationsdauer"] = VE_Simdauer;
1099  myKnownElements["startuhrzeit"] = VE_Startuhrzeit;
1100  myKnownElements["simulationsrate"] = VE_SimRate;
1101  myKnownElements["zeitschritt"] = VE_Zeitschrittfaktor;
1102  myKnownElements["linksverkehr"] = VE_Linksverkehr;
1103  myKnownElements["dynuml"] = VE_DynUml;
1105  myKnownElements["gelbverhalten"] = VE_Gelbverhaltendefinition;
1107  myKnownElements["verbindung"] = VE_Verbindungsdefinition;
1108  myKnownElements["richtungsentscheidung"] = VE_Richtungsentscheidungsdefinition;
1109  myKnownElements["routenentscheidung"] = VE_Routenentscheidungsdefinition;
1110  myKnownElements["vwunschentscheidung"] = VE_VWunschentscheidungsdefinition;
1111  myKnownElements["langsamfahrbereich"] = VE_Langsamfahrbereichdefinition;
1113  myKnownElements["fahrzeugtyp"] = VE_Fahrzeugtypdefinition;
1114  myKnownElements["fahrzeugklasse"] = VE_Fahrzeugklassendefinition;
1124  myKnownElements["wunschbeschleunigung"] = VE_Wunschbeschleunigungskurvedefinition;
1127  myKnownElements["querverkehrsstoerung"] = VE_Querverkehrsstoerungsdefinition;
1129  myKnownElements["signalgruppe"] = VE_Signalgruppendefinition;
1130  myKnownElements["signalgeber"] = VE_Signalgeberdefinition;
1131  myKnownElements["lsakopplung"] = VE_LSAKopplungdefinition;
1133  myKnownElements["haltestelle"] = VE_Haltestellendefinition;
1135  myKnownElements["stopschild"] = VE_Stopschilddefinition;
1139  myKnownElements["querschnittsmessung"] = VE_Querschnittsmessungsdefinition;
1140  myKnownElements["stauzaehler"] = VE_Stauzaehlerdefinition;
1141  myKnownElements["auswertung"] = VE_Auswertungsdefinition;
1144  myKnownElements["parkplatz"] = VE_Parkplatzdefinition;
1147  myKnownElements["netzobjekt"] = VE_Netzobjektdefinition;
1148  myKnownElements["richtungspfeil"] = VE_Richtungspfeildefinition;
1150  myKnownElements["fahrverhalten"] = VE_Fahrverhaltendefinition;
1151  myKnownElements["fahrtverlaufdateien"] = VE_Fahrtverlaufdateien;
1152  myKnownElements["emission"] = VE_Emission;
1154  myKnownElements["streckentyp"] = VE_Streckentypdefinition;
1155  myKnownElements["kantensperrung"] = VE_Kantensperrung;
1157 
1158 
1159  myKnownElements["advance"] = VE_DUMMY;
1160  myKnownElements["temperatur"] = VE_DUMMY;
1161 
1162 }
1163 
1164 
1165 
1166 void
1172  myParsers[VE_DynUml] =
1246 
1289 
1290 }
1291 
1292 
1293 
1294 /****************************************************************************/
1295 
static void clearDict()
static void joinBySameEdges(double offset)
Tries to joind clusters participating within a node This is done by joining clusters which overlap...
void readUntil(std::istream &from, const std::string &name)
Reads from the stream until the keywor occurs.
static void dict_BuildDistricts(NBDistrictCont &dc, NBEdgeCont &ec, NBNodeCont &nc)
Builds the districts.
static bool dictionary(int id, const std::string &name, const RGBColor &color, std::vector< int > &types)
static void dict_buildNBEdgeConnections(NBEdgeCont &ec)
static bool isReadable(std::string path)
Checks whether the given file is readable.
Definition: FileHelpers.cpp:54
NIVissimXMLHandler_Streckendefinition(nodeMap &elemData)
Constructor.
static const RGBColor WHITE
Definition: RGBColor.h:196
static bool dictionary(int id, const std::string &link1, const std::string &link2, const std::string &status)
Adds the described item to the dictionary Builds the conflict area first.
std::string myRead(std::istream &from)
reads from the stream and returns the lower case version of the read value
static void dict_checkEdges2Join()
static void reportUnsetSpeeds()
Writes edges with unset speeds to the warnings message log instance.
std::string readEndSecure(std::istream &from, const std::string &excl="")
as myRead, but returns "DATAEND" when the current field has ended
std::vector< NIVissimClosedLaneDef * > NIVissimClosedLanesVector
~NIImporter_Vissim()
destructor
static StringBijection< int >::Entry vissimAttrs[]
The names of VISSIM-XML attributes (for passing to GenericSAXHandler)
static void clearDict()
Importer for networks stored in Vissim format.
VissimSingleTypeParser(NIImporter_Vissim &parent)
Constructor.
static void dict_buildNBEdges(NBDistrictCont &dc, NBNodeCont &nc, NBEdgeCont &ec, double offset)
Builds NBEdges from the VissimEdges within the dictionary.
virtual bool parse(std::istream &from)=0
Parses a single data type. Returns whether no error occured.
bool readContents(std::istream &strm)
static bool dictionary(const std::string &type, const std::string &id, Distribution *d)
Adds a distribution of the given type and name to the container.
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
static const RGBColor BLACK
Definition: RGBColor.h:197
static bool dictionary(int id, NIVissimConnection *o)
int myLastNodeID
ID of the currently parsed node, for reporting mainly.
static void clearDict()
static int getMaxID()
static bool runParser(GenericSAXHandler &handler, const std::string &file, const bool isNet=false)
Runs the given handler on the given file; returns if everything&#39;s ok.
Definition: XMLSubSys.cpp:110
void myEndElement(int element)
Callback method for a closing tag to implement by derived classes.
#define UNUSED_PARAMETER(x)
Definition: StdDefs.h:38
void myStartElement(int element, const SUMOSAXAttributes &attrs)
Called on the opening of a tag;.
static void setPriorityRegulation(NBEdgeCont &ec)
Sets the priority regulation according to the VISSIM conflict area data.
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:65
A temporary storage for edges imported from Vissim.
Definition: NIVissimEdge.h:60
static double _str2double(const std::string &sData)
converts a string into the double value described by it by calling the char-type converter ...
Definition: TplConvert.h:348
void loadXML(const OptionsCont &options, NBNetBuilder &nb)
ToParserMap myParsers
Parsers by element id.
static void dict_assignToEdges()
void insertKnownElements()
adds name-to-id - relationships of known elements into myKnownElements
bool isSet(const std::string &name, bool failOnNonExistant=true) const
Returns the information whether the named option is set.
ToElemIDMap myKnownElements
Map from element names to their numerical representation.
A handler which converts occuring elements and attributes into enums.
static void setCurrentVirtID(int id)
static const RGBColor GREEN
Definition: RGBColor.h:190
static const RGBColor GREY
Definition: RGBColor.h:198
void setFileName(const std::string &name)
Sets the current file name.
void myStartElement(int element, const SUMOSAXAttributes &attrs)
Called on the opening of a tag;.
void myEndElement(int element)
Callback method for a closing tag to implement by derived classes.
NIVissimExtendedEdgePoint readExtEdgePointDef(std::istream &from)
static void dict_addDisturbances(NBDistrictCont &dc, NBNodeCont &nc, NBEdgeCont &ec)
Encapsulated SAX-Attributes.
static void dict_propagateSpeeds()
void load(const OptionsCont &options)
loads the vissim file
T get(int attr, const char *objectid, bool &ok, bool report=true) const
Tries to read given attribute assuming it is an int.
static void clearDict()
Clears the dictionary.
void myStartElement(int element, const SUMOSAXAttributes &attrs)
Called on the opening of a tag;.
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:46
NBEdgeCont & getEdgeCont()
Definition: NBNetBuilder.h:155
static StringBijection< int >::Entry vissimTags[]
The names of VISSIM-XML elements (for passing to GenericSAXHandler)
A list of positions.
ColorMap myColorMap
a map from color names to color definitions
std::string getString(const std::string &name) const
Returns the string-value of the named option (only for Option_String)
static int _str2int(const std::string &sData)
converts a string into the integer value described by it by calling the char-type converter...
Definition: TplConvert.h:160
static bool dict_SetSignals(NBTrafficLightLogicCont &tlc, NBEdgeCont &ec)
Definition: NIVissimTL.cpp:373
void myStartElement(int element, const SUMOSAXAttributes &attrs)
Called on the opening of a tag;.
void myStartElement(int element, const SUMOSAXAttributes &attrs)
Called on the opening of a tag;.
static const RGBColor MAGENTA
Definition: RGBColor.h:194
#define PROGRESS_BEGIN_MESSAGE(msg)
Definition: MsgHandler.h:202
Position getPosition(std::istream &from)
returns the 2d-position saved as next within the stream
void myEndElement(int element)
Callback method for a closing tag to implement by derived classes.
void myStartElement(int element, const SUMOSAXAttributes &attrs)
Called on the opening of a tag;.
static bool dictionary(int id, const std::string &name, const std::string &type, int noLanes, double zuschlag1, double zuschlag2, double length, const PositionVector &geom, const NIVissimClosedLanesVector &clv)
Adds the described item to the dictionary Builds the edge first.
std::string readName(std::istream &from)
Reads the structures name We cannot use the "<<" operator, as names may contain more than one word wh...
double getFloat(const std::string &name) const
Returns the double-value of the named option (only for Option_Float)
static std::string convertUmlaute(std::string str)
Converts german "Umlaute" to their latin-version.
Definition: StringUtils.cpp:91
std::vector< std::string > getVector()
void buildParsers()
adds id-to-parser - relationships of elements to parse into myParsers
#define WRITE_ERROR(msg)
Definition: MsgHandler.h:206
static void clearDict()
Clears the dictionary.
static void buildConnectionClusters()
Clusters connections of each edge.
static std::string to_lower_case(std::string str)
Transfers the content to lower case.
Definition: StringUtils.cpp:63
static const RGBColor YELLOW
Definition: RGBColor.h:192
static int _2int(const E *const data)
converts a char-type array into the integer value described by it
Definition: TplConvert.h:149
static const RGBColor RED
Definition: RGBColor.h:189
double length() const
Returns the length.
static const RGBColor CYAN
Definition: RGBColor.h:193
std::map< std::string, std::list< std::string > > nodeMap
NIImporter_Vissim(NBNetBuilder &nb, const std::string &file)
constructor
NBNodeCont & getNodeCont()
Returns a reference to the node container.
Definition: NBNetBuilder.h:160
void myStartElement(int element, const SUMOSAXAttributes &attrs)
Called on the opening of a tag;.
Instance responsible for building networks.
Definition: NBNetBuilder.h:114
A storage for options typed value containers)
Definition: OptionsCont.h:99
bool skipOverreading(std::istream &from, const std::string &name="")
Overreads the named parameter (if) given and skips the rest until "DATAEND".
static void loadNetwork(const OptionsCont &oc, NBNetBuilder &nb)
Loads network definition from the assigned option and stores it in the given network builder...
NBTrafficLightLogicCont & getTLLogicCont()
Returns a reference to the traffic light logics container.
Definition: NBNetBuilder.h:170
static void buildNBNodes(NBNodeCont &nc)
static void clearDict()
Definition: NIVissimTL.cpp:361
void postLoadBuild(double offset)
static void dict_SetDisturbances()
void push_back_noDoublePos(const Position &p)
insert in back a non double position
NBNetBuilder & myNetBuilder
#define PROGRESS_DONE_MESSAGE()
Definition: MsgHandler.h:203
std::string myLastSecure
static int _strHex2int(const std::string &sData)
converts a string with a hex value into the integer value described by it by calling the char-type co...
Definition: TplConvert.h:179
void myEndElement(int element)
Callback method for a closing tag to implement by derived classes.
bool add(T val, double prob, bool checkDuplicates=true)
Adds a value with an assigned probability to the distribution.
NBDistrictCont & getDistrictCont()
Returns a reference the districts container.
Definition: NBNetBuilder.h:175
void myEndElement(int element)
Callback method for a closing tag to implement by derived classes.
bool admitContinue(const std::string &tag)
std::string overrideOptionalLabel(std::istream &from, const std::string &tag="")
overrides the optional label definition; returns the next tag as done by readEndSecure ...
void myStartElement(int element, const SUMOSAXAttributes &attrs)
Called on the opening of a tag;.
std::vector< int > parseAssignedVehicleTypes(std::istream &from, const std::string &next)
parses a listof vehicle types assigned to the current data field One should remeber, that -1 means "all" vehicle types
static bool dictionary(const std::string &id, const std::string &name, const std::string &edgeid)
static void dict_BuildDistrictNodes(NBDistrictCont &dc, NBNodeCont &nc)
Builds the nodes that belong to a district.
static bool dictionary(int id, const std::string &name, const std::vector< int > &districts, const std::vector< double > &percentages, int edgeid, double position, const std::vector< std::pair< int, int > > &assignedVehicles)
Inserts the connection into the dictionary after building it.