SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GUIParameterTableItem.h
Go to the documentation of this file.
1 /****************************************************************************/
8 // A single line in a parameter window
9 /****************************************************************************/
10 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/
11 // Copyright (C) 2001-2013 DLR (http://www.dlr.de/) and contributors
12 /****************************************************************************/
13 //
14 // This file is part of SUMO.
15 // SUMO is free software: you can redistribute it and/or modify
16 // it under the terms of the GNU General Public License as published by
17 // the Free Software Foundation, either version 3 of the License, or
18 // (at your option) any later version.
19 //
20 /****************************************************************************/
21 #ifndef GUIParameterTableItem_h
22 #define GUIParameterTableItem_h
23 
24 
25 // ===========================================================================
26 // included modules
27 // ===========================================================================
28 #ifdef _MSC_VER
29 #include <windows_config.h>
30 #else
31 #include <config.h>
32 #endif
33 
34 #include <string>
35 #include <fx.h>
37 #include <utils/common/ToString.h>
41 
42 
43 // ===========================================================================
44 // class definitions
45 // ===========================================================================
46 // ---------------------------------------------------------------------------
47 // GUIParameterTableItemInterface
48 // ---------------------------------------------------------------------------
65 public:
68 
69 
72 
77  virtual bool dynamic() const = 0;
78 
79 
82  virtual void update() = 0;
83 
84 
89  virtual ValueSource<SUMOReal>* getSUMORealSourceCopy() const = 0;
90 
91 
96  virtual const std::string& getName() const = 0;
98 
99 };
100 
101 
102 // ---------------------------------------------------------------------------
103 // GUIParameterTableItem
104 // ---------------------------------------------------------------------------
119 template<class T>
121 public:
132  GUIParameterTableItem(FXTable* table, unsigned pos,
133  const std::string& name, bool dynamic,
134  ValueSource<T>* src)
135  : myAmDynamic(dynamic), myName(name), myTablePosition((FXint) pos), mySource(src),
136  myValue(src->getValue()), myTable(table) {
137  init(dynamic, toString<T>(src->getValue()));
138  }
139 
140 
152  GUIParameterTableItem(FXTable* table, unsigned pos,
153  const std::string& name, bool dynamic,
154  T value)
155  : myAmDynamic(dynamic), myName(name), myTablePosition((FXint) pos), mySource(0),
156  myValue(value), myTable(table) {
157  init(dynamic, toString<T>(value));
158  }
159 
160 
172  GUIParameterTableItem(FXTable* table, unsigned pos,
173  const std::string& name, bool dynamic,
174  std::string value)
175  : myAmDynamic(dynamic), myName(name), myTablePosition((FXint) pos), mySource(0),
176  myValue(0), myTable(table) {
177  init(dynamic, value);
178  }
179 
180 
183  delete mySource;
184  }
185 
186 
195  void init(bool dynamic, std::string value) {
196  myTable->setItemText(myTablePosition, 0, myName.c_str());
197  myTable->setItemText(myTablePosition, 1, value.c_str());
198  if (dynamic) {
200  } else {
202  }
203  myTable->setItemJustify(myTablePosition, 2, FXTableItem::CENTER_X | FXTableItem::CENTER_Y);
204  }
205 
206 
207 
212  bool dynamic() const {
213  return myAmDynamic;
214  }
215 
216 
221  const std::string& getName() const {
222  return myName;
223  }
224 
225 
233  void update() {
234  if (!dynamic() || mySource == 0) {
235  return;
236  }
237  T value = mySource->getValue();
238  if (value != myValue) {
239  myValue = value;
240  myTable->setItemText(myTablePosition, 1, toString<T>(myValue).c_str());
241  }
242  }
243 
244 
250  if (mySource == 0) {
251  return 0;
252  }
253  return mySource->copy();
254  }
255 
256 
262  if (mySource == 0) {
263  return 0;
264  }
265  return mySource->makeSUMORealReturningCopy();
266  }
267 
268 
269 private:
272 
274  std::string myName;
275 
278 
281 
284 
287 
288 };
289 
290 
291 #endif
292 
293 /****************************************************************************/
294