|
SUMO - Simulation of Urban MObility
|
00001 /****************************************************************************/ 00007 // Interface for building edges 00008 /****************************************************************************/ 00009 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/ 00010 // Copyright (C) 2001-2011 DLR (http://www.dlr.de/) and contributors 00011 /****************************************************************************/ 00012 // 00013 // This program is free software; you can redistribute it and/or modify 00014 // it under the terms of the GNU General Public License as published by 00015 // the Free Software Foundation; either version 2 of the License, or 00016 // (at your option) any later version. 00017 // 00018 /****************************************************************************/ 00019 00020 00021 // =========================================================================== 00022 // included modules 00023 // =========================================================================== 00024 #ifdef _MSC_VER 00025 #include <windows_config.h> 00026 #else 00027 #include <config.h> 00028 #endif 00029 00030 #include <vector> 00031 #include <string> 00032 #include <map> 00033 #include <algorithm> 00034 #include <iterator> 00035 #include <microsim/MSLane.h> 00036 #include <microsim/MSInternalLane.h> 00037 #include <microsim/MSEdge.h> 00038 #include <microsim/MSEdgeControl.h> 00039 #include <utils/common/StringTokenizer.h> 00040 #include <utils/common/UtilExceptions.h> 00041 #include "NLBuilder.h" 00042 #include "NLEdgeControlBuilder.h" 00043 #include <utils/options/OptionsCont.h> 00044 #include <utils/iodevices/OutputDevice.h> 00045 00046 #ifdef HAVE_MESOSIM 00047 #include <mesosim/MELoop.h> 00048 #endif 00049 00050 #ifdef CHECK_MEMORY_LEAKS 00051 #include <foreign/nvwa/debug_new.h> 00052 #endif // CHECK_MEMORY_LEAKS 00053 00054 00055 // =========================================================================== 00056 // method definitions 00057 // =========================================================================== 00058 NLEdgeControlBuilder::NLEdgeControlBuilder() 00059 : myCurrentNumericalLaneID(0), myCurrentNumericalEdgeID(0), myEdges(0) { 00060 myActiveEdge = (MSEdge*) 0; 00061 myLaneStorage = new std::vector<MSLane*>(); 00062 } 00063 00064 00065 NLEdgeControlBuilder::~NLEdgeControlBuilder() { 00066 delete myLaneStorage; 00067 } 00068 00069 00070 void 00071 NLEdgeControlBuilder::beginEdgeParsing( 00072 const std::string& id, MSEdge::EdgeBasicFunction function, 00073 const std::string& streetName) { 00074 myActiveEdge = buildEdge(id, streetName); 00075 if (MSEdge::dictionary(id) != 0) { 00076 throw InvalidArgument("Another edge with the id '" + id + "' exists."); 00077 } 00078 myEdges.push_back(myActiveEdge); 00079 myFunction = function; 00080 } 00081 00082 00083 MSLane* 00084 NLEdgeControlBuilder::addLane(const std::string& id, 00085 SUMOReal maxSpeed, SUMOReal length, 00086 const PositionVector& shape, SUMOReal width, 00087 const SUMOVehicleClasses& allowed, 00088 const SUMOVehicleClasses& disallowed) { 00089 MSLane* lane = 0; 00090 switch (myFunction) { 00091 case MSEdge::EDGEFUNCTION_INTERNAL: 00092 lane = new MSInternalLane(id, maxSpeed, length, myActiveEdge, 00093 myCurrentNumericalLaneID++, shape, width, allowed, disallowed); 00094 break; 00095 case MSEdge::EDGEFUNCTION_NORMAL: 00096 case MSEdge::EDGEFUNCTION_CONNECTOR: 00097 lane = new MSLane(id, maxSpeed, length, myActiveEdge, 00098 myCurrentNumericalLaneID++, shape, width, allowed, disallowed); 00099 break; 00100 default: 00101 throw InvalidArgument("Unrecognised edge type."); 00102 } 00103 myLaneStorage->push_back(lane); 00104 return lane; 00105 } 00106 00107 00108 MSEdge* 00109 NLEdgeControlBuilder::closeEdge() { 00110 std::vector<MSLane*> *lanes = new std::vector<MSLane*>(); 00111 lanes->reserve(myLaneStorage->size()); 00112 copy(myLaneStorage->begin(), myLaneStorage->end(), back_inserter(*lanes)); 00113 myLaneStorage->clear(); 00114 myActiveEdge->initialize(lanes, myFunction); 00115 return myActiveEdge; 00116 } 00117 00118 00119 MSEdgeControl* 00120 NLEdgeControlBuilder::build() { 00121 for (EdgeCont::iterator i1=myEdges.begin(); i1!=myEdges.end(); i1++) { 00122 (*i1)->closeBuilding(); 00123 #ifdef HAVE_MESOSIM 00124 if (MSGlobals::gUseMesoSim) { 00125 MSGlobals::gMesoNet->buildSegmentsFor(**i1, OptionsCont::getOptions()); 00126 } 00127 #endif 00128 } 00129 return new MSEdgeControl(myEdges); 00130 } 00131 00132 00133 MSEdge* 00134 NLEdgeControlBuilder::buildEdge(const std::string& id, const std::string& streetName) throw() { 00135 return new MSEdge(id, myCurrentNumericalEdgeID++, streetName); 00136 } 00137 00138 00139 00140 /****************************************************************************/ 00141