Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/netedit/frames/GNETLSTable.h
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 GNETLSTable.h
15
/// @author Pablo Alvarez Lopez
16
/// @date 2022-07-21
17
///
18
// Table used in GNETLSFrame for editing TLS programs
19
/****************************************************************************/
20
#ifndef GNETLSTable_h
21
#define GNETLSTable_h
22
#include <config.h>
23
24
#include <vector>
25
#include <netedit/frames/network/GNETLSEditorFrame.h>
26
#include <utils/tests/InternalTestStep.h>
27
28
// ===========================================================================
29
// class declaration
30
// ===========================================================================
31
32
class MFXTextFieldIcon;
33
class MFXLabelTooltip;
34
class MFXMenuButtonTooltip;
35
36
// ===========================================================================
37
// class definitions
38
// ===========================================================================
39
40
class GNETLSTable : public FXHorizontalFrame {
41
/// @brief fox declaration
42
FXDECLARE(GNETLSTable)
43
44
public:
45
/// @brief constructor (Exactly like the FXButton constructor)
46
GNETLSTable(GNETLSEditorFrame::TLSPhases* TLSPhasesParent);
47
48
/// @brief destructor (Called automatically)
49
~GNETLSTable();
50
51
/// @brief Enable table
52
void enable();
53
54
/// @brief Disable table
55
void disable();
56
57
/// @frame get pointer to TLSEditorFrame phases parent
58
GNETLSEditorFrame::TLSPhases* getTLSPhasesParent() const;
59
60
/// @brief recalc width (call when all labels and contents are fill)
61
void recalcTableWidth();
62
63
/// @brief clear table
64
void clearTable();
65
66
/// @brief Modify cell text
67
void setItemText(FXint row, FXint column, const std::string& text);
68
69
/// @brief Return cell text
70
std::string getItemText(const int row, const int column) const;
71
72
/// @brief Get number of rows
73
int getNumRows() const;
74
75
/// @brief Get current selected row
76
int getCurrentSelectedRow() const;
77
78
/// @brief Select a row
79
void selectRow(const int rowIndex);
80
81
/// @brief Change column header text
82
void setColumnLabelTop(const int column, const std::string& text, const std::string& tooltip = "");
83
84
/// @brief Change column bottom text
85
void setColumnLabelBot(const int column, const std::string& text);
86
87
/**@brief Set the table size to nr rows and nc columns; all existing items will be removed. Format:
88
* s -> select row (radio button)
89
* u -> duration (float, textField)
90
* f -> float (float, textField)
91
* p -> program (rrGggy..., textField)
92
* m -> name (automatic size, textField)
93
* i -> insert phase (button)
94
* d -> delete phase (button)
95
* t -> move phase up (button)
96
* b -> move phase down (button)
97
* - -> general text (textField)
98
*/
99
void setTableSize(const std::string& columnsType, const int numberRow);
100
101
/// @brief test table (using internal tests)
102
long testTable(const InternalTestStep::TLSTableTest* tableTest);
103
104
/// @name FOX callbacks
105
/// @{
106
107
/// @brief called when a row is focused
108
long onFocusRow(FXObject*, FXSelector, void*);
109
110
/// @brief called when add phase button is selected
111
long onCmdAddPhasePressed(FXObject*, FXSelector, void*);
112
113
/// @brief called when a row is modified
114
long onCmdEditRow(FXObject*, FXSelector, void*);
115
116
/// @brief called when a key is pressed
117
long onCmdKeyPress(FXObject*, FXSelector, void*);
118
119
/// @brief called when an add phase button is pressed
120
long onCmdAddPhase(FXObject*, FXSelector, void*);
121
122
/// @brief called when a duplicate phase button is pressed
123
long onCmdDuplicatePhase(FXObject*, FXSelector, void*);
124
125
/// @brief called when an add all green red phase button is pressed
126
long onCmdAddPhaseAllRed(FXObject*, FXSelector, void*);
127
128
/// @brief called when an add all green red phase button is pressed
129
long onCmdAddPhaseAllYellow(FXObject*, FXSelector, void*);
130
131
/// @brief called when an add all green red phase button is pressed
132
long onCmdAddPhaseAllGreen(FXObject*, FXSelector, void*);
133
134
/// @brief called when an add all green red phase button is pressed
135
long onCmdAddPhaseAllGreenPriority(FXObject*, FXSelector, void*);
136
137
/// @brief called when a remove phase button is pressed
138
long onCmdRemovePhase(FXObject*, FXSelector, void*);
139
140
/// @brief called when a move up phase button is pressed
141
long onCmdMoveUpPhase(FXObject*, FXSelector, void*);
142
143
/// @brief called when a move up phase button is pressed
144
long onCmdMoveDownPhase(FXObject*, FXSelector, void*);
145
146
/// @}
147
148
protected:
149
/// @brief FOX needs this
150
FOX_CONSTRUCTOR(GNETLSTable)
151
152
/// @brief table cell
153
class Cell {
154
155
public:
156
/// @brief constructor for textField
157
Cell(GNETLSTable* TLSTable, MFXTextFieldIcon* textField, int col, int row);
158
159
/// @brief constructor for index label
160
Cell(GNETLSTable* TLSTable, FXLabel* indexLabel, FXLabel* indexLabelBold, int col, int row);
161
162
/// @brief constructor for buttons
163
Cell(GNETLSTable* TLSTable, MFXButtonTooltip* button, int col, int row);
164
165
/// @brief constructor for menu buttons
166
Cell(GNETLSTable* TLSTable, int col, int row);
167
168
/// @brief destructor
169
~Cell();
170
171
/// @brief Enable cell
172
void enable();
173
174
/// @brief Disable cell
175
void disable();
176
177
/// @brief check if current cell has focus
178
bool hasFocus() const;
179
180
/// @brief set focus in the current cell
181
void setFocus();
182
183
/// @brief get double value (only for types 'u' and 'd')
184
double getDoubleValue() const;
185
186
/// @brief set tooltip
187
void setTooltip(const std::string& toolTip);
188
189
/// @brief get textField
190
MFXTextFieldIcon* getTextField() const;
191
192
/// @brief get index label
193
FXLabel* getIndexLabel() const;
194
195
/// @brief get add button
196
MFXMenuButtonTooltip* getAddButton() const;
197
198
/// @brief get remove, move up or move down button
199
MFXButtonTooltip* getButton();
200
201
/// @brief get add phase button
202
MFXButtonTooltip* getAddPhaseButton();
203
204
/// @brief get duplicate phase button
205
MFXButtonTooltip* getDuplicatePhaseButton();
206
207
/// @brief get add all red phase button
208
MFXButtonTooltip* getAddAllRedPhaseButton();
209
210
/// @brief get add all yellow phase button
211
MFXButtonTooltip* getAddAllYellowPhaseButton();
212
213
/// @brief get add all green phase button
214
MFXButtonTooltip* getAddAllGreenPhaseButton();
215
216
/// @brief get add all green priority phase button
217
MFXButtonTooltip* getAddAllGreenPriorityPhaseButton();
218
219
/// @brief show label index normal
220
void showIndexLabelNormal();
221
222
/// @brief show label index bold
223
void showIndexLabelBold();
224
225
/// @brief column index
226
int getCol() const;
227
228
/// @brief row index
229
int getRow() const;
230
231
/// @brief get column type
232
char getType() const;
233
234
/// @brief hide menuButton popup
235
void hideMenuButtonPopup();
236
237
/// @brief disable button (used for delete, move up and move down)
238
void disableButton();
239
240
private:
241
/// @brief pointer to TLSTable parent
242
GNETLSTable* myTLSTable = nullptr;
243
244
/// @brief MFXTextFieldIcon
245
MFXTextFieldIcon* myTextField = nullptr;
246
247
/// @brief index label
248
FXLabel* myIndexLabel = nullptr;
249
250
/// @brief index label bold
251
FXLabel* myIndexLabelBold = nullptr;
252
253
/// @brief button
254
MFXButtonTooltip* myButton = nullptr;
255
256
/// @brief popup for buttons
257
FXPopup* myMenuButtonPopup = nullptr;
258
259
/// @brief menu button tooltip
260
MFXMenuButtonTooltip* myAddButton = nullptr;
261
262
/// @brief add phase button
263
MFXButtonTooltip* myAddPhaseButton = nullptr;
264
265
/// @brief duplicate phase button
266
MFXButtonTooltip* myDuplicatePhaseButton = nullptr;
267
268
/// @brief add all red phase button
269
MFXButtonTooltip* myAddAllRedButton = nullptr;
270
271
/// @brief add all yellow phase button
272
MFXButtonTooltip* myAddAllYellowButton = nullptr;
273
274
/// @brief add all green phase button
275
MFXButtonTooltip* myAddAllGreenButton = nullptr;
276
277
/// @brief add all green priority phase button
278
MFXButtonTooltip* myAddAllGreenPriorityButton = nullptr;
279
280
/// @brief column index
281
const int myCol;
282
283
/// @brief row index
284
const int myRow;
285
286
/// @brief disable button
287
bool myDisableButton = false;
288
289
/// @brief default constructor
290
Cell();
291
};
292
293
/// @brief table column
294
class Column {
295
296
public:
297
/// @brief constructor
298
Column(GNETLSTable* table, const int index, const char type);
299
300
/// @brief destructor
301
~Column();
302
303
/// @brief get vertical cell frame
304
FXVerticalFrame* getVerticalCellFrame() const;
305
306
/// @brief get column type
307
char getType() const;
308
309
/// @brief get column label top
310
FXString getColumnLabelTop() const;
311
312
/// @brief set column label top
313
void setColumnLabelTop(const std::string& text, const std::string& tooltip);
314
315
/// @brief set column label boit
316
void setColumnLabelBot(const std::string& text);
317
318
/// @brief get column minimum width
319
int getColumnMinimumWidth();
320
321
/// @brief set colum width
322
void setColumnWidth(const int colWidth);
323
324
private:
325
/// @brief pointer to table
326
GNETLSTable* myTable = nullptr;
327
328
/// @brief vertical frame
329
FXVerticalFrame* myVerticalFrame = nullptr;
330
331
/// @brief column top tooltip label
332
MFXLabelTooltip* myTopLabel = nullptr;
333
334
/// @brief vertical frame
335
FXVerticalFrame* myVerticalCellFrame = nullptr;
336
337
/// @brief column bot label
338
FXLabel* myBotLabel = nullptr;
339
340
/// @brief column index
341
const int myIndex;
342
343
/// @brief column type
344
const char myType;
345
346
/// @brief check if current type correspond to a textField
347
bool isTextFieldColumn() const;
348
349
/// @brief default constructor
350
Column();
351
};
352
353
/// @brief table row
354
class Row {
355
356
public:
357
/// @brief constructor
358
Row(GNETLSTable* table);
359
360
/// @brief destructor
361
~Row();
362
363
/// @brief get text
364
std::string getText(int index) const;
365
366
/// @brief set text
367
void setText(int index, const std::string& text) const;
368
369
/// @brief get cells
370
const std::vector<Cell*>& getCells() const;
371
372
/// @brief disable row buttons
373
void disableButtons();
374
375
protected:
376
/// @brief poiner to table parent
377
GNETLSTable* myTable = nullptr;
378
379
/// @brief list wtih cells
380
std::vector<Cell*> myCells;
381
382
private:
383
/// @brief default constructor
384
Row();
385
};
386
387
/// @brief update index labels
388
void updateIndexLabel();
389
390
/// @brief update accumulated duration();
391
void updateAccumulatedDuration();
392
393
/// @brief move focus to current row
394
bool moveFocus();
395
396
/// @brief font for the phase table
397
FXFont* myProgramFont = nullptr;
398
399
/// @brief font for index
400
FXFont* myIndexFont = nullptr;
401
402
/// @brief font for index selected
403
FXFont* myIndexSelectedFont = nullptr;
404
405
/// @frame pointer to TLSEditorFrame phases parent
406
GNETLSEditorFrame::TLSPhases* myTLSPhasesParent = nullptr;
407
408
/// @brief columns
409
std::vector<Column*> myColumns;
410
411
/// @brief rows
412
std::vector<Row*> myRows;
413
414
/// @brief current selected row
415
int myCurrentSelectedRow = -1;
416
417
private:
418
/// @brief Invalidated duplicate constructor.
419
GNETLSTable(const GNETLSTable&) = delete;
420
421
/// @brief Invalidated assignment operator.
422
GNETLSTable& operator=(const GNETLSTable&) = delete;
423
};
424
425
#endif
426
427