Path: blob/main/src/utils/gui/div/GUIParameterTableWindow.h
169684 views
/****************************************************************************/1// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo2// Copyright (C) 2002-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 GUIParameterTableWindow.h14/// @author Daniel Krajzewicz15/// @author Michael Behrisch16/// @author Jakob Erdmann17/// @date Sept 200218///19// The window that holds the table of an object's parameter20/****************************************************************************/21#pragma once22#include <config.h>2324#include <vector>25#include <string>26#include <algorithm>27#include <functional>28#include <utils/foxtools/fxheader.h>29#include <utils/common/ValueSource.h>30#include <utils/common/SUMOTime.h>31#include <utils/gui/div/GUIPersistentWindowPos.h>32#include "GUIParameterTableItem.h"333435// ===========================================================================36// class declarations37// ===========================================================================38class GUIGlObject;39class GUIMainWindow;40class GUIParameterTableItemInterface;41class Parameterised;424344// ===========================================================================45// class definitions46// ===========================================================================47/**48* @class GUIParameterTableWindow49* @brief A window containing a gl-object's parameter50*51* This class realises a view on some parameter of a gl-object. The gl-object52* itself is responsible for filling this table.53*54* After allocating such a table, the object should fill the rows by calling55* one of the mkItem-methods for each. The building is closed using closeBuilding56* what forces the table to be displayed.57*58* Each row is represented using an instance of GUIParameterTableItemInterface.59*/60class GUIParameterTableWindow : public FXMainWindow, public GUIPersistentWindowPos {61FXDECLARE(GUIParameterTableWindow)62public:63/** @brief Constructor64*65* @param[in] app The application this window belongs to66* @param[in] o The gl-object this table describes67*/68GUIParameterTableWindow(GUIMainWindow& app, GUIGlObject& o, const std::string& title = "");697071/// @brief Destructor72~GUIParameterTableWindow();737475/** @brief Closes the building of the table76*77* Adds the table to the list of child windows of the applications also78* telling the application that the window should be updated in each79* simulation step. Shows the table.80*81* @see GUIMainWindow::addChild82*/83void closeBuilding(const Parameterised* p = 0);848586/// @brief ensure that the font covers the given text87void checkFont(const std::string& text);8889/** @brief Lets this window know the object shown is being deleted90* @param[in] o The deleted (shown) object91*/92void removeObject(GUIGlObject* const o);93949596/// @name Row adding functions97/// @{9899/** @brief Adds a row which obtains its value from a ValueSource100*101* @param[in] name The name of the row entry102* @param[in] dynamic Information whether the entry is dynamic103* @param[in] src The value source to use104*/105template<class T>106void mkItem(const char* name, bool dynamic, ValueSource<T>* src) {107myTable->insertRows((int)myItems.size() + 1);108GUIParameterTableItemInterface* i = new GUIParameterTableItem<T>(myTable, myCurrentPos++, name, dynamic, src);109myItems.push_back(i);110}111112/** @brief Adds a row which shows a string-value113*114* @param[in] name The name of the row entry115* @param[in] dynamic Information whether the entry is dynamic116* @param[in] value The value to show117* @todo the dynamic-parameter is obsolete(?)118*/119void mkItem(const char* name, bool dynamic, std::string value);120121122/** @brief Adds a row which shows a unsigned-value123*124* @param[in] name The name of the row entry125* @param[in] dynamic Information whether the entry is dynamic126* @param[in] value The value to show127* @todo the dynamic-parameter is obsolete128*/129void mkItem(const char* name, bool dynamic, unsigned value);130131132/** @brief Adds a row which shows a integer-value133*134* @param[in] name The name of the row entry135* @param[in] dynamic Information whether the entry is dynamic136* @param[in] value The value to show137* @todo the dynamic-parameter is obsolete138*/139void mkItem(const char* name, bool dynamic, int value);140141142/** @brief Adds a row which shows a 64 bit integer-value143*144* @param[in] name The name of the row entry145* @param[in] dynamic Information whether the entry is dynamic146* @param[in] value The value to show147* @todo the dynamic-parameter is obsolete148*/149void mkItem(const char* name, bool dynamic, long long int value);150151152/** @brief Adds a row which shows a double-value153*154* @param[in] name The name of the row entry155* @param[in] dynamic Information whether the entry is dynamic156* @param[in] value The value to show157* @todo the dynamic-parameter is obsolete158*/159void mkItem(const char* name, bool dynamic, double value);160161162/// @}163164165166/// @name FOX-callbacks167/// @{168169/** @brief Updates the table due to a simulation step */170long onSimStep(FXObject*, FXSelector, void*);171172/** @brief Does nothing173* @todo Recheck whether this is needed (to override FXTable-behaviour?)174*/175long onTableSelected(FXObject*, FXSelector, void*);176177/** @brief Does nothing178* @todo Recheck whether this is needed (to override FXTable-behaviour?)179*/180long onTableDeselected(FXObject*, FXSelector, void*);181182183/** @brief Shows a popup184*185* Callback for right-mouse-button pressing event. Obtains the selected row186* and determines whether it is dynamic. If so, a popup-menu which allows187* to open a tracker for this value is built and shown.188*189* @see GUIParameterTableItemInterface190* @see GUIParam_PopupMenuInterface191*/192long onRightButtonPress(FXObject*, FXSelector, void*);193194/// @brief directly opens tracker when clicking on last column195long onLeftBtnPress(FXObject*, FXSelector, void*);196/// @}197198/** @brief Updates all instances199*/200static void updateAll() {201FXMutexLock locker(myGlobalContainerLock);202for (GUIParameterTableWindow* const window : myContainer) {203window->updateTable();204}205}206207protected:208/** @brief Updates the table209*210* Goes through all entries and updates them using GUIParameterTableItemInterface::update.211*212* @see GUIParameterTableItemInterface::update213*/214void updateTable();215216/// @brief The mutex used to avoid concurrent updates of the instance container217static FXMutex myGlobalContainerLock;218219/// @brief The container of items that shall be updated220static std::vector<GUIParameterTableWindow*> myContainer;221222private:223/// @brief The object to get the information from224GUIGlObject* myObject;225226/// @brief The table to display the information in227FXTable* myTable;228229/// @brief The main application window230GUIMainWindow* myApplication;231232/// @brief The list of table rows233std::vector<GUIParameterTableItemInterface*> myItems;234235/// @brief y-position for opening new tracker window236int myTrackerY;237238/// @brief The index of the next row to add - used while building239unsigned myCurrentPos;240241/// @brief A lock assuring save updates in case of object deletion242mutable FXMutex myLock;243244/// @brief returns the number of parameters if obj is Parameterised and 0 otherwise245static int numParams(const GUIGlObject* obj);246247protected:248FOX_CONSTRUCTOR(GUIParameterTableWindow)249250};251252253