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 /****************************************************************************/
14 // Dialog for edit rerouters
15 /****************************************************************************/
16 
17 // ===========================================================================
18 // included modules
19 // ===========================================================================
20 #include <config.h>
21 
26 #include <netedit/GNEViewNet.h>
27 #include <netedit/GNEUndoList.h>
28 
29 #include "GNERerouterDialog.h"
31 
32 
33 // ===========================================================================
34 // FOX callback mapping
35 // ===========================================================================
36 
37 FXDEFMAP(GNERerouterDialog) GNERerouterDialogMap[] = {
43 };
44 
45 // Object implementation
46 FXIMPLEMENT(GNERerouterDialog, GNEAdditionalDialog, GNERerouterDialogMap, ARRAYNUMBER(GNERerouterDialogMap))
47 
48 // ===========================================================================
49 // member method definitions
50 // ===========================================================================
51 
53  GNEAdditionalDialog(rerouterParent, false, 320, 240) {
54 
55  // create Horizontal frame for row elements
56  FXHorizontalFrame* myAddIntervalFrame = new FXHorizontalFrame(myContentFrame, GUIDesignAuxiliarHorizontalFrame);
57  // create Button and Label for adding new Wors
58  myAddInterval = new FXButton(myAddIntervalFrame, "", GUIIconSubSys::getIcon(ICON_ADD), this, MID_GNE_REROUTEDIALOG_ADD_INTERVAL, GUIDesignButtonIcon);
59  new FXLabel(myAddIntervalFrame, ("Add new " + toString(SUMO_TAG_INTERVAL)).c_str(), nullptr, GUIDesignLabelThick);
60  // create Button and Label for sort intervals
61  mySortIntervals = new FXButton(myAddIntervalFrame, "", GUIIconSubSys::getIcon(ICON_RELOAD), this, MID_GNE_REROUTEDIALOG_SORT_INTERVAL, GUIDesignButtonIcon);
62  new FXLabel(myAddIntervalFrame, ("Sort " + toString(SUMO_TAG_INTERVAL) + "s").c_str(), nullptr, GUIDesignLabelThick);
63 
64  // Create table
65  myIntervalTable = new FXTable(myContentFrame, this, MID_GNE_REROUTEDIALOG_TABLE_INTERVAL, GUIDesignTableAdditionals);
66  myIntervalTable->setSelBackColor(FXRGBA(255, 255, 255, 255));
67  myIntervalTable->setSelTextColor(FXRGBA(0, 0, 0, 255));
68  myIntervalTable->setEditable(false);
69 
70  // update intervals
71  updateIntervalTable();
72 
73  // start a undo list for editing local to this additional
74  initChanges();
75 
76  // Open dialog as modal
77  openAsModalDialog();
78 }
79 
80 
82 
83 
84 long
85 GNERerouterDialog::onCmdAccept(FXObject*, FXSelector, void*) {
86  // Check if there is overlapping between Intervals
88  // write warning if netedit is running in testing mode
89  WRITE_DEBUG("Opening FXMessageBox of type 'warning'");
90  // open warning Box
91  FXMessageBox::warning(getApp(), MBOX_OK, "Overlapping detected", "%s", ("Values of '" + myEditedAdditional->getID() + "' cannot be saved. There are intervals overlapped.").c_str());
92  // write warning if netedit is running in testing mode
93  WRITE_DEBUG("Closed FXMessageBox of type 'warning' with 'OK'");
94  return 0;
95  } else {
96  // accept changes before closing dialog
97  acceptChanges();
98  // Stop Modal
99  getApp()->stopModal(this, TRUE);
100  return 1;
101  }
102 }
103 
104 
105 long
106 GNERerouterDialog::onCmdCancel(FXObject*, FXSelector, void*) {
107  // cancel changes
108  cancelChanges();
109  // Stop Modal
110  getApp()->stopModal(this, FALSE);
111  return 1;
112 }
113 
114 
115 long
116 GNERerouterDialog::onCmdReset(FXObject*, FXSelector, void*) {
117  // reset changes
118  resetChanges();
119  // update interval table
121  return 1;
122 }
123 
124 
125 long
126 GNERerouterDialog::onCmdAddInterval(FXObject*, FXSelector, void*) {
127  // create empty rerouter interval and configure it with GNERerouterIntervalDialog
129  // update interval table
131  return 1;
132 }
133 
134 
135 long
136 GNERerouterDialog::onCmdSortIntervals(FXObject*, FXSelector, void*) {
137  // Sort variable speed sign steps
139  // update table
141  return 1;
142 }
143 
144 
145 long
146 GNERerouterDialog::onCmdClickedInterval(FXObject*, FXSelector, void*) {
147  // check if some delete button was pressed
148  for (int i = 0; i < (int)myEditedAdditional->getChildAdditionals().size(); i++) {
149  if (myIntervalTable->getItem(i, 2)->hasFocus()) {
150  // remove interval
152  // update interval table after removing
154  return 1;
155  }
156  }
157  // check if some begin or o end button was pressed
158  for (int i = 0; i < (int)myEditedAdditional->getChildAdditionals().size(); i++) {
159  if (myIntervalTable->getItem(i, 0)->hasFocus() || myIntervalTable->getItem(i, 1)->hasFocus()) {
160  // edit interval
162  // update interval table after editing
164  return 1;
165  }
166  }
167  // nothing to do
168  return 0;
169 }
170 
171 
172 void
174  // clear table
175  myIntervalTable->clearItems();
176  // set number of rows
177  myIntervalTable->setTableSize(int(myEditedAdditional->getChildAdditionals().size()), 3);
178  // Configure list
179  myIntervalTable->setVisibleColumns(4);
180  myIntervalTable->setColumnWidth(0, 137);
181  myIntervalTable->setColumnWidth(1, 136);
182  myIntervalTable->setColumnWidth(2, GUIDesignTableIconCellWidth);
183  myIntervalTable->setColumnText(0, toString(SUMO_ATTR_BEGIN).c_str());
184  myIntervalTable->setColumnText(1, toString(SUMO_ATTR_END).c_str());
185  myIntervalTable->setColumnText(2, "");
186  myIntervalTable->getRowHeader()->setWidth(0);
187  // Declare index for rows and pointer to FXTableItem
188  int indexRow = 0;
189  FXTableItem* item = nullptr;
190  // iterate over values
191  for (auto i : myEditedAdditional->getChildAdditionals()) {
192  // Set time
193  item = new FXTableItem(i->getAttribute(SUMO_ATTR_BEGIN).c_str());
194  myIntervalTable->setItem(indexRow, 0, item);
195  // Set speed
196  item = new FXTableItem(i->getAttribute(SUMO_ATTR_END).c_str());
197  myIntervalTable->setItem(indexRow, 1, item);
198  // set remove
199  item = new FXTableItem("", GUIIconSubSys::getIcon(ICON_REMOVE));
200  item->setJustify(FXTableItem::CENTER_X | FXTableItem::CENTER_Y);
201  item->setEnabled(false);
202  myIntervalTable->setItem(indexRow, 2, item);
203  // Update index
204  indexRow++;
205  }
206 }
207 
208 /****************************************************************************/
GNERerouterDialog.h
GUIDesignAuxiliarHorizontalFrame
#define GUIDesignAuxiliarHorizontalFrame
design for auxiliar (Without borders) horizontal frame used to pack another frames
Definition: GUIDesigns.h:273
GUIDesignLabelThick
#define GUIDesignLabelThick
label extended over frame with thick and with text justify to left and height of 23
Definition: GUIDesigns.h:158
GNEAttributeCarrier::getID
const std::string getID() const
function to support debugging
Definition: GNEAttributeCarrier.cpp:1289
GNERerouterInterval
Definition: GNERerouterInterval.h:45
GNERerouterDialog::onCmdCancel
long onCmdCancel(FXObject *, FXSelector, void *)
event after press cancel button
Definition: GNERerouterDialog.cpp:106
GNERerouterDialog
Dialog for edit rerouters.
Definition: GNERerouterDialog.h:44
GNERerouterDialog::updateIntervalTable
void updateIntervalTable()
update data table
Definition: GNERerouterDialog.cpp:173
GNEChange_Additional
Definition: GNEChange_Additional.h:44
GNEAdditionalDialog
Dialog to edit sequences, parameters, etc.. of Additionals.
Definition: GNEAdditionalDialog.h:44
GNEHierarchicalChildElements::sortChildAdditionals
void sortChildAdditionals()
sort child additionals (used by Rerouters, VSS, TAZs...)
Definition: GNEHierarchicalChildElements.cpp:137
GUIDesigns.h
GNERerouter
Definition: GNERerouter.h:39
GUIIconSubSys::getIcon
static FXIcon * getIcon(GUIIcon which)
returns a icon previously defined in the enum GUIIcon
Definition: GUIIconSubSys.cpp:609
ICON_REMOVE
@ ICON_REMOVE
Definition: GUIIcons.h:184
GNERerouterDialog::onCmdReset
long onCmdReset(FXObject *, FXSelector, void *)
event after press reset button
Definition: GNERerouterDialog.cpp:116
GUIAppEnum.h
SUMO_ATTR_BEGIN
@ SUMO_ATTR_BEGIN
weights: time range begin
Definition: SUMOXMLDefinitions.h:678
GNEAdditionalDialog::cancelChanges
void cancelChanges()
Cancel changes did in this dialog.
Definition: GNEAdditionalDialog.cpp:135
GNEChange_Additional.h
GNERerouterDialog::onCmdAddInterval
long onCmdAddInterval(FXObject *, FXSelector, void *)
add new interval
Definition: GNERerouterDialog.cpp:126
ICON_RELOAD
@ ICON_RELOAD
Definition: GUIIcons.h:47
GUIDesignTableIconCellWidth
#define GUIDesignTableIconCellWidth
width of cells that only contains an Icon
Definition: GUIDesigns.h:467
GUIDesignButtonIcon
#define GUIDesignButtonIcon
button only with icon (23x23)
Definition: GUIDesigns.h:59
ICON_ADD
@ ICON_ADD
Definition: GUIIcons.h:183
GNEViewNet.h
GNERerouterIntervalDialog.h
GNEViewNet::getUndoList
GNEUndoList * getUndoList() const
get the undoList object
Definition: GNEViewNet.cpp:1020
GNERerouterDialog::onCmdSortIntervals
long onCmdSortIntervals(FXObject *, FXSelector, void *)
sort current intervals
Definition: GNERerouterDialog.cpp:136
GNERerouterDialog::onCmdClickedInterval
long onCmdClickedInterval(FXObject *, FXSelector, void *)
remove or edit interval
Definition: GNERerouterDialog.cpp:146
GNERerouterDialog::~GNERerouterDialog
~GNERerouterDialog()
destructor
Definition: GNERerouterDialog.cpp:81
GNEAdditionalDialog::myEditedAdditional
GNEAdditional * myEditedAdditional
pointer to edited aditional
Definition: GNEAdditionalDialog.h:81
toString
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:47
GNERerouterDialog::onCmdAccept
long onCmdAccept(FXObject *, FXSelector, void *)
Definition: GNERerouterDialog.cpp:85
GNEHierarchicalChildElements::checkChildAdditionalsOverlapping
bool checkChildAdditionalsOverlapping() const
check if children are overlapped (Used by Rerouters)
Definition: GNEHierarchicalChildElements.cpp:215
MID_GNE_REROUTEDIALOG_TABLE_INTERVAL
@ MID_GNE_REROUTEDIALOG_TABLE_INTERVAL
select table interval
Definition: GUIAppEnum.h:993
MID_GNE_REROUTEDIALOG_SORT_INTERVAL
@ MID_GNE_REROUTEDIALOG_SORT_INTERVAL
sort rerouter intervals
Definition: GUIAppEnum.h:1007
GNEAdditionalDialog::acceptChanges
void acceptChanges()
Accept changes did in this dialog.
Definition: GNEAdditionalDialog.cpp:124
FXDEFMAP
FXDEFMAP(GNERerouterDialog) GNERerouterDialogMap[]
GNEAdditional::getViewNet
GNEViewNet * getViewNet() const
Returns a pointer to GNEViewNet in which additional element is located.
Definition: GNEAdditional.cpp:307
GNERerouter.h
config.h
SUMO_ATTR_END
@ SUMO_ATTR_END
weights: time range end
Definition: SUMOXMLDefinitions.h:680
GUIDesignTableAdditionals
#define GUIDesignTableAdditionals
design for tables used in additional dialogs
Definition: GUIDesigns.h:464
SUMO_TAG_INTERVAL
@ SUMO_TAG_INTERVAL
an aggreagated-output interval
Definition: SUMOXMLDefinitions.h:159
MID_GNE_REROUTEDIALOG_ADD_INTERVAL
@ MID_GNE_REROUTEDIALOG_ADD_INTERVAL
add interval
Definition: GUIAppEnum.h:1005
GNERerouterDialog::myIntervalTable
FXTable * myIntervalTable
list with intervals
Definition: GNERerouterDialog.h:86
WRITE_DEBUG
#define WRITE_DEBUG(msg)
Definition: MsgHandler.h:284
GNEHierarchicalChildElements::getChildAdditionals
const std::vector< GNEAdditional * > & getChildAdditionals() const
return child additionals
Definition: GNEHierarchicalChildElements.cpp:131
GNEAdditionalDialog::resetChanges
void resetChanges()
reset changes did in this dialog.
Definition: GNEAdditionalDialog.cpp:141
GNERerouterIntervalDialog
Dialog for edit rerouter intervals.
Definition: GNERerouterIntervalDialog.h:49
GNEUndoList.h