Eclipse SUMO - Simulation of Urban MObility
GNETLSEditorFrame.h
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3// Copyright (C) 2001-2022 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/****************************************************************************/
18// The Widget for modifying traffic lights
19/****************************************************************************/
20#pragma once
21#include <config.h>
22
25
26
27// ===========================================================================
28// class declarations
29// ===========================================================================
32class NBOwnTLDef;
33class GNEInternalLane;
34class GNETLSTable;
36
37// ===========================================================================
38// class definitions
39// ===========================================================================
45
46public:
47 // ===========================================================================
48 // class TLSJunction
49 // ===========================================================================
50
54
55 public:
57 TLSJunction(GNETLSEditorFrame* TLSEditorParent);
58
61
64
66 void setCurrentJunction(GNEJunction* junction);
67
70
73
75 bool isJoiningJunctions() const;
76
78 bool isJunctionSelected(const GNEJunction* junction) const;
79
81 void toggleJunctionSelected(const GNEJunction* junction);
82
84 const std::vector<std::string>& getSelectedJunctionIDs() const;
85
89 long onCmdRenameTLS(FXObject*, FXSelector, void*);
90
92 long onUpdTLSID(FXObject*, FXSelector, void*);
93
95 long onCmdChangeType(FXObject*, FXSelector, void*);
96
98 long onUpdTLSType(FXObject*, FXSelector, void*);
99
101 long onCmdToggleJoinTLS(FXObject*, FXSelector, void*);
102
104 long onUpdJoinTLS(FXObject*, FXSelector, void*);
105
107 long onCmdDisjoinTLS(FXObject*, FXSelector, void*);
108
110 long onUpdDisjoinTLS(FXObject*, FXSelector, void*);
111
113
114 protected:
116 FOX_CONSTRUCTOR(TLSJunction)
117
118 private:
121
123 FXLabel* myJunctionIDLabel = nullptr;
124
127
130
133
136
139
142
144 std::vector<std::string> mySelectedJunctionIDs;
145 };
146
147 // ===========================================================================
148 // class TLSDefinition
149 // ===========================================================================
150
154
155 public:
157 TLSDefinition(GNETLSEditorFrame* TLSEditorParent);
158
161
163 void showTLSDefinition();
164
166 void hideTLSDefinition();
167
169 bool initTLSDefinitions();
170
172 void clearTLSDefinitions();
173
175 int getNumberOfPrograms() const;
176
178 int getNumberOfTLSDefinitions() const;
179
181 bool checkHaveModifications() const;
182
184 void markAsModified();
185
188
190 const std::string getCurrentTLSProgramID() const;
191
193 void discardChanges(const bool editJunctionAgain);
194
198 long onCmdCreate(FXObject*, FXSelector, void*);
199
201 long onUpdCreate(FXObject*, FXSelector, void*);
202
204 long onCmdDelete(FXObject*, FXSelector, void*);
205
207 long onCmdResetCurrentProgram(FXObject*, FXSelector, void*);
208
210 long onCmdResetAll(FXObject*, FXSelector, void*);
211
213 long onCmdDefSwitchTLSProgram(FXObject*, FXSelector, void*);
214
216 long onUpdTLSEnableModified(FXObject*, FXSelector, void*);
217
219 long onUpdTLSDisableModified(FXObject*, FXSelector, void*);
220
222 long onUpdTLSDisableResetAll(FXObject*, FXSelector, void*);
223
225 long onCmdSaveChanges(FXObject*, FXSelector, void*);
226
228 long onCmdDiscardChanges(FXObject*, FXSelector, void*);
229
231
232 protected:
234 FOX_CONSTRUCTOR(TLSDefinition)
235
236
237 void createTLS(GNEJunction* junction);
238
240 bool switchProgram();
241
242 private:
245
247 std::vector<NBTrafficLightDefinition*> myTLSDefinitions;
248
250 FXComboBox* myProgramComboBox;
251
254
256 FXButton* myCreateButton = nullptr;
257 };
258
259 // ===========================================================================
260 // class TLSAttributes
261 // ===========================================================================
262
266
267 public:
269 TLSAttributes(GNETLSEditorFrame* TLSEditorParent);
270
273
275 void showTLSAttributes();
276
278 void hideTLSAttributes();
279
281 void initTLSAttributes();
282
284 void clearTLSAttributes();
285
287 SUMOTime getOffset() const;
288
290 void setOffset(const SUMOTime& offset);
291
293 bool isValidOffset();
294
296 std::string getParameters() const;
297
299 void setParameters(const std::string& parameters);
300
302 bool isValidParameters();
303
306
309
311 const std::map<std::string, std::string>& getE1Detectors() const;
312
315
319 long onCmdSetOffset(FXObject*, FXSelector, void*);
320
322 long onUpdOffset(FXObject*, FXSelector, void*);
323
325 long onCmdSetParameters(FXObject*, FXSelector, void*);
326
328 long onCmdParametersDialog(FXObject*, FXSelector, void* ptr);
329
331 long onUpdParameters(FXObject*, FXSelector, void*);
332
334 long onCmdToggleDetectorMode(FXObject*, FXSelector, void* ptr);
335
337 long onUpdSetDetectorMode(FXObject*, FXSelector, void*);
338
340
341 protected:
343 FOX_CONSTRUCTOR(TLSAttributes)
344
345
346 void updateE1Detectors();
347
348 private:
351
353 FXTextField* myOffsetTextField = nullptr;
354
356 FXButton* myButtonEditParameters = nullptr;
357
359 FXTextField* myParametersTextField = nullptr;
360
363
365 std::map<std::string, std::string> myE1Detectors;
366 };
367
368 // ===========================================================================
369 // class TLSPhases
370 // ===========================================================================
371
375
376 public:
378 TLSPhases(GNETLSEditorFrame* TLSEditorParent);
379
381 ~TLSPhases();
382
384 void showTLSPhases();
385
387 void hideTLSPhases();
388
391
393 GNETLSTable* getPhaseTable() const;
394
398 void initPhaseTable();
399
401 bool changePhaseValue(const int col, const int row, const std::string& value);
402
404 void addPhase(const int row, const char c = ' ');
405
407 void duplicatePhase(const int row);
408
410 void removePhase(const int row);
411
413 void movePhaseUp(const int row);
414
416 void movePhaseDown(const int row);
417
419 void updateTLSColoring();
420
424 long onCmdCleanStates(FXObject*, FXSelector, void*);
425
427 long onCmdAddUnusedStates(FXObject*, FXSelector, void*);
428
430 long onCmdGroupStates(FXObject*, FXSelector, void*);
431
433 long onCmdUngroupStates(FXObject*, FXSelector, void*);
434
436 long onUpdUngroupStates(FXObject*, FXSelector, void*);
437
439 long onUpdNeedsSingleDef(FXObject*, FXSelector, void*);
440
442 long onUpdNeedsDef(FXObject*, FXSelector, void*);
443
445 long onUpdNeedsDefAndPhase(FXObject*, FXSelector, void*);
446
448
449 protected:
451 FOX_CONSTRUCTOR(TLSPhases)
452
453 private:
456
459
462
464 void initNEMAPhaseTable();
465
467 int buildDefaultPhase(const int row);
468
470 bool setDuration(const int col, const int row, const std::string& value);
471
473 bool setState(const int col, const int row, const std::string& value);
474
476 bool setNext(const int col, const int row, const std::string& value);
477
479 bool setName(const int row, const std::string& value);
480
482 bool setMinDur(const int row, const std::string& value);
483
485 bool setMaxDur(const int row, const std::string& value);
486
488 bool setEarliestEnd(const int row, const std::string& value);
489
491 bool setLatestEnd(const int row, const std::string& value);
492
494 bool setVehExt(const int row, const std::string& value);
495
497 bool setYellow(const int row, const std::string& value);
498
500 bool setRed(const int row, const std::string& value);
501
503 void updateCycleDuration(const int col);
504
506 void updateStateSize(const int col);
507
510
513 };
514
515 // ===========================================================================
516 // class TLSFile
517 // ===========================================================================
518
519 class TLSFile : public MFXGroupBoxModule {
522
523 public:
525 TLSFile(GNETLSEditorFrame* TLSEditorParent);
526
528 ~TLSFile();
529
531 void showTLSFile();
532
534 void hideTLSFile();
535
539 long onCmdLoadTLSProgram(FXObject*, FXSelector, void*);
540
542 long onCmdSaveTLSProgram(FXObject*, FXSelector, void*);
543
545 long onUpdButtons(FXObject*, FXSelector, void*);
547
548 protected:
550 FOX_CONSTRUCTOR(TLSFile)
551
552 private:
555
557 std::string writeSUMOTime(SUMOTime steps);
558 };
559
564 GNETLSEditorFrame(GNEViewParent* viewParent, GNEViewNet* viewNet);
565
568
570 void show();
571
573 void frameWidthUpdated();
574
579 void editTLS(const Position& clickedPosition, const GNEViewNetHelper::ObjectsUnderCursor& objectsUnderCursor);
580
582 bool isTLSSaved();
583
585 bool parseTLSPrograms(const std::string& file);
586
588 void handleChange(GNEInternalLane* lane);
589
591 void handleMultiChange(GNELane* lane, FXObject* obj, FXSelector sel, void* data);
592
594 bool controlsEdge(GNEEdge* edge) const;
595
598
602 void editJunction(GNEJunction* junction);
603
606
609
612
613protected:
615 static SUMOTime getSUMOTime(const std::string& value);
616
618 static const std::string getSteps2Time(const SUMOTime value);
619
620private:
623
626
629
632
635
638
640 std::map<int, std::vector<GNEInternalLane*> > myInternalLanes;
641
644
646 void cleanup();
647
650
652 const NBTrafficLightLogic::PhaseDefinition& getPhase(const int index);
653
655 static std::string varDurString(SUMOTime dur);
656};
long long int SUMOTime
Definition: GUI.h:36
An Element which don't belong to GNENet but has influence in the simulation.
Definition: GNEAdditional.h:48
A road/street connecting two junctions (netedit-version)
Definition: GNEEdge.h:53
This object is responsible for drawing a shape and for supplying a a popup menu. Messages are routete...
This lane is powered by an underlying GNEEdge and basically knows how to draw itself.
Definition: GNELane.h:46
long onCmdSetParameters(FXObject *, FXSelector, void *)
Called when the user changes parameters of a TLS.
long onCmdSetOffset(FXObject *, FXSelector, void *)
bool isValidOffset()
is current offset valid
long onCmdParametersDialog(FXObject *, FXSelector, void *ptr)
Called when user press edit parameters button.
long onUpdParameters(FXObject *, FXSelector, void *)
Called when the offset is updated.
MFXToggleButtonTooltip * mySetDetectorsToggleButton
toggle button for set detectors mode
bool isSetDetectorsToggleButtonEnabled() const
toggle button for set detectors mode
bool isValidParameters()
are current parameter valid
FXTextField * myOffsetTextField
the TextField for modifying offset
void updateE1Detectors()
FOX needs this.
void disableE1DetectorMode()
disable detector mode
SUMOTime getOffset() const
get current offset in string format
long onUpdSetDetectorMode(FXObject *, FXSelector, void *)
Called when occurs an update of set detector mode.
void setParameters(const std::string &parameters)
set new parameters
const std::map< std::string, std::string > & getE1Detectors() const
get E1 detectors vinculated with this TLS
void clearTLSAttributes()
clear TLS attributes
long onUpdOffset(FXObject *, FXSelector, void *)
Called when the offset is updated.
void setOffset(const SUMOTime &offset)
set new offset
std::map< std::string, std::string > myE1Detectors
set with E1 detector IDs and their lanes vinculated with the TLS <laneID, E1ID>
std::string getParameters() const
get current parameters in string format
bool toggleE1DetectorSelection(const GNEAdditional *E1)
select or unselect E1 detector in the current TLS
void initTLSAttributes()
initializes the definitions and corresponding listbox
FXButton * myButtonEditParameters
button for edit parameters
TLSAttributes(GNETLSEditorFrame *TLSEditorParent)
FOX-declaration.
FXTextField * myParametersTextField
the TextField for modifying parameters
void hideTLSAttributes()
hide TLSAttributes
void showTLSAttributes()
show TLSAttributes
GNETLSEditorFrame * myTLSEditorParent
pointer to TLSEditorParent
long onCmdToggleDetectorMode(FXObject *, FXSelector, void *ptr)
Called when user toggle set detector mode.
void createTLS(GNEJunction *junction)
FOX needs this.
void clearTLSDefinitions()
clear TLS Definitions
long onCmdDefSwitchTLSProgram(FXObject *, FXSelector, void *)
Called when the user switches a TLS.
std::vector< NBTrafficLightDefinition * > myTLSDefinitions
the list of Definitions for the current junction
long onUpdTLSDisableResetAll(FXObject *, FXSelector, void *)
Called when occurs an update of switch definition.
bool myHaveModifications
whether the current tls was modified
bool checkHaveModifications() const
check if current TLS was modified
void hideTLSDefinition()
hide TLSDefinition
long onCmdSaveChanges(FXObject *, FXSelector, void *)
Called when the user presses the save-Button.
long onCmdDiscardChanges(FXObject *, FXSelector, void *)
Called when the user presses the Cancel-button.
void markAsModified()
mark Program as modified
FXComboBox * myProgramComboBox
the comboBox for selecting the tl-definition to edit
const std::string getCurrentTLSProgramID() const
get current program ID
int getNumberOfTLSDefinitions() const
get number of TLS definitions
long onCmdResetCurrentProgram(FXObject *, FXSelector, void *)
Called when the user press button reset current TLS Program.
long onCmdDelete(FXObject *, FXSelector, void *)
Called when the user press button delete TLS Program.
int getNumberOfPrograms() const
get number of programs
void showTLSDefinition()
show TLSDefinition
long onUpdCreate(FXObject *, FXSelector, void *)
Called when occurs an update of create definition.
bool initTLSDefinitions()
init TLS Definitions
NBTrafficLightDefinition * getCurrentTLSDefinition() const
get current definition
long onCmdCreate(FXObject *, FXSelector, void *)
GNETLSEditorFrame * myTLSEditorParent
pointer to GNETLSEditorFrame parent
TLSDefinition(GNETLSEditorFrame *TLSEditorParent)
FOX-declaration.
void discardChanges(const bool editJunctionAgain)
discard changes
long onUpdTLSEnableModified(FXObject *, FXSelector, void *)
Called when occurs an update of switch definition.
long onCmdResetAll(FXObject *, FXSelector, void *)
Called when the user press button reset all TLS Programs.
FXButton * myCreateButton
button for create new Traffic light program
long onUpdTLSDisableModified(FXObject *, FXSelector, void *)
Called when occurs an update of switch definition.
void showTLSFile()
show TLSPhases
void hideTLSFile()
hide TLSPhases
long onCmdLoadTLSProgram(FXObject *, FXSelector, void *)
TLSFile(GNETLSEditorFrame *TLSEditorParent)
FOX-declaration.
std::string writeSUMOTime(SUMOTime steps)
convert SUMOTime into string
long onUpdButtons(FXObject *, FXSelector, void *)
enable buttons, only when a tlLogic is being edited
long onCmdSaveTLSProgram(FXObject *, FXSelector, void *)
save TLS Program to an additional file
GNETLSEditorFrame * myTLSEditorParent
FOX needs this.
long onCmdChangeType(FXObject *, FXSelector, void *)
Called when the user change TLS Type.
long onCmdDisjoinTLS(FXObject *, FXSelector, void *)
Called when the user join TLS.
std::vector< std::string > mySelectedJunctionIDs
selected junction (used for join)
GNETLSEditorFrame * myTLSEditorParent
FOX needs this.
const std::vector< std::string > & getSelectedJunctionIDs() const
get selected junction IDs
long onUpdTLSType(FXObject *, FXSelector, void *)
Called when occurs an update of modified.
long onCmdToggleJoinTLS(FXObject *, FXSelector, void *)
Called when the user join TLS.
long onCmdRenameTLS(FXObject *, FXSelector, void *)
TLSJunction(GNETLSEditorFrame *TLSEditorParent)
FOX-declaration.
long onUpdJoinTLS(FXObject *, FXSelector, void *)
Called when update join TLS.
MFXToggleButtonTooltip * myJoinTLSToggleButton
Toggle button for join TLS.
void updateJunctionDescription()
update junction description
void toggleJunctionSelected(const GNEJunction *junction)
select or unselect junction in the current TLS
GNEJunction * getCurrentJunction() const
get current modified junction
void setCurrentJunction(GNEJunction *junction)
set current junction
long onUpdDisjoinTLS(FXObject *, FXSelector, void *)
Called when update join TLS.
FXLabel * myJunctionIDLabel
label for junction ID
GNEJunction * myCurrentJunction
the junction of the tls is being modified
bool isJunctionSelected(const GNEJunction *junction) const
check if given junction is selected (used fo joining)
void disableJoiningJunctionMode()
disable joining junction mode
MFXButtonTooltip * myDisjoinTLSButton
button for disjoin TLS
bool isJoiningJunctions() const
is joining junctions
MFXTextFieldTooltip * myTLSIDTextField
text field for junction ID
long onUpdTLSID(FXObject *, FXSelector, void *)
Called when occurs an update of modified.
MFXTextFieldTooltip * myJunctionIDTextField
text field for junction ID
MFXIconComboBox * myTLSTypeComboBox
ComboBox for TLS Types.
bool setEarliestEnd(const int row, const std::string &value)
set earliestEnd
long onCmdUngroupStates(FXObject *, FXSelector, void *)
Called when the user ungroups states.
void showTLSPhases()
show TLSPhases
GNETLSTable * myPhaseTable
table for selecting and rearranging phases and for changing duration
long onCmdCleanStates(FXObject *, FXSelector, void *)
long onCmdGroupStates(FXObject *, FXSelector, void *)
Called when the user groups states.
bool setVehExt(const int row, const std::string &value)
set vehExt
int buildDefaultPhase(const int row)
build default phase
TLSPhases(GNETLSEditorFrame *TLSEditorParent)
FOX-declaration.
void movePhaseDown(const int row)
move phase down
void initActuatedPhaseTable()
init actuated phase table
void initPhaseTable()
initializes the phase table
void initNEMAPhaseTable()
init NEMA phase table
bool setYellow(const int row, const std::string &value)
set yellow
bool changePhaseValue(const int col, const int row, const std::string &value)
change phase value (state, name, next, etc.)
long onUpdNeedsSingleDef(FXObject *, FXSelector, void *)
Called to buttons that modify link indices.
void initDelayBasePhaseTable()
init delayBase phase table
void movePhaseUp(const int row)
move phase up
bool setMinDur(const int row, const std::string &value)
set minDur
bool setLatestEnd(const int row, const std::string &value)
set latestEnd
void updateStateSize(const int col)
update state size
long onCmdAddUnusedStates(FXObject *, FXSelector, void *)
Called when the user cleans up states.
void initStaticPhaseTable()
FOX needs this.
GNETLSEditorFrame * myTLSEditorParent
pointer to TLSEditor Parent
long onUpdUngroupStates(FXObject *, FXSelector, void *)
Called to update the ungroups states button.
bool setDuration(const int col, const int row, const std::string &value)
set duration
bool setMaxDur(const int row, const std::string &value)
set maxDur
long onUpdNeedsDef(FXObject *, FXSelector, void *)
enable buttons, only when a tlLogic is being edited
void updateTLSColoring()
update TLS coloring
GNETLSTable * getPhaseTable() const
get phase table
void removePhase(const int row)
delete phase
bool setRed(const int row, const std::string &value)
set red
bool setName(const int row, const std::string &value)
set name
bool setState(const int col, const int row, const std::string &value)
set state
bool setNext(const int col, const int row, const std::string &value)
set next
long onUpdNeedsDefAndPhase(FXObject *, FXSelector, void *)
Called when occurs an update of needs definition and phase.
void duplicatePhase(const int row)
duplicate phase
void addPhase(const int row, const char c=' ')
add phase
GNETLSEditorFrame * getTLSEditorParent() const
get TLSEditor Parent
void hideTLSPhases()
hide TLSPhases
void updateCycleDuration(const int col)
recomputes cycle duration and updates label
GNETLSEditorFrame::TLSFile * myTLSFile
module for load/Save TLS Programs
void handleChange(GNEInternalLane *lane)
update phase definition for the current traffic light and phase
GNEOverlappedInspection * myOverlappedInspection
Overlapped Inspection.
GNETLSEditorFrame::TLSAttributes * getTLSAttributes() const
get module for TLS attributes
GNETLSEditorFrame::TLSAttributes * myTLSAttributes
module for TLS attributes
static std::string varDurString(SUMOTime dur)
convert duration (potentially undefined) to string
bool isTLSSaved()
check if modifications in TLS was saved
void editJunction(GNEJunction *junction)
edits the traffic light for the given junction
GNETLSEditorFrame::TLSPhases * myTLSPhases
module for TLS Phases
void selectedOverlappedElement(GNEAttributeCarrier *AC)
open GNEAttributesCreator extended dialog (can be reimplemented in frame children)
GNETLSEditorFrame(GNEViewParent *viewParent, GNEViewNet *viewNet)
Constructor.
std::map< int, std::vector< GNEInternalLane * > > myInternalLanes
the internal lanes belonging the the current junction indexed by their tl-index
bool parseTLSPrograms(const std::string &file)
parse TLS Programs from a file
bool controlsEdge(GNEEdge *edge) const
whether the given edge is controlled by the currently edited tlDef
static const std::string getSteps2Time(const SUMOTime value)
converts to SUMOTime
void buildInternalLanes(const NBTrafficLightDefinition *tlDef)
builds internal lanes for the given tlDef
const NBTrafficLightLogic::PhaseDefinition & getPhase(const int index)
get certain phase of the current traffic light
void handleMultiChange(GNELane *lane, FXObject *obj, FXSelector sel, void *data)
update phase definition for the current traffic light and phase
GNETLSEditorFrame::TLSDefinition * myTLSDefinition
module for TLS Definition
GNETLSEditorFrame::TLSJunction * getTLSJunction() const
get module for TLS Junction
static SUMOTime getSUMOTime(const std::string &value)
converts to SUMOTime
~GNETLSEditorFrame()
Destructor.
NBLoadedSUMOTLDef * myEditedDef
the traffic light definition being edited
void frameWidthUpdated()
function called after setting new width in current frame
GNETLSEditorFrame::TLSJunction * myTLSJunction
module for TLS Junction
void editTLS(const Position &clickedPosition, const GNEViewNetHelper::ObjectsUnderCursor &objectsUnderCursor)
edits the traffic light for the given clicked junction
void cleanup()
cleans up previous lanes
GNETLSEditorFrame::TLSDefinition * getTLSDefinition() const
get module for TLS Definition
void show()
show inspector frame
class used to group all variables related with objects under cursor after a click over view
A single child window which contains a view of the simulation area.
Definition: GNEViewParent.h:84
MFXGroupBoxModule (based on FXGroupBox)
ComboBox with icon.
A loaded (complete) traffic light logic.
A traffic light logics which must be computed (only nodes/edges are given)
Definition: NBOwnTLDef.h:44
The base class for traffic light logic definitions.
The definition of a single phase of the logic.
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:37