SUMO - Simulation of Urban MObility

NLSucceedingLaneBuilder.cpp

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