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-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 /****************************************************************************/
18 //
19 /****************************************************************************/
20 
21 
22 // ===========================================================================
23 // included modules
24 // ===========================================================================
25 #ifdef _MSC_VER
26 #include <windows_config.h>
27 #else
28 #include <config.h>
29 #endif
30 
31 #include <iostream>
34 #include "../NIImporter_Vissim.h"
35 #include "../tempstructs/NIVissimConnection.h"
37 
38 
39 // ===========================================================================
40 // method definitions
41 // ===========================================================================
43  : NIImporter_Vissim::VissimSingleTypeParser(parent) {}
44 
45 
47 
48 
49 bool
51  int id;
52  from >> id; // type-checking is missing!
53  std::string tag;
54  // Read optional value "Name", skip optional value "Beschriftung"
55  std::string name;
56  while (tag != "von") {
57  tag = overrideOptionalLabel(from);
58  if (tag == "name") {
59  name = readName(from);
60  }
61  }
62  // Read the geometry information
64  PositionVector geom;
65  tag = myRead(from); // "ueber"
66  while (tag != "nach") {
67  std::string x = myRead(from);
68  std::string y = myRead(from);
69  if (y != "nach") {
71  Position(
72  TplConvert::_2double(x.c_str()),
73  TplConvert::_2double(y.c_str())
74  ));
75  tag = myRead(from);
76  try {
77  TplConvert::_2double(tag.c_str());
78  tag = myRead(from);
79  } catch (NumberFormatException&) {}
80  } else {
81  tag = y;
82  }
83  }
85  // read some optional values until mandatory "Fahrzeugklassen" occurs
86  double dxnothalt = 0;
87  double dxeinordnen = 0;
88  double zuschlag1, zuschlag2;
89  zuschlag1 = zuschlag2 = 0;
90  double seglength = 0;
91  tag = myRead(from);
92 // NIVissimConnection::Direction direction = NIVissimConnection::NIVC_DIR_ALL;
93  while (tag != "fahrzeugklassen" && tag != "sperrung" && tag != "auswertung" && tag != "DATAEND") {
94  if (tag == "rechts") {
95 // direction = NIVissimConnection::NIVC_DIR_RIGHT;
96  } else if (tag == "links") {
97 // direction = NIVissimConnection::NIVC_DIR_LEFT;
98  } else if (tag == "alle") {
99 // direction = NIVissimConnection::NIVC_DIR_ALL;
100  } else if (tag == "dxnothalt") {
101  from >> dxnothalt; // type-checking is missing!
102  } else if (tag == "dxeinordnen") {
103  from >> dxeinordnen; // type-checking is missing!
104  } else if (tag == "segment") {
105  from >> tag;
106  from >> seglength;
107  }
108  if (tag == "zuschlag") {
109  from >> zuschlag1; // type-checking is missing!
110  tag = readEndSecure(from);
111  if (tag == "zuschlag") {
112  from >> zuschlag2; // type-checking is missing!
113  tag = readEndSecure(from, "auswertung");
114  }
115  } else {
116  tag = readEndSecure(from, "auswertung");
117  }
118  }
119  // read in allowed vehicle classes
120  std::vector<int> assignedVehicles;
121  if (tag == "fahrzeugklassen") {
122  tag = readEndSecure(from);
123  while (tag != "DATAEND" && tag != "sperrung" && tag != "auswertung") {
124  int classes = TplConvert::_2int(tag.c_str());
125  assignedVehicles.push_back(classes);
126  tag = readEndSecure(from, "auswertung");
127  }
128  }
129  // Read definitions of closed lanes
131  if (tag != "DATAEND") {
132  do {
133  // check whether a next close lane definition can be found
134  tag = readEndSecure(from);
135  if (tag == "keinspurwechsel") {
136  while (tag != "DATAEND") {
137  tag = readEndSecure(from);
138  }
139  } else if (tag == "spur") {
140  // get the lane number
141 // from >> tag;
142  int laneNo;
143  from >> laneNo; // unused and type-checking is missing!
144  // get the list of assigned car classes
145  std::vector<int> assignedVehicles;
146  tag = myRead(from);
147  if (tag == "fahrzeugklassen") {
148  tag = myRead(from);
149  }
150  while (tag != "DATAEND" && tag != "spur" && tag != "keinspurwechsel") {
151  int classes = TplConvert::_2int(tag.c_str());
152  assignedVehicles.push_back(classes);
153  tag = readEndSecure(from);
154  }
155  // build and add the definition
156  NIVissimClosedLaneDef* cld = new NIVissimClosedLaneDef(assignedVehicles);
157  clv.push_back(cld);
158  }
159  } while (tag != "DATAEND");
160  }
161  NIVissimConnection* c = new NIVissimConnection(id, name, from_def, to_def, geom,
162  assignedVehicles, clv);
163 
164  if (!NIVissimConnection::dictionary(id, c)) {
165  return false;
166  }
167  return true;
168  //return NIVissimAbstractEdge::dictionary(id, c);
169 }
170 
171 
172 
173 /****************************************************************************/
174 
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)
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:45
A list of positions.
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.
static int _2int(const E *const data)
converts a char-type array into the integer value described by it
Definition: TplConvert.h:155
static double _2double(const E *const data)
converts a char-type array into the double value described by it
Definition: TplConvert.h:311
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 ...