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 /****************************************************************************/
GUIDesignAuxiliarHorizontalFrame
#define GUIDesignAuxiliarHorizontalFrame
design for auxiliar (Without borders) horizontal frame used to pack another frames
Definition: GUIDesigns.h:289
GNEVariableSpeedSign.h
GNEAdditional
An Element which don't belongs to GNENet but has influency in the simulation.
Definition: GNEAdditional.h:47
GUIDesignLabelThick
#define GUIDesignLabelThick
label extended over frame with thick and with text justify to left and height of 23
Definition: GUIDesigns.h:174
GNEVariableSpeedSignDialog::~GNEVariableSpeedSignDialog
~GNEVariableSpeedSignDialog()
destructor
Definition: GNEVariableSpeedSignDialog.cpp:82
GNEVariableSpeedSignStep
Definition: GNEVariableSpeedSignStep.h:41
ICON_CORRECT
Definition: GUIIcons.h:382
GNEVariableSpeedSignDialog::onCmdClickedStep
long onCmdClickedStep(FXObject *, FXSelector, void *)
event called after clicked a row
Definition: GNEVariableSpeedSignDialog.cpp:126
GNEChange_Additional
Definition: GNEChange_Additional.h:45
MID_GNE_VARIABLESPEEDSIGN_TABLE
Click over Table.
Definition: GUIAppEnum.h:958
GNEAdditionalDialog
Dialog to edit sequences, parameters, etc.. of Additionals.
Definition: GNEAdditionalDialog.h:45
MID_GNE_VARIABLESPEEDSIGN_ADDROW
add row
Definition: GUIAppEnum.h:956
GNEVariableSpeedSign
Definition: GNEVariableSpeedSign.h:40
SUMO_ATTR_SPEED
Definition: SUMOXMLDefinitions.h:385
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:94
GUIIconSubSys::getIcon
static FXIcon * getIcon(GUIIcon which)
returns a icon previously defined in the enum GUIIcon
Definition: GUIIconSubSys.cpp:602
GNEVariableSpeedSignDialog::onCmdAccept
long onCmdAccept(FXObject *, FXSelector, void *)
event called after press accept button
Definition: GNEVariableSpeedSignDialog.cpp:152
GNEVariableSpeedSignDialog::myStepsTable
FXTable * myStepsTable
Table with the data.
Definition: GNEVariableSpeedSignDialog.h:85
ICON_REMOVE
Definition: GUIIcons.h:185
GNEVariableSpeedSignDialog::onCmdSortSteps
long onCmdSortSteps(FXObject *, FXSelector, void *)
event called after clicked over sort step button
Definition: GNEVariableSpeedSignDialog.cpp:142
GUIAppEnum.h
GNEAdditionalDialog::cancelChanges
void cancelChanges()
Cancel changes did in this dialog.
Definition: GNEAdditionalDialog.cpp:136
GNEVariableSpeedSignDialog::onCmdCancel
long onCmdCancel(FXObject *, FXSelector, void *)
event called after press cancel button
Definition: GNEVariableSpeedSignDialog.cpp:175
GNEChange_Additional.h
GNEVariableSpeedSignDialog::onCmdEditStep
long onCmdEditStep(FXObject *, FXSelector, void *)
event called after edit row
Definition: GNEVariableSpeedSignDialog.cpp:97
ICON_RELOAD
Definition: GUIIcons.h:48
GUIDesignTableIconCellWidth
#define GUIDesignTableIconCellWidth
width of cells that only contains an Icon
Definition: GUIDesigns.h:483
FXDEFMAP
FXDEFMAP(GNEVariableSpeedSignDialog) GNERerouterDialogMap[]
GUIDesignButtonIcon
#define GUIDesignButtonIcon
button only with icon (23x23)
Definition: GUIDesigns.h:75
SUMO_TAG_VSS
A variable speed sign.
Definition: SUMOXMLDefinitions.h:90
ICON_ADD
Definition: GUIIcons.h:184
GNEViewNet.h
GNEVariableSpeedSignDialog.h
SUMO_TAG_STEP
trigger: a step description
Definition: SUMOXMLDefinitions.h:158
GNEViewNet::getUndoList
GNEUndoList * getUndoList() const
get the undoList object
Definition: GNEViewNet.cpp:933
SUMO_ATTR_TIME
trigger: the time of the step
Definition: SUMOXMLDefinitions.h:673
GNEVariableSpeedSignDialog
Definition: GNEVariableSpeedSignDialog.h:45
GNEAdditionalDialog::myEditedAdditional
GNEAdditional * myEditedAdditional
pointer to edited aditional
Definition: GNEAdditionalDialog.h:83
toString
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:48
GNEAdditionalDialog::acceptChanges
void acceptChanges()
Accept changes did in this dialog.
Definition: GNEAdditionalDialog.cpp:125
GNEHierarchicalElementChildren::getAdditionalChildren
const std::vector< GNEAdditional * > & getAdditionalChildren() const
return vector of additionals that have as Parent this edge (For example, Calibrators)
Definition: GNEHierarchicalElementChildren.cpp:132
GNEAdditional::getViewNet
GNEViewNet * getViewNet() const
Returns a pointer to GNEViewNet in which additional element is located.
Definition: GNEAdditional.cpp:387
MID_GNE_VARIABLESPEEDSIGN_SORT
sort table values
Definition: GUIAppEnum.h:960
config.h
GUIDesignTableAdditionals
#define GUIDesignTableAdditionals
design for tables used in additional dialogs
Definition: GUIDesigns.h:480
GNEVariableSpeedSignDialog::onCmdAddStep
long onCmdAddStep(FXObject *, FXSelector, void *)
Definition: GNEVariableSpeedSignDialog.cpp:86
GNEVariableSpeedSignDialog::updateTableSteps
void updateTableSteps()
update data table
Definition: GNEVariableSpeedSignDialog.cpp:195
GNEHierarchicalElementChildren::sortAdditionalChildren
void sortAdditionalChildren()
sort children (used by Rerouters, VSS, TAZs...)
Definition: GNEHierarchicalElementChildren.cpp:138
GNEVariableSpeedSignDialog::onCmdReset
long onCmdReset(FXObject *, FXSelector, void *)
event called after press cancel button
Definition: GNEVariableSpeedSignDialog.cpp:185
ICON_ERROR
Definition: GUIIcons.h:383
WRITE_DEBUG
#define WRITE_DEBUG(msg)
Definition: MsgHandler.h:246
GNEAdditional::isValid
virtual bool isValid(SumoXMLAttr key, const std::string &value)=0
method for checking if the key and their conrrespond attribute are valids
GNEAdditionalDialog::resetChanges
void resetChanges()
reset changes did in this dialog.
Definition: GNEAdditionalDialog.cpp:142
GNEUndoList.h