Eclipse SUMO - Simulation of Urban MObility
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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-2025 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
21#include <netedit/GNENet.h>
23#include <netedit/GNEUndoList.h>
24#include <netedit/GNEViewNet.h>
29
30#include "GNERerouterDialog.h"
32
33// ===========================================================================
34// FOX callback mapping
35// ===========================================================================
36
42
43// Object implementation
44FXIMPLEMENT(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
82long
83GNERerouterDialog::onCmdAccept(FXObject*, FXSelector, void*) {
84 // Check if there is overlapping between Intervals
86 // open warning Box
87 FXMessageBox::warning(getApp(), MBOX_OK, "Overlapping detected", "%s", ("Values of '" + myEditedAdditional->getID() + "' cannot be saved. There are intervals overlapped.").c_str());
88 return 0;
89 } else {
90 // accept changes before closing dialog
92 // Stop Modal
93 getApp()->stopModal(this, TRUE);
94 return 1;
95 }
96}
97
98
99long
100GNERerouterDialog::onCmdCancel(FXObject*, FXSelector, void*) {
101 // cancel changes
103 // Stop Modal
104 getApp()->stopModal(this, FALSE);
105 return 1;
106}
107
108
109long
110GNERerouterDialog::onCmdReset(FXObject*, FXSelector, void*) {
111 // reset changes
112 resetChanges();
113 // update interval table
115 return 1;
116}
117
118
119long
120GNERerouterDialog::onCmdAddInterval(FXObject*, FXSelector, void*) {
121 // create empty rerouter interval and configure it with modal GNERerouterIntervalDialog
122 GNERerouterIntervalDialog(new GNERerouterInterval(this), false); // NOSONAR, constructor returns after dialog has been closed
123 // update interval table
125 return 1;
126}
127
128
129long
130GNERerouterDialog::onCmdClickedInterval(FXObject*, FXSelector, void*) {
131 // get rerouter children
132 std::vector<GNEAdditional*> rerouterChildren;
133 for (const auto& rerouterChild : myEditedAdditional->getChildAdditionals()) {
134 if (!rerouterChild->getTagProperty()->isSymbol()) {
135 rerouterChildren.push_back(rerouterChild);
136 }
137 }
138 // check if some delete button was pressed
139 for (int i = 0; i < (int)rerouterChildren.size(); i++) {
140 if (myIntervalTable->getItem(i, 2)->hasFocus()) {
141 // remove interval
142 myEditedAdditional->getNet()->getViewNet()->getUndoList()->add(new GNEChange_Additional(rerouterChildren.at(i), false), true);
143 // update interval table after removing
145 return 1;
146 }
147 }
148 // check if some begin or o end button was pressed
149 for (int i = 0; i < (int)rerouterChildren.size(); i++) {
150 if (myIntervalTable->getItem(i, 0)->hasFocus() || myIntervalTable->getItem(i, 1)->hasFocus()) {
151 // edit interval
152 GNERerouterIntervalDialog(rerouterChildren.at(i), true); // NOSONAR, constructor returns after dialog has been closed
153 // update interval table after editing
155 return 1;
156 }
157 }
158 // nothing to do
159 return 0;
160}
161
162
163void
165 // get rerouter children
166 std::vector<GNEAdditional*> rerouterChildren;
167 for (const auto& rerouterChild : myEditedAdditional->getChildAdditionals()) {
168 if (!rerouterChild->getTagProperty()->isSymbol()) {
169 rerouterChildren.push_back(rerouterChild);
170 }
171 }
172 // clear table
173 myIntervalTable->clearItems();
174 // set number of rows
175 myIntervalTable->setTableSize(int(rerouterChildren.size()), 3);
176 // Configure list
177 myIntervalTable->setVisibleColumns(4);
178 myIntervalTable->setColumnWidth(0, 137);
179 myIntervalTable->setColumnWidth(1, 136);
180 myIntervalTable->setColumnWidth(2, GUIDesignHeight);
181 myIntervalTable->setColumnText(0, toString(SUMO_ATTR_BEGIN).c_str());
182 myIntervalTable->setColumnText(1, toString(SUMO_ATTR_END).c_str());
183 myIntervalTable->setColumnText(2, "");
184 myIntervalTable->getRowHeader()->setWidth(0);
185 // Declare index for rows and pointer to FXTableItem
186 int indexRow = 0;
187 FXTableItem* item = nullptr;
188 // iterate over values
189 for (const auto& rerouterChild : rerouterChildren) {
190 // Set time
191 item = new FXTableItem(rerouterChild->getAttribute(SUMO_ATTR_BEGIN).c_str());
192 myIntervalTable->setItem(indexRow, 0, item);
193 // Set speed
194 item = new FXTableItem(rerouterChild->getAttribute(SUMO_ATTR_END).c_str());
195 myIntervalTable->setItem(indexRow, 1, item);
196 // set remove
197 item = new FXTableItem("", GUIIconSubSys::getIcon(GUIIcon::REMOVE));
198 item->setJustify(FXTableItem::CENTER_X | FXTableItem::CENTER_Y);
199 item->setEnabled(false);
200 myIntervalTable->setItem(indexRow, 2, item);
201 // Update index
202 indexRow++;
203 }
204}
205
206
207/****************************************************************************/
FXDEFMAP(GNERerouterDialog) GNERerouterDialogMap[]
@ MID_GNE_REROUTEDIALOG_ADD_INTERVAL
add interval
@ MID_GNE_REROUTEDIALOG_TABLE_INTERVAL
select table interval
@ MID_GNE_REROUTEDIALOG_SORT_INTERVAL
sort rerouter intervals
#define GUIDesignButtonIcon
button only with icon
Definition GUIDesigns.h:91
#define GUIDesignTableAdditionals
design for tables used in additional dialogs
Definition GUIDesigns.h:634
#define GUIDesignAuxiliarHorizontalFrame
design for auxiliar (Without borders) horizontal frame used to pack another frames
Definition GUIDesigns.h:399
#define GUIDesignLabelThick(justify)
label extended over frame with thick and with text justify to left
Definition GUIDesigns.h:249
@ 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:35
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
const GNEHierarchicalContainerChildren< GNEAdditional * > & getChildAdditionals() const
return child additionals
bool checkChildAdditionalsOverlapping() const
check if children are overlapped (Used by Rerouters)
GNEViewNet * getViewNet() const
get view net
Definition GNENet.cpp:2194
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
static FXIcon * getIcon(const GUIIcon which)
returns a icon previously defined in the enum GUIIcon