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