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-2020 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials are made available under the
5 // terms of the Eclipse Public License 2.0 which is available at
6 // https://www.eclipse.org/legal/epl-2.0/
7 // This Source Code may also be made available under the following Secondary
8 // Licenses when the conditions for such availability set forth in the Eclipse
9 // Public License 2.0 are satisfied: GNU General Public License, version 2
10 // or later which is available at
11 // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12 // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13 /****************************************************************************/
18 // Dialog for edit rerouters
19 /****************************************************************************/
20 #include <config.h>
21 
26 #include <netedit/GNENet.h>
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[] = {
42 };
43 
44 // Object implementation
45 FXIMPLEMENT(GNERerouterDialog, GNEAdditionalDialog, GNERerouterDialogMap, ARRAYNUMBER(GNERerouterDialogMap))
46 
47 // ===========================================================================
48 // member method definitions
49 // ===========================================================================
50 
52  GNEAdditionalDialog(rerouterParent, false, 320, 240) {
53 
54  // create Horizontal frame for row elements
55  FXHorizontalFrame* myAddIntervalFrame = new FXHorizontalFrame(myContentFrame, GUIDesignAuxiliarHorizontalFrame);
56  // create Button and Label for adding new Wors
57  myAddInterval = new FXButton(myAddIntervalFrame, "", GUIIconSubSys::getIcon(GUIIcon::ADD), this, MID_GNE_REROUTEDIALOG_ADD_INTERVAL, GUIDesignButtonIcon);
58  new FXLabel(myAddIntervalFrame, ("Add new " + toString(SUMO_TAG_INTERVAL)).c_str(), nullptr, GUIDesignLabelThick);
59  // create Button and Label for sort intervals
60  mySortIntervals = new FXButton(myAddIntervalFrame, "", GUIIconSubSys::getIcon(GUIIcon::RELOAD), this, MID_GNE_REROUTEDIALOG_SORT_INTERVAL, GUIDesignButtonIcon);
61  new FXLabel(myAddIntervalFrame, ("Sort " + toString(SUMO_TAG_INTERVAL) + "s").c_str(), nullptr, GUIDesignLabelThick);
62 
63  // Create table
64  myIntervalTable = new FXTable(myContentFrame, this, MID_GNE_REROUTEDIALOG_TABLE_INTERVAL, GUIDesignTableAdditionals);
65  myIntervalTable->setSelBackColor(FXRGBA(255, 255, 255, 255));
66  myIntervalTable->setSelTextColor(FXRGBA(0, 0, 0, 255));
67  myIntervalTable->setEditable(false);
68 
69  // update intervals
70  updateIntervalTable();
71 
72  // start a undo list for editing local to this additional
73  initChanges();
74 
75  // Open dialog as modal
76  openAsModalDialog();
77 }
78 
79 
81 
82 
83 long
84 GNERerouterDialog::onCmdAccept(FXObject*, FXSelector, void*) {
85  // Check if there is overlapping between Intervals
87  // write warning if netedit is running in testing mode
88  WRITE_DEBUG("Opening FXMessageBox of type 'warning'");
89  // open warning Box
90  FXMessageBox::warning(getApp(), MBOX_OK, "Overlapping detected", "%s", ("Values of '" + myEditedAdditional->getID() + "' cannot be saved. There are intervals overlapped.").c_str());
91  // write warning if netedit is running in testing mode
92  WRITE_DEBUG("Closed FXMessageBox of type 'warning' with 'OK'");
93  return 0;
94  } else {
95  // accept changes before closing dialog
96  acceptChanges();
97  // Stop Modal
98  getApp()->stopModal(this, TRUE);
99  return 1;
100  }
101 }
102 
103 
104 long
105 GNERerouterDialog::onCmdCancel(FXObject*, FXSelector, void*) {
106  // cancel changes
107  cancelChanges();
108  // Stop Modal
109  getApp()->stopModal(this, FALSE);
110  return 1;
111 }
112 
113 
114 long
115 GNERerouterDialog::onCmdReset(FXObject*, FXSelector, void*) {
116  // reset changes
117  resetChanges();
118  // update interval table
120  return 1;
121 }
122 
123 
124 long
125 GNERerouterDialog::onCmdAddInterval(FXObject*, FXSelector, void*) {
126  // create empty rerouter interval and configure it with GNERerouterIntervalDialog
128  // update interval table
130  return 1;
131 }
132 
133 
134 long
135 GNERerouterDialog::onCmdClickedInterval(FXObject*, FXSelector, void*) {
136  // get rerouter children
137  std::vector<GNEAdditional*> rerouterChildren;
138  for (const auto& rerouterChild : myEditedAdditional->getChildAdditionals()) {
139  if (!rerouterChild->getTagProperty().isSymbol()) {
140  rerouterChildren.push_back(rerouterChild);
141  }
142  }
143  // check if some delete button was pressed
144  for (int i = 0; i < (int)rerouterChildren.size(); i++) {
145  if (myIntervalTable->getItem(i, 2)->hasFocus()) {
146  // remove interval
147  myEditedAdditional->getNet()->getViewNet()->getUndoList()->add(new GNEChange_Additional(rerouterChildren.at(i), false), true);
148  // update interval table after removing
150  return 1;
151  }
152  }
153  // check if some begin or o end button was pressed
154  for (int i = 0; i < (int)rerouterChildren.size(); i++) {
155  if (myIntervalTable->getItem(i, 0)->hasFocus() || myIntervalTable->getItem(i, 1)->hasFocus()) {
156  // edit interval
157  GNERerouterIntervalDialog(rerouterChildren.at(i), true);
158  // update interval table after editing
160  return 1;
161  }
162  }
163  // nothing to do
164  return 0;
165 }
166 
167 
168 void
170  // get rerouter children
171  std::vector<GNEAdditional*> rerouterChildren;
172  for (const auto& rerouterChild : myEditedAdditional->getChildAdditionals()) {
173  if (!rerouterChild->getTagProperty().isSymbol()) {
174  rerouterChildren.push_back(rerouterChild);
175  }
176  }
177  // clear table
178  myIntervalTable->clearItems();
179  // set number of rows
180  myIntervalTable->setTableSize(int(rerouterChildren.size()), 3);
181  // Configure list
182  myIntervalTable->setVisibleColumns(4);
183  myIntervalTable->setColumnWidth(0, 137);
184  myIntervalTable->setColumnWidth(1, 136);
185  myIntervalTable->setColumnWidth(2, GUIDesignHeight);
186  myIntervalTable->setColumnText(0, toString(SUMO_ATTR_BEGIN).c_str());
187  myIntervalTable->setColumnText(1, toString(SUMO_ATTR_END).c_str());
188  myIntervalTable->setColumnText(2, "");
189  myIntervalTable->getRowHeader()->setWidth(0);
190  // Declare index for rows and pointer to FXTableItem
191  int indexRow = 0;
192  FXTableItem* item = nullptr;
193  // iterate over values
194  for (const auto& rerouterChild : rerouterChildren) {
195  // Set time
196  item = new FXTableItem(rerouterChild->getAttribute(SUMO_ATTR_BEGIN).c_str());
197  myIntervalTable->setItem(indexRow, 0, item);
198  // Set speed
199  item = new FXTableItem(rerouterChild->getAttribute(SUMO_ATTR_END).c_str());
200  myIntervalTable->setItem(indexRow, 1, item);
201  // set remove
202  item = new FXTableItem("", GUIIconSubSys::getIcon(GUIIcon::REMOVE));
203  item->setJustify(FXTableItem::CENTER_X | FXTableItem::CENTER_Y);
204  item->setEnabled(false);
205  myIntervalTable->setItem(indexRow, 2, item);
206  // Update index
207  indexRow++;
208  }
209 }
210 
211 
212 /****************************************************************************/
FXDEFMAP(GNERerouterDialog) GNERerouterDialogMap[]
@ MID_GNE_REROUTEDIALOG_ADD_INTERVAL
add interval
Definition: GUIAppEnum.h:1136
@ MID_GNE_REROUTEDIALOG_TABLE_INTERVAL
select table interval
Definition: GUIAppEnum.h:1124
@ MID_GNE_REROUTEDIALOG_SORT_INTERVAL
sort rerouter intervals
Definition: GUIAppEnum.h:1138
#define GUIDesignButtonIcon
button only with icon
Definition: GUIDesigns.h:71
#define GUIDesignTableAdditionals
design for tables used in additional dialogs
Definition: GUIDesigns.h:526
#define GUIDesignHeight
define a standard height for all elements (Change it carefully)
Definition: GUIDesigns.h:31
#define GUIDesignAuxiliarHorizontalFrame
design for auxiliar (Without borders) horizontal frame used to pack another frames
Definition: GUIDesigns.h:313
#define GUIDesignLabelThick
label extended over frame with thick and with text justify to left
Definition: GUIDesigns.h:184
#define WRITE_DEBUG(msg)
Definition: MsgHandler.h:286
@ SUMO_TAG_INTERVAL
an aggreagated-output interval
@ SUMO_ATTR_BEGIN
weights: time range begin
@ SUMO_ATTR_END
weights: time range end
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:44
Dialog to edit sequences, parameters, etc.. of Additionals.
void acceptChanges()
Accept changes did in this dialog.
void cancelChanges()
Cancel changes did in this dialog.
GNEAdditional * myEditedAdditional
pointer to edited aditional
void resetChanges()
reset changes did in this dialog.
const std::string & getID() const
get ID
GNENet * getNet() const
get pointer to net
bool checkChildAdditionalsOverlapping() const
check if children are overlapped (Used by Rerouters)
const std::vector< GNEAdditional * > & getChildAdditionals() const
return child additionals
GNEViewNet * getViewNet() const
get view net
Definition: GNENet.cpp:2245
Dialog for edit rerouters.
~GNERerouterDialog()
destructor
long onCmdAccept(FXObject *, FXSelector, void *)
long onCmdReset(FXObject *, FXSelector, void *)
event after press reset button
long onCmdAddInterval(FXObject *, FXSelector, void *)
add new interval
long onCmdCancel(FXObject *, FXSelector, void *)
event after press cancel button
long onCmdClickedInterval(FXObject *, FXSelector, void *)
remove or edit interval
FXTable * myIntervalTable
list with intervals
void updateIntervalTable()
update data table
Dialog for edit rerouter intervals.
GNEUndoList * getUndoList() const
get the undoList object
static FXIcon * getIcon(const GUIIcon which)
returns a icon previously defined in the enum GUIIcon