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 2001-2010 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 <microsim/MSLane.h>
00034 #include <microsim/MSInternalLane.h>
00035 #include <microsim/MSLink.h>
00036 #include <microsim/MSLinkCont.h>
00037 #include <microsim/MSGlobals.h>
00038 #include <microsim/traffic_lights/MSTrafficLightLogic.h>
00039 #include "NLBuilder.h"
00040 #include "NLSucceedingLaneBuilder.h"
00041 #include "NLJunctionControlBuilder.h"
00042 #include <utils/options/OptionsCont.h>
00043 #include <utils/common/UtilExceptions.h>
00044 #include <utils/geom/GeomHelper.h>
00045 
00046 #ifdef CHECK_MEMORY_LEAKS
00047 #include <foreign/nvwa/debug_new.h>
00048 #endif // CHECK_MEMORY_LEAKS
00049 
00050 
00051 // ===========================================================================
00052 // method definitions
00053 // ===========================================================================
00054 NLSucceedingLaneBuilder::NLSucceedingLaneBuilder(NLJunctionControlBuilder &jb) throw()
00055         : myJunctionControlBuilder(jb) {
00056     mySuccLanes = new MSLinkCont();
00057     mySuccLanes->reserve(10);
00058 }
00059 
00060 
00061 NLSucceedingLaneBuilder::~NLSucceedingLaneBuilder() throw() {
00062     delete mySuccLanes;
00063 }
00064 
00065 
00066 void
00067 NLSucceedingLaneBuilder::openSuccLane(const std::string &laneId) throw() {
00068     myCurrentLane = laneId;
00069 }
00070 
00071 
00072 void
00073 NLSucceedingLaneBuilder::addSuccLane(bool yield, const std::string &laneId,
00074 #ifdef HAVE_INTERNAL_LANES
00075                                      const std::string &viaID,
00076                                      SUMOReal pass,
00077 #endif
00078                                      MSLink::LinkDirection dir,
00079                                      MSLink::LinkState state,
00080                                      bool internalEnd,
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, yield, MSLink::LINKDIR_NODIR, MSLink::LINKSTATE_DEADEND, false, 0.);
00087 #else
00088         MSLink *link = new MSLink(0, yield, MSLink::LINKDIR_NODIR, MSLink::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, yield, dir, state, internalEnd, length);
00134 #else
00135     MSLink *link = new MSLink(lane, yield, dir, state, length);
00136 #endif
00137 
00138     if (MSLane::dictionary(myCurrentLane)!=0) {
00139 #ifdef HAVE_INTERNAL_LANES
00140         if (via!=0) {
00141             // from a normal in to a normal out via
00142             //  --> via incomes in out
00143             lane->addIncomingLane(via, link);
00144             //  --> in incomes in via
00145             via->addIncomingLane(MSLane::dictionary(myCurrentLane), link);
00146         } else {
00147             if (myCurrentLane[0]!=':') {
00148                 // internal not wished; other case already set
00149                 lane->addIncomingLane(MSLane::dictionary(myCurrentLane), link);
00150             }
00151         }
00152 #else
00153         lane->addIncomingLane(MSLane::dictionary(myCurrentLane), link);
00154 #endif
00155     }
00156     // if a traffic light is responsible for it, inform the traffic light
00157     // check whether this link is controlled by a traffic light
00158     if (tlid!="") {
00159         MSTLLogicControl::TLSLogicVariants &logics = myJunctionControlBuilder.getTLLogic(tlid);
00160         MSLane *current = MSLane::dictionary(myCurrentLane);
00161         if (current==0) {
00162             throw InvalidArgument("An unknown lane ('" + myCurrentLane + "') should be assigned to a tl-logic.");
00163         }
00164         logics.addLink(link, current, linkNo);
00165     }
00166     // add the link to the container
00167     mySuccLanes->push_back(link);
00168 }
00169 
00170 
00171 void
00172 NLSucceedingLaneBuilder::closeSuccLane() throw(InvalidArgument) {
00173     MSLane *current = MSLane::dictionary(myCurrentLane);
00174     if (current==0) {
00175         throw InvalidArgument("Trying to close connections of an unknown lane ('" + myCurrentLane + "').");
00176     }
00177     MSLinkCont *cont = new MSLinkCont();
00178     cont->reserve(mySuccLanes->size());
00179     copy(mySuccLanes->begin(), mySuccLanes->end(), back_inserter(*cont));
00180     current->initialize(cont);
00181     mySuccLanes->clear();
00182 }
00183 
00184 
00185 const std::string &
00186 NLSucceedingLaneBuilder::getCurrentLaneName() const throw() {
00187     return myCurrentLane;
00188 }
00189 
00190 
00191 
00192 /****************************************************************************/
00193 

Generated on Wed May 5 00:06:35 2010 for Sumo - Simulation of Urban MObility by  doxygen 1.5.6