/****************************************************************************/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 GUITLLogicPhasesTrackerWindow.h14/// @author Daniel Krajzewicz15/// @author Jakob Erdmann16/// @author Michael Behrisch17/// @date Oct/Nov 200318///19// A window displaying the phase diagram of a tl-logic20/****************************************************************************/21#pragma once22#include <config.h>2324#include <vector>25#include <string>26#include <bitset>27#include <utility>28#include <utils/foxtools/fxheader.h>29// fx3d includes windows.h so we need to guard against macro pollution30#ifdef WIN3231#define NOMINMAX32#endif33#include <fx3d.h>34#ifdef WIN3235#undef NOMINMAX36#endif37#include <microsim/traffic_lights/MSSimpleTrafficLightLogic.h>38#include <microsim/traffic_lights/MSTLLogicControl.h>39#include <utils/common/ValueRetriever.h>40#include <utils/gui/div/GLObjectValuePassConnector.h>41#include <microsim/logging/FunctionBinding.h>42#include <utils/common/SUMOTime.h>434445// ===========================================================================46// class declarations47// ===========================================================================48class GUIMainWindow;49class MSTrafficLightLogic;50class GUITrafficLightLogicWrapper;515253// ===========================================================================54// class definitions55// ===========================================================================56/**57* @class GUITLLogicPhasesTrackerWindow58* @brief This window displays a phase diagram for a chosen tl-logic.59*/60class GUITLLogicPhasesTrackerWindow61: public FXMainWindow,62public ValueRetriever<std::pair<SUMOTime, MSPhaseDefinition> > {63FXDECLARE(GUITLLogicPhasesTrackerWindow)64public:65/** @brief Constructor to track current phases66* @param[in] app The main application window67* @param[in] logic The logic to track68* @param[in] wrapper The tracked logic's wrapper69* @param[in] src The value source to track70*/71GUITLLogicPhasesTrackerWindow(GUIMainWindow& app,72MSTrafficLightLogic& logic, GUITrafficLightLogicWrapper& wrapper,73ValueSource<std::pair<SUMOTime, MSPhaseDefinition> >* src);747576/** @brief Constructor to show the complete phase diagram77* @param[in] app The main application window78* @param[in] logic The logic to show79* @param[in] wrapper The shown logic's wrapper80* @param[in] phases The phases to show81*/82GUITLLogicPhasesTrackerWindow(83GUIMainWindow& app,84MSTrafficLightLogic& logic, GUITrafficLightLogicWrapper& wrapper,85const MSSimpleTrafficLightLogic::Phases& phases);868788/// @brief Destructor89~GUITLLogicPhasesTrackerWindow();909192/// @brief Creates the window (FOX-Toolkit)93void create();949596/** @brief Adds a further phase definition97* @param[in] def The definition to add98*/99void addValue(std::pair<SUMOTime, MSPhaseDefinition> def);100101102/** @brief Sets the time the display shall be shown as beginning at103* @param[in] time The time to start to show the phases from104*/105void setBeginTime(SUMOTime time);106107108/// @name FOX-callbacks109/// {110111/// @brief called on size change112long onConfigure(FXObject* sender, FXSelector sel, void* ptr);113114/// @brief called if the widget shall be repainted115long onPaint(FXObject* sender, FXSelector sel, void* ptr);116117/// @brief called on a simulation step118long onSimStep(FXObject* sender, FXSelector sel, void* ptr);119120/// }121122123124public:125/// @brief Definition of a storage for phases126typedef std::vector<MSPhaseDefinition> PhasesVector;127128/// @brief Definition of a storage for durations129typedef std::vector<SUMOTime> DurationsVector;130131/// @brief Definition of a storage for indices132typedef std::vector<int> IndexVector;133134/// @brief Definition of a storage for detector and condition states135typedef std::vector<std::vector<double > > AdditionalStatesVector;136137/**138* @class GUITLLogicPhasesTrackerPanel139* @brief The canvas for the visualisation of phases140*141* The drawing itself id done by the parent.142*/143class GUITLLogicPhasesTrackerPanel : public FXGLCanvas {144FXDECLARE(GUITLLogicPhasesTrackerPanel)145public:146/** @brief Constructor147* @param[in] c The container for this panel148* @param[in] app The main application window149* @param[in] parent This panel's logical parent150*/151GUITLLogicPhasesTrackerPanel(FXComposite* c,152GUIMainWindow& app, GUITLLogicPhasesTrackerWindow& parent);153154/// @brief Destructor155~GUITLLogicPhasesTrackerPanel();156157/// needed to update158friend class GUITLLogicPhasesTrackerWindow;159160161/// @name FOX-callbacks162/// {163164/// @brief called on size change165long onConfigure(FXObject*, FXSelector, void*);166167/// @brief called if the widget shall be repainted168long onPaint(FXObject*, FXSelector, void*);169170/// @brief called on mouse movement (for updating tooltip)171long onMouseMove(FXObject*, FXSelector, void*);172/// }173174const Position& getMousePos() const {175return myMousePos;176};177178private:179/// @brief The parent window180GUITLLogicPhasesTrackerWindow* myParent;181182Position myMousePos;183184protected:185/// @brief protected constructor for FOX186GUITLLogicPhasesTrackerPanel() { }187188};189190191/** @brief Draws all values192* @param[in] The target panel193*/194void drawValues(GUITLLogicPhasesTrackerPanel& caller);195196197private:198/// @brief The main application199GUIMainWindow* myApplication;200201/// @brief The logic to display202MSTrafficLightLogic* myTLLogic;203204/// @brief The list of phases205PhasesVector myPhases;206207/// @brief The list of phase durations208DurationsVector myDurations;209210/// @brief The time within the cycle for the current phase211DurationsVector myTimeInCycle;212213/// @brief The index of the current phase214IndexVector myPhaseIndex;215216/// @brief The state of all used detectors of the current phase217AdditionalStatesVector myDetectorStates;218AdditionalStatesVector myConditionStates;219220/// @brief The list of detector state durations221DurationsVector myDetectorDurations;222DurationsVector myConditionDurations;223224/// @brief The panel to draw on225GUITLLogicPhasesTrackerPanel* myPanel;226227/// @brief A lock to avoid addition of new values while drawing228FXMutex myLock;229230/** @brief The names of links231*232* This holds an enumeration only - used to avoid time consuming string representation of ints */233std::vector<std::string> myLinkNames;234std::vector<std::string> myDetectorNames;235std::vector<std::string> myConditionNames;236237/// @brief The index of the first phase that fits into the window238int myFirstPhase2Show;239int myFirstDet2Show;240int myFirstCond2Show;241242/// @brief The offset to draw the first phase (left offset)243SUMOTime myFirstPhaseOffset;244SUMOTime myFirstDetOffset;245SUMOTime myFirstCondOffset;246247/// @brief The time the diagram begins at248SUMOTime myFirstTime2Show;249250/// @brief The first time a phase was added at251SUMOTime myBeginTime;252253/// @brief The last time a phase was added at254SUMOTime myLastTime;255256/// @brief The connector for retrieval of further phases257GLObjectValuePassConnector<std::pair<SUMOTime, MSPhaseDefinition> >* myConnector;258259/// @brief Information whether the tracking mode is on260bool myAmInTrackingMode;261262/// @brief The tool bar drag (tracking mode)263FXToolBarShell* myToolBarDrag;264265/// @brief The tool bar (tracking mode)266FXToolBar* myToolBar;267268/// @brief The offset changer (tracking mode)269FXRealSpinner* myBeginOffset;270271/// @brief The time mode272MFXComboBoxIcon* myTimeMode;273274/// @brief Whether green durations are printed275MFXComboBoxIcon* myGreenMode;276277/// @brief Whether phase names shall be printed instead of indices278FXCheckButton* myIndexMode;279280/// @brief Whether detector states are drawn281FXCheckButton* myDetectorMode;282283/// @brief Whether detector states are drawn284FXCheckButton* myConditionMode;285286/// @brief y-Position of previously opened window287static int myLastY;288289private:290291void initToolBar();292293void saveSettings();294void loadSettings();295296/// @brief compute required windowHeight297int computeHeight();298299/// @brief draw row title300void drawNames(const std::vector<std::string>& names, double fontHeight, double fontWidth, double divHeight, double divWidth, double& h, int extraLines);301302/// @brief draw detector and condition states303void drawAdditionalStates(GUITLLogicPhasesTrackerPanel& caller,304const AdditionalStatesVector& states, const DurationsVector& durations,305SUMOTime firstOffset, int first2Show, double hStart,306double panelWidth, double leftOffset, double barWidth, double stateHeight, double h20, double& h);307308/// @brief find time in cycle based on myTimeInCycle309SUMOTime findTimeInCycle(SUMOTime t);310311protected:312/// protected constructor for FOX313GUITLLogicPhasesTrackerWindow() { }314315316};317318319