SUMO - Simulation of Urban MObility
|
00001 /****************************************************************************/ 00009 // Temporary storage for a lanes succeeding lanes while parsing them 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 <string> 00034 #include <map> 00035 #include <vector> 00036 #include <iterator> 00037 #include <microsim/MSLane.h> 00038 #include <microsim/MSInternalLane.h> 00039 #include <microsim/MSLink.h> 00040 #include <microsim/MSLinkCont.h> 00041 #include <microsim/MSGlobals.h> 00042 #include <microsim/traffic_lights/MSTrafficLightLogic.h> 00043 #include "NLBuilder.h" 00044 #include "NLSucceedingLaneBuilder.h" 00045 #include "NLJunctionControlBuilder.h" 00046 #include <utils/options/OptionsCont.h> 00047 #include <utils/common/UtilExceptions.h> 00048 #include <utils/geom/GeomHelper.h> 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 NLSucceedingLaneBuilder::NLSucceedingLaneBuilder(NLJunctionControlBuilder& jb) 00059 : myJunctionControlBuilder(jb) { 00060 mySuccLanes = new MSLinkCont(); 00061 mySuccLanes->reserve(10); 00062 } 00063 00064 00065 NLSucceedingLaneBuilder::~NLSucceedingLaneBuilder() { 00066 delete mySuccLanes; 00067 } 00068 00069 00070 void 00071 NLSucceedingLaneBuilder::openSuccLane(const std::string& laneId) { 00072 myCurrentLane = laneId; 00073 } 00074 00075 00076 void 00077 NLSucceedingLaneBuilder::addSuccLane(const std::string& laneId, 00078 #ifdef HAVE_INTERNAL_LANES 00079 const std::string& viaID, 00080 SUMOReal pass, 00081 #endif 00082 LinkDirection dir, 00083 LinkState state, 00084 const std::string& tlid, unsigned int linkNo) throw(InvalidArgument) { 00085 // check whether the link is a dead link 00086 if (laneId == "SUMO_NO_DESTINATION") { 00087 // build the dead link and add it to the container 00088 #ifdef HAVE_INTERNAL_LANES 00089 MSLink* link = new MSLink(0, 0, LINKDIR_NODIR, LINKSTATE_DEADEND, 0.); 00090 #else 00091 MSLink* link = new MSLink(0, LINKDIR_NODIR, LINKSTATE_DEADEND, 0.); 00092 #endif 00093 mySuccLanes->push_back(link); 00094 if (tlid != "") { 00095 MSTLLogicControl::TLSLogicVariants& logics = myJunctionControlBuilder.getTLLogic(tlid); 00096 MSLane* current = MSLane::dictionary(myCurrentLane); 00097 if (current == 0) { 00098 throw InvalidArgument("An unknown lane ('" + myCurrentLane + "') should be assigned to a tl-logic."); 00099 } 00100 logics.addLink(link, current, linkNo); 00101 } 00102 return; 00103 } 00104 00105 // get the lane the link belongs to 00106 MSLane* lane = MSLane::dictionary(laneId); 00107 if (lane == 0) { 00108 throw InvalidArgument("An unknown lane ('" + laneId + "') should be set as a follower for lane '" + myCurrentLane + "'."); 00109 } 00110 #ifdef HAVE_INTERNAL_LANES 00111 MSLane* via = 0; 00112 if (viaID != "" && MSGlobals::gUsingInternalLanes) { 00113 via = MSLane::dictionary(viaID); 00114 if (via == 0) { 00115 throw InvalidArgument("An unknown lane ('" + viaID + "') should be set as a via-lane for lane '" + myCurrentLane + "'."); 00116 } 00117 } 00118 if (pass >= 0) { 00119 static_cast<MSInternalLane*>(lane)->setPassPosition(pass); 00120 } 00121 #endif 00122 MSLane* orig = MSLane::dictionary(myCurrentLane); 00123 if (orig == 0) { 00124 return; 00125 } 00126 00127 00128 // build the link 00129 SUMOReal length = orig != 0 && lane != 0 00130 ? orig->getShape()[-1].distanceTo(lane->getShape()[0]) 00131 : 0; 00132 #ifdef HAVE_INTERNAL_LANES 00133 if (via != 0) { 00134 length = via->getLength(); 00135 } 00136 MSLink* link = new MSLink(lane, via, dir, state, length); 00137 #else 00138 MSLink* link = new MSLink(lane, dir, state, length); 00139 #endif 00140 00141 MSLane* clane = MSLane::dictionary(myCurrentLane); 00142 if (clane != 0) { 00143 #ifdef HAVE_INTERNAL_LANES 00144 if (via != 0) { 00145 via->addIncomingLane(clane, link); 00146 } else { 00147 lane->addIncomingLane(clane, link); 00148 } 00149 #else 00150 lane->addIncomingLane(clane, link); 00151 #endif 00152 lane->addApproachingLane(clane); 00153 } 00154 // if a traffic light is responsible for it, inform the traffic light 00155 // check whether this link is controlled by a traffic light 00156 if (tlid != "") { 00157 MSTLLogicControl::TLSLogicVariants& logics = myJunctionControlBuilder.getTLLogic(tlid); 00158 MSLane* current = MSLane::dictionary(myCurrentLane); 00159 if (current == 0) { 00160 throw InvalidArgument("An unknown lane ('" + myCurrentLane + "') should be assigned to a tl-logic."); 00161 } 00162 logics.addLink(link, current, linkNo); 00163 } 00164 // add the link to the container 00165 mySuccLanes->push_back(link); 00166 } 00167 00168 00169 void 00170 NLSucceedingLaneBuilder::closeSuccLane() throw(InvalidArgument) { 00171 MSLane* current = MSLane::dictionary(myCurrentLane); 00172 if (current == 0) { 00173 throw InvalidArgument("Trying to close connections of an unknown lane ('" + myCurrentLane + "')."); 00174 } 00175 MSLinkCont* cont = new MSLinkCont(); 00176 cont->reserve(mySuccLanes->size()); 00177 copy(mySuccLanes->begin(), mySuccLanes->end(), back_inserter(*cont)); 00178 current->initialize(cont); 00179 mySuccLanes->clear(); 00180 } 00181 00182 00183 const std::string& 00184 NLSucceedingLaneBuilder::getCurrentLaneName() const { 00185 return myCurrentLane; 00186 } 00187 00188 00189 00190 /****************************************************************************/ 00191