SUMO - Simulation of Urban MObility
NIVissimSingleTypeParser_Verbindungsdefinition.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 /****************************************************************************/
16 //
17 /****************************************************************************/
18 
19 
20 // ===========================================================================
21 // included modules
22 // ===========================================================================
23 #include <config.h>
24 
25 #include <iostream>
28 #include "../NIImporter_Vissim.h"
29 #include "../tempstructs/NIVissimConnection.h"
31 
32 
33 // ===========================================================================
34 // method definitions
35 // ===========================================================================
37  : NIImporter_Vissim::VissimSingleTypeParser(parent) {}
38 
39 
41 
42 
43 bool
45  int id;
46  from >> id; // type-checking is missing!
47  std::string tag;
48  // Read optional value "Name", skip optional value "Beschriftung"
49  std::string name;
50  while (tag != "von") {
51  tag = overrideOptionalLabel(from);
52  if (tag == "name") {
53  name = readName(from);
54  }
55  }
56  // Read the geometry information
58  PositionVector geom;
59  tag = myRead(from); // "ueber"
60  while (tag != "nach") {
61  std::string x = myRead(from);
62  std::string y = myRead(from);
63  if (y != "nach") {
65  Position(
68  ));
69  tag = myRead(from);
70  try {
72  tag = myRead(from);
73  } catch (NumberFormatException&) {}
74  } else {
75  tag = y;
76  }
77  }
79  // read some optional values until mandatory "Fahrzeugklassen" occurs
80  double dxnothalt = 0;
81  double dxeinordnen = 0;
82  double zuschlag1, zuschlag2;
83  zuschlag1 = zuschlag2 = 0;
84  double seglength = 0;
85  tag = myRead(from);
86 // NIVissimConnection::Direction direction = NIVissimConnection::NIVC_DIR_ALL;
87  while (tag != "fahrzeugklassen" && tag != "sperrung" && tag != "auswertung" && tag != "DATAEND") {
88  if (tag == "rechts") {
89 // direction = NIVissimConnection::NIVC_DIR_RIGHT;
90  } else if (tag == "links") {
91 // direction = NIVissimConnection::NIVC_DIR_LEFT;
92  } else if (tag == "alle") {
93 // direction = NIVissimConnection::NIVC_DIR_ALL;
94  } else if (tag == "dxnothalt") {
95  from >> dxnothalt; // type-checking is missing!
96  } else if (tag == "dxeinordnen") {
97  from >> dxeinordnen; // type-checking is missing!
98  } else if (tag == "segment") {
99  from >> tag;
100  from >> seglength;
101  }
102  if (tag == "zuschlag") {
103  from >> zuschlag1; // type-checking is missing!
104  tag = readEndSecure(from);
105  if (tag == "zuschlag") {
106  from >> zuschlag2; // type-checking is missing!
107  tag = readEndSecure(from, "auswertung");
108  }
109  } else {
110  tag = readEndSecure(from, "auswertung");
111  }
112  }
113  // read in allowed vehicle classes
114  std::vector<int> assignedVehicles;
115  if (tag == "fahrzeugklassen") {
116  tag = readEndSecure(from);
117  while (tag != "DATAEND" && tag != "sperrung" && tag != "auswertung") {
118  int classes = StringUtils::toInt(tag);
119  assignedVehicles.push_back(classes);
120  tag = readEndSecure(from, "auswertung");
121  }
122  }
123  // Read definitions of closed lanes
125  if (tag != "DATAEND") {
126  do {
127  // check whether a next close lane definition can be found
128  tag = readEndSecure(from);
129  if (tag == "keinspurwechsel") {
130  while (tag != "DATAEND") {
131  tag = readEndSecure(from);
132  }
133  } else if (tag == "spur") {
134  // get the lane number
135 // from >> tag;
136  int laneNo;
137  from >> laneNo; // unused and type-checking is missing!
138  // get the list of assigned car classes
139  std::vector<int> assignedVehicles;
140  tag = myRead(from);
141  if (tag == "fahrzeugklassen") {
142  tag = myRead(from);
143  }
144  while (tag != "DATAEND" && tag != "spur" && tag != "keinspurwechsel") {
145  int classes = StringUtils::toInt(tag);
146  assignedVehicles.push_back(classes);
147  tag = readEndSecure(from);
148  }
149  // build and add the definition
150  NIVissimClosedLaneDef* cld = new NIVissimClosedLaneDef(assignedVehicles);
151  clv.push_back(cld);
152  }
153  } while (tag != "DATAEND");
154  }
155  NIVissimConnection* c = new NIVissimConnection(id, name, from_def, to_def, geom,
156  assignedVehicles, clv);
157 
158  if (!NIVissimConnection::dictionary(id, c)) {
159  return false;
160  }
161  return true;
162  //return NIVissimAbstractEdge::dictionary(id, c);
163 }
164 
165 
166 
167 /****************************************************************************/
168 
std::string myRead(std::istream &from)
reads from the stream and returns the lower case version of the read value
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
Importer for networks stored in Vissim format.
static bool dictionary(int id, NIVissimConnection *o)
NIVissimExtendedEdgePoint readExtEdgePointDef(std::istream &from)
static double toDouble(const std::string &sData)
converts a string into the double value described by it by calling the char-type converter ...
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:39
A list of positions.
static int toInt(const std::string &sData)
converts a string into the integer value described by it by calling the char-type converter...
bool parse(std::istream &from)
Parses the data type from the given stream.
std::string readName(std::istream &from)
Reads the structures name We cannot use the "<<" operator, as names may contain more than one word wh...
NIVissimSingleTypeParser_Verbindungsdefinition(NIImporter_Vissim &parent)
Constructor.
void push_back_noDoublePos(const Position &p)
insert in back a non double position
std::string overrideOptionalLabel(std::istream &from, const std::string &tag="")
overrides the optional label definition; returns the next tag as done by readEndSecure ...