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, 0, ok);
239  myLastNodeID = id;
240 
241  // !!! assuming empty myElemData
242  myElemData["id"].push_back(attrs.get<std::string>(VISSIM_ATTR_NO, 0, ok));
243  // error ignored if name is empty
244  myElemData["name"].push_back(attrs.get<std::string>(VISSIM_ATTR_NAME, 0, ok, false));
245  myElemData["type"].push_back(attrs.get<std::string>(VISSIM_ATTR_LINKBEHAVETYPE, 0, ok));
246  myElemData["zuschlag1"].push_back(attrs.get<std::string>(VISSIM_ATTR_ZUSCHLAG1, 0, ok));
247  myElemData["zuschlag2"].push_back(attrs.get<std::string>(VISSIM_ATTR_ZUSCHLAG2, 0, 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, 0, 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, 0, ok), " ").getVector());
264  myElemData["from_pos"].push_back(attrs.get<std::string>(VISSIM_ATTR_POS, 0, 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, 0, ok), " ").getVector());
273  myElemData["to_pos"].push_back(attrs.get<std::string>(VISSIM_ATTR_POS, 0, 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, 0, ok));
284  posS += sep;
285  posS.append(attrs.get<std::string>(VISSIM_ATTR_Y, 0, ok));
286  // allow for no Z
287  std::string z(attrs.get<std::string>(VISSIM_ATTR_ZOFFSET, 0, 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(TplConvert::_str2int(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  TplConvert::_str2double(myElemData["zuschlag1"].front()),
330  TplConvert::_str2double(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] = TplConvert::_str2int(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  TplConvert::_str2int(myElemData["from_id"].front()),
354  laneVec,
355  TplConvert::_str2double(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] = TplConvert::_str2int(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  TplConvert::_str2int(myElemData["to_id"].front()),
368  laneVec,
369  TplConvert::_str2double(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, 0, ok);
409  std::string edgeid = attrs.get<std::string>(VISSIM_ATTR_LINK, 0, ok);
410  std::string name = attrs.get<std::string>(VISSIM_ATTR_NAME, 0, 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, 0, ok);
436  int edgeid = attrs.get<int>(VISSIM_ATTR_INTLINK, 0, ok);
437  std::string name = attrs.get<std::string>(VISSIM_ATTR_NAME, 0, ok, false);
438  double position = attrs.get<double>(VISSIM_ATTR_POS, 0, 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, 0, ok));
446  percentages.push_back(attrs.get<double>(VISSIM_ATTR_PERCENTAGE, 0, 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, 0, ok));
480  myElemData["name"].push_back(attrs.get<std::string>(VISSIM_ATTR_NAME, 0, ok, false));
481  std::string colorStr(attrs.get<std::string>(VISSIM_ATTR_COLOR, 0, 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, 0, 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(),
505 
506  color = RGBColor((unsigned char)myColorVector[0],
507  (unsigned char)myColorVector[1],
508  (unsigned char)myColorVector[2],
509  (unsigned char)myColorVector[3]);
510  std::vector<int> types;
511  while (!myElemData["types"].empty()) {
512  types.push_back(TplConvert::_str2int(myElemData["types"].front()));
513  myElemData["types"].pop_front();
514  }
515 
517  myElemData["name"].front(),
518  color,
519  types);
520  myElemData.clear();
521  }
523 }
524 
525 // ---------------------------------------------------------------------------
526 // definitions of NIVissimXMLHandler_Geschwindigkeitsverteilungsdefinition-methods
527 // ---------------------------------------------------------------------------
531  "vissim - file"),
532  myElemData(elemData),
533  myHierarchyLevel(0) {
534  myElemData.clear();
535 }
536 
538 
539 void
542  if (element == VISSIM_TAG_SPEED_DIST) {
543  bool ok = true;
544  myElemData["id"].push_back(attrs.get<std::string>(VISSIM_ATTR_NO, 0, ok));
545  }
546 
547  if (element == VISSIM_TAG_DATAPOINT) {
548  bool ok = true;
549  std::string sep(" ");
550  std::string posS(attrs.get<std::string>(VISSIM_ATTR_X, 0, ok));
551  posS += sep;
552  posS.append(attrs.get<std::string>(VISSIM_ATTR_FX, 0, ok));
553  myElemData["points"].push_back(posS);
554 
555  }
556 
557 }
558 
559 void
561  if (element == VISSIM_TAG_SPEED_DIST && myHierarchyLevel == 3) {
562  Distribution_Points* points = new Distribution_Points(myElemData["id"].front());
563  while (!myElemData["points"].empty()) {
564  std::vector<std::string> sPos_v(StringTokenizer(
565  myElemData["points"].front(), " ").getVector());
566  myElemData["points"].pop_front();
567  points->add(TplConvert::_str2double(sPos_v[0]), TplConvert::_str2double(sPos_v[1]));
568  }
569  DistributionCont::dictionary("speed", myElemData["id"].front(), points);
570  myElemData.clear();
571  }
573 }
574 
575 // ---------------------------------------------------------------------------
576 // definitions of NIVissimXMLHandler_VWunschentscheidungsdefinition-methods
577 // ---------------------------------------------------------------------------
581  "vissim - file"),
582  myElemData(elemData),
583  myHierarchyLevel(0) {
584  myElemData.clear();
585 }
586 
588 
589 void
592  if (element == VISSIM_TAG_SPEED_DECISION) {
593  bool ok = true;
594  myElemData["name"].push_back(attrs.get<std::string>(VISSIM_ATTR_NAME, 0, ok, false));
595  //FIXME: 2 vWunsch in the xml file, but only 1 of them is set???
596  }
597 
598 }
599 
600 void
603 }
604 
605 
606 // ---------------------------------------------------------------------------
607 // definitions of NIVissimXMLHandler_Routenentscheidungsdefinition-methods
608 // ---------------------------------------------------------------------------
612  "vissim - file"),
613  myElemData(elemData),
614  myHierarchyLevel(0) {
615  myElemData.clear();
616 }
617 
619 
620 void
623  if (element == VISSIM_TAG_DECISION_STATIC) {
624  bool ok = true;
625  myElemData["startLink"].push_back(attrs.get<std::string>(VISSIM_ATTR_LINK, 0, ok));
626  myElemData["startPos"].push_back(attrs.get<std::string>(VISSIM_ATTR_POS, 0, ok));
627  }
628  if (element == VISSIM_TAG_ROUTE_STATIC) {
629  bool ok = true;
630  myElemData["destLink"].push_back(attrs.get<std::string>(VISSIM_ATTR_DESTLINK, 0, ok));
631  myElemData["destPos"].push_back(attrs.get<std::string>(VISSIM_ATTR_DESTPOS, 0, ok));
632  myElemData["id"].push_back(attrs.get<std::string>(VISSIM_ATTR_NO, 0, ok));
633  }
634  if (element == VISSIM_TAG_INTOBJECTREF) {
635  // bool ok = true;
636  }
637 
638 }
639 
640 void
643 }
644 
645 // ---------------------------------------------------------------------------
646 // definitions of NIVissimXMLHandler_ConflictArea-methods
647 // ---------------------------------------------------------------------------
651  "vissim - file") {}
652 
654 
655 void
657  // finding an actual flow
658  if (element == VISSIM_TAG_CA) {
659  //parse all flows
660  bool ok = true;
661  std::string status = attrs.get<std::string>(VISSIM_ATTR_STATUS, 0, ok);
662  //get only the conflict areas which were set in VISSIM
663  if (status != "PASSIVE") {
665  attrs.get<std::string>(VISSIM_ATTR_LINK1, 0, ok),
666  attrs.get<std::string>(VISSIM_ATTR_LINK2, 0, ok),
667  status);
668  }
669 
670  }
671 }
672 
673 
674 /* -------------------------------------------------------------------------
675  * NIImporter_Vissim::VissimSingleTypeParser-methods
676  * ----------------------------------------------------------------------- */
678  : myVissimParent(parent) {}
679 
680 
682 
683 
684 std::string
686  std::string tmp;
687  from >> tmp;
688  return StringUtils::to_lower_case(tmp);
689 }
690 
691 
692 
693 std::string
695  const std::string& excl) {
696  std::string myExcl = StringUtils::to_lower_case(excl);
697  std::string tmp = myRead(from);
698  if (tmp == "") {
699  return "DATAEND";
700  }
701  if (tmp != myExcl
702  &&
703  (tmp.substr(0, 2) == "--" || !myVissimParent.admitContinue(tmp))
704  ) {
705  return "DATAEND";
706  }
707  return StringUtils::to_lower_case(tmp);
708 }
709 
710 
711 std::string
713  const std::vector<std::string>& excl) {
714  std::vector<std::string> myExcl;
715  std::vector<std::string>::const_iterator i;
716  for (i = excl.begin(); i != excl.end(); i++) {
717  std::string mes = StringUtils::to_lower_case(*i);
718  myExcl.push_back(mes);
719  }
720  std::string tmp = myRead(from);
721  if (tmp == "") {
722  return "DATAEND";
723  }
724 
725  bool equals = false;
726  for (i = myExcl.begin(); i != myExcl.end() && !equals; i++) {
727  if ((*i) == tmp) {
728  equals = true;
729  }
730  }
731  if (!equals
732  &&
733  (tmp.substr(0, 2) == "--" || !myVissimParent.admitContinue(tmp))
734  ) {
735  return "DATAEND";
736  }
737  return StringUtils::to_lower_case(tmp);
738 }
739 
740 
741 std::string
743  const std::string& tag) {
744  std::string tmp;
745  if (tag == "") {
746  tmp = myRead(from);
747  } else {
748  tmp = tag;
749  }
750  if (tmp == "beschriftung") {
751  tmp = myRead(from);
752  if (tmp == "keine") {
753  from >> tmp;
754  }
755  tmp = myRead(from);
756  tmp = myRead(from);
757  }
758  return tmp;
759 }
760 
761 
762 Position
764  double x, y;
765  from >> x; // type-checking is missing!
766  from >> y; // type-checking is missing!
767  return Position(x, y);
768 }
769 
770 
771 std::vector<int>
773  std::istream& from, const std::string& next) {
774  std::string tmp = readEndSecure(from);
775  std::vector<int> ret;
776  if (tmp == "alle") {
777  ret.push_back(-1);
778  return ret;
779  }
780  while (tmp != "DATAEND" && tmp != next) {
781  ret.push_back(TplConvert::_2int(tmp.c_str()));
782  tmp = readEndSecure(from);
783  }
784  return ret;
785 }
786 
787 
790  std::istream& from) {
791  std::string tag;
792  from >> tag; // "Strecke"
793  int edgeid;
794  from >> edgeid; // type-checking is missing!
795  from >> tag; // "Spuren"
796  std::vector<int> lanes;
797  while (tag != "bei") {
798  tag = readEndSecure(from);
799  if (tag != "bei") {
800  int lane = TplConvert::_2int(tag.c_str());
801  lanes.push_back(lane - 1);
802  }
803  }
804  double position;
805  from >> position;
806  std::vector<int> dummy;
807  return NIVissimExtendedEdgePoint(edgeid, lanes, position, dummy);
808 }
809 
810 
811 std::string
813  std::string name;
814  from >> name;
815  if (name[0] == '"') {
816  while (name[name.length() - 1] != '"') {
817  std::string tmp;
818  from >> tmp;
819  name = name + " " + tmp;
820  }
821  name = name.substr(1, name.length() - 2);
822  }
823  return StringUtils::convertUmlaute(name);
824 }
825 
826 
827 void
829  const std::string& name) {
830  std::string tag;
831  while (tag != name) {
832  tag = myRead(from);
833  }
834 }
835 
836 bool
838  const std::string& name) {
839  std::string tag;
840  while (tag != name) {
841  tag = myRead(from);
842  }
843  while (tag != "DATAEND") {
844  tag = readEndSecure(from);
845  }
846  return true;
847 }
848 
849 
850 
851 /* -------------------------------------------------------------------------
852  * NIImporter_Vissim-methods
853  * ----------------------------------------------------------------------- */
855  : myNetBuilder(nb), myInputIsLegacyFormat(false) {
856  UNUSED_PARAMETER(file);
858  buildParsers();
859  myColorMap["blau"] = RGBColor(77, 77, 255, 255);
860  myColorMap["gelb"] = RGBColor::YELLOW;
861  myColorMap["grau"] = RGBColor::GREY;
862  myColorMap["lila"] = RGBColor::MAGENTA;
863  myColorMap["gruen"] = RGBColor::GREEN;
864  myColorMap["rot"] = RGBColor::RED;
865  myColorMap["schwarz"] = RGBColor::BLACK;
866  myColorMap["tuerkis"] = RGBColor::CYAN;
867  myColorMap["weiss"] = RGBColor::WHITE;
868  myColorMap["keine"] = RGBColor::WHITE;
869 }
870 
871 
872 
873 
893  for (ToParserMap::iterator i = myParsers.begin(); i != myParsers.end(); i++) {
894  delete(*i).second;
895  }
896 }
897 
898 
899 void
901  // load file contents
902  // try to open the file
903  std::ifstream strm(options.getString("vissim-file").c_str());
904  if (!strm.good()) {
905  WRITE_ERROR("The vissim-file '" + options.getString("vissim-file") + "' was not found.");
906  return;
907  }
908  if (!readContents(strm)) {
909  return;
910  }
911  postLoadBuild(options.getFloat("vissim.join-distance"));
912 }
913 
914 void
916  // Parse file
917  std::string file = options.getString("vissim-file");
918  // Create NIVissimXMLHandlers
919  NIVissimXMLHandler_Streckendefinition XMLHandler_Streckendefinition(elementData);
920  NIVissimXMLHandler_Zuflussdefinition XMLHandler_Zuflussdefinition;
921  //NIVissimXMLHandler_Parkplatzdefinition XMLHandler_Parkplatzdefinition;
922  NIVissimXMLHandler_Fahrzeugklassendefinition XMLHandler_Fahrzeugklassendefinition(elementData);
923  NIVissimXMLHandler_Geschwindigkeitsverteilungsdefinition XMLHandler_Geschwindigkeitsverteilung(elementData);
924  NIVissimXMLHandler_ConflictArea XMLHandler_ConflictAreas;
925  if (!FileHelpers::isReadable(file)) {
926  WRITE_ERROR("Could not open vissim-file '" + file + "'.");
927  return;
928  }
929 
930  // Strecken + Verbinder
931  XMLHandler_Streckendefinition.setFileName(file);
932  PROGRESS_BEGIN_MESSAGE("Parsing strecken+verbinder from vissim-file '" + file + "'");
933  if (!XMLSubSys::runParser(XMLHandler_Streckendefinition, file)) {
934  return;
935  }
937 
938  // Zuflüsse
939  XMLHandler_Zuflussdefinition.setFileName(file);
940  PROGRESS_BEGIN_MESSAGE("Parsing zuflüsse from vissim-file '" + file + "'");
941  if (!XMLSubSys::runParser(XMLHandler_Zuflussdefinition, file)) {
942  return;
943  }
945 
946  //Geschwindigkeitsverteilungen
947  XMLHandler_Geschwindigkeitsverteilung.setFileName(file);
948  PROGRESS_BEGIN_MESSAGE("Parsing parkplätze from vissim-file '" + file + "'");
949  if (!XMLSubSys::runParser(XMLHandler_Geschwindigkeitsverteilung, file)) {
950  return;
951  }
953 
954 
955  //Fahrzeugklassen
956  XMLHandler_Fahrzeugklassendefinition.setFileName(file);
957  PROGRESS_BEGIN_MESSAGE("Parsing parkplätze from vissim-file '" + file + "'");
958  if (!XMLSubSys::runParser(XMLHandler_Fahrzeugklassendefinition, file)) {
959  return;
960  }
962 
963  //Parkplätze
964  /*XMLHandler_Parkplatzdefinition.setFileName(file);
965  PROGRESS_BEGIN_MESSAGE("Parsing parkplätze from vissim-file '" + file + "'");
966  if (!XMLSubSys::runParser(XMLHandler_Parkplatzdefinition, file)) {
967  return;
968  }
969  PROGRESS_DONE_MESSAGE();*/
970 
971 
972  //Konfliktflächen
973  XMLHandler_ConflictAreas.setFileName(file);
974  PROGRESS_BEGIN_MESSAGE("Parsing conflict areas from vissim-file '" + file + "'");
975  if (!XMLSubSys::runParser(XMLHandler_ConflictAreas, file)) {
976  return;
977  }
979 
980  postLoadBuild(options.getFloat("vissim.join-distance"));
981 }
982 
983 bool
984 NIImporter_Vissim::admitContinue(const std::string& tag) {
985  ToElemIDMap::const_iterator i = myKnownElements.find(tag);
986  if (i == myKnownElements.end()) {
987  return true;
988  }
989  myLastSecure = tag;
990  return false;
991 }
992 
993 
994 bool
995 NIImporter_Vissim::readContents(std::istream& strm) {
996  // read contents
997  bool ok = true;
998  while (strm.good() && ok) {
999  std::string tag;
1000  if (myLastSecure != "") {
1001  tag = myLastSecure;
1002  } else {
1003  strm >> tag;
1004  }
1005  myLastSecure = "";
1006  bool parsed = false;
1007  while (!parsed && strm.good() && ok) {
1008  ToElemIDMap::iterator i = myKnownElements.find(StringUtils::to_lower_case(tag));
1009  if (i != myKnownElements.end()) {
1010  ToParserMap::iterator j = myParsers.find((*i).second);
1011  if (j != myParsers.end()) {
1012  VissimSingleTypeParser* parser = (*j).second;
1013  ok = parser->parse(strm);
1014  parsed = true;
1015  }
1016  }
1017  if (!parsed) {
1018  std::string line;
1019  std::streamoff pos;
1020  do {
1021  pos = strm.tellg();
1022  getline(strm, line);
1023  } while (strm.good() && (line == "" || line[0] == ' ' || line[0] == '-'));
1024  if (!strm.good()) {
1025  return true;
1026  }
1027  strm.seekg(pos);
1028  strm >> tag;
1029  }
1030  }
1031  }
1032  return ok;
1033 }
1034 
1035 
1036 void
1038  // close the loading process
1042  // build district->connections map
1044  // build clusters around nodes
1045 // NIVissimNodeDef::buildNodeClusters();
1046  // build node clusters around traffic lights
1047 // NIVissimTL::buildNodeClusters();
1048 
1049  // when connections or disturbances are left, build nodes around them
1050 
1051  // try to assign connection clusters to nodes
1052  // only left connections will be processed in
1053  // buildConnectionClusters & join
1054 //30.4. brauchen wir noch! NIVissimNodeDef::dict_assignConnectionsToNodes();
1055 
1056  // build clusters of connections with the same direction and a similar position along the streets
1058  // check whether further nodes (connection clusters by now) must be added
1060 
1061  // join clusters when overlapping (different streets are possible)
1064 // NIVissimConnectionCluster::joinByDisturbances(offset);
1065 
1066 // NIVissimConnectionCluster::addTLs(offset);
1067 
1068  // build nodes from clusters
1071 
1072 // NIVissimNodeCluster::dict_recheckEdgeChanges();
1078  if (OptionsCont::getOptions().getBool("vissim.report-unset-speeds")) {
1080  }
1086 }
1087 
1088 
1089 void
1091  myKnownElements["kennung"] = VE_Kennungszeile;
1092  myKnownElements["zufallszahl"] = VE_Startzufallszahl;
1093  myKnownElements["simulationsdauer"] = VE_Simdauer;
1094  myKnownElements["startuhrzeit"] = VE_Startuhrzeit;
1095  myKnownElements["simulationsrate"] = VE_SimRate;
1096  myKnownElements["zeitschritt"] = VE_Zeitschrittfaktor;
1097  myKnownElements["linksverkehr"] = VE_Linksverkehr;
1098  myKnownElements["dynuml"] = VE_DynUml;
1100  myKnownElements["gelbverhalten"] = VE_Gelbverhaltendefinition;
1102  myKnownElements["verbindung"] = VE_Verbindungsdefinition;
1103  myKnownElements["richtungsentscheidung"] = VE_Richtungsentscheidungsdefinition;
1104  myKnownElements["routenentscheidung"] = VE_Routenentscheidungsdefinition;
1105  myKnownElements["vwunschentscheidung"] = VE_VWunschentscheidungsdefinition;
1106  myKnownElements["langsamfahrbereich"] = VE_Langsamfahrbereichdefinition;
1108  myKnownElements["fahrzeugtyp"] = VE_Fahrzeugtypdefinition;
1109  myKnownElements["fahrzeugklasse"] = VE_Fahrzeugklassendefinition;
1119  myKnownElements["wunschbeschleunigung"] = VE_Wunschbeschleunigungskurvedefinition;
1122  myKnownElements["querverkehrsstoerung"] = VE_Querverkehrsstoerungsdefinition;
1124  myKnownElements["signalgruppe"] = VE_Signalgruppendefinition;
1125  myKnownElements["signalgeber"] = VE_Signalgeberdefinition;
1126  myKnownElements["lsakopplung"] = VE_LSAKopplungdefinition;
1128  myKnownElements["haltestelle"] = VE_Haltestellendefinition;
1130  myKnownElements["stopschild"] = VE_Stopschilddefinition;
1134  myKnownElements["querschnittsmessung"] = VE_Querschnittsmessungsdefinition;
1135  myKnownElements["stauzaehler"] = VE_Stauzaehlerdefinition;
1136  myKnownElements["auswertung"] = VE_Auswertungsdefinition;
1139  myKnownElements["parkplatz"] = VE_Parkplatzdefinition;
1142  myKnownElements["netzobjekt"] = VE_Netzobjektdefinition;
1143  myKnownElements["richtungspfeil"] = VE_Richtungspfeildefinition;
1145  myKnownElements["fahrverhalten"] = VE_Fahrverhaltendefinition;
1146  myKnownElements["fahrtverlaufdateien"] = VE_Fahrtverlaufdateien;
1147  myKnownElements["emission"] = VE_Emission;
1149  myKnownElements["streckentyp"] = VE_Streckentypdefinition;
1150  myKnownElements["kantensperrung"] = VE_Kantensperrung;
1152 
1153 
1154  myKnownElements["advance"] = VE_DUMMY;
1155  myKnownElements["temperatur"] = VE_DUMMY;
1156 
1157 }
1158 
1159 
1160 
1161 void
1167  myParsers[VE_DynUml] =
1241 
1284 
1285 }
1286 
1287 
1288 
1289 /****************************************************************************/
1290 
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:179
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:180
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
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:357
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:173
static const RGBColor GREY
Definition: RGBColor.h:181
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: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 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:161
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:177
#define PROGRESS_BEGIN_MESSAGE(msg)
Definition: MsgHandler.h:244
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:84
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:248
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:56
static const RGBColor YELLOW
Definition: RGBColor.h:175
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
named colors
Definition: RGBColor.h:172
double length() const
Returns the length.
static const RGBColor CYAN
Definition: RGBColor.h:176
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:245
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:182
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
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.