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