SUMO - Simulation of Urban MObility
GNERerouterDialog.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>
34 
35 #include "GNERerouterDialog.h"
36 #include "GNERerouter.h"
37 #include "GNERerouterInterval.h"
39 
40 #ifdef CHECK_MEMORY_LEAKS
41 #include <foreign/nvwa/debug_new.h>
42 #endif
43 
44 // ===========================================================================
45 // FOX callback mapping
46 // ===========================================================================
47 
48 FXDEFMAP(GNERerouterDialog) GNERerouterDialogMap[] = {
54 };
55 
56 // Object implementation
57 FXIMPLEMENT(GNERerouterDialog, FXDialogBox, GNERerouterDialogMap, ARRAYNUMBER(GNERerouterDialogMap))
58 
59 // ===========================================================================
60 // member method definitions
61 // ===========================================================================
62 
64  GNEAdditionalDialog(rerouterParent, 320, 240),
65  myRerouterParent(rerouterParent) {
66 
67  // create add buton and label
68  FXHorizontalFrame* buttonAndLabelInterval = new FXHorizontalFrame(myContentFrame, GUIDesignAuxiliarHorizontalFrame);
69  myAddInterval = new FXButton(buttonAndLabelInterval, "", GUIIconSubSys::getIcon(ICON_ADD), this, MID_GNE_REROUTEDIALOG_ADD_INTERVAL, GUIDesignButtonIcon);
70  new FXLabel(buttonAndLabelInterval, ("Add new " + toString(SUMO_TAG_CLOSING_LANE_REROUTE) + "s").c_str(), 0, GUIDesignLabelThick);
71 
72  // Create table, copy intervals and update table
73  myIntervalList = new FXTable(myContentFrame, this, MID_GNE_REROUTEDIALOG_TABLE_INTERVAL, GUIDesignTableAdditionals);
74  myIntervalList->setSelBackColor(FXRGBA(255, 255, 255, 255));
75  myIntervalList->setSelTextColor(FXRGBA(0, 0, 0, 255));
76  myIntervalList->setEditable(false);
77  myCopyOfRerouterIntervals = myRerouterParent->getRerouterIntervals();
78  updateIntervalTable();
79 
80  // Execute additional dialog (To make it modal)
81  execute();
82 }
83 
84 
86 }
87 
88 
91  return myRerouterParent;
92 }
93 
94 
95 bool
97  // Iterate over intervals
98  for (std::vector<GNERerouterInterval>::const_iterator i = myCopyOfRerouterIntervals.begin(); i != myCopyOfRerouterIntervals.end(); i++) {
99  if ((i->getBegin() == begin) && (i->getEnd() == end)) {
100  return true;
101  }
102  }
103  return false;
104 }
105 
106 
107 bool
109  if ((begin < 0) || (end < 0)) {
110  return false;
111  } else if ((begin == 0) && (end == 0)) {
112  return false;
113  } else if (begin >= end) {
114  return false;
115  } else {
117  return true;
118  }
119 }
120 
121 
122 bool
123 GNERerouterDialog::checkModifyInterval(SUMOReal oldBegin, SUMOReal oldEnd, SUMOReal newBegin, SUMOReal newEnd) const {
124  // Iterate over intervals
125  for (std::vector<GNERerouterInterval>::const_iterator i = myCopyOfRerouterIntervals.begin(); i != myCopyOfRerouterIntervals.end(); i++) {
126  if ((i->getBegin() == oldBegin) && (i->getEnd() == oldEnd)) {
127  // Check that new interval is valid
128  if ((newBegin < 0) || (newEnd < 0)) {
129  return false;
130  } else if ((newBegin == 0) && (newEnd == 0)) {
131  return false;
132  } else if (newBegin >= newEnd) {
133  return false;
134  } else {
136  return true;
137  }
138  }
139  }
140  return false;
141 }
142 
143 
144 long
145 GNERerouterDialog::onCmdAccept(FXObject*, FXSelector, void*) {
146  // in this point we need to use GNEChange_RerouterInterval to allow undo/redos of rerouterIntervals
147  // see Ticket #2844
148  // set new intervals into rerouter
150  // Stop Modal
151  getApp()->stopModal(this, TRUE);
152  return 1;
153 }
154 
155 
156 long
157 GNERerouterDialog::onCmdCancel(FXObject*, FXSelector, void*) {
158  // Stop Modal
159  getApp()->stopModal(this, FALSE);
160  return 1;
161 }
162 
163 
164 long
165 GNERerouterDialog::onCmdReset(FXObject*, FXSelector, void*) {
166  // Copy original intervals again and update table
169  return 1;
170 }
171 
172 
173 long
174 GNERerouterDialog::onCmdAddInterval(FXObject*, FXSelector, void*) {
175  // create empty rerouter interval and configure it with GNERerouterIntervalDialog
176  GNERerouterInterval newInterval(myRerouterParent, 0, 0);
177  if (GNERerouterIntervalDialog(this, newInterval).execute() == TRUE) {
178  // if new interval was sucesfully configured, add it to myCopyOfRerouterIntervals
179  myCopyOfRerouterIntervals.push_back(newInterval);
181  return 1;
182  } else {
183  return 0;
184  }
185 }
186 
187 
188 long
189 GNERerouterDialog::onCmdClickedInterval(FXObject*, FXSelector, void*) {
190  // check if some delete button was pressed
191  for (int i = 0; i < (int)myCopyOfRerouterIntervals.size(); i++) {
192  if (myIntervalList->getItem(i, 2)->hasFocus()) {
193  // remove row
194  myIntervalList->removeRows(i);
196  return 1;
197  }
198  }
199  // check if some begin or o end button was pressed
200  for (int i = 0; i < (int)myCopyOfRerouterIntervals.size(); i++) {
201  if (myIntervalList->getItem(i, 0)->hasFocus() || myIntervalList->getItem(i, 1)->hasFocus()) {
202  // edit interval
203  GNERerouterIntervalDialog(this, *(myCopyOfRerouterIntervals.begin() + i)).execute();
204  return 1;
205  }
206  }
207  // nothing to do
208  return 0;
209 }
210 
211 
212 void
214  // clear table
215  myIntervalList->clearItems();
216  // set number of rows
217  myIntervalList->setTableSize(int(myCopyOfRerouterIntervals.size()), 3);
218  // Configure list
219  myIntervalList->setVisibleColumns(4);
220  myIntervalList->setColumnWidth(0, 137);
221  myIntervalList->setColumnWidth(1, 136);
222  myIntervalList->setColumnWidth(2, GUIDesignTableIconCellWidth);
223  myIntervalList->setColumnText(0, toString(SUMO_ATTR_BEGIN).c_str());
224  myIntervalList->setColumnText(1, toString(SUMO_ATTR_END).c_str());
225  myIntervalList->setColumnText(2, "");
226  myIntervalList->getRowHeader()->setWidth(0);
227  // Declare index for rows and pointer to FXTableItem
228  int indexRow = 0;
229  FXTableItem* item = 0;
230  // iterate over values
231  for (std::vector<GNERerouterInterval>::iterator i = myCopyOfRerouterIntervals.begin(); i != myCopyOfRerouterIntervals.end(); i++) {
232  // Set time
233  item = new FXTableItem(toString(i->getBegin()).c_str());
234  myIntervalList->setItem(indexRow, 0, item);
235  // Set speed
236  item = new FXTableItem(toString(i->getEnd()).c_str());
237  myIntervalList->setItem(indexRow, 1, item);
238  // set remove
239  item = new FXTableItem("", GUIIconSubSys::getIcon(ICON_REMOVE));
240  item->setJustify(FXTableItem::CENTER_X | FXTableItem::CENTER_Y);
241  item->setEnabled(false);
242  myIntervalList->setItem(indexRow, 2, item);
243  // Update index
244  indexRow++;
245  }
246 }
247 
248 /****************************************************************************/
#define GUIDesignTableIconCellWidth
width of cells that only contains an Icon
Definition: GUIDesigns.h:426
GNERerouter * myRerouterParent
pointer to rerouter parent
Dialog for edit rerouter intervals.
lane of a reroute of type closing
bool checkInterval(SUMOReal begin, SUMOReal end) const
check begin and end of an new interval
Dialog to edit sequences, parameters, etc.. of Additionals.
long onCmdClickedInterval(FXObject *, FXSelector, void *)
remove or edit interval
weights: time range begin
FXDEFMAP(GNERerouterDialog) GNERerouterDialogMap[]
bool findInterval(SUMOReal begin, SUMOReal end) const
check if a interval exists
Dialog for edit rerouters.
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:55
void setRerouterIntervals(const std::vector< GNERerouterInterval > &rerouterIntervals)
set rerouter intervals
GNERerouter * getRerouterParent() const
get rerouter parent
#define GUIDesignAuxiliarHorizontalFrame
design for auxiliar (Without borders) horizontal frame used to pack another frames ...
Definition: GUIDesigns.h:226
const std::vector< GNERerouterInterval > & getRerouterIntervals() const
get rerouter intervals
std::vector< GNERerouterInterval > myCopyOfRerouterIntervals
set with a copy of rerouter intervals
long onCmdReset(FXObject *, FXSelector, void *)
event after press reset button
#define GUIDesignTableAdditionals
design for tables used in additional dialogs
Definition: GUIDesigns.h:423
long onCmdAddInterval(FXObject *, FXSelector, void *)
add new interval
#define GUIDesignButtonIcon
button only with icon with the same size as a Label
Definition: GUIDesigns.h:78
weights: time range end
bool checkModifyInterval(SUMOReal oldBegin, SUMOReal oldEnd, SUMOReal newBegin, SUMOReal newEnd) const
check if begin and end of an existent interval can be modified
FXTable * myIntervalList
list with intervals
#define GUIDesignLabelThick
label extended over over frame with thick and with text justify to left
Definition: GUIDesigns.h:148
#define SUMOReal
Definition: config.h:208
long onCmdCancel(FXObject *, FXSelector, void *)
event after press cancel button
~GNERerouterDialog()
destructor
void updateIntervalTable()
update data table
long onCmdAccept(FXObject *, FXSelector, void *)
static FXIcon * getIcon(GUIIcon which)
returns a icon previously defined in the enum GUIIcon