SUMO - Simulation of Urban MObility
GNEVariableSpeedSignDialog.cpp
Go to the documentation of this file.
1 /****************************************************************************/
8 /****************************************************************************/
9 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
10 // Copyright (C) 2001-2017 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>
35 
37 #include "GNEVariableSpeedSign.h"
38 
39 #ifdef CHECK_MEMORY_LEAKS
40 #include <foreign/nvwa/debug_new.h>
41 #endif
42 
43 
44 // ===========================================================================
45 // FOX callback mapping
46 // ===========================================================================
47 
48 FXDEFMAP(GNEVariableSpeedSignDialog) GNERerouterDialogMap[] = {
54 };
55 
56 // Object implementation
57 FXIMPLEMENT(GNEVariableSpeedSignDialog, FXDialogBox, GNERerouterDialogMap, ARRAYNUMBER(GNERerouterDialogMap))
58 
59 // ===========================================================================
60 // member method definitions
61 // ===========================================================================
62 
64  GNEAdditionalDialog(variableSpeedSignParent, 240, 240),
65  myVariableSpeedSignParent(variableSpeedSignParent) {
66 
67  // create List with the data
68  myDataList = new FXTable(myContentFrame, this, MID_GNE_VARIABLESPEEDSIGN_REMOVEROW, GUIDesignTableLimitedHeight);
69  myDataList->setEditable(false);
70 
71  // create Horizontal frame for row elements
72  myRowFrame = new FXHorizontalFrame(myContentFrame, GUIDesignAuxiliarHorizontalFrame);
73 
74  // create Text field for the timeStep
75  myRowStep = new FXTextField(myRowFrame, 10, this, MID_GNE_VARIABLESPEEDSIGN_CHANGEVALUE, GUIDesignTextField);
76 
77  // create Text field for the speed
78  myRowSpeed = new FXTextField(myRowFrame, 10, this, MID_GNE_VARIABLESPEEDSIGN_CHANGEVALUE, GUIDesignTextField);
79 
80  // create Button for insert row
81  myAddRow = new FXButton(myRowFrame, "Add", 0, this, MID_GNE_VARIABLESPEEDSIGN_ADDROW, GUIDesignButtonIcon);
82 
83  // Get values of variable speed signal
84  myVSSValues = myVariableSpeedSignParent->getVariableSpeedSignSteps();
85 
86  // update table
87  updateTable();
88 
89  // Execute additional dialog (To make it modal)
90  execute();
91 }
92 
94 }
95 
96 
97 long
98 GNEVariableSpeedSignDialog::onCmdAddRow(FXObject*, FXSelector, void*) {
99  // Declare variables for time and speed
100  SUMOReal time, speed;
101 
102  // Get Time
103  if (TplCheck::_str2SUMOReal(myRowStep->getText().text()) == false) {
104  return 0;
105  } else {
106  time = TplConvert::_str2SUMOReal(myRowStep->getText().text());
107  }
108 
109  // get SPeed
110  if (TplCheck::_str2SUMOReal(myRowSpeed->getText().text()) == false) {
111  return 0;
112  } else {
113  speed = TplConvert::_str2SUMOReal(myRowSpeed->getText().text());
114  }
115 
116  // Set new time and their speed if don't exist already
117  if (myVSSValues.find(time) == myVSSValues.end()) {
118  myVSSValues[time] = speed;
119  } else {
120  return false;
121  }
122 
123  // Update table
124  updateTable();
125  return 1;
126 }
127 
128 
129 long
130 GNEVariableSpeedSignDialog::onCmdRemoveRow(FXObject*, FXSelector, void*) {
131  // Iterate over rows to find the row to erase
132  for (int i = 0; i < myDataList->getNumRows(); i++) {
133  if (myDataList->getItem(i, 2)->isSelected()) {
134  // Remove element of table and map
135  myVSSValues.erase(TplConvert::_2int(myDataList->getItem(i, 0)->getText().text()));
136  myDataList->removeRows(i);
137  // update table
138  updateTable();
139  return 1;
140  }
141  }
142  return 0;
143 }
144 
145 
146 long
147 GNEVariableSpeedSignDialog::onCmdAccept(FXObject*, FXSelector, void*) {
148  // Save new data in Variable Speed Signal edited
150  // Stop Modal with positive out
151  getApp()->stopModal(this, TRUE);
152  return 1;
153 }
154 
155 
156 long
157 GNEVariableSpeedSignDialog::onCmdCancel(FXObject*, FXSelector, void*) {
158  // Stop Modal with negative out
159  getApp()->stopModal(this, FALSE);
160  return 1;
161 }
162 
163 
164 long
165 GNEVariableSpeedSignDialog::onCmdReset(FXObject*, FXSelector, void*) {
166  // Get old values
168  updateTable();
169  return 1;
170 }
171 
172 
173 void
175  // clear table
176  myDataList->clearItems();
177  // set number of rows
178  myDataList->setTableSize(int(myVSSValues.size()), 3);
179  // Configure list
180  myDataList->setVisibleColumns(3);
181  myDataList->setColumnWidth(0, getWidth() / 3);
182  myDataList->setColumnWidth(1, getWidth() / 3);
183  myDataList->setColumnWidth(2, getWidth() / 3 - 10);
184  myDataList->setColumnText(0, "timeStep");
185  myDataList->setColumnText(1, "speed (km/h)");
186  myDataList->setColumnText(2, "remove");
187  myDataList->getRowHeader()->setWidth(0);
188  // Declare index for rows and pointer to FXTableItem
189  int indexRow = 0;
190  FXTableItem* item = 0;
191  // iterate over values
192  for (std::map<SUMOReal, SUMOReal>::iterator i = myVSSValues.begin(); i != myVSSValues.end(); i++) {
193  // Set time
194  item = new FXTableItem(toString(i->first).c_str());
195  myDataList->setItem(indexRow, 0, item);
196  // Set speed
197  item = new FXTableItem(toString(i->second).c_str());
198  myDataList->setItem(indexRow, 1, item);
199  // set remove
200  item = new FXTableItem("", GUIIconSubSys::getIcon(ICON_REMOVE));
201  item->setJustify(FXTableItem::CENTER_X | FXTableItem::CENTER_Y);
202  myDataList->setItem(indexRow, 2, item);
203  // Update index
204  indexRow++;
205  }
206 }
207 
208 /****************************************************************************/
FXTextField * myRowStep
Text field with step
std::map< SUMOReal, SUMOReal > getVariableSpeedSignSteps() const
get values of variable speed signal
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:348
#define GUIDesignTableLimitedHeight
design for table extended over frame but with limited Height
Definition: GUIDesigns.h:420
Dialog to edit sequences, parameters, etc.. of Additionals.
FXTextField * myRowSpeed
Text field with speed.
long onCmdAddRow(FXObject *, FXSelector, void *)
void setVariableSpeedSignSteps(const std::map< SUMOReal, SUMOReal > &vssValues)
set values of variable speed signal
long onCmdRemoveRow(FXObject *, FXSelector, void *)
event called after press remove row
GNEVariableSpeedSign * myVariableSpeedSignParent
Pointer to Variable Speed Signal.
#define GUIDesignTextField
Definition: GUIDesigns.h:41
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:55
Variable Speed Signal dialog.
Definition: GUIAppEnum.h:477
#define GUIDesignAuxiliarHorizontalFrame
design for auxiliar (Without borders) horizontal frame used to pack another frames ...
Definition: GUIDesigns.h:226
FXTable * myDataList
Table with the data.
long onCmdAccept(FXObject *, FXSelector, void *)
event called after press accept button
#define GUIDesignButtonIcon
button only with icon with the same size as a Label
Definition: GUIDesigns.h:78
static int _2int(const E *const data)
converts a char-type array into the integer value described by it
Definition: TplConvert.h:149
long onCmdCancel(FXObject *, FXSelector, void *)
event called after press cancel button
std::map< SUMOReal, SUMOReal > myVSSValues
Map with the temporal VSSValues.
#define SUMOReal
Definition: config.h:208
static bool _str2SUMOReal(const std::string &data)
check if a String can be parsed into a SUMOReal check overflows
Definition: TplCheck.h:67
long onCmdReset(FXObject *, FXSelector, void *)
event called after press cancel button
FXDEFMAP(GNEVariableSpeedSignDialog) GNERerouterDialogMap[]
static FXIcon * getIcon(GUIIcon which)
returns a icon previously defined in the enum GUIIcon