Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
GNEVariableSpeedSignDialog.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// A class for edit phases of Variable Speed Signals
19/****************************************************************************/
20
21#include <netedit/GNENet.h>
23#include <netedit/GNEUndoList.h>
24#include <netedit/GNEViewNet.h>
29
31
32// ===========================================================================
33// FOX callback mapping
34// ===========================================================================
35
44
45// Object implementation
46FXIMPLEMENT(GNEVariableSpeedSignDialog, GNEAdditionalDialog, GNERerouterDialogMap, ARRAYNUMBER(GNERerouterDialogMap))
47
48// ===========================================================================
49// member method definitions
50// ===========================================================================
51
53 GNEAdditionalDialog(editedVariableSpeedSign, false, 300, 400),
54 myStepsValids(false) {
55 // create Horizontal frame for row elements
56 FXHorizontalFrame* myAddStepFrame = new FXHorizontalFrame(myContentFrame, GUIDesignAuxiliarHorizontalFrame);
57 // create Button and Label for adding new rows
59 new FXLabel(myAddStepFrame, ("Add new " + toString(SUMO_TAG_STEP)).c_str(), nullptr, GUIDesignLabelThick(JUSTIFY_NORMAL));
60 // create Button and Label for sort intervals
62 new FXLabel(myAddStepFrame, ("Sort " + toString(SUMO_TAG_STEP) + "s").c_str(), nullptr, GUIDesignLabelThick(JUSTIFY_NORMAL));
63 // create List with the data
64 myStepsTable = new FXTable(myContentFrame, this, MID_GNE_VARIABLESPEEDSIGN_TABLE, GUIDesignTableAdditionals);
65 myStepsTable->setSelBackColor(FXRGBA(255, 255, 255, 255));
66 myStepsTable->setSelTextColor(FXRGBA(0, 0, 0, 255));
67 // update table
68 updateTableSteps();
69 // start a undo list for editing local to this additional
70 initChanges();
71 // Open dialog as modal
72 openAsModalDialog();
73}
74
75
77
78
79long
80GNEVariableSpeedSignDialog::onCmdAddStep(FXObject*, FXSelector, void*) {
81 // create step
83 // add it using GNEChange_additional
85 // Update table
87 return 1;
88}
89
90
91long
92GNEVariableSpeedSignDialog::onCmdEditStep(FXObject*, FXSelector, void*) {
93 // get VSS children
94 std::vector<GNEAdditional*> VSSChildren;
95 for (const auto& VSSChild : myEditedAdditional->getChildAdditionals()) {
96 if (!VSSChild->getTagProperty()->isSymbol()) {
97 VSSChildren.push_back(VSSChild);
98 }
99 }
100 myStepsValids = true;
101 // iterate over table and check that all parameters are correct
102 for (int i = 0; i < myStepsTable->getNumRows(); i++) {
103 GNEAdditional* step = VSSChildren.at(i);
104 if (step->isValid(SUMO_ATTR_TIME, myStepsTable->getItem(i, 0)->getText().text()) == false) {
105 myStepsValids = false;
107 } else if (step->isValid(SUMO_ATTR_SPEED, myStepsTable->getItem(i, 1)->getText().text()) == false) {
108 myStepsValids = false;
110 } else {
111 // we need filter attribute (to avoid problems as 1 != 1.00)
112 const double time = GNEAttributeCarrier::parse<double>(myStepsTable->getItem(i, 0)->getText().text());
113 const std::string speed = myStepsTable->getItem(i, 1)->getText().text();
114 // set new values in Closing reroute
117 // set Correct label
118 myStepsTable->getItem(i, 2)->setIcon(GUIIconSubSys::getIcon(GUIIcon::CORRECT));
119 }
120 }
121 // update list
122 myStepsTable->update();
123 return 1;
124}
125
126
127long
128GNEVariableSpeedSignDialog::onCmdClickedStep(FXObject*, FXSelector, void*) {
129 // get VSS children
130 std::vector<GNEAdditional*> VSSChildren;
131 for (const auto& VSSChild : myEditedAdditional->getChildAdditionals()) {
132 if (!VSSChild->getTagProperty()->isSymbol()) {
133 VSSChildren.push_back(VSSChild);
134 }
135 }
136 // check if some delete button was pressed
137 for (int i = 0; i < (int)VSSChildren.size(); i++) {
138 if (myStepsTable->getItem(i, 3)->hasFocus()) {
139 myStepsTable->removeRows(i);
140 myEditedAdditional->getNet()->getViewNet()->getUndoList()->add(new GNEChange_Additional(VSSChildren.at(i), false), true);
141 // Update table
143 return 1;
144 }
145 }
146 return 0;
147}
148
149
150long
151GNEVariableSpeedSignDialog::onCmdSortSteps(FXObject*, FXSelector, void*) {
152 // update table
154 return 1;
155}
156
157
158long
159GNEVariableSpeedSignDialog::onCmdAccept(FXObject*, FXSelector, void*) {
160 if (!myStepsValids) {
161 // open warning Box
162 FXMessageBox::warning(getApp(), MBOX_OK, ("Error updating " + toString(SUMO_TAG_VSS) + " " + toString(SUMO_TAG_STEP)).c_str(), "%s",
163 (toString(SUMO_TAG_VSS) + " " + toString(SUMO_TAG_STEP) + "cannot be updated because there are invalid values").c_str());
164 return 0;
165 } else {
166 // accept changes before closing dialog
168 // stop dialog successfully
169 getApp()->stopModal(this, TRUE);
170 return 1;
171 }
172}
173
174
175long
176GNEVariableSpeedSignDialog::onCmdCancel(FXObject*, FXSelector, void*) {
177 // cancel changes
179 // Stop Modal
180 getApp()->stopModal(this, FALSE);
181 return 1;
182}
183
184
185long
186GNEVariableSpeedSignDialog::onCmdReset(FXObject*, FXSelector, void*) {
187 // reset changes
188 resetChanges();
189 // update steps tables
191 return 1;
192}
193
194
195void
197 // get VSS children
198 std::vector<GNEAdditional*> VSSChildren;
199 for (const auto& VSSChild : myEditedAdditional->getChildAdditionals()) {
200 if (!VSSChild->getTagProperty()->isSymbol()) {
201 VSSChildren.push_back(VSSChild);
202 }
203 }
204 // clear table
205 myStepsTable->clearItems();
206 // set number of rows
207 myStepsTable->setTableSize(int(VSSChildren.size()), 4);
208 // Configure list
209 myStepsTable->setVisibleColumns(4);
210 myStepsTable->setColumnWidth(0, 115);
211 myStepsTable->setColumnWidth(1, 114);
212 myStepsTable->setColumnWidth(2, GUIDesignHeight);
213 myStepsTable->setColumnWidth(3, GUIDesignHeight);
214 myStepsTable->setColumnText(0, "timeStep");
215 myStepsTable->setColumnText(1, "speed (m/s)");
216 myStepsTable->setColumnText(2, "");
217 myStepsTable->setColumnText(3, "");
218 myStepsTable->getRowHeader()->setWidth(0);
219 // Declare index for rows and pointer to FXTableItem
220 FXTableItem* item = nullptr;
221 // iterate over values
222 for (int i = 0; i < (int)VSSChildren.size(); i++) {
223 // Set time
224 item = new FXTableItem(VSSChildren.at(i)->getAttribute(SUMO_ATTR_TIME).c_str());
225 myStepsTable->setItem(i, 0, item);
226 // Set speed
227 item = new FXTableItem(VSSChildren.at(i)->getAttribute(SUMO_ATTR_SPEED).c_str());
228 myStepsTable->setItem(i, 1, item);
229 // set valid icon
230 item = new FXTableItem("");
232 item->setJustify(FXTableItem::CENTER_X | FXTableItem::CENTER_Y);
233 item->setEnabled(false);
234 myStepsTable->setItem(i, 2, item);
235 // set remove Icon
236 item = new FXTableItem("", GUIIconSubSys::getIcon(GUIIcon::REMOVE));
237 item->setJustify(FXTableItem::CENTER_X | FXTableItem::CENTER_Y);
238 item->setEnabled(false);
239 myStepsTable->setItem(i, 3, item);
240 }
241}
242
243
244/****************************************************************************/
FXDEFMAP(GNEVariableSpeedSignDialog) GNERerouterDialogMap[]
@ MID_GNE_VARIABLESPEEDSIGN_TABLE
Click over Table.
@ MID_GNE_VARIABLESPEEDSIGN_ADDROW
add row
@ MID_GNE_VARIABLESPEEDSIGN_SORT
sort table values
#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_STEP
trigger: a step description
@ SUMO_TAG_VSS
A variable speed sign.
@ SUMO_ATTR_SPEED
@ SUMO_ATTR_TIME
trigger: the time of the step
int GUIDesignHeight
the default size for GUI elements
Definition StdDefs.cpp:36
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.
virtual void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)=0
method for setting the attribute and letting the object perform additional changes
virtual bool isValid(SumoXMLAttr key, const std::string &value)=0
method for checking if the key and their correspondent attribute are valids
GNENet * getNet() const
get pointer to net
const GNEHierarchicalContainerChildren< GNEAdditional * > & getChildAdditionals() const
return child additionals
GNEViewNet * getViewNet() const
get view net
Definition GNENet.cpp:2195
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...
FXTable * myStepsTable
Table with the data.
long onCmdClickedStep(FXObject *, FXSelector, void *)
event called after clicked a row
long onCmdCancel(FXObject *, FXSelector, void *)
event called after press cancel button
long onCmdAccept(FXObject *, FXSelector, void *)
event called after press accept button
long onCmdEditStep(FXObject *, FXSelector, void *)
event called after edit row
long onCmdSortSteps(FXObject *, FXSelector, void *)
event called after clicked over sort step button
long onCmdAddStep(FXObject *, FXSelector, void *)
long onCmdReset(FXObject *, FXSelector, void *)
event called after press cancel button
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