NLSucceedingLaneBuilder.cpp
Go to the documentation of this file.00001
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
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
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
00083 if (laneId=="SUMO_NO_DESTINATION") {
00084
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
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
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
00142
00143 lane->addIncomingLane(via, link);
00144
00145 via->addIncomingLane(MSLane::dictionary(myCurrentLane), link);
00146 } else {
00147 if (myCurrentLane[0]!=':') {
00148
00149 lane->addIncomingLane(MSLane::dictionary(myCurrentLane), link);
00150 }
00151 }
00152 #else
00153 lane->addIncomingLane(MSLane::dictionary(myCurrentLane), link);
00154 #endif
00155 }
00156
00157
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
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