SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
GNEVariableSpeedSignalDialog.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>
32 #include <utils/common/TplCheck.h>
34 
36 #include "GNEVariableSpeedSignal.h"
37 
38 #ifdef CHECK_MEMORY_LEAKS
39 #include <foreign/nvwa/debug_new.h>
40 #endif
41 
42 
43 // ===========================================================================
44 // FOX callback mapping
45 // ===========================================================================
46 
47 FXDEFMAP(GNEVariableSpeedSignalDialog) GNERerouterDialogMap[] = {
53 };
54 
55 // Object implementation
56 FXIMPLEMENT(GNEVariableSpeedSignalDialog, FXDialogBox, GNERerouterDialogMap, ARRAYNUMBER(GNERerouterDialogMap))
57 
58 // ===========================================================================
59 // member method definitions
60 // ===========================================================================
61 
63  GNEAdditionalDialog(variableSpeedSignalParent, 240, 240),
64  myVariableSpeedSignalParent(variableSpeedSignalParent) {
65 
66  // create List with the data
67  myDataList = new FXTable(myContentFrame, this, MID_GNE_VARIABLESPEEDSIGNAL_REMOVEROW, LAYOUT_FILL_X | LAYOUT_FILL_Y);
68  myDataList->setEditable(false);
69 
70  // create Horizontal frame for row elements
71  myRowFrame = new FXHorizontalFrame(myContentFrame, LAYOUT_FILL_X);
72 
73  // create Text field for the timeStep
74  myRowStep = new FXTextField(myRowFrame, 10, this, MID_GNE_VARIABLESPEEDSIGNAL_CHANGEVALUE, FRAME_THICK | LAYOUT_FILL_X);
75 
76  // create Text field for the speed
77  myRowSpeed = new FXTextField(myRowFrame, 10, this, MID_GNE_VARIABLESPEEDSIGNAL_CHANGEVALUE, FRAME_THICK | LAYOUT_FILL_X);
78 
79  // create Button for insert row
80  myAddRow = new FXButton(myRowFrame, "Add", 0, this, MID_GNE_VARIABLESPEEDSIGNAL_ADDROW, FRAME_THICK);
81 
82  // Get values of variable speed signal
83  myVSSValues = myVariableSpeedSignalParent->getVariableSpeedSignalSteps();
84 
85  // update table
86  updateTable();
87 
88  // Execute additional dialog (To make it modal)
89  execute();
90 }
91 
93 }
94 
95 
96 long
97 GNEVariableSpeedSignalDialog::onCmdAddRow(FXObject*, FXSelector, void*) {
98  // Declare variables for time and speed
99  SUMOTime time;
100  SUMOReal speed;
101 
102  // Get Time
103  if (TplCheck::_str2SUMOTime(myRowStep->getText().text()) == false) {
104  return 0;
105  } else {
106 // @toDo IMPLEMENT _str2Time TO TIME
107  time = TplConvert::_str2int(myRowStep->getText().text());
108  }
109 
110  // get SPeed
111  if (TplCheck::_str2SUMOReal(myRowSpeed->getText().text()) == false) {
112  return 0;
113  } else {
114  speed = TplConvert::_str2SUMOReal(myRowSpeed->getText().text());
115  }
116 
117  // Set new time and their speed if don't exist already
118  if (myVSSValues.find(time) == myVSSValues.end()) {
119  myVSSValues[time] = speed;
120  } else {
121  return false;
122  }
123 
124  // Update table
125  updateTable();
126  return 1;
127 }
128 
129 
130 long
131 GNEVariableSpeedSignalDialog::onCmdRemoveRow(FXObject*, FXSelector, void*) {
132  // Iterate over rows to find the row to erase
133  for (int i = 0; i < myDataList->getNumRows(); i++) {
134  if (myDataList->getItem(i, 2)->isSelected()) {
135  // Remove element of table and map
136 // @todo IMPLEMENT _2SUMOTIme
137  myVSSValues.erase(TplConvert::_2int(myDataList->getItem(i, 0)->getText().text()));
138  myDataList->removeRows(i);
139  // update table
140  updateTable();
141  return 1;
142  }
143  }
144  return 0;
145 }
146 
147 
148 long
149 GNEVariableSpeedSignalDialog::onCmdAccept(FXObject*, FXSelector, void*) {
150  // Save new data in Variable Speed Signal edited
152  // Stop Modal with positive out
153  getApp()->stopModal(this, TRUE);
154  return 1;
155 }
156 
157 
158 long
159 GNEVariableSpeedSignalDialog::onCmdCancel(FXObject*, FXSelector, void*) {
160  // Stop Modal with negative out
161  getApp()->stopModal(this, FALSE);
162  return 1;
163 }
164 
165 
166 long
167 GNEVariableSpeedSignalDialog::onCmdReset(FXObject*, FXSelector, void*) {
168  // Get old values
170  updateTable();
171  return 1;
172 }
173 
174 
175 void
177  // clear table
178  myDataList->clearItems();
179  // set number of rows
180  myDataList->setTableSize(int(myVSSValues.size()), 3);
181  // Configure list
182  myDataList->setVisibleColumns(3);
183  myDataList->setColumnWidth(0, getWidth() / 3);
184  myDataList->setColumnWidth(1, getWidth() / 3);
185  myDataList->setColumnWidth(2, getWidth() / 3 - 10);
186  myDataList->setColumnText(0, "timeStep");
187  myDataList->setColumnText(1, "speed (km/h)");
188  myDataList->setColumnText(2, "remove");
189  myDataList->getRowHeader()->setWidth(0);
190  // Declare index for rows and pointer to FXTableItem
191  int indexRow = 0;
192  FXTableItem* item = 0;
193  // iterate over values
194  for (std::map<SUMOTime, SUMOReal>::iterator i = myVSSValues.begin(); i != myVSSValues.end(); i++) {
195  // Set time
196  item = new FXTableItem(toString(i->first).c_str());
197  myDataList->setItem(indexRow, 0, item);
198  // Set speed
199  item = new FXTableItem(toString(i->second).c_str());
200  myDataList->setItem(indexRow, 1, item);
201  // set remove
202  item = new FXTableItem("", GUIIconSubSys::getIcon(ICON_REMOVE));
203  item->setJustify(FXTableItem::CENTER_X | FXTableItem::CENTER_Y);
204  myDataList->setItem(indexRow, 2, item);
205  // Update index
206  indexRow++;
207  }
208 }
209 
210 /****************************************************************************/
std::map< SUMOTime, SUMOReal > myVSSValues
Map with the temporal VSSValues.
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
long onCmdReset(FXObject *, FXSelector, void *)
event called after press cancel button
long long int SUMOTime
Definition: SUMOTime.h:43
long onCmdCancel(FXObject *, FXSelector, void *)
event called after press cancel button
long onCmdAccept(FXObject *, FXSelector, void *)
event called after press accept button
static bool _str2SUMOTime(const std::string &data)
check if a String can be parsed into a SUMOTime check overflows
Definition: TplCheck.h:104
Dialog to edit sequences, parameters, etc.. of Additionals.
void setVariableSpeedSignalSteps(const std::map< SUMOTime, SUMOReal > &vssValues)
set values of variable speed signal
FXTextField * myRowSpeed
Text field with speed.
Variable Speed Signal dialog.
Definition: GUIAppEnum.h:438
long onCmdRemoveRow(FXObject *, FXSelector, void *)
event called after press remove row
FXTable * myDataList
Table with the data.
FXDEFMAP(GNEVariableSpeedSignalDialog) GNERerouterDialogMap[]
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
std::map< SUMOTime, SUMOReal > getVariableSpeedSignalSteps() const
get values of variable speed signal
long onCmdAddRow(FXObject *, FXSelector, void *)
std::string toString(const T &t, std::streamsize accuracy=OUTPUT_ACCURACY)
Definition: ToString.h:55
static int _2int(const E *const data)
converts a char-type array into the integer value described by it
Definition: TplConvert.h:149
#define SUMOReal
Definition: config.h:214
static bool _str2SUMOReal(const std::string &data)
check if a String can be parsed into a SUMOReal check overflows
Definition: TplCheck.h:67
static FXIcon * getIcon(GUIIcon which)
returns a icon previously defined in the enum GUIIcon
GNEVariableSpeedSignal * myVariableSpeedSignalParent
Pointer to Variable Speed Signal.
FXTextField * myRowStep
Text field with step