SUMO - Simulation of Urban MObility
NIVissimSingleTypeParser_Verbindungsdefinition.cpp
Go to the documentation of this file.
1 /****************************************************************************/
8 //
9 /****************************************************************************/
10 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
11 // Copyright (C) 2001-2017 DLR (http://www.dlr.de/) and contributors
12 /****************************************************************************/
13 //
14 // This file is part of SUMO.
15 // SUMO is free software: you can redistribute it and/or modify
16 // it under the terms of the GNU General Public License as published by
17 // the Free Software Foundation, either version 3 of the License, or
18 // (at your option) any later version.
19 //
20 /****************************************************************************/
21 
22 
23 // ===========================================================================
24 // included modules
25 // ===========================================================================
26 #ifdef _MSC_VER
27 #include <windows_config.h>
28 #else
29 #include <config.h>
30 #endif
31 
32 #include <iostream>
35 #include "../NIImporter_Vissim.h"
36 #include "../tempstructs/NIVissimConnection.h"
38 
39 
40 // ===========================================================================
41 // method definitions
42 // ===========================================================================
44  : NIImporter_Vissim::VissimSingleTypeParser(parent) {}
45 
46 
48 
49 
50 bool
52  int id;
53  from >> id; // type-checking is missing!
54  std::string tag;
55  // Read optional value "Name", skip optional value "Beschriftung"
56  std::string name;
57  while (tag != "von") {
58  tag = overrideOptionalLabel(from);
59  if (tag == "name") {
60  name = readName(from);
61  }
62  }
63  // Read the geometry information
65  PositionVector geom;
66  tag = myRead(from); // "ueber"
67  while (tag != "nach") {
68  std::string x = myRead(from);
69  std::string y = myRead(from);
70  if (y != "nach") {
72  Position(
73  TplConvert::_2double(x.c_str()),
74  TplConvert::_2double(y.c_str())
75  ));
76  tag = myRead(from);
77  try {
78  TplConvert::_2double(tag.c_str());
79  tag = myRead(from);
80  } catch (NumberFormatException&) {}
81  } else {
82  tag = y;
83  }
84  }
86  // read some optional values until mandatory "Fahrzeugklassen" occurs
87  double dxnothalt = 0;
88  double dxeinordnen = 0;
89  double zuschlag1, zuschlag2;
90  zuschlag1 = zuschlag2 = 0;
91  double seglength = 0;
92  tag = myRead(from);
93 // NIVissimConnection::Direction direction = NIVissimConnection::NIVC_DIR_ALL;
94  while (tag != "fahrzeugklassen" && tag != "sperrung" && tag != "auswertung" && tag != "DATAEND") {
95  if (tag == "rechts") {
96 // direction = NIVissimConnection::NIVC_DIR_RIGHT;
97  } else if (tag == "links") {
98 // direction = NIVissimConnection::NIVC_DIR_LEFT;
99  } else if (tag == "alle") {
100 // direction = NIVissimConnection::NIVC_DIR_ALL;
101  } else if (tag == "dxnothalt") {
102  from >> dxnothalt; // type-checking is missing!
103  } else if (tag == "dxeinordnen") {
104  from >> dxeinordnen; // type-checking is missing!
105  } else if (tag == "segment") {
106  from >> tag;
107  from >> seglength;
108  }
109  if (tag == "zuschlag") {
110  from >> zuschlag1; // type-checking is missing!
111  tag = readEndSecure(from);
112  if (tag == "zuschlag") {
113  from >> zuschlag2; // type-checking is missing!
114  tag = readEndSecure(from, "auswertung");
115  }
116  } else {
117  tag = readEndSecure(from, "auswertung");
118  }
119  }
120  // read in allowed vehicle classes
121  std::vector<int> assignedVehicles;
122  if (tag == "fahrzeugklassen") {
123  tag = readEndSecure(from);
124  while (tag != "DATAEND" && tag != "sperrung" && tag != "auswertung") {
125  int classes = TplConvert::_2int(tag.c_str());
126  assignedVehicles.push_back(classes);
127  tag = readEndSecure(from, "auswertung");
128  }
129  }
130  // Read definitions of closed lanes
132  if (tag != "DATAEND") {
133  do {
134  // check whether a next close lane definition can be found
135  tag = readEndSecure(from);
136  if (tag == "keinspurwechsel") {
137  while (tag != "DATAEND") {
138  tag = readEndSecure(from);
139  }
140  } else if (tag == "spur") {
141  // get the lane number
142 // from >> tag;
143  int laneNo;
144  from >> laneNo; // unused and type-checking is missing!
145  // get the list of assigned car classes
146  std::vector<int> assignedVehicles;
147  tag = myRead(from);
148  if (tag == "fahrzeugklassen") {
149  tag = myRead(from);
150  }
151  while (tag != "DATAEND" && tag != "spur" && tag != "keinspurwechsel") {
152  int classes = TplConvert::_2int(tag.c_str());
153  assignedVehicles.push_back(classes);
154  tag = readEndSecure(from);
155  }
156  // build and add the definition
157  NIVissimClosedLaneDef* cld = new NIVissimClosedLaneDef(assignedVehicles);
158  clv.push_back(cld);
159  }
160  } while (tag != "DATAEND");
161  }
162  NIVissimConnection* c = new NIVissimConnection(id, name, from_def, to_def, geom,
163  assignedVehicles, clv);
164 
165  if (!NIVissimConnection::dictionary(id, c)) {
166  return false;
167  }
168  return true;
169  //return NIVissimAbstractEdge::dictionary(id, c);
170 }
171 
172 
173 
174 /****************************************************************************/
175 
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:46
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:149
static double _2double(const E *const data)
converts a char-type array into the double value described by it
Definition: TplConvert.h:297
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 ...