SUMO - Simulation of Urban MObility
GNECalibratorDialog.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-2017 German Aerospace Center (DLR) and others.
4 /****************************************************************************/
5 //
6 // This program and the accompanying materials
7 // are made available under the terms of the Eclipse Public License v2.0
8 // which accompanies this distribution, and is available at
9 // http://www.eclipse.org/legal/epl-v20.html
10 //
11 /****************************************************************************/
17 // Dialog for edit calibrators
18 /****************************************************************************/
19 
20 // ===========================================================================
21 // included modules
22 // ===========================================================================
23 #ifdef _MSC_VER
24 #include <windows_config.h>
25 #else
26 #include <config.h>
27 #endif
28 
29 #include <iostream>
35 
37 #include "GNEViewNet.h"
38 #include "GNENet.h"
39 #include "GNECalibratorDialog.h"
43 #include "GNEUndoList.h"
44 #include "GNECalibrator.h"
45 #include "GNECalibratorRoute.h"
46 #include "GNECalibratorFlow.h"
48 
49 
50 // ===========================================================================
51 // FOX callback mapping
52 // ===========================================================================
53 
54 FXDEFMAP(GNECalibratorDialog) GNECalibratorDialogMap[] = {
61 };
62 
63 // Object implementation
64 FXIMPLEMENT(GNECalibratorDialog, GNEAdditionalDialog, GNECalibratorDialogMap, ARRAYNUMBER(GNECalibratorDialogMap))
65 
66 // ===========================================================================
67 // member method definitions
68 // ===========================================================================
69 
71  GNEAdditionalDialog(editedCalibrator, 640, 480),
72  myEditedCalibrator(editedCalibrator) {
73 
74  // Create two columns, one for Routes and VehicleTypes, and other for Flows
75  FXHorizontalFrame* columns = new FXHorizontalFrame(myContentFrame, GUIDesignUniformHorizontalFrame);
76  FXVerticalFrame* columnLeft = new FXVerticalFrame(columns, GUIDesignAuxiliarFrame);
77  FXVerticalFrame* columnRight = new FXVerticalFrame(columns, GUIDesignAuxiliarFrame);
78 
79  // create add buton and label for routes
80  FXHorizontalFrame* buttonAndLabelRoute = new FXHorizontalFrame(columnLeft, GUIDesignAuxiliarHorizontalFrame);
81  myAddRoute = new FXButton(buttonAndLabelRoute, "", GUIIconSubSys::getIcon(ICON_ADD), this, MID_GNE_CALIBRATORDIALOG_ADD_ROUTE, GUIDesignButtonIcon);
82  new FXLabel(buttonAndLabelRoute, ("Add new " + toString(SUMO_TAG_ROUTE) + "s").c_str(), 0, GUIDesignLabelThick);
83 
84  // Create table in left frame
85  myRouteList = new FXTable(columnLeft, this, MID_GNE_CALIBRATORDIALOG_TABLE_ROUTE, GUIDesignTableAdditionals);
86  myRouteList->setSelBackColor(FXRGBA(255, 255, 255, 255));
87  myRouteList->setSelTextColor(FXRGBA(0, 0, 0, 255));
88  myRouteList->setEditable(false);
89 
90  // create add buton and label for vehicle types
91  FXHorizontalFrame* buttonAndLabelVehicleType = new FXHorizontalFrame(columnLeft, GUIDesignAuxiliarHorizontalFrame);
92  myAddVehicleType = new FXButton(buttonAndLabelVehicleType, "", GUIIconSubSys::getIcon(ICON_ADD), this, MID_GNE_CALIBRATORDIALOG_ADD_VEHICLETYPE, GUIDesignButtonIcon);
93  new FXLabel(buttonAndLabelVehicleType, ("Add new " + toString(SUMO_TAG_VTYPE) + "s").c_str(), 0, GUIDesignLabelThick);
94 
95  // Create table in left frame
96  myVehicleTypeList = new FXTable(columnLeft, this, MID_GNE_CALIBRATORDIALOG_TABLE_VEHICLETYPE, GUIDesignTableAdditionals);
97  myVehicleTypeList->setSelBackColor(FXRGBA(255, 255, 255, 255));
98  myVehicleTypeList->setSelTextColor(FXRGBA(0, 0, 0, 255));
99  myVehicleTypeList->setEditable(false);
100 
101  // create add buton and label for flows in right frame
102  FXHorizontalFrame* buttonAndLabelFlow = new FXHorizontalFrame(columnRight, GUIDesignAuxiliarHorizontalFrame);
103  myAddFlow = new FXButton(buttonAndLabelFlow, "", GUIIconSubSys::getIcon(ICON_ADD), this, MID_GNE_CALIBRATORDIALOG_ADD_FLOW, GUIDesignButtonIcon);
104  myLabelFlow = new FXLabel(buttonAndLabelFlow, ("Add new " + toString(SUMO_TAG_FLOW) + "s").c_str(), 0, GUIDesignLabelThick);
105 
106  // Create table in right frame
107  myFlowList = new FXTable(columnRight, this, MID_GNE_CALIBRATORDIALOG_TABLE_FLOW, GUIDesignTableAdditionals);
108  myFlowList->setSelBackColor(FXRGBA(255, 255, 255, 255));
109  myFlowList->setSelTextColor(FXRGBA(0, 0, 0, 255));
110  myFlowList->setEditable(false);
111 
112  // update tables
113  updateRouteTable();
114  updateVehicleTypeTable();
115  updateFlowTable();
116 
117  // start a undo list for editing local to this additional
118  initChanges();
119 
120  // Open dialog as modal
121  openAsModalDialog();
122 }
123 
124 
126 
127 
130  return myEditedCalibrator;
131 }
132 
133 
134 long
135 GNECalibratorDialog::onCmdAccept(FXObject*, FXSelector, void*) {
136  // accept changes before closing dialog
137  acceptChanges();
138  // Stop Modal
139  getApp()->stopModal(this, TRUE);
140  return 1;
141 }
142 
143 
144 long
145 GNECalibratorDialog::onCmdCancel(FXObject*, FXSelector, void*) {
146  // cancel changes
147  cancelChanges();
148  // Stop Modal
149  getApp()->stopModal(this, FALSE);
150  return 1;
151 }
152 
153 
154 long
155 GNECalibratorDialog::onCmdReset(FXObject*, FXSelector, void*) {
156  // reset changes
157  resetChanges();
158  // update tables
161  updateFlowTable();
162  return 1;
163 }
164 
165 
166 long
167 GNECalibratorDialog::onCmdAddRoute(FXObject*, FXSelector, void*) {
168  // create nes calibrator route and configure it with GNECalibratorRouteDialog
170  // update routes table
172  return 1;
173 }
174 
175 
176 long
177 GNECalibratorDialog::onCmdClickedRoute(FXObject*, FXSelector, void*) {
178  // check if some delete button was pressed
179  for (int i = 0; i < (int)myEditedCalibrator->getCalibratorRoutes().size(); i++) {
180  if (myRouteList->getItem(i, 2)->hasFocus()) {
181  // find all flows that contains route to delete as "route" parameter
182  std::vector<GNECalibratorFlow*> calibratorFlowsToErase;
183  for (auto j : myEditedCalibrator->getCalibratorFlows()) {
184  if (j->getAttribute(SUMO_ATTR_ROUTE) == myRouteList->getItem(i, 0)->getText().text()) {
185  calibratorFlowsToErase.push_back(j);
186  }
187  }
188  // if there are flows that has route to remove as "route" parameter
189  if (calibratorFlowsToErase.size() > 0) {
190  // write warning if netedit is running in testing mode
191  if (OptionsCont::getOptions().getBool("gui-testing-debug")) {
192  WRITE_WARNING("Opening FXMessageBox of type 'question'");
193  }
194  // open question dialog box
195  FXuint answer = FXMessageBox::question(getApp(), MBOX_YES_NO, ("Remove " + toString(SUMO_TAG_FLOW) + "s").c_str(), "%s",
196  ("Deletion of " + toString(SUMO_TAG_ROUTE) + " '" + myRouteList->getItem(i, 0)->getText().text() +
197  "' will remove " + toString(calibratorFlowsToErase.size()) + " " + toString(SUMO_TAG_FLOW) + (calibratorFlowsToErase.size() > 1 ? ("s") : ("")) +
198  ". Continue?").c_str());
199  if (answer != 1) { //1:yes, 2:no, 4:esc
200  // write warning if netedit is running in testing mode
201  if ((answer == 2) && (OptionsCont::getOptions().getBool("gui-testing-debug"))) {
202  WRITE_WARNING("Closed FXMessageBox of type 'question' with 'No'");
203  } else if ((answer == 4) && (OptionsCont::getOptions().getBool("gui-testing-debug"))) {
204  WRITE_WARNING("Closed FXMessageBox of type 'question' with 'ESC'");
205  }
206  // abort deletion of route
207  return 0;
208  } else {
209  // write warning if netedit is running in testing mode
210  if (OptionsCont::getOptions().getBool("gui-testing-debug")) {
211  WRITE_WARNING("Closed FXMessageBox of type 'question' with 'Yes'");
212  }
213  // remove affected flows of calibrator flows
214  for (auto j : calibratorFlowsToErase) {
215  myEditedCalibrator->getViewNet()->getUndoList()->add(new GNEChange_CalibratorItem(j, false), true);
216  }
217  // remove route of calibrator routes
219  // update flows and route table
220  updateFlowTable();
222  return 1;
223  }
224  } else {
225  // remove route
227  // update routes table
229  return 1;
230  }
231  } else if (myRouteList->getItem(i, 0)->hasFocus() || myRouteList->getItem(i, 1)->hasFocus()) {
232  // modify route of calibrator routes
234  // update routes table
236  return 1;
237  }
238  }
239  // nothing to do
240  return 0;
241 }
242 
243 
244 long
245 GNECalibratorDialog::onCmdAddFlow(FXObject*, FXSelector, void*) {
246  // only add flow if there is CalibratorRoutes and Calibrator vehicle types
248  // create new calibrator and configure it with GNECalibratorFlowDialog
249  GNECalibratorFlowDialog(new GNECalibratorFlow(this), false);
250  // update flows table
251  updateFlowTable();
252  return 1;
253  } else {
254  throw ProcessError("Neiter myModifiedCalibratorRoutes nor myModifiedCalibratorVehicleTypes can be empty");
255  }
256 }
257 
258 
259 long
260 GNECalibratorDialog::onCmdClickedFlow(FXObject*, FXSelector, void*) {
261  // check if some delete button was pressed
262  for (int i = 0; i < (int)myEditedCalibrator->getCalibratorFlows().size(); i++) {
263  if (myFlowList->getItem(i, 3)->hasFocus()) {
264  // remove flow of calibrator flows
266  // update flows table
267  updateFlowTable();
268  return 1;
269  } else if (myFlowList->getItem(i, 0)->hasFocus() || myFlowList->getItem(i, 1)->hasFocus() || myFlowList->getItem(i, 2)->hasFocus()) {
270  // modify flow of calibrator flows
272  // update flows table
273  updateFlowTable();
274  return 1;
275  }
276  }
277  // nothing to do
278  return 0;
279 }
280 
281 
282 long
283 GNECalibratorDialog::onCmdAddVehicleType(FXObject*, FXSelector, void*) {
284  // create new calibrator flow and configure it with GNECalibratorVehicleTypeDialog
286  // update vehicle types table
288  return 1;
289 }
290 
291 
292 long
293 GNECalibratorDialog::onCmdClickedVehicleType(FXObject*, FXSelector, void*) {
294  // check if some delete button was pressed
295  for (int i = 0; i < (int)myEditedCalibrator->getCalibratorVehicleTypes().size(); i++) {
296  if (myVehicleTypeList->getItem(i, 2)->hasFocus()) {
297  // find all flows that contains vehicle type to delete as "vehicle type" parameter
298  std::vector<GNECalibratorFlow*> calibratorFlowsToErase;
299  for (auto j : myEditedCalibrator->getCalibratorFlows()) {
300  if (j->getAttribute(SUMO_ATTR_TYPE) == myVehicleTypeList->getItem(i, 0)->getText().text()) {
301  calibratorFlowsToErase.push_back(j);
302  }
303  }
304  // if there are flows that has vehicle type to remove as "vehicle type" parameter
305  if (calibratorFlowsToErase.size() > 0) {
306  FXuint answer = FXMessageBox::question(getApp(), MBOX_YES_NO, ("Remove " + toString(SUMO_TAG_FLOW) + "s").c_str(), "%s",
307  ("Deletion of " + toString(SUMO_TAG_ROUTE) + " '" + myRouteList->getItem(i, 0)->getText().text() +
308  "' will remove " + toString(calibratorFlowsToErase.size()) + " " + toString(SUMO_TAG_FLOW) + (calibratorFlowsToErase.size() > 1 ? ("s") : ("")) +
309  ". Continue?").c_str());
310  if (answer != 1) { //1:yes, 2:no, 4:esc
311  // write warning if netedit is running in testing mode
312  if ((answer == 2) && (OptionsCont::getOptions().getBool("gui-testing-debug"))) {
313  WRITE_WARNING("Closed FXMessageBox of type 'question' with 'No'");
314  } else if ((answer == 4) && (OptionsCont::getOptions().getBool("gui-testing-debug"))) {
315  WRITE_WARNING("Closed FXMessageBox of type 'question' with 'ESC'");
316  }
317  // abort deletion of vehicle type
318  return 0;
319  } else {
320  // write warning if netedit is running in testing mode
321  if (OptionsCont::getOptions().getBool("gui-testing-debug")) {
322  WRITE_WARNING("Closed FXMessageBox of type 'question' with 'Yes'");
323  }
324  // remove affected flows of calibrator flows
325  for (auto j : calibratorFlowsToErase) {
326  myEditedCalibrator->getViewNet()->getUndoList()->add(new GNEChange_CalibratorItem(j, false), true);
327  }
328  // remove vehicle type of calibrator vehicle types
330  // update flows and vehicle types table
331  updateFlowTable();
333  return 1;
334  }
335  } else {
336  // remove vehicle type of calibrator vehicle types
338  // update vehicle types table
340  return 1;
341  }
342  } else if (myVehicleTypeList->getItem(i, 0)->hasFocus() || myVehicleTypeList->getItem(i, 1)->hasFocus()) {
343  // modify vehicle type of calibratorVehicleTypes
345  // update vehicle types table
347  return 1;
348  }
349  }
350  // nothing to do
351  return 0;
352 }
353 
354 
355 void
357  // clear table
358  myRouteList->clearItems();
359  // set number of rows
360  myRouteList->setTableSize(int(myEditedCalibrator->getCalibratorRoutes().size()), 3);
361  // Configure list
362  myRouteList->setVisibleColumns(4);
363  myRouteList->setColumnWidth(0, 136);
364  myRouteList->setColumnWidth(1, 136);
365  myRouteList->setColumnWidth(2, GUIDesignTableIconCellWidth);
366  myRouteList->setColumnText(0, toString(SUMO_ATTR_ID).c_str());
367  myRouteList->setColumnText(1, toString(SUMO_ATTR_EDGES).c_str());
368  myRouteList->setColumnText(2, "");
369  myRouteList->getRowHeader()->setWidth(0);
370  // Declare index for rows and pointer to FXTableItem
371  int indexRow = 0;
372  FXTableItem* item = 0;
373  // iterate over routes
374  for (auto i : myEditedCalibrator->getCalibratorRoutes()) {
375  // Set ID
376  item = new FXTableItem(toString(i->getID()).c_str());
377  myRouteList->setItem(indexRow, 0, item);
378  // Set edges
379  item = new FXTableItem(toString(i->getAttribute(SUMO_ATTR_EDGES)).c_str());
380  myRouteList->setItem(indexRow, 1, item);
381  // set remove
382  item = new FXTableItem("", GUIIconSubSys::getIcon(ICON_REMOVE));
383  item->setJustify(FXTableItem::CENTER_X | FXTableItem::CENTER_Y);
384  item->setEnabled(false);
385  myRouteList->setItem(indexRow, 2, item);
386  // Update index
387  indexRow++;
388  }
389  // enable or disable flow and label button
391 }
392 
393 
394 void
396  // clear table
397  myFlowList->clearItems();
398  // set number of rows
399  myFlowList->setTableSize(int(myEditedCalibrator->getCalibratorFlows().size()), 4);
400  // Configure list
401  myFlowList->setVisibleColumns(4);
402  myFlowList->setColumnWidth(0, 92);
403  myFlowList->setColumnWidth(1, 90);
404  myFlowList->setColumnWidth(2, 90);
405  myFlowList->setColumnWidth(3, GUIDesignTableIconCellWidth);
406  myFlowList->setColumnText(0, toString(SUMO_ATTR_ID).c_str());
407  myFlowList->setColumnText(1, toString(SUMO_ATTR_VCLASS).c_str());
408  myFlowList->setColumnText(2, toString(SUMO_ATTR_ROUTE).c_str());
409  myFlowList->setColumnText(3, "");
410  myFlowList->getRowHeader()->setWidth(0);
411  // Declare index for rows and pointer to FXTableItem
412  int indexRow = 0;
413  FXTableItem* item = 0;
414  // iterate over flows
415  for (auto i : myEditedCalibrator->getCalibratorFlows()) {
416  // Set id
417  item = new FXTableItem(i->getID().c_str());
418  myFlowList->setItem(indexRow, 0, item);
419  // Set vehicle type
420  item = new FXTableItem(i->getAttribute(SUMO_ATTR_TYPE).c_str());
421  myFlowList->setItem(indexRow, 1, item);
422  // Set route
423  item = new FXTableItem(i->getAttribute(SUMO_ATTR_ROUTE).c_str());
424  myFlowList->setItem(indexRow, 2, item);
425  // set remove
426  item = new FXTableItem("", GUIIconSubSys::getIcon(ICON_REMOVE));
427  item->setJustify(FXTableItem::CENTER_X | FXTableItem::CENTER_Y);
428  item->setEnabled(false);
429  myFlowList->setItem(indexRow, 3, item);
430  // Update index
431  indexRow++;
432  }
433  // enable or disable flow and label button
435 }
436 
437 
438 void
440  // clear table
441  myVehicleTypeList->clearItems();
442  // set number of rows
443  myVehicleTypeList->setTableSize(int(myEditedCalibrator->getCalibratorVehicleTypes().size()), 3);
444  // Configure list
445  myVehicleTypeList->setVisibleColumns(4);
446  myVehicleTypeList->setColumnWidth(0, 136);
447  myVehicleTypeList->setColumnWidth(1, 136);
449  myVehicleTypeList->setColumnText(0, toString(SUMO_ATTR_ID).c_str());
450  myVehicleTypeList->setColumnText(1, toString(SUMO_ATTR_VCLASS).c_str());
451  myVehicleTypeList->setColumnText(2, "");
452  myVehicleTypeList->getRowHeader()->setWidth(0);
453  // Declare index for rows and pointer to FXTableItem
454  int indexRow = 0;
455  FXTableItem* item = 0;
456  // iterate over vehicle types
458  // Set id
459  item = new FXTableItem(i->getID().c_str());
460  myVehicleTypeList->setItem(indexRow, 0, item);
461  // Set VClass
462  item = new FXTableItem(i->getAttribute(SUMO_ATTR_VCLASS).c_str());
463  myVehicleTypeList->setItem(indexRow, 1, item);
464  // set remove
465  item = new FXTableItem("", GUIIconSubSys::getIcon(ICON_REMOVE));
466  item->setJustify(FXTableItem::CENTER_X | FXTableItem::CENTER_Y);
467  item->setEnabled(false);
468  myVehicleTypeList->setItem(indexRow, 2, item);
469  // Update index
470  indexRow++;
471  }
472  // enable or disable flow and label button
474 }
475 
476 void
478  // Enable or disable AddFlow button and flow list depending of currently there are routes and vehicle types defined
479  std::string errorMsg;
481  errorMsg = " and ";
482  }
484  myAddFlow->disable();
485  myFlowList->disable();
486  std::string errorMessage = "No " + (myEditedCalibrator->getCalibratorRoutes().empty() ? (toString(SUMO_TAG_ROUTE) + "s") : ("")) + errorMsg +
487  (myEditedCalibrator->getCalibratorVehicleTypes().empty() ? (toString(SUMO_TAG_VTYPE) + "s") : ("")) + " defined";
488  myLabelFlow->setText(errorMessage.c_str());
489  } else {
490  myAddFlow->enable();
491  myFlowList->enable();
492  myLabelFlow->setText(("Add new " + toString(SUMO_TAG_FLOW) + "s").c_str());
493  }
494 }
495 
496 /****************************************************************************/
void updateFlowTable()
update data table with flows
#define GUIDesignTableIconCellWidth
width of cells that only contains an Icon
Definition: GUIDesigns.h:414
void resetChanges()
reset changes did in this dialog.
description of a vehicle type
FXButton * myAddFlow
button for add new flow
a flow definition (used by router)
const std::vector< GNECalibratorVehicleType * > & getCalibratorVehicleTypes() const
get calibrator vehicleTypes
long onCmdAddVehicleType(FXObject *, FXSelector, void *)
add new vehicle type
Dialog to edit sequences, parameters, etc.. of Additionals.
long onCmdAddRoute(FXObject *, FXSelector, void *)
add new route
FXTable * myFlowList
list with flows
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
void updateRouteTable()
update data table with routes
FXLabel * myLabelFlow
label for flows
begin/end of the description of a route
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:199
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:64
void updateFlowAndLabelButton()
update flow and label button
long onCmdReset(FXObject *, FXSelector, void *)
event after press reset button
FXTable * myRouteList
list with routes
GNEUndoList * getUndoList() const
get the undoList object
#define GUIDesignAuxiliarFrame
design for auxiliar (Without borders) frames used to pack another frames extended in all directions ...
Definition: GUIDesigns.h:243
the edges of a route
GNECalibrator * myEditedCalibrator
pointer to edited calibrator
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:55
#define GUIDesignUniformHorizontalFrame
design for horizontal frame used to pack another frames with a uniform width
Definition: GUIDesigns.h:252
long onCmdClickedRoute(FXObject *, FXSelector, void *)
remove or edit route
#define GUIDesignAuxiliarHorizontalFrame
design for auxiliar (Without borders) horizontal frame used to pack another frames ...
Definition: GUIDesigns.h:246
FXTable * myVehicleTypeList
list with vehicle types
Dialog for edit rerouter intervals.
long onCmdClickedFlow(FXObject *, FXSelector, void *)
remove or edit flow
void updateVehicleTypeTable()
update data table with vehicle types
long onCmdAddFlow(FXObject *, FXSelector, void *)
add new flow
#define GUIDesignTableAdditionals
design for tables used in additional dialogs
Definition: GUIDesigns.h:411
#define GUIDesignButtonIcon
button only with icon (23x23)
Definition: GUIDesigns.h:65
const std::vector< GNECalibratorRoute * > & getCalibratorRoutes() const
get calibrator routes
GNECalibrator * getEditedCalibrator() const
get edited calibrator
Dialog for edit calibrators.
GNEViewNet * getViewNet() const
Returns a pointer to GNEViewNet in which additional element is located.
void acceptChanges()
Accept changes did in this dialog.
Dialog for edit Calibrator Routes.
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:152
FXDEFMAP(GNECalibratorDialog) GNECalibratorDialogMap[]
const std::vector< GNECalibratorFlow * > & getCalibratorFlows() const
get calibrator flows
Dialog for edit rerouter intervals.
static FXIcon * getIcon(GUIIcon which)
returns a icon previously defined in the enum GUIIcon
long onCmdCancel(FXObject *, FXSelector, void *)
event after press cancel button
long onCmdClickedVehicleType(FXObject *, FXSelector, void *)
remove or edit vehicle type
long onCmdAccept(FXObject *, FXSelector, void *)