SUMO - Simulation of Urban MObility
NIImporter_Vissim.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2018 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 /****************************************************************************/
19 // -------------------
20 /****************************************************************************/
21 
22 
23 // ===========================================================================
24 // included modules
25 // ===========================================================================
26 #include <config.h>
27 
28 
29 #include <string>
30 #include <fstream>
35 #include <netbuild/NBNetBuilder.h>
36 #include "NIImporter_Vissim.h"
92 
93 
94 #include "tempstructs/NIVissimTL.h"
107 
109 #include <utils/xml/XMLSubSys.h>
114 
115 #include <netbuild/NBEdgeCont.h> // !!! only for debugging purposes
116 
117 
118 // ===========================================================================
119 // static variables
120 // ===========================================================================
129  { "fromLinkEndPt", NIImporter_Vissim::VISSIM_TAG_FROM },
130  { "toLinkEndPt", NIImporter_Vissim::VISSIM_TAG_TO },
134  { "intObjectRef", NIImporter_Vissim::VISSIM_TAG_INTOBJECTREF },
135  { "desSpeedDecision", NIImporter_Vissim::VISSIM_TAG_SPEED_DECISION },
136  {
137  "desSpeedDistribution",
139  },
140  {
141  "speedDistributionDataPoint",
143  },
144  {
145  "vehicleRoutingDecisionStatic",
147  },
148  {
149  "vehicleRouteStatic",
151  },
152  { "conflictArea", NIImporter_Vissim::VISSIM_TAG_CA },
154 };
155 
156 
158  { "no", NIImporter_Vissim::VISSIM_ATTR_NO }, //id
170  { "intLink", NIImporter_Vissim::VISSIM_ATTR_INTLINK }, //edgeID
182 };
183 
184 
185 // ===========================================================================
186 // method definitions
187 // ===========================================================================
188 // ---------------------------------------------------------------------------
189 // static methods (interface in this case)
190 // ---------------------------------------------------------------------------
191 void
193  if (!oc.isSet("vissim-file")) {
194  return;
195  }
196  NIImporter_Vissim loader(nb, oc.getString("vissim-file"));
197  // check if legacy format file or newer XML file
198  // file name extension check
199  if ((oc.getString("vissim-file").find(".inpx") != std::string::npos))
200  //TODO: check if the given position of .inpx is at the end
201  {
202  // load the XML vissim network
203  loader.loadXML(oc, nb);
204  loader.myInputIsLegacyFormat = false;
205  } else {
206  // load the legacy vissim network
207  loader.load(oc);
208  loader.myInputIsLegacyFormat = true;
209  }
210 }
211 
212 
213 // ---------------------------------------------------------------------------
214 // definitions of NIVissimXMLHandler_Streckendefinition-methods
215 // ---------------------------------------------------------------------------
217  //std::map<int, VissimXMLEdge>& toFill)
218  nodeMap& elemData)
221  "vissim - file"),
222  myElemData(elemData),
223  myHierarchyLevel(0),
224  isConnector(false) {
225  myElemData.clear();
226 }
227 
229 
230 void
233 
234  // finding an actual LINK
235  if (element == VISSIM_TAG_LINK) {
236  //parse all links
237  bool ok = true;
238  int id = attrs.get<int>(VISSIM_ATTR_NO, nullptr, ok);
239  myLastNodeID = id;
240 
241  // !!! assuming empty myElemData
242  myElemData["id"].push_back(attrs.get<std::string>(VISSIM_ATTR_NO, nullptr, ok));
243  // error ignored if name is empty
244  myElemData["name"].push_back(attrs.get<std::string>(VISSIM_ATTR_NAME, nullptr, ok, false));
245  myElemData["type"].push_back(attrs.get<std::string>(VISSIM_ATTR_LINKBEHAVETYPE, nullptr, ok));
246  myElemData["zuschlag1"].push_back(attrs.get<std::string>(VISSIM_ATTR_ZUSCHLAG1, nullptr, ok));
247  myElemData["zuschlag2"].push_back(attrs.get<std::string>(VISSIM_ATTR_ZUSCHLAG2, nullptr, ok));
248  }
249 
250  if (element == VISSIM_TAG_LANE) {
251  bool ok = true;
252  // appends empty element if no width found
253  // error ignored if name is empty
254  myElemData["width"].push_back(attrs.get<std::string>(VISSIM_ATTR_WIDTH, nullptr, ok, false));
255  }
256 
257  if (element == VISSIM_TAG_FROM) {
258  if (isConnector != true) {
259  isConnector = true;
260  }
261  bool ok = true;
262  std::vector<std::string> from(StringTokenizer(attrs.get<std::string>(
263  VISSIM_ATTR_LANE, nullptr, ok), " ").getVector());
264  myElemData["from_pos"].push_back(attrs.get<std::string>(VISSIM_ATTR_POS, nullptr, ok));
265  myElemData["from_id"].push_back(from[0]);
266  myElemData["from_lane"].push_back(from[1]);
267  }
268 
269  if (element == VISSIM_TAG_TO) {
270  bool ok = true;
271  std::vector<std::string> to(StringTokenizer(attrs.get<std::string>(
272  VISSIM_ATTR_LANE, nullptr, ok), " ").getVector());
273  myElemData["to_pos"].push_back(attrs.get<std::string>(VISSIM_ATTR_POS, nullptr, ok));
274  myElemData["to_id"].push_back(to[0]);
275  myElemData["to_lane"].push_back(to[1]);
276  }
277 
278  if (element == VISSIM_TAG_POINT3D) {
279  bool ok = true;
280  // create a <sep> separated string of coordinate data
281  std::string sep(" ");
282 
283  std::string posS(attrs.get<std::string>(VISSIM_ATTR_X, nullptr, ok));
284  posS += sep;
285  posS.append(attrs.get<std::string>(VISSIM_ATTR_Y, nullptr, ok));
286  // allow for no Z
287  std::string z(attrs.get<std::string>(VISSIM_ATTR_ZOFFSET, nullptr, ok, false));
288  if (z.length() > 0) {
289  posS += sep;
290  posS.append(z);
291  }
292  myElemData["pos"].push_back(posS);
293  }
294 
295 
296 }
297 
298 void
300  if (element == VISSIM_TAG_LINK && myHierarchyLevel == 3) {
301  //std::cout << "elemData len:" << myElemData.size() << std::endl;
302 
303  NIVissimClosedLanesVector clv; //FIXME -> clv einlesen
304  std::vector<int> assignedVehicles; //FIXME -> assignedVehicles einlesen
305  int id(StringUtils::toInt(myElemData["id"].front()));
306 
307  PositionVector geom;
308  // convert all position coordinate strings to PositionVectors
309  while (!myElemData["pos"].empty()) {
310  std::vector<std::string> sPos_v(StringTokenizer(
311  myElemData["pos"].front(), " ").getVector());
312  myElemData["pos"].pop_front();
313  std::vector<double> pos_v(3);
314 
315  // doing a transform with explicit hint on function signature
316  std::transform(sPos_v.begin(), sPos_v.end(), pos_v.begin(),
318  geom.push_back_noDoublePos(Position(pos_v[0], pos_v[1], pos_v[2]));
319  }
320  // FIXME: a length = 0 PosVec seems fatal -> segfault
321  double length(geom.length());
322 
323  if (isConnector == false) {
324  // Add Edge
325  NIVissimEdge* edge = new NIVissimEdge(id,
326  myElemData["name"].front(),
327  myElemData["type"].front(),
328  (int)myElemData["width"].size(), // numLanes,
329  StringUtils::toDouble(myElemData["zuschlag1"].front()),
330  StringUtils::toDouble(myElemData["zuschlag2"].front()),
331  length, geom, clv);
332  NIVissimEdge::dictionary(id, edge);
333  if (id == 85 || id == 91) {
334  std::cout << id << "\n";
335  std::cout << myElemData["width"].size() << "\n";
336  std::cout << length << "\n";
337  std::cout << geom << "\n";
338  }
339  } else {
340  int numLanes = (int)myElemData["width"].size();
341  std::vector<int> laneVec(numLanes);
342  // Add Connector
343 
344  //NOTE: there should be only 1 lane number in XML
345  // subtraction of 1 as in readExtEdgePointDef()
346  laneVec[0] = StringUtils::toInt(myElemData["from_lane"].front()) - 1;
347  // then count up, building lane number vector
348  for (std::vector<int>::iterator each = ++laneVec.begin(); each != laneVec.end(); ++each) {
349  *each = *(each - 1) + 1;
350  }
351 
352  NIVissimExtendedEdgePoint from_def(
353  StringUtils::toInt(myElemData["from_id"].front()),
354  laneVec,
355  StringUtils::toDouble(myElemData["from_pos"].front()),
356  assignedVehicles);
357 
358  //NOTE: there should be only 1 lane number in XML
359  // subtraction of 1 as in readExtEdgePointDef()
360  laneVec[0] = StringUtils::toInt(myElemData["to_lane"].front()) - 1;
361  // then count up, building lane number vector
362  for (std::vector<int>::iterator each = ++laneVec.begin(); each != laneVec.end(); ++each) {
363  *each = *(each - 1) + 1;
364  }
365 
367  StringUtils::toInt(myElemData["to_id"].front()),
368  laneVec,
369  StringUtils::toDouble(myElemData["to_pos"].front()),
370  assignedVehicles);
371 
372  NIVissimConnection* connector = new
374  myElemData["name"].front(),
375  from_def, to_def,
376  geom, assignedVehicles, clv);
377 
378  NIVissimConnection::dictionary(id, connector);
379  }
380  // clear the element data
381  myElemData.clear();
382  isConnector = false;
383  //std::cout << "elemData len (clear):" << myElemData.size() << std::endl;
384  //std::cout.flush();
385 
386  }
388 }
389 
390 
391 // ---------------------------------------------------------------------------
392 // definitions of NIVissimXMLHandler_Zuflussdefinition-methods
393 // ---------------------------------------------------------------------------
397  "vissim - file") {
398 }
399 
401 
402 void
404  // finding an actual flow
405  if (element == VISSIM_TAG_VEHICLE_INPUT) {
406  //parse all flows
407  bool ok = true;
408  std::string id = attrs.get<std::string>(VISSIM_ATTR_NO, nullptr, ok);
409  std::string edgeid = attrs.get<std::string>(VISSIM_ATTR_LINK, nullptr, ok);
410  std::string name = attrs.get<std::string>(VISSIM_ATTR_NAME, nullptr, ok, false);
411 
413  name,
414  edgeid);
415  }
416 }
417 
418 // ---------------------------------------------------------------------------
419 // definitions of NIVissimXMLHandler_Parkplatzdefinition-methods
420 // ---------------------------------------------------------------------------
424  "vissim - file") {
425 }
426 
428 
429 void
431  // finding an actual parkinglot
432  if (element == VISSIM_TAG_PARKINGLOT) {
433  //parse all parkinglots
434  bool ok = true;
435  int id = attrs.get<int>(VISSIM_ATTR_NO, nullptr, ok);
436  int edgeid = attrs.get<int>(VISSIM_ATTR_INTLINK, nullptr, ok);
437  std::string name = attrs.get<std::string>(VISSIM_ATTR_NAME, nullptr, ok, false);
438  double position = attrs.get<double>(VISSIM_ATTR_POS, nullptr, ok);
439  std::vector<std::pair<int, int> > assignedVehicles; // (vclass, vwunsch)
440  //FIXME: vWunsch + Fahzeugklassen einlesen
441  // There can be s
442  std::vector<int> districts;
443  //FIXME: Parkplatzdefinition für mehrere Zonen implementieren
444  std::vector<double> percentages;
445  districts.push_back(attrs.get<int>(VISSIM_ATTR_DISTRICT, nullptr, ok));
446  percentages.push_back(attrs.get<double>(VISSIM_ATTR_PERCENTAGE, nullptr, ok));
447 
449  name,
450  districts,
451  percentages,
452  edgeid,
453  position,
454  assignedVehicles);
455  }
456 }
457 
458 
459 // ---------------------------------------------------------------------------
460 // definitions of NIVissimXMLHandler_Fahrzeugklassendefinition-methods
461 // ---------------------------------------------------------------------------
465  "vissim - file"),
466  myElemData(elemData),
467  myHierarchyLevel(0) {
468  myElemData.clear();
469 }
470 
472 
473 void
476 
477  if (element == VISSIM_TAG_VEHICLE_CLASS) {
478  bool ok = true;
479  myElemData["id"].push_back(attrs.get<std::string>(VISSIM_ATTR_NO, nullptr, ok));
480  myElemData["name"].push_back(attrs.get<std::string>(VISSIM_ATTR_NAME, nullptr, ok, false));
481  std::string colorStr(attrs.get<std::string>(VISSIM_ATTR_COLOR, nullptr, ok));
482  for (int pos = (int)colorStr.size() - 2; pos > 0; pos -= 2) {
483  colorStr.insert(pos, " ");
484  }
485  myElemData["color"].push_back(colorStr);
486  }
487  if (element == VISSIM_TAG_INTOBJECTREF) {
488  bool ok = true;
489  myElemData["types"].push_back(attrs.get<std::string>(VISSIM_ATTR_KEY, nullptr, ok));
490 
491 
492  }
493 }
494 
495 void
497  if (element == VISSIM_TAG_VEHICLE_CLASS && myHierarchyLevel == 3) {
498  RGBColor color;
499  std::istringstream iss(myElemData["color"].front());
500  std::vector<std::string> sCol_v(StringTokenizer(
501  myElemData["color"].front(), " ").getVector());
502  std::vector<int> myColorVector(sCol_v.size());
503  std::transform(sCol_v.begin(), sCol_v.end(), myColorVector.begin(), StringUtils::hexToInt);
504 
505  color = RGBColor((unsigned char)myColorVector[0],
506  (unsigned char)myColorVector[1],
507  (unsigned char)myColorVector[2],
508  (unsigned char)myColorVector[3]);
509  std::vector<int> types;
510  while (!myElemData["types"].empty()) {
511  types.push_back(StringUtils::toInt(myElemData["types"].front()));
512  myElemData["types"].pop_front();
513  }
514 
516  myElemData["name"].front(),
517  color,
518  types);
519  myElemData.clear();
520  }
522 }
523 
524 // ---------------------------------------------------------------------------
525 // definitions of NIVissimXMLHandler_Geschwindigkeitsverteilungsdefinition-methods
526 // ---------------------------------------------------------------------------
530  "vissim - file"),
531  myElemData(elemData),
532  myHierarchyLevel(0) {
533  myElemData.clear();
534 }
535 
537 
538 void
541  if (element == VISSIM_TAG_SPEED_DIST) {
542  bool ok = true;
543  myElemData["id"].push_back(attrs.get<std::string>(VISSIM_ATTR_NO, nullptr, ok));
544  }
545 
546  if (element == VISSIM_TAG_DATAPOINT) {
547  bool ok = true;
548  std::string sep(" ");
549  std::string posS(attrs.get<std::string>(VISSIM_ATTR_X, nullptr, ok));
550  posS += sep;
551  posS.append(attrs.get<std::string>(VISSIM_ATTR_FX, nullptr, ok));
552  myElemData["points"].push_back(posS);
553 
554  }
555 
556 }
557 
558 void
560  if (element == VISSIM_TAG_SPEED_DIST && myHierarchyLevel == 3) {
561  Distribution_Points* points = new Distribution_Points(myElemData["id"].front());
562  while (!myElemData["points"].empty()) {
563  std::vector<std::string> sPos_v(StringTokenizer(
564  myElemData["points"].front(), " ").getVector());
565  myElemData["points"].pop_front();
566  points->add(StringUtils::toDouble(sPos_v[0]), StringUtils::toDouble(sPos_v[1]));
567  }
568  DistributionCont::dictionary("speed", myElemData["id"].front(), points);
569  myElemData.clear();
570  }
572 }
573 
574 // ---------------------------------------------------------------------------
575 // definitions of NIVissimXMLHandler_VWunschentscheidungsdefinition-methods
576 // ---------------------------------------------------------------------------
580  "vissim - file"),
581  myElemData(elemData),
582  myHierarchyLevel(0) {
583  myElemData.clear();
584 }
585 
587 
588 void
591  if (element == VISSIM_TAG_SPEED_DECISION) {
592  bool ok = true;
593  myElemData["name"].push_back(attrs.get<std::string>(VISSIM_ATTR_NAME, nullptr, ok, false));
594  //FIXME: 2 vWunsch in the xml file, but only 1 of them is set???
595  }
596 
597 }
598 
599 void
602 }
603 
604 
605 // ---------------------------------------------------------------------------
606 // definitions of NIVissimXMLHandler_Routenentscheidungsdefinition-methods
607 // ---------------------------------------------------------------------------
611  "vissim - file"),
612  myElemData(elemData),
613  myHierarchyLevel(0) {
614  myElemData.clear();
615 }
616 
618 
619 void
622  if (element == VISSIM_TAG_DECISION_STATIC) {
623  bool ok = true;
624  myElemData["startLink"].push_back(attrs.get<std::string>(VISSIM_ATTR_LINK, nullptr, ok));
625  myElemData["startPos"].push_back(attrs.get<std::string>(VISSIM_ATTR_POS, nullptr, ok));
626  }
627  if (element == VISSIM_TAG_ROUTE_STATIC) {
628  bool ok = true;
629  myElemData["destLink"].push_back(attrs.get<std::string>(VISSIM_ATTR_DESTLINK, nullptr, ok));
630  myElemData["destPos"].push_back(attrs.get<std::string>(VISSIM_ATTR_DESTPOS, nullptr, ok));
631  myElemData["id"].push_back(attrs.get<std::string>(VISSIM_ATTR_NO, nullptr, ok));
632  }
633  if (element == VISSIM_TAG_INTOBJECTREF) {
634  // bool ok = true;
635  }
636 
637 }
638 
639 void
642 }
643 
644 // ---------------------------------------------------------------------------
645 // definitions of NIVissimXMLHandler_ConflictArea-methods
646 // ---------------------------------------------------------------------------
650  "vissim - file") {}
651 
653 
654 void
656  // finding an actual flow
657  if (element == VISSIM_TAG_CA) {
658  //parse all flows
659  bool ok = true;
660  std::string status = attrs.get<std::string>(VISSIM_ATTR_STATUS, nullptr, ok);
661  //get only the conflict areas which were set in VISSIM
662  if (status != "PASSIVE") {
663  NIVissimConflictArea::dictionary(attrs.get<int>(VISSIM_ATTR_NO, nullptr, ok),
664  attrs.get<std::string>(VISSIM_ATTR_LINK1, nullptr, ok),
665  attrs.get<std::string>(VISSIM_ATTR_LINK2, nullptr, ok),
666  status);
667  }
668 
669  }
670 }
671 
672 
673 /* -------------------------------------------------------------------------
674  * NIImporter_Vissim::VissimSingleTypeParser-methods
675  * ----------------------------------------------------------------------- */
677  : myVissimParent(parent) {}
678 
679 
681 
682 
683 std::string
685  std::string tmp;
686  from >> tmp;
687  return StringUtils::to_lower_case(tmp);
688 }
689 
690 
691 
692 std::string
694  const std::string& excl) {
695  std::string myExcl = StringUtils::to_lower_case(excl);
696  std::string tmp = myRead(from);
697  if (tmp == "") {
698  return "DATAEND";
699  }
700  if (tmp != myExcl
701  &&
702  (tmp.substr(0, 2) == "--" || !myVissimParent.admitContinue(tmp))
703  ) {
704  return "DATAEND";
705  }
706  return StringUtils::to_lower_case(tmp);
707 }
708 
709 
710 std::string
712  const std::vector<std::string>& excl) {
713  std::vector<std::string> myExcl;
714  std::vector<std::string>::const_iterator i;
715  for (i = excl.begin(); i != excl.end(); i++) {
716  std::string mes = StringUtils::to_lower_case(*i);
717  myExcl.push_back(mes);
718  }
719  std::string tmp = myRead(from);
720  if (tmp == "") {
721  return "DATAEND";
722  }
723 
724  bool equals = false;
725  for (i = myExcl.begin(); i != myExcl.end() && !equals; i++) {
726  if ((*i) == tmp) {
727  equals = true;
728  }
729  }
730  if (!equals
731  &&
732  (tmp.substr(0, 2) == "--" || !myVissimParent.admitContinue(tmp))
733  ) {
734  return "DATAEND";
735  }
736  return StringUtils::to_lower_case(tmp);
737 }
738 
739 
740 std::string
742  const std::string& tag) {
743  std::string tmp;
744  if (tag == "") {
745  tmp = myRead(from);
746  } else {
747  tmp = tag;
748  }
749  if (tmp == "beschriftung") {
750  tmp = myRead(from);
751  if (tmp == "keine") {
752  from >> tmp;
753  }
754  tmp = myRead(from);
755  tmp = myRead(from);
756  }
757  return tmp;
758 }
759 
760 
761 Position
763  double x, y;
764  from >> x; // type-checking is missing!
765  from >> y; // type-checking is missing!
766  return Position(x, y);
767 }
768 
769 
770 std::vector<int>
772  std::istream& from, const std::string& next) {
773  std::string tmp = readEndSecure(from);
774  std::vector<int> ret;
775  if (tmp == "alle") {
776  ret.push_back(-1);
777  return ret;
778  }
779  while (tmp != "DATAEND" && tmp != next) {
780  ret.push_back(StringUtils::toInt(tmp));
781  tmp = readEndSecure(from);
782  }
783  return ret;
784 }
785 
786 
789  std::istream& from) {
790  std::string tag;
791  from >> tag; // "Strecke"
792  int edgeid;
793  from >> edgeid; // type-checking is missing!
794  from >> tag; // "Spuren"
795  std::vector<int> lanes;
796  while (tag != "bei") {
797  tag = readEndSecure(from);
798  if (tag != "bei") {
799  int lane = StringUtils::toInt(tag);
800  lanes.push_back(lane - 1);
801  }
802  }
803  double position;
804  from >> position;
805  std::vector<int> dummy;
806  return NIVissimExtendedEdgePoint(edgeid, lanes, position, dummy);
807 }
808 
809 
810 std::string
812  std::string name;
813  from >> name;
814  if (name[0] == '"') {
815  while (name[name.length() - 1] != '"') {
816  std::string tmp;
817  from >> tmp;
818  name = name + " " + tmp;
819  }
820  name = name.substr(1, name.length() - 2);
821  }
822  return StringUtils::convertUmlaute(name);
823 }
824 
825 
826 void
828  const std::string& name) {
829  std::string tag;
830  while (tag != name) {
831  tag = myRead(from);
832  }
833 }
834 
835 bool
837  const std::string& name) {
838  std::string tag;
839  while (tag != name) {
840  tag = myRead(from);
841  }
842  while (tag != "DATAEND") {
843  tag = readEndSecure(from);
844  }
845  return true;
846 }
847 
848 
849 
850 /* -------------------------------------------------------------------------
851  * NIImporter_Vissim-methods
852  * ----------------------------------------------------------------------- */
854  : myNetBuilder(nb), myInputIsLegacyFormat(false) {
855  UNUSED_PARAMETER(file);
857  buildParsers();
858  myColorMap["blau"] = RGBColor(77, 77, 255, 255);
859  myColorMap["gelb"] = RGBColor::YELLOW;
860  myColorMap["grau"] = RGBColor::GREY;
861  myColorMap["lila"] = RGBColor::MAGENTA;
862  myColorMap["gruen"] = RGBColor::GREEN;
863  myColorMap["rot"] = RGBColor::RED;
864  myColorMap["schwarz"] = RGBColor::BLACK;
865  myColorMap["tuerkis"] = RGBColor::CYAN;
866  myColorMap["weiss"] = RGBColor::WHITE;
867  myColorMap["keine"] = RGBColor::WHITE;
868 }
869 
870 
871 
872 
892  for (ToParserMap::iterator i = myParsers.begin(); i != myParsers.end(); i++) {
893  delete(*i).second;
894  }
895 }
896 
897 
898 void
900  // load file contents
901  // try to open the file
902  std::ifstream strm(options.getString("vissim-file").c_str());
903  if (!strm.good()) {
904  WRITE_ERROR("The vissim-file '" + options.getString("vissim-file") + "' was not found.");
905  return;
906  }
907  if (!readContents(strm)) {
908  return;
909  }
910  postLoadBuild(options.getFloat("vissim.join-distance"));
911 }
912 
913 void
915  // Parse file
916  std::string file = options.getString("vissim-file");
917  // Create NIVissimXMLHandlers
918  NIVissimXMLHandler_Streckendefinition XMLHandler_Streckendefinition(elementData);
919  NIVissimXMLHandler_Zuflussdefinition XMLHandler_Zuflussdefinition;
920  //NIVissimXMLHandler_Parkplatzdefinition XMLHandler_Parkplatzdefinition;
921  NIVissimXMLHandler_Fahrzeugklassendefinition XMLHandler_Fahrzeugklassendefinition(elementData);
922  NIVissimXMLHandler_Geschwindigkeitsverteilungsdefinition XMLHandler_Geschwindigkeitsverteilung(elementData);
923  NIVissimXMLHandler_ConflictArea XMLHandler_ConflictAreas;
924  if (!FileHelpers::isReadable(file)) {
925  WRITE_ERROR("Could not open vissim-file '" + file + "'.");
926  return;
927  }
928 
929  // Strecken + Verbinder
930  XMLHandler_Streckendefinition.setFileName(file);
931  PROGRESS_BEGIN_MESSAGE("Parsing strecken+verbinder from vissim-file '" + file + "'");
932  if (!XMLSubSys::runParser(XMLHandler_Streckendefinition, file)) {
933  return;
934  }
936 
937  // Zuflüsse
938  XMLHandler_Zuflussdefinition.setFileName(file);
939  PROGRESS_BEGIN_MESSAGE("Parsing zuflüsse from vissim-file '" + file + "'");
940  if (!XMLSubSys::runParser(XMLHandler_Zuflussdefinition, file)) {
941  return;
942  }
944 
945  //Geschwindigkeitsverteilungen
946  XMLHandler_Geschwindigkeitsverteilung.setFileName(file);
947  PROGRESS_BEGIN_MESSAGE("Parsing parkplätze from vissim-file '" + file + "'");
948  if (!XMLSubSys::runParser(XMLHandler_Geschwindigkeitsverteilung, file)) {
949  return;
950  }
952 
953 
954  //Fahrzeugklassen
955  XMLHandler_Fahrzeugklassendefinition.setFileName(file);
956  PROGRESS_BEGIN_MESSAGE("Parsing parkplätze from vissim-file '" + file + "'");
957  if (!XMLSubSys::runParser(XMLHandler_Fahrzeugklassendefinition, file)) {
958  return;
959  }
961 
962  //Parkplätze
963  /*XMLHandler_Parkplatzdefinition.setFileName(file);
964  PROGRESS_BEGIN_MESSAGE("Parsing parkplätze from vissim-file '" + file + "'");
965  if (!XMLSubSys::runParser(XMLHandler_Parkplatzdefinition, file)) {
966  return;
967  }
968  PROGRESS_DONE_MESSAGE();*/
969 
970 
971  //Konfliktflächen
972  XMLHandler_ConflictAreas.setFileName(file);
973  PROGRESS_BEGIN_MESSAGE("Parsing conflict areas from vissim-file '" + file + "'");
974  if (!XMLSubSys::runParser(XMLHandler_ConflictAreas, file)) {
975  return;
976  }
978 
979  postLoadBuild(options.getFloat("vissim.join-distance"));
980 }
981 
982 bool
983 NIImporter_Vissim::admitContinue(const std::string& tag) {
984  ToElemIDMap::const_iterator i = myKnownElements.find(tag);
985  if (i == myKnownElements.end()) {
986  return true;
987  }
988  myLastSecure = tag;
989  return false;
990 }
991 
992 
993 bool
994 NIImporter_Vissim::readContents(std::istream& strm) {
995  // read contents
996  bool ok = true;
997  while (strm.good() && ok) {
998  std::string tag;
999  if (myLastSecure != "") {
1000  tag = myLastSecure;
1001  } else {
1002  strm >> tag;
1003  }
1004  myLastSecure = "";
1005  bool parsed = false;
1006  while (!parsed && strm.good() && ok) {
1007  ToElemIDMap::iterator i = myKnownElements.find(StringUtils::to_lower_case(tag));
1008  if (i != myKnownElements.end()) {
1009  ToParserMap::iterator j = myParsers.find((*i).second);
1010  if (j != myParsers.end()) {
1011  VissimSingleTypeParser* parser = (*j).second;
1012  ok = parser->parse(strm);
1013  parsed = true;
1014  }
1015  }
1016  if (!parsed) {
1017  std::string line;
1018  std::streamoff pos;
1019  do {
1020  pos = strm.tellg();
1021  getline(strm, line);
1022  } while (strm.good() && (line == "" || line[0] == ' ' || line[0] == '-'));
1023  if (!strm.good()) {
1024  return true;
1025  }
1026  strm.seekg(pos);
1027  strm >> tag;
1028  }
1029  }
1030  }
1031  return ok;
1032 }
1033 
1034 
1035 void
1037  // close the loading process
1041  // build district->connections map
1043  // build clusters around nodes
1044 // NIVissimNodeDef::buildNodeClusters();
1045  // build node clusters around traffic lights
1046 // NIVissimTL::buildNodeClusters();
1047 
1048  // when connections or disturbances are left, build nodes around them
1049 
1050  // try to assign connection clusters to nodes
1051  // only left connections will be processed in
1052  // buildConnectionClusters & join
1053 //30.4. brauchen wir noch! NIVissimNodeDef::dict_assignConnectionsToNodes();
1054 
1055  // build clusters of connections with the same direction and a similar position along the streets
1057  // check whether further nodes (connection clusters by now) must be added
1059 
1060  // join clusters when overlapping (different streets are possible)
1063 // NIVissimConnectionCluster::joinByDisturbances(offset);
1064 
1065 // NIVissimConnectionCluster::addTLs(offset);
1066 
1067  // build nodes from clusters
1070 
1071 // NIVissimNodeCluster::dict_recheckEdgeChanges();
1077  if (OptionsCont::getOptions().getBool("vissim.report-unset-speeds")) {
1079  }
1085 }
1086 
1087 
1088 void
1090  myKnownElements["kennung"] = VE_Kennungszeile;
1091  myKnownElements["zufallszahl"] = VE_Startzufallszahl;
1092  myKnownElements["simulationsdauer"] = VE_Simdauer;
1093  myKnownElements["startuhrzeit"] = VE_Startuhrzeit;
1094  myKnownElements["simulationsrate"] = VE_SimRate;
1095  myKnownElements["zeitschritt"] = VE_Zeitschrittfaktor;
1096  myKnownElements["linksverkehr"] = VE_Linksverkehr;
1097  myKnownElements["dynuml"] = VE_DynUml;
1099  myKnownElements["gelbverhalten"] = VE_Gelbverhaltendefinition;
1101  myKnownElements["verbindung"] = VE_Verbindungsdefinition;
1102  myKnownElements["richtungsentscheidung"] = VE_Richtungsentscheidungsdefinition;
1103  myKnownElements["routenentscheidung"] = VE_Routenentscheidungsdefinition;
1104  myKnownElements["vwunschentscheidung"] = VE_VWunschentscheidungsdefinition;
1105  myKnownElements["langsamfahrbereich"] = VE_Langsamfahrbereichdefinition;
1107  myKnownElements["fahrzeugtyp"] = VE_Fahrzeugtypdefinition;
1108  myKnownElements["fahrzeugklasse"] = VE_Fahrzeugklassendefinition;
1118  myKnownElements["wunschbeschleunigung"] = VE_Wunschbeschleunigungskurvedefinition;
1121  myKnownElements["querverkehrsstoerung"] = VE_Querverkehrsstoerungsdefinition;
1123  myKnownElements["signalgruppe"] = VE_Signalgruppendefinition;
1124  myKnownElements["signalgeber"] = VE_Signalgeberdefinition;
1125  myKnownElements["lsakopplung"] = VE_LSAKopplungdefinition;
1127  myKnownElements["haltestelle"] = VE_Haltestellendefinition;
1129  myKnownElements["stopschild"] = VE_Stopschilddefinition;
1133  myKnownElements["querschnittsmessung"] = VE_Querschnittsmessungsdefinition;
1134  myKnownElements["stauzaehler"] = VE_Stauzaehlerdefinition;
1135  myKnownElements["auswertung"] = VE_Auswertungsdefinition;
1138  myKnownElements["parkplatz"] = VE_Parkplatzdefinition;
1141  myKnownElements["netzobjekt"] = VE_Netzobjektdefinition;
1142  myKnownElements["richtungspfeil"] = VE_Richtungspfeildefinition;
1144  myKnownElements["fahrverhalten"] = VE_Fahrverhaltendefinition;
1145  myKnownElements["fahrtverlaufdateien"] = VE_Fahrtverlaufdateien;
1146  myKnownElements["emission"] = VE_Emission;
1148  myKnownElements["streckentyp"] = VE_Streckentypdefinition;
1149  myKnownElements["kantensperrung"] = VE_Kantensperrung;
1151 
1152 
1153  myKnownElements["advance"] = VE_DUMMY;
1154  myKnownElements["temperatur"] = VE_DUMMY;
1155 
1156 }
1157 
1158 
1159 
1160 void
1166  myParsers[VE_DynUml] =
1240 
1283 
1284 }
1285 
1286 
1287 
1288 /****************************************************************************/
1289 
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:47
NIVissimXMLHandler_Streckendefinition(nodeMap &elemData)
Constructor.
static const RGBColor WHITE
Definition: RGBColor.h:191
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 occurred.
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:192
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:113
void myEndElement(int element)
Callback method for a closing tag to implement by derived classes.
#define UNUSED_PARAMETER(x)
Definition: StdDefs.h:33
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:58
A temporary storage for edges imported from Vissim.
Definition: NIVissimEdge.h:53
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:185
static const RGBColor GREY
Definition: RGBColor.h:193
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 double toDouble(const std::string &sData)
converts a string into the double value described by it by calling the char-type converter ...
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:39
NBEdgeCont & getEdgeCont()
Definition: NBNetBuilder.h:150
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 bool dict_SetSignals(NBTrafficLightLogicCont &tlc, NBEdgeCont &ec)
Definition: NIVissimTL.cpp:366
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:189
#define PROGRESS_BEGIN_MESSAGE(msg)
Definition: MsgHandler.h:243
Position getPosition(std::istream &from)
returns the 2d-position saved as next within the stream
static int toInt(const std::string &sData)
converts a string into the integer value described by it by calling the char-type converter...
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:86
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:247
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:58
static const RGBColor YELLOW
Definition: RGBColor.h:187
static const RGBColor RED
named colors
Definition: RGBColor.h:184
double length() const
Returns the length.
static const RGBColor CYAN
Definition: RGBColor.h:188
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:155
void myStartElement(int element, const SUMOSAXAttributes &attrs)
Called on the opening of a tag;.
Instance responsible for building networks.
Definition: NBNetBuilder.h:109
A storage for options typed value containers)
Definition: OptionsCont.h:92
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:165
static void buildNBNodes(NBNodeCont &nc)
static void clearDict()
Definition: NIVissimTL.cpp:354
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:244
std::string myLastSecure
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:170
static int hexToInt(const std::string &sData)
converts a string with a hex value into the integer value described by it by calling the char-type co...
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.