Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/netedit/frames/GNEPlanSelector.cpp
193674 views
1
/****************************************************************************/
2
// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3
// Copyright (C) 2001-2026 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 GNEPlanSelector.cpp
15
/// @author Pablo Alvarez Lopez
16
/// @date Sep 2023
17
///
18
// Frame for select person/container plans
19
/****************************************************************************/
20
21
#include <netedit/elements/additional/GNEAccess.h>
22
#include <netedit/elements/additional/GNEBusStop.h>
23
#include <netedit/elements/additional/GNECalibrator.h>
24
#include <netedit/elements/additional/GNECalibratorFlow.h>
25
#include <netedit/elements/additional/GNEChargingStation.h>
26
#include <netedit/elements/additional/GNEClosingLaneReroute.h>
27
#include <netedit/elements/additional/GNEClosingReroute.h>
28
#include <netedit/elements/additional/GNEContainerStop.h>
29
#include <netedit/elements/additional/GNEDestProbReroute.h>
30
#include <netedit/elements/additional/GNEEntryExitDetector.h>
31
#include <netedit/elements/additional/GNEInductionLoopDetector.h>
32
#include <netedit/elements/additional/GNEInstantInductionLoopDetector.h>
33
#include <netedit/elements/additional/GNELaneAreaDetector.h>
34
#include <netedit/elements/additional/GNEMultiEntryExitDetector.h>
35
#include <netedit/elements/additional/GNEOverheadWire.h>
36
#include <netedit/elements/additional/GNEParkingArea.h>
37
#include <netedit/elements/additional/GNEParkingAreaReroute.h>
38
#include <netedit/elements/additional/GNEParkingSpace.h>
39
#include <netedit/elements/additional/GNEPOI.h>
40
#include <netedit/elements/additional/GNEPoly.h>
41
#include <netedit/elements/additional/GNERerouter.h>
42
#include <netedit/elements/additional/GNERerouterInterval.h>
43
#include <netedit/elements/additional/GNERouteProbe.h>
44
#include <netedit/elements/additional/GNERouteProbReroute.h>
45
#include <netedit/elements/additional/GNETAZ.h>
46
#include <netedit/elements/additional/GNETAZSourceSink.h>
47
#include <netedit/elements/additional/GNETractionSubstation.h>
48
#include <netedit/elements/additional/GNEVaporizer.h>
49
#include <netedit/elements/additional/GNEVariableSpeedSign.h>
50
#include <netedit/elements/additional/GNEVariableSpeedSignStep.h>
51
#include <netedit/elements/demand/GNEContainer.h>
52
#include <netedit/elements/demand/GNEPerson.h>
53
#include <netedit/elements/demand/GNEPersonTrip.h>
54
#include <netedit/elements/demand/GNERide.h>
55
#include <netedit/elements/demand/GNERoute.h>
56
#include <netedit/elements/demand/GNEStop.h>
57
#include <netedit/elements/demand/GNEStopPlan.h>
58
#include <netedit/elements/demand/GNETranship.h>
59
#include <netedit/elements/demand/GNETransport.h>
60
#include <netedit/elements/demand/GNEVehicle.h>
61
#include <netedit/elements/demand/GNEVType.h>
62
#include <netedit/elements/demand/GNEVTypeDistribution.h>
63
#include <netedit/elements/demand/GNEWalk.h>
64
#include <netedit/frames/common/GNEInspectorFrame.h>
65
#include <netedit/GNEApplicationWindow.h>
66
#include <netedit/GNENet.h>
67
#include <netedit/GNEViewNet.h>
68
#include <netedit/GNEViewParent.h>
69
#include <utils/gui/div/GUIDesigns.h>
70
#include <utils/gui/windows/GUIAppEnum.h>
71
72
#include "GNEPlanSelector.h"
73
74
// ===========================================================================
75
// FOX callback mapping
76
// ===========================================================================
77
78
FXDEFMAP(GNEPlanSelector) TagSelectorMap[] = {
79
FXMAPFUNC(SEL_COMMAND, MID_GNE_TAG_SELECTED, GNEPlanSelector::onCmdSelectPlan)
80
};
81
82
// Object implementation
83
FXIMPLEMENT(GNEPlanSelector, GNEGroupBoxModule, TagSelectorMap, ARRAYNUMBER(TagSelectorMap))
84
85
// ===========================================================================
86
// method definitions
87
// ===========================================================================
88
89
GNEPlanSelector::GNEPlanSelector(GNEFrame* frameParent, SumoXMLTag planType) :
90
GNEGroupBoxModule(frameParent, TL("Plan type")),
91
myPlanType(planType),
92
myFrameParent(frameParent) {
93
// Create MFXComboBoxIcon
94
myPlansComboBox = new MFXComboBoxIcon(getCollapsableFrame(), frameParent->getViewNet()->getViewParent()->getGNEAppWindows()->getStaticTooltipMenu(),
95
false, GUIDesignComboBoxVisibleItems, this, MID_GNE_TAG_SELECTED, GUIDesignComboBox);
96
// add person plan elements
97
for (const auto& planTemplate : myFrameParent->getViewNet()->getNet()->getACTemplates()->getPlanTemplates(myPlanType)) {
98
planTemplate.second->resetDefaultValues(false);
99
myPlansComboBox->appendIconItem(planTemplate.first->getTooltipText().c_str(),
100
GUIIconSubSys::getIcon(planTemplate.second->getTagProperty()->getGUIIcon()),
101
planTemplate.second->getTagProperty()->getBackGroundColor());
102
}
103
// set myCurrentPlanTemplate
104
myCurrentPlanTemplate = myFrameParent->getViewNet()->getNet()->getACTemplates()->getPlanTemplates(myPlanType).front();
105
// set color of myTypeMatchBox to black (valid)
106
myPlansComboBox->setTextColor(GUIDesignTextColorBlack);
107
myPlansComboBox->killFocus();
108
// GNEPlanSelector is always shown
109
show();
110
}
111
112
113
GNEPlanSelector::~GNEPlanSelector() {
114
}
115
116
117
void
118
GNEPlanSelector::showPlanSelector() {
119
show();
120
updateEdgeColors();
121
updateJunctionColors();
122
}
123
124
125
void
126
GNEPlanSelector::hidePlanSelector() {
127
hide();
128
clearEdgeColors();
129
clearJunctionColors();
130
}
131
132
133
const GNETagProperties*
134
GNEPlanSelector::getCurrentPlanTagProperties() const {
135
return myCurrentPlanTemplate.first;
136
}
137
138
139
GNEDemandElement*
140
GNEPlanSelector::getCurrentPlanTemplate() const {
141
return myCurrentPlanTemplate.second;
142
}
143
144
145
void
146
GNEPlanSelector::refreshPlanSelector() {
147
if (isPlanValid()) {
148
// call tag selected function
149
myFrameParent->tagSelected();
150
} else {
151
// set first item
152
myPlansComboBox->setCurrentItem(0, TRUE);
153
}
154
}
155
156
157
bool
158
GNEPlanSelector::markRoutes() const {
159
// first check if this modul is shown and selected plan is valid
160
if (isPlanValid()) {
161
return myCurrentPlanTemplate.first->planRoute();
162
} else {
163
return false;
164
}
165
}
166
167
168
bool
169
GNEPlanSelector::markEdges() const {
170
// first check if this modul is shown and selected plan is valid
171
if (isPlanValid()) {
172
return myCurrentPlanTemplate.first->planConsecutiveEdges() ||
173
myCurrentPlanTemplate.first->planEdge() ||
174
myCurrentPlanTemplate.first->planFromEdge() ||
175
myCurrentPlanTemplate.first->planToEdge();
176
} else {
177
return false;
178
}
179
}
180
181
182
bool
183
GNEPlanSelector::markJunctions() const {
184
// first check if this modul is shown and selected plan is valid
185
if (isPlanValid()) {
186
return myCurrentPlanTemplate.first->planFromJunction() ||
187
myCurrentPlanTemplate.first->planToJunction();
188
} else {
189
return false;
190
}
191
}
192
193
194
bool
195
GNEPlanSelector::markStoppingPlaces() const {
196
// first check if this modul is shown and selected plan is valid
197
if (isPlanValid()) {
198
return myCurrentPlanTemplate.first->planStoppingPlace() ||
199
myCurrentPlanTemplate.first->planFromStoppingPlace() ||
200
myCurrentPlanTemplate.first->planToStoppingPlace();
201
} else {
202
return false;
203
}
204
}
205
206
207
bool
208
GNEPlanSelector::markTAZs() const {
209
// first check if this modul is shown and selected plan is valid
210
if (isPlanValid()) {
211
return myCurrentPlanTemplate.first->planFromTAZ() ||
212
myCurrentPlanTemplate.first->planToTAZ();
213
} else {
214
return false;
215
}
216
}
217
218
219
void
220
GNEPlanSelector::updateJunctionColors() {
221
// clear junction colors
222
clearJunctionColors();
223
// we assume that all junctions don't support pedestrians
224
for (const auto& junction : myFrameParent->getViewNet()->getNet()->getAttributeCarriers()->getJunctions()) {
225
junction.second->setInvalidCandidate(true);
226
}
227
// mark junctions that supports pedestrian as candidates
228
for (const auto& edge : myFrameParent->getViewNet()->getNet()->getAttributeCarriers()->getEdges()) {
229
for (int i = 0; i < (int)edge.second->getChildLanes().size(); i++) {
230
if (edge.second->getNBEdge()->getLanes().at(i).permissions & SVC_PEDESTRIAN) {
231
edge.second->getFromJunction()->setPossibleCandidate(true);
232
edge.second->getToJunction()->setPossibleCandidate(true);
233
}
234
}
235
}
236
// update view net
237
myFrameParent->getViewNet()->updateViewNet();
238
}
239
240
241
void
242
GNEPlanSelector::updateEdgeColors() {
243
// clear edge colors
244
clearEdgeColors();
245
// mark edges that supports pedestrian as candidates
246
for (const auto& edge : myFrameParent->getViewNet()->getNet()->getAttributeCarriers()->getEdges()) {
247
bool allowPedestrian = false;
248
for (int i = 0; i < (int)edge.second->getChildLanes().size(); i++) {
249
if (edge.second->getNBEdge()->getLanes().at(i).permissions & SVC_PEDESTRIAN) {
250
allowPedestrian = true;
251
}
252
}
253
if (allowPedestrian) {
254
edge.second->setPossibleCandidate(true);
255
} else {
256
edge.second->setInvalidCandidate(true);
257
}
258
}
259
// update view net
260
myFrameParent->getViewNet()->updateViewNet();
261
}
262
263
264
void
265
GNEPlanSelector::clearJunctionColors() {
266
// reset all junction flags
267
for (const auto& junction : myFrameParent->getViewNet()->getNet()->getAttributeCarriers()->getJunctions()) {
268
junction.second->resetCandidateFlags();
269
}
270
}
271
272
273
void
274
GNEPlanSelector::clearEdgeColors() {
275
// reset all junction flags
276
for (const auto& edge : myFrameParent->getViewNet()->getNet()->getAttributeCarriers()->getEdges()) {
277
edge.second->resetCandidateFlags();
278
}
279
}
280
281
282
long
283
GNEPlanSelector::onCmdSelectPlan(FXObject*, FXSelector, void*) {
284
// check if selected plan of comboBox exists in plans
285
for (const auto& planTemplate : myFrameParent->getViewNet()->getNet()->getACTemplates()->getPlanTemplates(myPlanType)) {
286
if (planTemplate.first->getTooltipText().c_str() == myPlansComboBox->getText()) {
287
// update myCurrentPlanTemplate
288
myCurrentPlanTemplate = planTemplate;
289
// set color of myTypeMatchBox to black (valid)
290
myPlansComboBox->setTextColor(GUIDesignTextColorBlack);
291
myPlansComboBox->killFocus();
292
// call tag selected function
293
myFrameParent->tagSelected();
294
return 1;
295
}
296
}
297
// reset myCurrentPlanTemplate
298
myCurrentPlanTemplate = std::make_pair(nullptr, nullptr);
299
// set color of myTypeMatchBox to red (invalid)
300
myPlansComboBox->setTextColor(GUIDesignTextColorRed);
301
// call tag selected function
302
myFrameParent->tagSelected();
303
return 1;
304
}
305
306
307
bool
308
GNEPlanSelector::isPlanValid() const {
309
if (myCurrentPlanTemplate.second) {
310
return myPlansComboBox->getTextColor() == GUIDesignTextColorBlack;
311
} else {
312
return false;
313
}
314
}
315
316
/****************************************************************************/
317
318