SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
NLEdgeControlBuilder.cpp
Go to the documentation of this file.
1 /****************************************************************************/
9 // Interface for building edges
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 <vector>
34 #include <string>
35 #include <map>
36 #include <algorithm>
37 #include <iterator>
38 #include <microsim/MSLane.h>
40 #include <microsim/MSEdge.h>
41 #include <microsim/MSEdgeControl.h>
44 #include "NLBuilder.h"
45 #include "NLEdgeControlBuilder.h"
48 
49 #ifdef HAVE_INTERNAL
50 #include <mesosim/MELoop.h>
51 #endif
52 
53 #ifdef CHECK_MEMORY_LEAKS
54 #include <foreign/nvwa/debug_new.h>
55 #endif // CHECK_MEMORY_LEAKS
56 
57 
58 // ===========================================================================
59 // method definitions
60 // ===========================================================================
62  : myCurrentNumericalLaneID(0), myCurrentNumericalEdgeID(0), myEdges(0) {
63  myActiveEdge = (MSEdge*) 0;
64  myLaneStorage = new std::vector<MSLane*>();
65 }
66 
67 
69  delete myLaneStorage;
70 }
71 
72 
73 void
75  const std::string& id, const MSEdge::EdgeBasicFunction function,
76  const std::string& streetName) {
77  myActiveEdge = buildEdge(id, function, streetName);
78  if (MSEdge::dictionary(id) != 0) {
79  throw InvalidArgument("Another edge with the id '" + id + "' exists.");
80  }
81  myEdges.push_back(myActiveEdge);
82 }
83 
84 
85 MSLane*
86 NLEdgeControlBuilder::addLane(const std::string& id,
87  SUMOReal maxSpeed, SUMOReal length,
88  const PositionVector& shape, SUMOReal width,
89  SVCPermissions permissions) {
90  MSLane* lane = 0;
91  switch (myActiveEdge->getPurpose()) {
93  lane = new MSInternalLane(id, maxSpeed, length, myActiveEdge,
94  myCurrentNumericalLaneID++, shape, width, permissions);
95  break;
98  lane = new MSLane(id, maxSpeed, length, myActiveEdge,
99  myCurrentNumericalLaneID++, shape, width, permissions);
100  break;
101  default:
102  throw InvalidArgument("Unrecognised edge type.");
103  }
104  myLaneStorage->push_back(lane);
105  return lane;
106 }
107 
108 
109 MSEdge*
111  std::vector<MSLane*>* lanes = new std::vector<MSLane*>();
112  lanes->reserve(myLaneStorage->size());
113  copy(myLaneStorage->begin(), myLaneStorage->end(), back_inserter(*lanes));
114  myLaneStorage->clear();
115  myActiveEdge->initialize(lanes);
116  return myActiveEdge;
117 }
118 
119 
122  for (EdgeCont::iterator i1 = myEdges.begin(); i1 != myEdges.end(); i1++) {
123  (*i1)->closeBuilding();
124 #ifdef HAVE_INTERNAL
126  MSGlobals::gMesoNet->buildSegmentsFor(**i1, OptionsCont::getOptions());
127  }
128 #endif
129  }
130  return new MSEdgeControl(myEdges);
131 }
132 
133 
134 MSEdge*
135 NLEdgeControlBuilder::buildEdge(const std::string& id, const MSEdge::EdgeBasicFunction function, const std::string& streetName) {
136  if (function == MSEdge::EDGEFUNCTION_INTERNAL) {
137  return new MSEdge(id, -1, function, streetName);
138  }
139  return new MSEdge(id, myCurrentNumericalEdgeID++, function, streetName);
140 }
141 
142 
143 
144 /****************************************************************************/
145