Eclipse SUMO - Simulation of Urban MObility
GNEVariableSpeedSignDialog.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-2022 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
25#include <netedit/GNENet.h>
26#include <netedit/GNEViewNet.h>
27#include <netedit/GNEUndoList.h>
28
30
31
32// ===========================================================================
33// FOX callback mapping
34// ===========================================================================
35
36FXDEFMAP(GNEVariableSpeedSignDialog) GNERerouterDialogMap[] = {
43};
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 Wors
58 myAddStepButton = new FXButton(myAddStepFrame, "", GUIIconSubSys::getIcon(GUIIcon::ADD), this, MID_GNE_VARIABLESPEEDSIGN_ADDROW, GUIDesignButtonIcon);
59 new FXLabel(myAddStepFrame, ("Add new " + toString(SUMO_TAG_STEP)).c_str(), nullptr, GUIDesignLabelThick);
60 // create Button and Label for sort intervals
61 mySortStepButton = new FXButton(myAddStepFrame, "", GUIIconSubSys::getIcon(GUIIcon::RELOAD), this, MID_GNE_VARIABLESPEEDSIGN_SORT, GUIDesignButtonIcon);
62 new FXLabel(myAddStepFrame, ("Sort " + toString(SUMO_TAG_STEP) + "s").c_str(), nullptr, GUIDesignLabelThick);
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 problemes 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 == false) {
161 // write warning if netedit is running in testing mode
162 WRITE_DEBUG("Opening FXMessageBox of type 'warning'");
163 // open warning Box
164 FXMessageBox::warning(getApp(), MBOX_OK, ("Error updating " + toString(SUMO_TAG_VSS) + " " + toString(SUMO_TAG_STEP)).c_str(), "%s",
165 (toString(SUMO_TAG_VSS) + " " + toString(SUMO_TAG_STEP) + "cannot be updated because there are invalid values").c_str());
166 // write warning if netedit is running in testing mode
167 WRITE_DEBUG("Closed FXMessageBox of type 'warning' with 'OK'");
168 return 0;
169 } else {
170 // accept changes before closing dialog
172 // stop dialog successfully
173 getApp()->stopModal(this, TRUE);
174 return 1;
175 }
176}
177
178
179long
180GNEVariableSpeedSignDialog::onCmdCancel(FXObject*, FXSelector, void*) {
181 // cancel changes
183 // Stop Modal
184 getApp()->stopModal(this, FALSE);
185 return 1;
186}
187
188
189long
190GNEVariableSpeedSignDialog::onCmdReset(FXObject*, FXSelector, void*) {
191 // reset changes
192 resetChanges();
193 // update steps tables
195 return 1;
196}
197
198
199void
201 // get VSS children
202 std::vector<GNEAdditional*> VSSChildren;
203 for (const auto& VSSChild : myEditedAdditional->getChildAdditionals()) {
204 if (!VSSChild->getTagProperty().isSymbol()) {
205 VSSChildren.push_back(VSSChild);
206 }
207 }
208 // clear table
209 myStepsTable->clearItems();
210 // set number of rows
211 myStepsTable->setTableSize(int(VSSChildren.size()), 4);
212 // Configure list
213 myStepsTable->setVisibleColumns(4);
214 myStepsTable->setColumnWidth(0, 115);
215 myStepsTable->setColumnWidth(1, 114);
216 myStepsTable->setColumnWidth(2, GUIDesignHeight);
217 myStepsTable->setColumnWidth(3, GUIDesignHeight);
218 myStepsTable->setColumnText(0, "timeStep");
219 myStepsTable->setColumnText(1, "speed (m/s)");
220 myStepsTable->setColumnText(2, "");
221 myStepsTable->setColumnText(3, "");
222 myStepsTable->getRowHeader()->setWidth(0);
223 // Declare index for rows and pointer to FXTableItem
224 FXTableItem* item = nullptr;
225 // iterate over values
226 for (int i = 0; i < (int)VSSChildren.size(); i++) {
227 // Set time
228 item = new FXTableItem(VSSChildren.at(i)->getAttribute(SUMO_ATTR_TIME).c_str());
229 myStepsTable->setItem(i, 0, item);
230 // Set speed
231 item = new FXTableItem(VSSChildren.at(i)->getAttribute(SUMO_ATTR_SPEED).c_str());
232 myStepsTable->setItem(i, 1, item);
233 // set valid icon
234 item = new FXTableItem("");
236 item->setJustify(FXTableItem::CENTER_X | FXTableItem::CENTER_Y);
237 item->setEnabled(false);
238 myStepsTable->setItem(i, 2, item);
239 // set remove Icon
240 item = new FXTableItem("", GUIIconSubSys::getIcon(GUIIcon::REMOVE));
241 item->setJustify(FXTableItem::CENTER_X | FXTableItem::CENTER_Y);
242 item->setEnabled(false);
243 myStepsTable->setItem(i, 3, item);
244 }
245}
246
247
248/****************************************************************************/
FXDEFMAP(GNEVariableSpeedSignDialog) GNERerouterDialogMap[]
@ MID_GNE_VARIABLESPEEDSIGN_TABLE
Click over Table.
Definition: GUIAppEnum.h:1320
@ MID_GNE_VARIABLESPEEDSIGN_ADDROW
add row
Definition: GUIAppEnum.h:1318
@ MID_GNE_VARIABLESPEEDSIGN_SORT
sort table values
Definition: GUIAppEnum.h:1322
#define GUIDesignButtonIcon
button only with icon
Definition: GUIDesigns.h:86
#define GUIDesignTableAdditionals
design for tables used in additional dialogs
Definition: GUIDesigns.h:616
#define GUIDesignHeight
define a standard height for all elements (Change it carefully)
Definition: GUIDesigns.h:37
#define GUIDesignAuxiliarHorizontalFrame
design for auxiliar (Without borders) horizontal frame used to pack another frames
Definition: GUIDesigns.h:397
#define GUIDesignLabelThick
label extended over frame with thick and with text justify to left
Definition: GUIDesigns.h:226
#define WRITE_DEBUG(msg)
Definition: MsgHandler.h:276
@ 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
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.
An Element which don't belong to GNENet but has influence in the simulation.
Definition: GNEAdditional.h:48
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 std::vector< GNEAdditional * > & getChildAdditionals() const
return child additionals
GNEViewNet * getViewNet() const
get view net
Definition: GNENet.cpp:1987
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
void updateTableSteps()
update data table
GNEUndoList * getUndoList() const
get the undoList object
static FXIcon * getIcon(const GUIIcon which)
returns a icon previously defined in the enum GUIIcon