Path: blob/main/src/guisim/Command_Hotkey_TrafficLight.cpp
169666 views
/****************************************************************************/1// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo2// Copyright (C) 2001-2025 German Aerospace Center (DLR) and others.3// This program and the accompanying materials are made available under the4// terms of the Eclipse Public License 2.0 which is available at5// https://www.eclipse.org/legal/epl-2.0/6// This Source Code may also be made available under the following Secondary7// Licenses when the conditions for such availability set forth in the Eclipse8// Public License 2.0 are satisfied: GNU General Public License, version 29// or later which is available at10// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html11// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later12/****************************************************************************/13/// @file Command_Hotkey_TrafficLight.cpp14/// @author Jakob Erdmann15/// @date 31 Jan 202216///17// Registers custom hotkey for aborting current traffic light phase18/****************************************************************************/19#include <config.h>2021#include <fxkeys.h>22#include <microsim/traffic_lights/MSTrafficLightLogic.h>23#include <guisim/GUINet.h>24#include "Command_Hotkey_TrafficLight.h"252627// ===========================================================================28// method definitions29// ===========================================================================30Command_Hotkey_TrafficLight::Command_Hotkey_TrafficLight(MSTrafficLightLogic& tll) :31myLogic(tll)32{ }333435Command_Hotkey_TrafficLight::~Command_Hotkey_TrafficLight() { }363738SUMOTime39Command_Hotkey_TrafficLight::execute(SUMOTime currentTime) {40int next = (myLogic.getCurrentPhaseIndex() + 1) % myLogic.getPhaseNumber();41myLogic.changeStepAndDuration(MSNet::getInstance()->getTLSControl(), currentTime, next, -1);42return 1;43}444546bool47Command_Hotkey_TrafficLight::registerHotkey(const std::string& key, MSTrafficLightLogic& tll) {48int hotkey = -1;49if (key.size() == 1) {50char c = key[0];51if ('a' <= c && c <= 'z') {52// see FXAccelTable::parseAccel53hotkey = c + FX::KEY_space - ' ';54} else {55WRITE_WARNINGF(TL("Hotkey '%' is not supported"), key);56return false;57}58} else {59WRITE_WARNINGF(TL("Hotkey '%' is not supported"), key);60return false;61}62GUINet* gn = dynamic_cast<GUINet*>(MSNet::getInstance());63if (gn != nullptr) {64gn->addHotkey(hotkey, new Command_Hotkey_TrafficLight(tll));65}66return true;67}686970/****************************************************************************/717273