Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/netedit/dialogs/GNEACChooserDialog.cpp
169678 views
1
/****************************************************************************/
2
// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3
// Copyright (C) 2001-2025 German Aerospace Center (DLR) and others.
4
// This program and the accompanying materials are made available under the
5
// terms of the Eclipse Public License 2.0 which is available at
6
// https://www.eclipse.org/legal/epl-2.0/
7
// This Source Code may also be made available under the following Secondary
8
// Licenses when the conditions for such availability set forth in the Eclipse
9
// Public License 2.0 are satisfied: GNU General Public License, version 2
10
// or later which is available at
11
// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13
/****************************************************************************/
14
/// @file GNEACChooserDialog.cpp
15
/// @author Pablo Alvarez Lopez
16
/// @date Apr 2018
17
///
18
// Class for the window that allows to choose a street, junction or vehicle
19
/****************************************************************************/
20
21
#include <netedit/GNENet.h>
22
#include <netedit/GNEViewParent.h>
23
#include <utils/gui/globjects/GUIGlObjectStorage.h>
24
25
#include "GNEACChooserDialog.h"
26
27
// ===========================================================================
28
// method definitions
29
// ===========================================================================
30
31
GNEACChooserDialog::GNEACChooserDialog(GNEViewParent* viewParent, int messageId,
32
FXIcon* icon, const std::string& title,
33
const std::map<std::string, GNEAttributeCarrier*>& ACs):
34
GUIDialog_ChooserAbstract(viewParent, messageId, icon, title.c_str(),
35
std::vector<GUIGlID>(), GUIGlObjectStorage::gIDStorage),
36
myViewParent(viewParent),
37
myLocateTLS(title.find("TLS") != std::string::npos) {
38
// fill ACs
39
myACs.reserve(ACs.size());
40
myFilteredACs.reserve(ACs.size());
41
for (const auto& AC : ACs) {
42
myACs.push_back(AC.second);
43
myFilteredACs.push_back(AC.second);
44
}
45
// @note refresh must be called here because the base class constructor cannot
46
// call the virtual function getObjectName
47
std::vector<GUIGlID> ids;
48
for (const auto& AC : ACs) {
49
ids.push_back(AC.second->getGUIGlObject()->getGlID());
50
}
51
refreshList(ids);
52
}
53
54
55
GNEACChooserDialog::~GNEACChooserDialog() {
56
myViewParent->eraseACChooserDialog(this);
57
}
58
59
60
void
61
GNEACChooserDialog::toggleSelection(int listIndex) {
62
// always filtered ACs
63
GNEAttributeCarrier* ac = myFilteredACs[listIndex];
64
if (ac->isAttributeCarrierSelected()) {
65
ac->unselectAttributeCarrier();
66
} else {
67
ac->selectAttributeCarrier();
68
}
69
}
70
71
72
void
73
GNEACChooserDialog::select(int listIndex) {
74
// always filtered ACs
75
GNEAttributeCarrier* ac = myFilteredACs[listIndex];
76
if (!ac->isAttributeCarrierSelected()) {
77
ac->selectAttributeCarrier();
78
}
79
}
80
81
82
void
83
GNEACChooserDialog::deselect(int listIndex) {
84
// always filtered ACs
85
GNEAttributeCarrier* ac = myFilteredACs[listIndex];
86
if (ac->isAttributeCarrierSelected()) {
87
ac->unselectAttributeCarrier();
88
}
89
}
90
91
92
void
93
GNEACChooserDialog::filterACs(const std::vector<GUIGlID>& GLIDs) {
94
if (GLIDs.empty()) {
95
myFilteredACs = myACs;
96
} else {
97
// clear myFilteredACs
98
myFilteredACs.clear();
99
// iterate over myACs
100
for (const auto& AC : myACs) {
101
// search in GLIDs
102
if (std::find(GLIDs.begin(), GLIDs.end(), AC->getGUIGlObject()->getGlID()) != GLIDs.end()) {
103
myFilteredACs.push_back(AC);
104
}
105
}
106
}
107
}
108
109
110
std::string
111
GNEACChooserDialog::getObjectName(GUIGlObject* o) const {
112
// check if we're locating a TLS
113
if (myLocateTLS) {
114
// obtain junction
115
GNEJunction* junction = dynamic_cast<GNEJunction*>(o);
116
// check that junction exist
117
if (junction == nullptr) {
118
throw ProcessError(TL("Invalid Junction"));
119
}
120
// get definitions
121
const std::set<NBTrafficLightDefinition*>& defs = junction->getNBNode()->getControllingTLS();
122
// check that traffic light exists
123
if (defs.empty()) {
124
throw ProcessError(TL("Invalid number of TLSs"));
125
}
126
// get TLDefinition
127
const std::string& tlDefID = (*defs.begin())->getID();
128
if (tlDefID == o->getMicrosimID()) {
129
return o->getMicrosimID();
130
} else {
131
return tlDefID + " (" + o->getMicrosimID() + ")";
132
}
133
} else {
134
return GUIDialog_ChooserAbstract::getObjectName(o);
135
}
136
}
137
138
139
/****************************************************************************/
140
141