void GUIViewTraffic::onGamingClick(Position pos) { MSTLLogicControl& tlsControl = MSNet::getInstance()->getTLSControl(); const std::vector<MSTrafficLightLogic*>& logics = tlsControl.getAllLogics(); MSTrafficLightLogic* minTll = 0; SUMOReal minDist = std::numeric_limits<SUMOReal>::infinity(); for (std::vector<MSTrafficLightLogic*>::const_iterator i = logics.begin(); i != logics.end(); ++i) { // get the logic MSTrafficLightLogic* tll = (*i); if (tlsControl.isActive(tll)) { // get the links const MSTrafficLightLogic::LaneVector& lanes = tll->getLanesAt(0); if (lanes.size() > 0) { const Position& endPos = lanes[0]->getShape().back(); if (endPos.distanceTo(pos) < minDist) { minDist = endPos.distanceTo(pos); minTll = tll; } } } } if (minTll != 0) { const MSTLLogicControl::TLSLogicVariants& vars = tlsControl.get(minTll->getID()); const std::vector<MSTrafficLightLogic*> logics = vars.getAllLogics(); if (logics.size() > 1) { MSSimpleTrafficLightLogic* l = (MSSimpleTrafficLightLogic*) logics[0]; for (unsigned int i = 0; i < logics.size() - 1; ++i) { if (minTll->getProgramID() == logics[i]->getProgramID()) { l = (MSSimpleTrafficLightLogic*) logics[i + 1]; tlsControl.switchTo(minTll->getID(), l->getProgramID()); } } if (l == logics[0]) { tlsControl.switchTo(minTll->getID(), l->getProgramID()); } l->changeStepAndDuration(tlsControl, MSNet::getInstance()->getCurrentTimeStep(), 0, l->getPhase(0).duration); update(); } } }
SUMOTime Command_SaveTLSSwitches::execute(SUMOTime currentTime) { MSTrafficLightLogic* light = myLogics.getActive(); const MSTrafficLightLogic::LinkVectorVector& links = light->getLinks(); const std::string& state = light->getCurrentPhaseDef().getState(); for (unsigned int i = 0; i < (unsigned int) links.size(); i++) { if (state[i] == LINKSTATE_TL_GREEN_MAJOR || state[i] == LINKSTATE_TL_GREEN_MINOR) { if (myPreviousLinkStates.find(i) == myPreviousLinkStates.end()) { // was not saved before myPreviousLinkStates[i] = currentTime; continue; } } else { if (myPreviousLinkStates.find(i) == myPreviousLinkStates.end()) { // was not yet green continue; } const MSTrafficLightLogic::LinkVector& currLinks = links[i]; const MSTrafficLightLogic::LaneVector& currLanes = light->getLanesAt(i); SUMOTime lastOn = myPreviousLinkStates[i]; for (int j = 0; j < (int) currLinks.size(); j++) { MSLink* link = currLinks[j]; myOutputDevice << " <tlsSwitch id=\"" << light->getID() << "\" programID=\"" << light->getProgramID() << "\" fromLane=\"" << currLanes[j]->getID() << "\" toLane=\"" << link->getLane()->getID() << "\" begin=\"" << time2string(lastOn) << "\" end=\"" << time2string(currentTime) << "\" duration=\"" << time2string(currentTime - lastOn) << "\"/>\n"; } myPreviousLinkStates.erase(myPreviousLinkStates.find(i)); } } return DELTA_T; }