/****************************************************************************/1// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo2// Copyright (C) 2001-2025 German Aerospace Center (DLR) and others.3// This program and the accompanying materials are made available under the4// terms of the Eclipse Public License 2.0 which is available at5// https://www.eclipse.org/legal/epl-2.0/6// This Source Code may also be made available under the following Secondary7// Licenses when the conditions for such availability set forth in the Eclipse8// Public License 2.0 are satisfied: GNU General Public License, version 29// or later which is available at10// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html11// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later12/****************************************************************************/13/// @file GNETLSTable.h14/// @author Pablo Alvarez Lopez15/// @date 2022-07-2116///17// Table used in GNETLSFrame for editing TLS programs18/****************************************************************************/19#ifndef GNETLSTable_h20#define GNETLSTable_h21#include <config.h>2223#include <vector>24#include <netedit/frames/network/GNETLSEditorFrame.h>25#include <utils/tests/InternalTestStep.h>2627// ===========================================================================28// class declaration29// ===========================================================================3031class MFXTextFieldIcon;32class MFXLabelTooltip;33class MFXMenuButtonTooltip;3435// ===========================================================================36// class definitions37// ===========================================================================3839class GNETLSTable : public FXHorizontalFrame {40/// @brief fox declaration41FXDECLARE(GNETLSTable)4243public:44/// @brief constructor (Exactly like the FXButton constructor)45GNETLSTable(GNETLSEditorFrame::TLSPhases* TLSPhasesParent);4647/// @brief destructor (Called automatically)48~GNETLSTable();4950/// @brief Enable table51void enable();5253/// @brief Disable table54void disable();5556/// @frame get pointer to TLSEditorFrame phases parent57GNETLSEditorFrame::TLSPhases* getTLSPhasesParent() const;5859/// @brief recalc width (call when all labels and contents are fill)60void recalcTableWidth();6162/// @brief clear table63void clearTable();6465/// @brief Modify cell text66void setItemText(FXint row, FXint column, const std::string& text);6768/// @brief Return cell text69std::string getItemText(const int row, const int column) const;7071/// @brief Get number of rows72int getNumRows() const;7374/// @brief Get current selected row75int getCurrentSelectedRow() const;7677/// @brief Select a row78void selectRow(const int rowIndex);7980/// @brief Change column header text81void setColumnLabelTop(const int column, const std::string& text, const std::string& tooltip = "");8283/// @brief Change column bottom text84void setColumnLabelBot(const int column, const std::string& text);8586/**@brief Set the table size to nr rows and nc columns; all existing items will be removed. Format:87* s -> select row (radio button)88* u -> duration (float, textField)89* f -> float (float, textField)90* p -> program (rrGggy..., textField)91* m -> name (automatic size, textField)92* i -> insert phase (button)93* d -> delete phase (button)94* t -> move phase up (button)95* b -> move phase down (button)96* - -> general text (textField)97*/98void setTableSize(const std::string& columnsType, const int numberRow);99100/// @brief test table (using internal tests)101long testTable(const InternalTestStep::TLSTableTest* tableTest);102103/// @name FOX callbacks104/// @{105106/// @brief called when a row is focused107long onFocusRow(FXObject*, FXSelector, void*);108109/// @brief called when add phase button is selected110long onCmdAddPhasePressed(FXObject*, FXSelector, void*);111112/// @brief called when a row is modified113long onCmdEditRow(FXObject*, FXSelector, void*);114115/// @brief called when a key is pressed116long onCmdKeyPress(FXObject*, FXSelector, void*);117118/// @brief called when an add phase button is pressed119long onCmdAddPhase(FXObject*, FXSelector, void*);120121/// @brief called when a duplicate phase button is pressed122long onCmdDuplicatePhase(FXObject*, FXSelector, void*);123124/// @brief called when an add all green red phase button is pressed125long onCmdAddPhaseAllRed(FXObject*, FXSelector, void*);126127/// @brief called when an add all green red phase button is pressed128long onCmdAddPhaseAllYellow(FXObject*, FXSelector, void*);129130/// @brief called when an add all green red phase button is pressed131long onCmdAddPhaseAllGreen(FXObject*, FXSelector, void*);132133/// @brief called when an add all green red phase button is pressed134long onCmdAddPhaseAllGreenPriority(FXObject*, FXSelector, void*);135136/// @brief called when a remove phase button is pressed137long onCmdRemovePhase(FXObject*, FXSelector, void*);138139/// @brief called when a move up phase button is pressed140long onCmdMoveUpPhase(FXObject*, FXSelector, void*);141142/// @brief called when a move up phase button is pressed143long onCmdMoveDownPhase(FXObject*, FXSelector, void*);144145/// @}146147protected:148/// @brief FOX needs this149FOX_CONSTRUCTOR(GNETLSTable)150151/// @brief table cell152class Cell {153154public:155/// @brief constructor for textField156Cell(GNETLSTable* TLSTable, MFXTextFieldIcon* textField, int col, int row);157158/// @brief constructor for index label159Cell(GNETLSTable* TLSTable, FXLabel* indexLabel, FXLabel* indexLabelBold, int col, int row);160161/// @brief constructor for buttons162Cell(GNETLSTable* TLSTable, MFXButtonTooltip* button, int col, int row);163164/// @brief constructor for menu buttons165Cell(GNETLSTable* TLSTable, int col, int row);166167/// @brief destructor168~Cell();169170/// @brief Enable cell171void enable();172173/// @brief Disable cell174void disable();175176/// @brief check if current cell has focus177bool hasFocus() const;178179/// @brief set focus in the current cell180void setFocus();181182/// @brief get double value (only for types 'u' and 'd')183double getDoubleValue() const;184185/// @brief set tooltip186void setTooltip(const std::string& toolTip);187188/// @brief get textField189MFXTextFieldIcon* getTextField() const;190191/// @brief get index label192FXLabel* getIndexLabel() const;193194/// @brief get add button195MFXMenuButtonTooltip* getAddButton() const;196197/// @brief get remove, move up or move down button198MFXButtonTooltip* getButton();199200/// @brief get add phase button201MFXButtonTooltip* getAddPhaseButton();202203/// @brief get duplicate phase button204MFXButtonTooltip* getDuplicatePhaseButton();205206/// @brief get add all red phase button207MFXButtonTooltip* getAddAllRedPhaseButton();208209/// @brief get add all yellow phase button210MFXButtonTooltip* getAddAllYellowPhaseButton();211212/// @brief get add all green phase button213MFXButtonTooltip* getAddAllGreenPhaseButton();214215/// @brief get add all green priority phase button216MFXButtonTooltip* getAddAllGreenPriorityPhaseButton();217218/// @brief show label index normal219void showIndexLabelNormal();220221/// @brief show label index bold222void showIndexLabelBold();223224/// @brief column index225int getCol() const;226227/// @brief row index228int getRow() const;229230/// @brief get column type231char getType() const;232233/// @brief hide menuButton popup234void hideMenuButtonPopup();235236/// @brief disable button (used for delete, move up and move down)237void disableButton();238239private:240/// @brief pointer to TLSTable parent241GNETLSTable* myTLSTable = nullptr;242243/// @brief MFXTextFieldIcon244MFXTextFieldIcon* myTextField = nullptr;245246/// @brief index label247FXLabel* myIndexLabel = nullptr;248249/// @brief index label bold250FXLabel* myIndexLabelBold = nullptr;251252/// @brief button253MFXButtonTooltip* myButton = nullptr;254255/// @brief popup for buttons256FXPopup* myMenuButtonPopup = nullptr;257258/// @brief menu button tooltip259MFXMenuButtonTooltip* myAddButton = nullptr;260261/// @brief add phase button262MFXButtonTooltip* myAddPhaseButton = nullptr;263264/// @brief duplicate phase button265MFXButtonTooltip* myDuplicatePhaseButton = nullptr;266267/// @brief add all red phase button268MFXButtonTooltip* myAddAllRedButton = nullptr;269270/// @brief add all yellow phase button271MFXButtonTooltip* myAddAllYellowButton = nullptr;272273/// @brief add all green phase button274MFXButtonTooltip* myAddAllGreenButton = nullptr;275276/// @brief add all green priority phase button277MFXButtonTooltip* myAddAllGreenPriorityButton = nullptr;278279/// @brief column index280const int myCol;281282/// @brief row index283const int myRow;284285/// @brief disable button286bool myDisableButton = false;287288/// @brief default constructor289Cell();290};291292/// @brief table column293class Column {294295public:296/// @brief constructor297Column(GNETLSTable* table, const int index, const char type);298299/// @brief destructor300~Column();301302/// @brief get vertical cell frame303FXVerticalFrame* getVerticalCellFrame() const;304305/// @brief get column type306char getType() const;307308/// @brief get column label top309FXString getColumnLabelTop() const;310311/// @brief set column label top312void setColumnLabelTop(const std::string& text, const std::string& tooltip);313314/// @brief set column label boit315void setColumnLabelBot(const std::string& text);316317/// @brief get column minimum width318int getColumnMinimumWidth();319320/// @brief set colum width321void setColumnWidth(const int colWidth);322323private:324/// @brief pointer to table325GNETLSTable* myTable = nullptr;326327/// @brief vertical frame328FXVerticalFrame* myVerticalFrame = nullptr;329330/// @brief column top tooltip label331MFXLabelTooltip* myTopLabel = nullptr;332333/// @brief vertical frame334FXVerticalFrame* myVerticalCellFrame = nullptr;335336/// @brief column bot label337FXLabel* myBotLabel = nullptr;338339/// @brief column index340const int myIndex;341342/// @brief column type343const char myType;344345/// @brief check if current type correspond to a textField346bool isTextFieldColumn() const;347348/// @brief default constructor349Column();350};351352/// @brief table row353class Row {354355public:356/// @brief constructor357Row(GNETLSTable* table);358359/// @brief destructor360~Row();361362/// @brief get text363std::string getText(int index) const;364365/// @brief set text366void setText(int index, const std::string& text) const;367368/// @brief get cells369const std::vector<Cell*>& getCells() const;370371/// @brief disable row buttons372void disableButtons();373374protected:375/// @brief poiner to table parent376GNETLSTable* myTable = nullptr;377378/// @brief list wtih cells379std::vector<Cell*> myCells;380381private:382/// @brief default constructor383Row();384};385386/// @brief update index labels387void updateIndexLabel();388389/// @brief update accumulated duration();390void updateAccumulatedDuration();391392/// @brief move focus to current row393bool moveFocus();394395/// @brief font for the phase table396FXFont* myProgramFont = nullptr;397398/// @brief font for index399FXFont* myIndexFont = nullptr;400401/// @brief font for index selected402FXFont* myIndexSelectedFont = nullptr;403404/// @frame pointer to TLSEditorFrame phases parent405GNETLSEditorFrame::TLSPhases* myTLSPhasesParent = nullptr;406407/// @brief columns408std::vector<Column*> myColumns;409410/// @brief rows411std::vector<Row*> myRows;412413/// @brief current selected row414int myCurrentSelectedRow = -1;415416private:417/// @brief Invalidated duplicate constructor.418GNETLSTable(const GNETLSTable&) = delete;419420/// @brief Invalidated assignment operator.421GNETLSTable& operator=(const GNETLSTable&) = delete;422};423424#endif425426427