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