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-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 /****************************************************************************/
15 // A class for edit phases of Variable Speed Signals
16 /****************************************************************************/
17 
18 // ===========================================================================
19 // included modules
20 // ===========================================================================
21 #include <config.h>
22 
27 #include <netedit/GNEViewNet.h>
28 #include <netedit/GNEUndoList.h>
29 
31 
32 
33 // ===========================================================================
34 // FOX callback mapping
35 // ===========================================================================
36 
37 FXDEFMAP(GNEVariableSpeedSignDialog) GNERerouterDialogMap[] = {
44 };
45 
46 // Object implementation
47 FXIMPLEMENT(GNEVariableSpeedSignDialog, GNEAdditionalDialog, GNERerouterDialogMap, ARRAYNUMBER(GNERerouterDialogMap))
48 
49 // ===========================================================================
50 // member method definitions
51 // ===========================================================================
52 
54  GNEAdditionalDialog(editedVariableSpeedSign, false, 300, 400),
55  myStepsValids(false) {
56 
57  // create Horizontal frame for row elements
58  FXHorizontalFrame* myAddStepFrame = new FXHorizontalFrame(myContentFrame, GUIDesignAuxiliarHorizontalFrame);
59  // create Button and Label for adding new Wors
60  myAddStepButton = new FXButton(myAddStepFrame, "", GUIIconSubSys::getIcon(ICON_ADD), this, MID_GNE_VARIABLESPEEDSIGN_ADDROW, GUIDesignButtonIcon);
61  new FXLabel(myAddStepFrame, ("Add new " + toString(SUMO_TAG_STEP)).c_str(), nullptr, GUIDesignLabelThick);
62  // create Button and Label for sort intervals
63  mySortStepButton = new FXButton(myAddStepFrame, "", GUIIconSubSys::getIcon(ICON_RELOAD), this, MID_GNE_VARIABLESPEEDSIGN_SORT, GUIDesignButtonIcon);
64  new FXLabel(myAddStepFrame, ("Sort " + toString(SUMO_TAG_STEP) + "s").c_str(), nullptr, GUIDesignLabelThick);
65 
66  // create List with the data
67  myStepsTable = new FXTable(myContentFrame, this, MID_GNE_VARIABLESPEEDSIGN_TABLE, GUIDesignTableAdditionals);
68  myStepsTable->setSelBackColor(FXRGBA(255, 255, 255, 255));
69  myStepsTable->setSelTextColor(FXRGBA(0, 0, 0, 255));
70 
71  // update table
72  updateTableSteps();
73 
74  // start a undo list for editing local to this additional
75  initChanges();
76 
77  // Open dialog as modal
78  openAsModalDialog();
79 }
80 
81 
83 
84 
85 long
86 GNEVariableSpeedSignDialog::onCmdAddStep(FXObject*, FXSelector, void*) {
87  // Declare variables for time and speed
89  myEditedAdditional->getViewNet()->getUndoList()->add(new GNEChange_Additional(step, true), true);
90  // Update table
92  return 1;
93 }
94 
95 
96 long
97 GNEVariableSpeedSignDialog::onCmdEditStep(FXObject*, FXSelector, void*) {
98  myStepsValids = true;
99  // iterate over table and check that all parameters are correct
100  for (int i = 0; i < myStepsTable->getNumRows(); i++) {
102  if (step->isValid(SUMO_ATTR_TIME, myStepsTable->getItem(i, 0)->getText().text()) == false) {
103  myStepsValids = false;
104  myStepsTable->getItem(i, 2)->setIcon(GUIIconSubSys::getIcon(ICON_ERROR));
105  } else if (step->isValid(SUMO_ATTR_SPEED, myStepsTable->getItem(i, 1)->getText().text()) == false) {
106  myStepsValids = false;
107  myStepsTable->getItem(i, 2)->setIcon(GUIIconSubSys::getIcon(ICON_ERROR));
108  } else {
109  // we need filter attribute (to avoid problemes as 1 != 1.00)
110  double time = GNEAttributeCarrier::parse<double>(myStepsTable->getItem(i, 0)->getText().text());
111  double speed = GNEAttributeCarrier::parse<double>(myStepsTable->getItem(i, 1)->getText().text());
112  // set new values in Closing reroute
115  // set Correct label
116  myStepsTable->getItem(i, 2)->setIcon(GUIIconSubSys::getIcon(ICON_CORRECT));
117  }
118  }
119  // update list
120  myStepsTable->update();
121  return 1;
122 }
123 
124 
125 long
126 GNEVariableSpeedSignDialog::onCmdClickedStep(FXObject*, FXSelector, void*) {
127  // check if some delete button was pressed
128  for (int i = 0; i < (int)myEditedAdditional->getAdditionalChildren().size(); i++) {
129  if (myStepsTable->getItem(i, 3)->hasFocus()) {
130  myStepsTable->removeRows(i);
132  // Update table
134  return 1;
135  }
136  }
137  return 0;
138 }
139 
140 
141 long
142 GNEVariableSpeedSignDialog::onCmdSortSteps(FXObject*, FXSelector, void*) {
143  // Sort variable speed sign steps
145  // update table
147  return 1;
148 }
149 
150 
151 long
152 GNEVariableSpeedSignDialog::onCmdAccept(FXObject*, FXSelector, void*) {
153  if (myStepsValids == false) {
154  // write warning if netedit is running in testing mode
155  WRITE_DEBUG("Opening FXMessageBox of type 'warning'");
156  // open warning Box
157  FXMessageBox::warning(getApp(), MBOX_OK, ("Error updating " + toString(SUMO_TAG_VSS) + " " + toString(SUMO_TAG_STEP)).c_str(), "%s",
158  (toString(SUMO_TAG_VSS) + " " + toString(SUMO_TAG_STEP) + "cannot be updated because there are invalid values").c_str());
159  // write warning if netedit is running in testing mode
160  WRITE_DEBUG("Closed FXMessageBox of type 'warning' with 'OK'");
161  return 0;
162  } else {
163  // accept changes before closing dialog
164  acceptChanges();
165  // sort steps after finish
167  // stop dialgo sucesfully
168  getApp()->stopModal(this, TRUE);
169  return 1;
170  }
171 }
172 
173 
174 long
175 GNEVariableSpeedSignDialog::onCmdCancel(FXObject*, FXSelector, void*) {
176  // cancel changes
177  cancelChanges();
178  // Stop Modal
179  getApp()->stopModal(this, FALSE);
180  return 1;
181 }
182 
183 
184 long
185 GNEVariableSpeedSignDialog::onCmdReset(FXObject*, FXSelector, void*) {
186  // reset changes
187  resetChanges();
188  // update steps tables
190  return 1;
191 }
192 
193 
194 void
196  // clear table
197  myStepsTable->clearItems();
198  // set number of rows
199  myStepsTable->setTableSize(int(myEditedAdditional->getAdditionalChildren().size()), 4);
200  // Configure list
201  myStepsTable->setVisibleColumns(4);
202  myStepsTable->setColumnWidth(0, 115);
203  myStepsTable->setColumnWidth(1, 114);
204  myStepsTable->setColumnWidth(2, GUIDesignTableIconCellWidth);
205  myStepsTable->setColumnWidth(3, GUIDesignTableIconCellWidth);
206  myStepsTable->setColumnText(0, "timeStep");
207  myStepsTable->setColumnText(1, "speed (m/s)");
208  myStepsTable->setColumnText(2, "");
209  myStepsTable->setColumnText(3, "");
210  myStepsTable->getRowHeader()->setWidth(0);
211  // Declare index for rows and pointer to FXTableItem
212  FXTableItem* item = nullptr;
213  // iterate over values
214  for (int i = 0; i < (int)myEditedAdditional->getAdditionalChildren().size(); i++) {
215  // Set time
216  item = new FXTableItem(myEditedAdditional->getAdditionalChildren().at(i)->getAttribute(SUMO_ATTR_TIME).c_str());
217  myStepsTable->setItem(i, 0, item);
218  // Set speed
219  item = new FXTableItem(myEditedAdditional->getAdditionalChildren().at(i)->getAttribute(SUMO_ATTR_SPEED).c_str());
220  myStepsTable->setItem(i, 1, item);
221  // set valid icon
222  item = new FXTableItem("");
223  item->setIcon(GUIIconSubSys::getIcon(ICON_CORRECT));
224  item->setJustify(FXTableItem::CENTER_X | FXTableItem::CENTER_Y);
225  item->setEnabled(false);
226  myStepsTable->setItem(i, 2, item);
227  // set remove Icon
228  item = new FXTableItem("", GUIIconSubSys::getIcon(ICON_REMOVE));
229  item->setJustify(FXTableItem::CENTER_X | FXTableItem::CENTER_Y);
230  item->setEnabled(false);
231  myStepsTable->setItem(i, 3, item);
232  }
233 }
234 
235 /****************************************************************************/
virtual bool isValid(SumoXMLAttr key, const std::string &value)=0
method for checking if the key and their conrrespond attribute are valids
#define GUIDesignTableIconCellWidth
width of cells that only contains an Icon
Definition: GUIDesigns.h:483
void resetChanges()
reset changes did in this dialog.
void sortAdditionalChildren()
sort children (used by Rerouters, VSS, TAZs...)
void updateTableSteps()
update data table
Dialog to edit sequences, parameters, etc.. of Additionals.
FXTable * myStepsTable
Table with the data.
virtual void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)=0
method for setting the attribute and letting the object perform additional changes ...
long onCmdSortSteps(FXObject *, FXSelector, void *)
event called after clicked over sort step button
const std::vector< GNEAdditional * > & getAdditionalChildren() const
return vector of additionals that have as Parent this edge (For example, Calibrators) ...
GNEUndoList * getUndoList() const
get the undoList object
Definition: GNEViewNet.cpp:933
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:48
#define GUIDesignAuxiliarHorizontalFrame
design for auxiliar (Without borders) horizontal frame used to pack another frames ...
Definition: GUIDesigns.h:289
long onCmdClickedStep(FXObject *, FXSelector, void *)
event called after clicked a row
#define WRITE_DEBUG(msg)
Definition: MsgHandler.h:246
#define GUIDesignTableAdditionals
design for tables used in additional dialogs
Definition: GUIDesigns.h:480
long onCmdAccept(FXObject *, FXSelector, void *)
event called after press accept button
#define GUIDesignButtonIcon
button only with icon (23x23)
Definition: GUIDesigns.h:75
GNEAdditional * myEditedAdditional
pointer to edited aditional
trigger: the time of the step
void acceptChanges()
Accept changes did in this dialog.
GNEViewNet * getViewNet() const
Returns a pointer to GNEViewNet in which additional element is located.
An Element which don&#39;t belongs to GNENet but has influency in the simulation.
Definition: GNEAdditional.h:47
void cancelChanges()
Cancel changes did in this dialog.
#define GUIDesignLabelThick
label extended over frame with thick and with text justify to left and height of 23 ...
Definition: GUIDesigns.h:174
long onCmdCancel(FXObject *, FXSelector, void *)
event called after press cancel button
long onCmdAddStep(FXObject *, FXSelector, void *)
A variable speed sign.
long onCmdReset(FXObject *, FXSelector, void *)
event called after press cancel button
long onCmdEditStep(FXObject *, FXSelector, void *)
event called after edit row
FXDEFMAP(GNEVariableSpeedSignDialog) GNERerouterDialogMap[]
static FXIcon * getIcon(GUIIcon which)
returns a icon previously defined in the enum GUIIcon
trigger: a step description