SUMO - Simulation of Urban MObility
GNECalibratorDialog.cpp
Go to the documentation of this file.
1 /****************************************************************************/
8 /****************************************************************************/
9 // SUMO, Simulation of Urban MObility; see http://sumo-sim.org/
10 // Copyright (C) 2001-2013 DLR (http://www.dlr.de/) and contributors
11 /****************************************************************************/
12 //
13 // This file is part of SUMO.
14 // SUMO is free software; you can redistribute it and/or modify
15 // it under the terms of the GNU General Public License as published by
16 // the Free Software Foundation; either version 3 of the License, or
17 // (at your option) any later version.
18 //
19 /****************************************************************************/
20 
21 // ===========================================================================
22 // included modules
23 // ===========================================================================
24 #ifdef _MSC_VER
25 #include <windows_config.h>
26 #else
27 #include <config.h>
28 #endif
29 
30 #include <iostream>
31 #include <utils/common/TplCheck.h>
34 
35 #include "GNECalibratorDialog.h"
36 
37 #ifdef CHECK_MEMORY_LEAKS
38 #include <foreign/nvwa/debug_new.h>
39 #endif
40 
41 // ===========================================================================
42 // FOX callback mapping
43 // ===========================================================================
44 
45 FXDEFMAP(GNECalibratorDialog) GNECalibratorDialogMap[] = {
51 };
52 
53 // Object implementation
54 FXIMPLEMENT(GNECalibratorDialog, FXDialogBox, GNECalibratorDialogMap, ARRAYNUMBER(GNECalibratorDialogMap))
55 
56 // ===========================================================================
57 // member method definitions
58 // ===========================================================================
59 
61  GNEAdditionalDialog(calibratorParent, 1024, 360),
62  myCalibratorParent(calibratorParent) {
63 
64  // create List with the data
65  myDataList = new FXTable(myContentFrame, this, MID_GNE_CALIBRATOR_REMOVEROW, LAYOUT_FILL_X | LAYOUT_FILL_Y);
66  myDataList->setEditable(false);
67 
68  // create Horizontal frame for row elements
69  myRowFrame = new FXHorizontalFrame(myContentFrame, LAYOUT_FILL_X);
70 
71  // create Text field for id
72  myTextFieldId = new FXTextField(myRowFrame, 10, this, MID_GNE_CALIBRATOR_CHANGEVALUE, FRAME_THICK | LAYOUT_FILL_X);
73 
74  // create Text field for begin
75  myTextFieldBegin = new FXTextField(myRowFrame, 10, this, MID_GNE_CALIBRATOR_CHANGEVALUE, TEXTFIELD_INTEGER | FRAME_THICK | LAYOUT_FILL_X);
76 
77  // create Text field for end
78  myTextFieldEnd = new FXTextField(myRowFrame, 10, this, MID_GNE_CALIBRATOR_CHANGEVALUE, TEXTFIELD_INTEGER | FRAME_THICK | LAYOUT_FILL_X);
79 
80  // create Text field for type
81  myTextFieldType = new FXTextField(myRowFrame, 10, this, MID_GNE_CALIBRATOR_CHANGEVALUE, FRAME_THICK | LAYOUT_FILL_X);
82 
83  // create Text field for route
84  myTextFieldRoute = new FXTextField(myRowFrame, 10, this, MID_GNE_CALIBRATOR_CHANGEVALUE, FRAME_THICK | LAYOUT_FILL_X);
85 
86  // create Text field for color
87  myTextFieldColor = new FXTextField(myRowFrame, 10, this, MID_GNE_CALIBRATOR_CHANGEVALUE, FRAME_THICK | LAYOUT_FILL_X);
88 
89  // create Text field for depart lane
90  myTextFieldDepartLane = new FXTextField(myRowFrame, 10, this, MID_GNE_CALIBRATOR_CHANGEVALUE, FRAME_THICK | LAYOUT_FILL_X);
91 
92  // create Text field for depart pos
93  myTextFieldDepartPos = new FXTextField(myRowFrame, 10, this, MID_GNE_CALIBRATOR_CHANGEVALUE, FRAME_THICK | LAYOUT_FILL_X);
94 
95  // create Text field for depart speed
96  myTextFieldDepartSpeed = new FXTextField(myRowFrame, 10, this, MID_GNE_CALIBRATOR_CHANGEVALUE, FRAME_THICK | LAYOUT_FILL_X);
97 
98  // create Text field for arrival lane
99  myTextFieldArrivalLane = new FXTextField(myRowFrame, 10, this, MID_GNE_CALIBRATOR_CHANGEVALUE, FRAME_THICK | LAYOUT_FILL_X);
100 
101  // create Text field for arrival pos
102  myTextFieldArrivalPos = new FXTextField(myRowFrame, 10, this, MID_GNE_CALIBRATOR_CHANGEVALUE, FRAME_THICK | LAYOUT_FILL_X);
103 
104  // create Text field for arrival speed
105  myTextFieldArrivalSpeed = new FXTextField(myRowFrame, 10, this, MID_GNE_CALIBRATOR_CHANGEVALUE, FRAME_THICK | LAYOUT_FILL_X);
106 
107  // create Text field for line
108  myTextFieldLine = new FXTextField(myRowFrame, 10, this, MID_GNE_CALIBRATOR_CHANGEVALUE, FRAME_THICK | LAYOUT_FILL_X);
109 
110  // create Text field for person number
111  myTextFieldPersonNumber = new FXTextField(myRowFrame, 10, this, MID_GNE_CALIBRATOR_CHANGEVALUE, TEXTFIELD_INTEGER | FRAME_THICK | LAYOUT_FILL_X);
112 
113  // create Text field for container number
114  myTextFieldContainerNumber = new FXTextField(myRowFrame, 10, this, MID_GNE_CALIBRATOR_CHANGEVALUE, TEXTFIELD_INTEGER | FRAME_THICK | LAYOUT_FILL_X);
115 
116  // create Text field for vehsPerHour
117  myTextFieldVehsPerHour = new FXTextField(myRowFrame, 10, this, MID_GNE_CALIBRATOR_CHANGEVALUE, TEXTFIELD_REAL | FRAME_THICK | LAYOUT_FILL_X);
118 
119  // create Text field for period
120  myTextFieldPeriod = new FXTextField(myRowFrame, 10, this, MID_GNE_CALIBRATOR_CHANGEVALUE, TEXTFIELD_REAL | FRAME_THICK | LAYOUT_FILL_X);
121 
122  // create Text field for probability
123  myTextFieldProbability = new FXTextField(myRowFrame, 10, this, MID_GNE_CALIBRATOR_CHANGEVALUE, TEXTFIELD_REAL | FRAME_THICK | LAYOUT_FILL_X);
124 
125  // create Text field for number
126  myTextFieldNumber = new FXTextField(myRowFrame, 10, this, MID_GNE_CALIBRATOR_CHANGEVALUE, TEXTFIELD_INTEGER | FRAME_THICK | LAYOUT_FILL_X);
127 
128  // create Button for insert row
129  myAddRow = new FXButton(myRowFrame, "Add", 0, this, MID_GNE_CALIBRATOR_ADDROW, FRAME_THICK | LAYOUT_FILL_X);
130 
131  // Get values of variable speed signal
132  myFlowValues = myCalibratorParent->getFlowValues();
133 
134  // Fill table
135  updateTable();
136 
137  // Execute additional dialog (To make it modal)
138  execute();
139 }
140 
141 
143 }
144 
145 
146 long
147 GNECalibratorDialog::onCmdAddRow(FXObject*, FXSelector, void*) {
148  // Declare new calibrator
149  GNECalibrator::CalibratorFlow calibratorFlow;
150  // set ID
151  std::string id = myTextFieldId->getText().text();
152 
153  // set Start
154  if (myTextFieldBegin->getText().empty()) {
155  return 0;
156  } else {
157  // @todo SUMOTIME
158  calibratorFlow.begin = TplConvert::_str2int(myTextFieldBegin->getText().text());
159  }
160 
161  // set End
162  if (myTextFieldEnd->getText().empty()) {
163  return 0;
164  } else {
165  // @todo SUMOTIME
166  calibratorFlow.end = TplConvert::_str2int(myTextFieldEnd->getText().text());
167  }
168 
169  // set Type
170  if (myTextFieldType->getText().empty()) {
171  return 0;
172  } else {
173  calibratorFlow.type = myTextFieldType->getText().text();
174  }
175 
176  // set Route
177  if (myTextFieldType->getText().empty()) {
178  return 0;
179  } else {
180  calibratorFlow.route = myTextFieldRoute->getText().text();
181  }
182 
183  // Set color
184  calibratorFlow.color = myTextFieldColor->getText().text();
185 
186  // Set depart lane
187  calibratorFlow.departLane = myTextFieldDepartLane->getText().text();
188 
189  // Set depart pos
190  calibratorFlow.departPos = myTextFieldDepartPos->getText().text();
191 
192  // Set depart speed
193  calibratorFlow.departSpeed = myTextFieldDepartSpeed->getText().text();
194 
195  // Set arrival lane
196  calibratorFlow.arrivalLane = myTextFieldArrivalLane->getText().text();
197 
198  // Set arrival pos
199  calibratorFlow.arrivalPos = myTextFieldArrivalPos->getText().text();
200 
201  // Set arrival speed
202  calibratorFlow.arrivalSpeed = myTextFieldArrivalSpeed->getText().text();
203 
204  // Set Line
205  calibratorFlow.line = myTextFieldLine->getText().text();
206 
207  // set PersionNumber
208  calibratorFlow.personNumber = TplConvert::_str2int(myTextFieldPersonNumber->getText().text());
209 
210  // set Container Number
211  calibratorFlow.containerNumber = TplConvert::_str2int(myTextFieldContainerNumber->getText().text());
212 
213  // Set vehsPerHour
214  calibratorFlow.vehsPerHour = TplConvert::_str2SUMOReal(myTextFieldVehsPerHour->getText().text());
215 
216  // set Period
217  calibratorFlow.period = TplConvert::_str2SUMOReal(myTextFieldPeriod->getText().text());
218 
219  // set Probability
220  calibratorFlow.probability = TplCheck::_str2SUMOReal(myTextFieldProbability->getText().text());
221 
222  // set Number
223  calibratorFlow.number = TplConvert::_str2int(myTextFieldNumber->getText().text());
224 
225  // Set new time and their speed if don't exist already a flow with the same ID
226  if (myFlowValues.find(id) == myFlowValues.end()) {
227  myFlowValues[id] = calibratorFlow;
228  } else {
229  return 0;
230  }
231 
232  // Update table
233  updateTable();
234  return 1;
235 }
236 
237 
238 long
239 GNECalibratorDialog::onCmdRemoveRow(FXObject*, FXSelector, void*) {
240  // Iterate over rows to find the row to erase
241  for (int i = 0; i < myDataList->getNumRows(); i++) {
242  if (myDataList->getItem(i, 19)->isSelected()) {
243  // Remove element of table and map
244  myFlowValues.erase(myDataList->getItem(i, 0)->getText().text());
245  myDataList->removeRows(i);
246  // update table
247  updateTable();
248  return 1;
249  }
250  }
251  return 0;
252 }
253 
254 
255 long
256 GNECalibratorDialog::onCmdAccept(FXObject*, FXSelector, void*) {
257  // Get values of variable speed signal
259  // Stop Modal
260  getApp()->stopModal(this, TRUE);
261  return 1;
262 }
263 
264 
265 long
266 GNECalibratorDialog::onCmdCancel(FXObject*, FXSelector, void*) {
267  // Stop Modal
268  getApp()->stopModal(this, TRUE);
269  return 1;
270 }
271 
272 
273 long
274 GNECalibratorDialog::onCmdReset(FXObject*, FXSelector, void*) {
275  // Get values of variable speed signal
277  // Update Table
278  updateTable();
279  return 1;
280 }
281 
282 
283 void
285  // clear table
286  myDataList->clearItems();
287  // set number of rows
288  myDataList->setTableSize(int(myFlowValues.size()), 20);
289  // Configure list
290  myDataList->setVisibleColumns(20);
291  myDataList->setColumnWidth(0, getWidth() * 0.05);
292  myDataList->setColumnWidth(1, getWidth() * 0.05);
293  myDataList->setColumnWidth(2, getWidth() * 0.05);
294  myDataList->setColumnWidth(3, getWidth() * 0.05);
295  myDataList->setColumnWidth(4, getWidth() * 0.05);
296  myDataList->setColumnWidth(5, getWidth() * 0.05);
297  myDataList->setColumnWidth(6, getWidth() * 0.05);
298  myDataList->setColumnWidth(7, getWidth() * 0.05);
299  myDataList->setColumnWidth(8, getWidth() * 0.05);
300  myDataList->setColumnWidth(9, getWidth() * 0.05);
301  myDataList->setColumnWidth(10, getWidth() * 0.05);
302  myDataList->setColumnWidth(11, getWidth() * 0.05);
303  myDataList->setColumnWidth(12, getWidth() * 0.05);
304  myDataList->setColumnWidth(13, getWidth() * 0.05);
305  myDataList->setColumnWidth(14, getWidth() * 0.05);
306  myDataList->setColumnWidth(15, getWidth() * 0.05);
307  myDataList->setColumnWidth(16, getWidth() * 0.05);
308  myDataList->setColumnWidth(17, getWidth() * 0.05);
309  myDataList->setColumnWidth(18, getWidth() * 0.05);
310  myDataList->setColumnWidth(19, (getWidth() * 0.05) - 10);
311  myDataList->setColumnText(0, "Id");
312  myDataList->setColumnText(1, "Begin");
313  myDataList->setColumnText(2, "End");
314  myDataList->setColumnText(3, "Type");
315  myDataList->setColumnText(4, "Route");
316  myDataList->setColumnText(5, "Color");
317  myDataList->setColumnText(6, "Dep.Lane");
318  myDataList->setColumnText(7, "Dep.Pos.");
319  myDataList->setColumnText(8, "Dep.Speed");
320  myDataList->setColumnText(9, "Arr.Lane");
321  myDataList->setColumnText(10, "Arr.Pos.");
322  myDataList->setColumnText(11, "Arr.Speed");
323  myDataList->setColumnText(12, "Line");
324  myDataList->setColumnText(13, "Per.Num.");
325  myDataList->setColumnText(14, "Con.Num");
326  myDataList->setColumnText(15, "VehPerHour");
327  myDataList->setColumnText(16, "Period");
328  myDataList->setColumnText(17, "Prob.");
329  myDataList->setColumnText(18, "Number");
330  myDataList->setColumnText(19, "Del.");
331  myDataList->getRowHeader()->setWidth(0);
332 
333  // Declare index for rows and pointer to FXTableItem
334  int indexRow = 0;
335  FXTableItem* item = 0;
336 
337  // iterate over values
338  for (std::map<std::string, GNECalibrator::CalibratorFlow>::iterator i = myFlowValues.begin(); i != myFlowValues.end(); i++) {
339  // set ID
340  item = new FXTableItem(toString(i->first).c_str());
341  myDataList->setItem(indexRow, 0, item);
342 
343  // set begin
344  item = new FXTableItem(toString(i->second.begin).c_str());
345  myDataList->setItem(indexRow, 1, item);
346 
347  // set end
348  item = new FXTableItem(toString(i->second.end).c_str());
349  myDataList->setItem(indexRow, 2, item);
350 
351  // set type
352  item = new FXTableItem(toString(i->second.type).c_str());
353  myDataList->setItem(indexRow, 3, item);
354 
355  // set route
356  item = new FXTableItem(toString(i->second.route).c_str());
357  myDataList->setItem(indexRow, 4, item);
358 
359  // set color
360  item = new FXTableItem(toString(i->second.color).c_str());
361  myDataList->setItem(indexRow, 5, item);
362 
363  // set depart lane
364  item = new FXTableItem(toString(i->second.departLane).c_str());
365  myDataList->setItem(indexRow, 6, item);
366 
367  // set depart pos
368  item = new FXTableItem(toString(i->second.departPos).c_str());
369  myDataList->setItem(indexRow, 7, item);
370 
371  // set depart speed
372  item = new FXTableItem(toString(i->second.departSpeed).c_str());
373  myDataList->setItem(indexRow, 8, item);
374 
375  // set arrival lane
376  item = new FXTableItem(toString(i->second.arrivalLane).c_str());
377  myDataList->setItem(indexRow, 9, item);
378 
379  // set arrival pos
380  item = new FXTableItem(toString(i->second.arrivalPos).c_str());
381  myDataList->setItem(indexRow, 10, item);
382 
383  // set arrival speed
384  item = new FXTableItem(toString(i->second.arrivalSpeed).c_str());
385  myDataList->setItem(indexRow, 11, item);
386 
387  // set line
388  item = new FXTableItem(toString(i->second.line).c_str());
389  myDataList->setItem(indexRow, 12, item);
390 
391  // set person number
392  item = new FXTableItem(toString(i->second.personNumber).c_str());
393  myDataList->setItem(indexRow, 13, item);
394 
395  // set container number
396  item = new FXTableItem(toString(i->second.containerNumber).c_str());
397  myDataList->setItem(indexRow, 14, item);
398 
399  // set vehsPerHour
400  item = new FXTableItem(toString(i->second.vehsPerHour).c_str());
401  myDataList->setItem(indexRow, 15, item);
402 
403  // set period
404  item = new FXTableItem(toString(i->second.period).c_str());
405  myDataList->setItem(indexRow, 16, item);
406 
407  // set probability
408  item = new FXTableItem(toString(i->second.probability).c_str());
409  myDataList->setItem(indexRow, 17, item);
410 
411  // set number
412  item = new FXTableItem(toString(i->second.number).c_str());
413  myDataList->setItem(indexRow, 18, item);
414 
415  // set remove
416  item = new FXTableItem("", GUIIconSubSys::getIcon(ICON_REMOVE));
417  item->setJustify(FXTableItem::CENTER_X | FXTableItem::CENTER_Y);
418  myDataList->setItem(indexRow, 19, item);
419 
420  // Update index
421  indexRow++;
422  }
423 }
424 
425 /****************************************************************************/
FXTextField * myTextFieldContainerNumber
textField for insert a flow&#39;s ContainerNumber
static SUMOReal _str2SUMOReal(const std::string &sData)
converts a string into the SUMOReal value described by it by calling the char-type converter ...
Definition: TplConvert.h:341
FXTextField * myTextFieldRoute
textField for insert a flow&#39;s Route
FXTable * myDataList
Table with the data.
FXTextField * myTextFieldProbability
textField for insert a flow&#39;s probability
std::map< std::string, GNECalibrator::CalibratorFlow > myFlowValues
Map with the temporal FlowValues.
FXTextField * myTextFieldArrivalLane
textField for insert a flow&#39;s ArrivalLane
Dialog to edit sequences, parameters, etc.. of Additionals.
void updateTable()
update data table
FXTextField * myTextFieldDepartLane
textField for insert a flow&#39;s DepartLane
FXTextField * myTextFieldLine
textField for insert a flow&#39;s Line
GNECalibrator * myCalibratorParent
pointer to calibrator parent
void setFlowValues(std::map< std::string, CalibratorFlow > calibratorFlowValues)
set Calbratorflow values
std::map< std::string, CalibratorFlow > getFlowValues() const
get Calbratorflow values
long onCmdReset(FXObject *, FXSelector, void *)
event after press reset button
FXTextField * myTextFieldId
textField for insert a flow&#39;s Id
long onCmdRemoveRow(FXObject *, FXSelector, void *)
event called after press remove row
long onCmdAddRow(FXObject *, FXSelector, void *)
FXTextField * myTextFieldType
textField for insert a flow&#39;s Type
static int _str2int(const std::string &sData)
converts a string into the integer value described by it by calling the char-type converter...
Definition: TplConvert.h:160
FXTextField * myTextFieldDepartPos
textField for insert a flow&#39;s DepartPos
FXTextField * myTextFieldVehsPerHour
textField for insert a flow&#39;s vehsPerHour
std::string toString(const T &t, std::streamsize accuracy=OUTPUT_ACCURACY)
Definition: ToString.h:55
FXTextField * myTextFieldPersonNumber
textField for insert a flow&#39;s PersonNumber
Dialog for edit calibrators.
FXTextField * myTextFieldArrivalPos
textField for insert a flow&#39;s ArrivalPos
FXTextField * myTextFieldBegin
textField for insert a flow&#39;s begin
FXTextField * myTextFieldPeriod
textField for insert a flow&#39;s period
FXTextField * myTextFieldEnd
textField for insert a flow&#39;s end
FXTextField * myTextFieldDepartSpeed
textField for insert a flow&#39;s DepartSpeed
Calibrator dialog.
Definition: GUIAppEnum.h:446
FXDEFMAP(GNECalibratorDialog) GNECalibratorDialogMap[]
static bool _str2SUMOReal(const std::string &data)
check if a String can be parsed into a SUMOReal check overflows
Definition: TplCheck.h:67
FXTextField * myTextFieldColor
textField for insert a flow&#39;s color
static FXIcon * getIcon(GUIIcon which)
returns a icon previously defined in the enum GUIIcon
long onCmdCancel(FXObject *, FXSelector, void *)
event after press cancel button
FXTextField * myTextFieldNumber
textField for insert a flow&#39;s number
long onCmdAccept(FXObject *, FXSelector, void *)
event after press accept button
FXTextField * myTextFieldArrivalSpeed
textField for insert a flow&#39;s ArrivalSpeed