Eclipse 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-2019 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
15 // Dialog for edit rerouters
16 /****************************************************************************/
17 
18 // ===========================================================================
19 // included modules
20 // ===========================================================================
21 #include <config.h>
22 
27 #include <netedit/GNEViewNet.h>
28 #include <netedit/GNEUndoList.h>
29 
30 #include "GNERerouterDialog.h"
32 
33 
34 // ===========================================================================
35 // FOX callback mapping
36 // ===========================================================================
37 
38 FXDEFMAP(GNERerouterDialog) GNERerouterDialogMap[] = {
44 };
45 
46 // Object implementation
47 FXIMPLEMENT(GNERerouterDialog, GNEAdditionalDialog, GNERerouterDialogMap, ARRAYNUMBER(GNERerouterDialogMap))
48 
49 // ===========================================================================
50 // member method definitions
51 // ===========================================================================
52 
54  GNEAdditionalDialog(rerouterParent, false, 320, 240) {
55 
56  // create Horizontal frame for row elements
57  FXHorizontalFrame* myAddIntervalFrame = new FXHorizontalFrame(myContentFrame, GUIDesignAuxiliarHorizontalFrame);
58  // create Button and Label for adding new Wors
59  myAddInterval = new FXButton(myAddIntervalFrame, "", GUIIconSubSys::getIcon(ICON_ADD), this, MID_GNE_REROUTEDIALOG_ADD_INTERVAL, GUIDesignButtonIcon);
60  new FXLabel(myAddIntervalFrame, ("Add new " + toString(SUMO_TAG_INTERVAL)).c_str(), nullptr, GUIDesignLabelThick);
61  // create Button and Label for sort intervals
62  mySortIntervals = new FXButton(myAddIntervalFrame, "", GUIIconSubSys::getIcon(ICON_RELOAD), this, MID_GNE_REROUTEDIALOG_SORT_INTERVAL, GUIDesignButtonIcon);
63  new FXLabel(myAddIntervalFrame, ("Sort " + toString(SUMO_TAG_INTERVAL) + "s").c_str(), nullptr, GUIDesignLabelThick);
64 
65  // Create table
66  myIntervalTable = new FXTable(myContentFrame, this, MID_GNE_REROUTEDIALOG_TABLE_INTERVAL, GUIDesignTableAdditionals);
67  myIntervalTable->setSelBackColor(FXRGBA(255, 255, 255, 255));
68  myIntervalTable->setSelTextColor(FXRGBA(0, 0, 0, 255));
69  myIntervalTable->setEditable(false);
70 
71  // update intervals
72  updateIntervalTable();
73 
74  // start a undo list for editing local to this additional
75  initChanges();
76 
77  // Open dialog as modal
78  openAsModalDialog();
79 }
80 
81 
83 
84 
85 long
86 GNERerouterDialog::onCmdAccept(FXObject*, FXSelector, void*) {
87  // Check if there is overlapping between Intervals
89  // write warning if netedit is running in testing mode
90  WRITE_DEBUG("Opening FXMessageBox of type 'warning'");
91  // open warning Box
92  FXMessageBox::warning(getApp(), MBOX_OK, "Overlapping detected", "%s", ("Values of '" + myEditedAdditional->getID() + "' cannot be saved. There are intervals overlapped.").c_str());
93  // write warning if netedit is running in testing mode
94  WRITE_DEBUG("Closed FXMessageBox of type 'warning' with 'OK'");
95  return 0;
96  } else {
97  // accept changes before closing dialog
98  acceptChanges();
99  // Stop Modal
100  getApp()->stopModal(this, TRUE);
101  return 1;
102  }
103 }
104 
105 
106 long
107 GNERerouterDialog::onCmdCancel(FXObject*, FXSelector, void*) {
108  // cancel changes
109  cancelChanges();
110  // Stop Modal
111  getApp()->stopModal(this, FALSE);
112  return 1;
113 }
114 
115 
116 long
117 GNERerouterDialog::onCmdReset(FXObject*, FXSelector, void*) {
118  // reset changes
119  resetChanges();
120  // update interval table
122  return 1;
123 }
124 
125 
126 long
127 GNERerouterDialog::onCmdAddInterval(FXObject*, FXSelector, void*) {
128  // create empty rerouter interval and configure it with GNERerouterIntervalDialog
130  // update interval table
132  return 1;
133 }
134 
135 
136 long
137 GNERerouterDialog::onCmdSortIntervals(FXObject*, FXSelector, void*) {
138  // Sort variable speed sign steps
140  // update table
142  return 1;
143 }
144 
145 
146 long
147 GNERerouterDialog::onCmdClickedInterval(FXObject*, FXSelector, void*) {
148  // check if some delete button was pressed
149  for (int i = 0; i < (int)myEditedAdditional->getAdditionalChildren().size(); i++) {
150  if (myIntervalTable->getItem(i, 2)->hasFocus()) {
151  // remove interval
153  // update interval table after removing
155  return 1;
156  }
157  }
158  // check if some begin or o end button was pressed
159  for (int i = 0; i < (int)myEditedAdditional->getAdditionalChildren().size(); i++) {
160  if (myIntervalTable->getItem(i, 0)->hasFocus() || myIntervalTable->getItem(i, 1)->hasFocus()) {
161  // edit interval
163  // update interval table after editing
165  return 1;
166  }
167  }
168  // nothing to do
169  return 0;
170 }
171 
172 
173 void
175  // clear table
176  myIntervalTable->clearItems();
177  // set number of rows
178  myIntervalTable->setTableSize(int(myEditedAdditional->getAdditionalChildren().size()), 3);
179  // Configure list
180  myIntervalTable->setVisibleColumns(4);
181  myIntervalTable->setColumnWidth(0, 137);
182  myIntervalTable->setColumnWidth(1, 136);
183  myIntervalTable->setColumnWidth(2, GUIDesignTableIconCellWidth);
184  myIntervalTable->setColumnText(0, toString(SUMO_ATTR_BEGIN).c_str());
185  myIntervalTable->setColumnText(1, toString(SUMO_ATTR_END).c_str());
186  myIntervalTable->setColumnText(2, "");
187  myIntervalTable->getRowHeader()->setWidth(0);
188  // Declare index for rows and pointer to FXTableItem
189  int indexRow = 0;
190  FXTableItem* item = nullptr;
191  // iterate over values
192  for (auto i : myEditedAdditional->getAdditionalChildren()) {
193  // Set time
194  item = new FXTableItem(i->getAttribute(SUMO_ATTR_BEGIN).c_str());
195  myIntervalTable->setItem(indexRow, 0, item);
196  // Set speed
197  item = new FXTableItem(i->getAttribute(SUMO_ATTR_END).c_str());
198  myIntervalTable->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  item->setEnabled(false);
203  myIntervalTable->setItem(indexRow, 2, item);
204  // Update index
205  indexRow++;
206  }
207 }
208 
209 /****************************************************************************/
#define GUIDesignTableIconCellWidth
width of cells that only contains an Icon
Definition: GUIDesigns.h:483
void resetChanges()
reset changes did in this dialog.
void sortAdditionalChildren()
sort children (used by Rerouters, VSS, TAZs...)
Dialog for edit rerouter intervals.
sort rerouter intervals
Definition: GUIAppEnum.h:982
Dialog to edit sequences, parameters, etc.. of Additionals.
long onCmdClickedInterval(FXObject *, FXSelector, void *)
remove or edit interval
weights: time range begin
FXDEFMAP(GNERerouterDialog) GNERerouterDialogMap[]
const std::vector< GNEAdditional * > & getAdditionalChildren() const
return vector of additionals that have as Parent this edge (For example, Calibrators) ...
Dialog for edit rerouters.
GNEUndoList * getUndoList() const
get the undoList object
Definition: GNEViewNet.cpp:933
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:48
#define GUIDesignAuxiliarHorizontalFrame
design for auxiliar (Without borders) horizontal frame used to pack another frames ...
Definition: GUIDesigns.h:289
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 WRITE_DEBUG(msg)
Definition: MsgHandler.h:246
#define GUIDesignTableAdditionals
design for tables used in additional dialogs
Definition: GUIDesigns.h:480
long onCmdAddInterval(FXObject *, FXSelector, void *)
add new interval
#define GUIDesignButtonIcon
button only with icon (23x23)
Definition: GUIDesigns.h:75
GNEAdditional * myEditedAdditional
pointer to edited aditional
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
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:174
long onCmdSortIntervals(FXObject *, FXSelector, void *)
sort current intervals
an aggreagated-output interval
long onCmdCancel(FXObject *, FXSelector, void *)
event after press cancel button
~GNERerouterDialog()
destructor
void updateIntervalTable()
update data table
bool checkAdditionalChildrenOverlapping() const
check if children are overlapped (Used by Rerouters)
long onCmdAccept(FXObject *, FXSelector, void *)
static FXIcon * getIcon(GUIIcon which)
returns a icon previously defined in the enum GUIIcon