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.dev/sumo
3 // Copyright (C) 2001-2024 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 
25 #include <netedit/GNENet.h>
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[] = {
41 };
42 
43 // Object implementation
44 FXIMPLEMENT(GNERerouterDialog, GNEAdditionalDialog, GNERerouterDialogMap, ARRAYNUMBER(GNERerouterDialogMap))
45 
46 // ===========================================================================
47 // member method definitions
48 // ===========================================================================
49 
51  GNEAdditionalDialog(rerouterParent, false, 320, 240) {
52 
53  // create Horizontal frame for row elements
54  FXHorizontalFrame* myAddIntervalFrame = new FXHorizontalFrame(myContentFrame, GUIDesignAuxiliarHorizontalFrame);
55  // create Button and Label for adding new Wors
57  new FXLabel(myAddIntervalFrame, ("Add new " + toString(SUMO_TAG_INTERVAL)).c_str(), nullptr, GUIDesignLabelThick(JUSTIFY_NORMAL));
58  // create Button and Label for sort intervals
60  new FXLabel(myAddIntervalFrame, ("Sort " + toString(SUMO_TAG_INTERVAL) + "s").c_str(), nullptr, GUIDesignLabelThick(JUSTIFY_NORMAL));
61 
62  // Create table
63  myIntervalTable = new FXTable(myContentFrame, this, MID_GNE_REROUTEDIALOG_TABLE_INTERVAL, GUIDesignTableAdditionals);
64  myIntervalTable->setSelBackColor(FXRGBA(255, 255, 255, 255));
65  myIntervalTable->setSelTextColor(FXRGBA(0, 0, 0, 255));
66  myIntervalTable->setEditable(false);
67 
68  // update intervals
69  updateIntervalTable();
70 
71  // start a undo list for editing local to this additional
72  initChanges();
73 
74  // Open dialog as modal
75  openAsModalDialog();
76 }
77 
78 
80 
81 
82 long
83 GNERerouterDialog::onCmdAccept(FXObject*, FXSelector, void*) {
84  // Check if there is overlapping between Intervals
86  // write warning if netedit is running in testing mode
87  WRITE_DEBUG("Opening FXMessageBox of type 'warning'");
88  // open warning Box
89  FXMessageBox::warning(getApp(), MBOX_OK, "Overlapping detected", "%s", ("Values of '" + myEditedAdditional->getID() + "' cannot be saved. There are intervals overlapped.").c_str());
90  // write warning if netedit is running in testing mode
91  WRITE_DEBUG("Closed FXMessageBox of type 'warning' with 'OK'");
92  return 0;
93  } else {
94  // accept changes before closing dialog
95  acceptChanges();
96  // Stop Modal
97  getApp()->stopModal(this, TRUE);
98  return 1;
99  }
100 }
101 
102 
103 long
104 GNERerouterDialog::onCmdCancel(FXObject*, FXSelector, void*) {
105  // cancel changes
106  cancelChanges();
107  // Stop Modal
108  getApp()->stopModal(this, FALSE);
109  return 1;
110 }
111 
112 
113 long
114 GNERerouterDialog::onCmdReset(FXObject*, FXSelector, void*) {
115  // reset changes
116  resetChanges();
117  // update interval table
119  return 1;
120 }
121 
122 
123 long
124 GNERerouterDialog::onCmdAddInterval(FXObject*, FXSelector, void*) {
125  // create empty rerouter interval and configure it with modal GNERerouterIntervalDialog
126  GNERerouterIntervalDialog(new GNERerouterInterval(this), false); // NOSONAR, constructor returns after dialog has been closed
127  // update interval table
129  return 1;
130 }
131 
132 
133 long
134 GNERerouterDialog::onCmdClickedInterval(FXObject*, FXSelector, void*) {
135  // get rerouter children
136  std::vector<GNEAdditional*> rerouterChildren;
137  for (const auto& rerouterChild : myEditedAdditional->getChildAdditionals()) {
138  if (!rerouterChild->getTagProperty().isSymbol()) {
139  rerouterChildren.push_back(rerouterChild);
140  }
141  }
142  // check if some delete button was pressed
143  for (int i = 0; i < (int)rerouterChildren.size(); i++) {
144  if (myIntervalTable->getItem(i, 2)->hasFocus()) {
145  // remove interval
146  myEditedAdditional->getNet()->getViewNet()->getUndoList()->add(new GNEChange_Additional(rerouterChildren.at(i), false), true);
147  // update interval table after removing
149  return 1;
150  }
151  }
152  // check if some begin or o end button was pressed
153  for (int i = 0; i < (int)rerouterChildren.size(); i++) {
154  if (myIntervalTable->getItem(i, 0)->hasFocus() || myIntervalTable->getItem(i, 1)->hasFocus()) {
155  // edit interval
156  GNERerouterIntervalDialog(rerouterChildren.at(i), true); // NOSONAR, constructor returns after dialog has been closed
157  // update interval table after editing
159  return 1;
160  }
161  }
162  // nothing to do
163  return 0;
164 }
165 
166 
167 void
169  // get rerouter children
170  std::vector<GNEAdditional*> rerouterChildren;
171  for (const auto& rerouterChild : myEditedAdditional->getChildAdditionals()) {
172  if (!rerouterChild->getTagProperty().isSymbol()) {
173  rerouterChildren.push_back(rerouterChild);
174  }
175  }
176  // clear table
177  myIntervalTable->clearItems();
178  // set number of rows
179  myIntervalTable->setTableSize(int(rerouterChildren.size()), 3);
180  // Configure list
181  myIntervalTable->setVisibleColumns(4);
182  myIntervalTable->setColumnWidth(0, 137);
183  myIntervalTable->setColumnWidth(1, 136);
184  myIntervalTable->setColumnWidth(2, GUIDesignHeight);
185  myIntervalTable->setColumnText(0, toString(SUMO_ATTR_BEGIN).c_str());
186  myIntervalTable->setColumnText(1, toString(SUMO_ATTR_END).c_str());
187  myIntervalTable->setColumnText(2, "");
188  myIntervalTable->getRowHeader()->setWidth(0);
189  // Declare index for rows and pointer to FXTableItem
190  int indexRow = 0;
191  FXTableItem* item = nullptr;
192  // iterate over values
193  for (const auto& rerouterChild : rerouterChildren) {
194  // Set time
195  item = new FXTableItem(rerouterChild->getAttribute(SUMO_ATTR_BEGIN).c_str());
196  myIntervalTable->setItem(indexRow, 0, item);
197  // Set speed
198  item = new FXTableItem(rerouterChild->getAttribute(SUMO_ATTR_END).c_str());
199  myIntervalTable->setItem(indexRow, 1, item);
200  // set remove
201  item = new FXTableItem("", GUIIconSubSys::getIcon(GUIIcon::REMOVE));
202  item->setJustify(FXTableItem::CENTER_X | FXTableItem::CENTER_Y);
203  item->setEnabled(false);
204  myIntervalTable->setItem(indexRow, 2, item);
205  // Update index
206  indexRow++;
207  }
208 }
209 
210 
211 /****************************************************************************/
FXDEFMAP(GNERerouterDialog) GNERerouterDialogMap[]
@ MID_GNE_REROUTEDIALOG_ADD_INTERVAL
add interval
Definition: GUIAppEnum.h:1454
@ MID_GNE_REROUTEDIALOG_TABLE_INTERVAL
select table interval
Definition: GUIAppEnum.h:1442
@ MID_GNE_REROUTEDIALOG_SORT_INTERVAL
sort rerouter intervals
Definition: GUIAppEnum.h:1456
#define GUIDesignButtonIcon
button only with icon
Definition: GUIDesigns.h:97
#define GUIDesignTableAdditionals
design for tables used in additional dialogs
Definition: GUIDesigns.h:637
#define GUIDesignAuxiliarHorizontalFrame
design for auxiliar (Without borders) horizontal frame used to pack another frames
Definition: GUIDesigns.h:405
#define GUIDesignLabelThick(justify)
label extended over frame with thick and with text justify to left
Definition: GUIDesigns.h:255
#define WRITE_DEBUG(msg)
Definition: MsgHandler.h:306
@ SUMO_TAG_INTERVAL
an aggreagated-output interval
@ SUMO_ATTR_BEGIN
weights: time range begin
@ SUMO_ATTR_END
weights: time range end
int GUIDesignHeight
the default size for GUI elements
Definition: StdDefs.cpp:34
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:46
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 additional
void resetChanges()
reset changes did in this dialog.
const std::string getID() const
get ID (all Attribute Carriers have one)
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:2056
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.
void add(GNEChange *command, bool doit=false, bool merge=true)
Add new command, executing it if desired. The new command will be merged with the previous command if...
GNEUndoList * getUndoList() const
get the undoList object
static FXButton * buildFXButton(FXComposite *p, const std::string &text, const std::string &tip, const std::string &help, FXIcon *ic, FXObject *tgt, FXSelector sel, FXuint opts=BUTTON_NORMAL, FXint x=0, FXint y=0, FXint w=0, FXint h=0, FXint pl=DEFAULT_PAD, FXint pr=DEFAULT_PAD, FXint pt=DEFAULT_PAD, FXint pb=DEFAULT_PAD)
build button
Definition: GUIDesigns.cpp:128
static FXIcon * getIcon(const GUIIcon which)
returns a icon previously defined in the enum GUIIcon