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-2017 German Aerospace Center (DLR) and others.
4 /****************************************************************************/
5 //
6 // This program and the accompanying materials
7 // are made available under the terms of the Eclipse Public License v2.0
8 // which accompanies this distribution, and is available at
9 // http://www.eclipse.org/legal/epl-v20.html
10 //
11 /****************************************************************************/
21 // -------------------
22 /****************************************************************************/
23 
24 
25 // ===========================================================================
26 // included modules
27 // ===========================================================================
28 #ifdef _MSC_VER
29 #include <windows_config.h>
30 #else
31 #include <config.h>
32 #endif
33 
34 
35 #include <string>
36 #include <fstream>
41 #include <netbuild/NBNetBuilder.h>
42 #include "NIImporter_Vissim.h"
98 
99 
100 #include "tempstructs/NIVissimTL.h"
113 
115 #include <utils/xml/XMLSubSys.h>
120 
121 #include <netbuild/NBEdgeCont.h> // !!! only for debugging purposes
122 
123 
124 // ===========================================================================
125 // static variables
126 // ===========================================================================
135  { "fromLinkEndPt", NIImporter_Vissim::VISSIM_TAG_FROM },
136  { "toLinkEndPt", NIImporter_Vissim::VISSIM_TAG_TO },
140  { "intObjectRef", NIImporter_Vissim::VISSIM_TAG_INTOBJECTREF },
141  { "desSpeedDecision", NIImporter_Vissim::VISSIM_TAG_SPEED_DECISION },
142  {
143  "desSpeedDistribution",
145  },
146  {
147  "speedDistributionDataPoint",
149  },
150  {
151  "vehicleRoutingDecisionStatic",
153  },
154  {
155  "vehicleRouteStatic",
157  },
158  { "conflictArea", NIImporter_Vissim::VISSIM_TAG_CA },
160 };
161 
162 
164  { "no", NIImporter_Vissim::VISSIM_ATTR_NO }, //id
176  { "intLink", NIImporter_Vissim::VISSIM_ATTR_INTLINK }, //edgeID
188 };
189 
190 
191 // ===========================================================================
192 // method definitions
193 // ===========================================================================
194 // ---------------------------------------------------------------------------
195 // static methods (interface in this case)
196 // ---------------------------------------------------------------------------
197 void
199  if (!oc.isSet("vissim-file")) {
200  return;
201  }
202  NIImporter_Vissim loader(nb, oc.getString("vissim-file"));
203  // check if legacy format file or newer XML file
204  // file name extension check
205  if ((oc.getString("vissim-file").find(".inpx") != std::string::npos))
206  //TODO: check if the given position of .inpx is at the end
207  {
208  // load the XML vissim network
209  loader.loadXML(oc, nb);
210  loader.myInputIsLegacyFormat = false;
211  } else {
212  // load the legacy vissim network
213  loader.load(oc);
214  loader.myInputIsLegacyFormat = true;
215  }
216 }
217 
218 
219 // ---------------------------------------------------------------------------
220 // definitions of NIVissimXMLHandler_Streckendefinition-methods
221 // ---------------------------------------------------------------------------
223  //std::map<int, VissimXMLEdge>& toFill)
224  nodeMap& elemData)
227  "vissim - file"),
228  myElemData(elemData),
229  myHierarchyLevel(0),
230  isConnector(false) {
231  myElemData.clear();
232 }
233 
235 
236 void
239 
240  // finding an actual LINK
241  if (element == VISSIM_TAG_LINK) {
242  //parse all links
243  bool ok = true;
244  int id = attrs.get<int>(VISSIM_ATTR_NO, 0, ok);
245  myLastNodeID = id;
246 
247  // !!! assuming empty myElemData
248  myElemData["id"].push_back(attrs.get<std::string>(VISSIM_ATTR_NO, 0, ok));
249  // error ignored if name is empty
250  myElemData["name"].push_back(attrs.get<std::string>(VISSIM_ATTR_NAME, 0, ok, false));
251  myElemData["type"].push_back(attrs.get<std::string>(VISSIM_ATTR_LINKBEHAVETYPE, 0, ok));
252  myElemData["zuschlag1"].push_back(attrs.get<std::string>(VISSIM_ATTR_ZUSCHLAG1, 0, ok));
253  myElemData["zuschlag2"].push_back(attrs.get<std::string>(VISSIM_ATTR_ZUSCHLAG2, 0, ok));
254  }
255 
256  if (element == VISSIM_TAG_LANE) {
257  bool ok = true;
258  // appends empty element if no width found
259  // error ignored if name is empty
260  myElemData["width"].push_back(attrs.get<std::string>(VISSIM_ATTR_WIDTH, 0, ok, false));
261  }
262 
263  if (element == VISSIM_TAG_FROM) {
264  if (isConnector != true) {
265  isConnector = true;
266  }
267  bool ok = true;
268  std::vector<std::string> from(StringTokenizer(attrs.get<std::string>(
269  VISSIM_ATTR_LANE, 0, ok), " ").getVector());
270  myElemData["from_pos"].push_back(attrs.get<std::string>(VISSIM_ATTR_POS, 0, ok));
271  myElemData["from_id"].push_back(from[0]);
272  myElemData["from_lane"].push_back(from[1]);
273  }
274 
275  if (element == VISSIM_TAG_TO) {
276  bool ok = true;
277  std::vector<std::string> to(StringTokenizer(attrs.get<std::string>(
278  VISSIM_ATTR_LANE, 0, ok), " ").getVector());
279  myElemData["to_pos"].push_back(attrs.get<std::string>(VISSIM_ATTR_POS, 0, ok));
280  myElemData["to_id"].push_back(to[0]);
281  myElemData["to_lane"].push_back(to[1]);
282  }
283 
284  if (element == VISSIM_TAG_POINT3D) {
285  bool ok = true;
286  // create a <sep> separated string of coordinate data
287  std::string sep(" ");
288 
289  std::string posS(attrs.get<std::string>(VISSIM_ATTR_X, 0, ok));
290  posS += sep;
291  posS.append(attrs.get<std::string>(VISSIM_ATTR_Y, 0, ok));
292  // allow for no Z
293  std::string z(attrs.get<std::string>(VISSIM_ATTR_ZOFFSET, 0, ok, false));
294  if (z.length() > 0) {
295  posS += sep;
296  posS.append(z);
297  }
298  myElemData["pos"].push_back(posS);
299  }
300 
301 
302 }
303 
304 void
306  if (element == VISSIM_TAG_LINK && myHierarchyLevel == 3) {
307  //std::cout << "elemData len:" << myElemData.size() << std::endl;
308 
309  NIVissimClosedLanesVector clv; //FIXME -> clv einlesen
310  std::vector<int> assignedVehicles; //FIXME -> assignedVehicles einlesen
311  int id(TplConvert::_str2int(myElemData["id"].front()));
312 
313  PositionVector geom;
314  // convert all position coordinate strings to PositionVectors
315  while (!myElemData["pos"].empty()) {
316  std::vector<std::string> sPos_v(StringTokenizer(
317  myElemData["pos"].front(), " ").getVector());
318  myElemData["pos"].pop_front();
319  std::vector<double> pos_v(3);
320 
321  // doing a transform with explicit hint on function signature
322  std::transform(sPos_v.begin(), sPos_v.end(), pos_v.begin(),
324  geom.push_back_noDoublePos(Position(pos_v[0], pos_v[1], pos_v[2]));
325  }
326  // FIXME: a length = 0 PosVec seems fatal -> segfault
327  double length(geom.length());
328 
329  if (isConnector == false) {
330  // Add Edge
331  NIVissimEdge* edge = new NIVissimEdge(id,
332  myElemData["name"].front(),
333  myElemData["type"].front(),
334  (int)myElemData["width"].size(), // numLanes,
335  TplConvert::_str2double(myElemData["zuschlag1"].front()),
336  TplConvert::_str2double(myElemData["zuschlag2"].front()),
337  length, geom, clv);
338  NIVissimEdge::dictionary(id, edge);
339  if (id == 85 || id == 91) {
340  std::cout << id << "\n";
341  std::cout << myElemData["width"].size() << "\n";
342  std::cout << length << "\n";
343  std::cout << geom << "\n";
344  }
345  } else {
346  int numLanes = (int)myElemData["width"].size();
347  std::vector<int> laneVec(numLanes);
348  // Add Connector
349 
350  //NOTE: there should be only 1 lane number in XML
351  // subtraction of 1 as in readExtEdgePointDef()
352  laneVec[0] = TplConvert::_str2int(myElemData["from_lane"].front()) - 1;
353  // then count up, building lane number vector
354  for (std::vector<int>::iterator each = ++laneVec.begin(); each != laneVec.end(); ++each) {
355  *each = *(each - 1) + 1;
356  }
357 
358  NIVissimExtendedEdgePoint from_def(
359  TplConvert::_str2int(myElemData["from_id"].front()),
360  laneVec,
361  TplConvert::_str2double(myElemData["from_pos"].front()),
362  assignedVehicles);
363 
364  //NOTE: there should be only 1 lane number in XML
365  // subtraction of 1 as in readExtEdgePointDef()
366  laneVec[0] = TplConvert::_str2int(myElemData["to_lane"].front()) - 1;
367  // then count up, building lane number vector
368  for (std::vector<int>::iterator each = ++laneVec.begin(); each != laneVec.end(); ++each) {
369  *each = *(each - 1) + 1;
370  }
371 
373  TplConvert::_str2int(myElemData["to_id"].front()),
374  laneVec,
375  TplConvert::_str2double(myElemData["to_pos"].front()),
376  assignedVehicles);
377 
378  NIVissimConnection* connector = new
380  myElemData["name"].front(),
381  from_def, to_def,
382  geom, assignedVehicles, clv);
383 
384  NIVissimConnection::dictionary(id, connector);
385  }
386  // clear the element data
387  myElemData.clear();
388  isConnector = false;
389  //std::cout << "elemData len (clear):" << myElemData.size() << std::endl;
390  //std::cout.flush();
391 
392  }
394 }
395 
396 
397 // ---------------------------------------------------------------------------
398 // definitions of NIVissimXMLHandler_Zuflussdefinition-methods
399 // ---------------------------------------------------------------------------
403  "vissim - file") {
404 }
405 
407 
408 void
410  // finding an actual flow
411  if (element == VISSIM_TAG_VEHICLE_INPUT) {
412  //parse all flows
413  bool ok = true;
414  std::string id = attrs.get<std::string>(VISSIM_ATTR_NO, 0, ok);
415  std::string edgeid = attrs.get<std::string>(VISSIM_ATTR_LINK, 0, ok);
416  std::string name = attrs.get<std::string>(VISSIM_ATTR_NAME, 0, ok, false);
417 
419  name,
420  edgeid);
421  }
422 }
423 
424 // ---------------------------------------------------------------------------
425 // definitions of NIVissimXMLHandler_Parkplatzdefinition-methods
426 // ---------------------------------------------------------------------------
430  "vissim - file") {
431 }
432 
434 
435 void
437  // finding an actual parkinglot
438  if (element == VISSIM_TAG_PARKINGLOT) {
439  //parse all parkinglots
440  bool ok = true;
441  int id = attrs.get<int>(VISSIM_ATTR_NO, 0, ok);
442  int edgeid = attrs.get<int>(VISSIM_ATTR_INTLINK, 0, ok);
443  std::string name = attrs.get<std::string>(VISSIM_ATTR_NAME, 0, ok, false);
444  double position = attrs.get<double>(VISSIM_ATTR_POS, 0, ok);
445  std::vector<std::pair<int, int> > assignedVehicles; // (vclass, vwunsch)
446  //FIXME: vWunsch + Fahzeugklassen einlesen
447  // There can be s
448  std::vector<int> districts;
449  //FIXME: Parkplatzdefinition für mehrere Zonen implementieren
450  std::vector<double> percentages;
451  districts.push_back(attrs.get<int>(VISSIM_ATTR_DISTRICT, 0, ok));
452  percentages.push_back(attrs.get<double>(VISSIM_ATTR_PERCENTAGE, 0, ok));
453 
455  name,
456  districts,
457  percentages,
458  edgeid,
459  position,
460  assignedVehicles);
461  }
462 }
463 
464 
465 // ---------------------------------------------------------------------------
466 // definitions of NIVissimXMLHandler_Fahrzeugklassendefinition-methods
467 // ---------------------------------------------------------------------------
471  "vissim - file"),
472  myElemData(elemData),
473  myHierarchyLevel(0) {
474  myElemData.clear();
475 }
476 
478 
479 void
482 
483  if (element == VISSIM_TAG_VEHICLE_CLASS) {
484  bool ok = true;
485  myElemData["id"].push_back(attrs.get<std::string>(VISSIM_ATTR_NO, 0, ok));
486  myElemData["name"].push_back(attrs.get<std::string>(VISSIM_ATTR_NAME, 0, ok, false));
487  std::string colorStr(attrs.get<std::string>(VISSIM_ATTR_COLOR, 0, ok));
488  for (int pos = (int)colorStr.size() - 2; pos > 0; pos -= 2) {
489  colorStr.insert(pos, " ");
490  }
491  myElemData["color"].push_back(colorStr);
492  }
493  if (element == VISSIM_TAG_INTOBJECTREF) {
494  bool ok = true;
495  myElemData["types"].push_back(attrs.get<std::string>(VISSIM_ATTR_KEY, 0, ok));
496 
497 
498  }
499 }
500 
501 void
503  if (element == VISSIM_TAG_VEHICLE_CLASS && myHierarchyLevel == 3) {
504  RGBColor color;
505  std::istringstream iss(myElemData["color"].front());
506  std::vector<std::string> sCol_v(StringTokenizer(
507  myElemData["color"].front(), " ").getVector());
508  std::vector<int> myColorVector(sCol_v.size());
509  std::transform(sCol_v.begin(), sCol_v.end(), myColorVector.begin(),
511 
512  color = RGBColor((unsigned char)myColorVector[0],
513  (unsigned char)myColorVector[1],
514  (unsigned char)myColorVector[2],
515  (unsigned char)myColorVector[3]);
516  std::vector<int> types;
517  while (!myElemData["types"].empty()) {
518  types.push_back(TplConvert::_str2int(myElemData["types"].front()));
519  myElemData["types"].pop_front();
520  }
521 
523  myElemData["name"].front(),
524  color,
525  types);
526  myElemData.clear();
527  }
529 }
530 
531 // ---------------------------------------------------------------------------
532 // definitions of NIVissimXMLHandler_Geschwindigkeitsverteilungsdefinition-methods
533 // ---------------------------------------------------------------------------
537  "vissim - file"),
538  myElemData(elemData),
539  myHierarchyLevel(0) {
540  myElemData.clear();
541 }
542 
544 
545 void
548  if (element == VISSIM_TAG_SPEED_DIST) {
549  bool ok = true;
550  myElemData["id"].push_back(attrs.get<std::string>(VISSIM_ATTR_NO, 0, ok));
551  }
552 
553  if (element == VISSIM_TAG_DATAPOINT) {
554  bool ok = true;
555  std::string sep(" ");
556  std::string posS(attrs.get<std::string>(VISSIM_ATTR_X, 0, ok));
557  posS += sep;
558  posS.append(attrs.get<std::string>(VISSIM_ATTR_FX, 0, ok));
559  myElemData["points"].push_back(posS);
560 
561  }
562 
563 }
564 
565 void
567  if (element == VISSIM_TAG_SPEED_DIST && myHierarchyLevel == 3) {
568  Distribution_Points* points = new Distribution_Points(myElemData["id"].front());
569  while (!myElemData["points"].empty()) {
570  std::vector<std::string> sPos_v(StringTokenizer(
571  myElemData["points"].front(), " ").getVector());
572  myElemData["points"].pop_front();
573  points->add(TplConvert::_str2double(sPos_v[0]), TplConvert::_str2double(sPos_v[1]));
574  }
575  DistributionCont::dictionary("speed", myElemData["id"].front(), points);
576  myElemData.clear();
577  }
579 }
580 
581 // ---------------------------------------------------------------------------
582 // definitions of NIVissimXMLHandler_VWunschentscheidungsdefinition-methods
583 // ---------------------------------------------------------------------------
587  "vissim - file"),
588  myElemData(elemData),
589  myHierarchyLevel(0) {
590  myElemData.clear();
591 }
592 
594 
595 void
598  if (element == VISSIM_TAG_SPEED_DECISION) {
599  bool ok = true;
600  myElemData["name"].push_back(attrs.get<std::string>(VISSIM_ATTR_NAME, 0, ok, false));
601  //FIXME: 2 vWunsch in the xml file, but only 1 of them is set???
602  }
603 
604 }
605 
606 void
609 }
610 
611 
612 // ---------------------------------------------------------------------------
613 // definitions of NIVissimXMLHandler_Routenentscheidungsdefinition-methods
614 // ---------------------------------------------------------------------------
618  "vissim - file"),
619  myElemData(elemData),
620  myHierarchyLevel(0) {
621  myElemData.clear();
622 }
623 
625 
626 void
629  if (element == VISSIM_TAG_DECISION_STATIC) {
630  bool ok = true;
631  myElemData["startLink"].push_back(attrs.get<std::string>(VISSIM_ATTR_LINK, 0, ok));
632  myElemData["startPos"].push_back(attrs.get<std::string>(VISSIM_ATTR_POS, 0, ok));
633  }
634  if (element == VISSIM_TAG_ROUTE_STATIC) {
635  bool ok = true;
636  myElemData["destLink"].push_back(attrs.get<std::string>(VISSIM_ATTR_DESTLINK, 0, ok));
637  myElemData["destPos"].push_back(attrs.get<std::string>(VISSIM_ATTR_DESTPOS, 0, ok));
638  myElemData["id"].push_back(attrs.get<std::string>(VISSIM_ATTR_NO, 0, ok));
639  }
640  if (element == VISSIM_TAG_INTOBJECTREF) {
641  // bool ok = true;
642  }
643 
644 }
645 
646 void
649 }
650 
651 // ---------------------------------------------------------------------------
652 // definitions of NIVissimXMLHandler_ConflictArea-methods
653 // ---------------------------------------------------------------------------
657  "vissim - file") {}
658 
660 
661 void
663  // finding an actual flow
664  if (element == VISSIM_TAG_CA) {
665  //parse all flows
666  bool ok = true;
667  std::string status = attrs.get<std::string>(VISSIM_ATTR_STATUS, 0, ok);
668  //get only the conflict areas which were set in VISSIM
669  if (status != "PASSIVE") {
671  attrs.get<std::string>(VISSIM_ATTR_LINK1, 0, ok),
672  attrs.get<std::string>(VISSIM_ATTR_LINK2, 0, ok),
673  status);
674  }
675 
676  }
677 }
678 
679 
680 /* -------------------------------------------------------------------------
681  * NIImporter_Vissim::VissimSingleTypeParser-methods
682  * ----------------------------------------------------------------------- */
684  : myVissimParent(parent) {}
685 
686 
688 
689 
690 std::string
692  std::string tmp;
693  from >> tmp;
694  return StringUtils::to_lower_case(tmp);
695 }
696 
697 
698 
699 std::string
701  const std::string& excl) {
702  std::string myExcl = StringUtils::to_lower_case(excl);
703  std::string tmp = myRead(from);
704  if (tmp == "") {
705  return "DATAEND";
706  }
707  if (tmp != myExcl
708  &&
709  (tmp.substr(0, 2) == "--" || !myVissimParent.admitContinue(tmp))
710  ) {
711  return "DATAEND";
712  }
713  return StringUtils::to_lower_case(tmp);
714 }
715 
716 
717 std::string
719  const std::vector<std::string>& excl) {
720  std::vector<std::string> myExcl;
721  std::vector<std::string>::const_iterator i;
722  for (i = excl.begin(); i != excl.end(); i++) {
723  std::string mes = StringUtils::to_lower_case(*i);
724  myExcl.push_back(mes);
725  }
726  std::string tmp = myRead(from);
727  if (tmp == "") {
728  return "DATAEND";
729  }
730 
731  bool equals = false;
732  for (i = myExcl.begin(); i != myExcl.end() && !equals; i++) {
733  if ((*i) == tmp) {
734  equals = true;
735  }
736  }
737  if (!equals
738  &&
739  (tmp.substr(0, 2) == "--" || !myVissimParent.admitContinue(tmp))
740  ) {
741  return "DATAEND";
742  }
743  return StringUtils::to_lower_case(tmp);
744 }
745 
746 
747 std::string
749  const std::string& tag) {
750  std::string tmp;
751  if (tag == "") {
752  tmp = myRead(from);
753  } else {
754  tmp = tag;
755  }
756  if (tmp == "beschriftung") {
757  tmp = myRead(from);
758  if (tmp == "keine") {
759  from >> tmp;
760  }
761  tmp = myRead(from);
762  tmp = myRead(from);
763  }
764  return tmp;
765 }
766 
767 
768 Position
770  double x, y;
771  from >> x; // type-checking is missing!
772  from >> y; // type-checking is missing!
773  return Position(x, y);
774 }
775 
776 
777 std::vector<int>
779  std::istream& from, const std::string& next) {
780  std::string tmp = readEndSecure(from);
781  std::vector<int> ret;
782  if (tmp == "alle") {
783  ret.push_back(-1);
784  return ret;
785  }
786  while (tmp != "DATAEND" && tmp != next) {
787  ret.push_back(TplConvert::_2int(tmp.c_str()));
788  tmp = readEndSecure(from);
789  }
790  return ret;
791 }
792 
793 
796  std::istream& from) {
797  std::string tag;
798  from >> tag; // "Strecke"
799  int edgeid;
800  from >> edgeid; // type-checking is missing!
801  from >> tag; // "Spuren"
802  std::vector<int> lanes;
803  while (tag != "bei") {
804  tag = readEndSecure(from);
805  if (tag != "bei") {
806  int lane = TplConvert::_2int(tag.c_str());
807  lanes.push_back(lane - 1);
808  }
809  }
810  double position;
811  from >> position;
812  std::vector<int> dummy;
813  return NIVissimExtendedEdgePoint(edgeid, lanes, position, dummy);
814 }
815 
816 
817 std::string
819  std::string name;
820  from >> name;
821  if (name[0] == '"') {
822  while (name[name.length() - 1] != '"') {
823  std::string tmp;
824  from >> tmp;
825  name = name + " " + tmp;
826  }
827  name = name.substr(1, name.length() - 2);
828  }
829  return StringUtils::convertUmlaute(name);
830 }
831 
832 
833 void
835  const std::string& name) {
836  std::string tag;
837  while (tag != name) {
838  tag = myRead(from);
839  }
840 }
841 
842 bool
844  const std::string& name) {
845  std::string tag;
846  while (tag != name) {
847  tag = myRead(from);
848  }
849  while (tag != "DATAEND") {
850  tag = readEndSecure(from);
851  }
852  return true;
853 }
854 
855 
856 
857 /* -------------------------------------------------------------------------
858  * NIImporter_Vissim-methods
859  * ----------------------------------------------------------------------- */
861  : myNetBuilder(nb), myInputIsLegacyFormat(false) {
862  UNUSED_PARAMETER(file);
864  buildParsers();
865  myColorMap["blau"] = RGBColor(77, 77, 255, 255);
866  myColorMap["gelb"] = RGBColor::YELLOW;
867  myColorMap["grau"] = RGBColor::GREY;
868  myColorMap["lila"] = RGBColor::MAGENTA;
869  myColorMap["gruen"] = RGBColor::GREEN;
870  myColorMap["rot"] = RGBColor::RED;
871  myColorMap["schwarz"] = RGBColor::BLACK;
872  myColorMap["tuerkis"] = RGBColor::CYAN;
873  myColorMap["weiss"] = RGBColor::WHITE;
874  myColorMap["keine"] = RGBColor::WHITE;
875 }
876 
877 
878 
879 
899  for (ToParserMap::iterator i = myParsers.begin(); i != myParsers.end(); i++) {
900  delete(*i).second;
901  }
902 }
903 
904 
905 void
907  // load file contents
908  // try to open the file
909  std::ifstream strm(options.getString("vissim-file").c_str());
910  if (!strm.good()) {
911  WRITE_ERROR("The vissim-file '" + options.getString("vissim-file") + "' was not found.");
912  return;
913  }
914  if (!readContents(strm)) {
915  return;
916  }
917  postLoadBuild(options.getFloat("vissim.join-distance"));
918 }
919 
920 void
922  // Parse file
923  std::string file = options.getString("vissim-file");
924  // Create NIVissimXMLHandlers
925  NIVissimXMLHandler_Streckendefinition XMLHandler_Streckendefinition(elementData);
926  NIVissimXMLHandler_Zuflussdefinition XMLHandler_Zuflussdefinition;
927  //NIVissimXMLHandler_Parkplatzdefinition XMLHandler_Parkplatzdefinition;
928  NIVissimXMLHandler_Fahrzeugklassendefinition XMLHandler_Fahrzeugklassendefinition(elementData);
929  NIVissimXMLHandler_Geschwindigkeitsverteilungsdefinition XMLHandler_Geschwindigkeitsverteilung(elementData);
930  NIVissimXMLHandler_ConflictArea XMLHandler_ConflictAreas;
931  if (!FileHelpers::isReadable(file)) {
932  WRITE_ERROR("Could not open vissim-file '" + file + "'.");
933  return;
934  }
935 
936  // Strecken + Verbinder
937  XMLHandler_Streckendefinition.setFileName(file);
938  PROGRESS_BEGIN_MESSAGE("Parsing strecken+verbinder from vissim-file '" + file + "'");
939  if (!XMLSubSys::runParser(XMLHandler_Streckendefinition, file)) {
940  return;
941  }
943 
944  // Zuflüsse
945  XMLHandler_Zuflussdefinition.setFileName(file);
946  PROGRESS_BEGIN_MESSAGE("Parsing zuflüsse from vissim-file '" + file + "'");
947  if (!XMLSubSys::runParser(XMLHandler_Zuflussdefinition, file)) {
948  return;
949  }
951 
952  //Geschwindigkeitsverteilungen
953  XMLHandler_Geschwindigkeitsverteilung.setFileName(file);
954  PROGRESS_BEGIN_MESSAGE("Parsing parkplätze from vissim-file '" + file + "'");
955  if (!XMLSubSys::runParser(XMLHandler_Geschwindigkeitsverteilung, file)) {
956  return;
957  }
959 
960 
961  //Fahrzeugklassen
962  XMLHandler_Fahrzeugklassendefinition.setFileName(file);
963  PROGRESS_BEGIN_MESSAGE("Parsing parkplätze from vissim-file '" + file + "'");
964  if (!XMLSubSys::runParser(XMLHandler_Fahrzeugklassendefinition, file)) {
965  return;
966  }
968 
969  //Parkplätze
970  /*XMLHandler_Parkplatzdefinition.setFileName(file);
971  PROGRESS_BEGIN_MESSAGE("Parsing parkplätze from vissim-file '" + file + "'");
972  if (!XMLSubSys::runParser(XMLHandler_Parkplatzdefinition, file)) {
973  return;
974  }
975  PROGRESS_DONE_MESSAGE();*/
976 
977 
978  //Konfliktflächen
979  XMLHandler_ConflictAreas.setFileName(file);
980  PROGRESS_BEGIN_MESSAGE("Parsing conflict areas from vissim-file '" + file + "'");
981  if (!XMLSubSys::runParser(XMLHandler_ConflictAreas, file)) {
982  return;
983  }
985 
986  postLoadBuild(options.getFloat("vissim.join-distance"));
987 }
988 
989 bool
990 NIImporter_Vissim::admitContinue(const std::string& tag) {
991  ToElemIDMap::const_iterator i = myKnownElements.find(tag);
992  if (i == myKnownElements.end()) {
993  return true;
994  }
995  myLastSecure = tag;
996  return false;
997 }
998 
999 
1000 bool
1001 NIImporter_Vissim::readContents(std::istream& strm) {
1002  // read contents
1003  bool ok = true;
1004  while (strm.good() && ok) {
1005  std::string tag;
1006  if (myLastSecure != "") {
1007  tag = myLastSecure;
1008  } else {
1009  strm >> tag;
1010  }
1011  myLastSecure = "";
1012  bool parsed = false;
1013  while (!parsed && strm.good() && ok) {
1014  ToElemIDMap::iterator i = myKnownElements.find(StringUtils::to_lower_case(tag));
1015  if (i != myKnownElements.end()) {
1016  ToParserMap::iterator j = myParsers.find((*i).second);
1017  if (j != myParsers.end()) {
1018  VissimSingleTypeParser* parser = (*j).second;
1019  ok = parser->parse(strm);
1020  parsed = true;
1021  }
1022  }
1023  if (!parsed) {
1024  std::string line;
1025  std::streamoff pos;
1026  do {
1027  pos = strm.tellg();
1028  getline(strm, line);
1029  } while (strm.good() && (line == "" || line[0] == ' ' || line[0] == '-'));
1030  if (!strm.good()) {
1031  return true;
1032  }
1033  strm.seekg(pos);
1034  strm >> tag;
1035  }
1036  }
1037  }
1038  return ok;
1039 }
1040 
1041 
1042 void
1044  // close the loading process
1048  // build district->connections map
1050  // build clusters around nodes
1051 // NIVissimNodeDef::buildNodeClusters();
1052  // build node clusters around traffic lights
1053 // NIVissimTL::buildNodeClusters();
1054 
1055  // when connections or disturbances are left, build nodes around them
1056 
1057  // try to assign connection clusters to nodes
1058  // only left connections will be processed in
1059  // buildConnectionClusters & join
1060 //30.4. brauchen wir noch! NIVissimNodeDef::dict_assignConnectionsToNodes();
1061 
1062  // build clusters of connections with the same direction and a similar position along the streets
1064  // check whether further nodes (connection clusters by now) must be added
1066 
1067  // join clusters when overlapping (different streets are possible)
1070 // NIVissimConnectionCluster::joinByDisturbances(offset);
1071 
1072 // NIVissimConnectionCluster::addTLs(offset);
1073 
1074  // build nodes from clusters
1077 
1078 // NIVissimNodeCluster::dict_recheckEdgeChanges();
1084  if (OptionsCont::getOptions().getBool("vissim.report-unset-speeds")) {
1086  }
1092 }
1093 
1094 
1095 void
1097  myKnownElements["kennung"] = VE_Kennungszeile;
1098  myKnownElements["zufallszahl"] = VE_Startzufallszahl;
1099  myKnownElements["simulationsdauer"] = VE_Simdauer;
1100  myKnownElements["startuhrzeit"] = VE_Startuhrzeit;
1101  myKnownElements["simulationsrate"] = VE_SimRate;
1102  myKnownElements["zeitschritt"] = VE_Zeitschrittfaktor;
1103  myKnownElements["linksverkehr"] = VE_Linksverkehr;
1104  myKnownElements["dynuml"] = VE_DynUml;
1106  myKnownElements["gelbverhalten"] = VE_Gelbverhaltendefinition;
1108  myKnownElements["verbindung"] = VE_Verbindungsdefinition;
1109  myKnownElements["richtungsentscheidung"] = VE_Richtungsentscheidungsdefinition;
1110  myKnownElements["routenentscheidung"] = VE_Routenentscheidungsdefinition;
1111  myKnownElements["vwunschentscheidung"] = VE_VWunschentscheidungsdefinition;
1112  myKnownElements["langsamfahrbereich"] = VE_Langsamfahrbereichdefinition;
1114  myKnownElements["fahrzeugtyp"] = VE_Fahrzeugtypdefinition;
1115  myKnownElements["fahrzeugklasse"] = VE_Fahrzeugklassendefinition;
1125  myKnownElements["wunschbeschleunigung"] = VE_Wunschbeschleunigungskurvedefinition;
1128  myKnownElements["querverkehrsstoerung"] = VE_Querverkehrsstoerungsdefinition;
1130  myKnownElements["signalgruppe"] = VE_Signalgruppendefinition;
1131  myKnownElements["signalgeber"] = VE_Signalgeberdefinition;
1132  myKnownElements["lsakopplung"] = VE_LSAKopplungdefinition;
1134  myKnownElements["haltestelle"] = VE_Haltestellendefinition;
1136  myKnownElements["stopschild"] = VE_Stopschilddefinition;
1140  myKnownElements["querschnittsmessung"] = VE_Querschnittsmessungsdefinition;
1141  myKnownElements["stauzaehler"] = VE_Stauzaehlerdefinition;
1142  myKnownElements["auswertung"] = VE_Auswertungsdefinition;
1145  myKnownElements["parkplatz"] = VE_Parkplatzdefinition;
1148  myKnownElements["netzobjekt"] = VE_Netzobjektdefinition;
1149  myKnownElements["richtungspfeil"] = VE_Richtungspfeildefinition;
1151  myKnownElements["fahrverhalten"] = VE_Fahrverhaltendefinition;
1152  myKnownElements["fahrtverlaufdateien"] = VE_Fahrtverlaufdateien;
1153  myKnownElements["emission"] = VE_Emission;
1155  myKnownElements["streckentyp"] = VE_Streckentypdefinition;
1156  myKnownElements["kantensperrung"] = VE_Kantensperrung;
1158 
1159 
1160  myKnownElements["advance"] = VE_DUMMY;
1161  myKnownElements["temperatur"] = VE_DUMMY;
1162 
1163 }
1164 
1165 
1166 
1167 void
1173  myParsers[VE_DynUml] =
1247 
1290 
1291 }
1292 
1293 
1294 
1295 /****************************************************************************/
1296 
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:53
NIVissimXMLHandler_Streckendefinition(nodeMap &elemData)
Constructor.
static const RGBColor WHITE
Definition: RGBColor.h:185
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:186
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:109
void myEndElement(int element)
Callback method for a closing tag to implement by derived classes.
#define UNUSED_PARAMETER(x)
Definition: StdDefs.h:39
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:64
A temporary storage for edges imported from Vissim.
Definition: NIVissimEdge.h:59
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:363
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:179
static const RGBColor GREY
Definition: RGBColor.h:187
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:45
NBEdgeCont & getEdgeCont()
Definition: NBNetBuilder.h:156
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:167
static bool dict_SetSignals(NBTrafficLightLogicCont &tlc, NBEdgeCont &ec)
Definition: NIVissimTL.cpp:372
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:183
#define PROGRESS_BEGIN_MESSAGE(msg)
Definition: MsgHandler.h:201
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:90
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:205
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:62
static const RGBColor YELLOW
Definition: RGBColor.h:181
static int _2int(const E *const data)
converts a char-type array into the integer value described by it
Definition: TplConvert.h:155
static const RGBColor RED
named colors
Definition: RGBColor.h:178
double length() const
Returns the length.
static const RGBColor CYAN
Definition: RGBColor.h:182
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:161
void myStartElement(int element, const SUMOSAXAttributes &attrs)
Called on the opening of a tag;.
Instance responsible for building networks.
Definition: NBNetBuilder.h:115
A storage for options typed value containers)
Definition: OptionsCont.h:98
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:171
static void buildNBNodes(NBNodeCont &nc)
static void clearDict()
Definition: NIVissimTL.cpp:360
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:202
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:188
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:176
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.