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