Path: blob/main/src/netedit/frames/network/GNETLSEditorFrame.h
169685 views
/****************************************************************************/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 GNETLSEditorFrame.h14/// @author Jakob Erdmann15/// @date May 201116///17// The Widget for modifying traffic lights18/****************************************************************************/19#pragma once20#include <config.h>2122#include <netedit/frames/GNEFrame.h>23#include <netedit/GNEViewNetHelper.h>24#include <netbuild/NBTrafficLightLogic.h>2526// ===========================================================================27// class declarations28// ===========================================================================2930class GNEOverlappedInspection;31class GNETLSTable;32class MFXComboBoxIcon;33class MFXTextFieldIcon;34class MFXToggleButtonTooltip;35class NBLoadedSUMOTLDef;36class NBOwnTLDef;37class NBTrafficLightDefinition;3839// ===========================================================================40// class definitions41// ===========================================================================4243class GNETLSEditorFrame : public GNEFrame {4445public:46// ===========================================================================47// class TLSJunction48// ===========================================================================4950class TLSJunction : public MFXGroupBoxModule {51/// @brief FOX-declaration52FXDECLARE(GNETLSEditorFrame::TLSJunction)5354public:55/// @brief constructor56TLSJunction(GNETLSEditorFrame* TLSEditorParent);5758/// @brief destructor59~TLSJunction();6061/// @brief update TLSJunction module62void updateTLSJunction();6364/// @brief get current modified junction65GNEJunction* getCurrentJunction() const;6667/// @brief set current junction68void setCurrentJunction(GNEJunction* junction);6970/// @brief is joining junctions71bool isJoiningJunctions() const;7273/// @brief check if given junction is selected (used fo joining)74bool isJunctionSelected(const GNEJunction* junction) const;7576/// @brief select or unselect junction in the current TLS77void toggleJunctionSelected(const GNEJunction* junction);7879/// @brief get selected junction IDs80const std::vector<std::string>& getSelectedJunctionIDs() const;8182/// @name FOX-callbacks83/// @{84/// @brief Called when the user rename TLS85long onCmdRenameTLS(FXObject*, FXSelector, void*);8687/// @brief Called when the user change TLS Type88long onCmdChangeType(FXObject*, FXSelector, void*);8990/// @brief Called when the user join TLS91long onCmdToggleJoinTLS(FXObject*, FXSelector, void*);9293/// @brief Called when the user join TLS94long onCmdDisjoinTLS(FXObject*, FXSelector, void*);9596/// @brief accept join97long onCmdAcceptJoin(FXObject*, FXSelector, void*);9899/// @brief cancel join100long onCmdCancelJoin(FXObject*, FXSelector, void*);101102/// @}103104protected:105/// @brief FOX needs this106FOX_CONSTRUCTOR(TLSJunction)107108/// @brief refresh TLJunction module109void refreshTLSJunction();110111private:112/// @brief TLS editor frame parent113GNETLSEditorFrame* myTLSEditorParent;114115/// @brief label for junction ID116FXLabel* myJunctionIDLabel = nullptr;117118/// @brief text field for junction ID119MFXTextFieldIcon* myJunctionIDTextField = nullptr;120121/// @brief text field for junction ID122MFXTextFieldIcon* myTLSIDTextField = nullptr;123124/// @brief ComboBox for TLS Types125MFXComboBoxIcon* myTLSTypeComboBox = nullptr;126127/// @brief Toggle button for join TLS128MFXToggleButtonTooltip* myJoinTLSToggleButton = nullptr;129130/// @brief button for disjoin TLS131MFXButtonTooltip* myDisjoinTLSButton = nullptr;132133/// @brief frame for accept/cancel buttons134FXHorizontalFrame* myJoinControlButtons = nullptr;135136/// @brief the junction of the tls is being modified137GNEJunction* myCurrentJunction = nullptr;138139/// @brief selected junction (used for join)140std::vector<std::string> mySelectedJunctionIDs;141142/// @brief original selected junction (used for join)143std::vector<std::string> myOriginalSelectedJunctionIDs;144145/// @brief Invalidated copy constructor.146TLSJunction(const TLSJunction&) = delete;147148/// @brief Invalidated assignment operator.149TLSJunction& operator=(const TLSJunction&) = delete;150};151152// ===========================================================================153// class TLSPrograms154// ===========================================================================155156class TLSPrograms : public MFXGroupBoxModule {157/// @brief FOX-declaration158FXDECLARE(GNETLSEditorFrame::TLSPrograms)159160public:161/// @brief constructor162TLSPrograms(GNETLSEditorFrame* TLSEditorParent);163164/// @brief destructor165~TLSPrograms();166167/// @brief update TLSPrograms module168void updateTLSPrograms();169170/// @brief show TLSPrograms171void showTLSPrograms();172173/// @brief hide TLSPrograms174void hideTLSPrograms();175176/// @brief init TLS Definitions177bool initTLSPrograms();178179/// @brief clear TLS Definitions180void clearTLSProgramss();181182/// @brief get number of programs183int getNumberOfPrograms() const;184185/// @brief check if current TLS was modified186bool checkHaveModifications() const;187188/// @brief mark Program as modified189void markAsModified();190191/// @brief get current definition192NBTrafficLightDefinition* getCurrentTLSPrograms() const;193194/// @brief get current program ID195const std::string getCurrentTLSProgramID() const;196197/// @brief discard changes198void discardChanges(const bool editJunctionAgain);199200/// @name FOX-callbacks201/// @{202/// @brief Called when the user press button create/duplicate TLS Program203long onCmdCreate(FXObject*, FXSelector, void*);204205/// @brief Called when the user press button delete TLS Program206long onCmdDelete(FXObject*, FXSelector, void*);207208/// @brief Called when the user press button reset current TLS Program209long onCmdResetCurrentProgram(FXObject*, FXSelector, void*);210211/// @brief Called when the user press button reset all TLS Programs212long onCmdResetAll(FXObject*, FXSelector, void*);213214/// @brief Called when the user switches a TLS215long onCmdDefSwitchTLSProgram(FXObject*, FXSelector, void*);216217/// @brief Called when the user presses the save-Button218long onCmdSaveChanges(FXObject*, FXSelector, void*);219220/// @brief Called when the user presses the Cancel-button221long onCmdDiscardChanges(FXObject*, FXSelector, void*);222223/// @}224225protected:226/// @brief FOX needs this227FOX_CONSTRUCTOR(TLSPrograms)228229/// @brief create (or duplicate) TLS in the given junction230void createTLS(GNEJunction* junction);231232/// @brief switch program233bool switchProgram();234235private:236/// @brief pointer to GNETLSEditorFrame parent237GNETLSEditorFrame* myTLSEditorParent = nullptr;238239/// @brief the list of Definitions for the current junction240std::vector<NBTrafficLightDefinition*> myTLSPrograms;241242/// @brief the comboBox for selecting the tl-definition to edit243MFXComboBoxIcon* myProgramComboBox;244245/// @brief whether the current tls was modified246bool myHaveModifications = false;247248/// @brief button for create new TLS program249FXButton* myCreateButton = nullptr;250251/// @brief button for delete existent TLS program252FXButton* myDeleteButton = nullptr;253254/// @brief button for reset TLS program255FXButton* myResetSingleButton = nullptr;256257/// @brief button for reset all TLS program258FXButton* myResetAllButton = nullptr;259260/// @brief button for save TLS program261FXButton* mySaveButon = nullptr;262263/// @brief button for cancel TLS program264FXButton* myCancelButon = nullptr;265266/// @brief Invalidated copy constructor.267TLSPrograms(const TLSPrograms&) = delete;268269/// @brief Invalidated assignment operator.270TLSPrograms& operator=(const TLSPrograms&) = delete;271};272273// ===========================================================================274// class TLSAttributes275// ===========================================================================276277class TLSAttributes : public MFXGroupBoxModule {278/// @brief FOX-declaration279FXDECLARE(GNETLSEditorFrame::TLSAttributes)280281public:282/// @brief constructor283TLSAttributes(GNETLSEditorFrame* TLSEditorParent);284285/// @brief destructor286~TLSAttributes();287288/// @brief update TLSAttributes module289void updateTLSAttributes();290291/// @brief show TLSAttributes292void showTLSAttributes();293294/// @brief hide TLSAttributes295void hideTLSAttributes();296297/// @brief initializes the definitions and corresponding listbox298void initTLSAttributes();299300/// @brief clear TLS attributes301void clearTLSAttributes();302303/// @brief get current offset in string format304SUMOTime getOffset() const;305306/// @brief set new offset307void setOffset(const SUMOTime& offset);308309/// @brief is current offset valid310bool isValidOffset();311312/// @brief get current parameters in string format313std::string getParameters() const;314315/// @brief set new parameters316void setParameters(const std::string& parameters);317318/// @brief are current parameter valid319bool isValidParameters();320321/// @brief toggle button for set detectors mode322bool isSetDetectorsToggleButtonEnabled() const;323324/// @brief select or unselect E1 detector in the current TLS325bool toggleE1DetectorSelection(const GNEAdditional* E1);326327/// @brief get E1 detectors vinculated with this TLS328const std::map<std::string, std::string>& getE1Detectors() const;329330/// @brief disable detector mode331void disableE1DetectorMode();332333/// @name FOX-callbacks334/// @{335/// @brief Called when the user changes the offset of a TLS336long onCmdSetOffset(FXObject*, FXSelector, void*);337338/// @brief Called when the user changes parameters of a TLS339long onCmdSetParameters(FXObject*, FXSelector, void*);340341/// @brief Called when user press edit parameters button342long onCmdParametersDialog(FXObject*, FXSelector, void* ptr);343344/// @brief Called when user toggle set detector mode345long onCmdToggleDetectorMode(FXObject*, FXSelector, void* ptr);346347/// @}348349protected:350/// @brief FOX needs this351FOX_CONSTRUCTOR(TLSAttributes)352353/// @brief update E1 detectors354void updateE1Detectors();355356private:357/// @brief pointer to TLSEditorParent358GNETLSEditorFrame* myTLSEditorParent;359360/// @brief the TextField for modifying offset361FXTextField* myOffsetTextField = nullptr;362363/// @brief button for edit parameters364FXButton* myButtonEditParameters = nullptr;365366/// @brief the TextField for modifying parameters367FXTextField* myParametersTextField = nullptr;368369/// @brief toggle button for set detectors mode370MFXToggleButtonTooltip* mySetDetectorsToggleButton = nullptr;371372/// @brief set with E1 detector IDs and their lanes vinculated with the TLS <laneID, E1ID>373std::map<std::string, std::string> myE1Detectors;374375/// @brief Invalidated copy constructor.376TLSAttributes(const TLSAttributes&) = delete;377378/// @brief Invalidated assignment operator.379TLSAttributes& operator=(const TLSAttributes&) = delete;380};381382// ===========================================================================383// class TLSPhases384// ===========================================================================385386class TLSPhases : public MFXGroupBoxModule {387/// @brief FOX-declaration388FXDECLARE(GNETLSEditorFrame::TLSPhases)389390public:391/// @brief constructor392TLSPhases(GNETLSEditorFrame* TLSEditorParent);393394/// @brief destructor395~TLSPhases();396397/// @brief update TLSPhases module398void updateTLSPhases();399400/// @brief show TLSPhases401void showTLSPhases();402403/// @brief hide TLSPhases404void hideTLSPhases();405406/// @brief get TLSEditor Parent407GNETLSEditorFrame* getTLSEditorParent() const;408409/// @brief get phase table410GNETLSTable* getPhaseTable() const;411412/**@brief initializes the phase table413* @param[in] index The index to select414*/415void initPhaseTable();416417/// @brief clear phase thable418void clearPhaseTable();419420/// @brief change phase value (state, name, next, etc.)421bool changePhaseValue(const int col, const int row, const std::string& value);422423/// @brief add phase424void addPhase(const int row, const char c = ' ');425426/// @brief duplicate phase427void duplicatePhase(const int row);428429/// @brief delete phase430void removePhase(const int row);431432/// @brief move phase up433void movePhaseUp(const int row);434435/// @brief move phase down436void movePhaseDown(const int row);437438/// @brief update TLS coloring439void updateTLSColoring();440441/// @name FOX-callbacks442/// @{443/// @brief Called when the user cleans up states444long onCmdCleanStates(FXObject*, FXSelector, void*);445446/// @brief Called when the user cleans up states447long onCmdAddUnusedStates(FXObject*, FXSelector, void*);448449/// @brief Called when the user groups states450long onCmdGroupStates(FXObject*, FXSelector, void*);451452/// @brief Called when the user ungroups states453long onCmdUngroupStates(FXObject*, FXSelector, void*);454455/// @}456457protected:458/// @brief FOX needs this459FOX_CONSTRUCTOR(TLSPhases)460461/// @brief update table462void updateTable();463464private:465/// @brief init static phase table466void initStaticPhaseTable();467468/// @brief init actuated phase table469void initActuatedPhaseTable();470471/// @brief init delayBase phase table472void initDelayBasePhaseTable();473474/// @brief init NEMA phase table475void initNEMAPhaseTable();476477/// @brief build default phase478int buildDefaultPhase(const int row);479480/// @brief set duration481bool setDuration(const int col, const int row, const std::string& value);482483/// @brief set state484bool setState(const int col, const int row, const std::string& value);485486/// @brief set next487bool setNext(const int row, const std::string& value);488489/// @brief set name490bool setName(const int row, const std::string& value);491492/// @brief set minDur493bool setMinDur(const int row, const std::string& value);494495/// @brief set maxDur496bool setMaxDur(const int row, const std::string& value);497498/// @brief set earliestEnd499bool setEarliestEnd(const int row, const std::string& value);500501/// @brief set latestEnd502bool setLatestEnd(const int row, const std::string& value);503504/// @brief set vehExt505bool setVehExt(const int row, const std::string& value);506507/// @brief set yellow508bool setYellow(const int row, const std::string& value);509510/// @brief set red511bool setRed(const int row, const std::string& value);512513/// @brief recomputes cycle duration and updates label514void updateCycleDuration(const int col);515516/// @brief update state size517void updateStateSize(const int col);518519/// @brief pointer to TLSEditor Parent520GNETLSEditorFrame* myTLSEditorParent;521522/// @brief table for selecting and rearranging phases and for changing duration523GNETLSTable* myPhaseTable;524525/// @brief clean states button526MFXButtonTooltip* myCleanStatesButton = nullptr;527528/// @brief add states button529MFXButtonTooltip* myAddStates = nullptr;530531/// @brief group signals button532MFXButtonTooltip* myGroupSignalsButton = nullptr;533534/// @brief ungroup signals button535MFXButtonTooltip* myUngroupSignalsButton = nullptr;536537/// @brief Invalidated copy constructor.538TLSPhases(const TLSPhases&) = delete;539540/// @brief Invalidated assignment operator.541TLSPhases& operator=(const TLSPhases&) = delete;542};543544// ===========================================================================545// class TLSFile546// ===========================================================================547548class TLSFile : public MFXGroupBoxModule {549/// @brief FOX-declaration550FXDECLARE(GNETLSEditorFrame::TLSFile)551552public:553/// @brief constructor554TLSFile(GNETLSEditorFrame* TLSEditorParent);555556/// @brief destructor557~TLSFile();558559/// @brief update TLSFile module560void updateTLSFile();561562/// @brief show TLSPhases563void showTLSFile();564565/// @brief hide TLSPhases566void hideTLSFile();567568/// @name FOX-callbacks569/// @{570571/// @brief load TLS Program from an additional file572long onCmdLoadTLSProgram(FXObject*, FXSelector, void*);573574/// @brief save TLS Program to an additional file575long onCmdSaveTLSProgram(FXObject*, FXSelector, void*);576577/// @}578579protected:580/// @brief FOX needs this581FOX_CONSTRUCTOR(TLSFile)582583/// @brief convert SUMOTime into string584std::string writeSUMOTime(SUMOTime steps);585586private:587/// @brief pointer to TLSEditor Parent588GNETLSEditorFrame* myTLSEditorParent;589590/// @brief load button591FXButton* myLoadButton = nullptr;592593/// @brief save button594FXButton* mySaveButton = nullptr;595596/// @brief Invalidated copy constructor.597TLSFile(const TLSFile&) = delete;598599/// @brief Invalidated assignment operator.600TLSFile& operator=(const TLSFile&) = delete;601};602603/**@brief Constructor604* @brief viewParent GNEViewParent in which this GNEFrame is placed605* @brief viewNet viewNet that uses this GNEFrame606*/607GNETLSEditorFrame(GNEViewParent* viewParent, GNEViewNet* viewNet);608609/// @brief Destructor610~GNETLSEditorFrame();611612/// @brief show inspector frame613void show();614615/// @brief function called after setting new width in current frame616void frameWidthUpdated();617618/// @brief update modules619void updateModules();620621/**@brief edits the traffic light for the given clicked junction622* @param[in] clickedPosition clicked position623* @param[in] viewObjects The clicked objects under cursor624*/625void editTLS(GNEViewNetHelper::ViewObjectsSelector& viewObjects, const Position& clickedPosition, const bool shiftKeyPressed);626627/// @brief check if modifications in TLS was saved628bool isTLSSaved();629630/// @brief parse TLS Programs from a file631bool parseTLSPrograms(const std::string& file);632633/// @brief update phase definition for the current traffic light and phase634void handleChange(GNEInternalLane* lane);635636/// @brief update phase definition for the current traffic light and phase637void handleMultiChange(GNELane* lane, FXObject* obj, FXSelector sel, void* data);638639/// @brief whether the given edge is controlled by the currently edited tlDef640bool controlsEdge(GNEEdge* edge) const;641642/// @brief open GNEAttributesCreator extended dialog (can be reimplemented in frame children)643void selectedOverlappedElement(GNEAttributeCarrier* AC);644645/**@brief edits the traffic light for the given junction646* @param[in] junction The junction of which the traffic light shall be edited647*/648void editJunction(GNEJunction* junction);649650/// @brief get module for TLS Junction651GNETLSEditorFrame::TLSJunction* getTLSJunction() const;652653/// @brief get module for TLS Definition654GNETLSEditorFrame::TLSPrograms* getTLSPrograms() const;655656/// @brief get module for TLS attributes657GNETLSEditorFrame::TLSAttributes* getTLSAttributes() const;658659/// @brief get module for TLS Phases660GNETLSEditorFrame::TLSPhases* getTLSPhases() const;661662protected:663/// @brief converts to SUMOTime664static SUMOTime getSUMOTime(const std::string& value);665666/// @brief converts to SUMOTime667static const std::string getSteps2Time(const SUMOTime value);668669private:670/// @brief Overlapped Inspection671GNEOverlappedInspection* myOverlappedInspection = nullptr;672673/// @brief module for TLS Junction674GNETLSEditorFrame::TLSJunction* myTLSJunction = nullptr;675676/// @brief module for TLS Definition677GNETLSEditorFrame::TLSPrograms* myTLSPrograms = nullptr;678679/// @brief module for TLS attributes680GNETLSEditorFrame::TLSAttributes* myTLSAttributes = nullptr;681682/// @brief module for TLS Phases683GNETLSEditorFrame::TLSPhases* myTLSPhases = nullptr;684685/// @brief module for load/Save TLS Programs686GNETLSEditorFrame::TLSFile* myTLSFile = nullptr;687688/// @brief the internal lanes belonging to the current junction indexed by their tl-index689std::map<int, std::vector<GNEInternalLane*> > myInternalLanes;690691/// @brief the traffic light definition being edited692NBLoadedSUMOTLDef* myEditedDef = nullptr;693694/// @brief cleans up previous lanes695void cleanup();696697/// @brief builds internal lanes for the given tlDef698void buildInternalLanes(const NBTrafficLightDefinition* tlDef);699700/// @brief get certain phase of the current traffic light701const NBTrafficLightLogic::PhaseDefinition& getPhase(const int index);702703/// @brief convert duration (potentially undefined) to string704static std::string varDurString(SUMOTime dur);705706/// @brief Invalidated copy constructor.707GNETLSEditorFrame(const GNETLSEditorFrame&) = delete;708709/// @brief Invalidated assignment operator.710GNETLSEditorFrame& operator=(const GNETLSEditorFrame&) = delete;711};712713714