SUMO - Simulation of Urban MObility
GNERerouterDialog.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2017 German Aerospace Center (DLR) and others.
4 /****************************************************************************/
5 //
6 // This program and the accompanying materials
7 // are made available under the terms of the Eclipse Public License v2.0
8 // which accompanies this distribution, and is available at
9 // http://www.eclipse.org/legal/epl-v20.html
10 //
11 /****************************************************************************/
17 // Dialog for edit rerouters
18 /****************************************************************************/
19 
20 // ===========================================================================
21 // included modules
22 // ===========================================================================
23 #ifdef _MSC_VER
24 #include <windows_config.h>
25 #else
26 #include <config.h>
27 #endif
28 
29 #include <iostream>
33 
34 #include "GNERerouterDialog.h"
35 #include "GNERerouter.h"
36 #include "GNERerouterInterval.h"
38 #include "GNENet.h"
39 #include "GNEViewNet.h"
40 #include "GNEUndoList.h"
41 #include "GNEChange_RerouterItem.h"
42 
43 
44 // ===========================================================================
45 // FOX callback mapping
46 // ===========================================================================
47 
48 FXDEFMAP(GNERerouterDialog) GNERerouterDialogMap[] = {
53 };
54 
55 // Object implementation
56 FXIMPLEMENT(GNERerouterDialog, GNEAdditionalDialog, GNERerouterDialogMap, ARRAYNUMBER(GNERerouterDialogMap))
57 
58 // ===========================================================================
59 // member method definitions
60 // ===========================================================================
61 
63  GNEAdditionalDialog(rerouterParent, 320, 240),
64  myEditedRerouter(rerouterParent) {
65 
66  // create add buton and label
67  FXHorizontalFrame* buttonAndLabelInterval = new FXHorizontalFrame(myContentFrame, GUIDesignAuxiliarHorizontalFrame);
68  myAddInterval = new FXButton(buttonAndLabelInterval, "", GUIIconSubSys::getIcon(ICON_ADD), this, MID_GNE_REROUTEDIALOG_ADD_INTERVAL, GUIDesignButtonIcon);
69  new FXLabel(buttonAndLabelInterval, ("Add new " + toString(SUMO_TAG_INTERVAL)).c_str(), 0, GUIDesignLabelThick);
70 
71  // Create table
72  myIntervalTable = new FXTable(myContentFrame, this, MID_GNE_REROUTEDIALOG_TABLE_INTERVAL, GUIDesignTableAdditionals);
73  myIntervalTable->setSelBackColor(FXRGBA(255, 255, 255, 255));
74  myIntervalTable->setSelTextColor(FXRGBA(0, 0, 0, 255));
75  myIntervalTable->setEditable(false);
76 
77  // update intervals
78  updateIntervalTable();
79 
80  // start a undo list for editing local to this additional
81  initChanges();
82 
83  // Open dialog as modal
84  openAsModalDialog();
85 }
86 
87 
89 
90 
93  return myEditedRerouter;
94 }
95 
96 
97 long
98 GNERerouterDialog::onCmdAccept(FXObject*, FXSelector, void*) {
99  // get number of Rerouter intervals overlapped
100  int numberOfOverlappings = myEditedRerouter->getNumberOfOverlappedIntervals();
101  // overlapped intervals aren't allowed
102  if (numberOfOverlappings > 0) {
103  // write warning if netedit is running in testing mode
104  if (OptionsCont::getOptions().getBool("gui-testing-debug")) {
105  WRITE_WARNING("Opening FXMessageBox of type 'warning'");
106  }
107  // open warning Box
108  std::string errorMessage = numberOfOverlappings > 1 ? ("There are " + toString(numberOfOverlappings) + " intervals overlapped.") : ("There is " + toString(numberOfOverlappings) + " interval overlapped.");
109  FXMessageBox::warning(getApp(), MBOX_OK, "Overlapping detected", "%s", ("Values of '" + myEditedRerouter->getID() + "' cannot be saved. " + errorMessage).c_str());
110  // write warning if netedit is running in testing mode
111  if (OptionsCont::getOptions().getBool("gui-testing-debug")) {
112  WRITE_WARNING("Closed FXMessageBox of type 'warning' with 'OK'");
113  }
114  return 0;
115  } else {
116  // accept changes before closing dialog
117  acceptChanges();
118  // Stop Modal
119  getApp()->stopModal(this, TRUE);
120  return 1;
121  }
122 }
123 
124 
125 long
126 GNERerouterDialog::onCmdCancel(FXObject*, FXSelector, void*) {
127  // cancel changes
128  cancelChanges();
129  // Stop Modal
130  getApp()->stopModal(this, FALSE);
131  return 1;
132 }
133 
134 
135 long
136 GNERerouterDialog::onCmdReset(FXObject*, FXSelector, void*) {
137  // reset changes
138  resetChanges();
139  // update interval table
141  return 1;
142 }
143 
144 
145 long
146 GNERerouterDialog::onCmdAddInterval(FXObject*, FXSelector, void*) {
147  // create empty rerouter interval and configure it with GNERerouterIntervalDialog
149  // update interval table
151  return 1;
152 }
153 
154 
155 long
156 GNERerouterDialog::onCmdClickedInterval(FXObject*, FXSelector, void*) {
157  // check if some delete button was pressed
158  for (int i = 0; i < (int)myEditedRerouter->getRerouterIntervals().size(); i++) {
159  if (myIntervalTable->getItem(i, 2)->hasFocus()) {
160  // get rerouter interval to remove
161  GNERerouterInterval* rerouterInterval = myEditedRerouter->getRerouterIntervals().at(i);
162  // drop all closing reroutes of interval
163  while (rerouterInterval->getClosingReroutes().size() > 0) {
164  myEditedRerouter->getViewNet()->getUndoList()->add(new GNEChange_RerouterItem(rerouterInterval->getClosingReroutes().front(), false), true);
165  }
166  // drop all closing lane reroutes of interval
167  while (rerouterInterval->getClosingLaneReroutes().size() > 0) {
168  myEditedRerouter->getViewNet()->getUndoList()->add(new GNEChange_RerouterItem(rerouterInterval->getClosingLaneReroutes().front(), false), true);
169  }
170  // drop all route probability reroutes of interval
171  while (rerouterInterval->getRouteProbReroutes().size() > 0) {
172  myEditedRerouter->getViewNet()->getUndoList()->add(new GNEChange_RerouterItem(rerouterInterval->getRouteProbReroutes().front(), false), true);
173  }
174  // drop all destiny probability reroutes of interval
175  while (rerouterInterval->getDestProbReroutes().size() > 0) {
176  myEditedRerouter->getViewNet()->getUndoList()->add(new GNEChange_RerouterItem(rerouterInterval->getDestProbReroutes().front(), false), true);
177  }
178  // remove interval
179  myEditedRerouter->getViewNet()->getUndoList()->add(new GNEChange_RerouterItem(rerouterInterval, false), true);
180  // update interval table after removing
182  return 1;
183  }
184  }
185  // check if some begin or o end button was pressed
186  for (int i = 0; i < (int)myEditedRerouter->getRerouterIntervals().size(); i++) {
187  if (myIntervalTable->getItem(i, 0)->hasFocus() || myIntervalTable->getItem(i, 1)->hasFocus()) {
188  // edit interval
190  // update interval table after editing
192  return 1;
193  }
194  }
195  // nothing to do
196  return 0;
197 }
198 
199 
200 void
202  // clear table
203  myIntervalTable->clearItems();
204  // set number of rows
205  myIntervalTable->setTableSize(int(myEditedRerouter->getRerouterIntervals().size()), 3);
206  // Configure list
207  myIntervalTable->setVisibleColumns(4);
208  myIntervalTable->setColumnWidth(0, 137);
209  myIntervalTable->setColumnWidth(1, 136);
210  myIntervalTable->setColumnWidth(2, GUIDesignTableIconCellWidth);
211  myIntervalTable->setColumnText(0, toString(SUMO_ATTR_BEGIN).c_str());
212  myIntervalTable->setColumnText(1, toString(SUMO_ATTR_END).c_str());
213  myIntervalTable->setColumnText(2, "");
214  myIntervalTable->getRowHeader()->setWidth(0);
215  // Declare index for rows and pointer to FXTableItem
216  int indexRow = 0;
217  FXTableItem* item = 0;
218  // iterate over values
219  for (auto i : myEditedRerouter->getRerouterIntervals()) {
220  // Set time
221  item = new FXTableItem(i->getAttribute(SUMO_ATTR_BEGIN).c_str());
222  myIntervalTable->setItem(indexRow, 0, item);
223  // Set speed
224  item = new FXTableItem(i->getAttribute(SUMO_ATTR_END).c_str());
225  myIntervalTable->setItem(indexRow, 1, item);
226  // set remove
227  item = new FXTableItem("", GUIIconSubSys::getIcon(ICON_REMOVE));
228  item->setJustify(FXTableItem::CENTER_X | FXTableItem::CENTER_Y);
229  item->setEnabled(false);
230  myIntervalTable->setItem(indexRow, 2, item);
231  // Update index
232  indexRow++;
233  }
234 }
235 
236 /****************************************************************************/
#define GUIDesignTableIconCellWidth
width of cells that only contains an Icon
Definition: GUIDesigns.h:414
void resetChanges()
reset changes did in this dialog.
const std::vector< GNEDestProbReroute * > & getDestProbReroutes() const
get destiny probability reroutes
const std::vector< GNEClosingLaneReroute * > & getClosingLaneReroutes() const
get closing reroutes
Dialog for edit rerouter intervals.
Dialog to edit sequences, parameters, etc.. of Additionals.
int getNumberOfOverlappedIntervals() const
get number of overlapped intervals
long onCmdClickedInterval(FXObject *, FXSelector, void *)
remove or edit interval
weights: time range begin
const std::vector< GNERouteProbReroute * > & getRouteProbReroutes() const
get reoute probability reroutes
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
FXDEFMAP(GNERerouterDialog) GNERerouterDialogMap[]
GNERerouter * myEditedRerouter
pointer to edited rerouter
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:199
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:64
Dialog for edit rerouters.
GNEUndoList * getUndoList() const
get the undoList object
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:55
#define GUIDesignAuxiliarHorizontalFrame
design for auxiliar (Without borders) horizontal frame used to pack another frames ...
Definition: GUIDesigns.h:246
FXTable * myIntervalTable
list with intervals
const std::string getID() const
function to support debugging
long onCmdReset(FXObject *, FXSelector, void *)
event after press reset button
#define GUIDesignTableAdditionals
design for tables used in additional dialogs
Definition: GUIDesigns.h:411
long onCmdAddInterval(FXObject *, FXSelector, void *)
add new interval
#define GUIDesignButtonIcon
button only with icon (23x23)
Definition: GUIDesigns.h:65
const std::vector< GNEClosingReroute * > & getClosingReroutes() const
get closing reroutes
GNEViewNet * getViewNet() const
Returns a pointer to GNEViewNet in which additional element is located.
void acceptChanges()
Accept changes did in this dialog.
weights: time range end
const std::vector< GNERerouterInterval * > & getRerouterIntervals() const
get rerouter intervals
void cancelChanges()
Cancel changes did in this dialog.
#define GUIDesignLabelThick
label extended over frame with thick and with text justify to left and height of 23 ...
Definition: GUIDesigns.h:152
an aggreagated-output interval
GNERerouter * getEditedRerouter() const
get edited rerouter
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