1 /****************************************************************************/ 2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo 3 // Copyright (C) 2002-2019 German Aerospace Center (DLR) and others. 4 // This program and the accompanying materials 5 // are made available under the terms of the Eclipse Public License v2.0 6 // which accompanies this distribution, and is available at 7 // http://www.eclipse.org/legal/epl-v20.html 8 // SPDX-License-Identifier: EPL-2.0 9 /****************************************************************************/ 10 /// @file GUIParameterTableWindow.h 11 /// @author Daniel Krajzewicz 12 /// @author Michael Behrisch 13 /// @author Jakob Erdmann 14 /// @date Sept 2002 15 /// @version $Id$ 16 /// 17 // The window that holds the table of an object's parameter 18 /****************************************************************************/ 19 #ifndef GUIParameterTableWindow_h 20 #define GUIParameterTableWindow_h 21 22 23 // =========================================================================== 24 // included modules 25 // =========================================================================== 26 #include <config.h> 27 28 #include <vector> 29 #include <string> 30 #include <algorithm> 31 #include <functional> 32 #include <fx.h> 33 #include <utils/common/ValueSource.h> 34 #include <utils/common/SUMOTime.h> 35 #include "GUIParameterTableItem.h" 36 37 38 // =========================================================================== 39 // class declarations 40 // =========================================================================== 41 class GUIGlObject; 42 class GUIMainWindow; 43 class GUIParameterTableItemInterface; 44 class Parameterised; 45 46 47 // =========================================================================== 48 // class definitions 49 // =========================================================================== 50 /** 51 * @class GUIParameterTableWindow 52 * @brief A window containing a gl-object's parameter 53 * 54 * This class realises a view on some parameter of a gl-object. The gl-object 55 * itself is responsible for filling this table. 56 * 57 * After allocating such a table, the object should fill the rows by calling 58 * one of the mkItem-methods for each. The building is closed using closeBuilding 59 * what forces the table to be displayed. 60 * 61 * Each row is represented using an instance of GUIParameterTableItemInterface. 62 */ 63 class GUIParameterTableWindow : public FXMainWindow { 64 FXDECLARE(GUIParameterTableWindow) 65 public: 66 /** @brief Constructor 67 * 68 * @param[in] app The application this window belongs to 69 * @param[in] o The gl-object this table describes 70 * @param[in] noRows Number of rows to allocate 71 */ 72 GUIParameterTableWindow(GUIMainWindow& app, 73 GUIGlObject& o, int noRows); 74 75 76 /// @brief Destructor 77 ~GUIParameterTableWindow(); 78 79 80 /** @brief Closes the building of the table 81 * 82 * Adds the table to the list of child windows of the applications also 83 * telling the application that the window should be updated in each 84 * simulation step. Shows the table. 85 * 86 * @see GUIMainWindow::addChild 87 */ 88 void closeBuilding(const Parameterised* p = 0); 89 90 91 92 /** @brief Lets this window know the object shown is being deleted 93 * @param[in] o The deleted (shown) object 94 */ 95 void removeObject(GUIGlObject* const o); 96 97 98 99 /// @name Row adding functions 100 /// @{ 101 102 /** @brief Adds a row which obtains its value from a ValueSource 103 * 104 * @param[in] name The name of the row entry 105 * @param[in] dynamic Information whether the entry is dynamic 106 * @param[in] src The value source to use 107 */ 108 template<class T> mkItem(const char * name,bool dynamic,ValueSource<T> * src)109 void mkItem(const char* name, bool dynamic, ValueSource<T>* src) { 110 GUIParameterTableItemInterface* i = new GUIParameterTableItem<T>(myTable, myCurrentPos++, name, dynamic, src); 111 myItems.push_back(i); 112 } 113 114 /** @brief Adds a row which shows a string-value 115 * 116 * @param[in] name The name of the row entry 117 * @param[in] dynamic Information whether the entry is dynamic 118 * @param[in] value The value to show 119 * @todo the dynamic-parameter is obsolete(?) 120 */ 121 void mkItem(const char* name, bool dynamic, std::string value); 122 123 124 /** @brief Adds a row which shows a unsigned-value 125 * 126 * @param[in] name The name of the row entry 127 * @param[in] dynamic Information whether the entry is dynamic 128 * @param[in] value The value to show 129 * @todo the dynamic-parameter is obsolete 130 */ 131 void mkItem(const char* name, bool dynamic, unsigned value); 132 133 134 /** @brief Adds a row which shows a integer-value 135 * 136 * @param[in] name The name of the row entry 137 * @param[in] dynamic Information whether the entry is dynamic 138 * @param[in] value The value to show 139 * @todo the dynamic-parameter is obsolete 140 */ 141 void mkItem(const char* name, bool dynamic, int value); 142 143 144 /** @brief Adds a row which shows a 64 bit integer-value 145 * 146 * @param[in] name The name of the row entry 147 * @param[in] dynamic Information whether the entry is dynamic 148 * @param[in] value The value to show 149 * @todo the dynamic-parameter is obsolete 150 */ 151 void mkItem(const char* name, bool dynamic, long long int value); 152 153 154 /** @brief Adds a row which shows a double-value 155 * 156 * @param[in] name The name of the row entry 157 * @param[in] dynamic Information whether the entry is dynamic 158 * @param[in] value The value to show 159 * @todo the dynamic-parameter is obsolete 160 */ 161 void mkItem(const char* name, bool dynamic, double value); 162 163 164 /// @} 165 166 167 168 /// @name FOX-callbacks 169 /// @{ 170 171 /** @brief Updates the table due to a simulation step */ 172 long onSimStep(FXObject*, FXSelector, void*); 173 174 /** @brief Does nothing 175 * @todo Recheck whether this is needed (to override FXTable-behaviour?) 176 */ 177 long onTableSelected(FXObject*, FXSelector, void*); 178 179 /** @brief Does nothing 180 * @todo Recheck whether this is needed (to override FXTable-behaviour?) 181 */ 182 long onTableDeselected(FXObject*, FXSelector, void*); 183 184 /** @brief Shows a popup 185 * 186 * Callback for right-mouse-button pressing event. Obtains the selected row 187 * and determines whether it is dynamic. If so, a popup-menu which allows 188 * to open a tracker for this value is built and shown. 189 * 190 * @see GUIParameterTableItemInterface 191 * @see GUIParam_PopupMenuInterface 192 */ 193 long onRightButtonPress(FXObject*, FXSelector, void*); 194 /// @} 195 196 /** @brief Updates all instances 197 */ updateAll()198 static void updateAll() { 199 FXMutexLock locker(myGlobalContainerLock); 200 std::for_each(myContainer.begin(), myContainer.end(), std::mem_fun(&GUIParameterTableWindow::updateTable)); 201 } 202 203 protected: 204 /** @brief Updates the table 205 * 206 * Goes through all entries and updates them using GUIParameterTableItemInterface::update. 207 * 208 * @see GUIParameterTableItemInterface::update 209 */ 210 void updateTable(); 211 212 /// @brief The mutex used to avoid concurrent updates of the instance container 213 static FXMutex myGlobalContainerLock; 214 215 /// @brief The container of items that shall be updated 216 static std::vector<GUIParameterTableWindow*> myContainer; 217 218 private: 219 /// @brief The object to get the information from 220 GUIGlObject* myObject; 221 222 /// @brief The table to display the information in 223 FXTable* myTable; 224 225 /// @brief The main application window 226 GUIMainWindow* myApplication; 227 228 /// @brief The list of table rows 229 std::vector<GUIParameterTableItemInterface*> myItems; 230 231 /// @brief The index of the next row to add - used while building 232 unsigned myCurrentPos; 233 234 /// @brief A lock assuring save updates in case of object deletion 235 mutable FXMutex myLock; 236 237 /// @brief returns the number of parameters if obj is Parameterised and 0 otherwise 238 static int numParams(const GUIGlObject* obj); 239 240 protected: 241 /// FOX needs this GUIParameterTableWindow()242 GUIParameterTableWindow() { } 243 244 }; 245 246 247 #endif 248 249 /****************************************************************************/ 250 251