Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/netedit/frames/network/GNETLSEditorFrame.h
169685 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 GNETLSEditorFrame.h
15
/// @author Jakob Erdmann
16
/// @date May 2011
17
///
18
// The Widget for modifying traffic lights
19
/****************************************************************************/
20
#pragma once
21
#include <config.h>
22
23
#include <netedit/frames/GNEFrame.h>
24
#include <netedit/GNEViewNetHelper.h>
25
#include <netbuild/NBTrafficLightLogic.h>
26
27
// ===========================================================================
28
// class declarations
29
// ===========================================================================
30
31
class GNEOverlappedInspection;
32
class GNETLSTable;
33
class MFXComboBoxIcon;
34
class MFXTextFieldIcon;
35
class MFXToggleButtonTooltip;
36
class NBLoadedSUMOTLDef;
37
class NBOwnTLDef;
38
class NBTrafficLightDefinition;
39
40
// ===========================================================================
41
// class definitions
42
// ===========================================================================
43
44
class GNETLSEditorFrame : public GNEFrame {
45
46
public:
47
// ===========================================================================
48
// class TLSJunction
49
// ===========================================================================
50
51
class TLSJunction : public MFXGroupBoxModule {
52
/// @brief FOX-declaration
53
FXDECLARE(GNETLSEditorFrame::TLSJunction)
54
55
public:
56
/// @brief constructor
57
TLSJunction(GNETLSEditorFrame* TLSEditorParent);
58
59
/// @brief destructor
60
~TLSJunction();
61
62
/// @brief update TLSJunction module
63
void updateTLSJunction();
64
65
/// @brief get current modified junction
66
GNEJunction* getCurrentJunction() const;
67
68
/// @brief set current junction
69
void setCurrentJunction(GNEJunction* junction);
70
71
/// @brief is joining junctions
72
bool isJoiningJunctions() const;
73
74
/// @brief check if given junction is selected (used fo joining)
75
bool isJunctionSelected(const GNEJunction* junction) const;
76
77
/// @brief select or unselect junction in the current TLS
78
void toggleJunctionSelected(const GNEJunction* junction);
79
80
/// @brief get selected junction IDs
81
const std::vector<std::string>& getSelectedJunctionIDs() const;
82
83
/// @name FOX-callbacks
84
/// @{
85
/// @brief Called when the user rename TLS
86
long onCmdRenameTLS(FXObject*, FXSelector, void*);
87
88
/// @brief Called when the user change TLS Type
89
long onCmdChangeType(FXObject*, FXSelector, void*);
90
91
/// @brief Called when the user join TLS
92
long onCmdToggleJoinTLS(FXObject*, FXSelector, void*);
93
94
/// @brief Called when the user join TLS
95
long onCmdDisjoinTLS(FXObject*, FXSelector, void*);
96
97
/// @brief accept join
98
long onCmdAcceptJoin(FXObject*, FXSelector, void*);
99
100
/// @brief cancel join
101
long onCmdCancelJoin(FXObject*, FXSelector, void*);
102
103
/// @}
104
105
protected:
106
/// @brief FOX needs this
107
FOX_CONSTRUCTOR(TLSJunction)
108
109
/// @brief refresh TLJunction module
110
void refreshTLSJunction();
111
112
private:
113
/// @brief TLS editor frame parent
114
GNETLSEditorFrame* myTLSEditorParent;
115
116
/// @brief label for junction ID
117
FXLabel* myJunctionIDLabel = nullptr;
118
119
/// @brief text field for junction ID
120
MFXTextFieldIcon* myJunctionIDTextField = nullptr;
121
122
/// @brief text field for junction ID
123
MFXTextFieldIcon* myTLSIDTextField = nullptr;
124
125
/// @brief ComboBox for TLS Types
126
MFXComboBoxIcon* myTLSTypeComboBox = nullptr;
127
128
/// @brief Toggle button for join TLS
129
MFXToggleButtonTooltip* myJoinTLSToggleButton = nullptr;
130
131
/// @brief button for disjoin TLS
132
MFXButtonTooltip* myDisjoinTLSButton = nullptr;
133
134
/// @brief frame for accept/cancel buttons
135
FXHorizontalFrame* myJoinControlButtons = nullptr;
136
137
/// @brief the junction of the tls is being modified
138
GNEJunction* myCurrentJunction = nullptr;
139
140
/// @brief selected junction (used for join)
141
std::vector<std::string> mySelectedJunctionIDs;
142
143
/// @brief original selected junction (used for join)
144
std::vector<std::string> myOriginalSelectedJunctionIDs;
145
146
/// @brief Invalidated copy constructor.
147
TLSJunction(const TLSJunction&) = delete;
148
149
/// @brief Invalidated assignment operator.
150
TLSJunction& operator=(const TLSJunction&) = delete;
151
};
152
153
// ===========================================================================
154
// class TLSPrograms
155
// ===========================================================================
156
157
class TLSPrograms : public MFXGroupBoxModule {
158
/// @brief FOX-declaration
159
FXDECLARE(GNETLSEditorFrame::TLSPrograms)
160
161
public:
162
/// @brief constructor
163
TLSPrograms(GNETLSEditorFrame* TLSEditorParent);
164
165
/// @brief destructor
166
~TLSPrograms();
167
168
/// @brief update TLSPrograms module
169
void updateTLSPrograms();
170
171
/// @brief show TLSPrograms
172
void showTLSPrograms();
173
174
/// @brief hide TLSPrograms
175
void hideTLSPrograms();
176
177
/// @brief init TLS Definitions
178
bool initTLSPrograms();
179
180
/// @brief clear TLS Definitions
181
void clearTLSProgramss();
182
183
/// @brief get number of programs
184
int getNumberOfPrograms() const;
185
186
/// @brief check if current TLS was modified
187
bool checkHaveModifications() const;
188
189
/// @brief mark Program as modified
190
void markAsModified();
191
192
/// @brief get current definition
193
NBTrafficLightDefinition* getCurrentTLSPrograms() const;
194
195
/// @brief get current program ID
196
const std::string getCurrentTLSProgramID() const;
197
198
/// @brief discard changes
199
void discardChanges(const bool editJunctionAgain);
200
201
/// @name FOX-callbacks
202
/// @{
203
/// @brief Called when the user press button create/duplicate TLS Program
204
long onCmdCreate(FXObject*, FXSelector, void*);
205
206
/// @brief Called when the user press button delete TLS Program
207
long onCmdDelete(FXObject*, FXSelector, void*);
208
209
/// @brief Called when the user press button reset current TLS Program
210
long onCmdResetCurrentProgram(FXObject*, FXSelector, void*);
211
212
/// @brief Called when the user press button reset all TLS Programs
213
long onCmdResetAll(FXObject*, FXSelector, void*);
214
215
/// @brief Called when the user switches a TLS
216
long onCmdDefSwitchTLSProgram(FXObject*, FXSelector, void*);
217
218
/// @brief Called when the user presses the save-Button
219
long onCmdSaveChanges(FXObject*, FXSelector, void*);
220
221
/// @brief Called when the user presses the Cancel-button
222
long onCmdDiscardChanges(FXObject*, FXSelector, void*);
223
224
/// @}
225
226
protected:
227
/// @brief FOX needs this
228
FOX_CONSTRUCTOR(TLSPrograms)
229
230
/// @brief create (or duplicate) TLS in the given junction
231
void createTLS(GNEJunction* junction);
232
233
/// @brief switch program
234
bool switchProgram();
235
236
private:
237
/// @brief pointer to GNETLSEditorFrame parent
238
GNETLSEditorFrame* myTLSEditorParent = nullptr;
239
240
/// @brief the list of Definitions for the current junction
241
std::vector<NBTrafficLightDefinition*> myTLSPrograms;
242
243
/// @brief the comboBox for selecting the tl-definition to edit
244
MFXComboBoxIcon* myProgramComboBox;
245
246
/// @brief whether the current tls was modified
247
bool myHaveModifications = false;
248
249
/// @brief button for create new TLS program
250
FXButton* myCreateButton = nullptr;
251
252
/// @brief button for delete existent TLS program
253
FXButton* myDeleteButton = nullptr;
254
255
/// @brief button for reset TLS program
256
FXButton* myResetSingleButton = nullptr;
257
258
/// @brief button for reset all TLS program
259
FXButton* myResetAllButton = nullptr;
260
261
/// @brief button for save TLS program
262
FXButton* mySaveButon = nullptr;
263
264
/// @brief button for cancel TLS program
265
FXButton* myCancelButon = nullptr;
266
267
/// @brief Invalidated copy constructor.
268
TLSPrograms(const TLSPrograms&) = delete;
269
270
/// @brief Invalidated assignment operator.
271
TLSPrograms& operator=(const TLSPrograms&) = delete;
272
};
273
274
// ===========================================================================
275
// class TLSAttributes
276
// ===========================================================================
277
278
class TLSAttributes : public MFXGroupBoxModule {
279
/// @brief FOX-declaration
280
FXDECLARE(GNETLSEditorFrame::TLSAttributes)
281
282
public:
283
/// @brief constructor
284
TLSAttributes(GNETLSEditorFrame* TLSEditorParent);
285
286
/// @brief destructor
287
~TLSAttributes();
288
289
/// @brief update TLSAttributes module
290
void updateTLSAttributes();
291
292
/// @brief show TLSAttributes
293
void showTLSAttributes();
294
295
/// @brief hide TLSAttributes
296
void hideTLSAttributes();
297
298
/// @brief initializes the definitions and corresponding listbox
299
void initTLSAttributes();
300
301
/// @brief clear TLS attributes
302
void clearTLSAttributes();
303
304
/// @brief get current offset in string format
305
SUMOTime getOffset() const;
306
307
/// @brief set new offset
308
void setOffset(const SUMOTime& offset);
309
310
/// @brief is current offset valid
311
bool isValidOffset();
312
313
/// @brief get current parameters in string format
314
std::string getParameters() const;
315
316
/// @brief set new parameters
317
void setParameters(const std::string& parameters);
318
319
/// @brief are current parameter valid
320
bool isValidParameters();
321
322
/// @brief toggle button for set detectors mode
323
bool isSetDetectorsToggleButtonEnabled() const;
324
325
/// @brief select or unselect E1 detector in the current TLS
326
bool toggleE1DetectorSelection(const GNEAdditional* E1);
327
328
/// @brief get E1 detectors vinculated with this TLS
329
const std::map<std::string, std::string>& getE1Detectors() const;
330
331
/// @brief disable detector mode
332
void disableE1DetectorMode();
333
334
/// @name FOX-callbacks
335
/// @{
336
/// @brief Called when the user changes the offset of a TLS
337
long onCmdSetOffset(FXObject*, FXSelector, void*);
338
339
/// @brief Called when the user changes parameters of a TLS
340
long onCmdSetParameters(FXObject*, FXSelector, void*);
341
342
/// @brief Called when user press edit parameters button
343
long onCmdParametersDialog(FXObject*, FXSelector, void* ptr);
344
345
/// @brief Called when user toggle set detector mode
346
long onCmdToggleDetectorMode(FXObject*, FXSelector, void* ptr);
347
348
/// @}
349
350
protected:
351
/// @brief FOX needs this
352
FOX_CONSTRUCTOR(TLSAttributes)
353
354
/// @brief update E1 detectors
355
void updateE1Detectors();
356
357
private:
358
/// @brief pointer to TLSEditorParent
359
GNETLSEditorFrame* myTLSEditorParent;
360
361
/// @brief the TextField for modifying offset
362
FXTextField* myOffsetTextField = nullptr;
363
364
/// @brief button for edit parameters
365
FXButton* myButtonEditParameters = nullptr;
366
367
/// @brief the TextField for modifying parameters
368
FXTextField* myParametersTextField = nullptr;
369
370
/// @brief toggle button for set detectors mode
371
MFXToggleButtonTooltip* mySetDetectorsToggleButton = nullptr;
372
373
/// @brief set with E1 detector IDs and their lanes vinculated with the TLS <laneID, E1ID>
374
std::map<std::string, std::string> myE1Detectors;
375
376
/// @brief Invalidated copy constructor.
377
TLSAttributes(const TLSAttributes&) = delete;
378
379
/// @brief Invalidated assignment operator.
380
TLSAttributes& operator=(const TLSAttributes&) = delete;
381
};
382
383
// ===========================================================================
384
// class TLSPhases
385
// ===========================================================================
386
387
class TLSPhases : public MFXGroupBoxModule {
388
/// @brief FOX-declaration
389
FXDECLARE(GNETLSEditorFrame::TLSPhases)
390
391
public:
392
/// @brief constructor
393
TLSPhases(GNETLSEditorFrame* TLSEditorParent);
394
395
/// @brief destructor
396
~TLSPhases();
397
398
/// @brief update TLSPhases module
399
void updateTLSPhases();
400
401
/// @brief show TLSPhases
402
void showTLSPhases();
403
404
/// @brief hide TLSPhases
405
void hideTLSPhases();
406
407
/// @brief get TLSEditor Parent
408
GNETLSEditorFrame* getTLSEditorParent() const;
409
410
/// @brief get phase table
411
GNETLSTable* getPhaseTable() const;
412
413
/**@brief initializes the phase table
414
* @param[in] index The index to select
415
*/
416
void initPhaseTable();
417
418
/// @brief clear phase thable
419
void clearPhaseTable();
420
421
/// @brief change phase value (state, name, next, etc.)
422
bool changePhaseValue(const int col, const int row, const std::string& value);
423
424
/// @brief add phase
425
void addPhase(const int row, const char c = ' ');
426
427
/// @brief duplicate phase
428
void duplicatePhase(const int row);
429
430
/// @brief delete phase
431
void removePhase(const int row);
432
433
/// @brief move phase up
434
void movePhaseUp(const int row);
435
436
/// @brief move phase down
437
void movePhaseDown(const int row);
438
439
/// @brief update TLS coloring
440
void updateTLSColoring();
441
442
/// @name FOX-callbacks
443
/// @{
444
/// @brief Called when the user cleans up states
445
long onCmdCleanStates(FXObject*, FXSelector, void*);
446
447
/// @brief Called when the user cleans up states
448
long onCmdAddUnusedStates(FXObject*, FXSelector, void*);
449
450
/// @brief Called when the user groups states
451
long onCmdGroupStates(FXObject*, FXSelector, void*);
452
453
/// @brief Called when the user ungroups states
454
long onCmdUngroupStates(FXObject*, FXSelector, void*);
455
456
/// @}
457
458
protected:
459
/// @brief FOX needs this
460
FOX_CONSTRUCTOR(TLSPhases)
461
462
/// @brief update table
463
void updateTable();
464
465
private:
466
/// @brief init static phase table
467
void initStaticPhaseTable();
468
469
/// @brief init actuated phase table
470
void initActuatedPhaseTable();
471
472
/// @brief init delayBase phase table
473
void initDelayBasePhaseTable();
474
475
/// @brief init NEMA phase table
476
void initNEMAPhaseTable();
477
478
/// @brief build default phase
479
int buildDefaultPhase(const int row);
480
481
/// @brief set duration
482
bool setDuration(const int col, const int row, const std::string& value);
483
484
/// @brief set state
485
bool setState(const int col, const int row, const std::string& value);
486
487
/// @brief set next
488
bool setNext(const int row, const std::string& value);
489
490
/// @brief set name
491
bool setName(const int row, const std::string& value);
492
493
/// @brief set minDur
494
bool setMinDur(const int row, const std::string& value);
495
496
/// @brief set maxDur
497
bool setMaxDur(const int row, const std::string& value);
498
499
/// @brief set earliestEnd
500
bool setEarliestEnd(const int row, const std::string& value);
501
502
/// @brief set latestEnd
503
bool setLatestEnd(const int row, const std::string& value);
504
505
/// @brief set vehExt
506
bool setVehExt(const int row, const std::string& value);
507
508
/// @brief set yellow
509
bool setYellow(const int row, const std::string& value);
510
511
/// @brief set red
512
bool setRed(const int row, const std::string& value);
513
514
/// @brief recomputes cycle duration and updates label
515
void updateCycleDuration(const int col);
516
517
/// @brief update state size
518
void updateStateSize(const int col);
519
520
/// @brief pointer to TLSEditor Parent
521
GNETLSEditorFrame* myTLSEditorParent;
522
523
/// @brief table for selecting and rearranging phases and for changing duration
524
GNETLSTable* myPhaseTable;
525
526
/// @brief clean states button
527
MFXButtonTooltip* myCleanStatesButton = nullptr;
528
529
/// @brief add states button
530
MFXButtonTooltip* myAddStates = nullptr;
531
532
/// @brief group signals button
533
MFXButtonTooltip* myGroupSignalsButton = nullptr;
534
535
/// @brief ungroup signals button
536
MFXButtonTooltip* myUngroupSignalsButton = nullptr;
537
538
/// @brief Invalidated copy constructor.
539
TLSPhases(const TLSPhases&) = delete;
540
541
/// @brief Invalidated assignment operator.
542
TLSPhases& operator=(const TLSPhases&) = delete;
543
};
544
545
// ===========================================================================
546
// class TLSFile
547
// ===========================================================================
548
549
class TLSFile : public MFXGroupBoxModule {
550
/// @brief FOX-declaration
551
FXDECLARE(GNETLSEditorFrame::TLSFile)
552
553
public:
554
/// @brief constructor
555
TLSFile(GNETLSEditorFrame* TLSEditorParent);
556
557
/// @brief destructor
558
~TLSFile();
559
560
/// @brief update TLSFile module
561
void updateTLSFile();
562
563
/// @brief show TLSPhases
564
void showTLSFile();
565
566
/// @brief hide TLSPhases
567
void hideTLSFile();
568
569
/// @name FOX-callbacks
570
/// @{
571
572
/// @brief load TLS Program from an additional file
573
long onCmdLoadTLSProgram(FXObject*, FXSelector, void*);
574
575
/// @brief save TLS Program to an additional file
576
long onCmdSaveTLSProgram(FXObject*, FXSelector, void*);
577
578
/// @}
579
580
protected:
581
/// @brief FOX needs this
582
FOX_CONSTRUCTOR(TLSFile)
583
584
/// @brief convert SUMOTime into string
585
std::string writeSUMOTime(SUMOTime steps);
586
587
private:
588
/// @brief pointer to TLSEditor Parent
589
GNETLSEditorFrame* myTLSEditorParent;
590
591
/// @brief load button
592
FXButton* myLoadButton = nullptr;
593
594
/// @brief save button
595
FXButton* mySaveButton = nullptr;
596
597
/// @brief Invalidated copy constructor.
598
TLSFile(const TLSFile&) = delete;
599
600
/// @brief Invalidated assignment operator.
601
TLSFile& operator=(const TLSFile&) = delete;
602
};
603
604
/**@brief Constructor
605
* @brief viewParent GNEViewParent in which this GNEFrame is placed
606
* @brief viewNet viewNet that uses this GNEFrame
607
*/
608
GNETLSEditorFrame(GNEViewParent* viewParent, GNEViewNet* viewNet);
609
610
/// @brief Destructor
611
~GNETLSEditorFrame();
612
613
/// @brief show inspector frame
614
void show();
615
616
/// @brief function called after setting new width in current frame
617
void frameWidthUpdated();
618
619
/// @brief update modules
620
void updateModules();
621
622
/**@brief edits the traffic light for the given clicked junction
623
* @param[in] clickedPosition clicked position
624
* @param[in] viewObjects The clicked objects under cursor
625
*/
626
void editTLS(GNEViewNetHelper::ViewObjectsSelector& viewObjects, const Position& clickedPosition, const bool shiftKeyPressed);
627
628
/// @brief check if modifications in TLS was saved
629
bool isTLSSaved();
630
631
/// @brief parse TLS Programs from a file
632
bool parseTLSPrograms(const std::string& file);
633
634
/// @brief update phase definition for the current traffic light and phase
635
void handleChange(GNEInternalLane* lane);
636
637
/// @brief update phase definition for the current traffic light and phase
638
void handleMultiChange(GNELane* lane, FXObject* obj, FXSelector sel, void* data);
639
640
/// @brief whether the given edge is controlled by the currently edited tlDef
641
bool controlsEdge(GNEEdge* edge) const;
642
643
/// @brief open GNEAttributesCreator extended dialog (can be reimplemented in frame children)
644
void selectedOverlappedElement(GNEAttributeCarrier* AC);
645
646
/**@brief edits the traffic light for the given junction
647
* @param[in] junction The junction of which the traffic light shall be edited
648
*/
649
void editJunction(GNEJunction* junction);
650
651
/// @brief get module for TLS Junction
652
GNETLSEditorFrame::TLSJunction* getTLSJunction() const;
653
654
/// @brief get module for TLS Definition
655
GNETLSEditorFrame::TLSPrograms* getTLSPrograms() const;
656
657
/// @brief get module for TLS attributes
658
GNETLSEditorFrame::TLSAttributes* getTLSAttributes() const;
659
660
/// @brief get module for TLS Phases
661
GNETLSEditorFrame::TLSPhases* getTLSPhases() const;
662
663
protected:
664
/// @brief converts to SUMOTime
665
static SUMOTime getSUMOTime(const std::string& value);
666
667
/// @brief converts to SUMOTime
668
static const std::string getSteps2Time(const SUMOTime value);
669
670
private:
671
/// @brief Overlapped Inspection
672
GNEOverlappedInspection* myOverlappedInspection = nullptr;
673
674
/// @brief module for TLS Junction
675
GNETLSEditorFrame::TLSJunction* myTLSJunction = nullptr;
676
677
/// @brief module for TLS Definition
678
GNETLSEditorFrame::TLSPrograms* myTLSPrograms = nullptr;
679
680
/// @brief module for TLS attributes
681
GNETLSEditorFrame::TLSAttributes* myTLSAttributes = nullptr;
682
683
/// @brief module for TLS Phases
684
GNETLSEditorFrame::TLSPhases* myTLSPhases = nullptr;
685
686
/// @brief module for load/Save TLS Programs
687
GNETLSEditorFrame::TLSFile* myTLSFile = nullptr;
688
689
/// @brief the internal lanes belonging to the current junction indexed by their tl-index
690
std::map<int, std::vector<GNEInternalLane*> > myInternalLanes;
691
692
/// @brief the traffic light definition being edited
693
NBLoadedSUMOTLDef* myEditedDef = nullptr;
694
695
/// @brief cleans up previous lanes
696
void cleanup();
697
698
/// @brief builds internal lanes for the given tlDef
699
void buildInternalLanes(const NBTrafficLightDefinition* tlDef);
700
701
/// @brief get certain phase of the current traffic light
702
const NBTrafficLightLogic::PhaseDefinition& getPhase(const int index);
703
704
/// @brief convert duration (potentially undefined) to string
705
static std::string varDurString(SUMOTime dur);
706
707
/// @brief Invalidated copy constructor.
708
GNETLSEditorFrame(const GNETLSEditorFrame&) = delete;
709
710
/// @brief Invalidated assignment operator.
711
GNETLSEditorFrame& operator=(const GNETLSEditorFrame&) = delete;
712
};
713
714