Path: blob/main/src/netedit/dialogs/GNEACChooserDialog.cpp
169678 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 GNEACChooserDialog.cpp14/// @author Pablo Alvarez Lopez15/// @date Apr 201816///17// Class for the window that allows to choose a street, junction or vehicle18/****************************************************************************/1920#include <netedit/GNENet.h>21#include <netedit/GNEViewParent.h>22#include <utils/gui/globjects/GUIGlObjectStorage.h>2324#include "GNEACChooserDialog.h"2526// ===========================================================================27// method definitions28// ===========================================================================2930GNEACChooserDialog::GNEACChooserDialog(GNEViewParent* viewParent, int messageId,31FXIcon* icon, const std::string& title,32const std::map<std::string, GNEAttributeCarrier*>& ACs):33GUIDialog_ChooserAbstract(viewParent, messageId, icon, title.c_str(),34std::vector<GUIGlID>(), GUIGlObjectStorage::gIDStorage),35myViewParent(viewParent),36myLocateTLS(title.find("TLS") != std::string::npos) {37// fill ACs38myACs.reserve(ACs.size());39myFilteredACs.reserve(ACs.size());40for (const auto& AC : ACs) {41myACs.push_back(AC.second);42myFilteredACs.push_back(AC.second);43}44// @note refresh must be called here because the base class constructor cannot45// call the virtual function getObjectName46std::vector<GUIGlID> ids;47for (const auto& AC : ACs) {48ids.push_back(AC.second->getGUIGlObject()->getGlID());49}50refreshList(ids);51}525354GNEACChooserDialog::~GNEACChooserDialog() {55myViewParent->eraseACChooserDialog(this);56}575859void60GNEACChooserDialog::toggleSelection(int listIndex) {61// always filtered ACs62GNEAttributeCarrier* ac = myFilteredACs[listIndex];63if (ac->isAttributeCarrierSelected()) {64ac->unselectAttributeCarrier();65} else {66ac->selectAttributeCarrier();67}68}697071void72GNEACChooserDialog::select(int listIndex) {73// always filtered ACs74GNEAttributeCarrier* ac = myFilteredACs[listIndex];75if (!ac->isAttributeCarrierSelected()) {76ac->selectAttributeCarrier();77}78}798081void82GNEACChooserDialog::deselect(int listIndex) {83// always filtered ACs84GNEAttributeCarrier* ac = myFilteredACs[listIndex];85if (ac->isAttributeCarrierSelected()) {86ac->unselectAttributeCarrier();87}88}899091void92GNEACChooserDialog::filterACs(const std::vector<GUIGlID>& GLIDs) {93if (GLIDs.empty()) {94myFilteredACs = myACs;95} else {96// clear myFilteredACs97myFilteredACs.clear();98// iterate over myACs99for (const auto& AC : myACs) {100// search in GLIDs101if (std::find(GLIDs.begin(), GLIDs.end(), AC->getGUIGlObject()->getGlID()) != GLIDs.end()) {102myFilteredACs.push_back(AC);103}104}105}106}107108109std::string110GNEACChooserDialog::getObjectName(GUIGlObject* o) const {111// check if we're locating a TLS112if (myLocateTLS) {113// obtain junction114GNEJunction* junction = dynamic_cast<GNEJunction*>(o);115// check that junction exist116if (junction == nullptr) {117throw ProcessError(TL("Invalid Junction"));118}119// get definitions120const std::set<NBTrafficLightDefinition*>& defs = junction->getNBNode()->getControllingTLS();121// check that traffic light exists122if (defs.empty()) {123throw ProcessError(TL("Invalid number of TLSs"));124}125// get TLDefinition126const std::string& tlDefID = (*defs.begin())->getID();127if (tlDefID == o->getMicrosimID()) {128return o->getMicrosimID();129} else {130return tlDefID + " (" + o->getMicrosimID() + ")";131}132} else {133return GUIDialog_ChooserAbstract::getObjectName(o);134}135}136137138/****************************************************************************/139140141