SUMO - Simulation of Urban MObility
GNECalibratorRouteDialog.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 calibrator routes
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>
34 
36 #include "GNECalibrator.h"
37 #include "GNECalibratorRoute.h"
38 #include "GNEEdge.h"
39 #include "GNELane.h"
40 #include "GNEViewNet.h"
41 #include "GNENet.h"
42 #include "GNEUndoList.h"
44 
45 
46 // ===========================================================================
47 // FOX callback mapping
48 // ===========================================================================
49 
50 FXDEFMAP(GNECalibratorRouteDialog) GNECalibratorRouteDialogMap[] = {
52 };
53 
54 // Object implementation
55 FXIMPLEMENT(GNECalibratorRouteDialog, GNEAdditionalDialog, GNECalibratorRouteDialogMap, ARRAYNUMBER(GNECalibratorRouteDialogMap))
56 
57 // ===========================================================================
58 // member method definitions
59 // ===========================================================================
60 
61 GNECalibratorRouteDialog::GNECalibratorRouteDialog(GNECalibratorRoute* editedCalibratorRoute, bool updatingElement) :
62  GNEAdditionalDialog(editedCalibratorRoute->getCalibratorParent(), 400, 120),
63  myEditedCalibratorRoute(editedCalibratorRoute),
64  myUpdatingElement(updatingElement),
65  myCalibratorRouteValid(true) {
66  // change default header
67  std::string typeOfOperation = myUpdatingElement ? "Edit " + toString(myEditedCalibratorRoute->getTag()) + " of " : "Create " + toString(myEditedCalibratorRoute->getTag()) + " for ";
68  changeAdditionalDialogHeader(typeOfOperation + toString(myEditedCalibratorRoute->getCalibratorParent()->getTag()) + " '" + myEditedCalibratorRoute->getCalibratorParent()->getID() + "'");
69 
70  // Create auxiliar frames for data
71  FXHorizontalFrame* columns = new FXHorizontalFrame(myContentFrame, GUIDesignUniformHorizontalFrame);
72  FXVerticalFrame* columnLeft = new FXVerticalFrame(columns, GUIDesignAuxiliarFrame);
73  FXVerticalFrame* columnRight = new FXVerticalFrame(columns, GUIDesignAuxiliarFrame);
74 
75  // create ID's elements
76  new FXLabel(columnLeft, toString(SUMO_ATTR_ID).c_str(), 0, GUIDesignLabelLeftThick);
77  myTextFieldRouteID = new FXTextField(columnRight, GUIDesignTextFieldNCol, this, MID_GNE_CALIBRATORDIALOG_SET_VARIABLE, GUIDesignTextField);
78 
79  // create list of edge's elements
80  new FXLabel(columnLeft, toString(SUMO_ATTR_EDGES).c_str(), 0, GUIDesignLabelLeftThick);
81  myTextFieldEdges = new FXTextField(columnRight, GUIDesignTextFieldNCol, this, MID_GNE_CALIBRATORDIALOG_SET_VARIABLE, GUIDesignTextField);
82 
83  // create color's elements
84  new FXLabel(columnLeft, toString(SUMO_ATTR_COLOR).c_str(), 0, GUIDesignLabelLeftThick);
85  myTextFieldColor = new FXTextField(columnRight, GUIDesignTextFieldNCol, this, MID_GNE_CALIBRATORDIALOG_SET_VARIABLE, GUIDesignTextField);
86 
87  // update tables
88  updateCalibratorRouteValues();
89 
90  // start a undo list for editing local to this additional
91  initChanges();
92 
93  // add element if we aren't updating an existent element
94  if (myUpdatingElement == false) {
95  myEditedCalibratorRoute->getCalibratorParent()->getViewNet()->getUndoList()->add(new GNEChange_CalibratorItem(myEditedCalibratorRoute, true), true);
96  }
97 
98  // open as modal dialog
99  openAsModalDialog();
100 }
101 
102 
104 
105 
106 long
107 GNECalibratorRouteDialog::onCmdAccept(FXObject*, FXSelector, void*) {
108  if (myCalibratorRouteValid == false) {
109  // write warning if netedit is running in testing mode
110  if (OptionsCont::getOptions().getBool("gui-testing-debug")) {
111  WRITE_WARNING("Opening FXMessageBox of type 'warning'");
112  }
113  std::string operation1 = myUpdatingElement ? ("updating") : ("creating");
114  std::string operation2 = myUpdatingElement ? ("updated") : ("created");
115  std::string parentTagString = toString(myEditedCalibratorRoute->getCalibratorParent()->getTag());
116  std::string tagString = toString(myEditedCalibratorRoute->getTag());
117  // open warning dialog box
118  FXMessageBox::warning(getApp(), MBOX_OK,
119  ("Error " + operation1 + " " + parentTagString + "'s " + tagString).c_str(), "%s",
120  (parentTagString + "'s " + tagString + " cannot be " + operation2 +
121  " because parameter " + toString(myInvalidAttr) +
122  " is invalid.").c_str());
123  // write warning if netedit is running in testing mode
124  if (OptionsCont::getOptions().getBool("gui-testing-debug")) {
125  WRITE_WARNING("Closed FXMessageBox of type 'warning' with 'OK'");
126  }
127  return 0;
128  } else {
129  // accept changes before closing dialog
130  acceptChanges();
131  // stop dialgo sucesfully
132  getApp()->stopModal(this, TRUE);
133  return 1;
134  }
135 }
136 
137 
138 long
139 GNECalibratorRouteDialog::onCmdCancel(FXObject*, FXSelector, void*) {
140  // cancel changes
141  cancelChanges();
142  // Stop Modal
143  getApp()->stopModal(this, FALSE);
144  return 1;
145 }
146 
147 
148 long
149 GNECalibratorRouteDialog::onCmdReset(FXObject*, FXSelector, void*) {
150  // reset changes
151  resetChanges();
152  // update fields
154  return 1;
155 }
156 
157 
158 long
159 GNECalibratorRouteDialog::onCmdSetVariable(FXObject*, FXSelector, void*) {
160  // At start we assumed, that all values are valid
161  myCalibratorRouteValid = true;
163  // get pointer to undo list (Only for code legilibity)
165  // set color of myTextFieldRouteID, depending if current value is valid or not
166  if (myEditedCalibratorRoute->getID() == myTextFieldRouteID->getText().text()) {
167  myTextFieldRouteID->setTextColor(FXRGB(0, 0, 0));
169  } else if (myEditedCalibratorRoute->isValid(SUMO_ATTR_ID, myTextFieldRouteID->getText().text())) {
170  myTextFieldRouteID->setTextColor(FXRGB(0, 0, 0));
172  } else {
173  myTextFieldRouteID->setTextColor(FXRGB(255, 0, 0));
174  myCalibratorRouteValid = false;
176  }
177 
178  // set color of myTextFieldRouteEdges, depending if current value is valEdges or not
180  myTextFieldEdges->setTextColor(FXRGB(0, 0, 0));
182  } else {
183  myTextFieldEdges->setTextColor(FXRGB(255, 0, 0));
184  myCalibratorRouteValid = false;
186  }
187 
188  // set color of myTextFieldColor, depending if current value is valid or not
190  myTextFieldColor->setTextColor(FXRGB(0, 0, 0));
192  } else {
193  myTextFieldColor->setTextColor(FXRGB(255, 0, 0));
194  myCalibratorRouteValid = false;
196  }
197  return 1;
198 }
199 
200 
201 void
203  myTextFieldRouteID->setText(myEditedCalibratorRoute->getID().c_str());
206 }
207 
208 /****************************************************************************/
void resetChanges()
reset changes did in this dialog.
FXTextField * myTextFieldColor
color of route
GNECalibratorRoute * myEditedCalibratorRoute
pointer to modified rerouter interval
bool myCalibratorRouteValid
flag to check if current calibrator vehicleType is valid
long onCmdCancel(FXObject *, FXSelector, void *)
event after press cancel button
Dialog to edit sequences, parameters, etc.. of Additionals.
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:199
void updateCalibratorRouteValues()
update data fields
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:64
SumoXMLAttr myInvalidAttr
current sumo attribute invalid
FXTextField * myTextFieldRouteID
route ID
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
long onCmdReset(FXObject *, FXSelector, void *)
event after press reset button
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
#define GUIDesignTextField
Definition: GUIDesigns.h:40
the edges of a route
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
invalid attribute
const std::string getID() const
function to support debugging
std::string getAttribute(SumoXMLAttr key) const
inherited from GNEAttributeCarrier
bool myUpdatingElement
flag to indicate if flow are being created or modified
#define GUIDesignTextFieldNCol
Num of column of text field.
Definition: GUIDesigns.h:49
bool isValid(SumoXMLAttr key, const std::string &value)
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.
long onCmdAccept(FXObject *, FXSelector, void *)
FXTextField * myTextFieldEdges
list of edges (string)
FXDEFMAP(GNECalibratorRouteDialog) GNECalibratorRouteDialogMap[]
long onCmdSetVariable(FXObject *, FXSelector, void *)
event after change value
A color information.
#define GUIDesignLabelLeftThick
label extended over frame with thick and with text justify to left and height of 23 ...
Definition: GUIDesigns.h:155
SumoXMLTag getTag() const
get XML Tag assigned to this object
GNECalibrator * getCalibratorParent() const
get pointer to calibrator parent