SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
NLSucceedingLaneBuilder.cpp
Go to the documentation of this file.
1 /****************************************************************************/
9 // Temporary storage for a lanes succeeding lanes while parsing them
10 /****************************************************************************/
11 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/
12 // Copyright (C) 2001-2012 DLR (http://www.dlr.de/) and contributors
13 /****************************************************************************/
14 //
15 // This file is part of SUMO.
16 // SUMO is free software: you can redistribute it and/or modify
17 // it under the terms of the GNU General Public License as published by
18 // the Free Software Foundation, either version 3 of the License, or
19 // (at your option) any later version.
20 //
21 /****************************************************************************/
22 
23 
24 // ===========================================================================
25 // included modules
26 // ===========================================================================
27 #ifdef _MSC_VER
28 #include <windows_config.h>
29 #else
30 #include <config.h>
31 #endif
32 
33 #include <string>
34 #include <map>
35 #include <vector>
36 #include <iterator>
37 #include <microsim/MSLane.h>
39 #include <microsim/MSLink.h>
40 #include <microsim/MSLinkCont.h>
41 #include <microsim/MSGlobals.h>
43 #include "NLBuilder.h"
48 #include <utils/geom/GeomHelper.h>
49 
50 #ifdef CHECK_MEMORY_LEAKS
51 #include <foreign/nvwa/debug_new.h>
52 #endif // CHECK_MEMORY_LEAKS
53 
54 
55 // ===========================================================================
56 // method definitions
57 // ===========================================================================
59  : myJunctionControlBuilder(jb) {
60  mySuccLanes = new MSLinkCont();
61  mySuccLanes->reserve(10);
62 }
63 
64 
66  delete mySuccLanes;
67 }
68 
69 
70 void
71 NLSucceedingLaneBuilder::openSuccLane(const std::string& laneId) {
72  myCurrentLane = laneId;
73 }
74 
75 
76 void
77 NLSucceedingLaneBuilder::addSuccLane(const std::string& laneId,
79  const std::string& viaID,
80  SUMOReal pass,
81 #endif
82  LinkDirection dir,
83  LinkState state,
84  const std::string& tlid, unsigned int linkNo) throw(InvalidArgument) {
85  // check whether the link is a dead link
86  if (laneId == "SUMO_NO_DESTINATION") {
87  // build the dead link and add it to the container
88 #ifdef HAVE_INTERNAL_LANES
89  MSLink* link = new MSLink(0, 0, LINKDIR_NODIR, LINKSTATE_DEADEND, 0.);
90 #else
91  MSLink* link = new MSLink(0, LINKDIR_NODIR, LINKSTATE_DEADEND, 0.);
92 #endif
93  mySuccLanes->push_back(link);
94  if (tlid != "") {
95  MSTLLogicControl::TLSLogicVariants& logics = myJunctionControlBuilder.getTLLogic(tlid);
96  MSLane* current = MSLane::dictionary(myCurrentLane);
97  if (current == 0) {
98  throw InvalidArgument("An unknown lane ('" + myCurrentLane + "') should be assigned to a tl-logic.");
99  }
100  logics.addLink(link, current, linkNo);
101  }
102  return;
103  }
104 
105  // get the lane the link belongs to
106  MSLane* lane = MSLane::dictionary(laneId);
107  if (lane == 0) {
108  throw InvalidArgument("An unknown lane ('" + laneId + "') should be set as a follower for lane '" + myCurrentLane + "'.");
109  }
110 #ifdef HAVE_INTERNAL_LANES
111  MSLane* via = 0;
112  if (viaID != "" && MSGlobals::gUsingInternalLanes) {
113  via = MSLane::dictionary(viaID);
114  if (via == 0) {
115  throw InvalidArgument("An unknown lane ('" + viaID + "') should be set as a via-lane for lane '" + myCurrentLane + "'.");
116  }
117  }
118  if (pass >= 0) {
119  static_cast<MSInternalLane*>(lane)->setPassPosition(pass);
120  }
121 #endif
122  MSLane* orig = MSLane::dictionary(myCurrentLane);
123  if (orig == 0) {
124  return;
125  }
126 
127 
128  // build the link
129  SUMOReal length = orig != 0 && lane != 0
130  ? orig->getShape()[-1].distanceTo(lane->getShape()[0])
131  : 0;
132 #ifdef HAVE_INTERNAL_LANES
133  if (via != 0) {
134  length = via->getLength();
135  }
136  MSLink* link = new MSLink(lane, via, dir, state, length);
137 #else
138  MSLink* link = new MSLink(lane, dir, state, length);
139 #endif
140 
141  MSLane* clane = MSLane::dictionary(myCurrentLane);
142  if (clane != 0) {
143 #ifdef HAVE_INTERNAL_LANES
144  if (via != 0) {
145  via->addIncomingLane(clane, link);
146  } else {
147  lane->addIncomingLane(clane, link);
148  }
149 #else
150  lane->addIncomingLane(clane, link);
151 #endif
152  lane->addApproachingLane(clane);
153  }
154  // if a traffic light is responsible for it, inform the traffic light
155  // check whether this link is controlled by a traffic light
156  if (tlid != "") {
157  MSTLLogicControl::TLSLogicVariants& logics = myJunctionControlBuilder.getTLLogic(tlid);
158  MSLane* current = MSLane::dictionary(myCurrentLane);
159  if (current == 0) {
160  throw InvalidArgument("An unknown lane ('" + myCurrentLane + "') should be assigned to a tl-logic.");
161  }
162  logics.addLink(link, current, linkNo);
163  }
164  // add the link to the container
165  mySuccLanes->push_back(link);
166 }
167 
168 
169 void
172  if (current == 0) {
173  throw InvalidArgument("Trying to close connections of an unknown lane ('" + myCurrentLane + "').");
174  }
175  MSLinkCont* cont = new MSLinkCont();
176  cont->reserve(mySuccLanes->size());
177  copy(mySuccLanes->begin(), mySuccLanes->end(), back_inserter(*cont));
178  current->initialize(cont);
179  mySuccLanes->clear();
180 }
181 
182 
183 const std::string&
185  return myCurrentLane;
186 }
187 
188 
189 
190 /****************************************************************************/
191