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-2018 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 // Dialog for edit calibrator routes
16 /****************************************************************************/
17 
18 // ===========================================================================
19 // included modules
20 // ===========================================================================
21 #include <config.h>
22 
23 #include <iostream>
33 #include <netedit/GNEViewNet.h>
34 #include <netedit/GNENet.h>
35 #include <netedit/GNEUndoList.h>
36 
38 
39 
40 // ===========================================================================
41 // FOX callback mapping
42 // ===========================================================================
43 
44 FXDEFMAP(GNECalibratorRouteDialog) GNECalibratorRouteDialogMap[] = {
46 };
47 
48 // Object implementation
49 FXIMPLEMENT(GNECalibratorRouteDialog, GNEAdditionalDialog, GNECalibratorRouteDialogMap, ARRAYNUMBER(GNECalibratorRouteDialogMap))
50 
51 // ===========================================================================
52 // member method definitions
53 // ===========================================================================
54 
55 GNECalibratorRouteDialog::GNECalibratorRouteDialog(GNEAdditional* editedCalibratorRoute, bool updatingElement) :
56  GNEAdditionalDialog(editedCalibratorRoute, updatingElement, 400, 120),
57  myCalibratorRouteValid(true) {
58  // change default header
59  std::string typeOfOperation = + " for ";
60  changeAdditionalDialogHeader(myUpdatingElement ? "Edit " + myEditedAdditional->getTagStr() + " of " : "Create " + myEditedAdditional->getTagStr());
61 
62  // Create auxiliar frames for data
63  FXHorizontalFrame* columns = new FXHorizontalFrame(myContentFrame, GUIDesignUniformHorizontalFrame);
64  FXVerticalFrame* columnLeft = new FXVerticalFrame(columns, GUIDesignAuxiliarFrame);
65  FXVerticalFrame* columnRight = new FXVerticalFrame(columns, GUIDesignAuxiliarFrame);
66 
67  // create ID's elements
68  new FXLabel(columnLeft, toString(SUMO_ATTR_ID).c_str(), nullptr, GUIDesignLabelLeftThick);
69  myTextFieldRouteID = new FXTextField(columnRight, GUIDesignTextFieldNCol, this, MID_GNE_CALIBRATORDIALOG_SET_VARIABLE, GUIDesignTextField);
70 
71  // create list of edge's elements
72  new FXLabel(columnLeft, toString(SUMO_ATTR_EDGES).c_str(), nullptr, GUIDesignLabelLeftThick);
73  myTextFieldEdges = new FXTextField(columnRight, GUIDesignTextFieldNCol, this, MID_GNE_CALIBRATORDIALOG_SET_VARIABLE, GUIDesignTextField);
74 
75  // create color's elements
76  new FXLabel(columnLeft, toString(SUMO_ATTR_COLOR).c_str(), nullptr, GUIDesignLabelLeftThick);
77  myTextFieldColor = new FXTextField(columnRight, GUIDesignTextFieldNCol, this, MID_GNE_CALIBRATORDIALOG_SET_VARIABLE, GUIDesignTextField);
78 
79  // update tables
80  updateCalibratorRouteValues();
81 
82  // start a undo list for editing local to this additional
83  initChanges();
84 
85  // add element if we aren't updating an existent element
86  if (myUpdatingElement == false) {
87  myEditedAdditional->getViewNet()->getUndoList()->add(new GNEChange_Additional(myEditedAdditional, true), true);
88  // Routes are created without edges
89  myCalibratorRouteValid = false;
90  myInvalidAttr = SUMO_ATTR_EDGES;
91  }
92 
93  // open as modal dialog
94  openAsModalDialog();
95 }
96 
97 
99 
100 
101 long
102 GNECalibratorRouteDialog::onCmdAccept(FXObject*, FXSelector, void*) {
103  if (myCalibratorRouteValid == false) {
104  // write warning if netedit is running in testing mode
105  WRITE_DEBUG("Opening FXMessageBox of type 'warning'");
106  std::string operation1 = myUpdatingElement ? ("updating") : ("creating");
107  std::string operation2 = myUpdatingElement ? ("updated") : ("created");
108  std::string tagString = myEditedAdditional->getTagStr();
109  // open warning dialog box
110  FXMessageBox::warning(getApp(), MBOX_OK,
111  ("Error " + operation1 + " " + tagString).c_str(), "%s",
112  (tagString + " cannot be " + operation2 + " because parameter " + toString(myInvalidAttr) + " is invalid.").c_str());
113  // write warning if netedit is running in testing mode
114  WRITE_DEBUG("Closed FXMessageBox of type 'warning' with 'OK'");
115  return 0;
116  } else {
117  // accept changes before closing dialog
118  acceptChanges();
119  // stop dialgo sucesfully
120  getApp()->stopModal(this, TRUE);
121  return 1;
122  }
123 }
124 
125 
126 long
127 GNECalibratorRouteDialog::onCmdCancel(FXObject*, FXSelector, void*) {
128  // cancel changes
129  cancelChanges();
130  // Stop Modal
131  getApp()->stopModal(this, FALSE);
132  return 1;
133 }
134 
135 
136 long
137 GNECalibratorRouteDialog::onCmdReset(FXObject*, FXSelector, void*) {
138  // reset changes
139  resetChanges();
140  // update fields
142  return 1;
143 }
144 
145 
146 long
147 GNECalibratorRouteDialog::onCmdSetVariable(FXObject*, FXSelector, void*) {
148  // At start we assumed, that all values are valid
149  myCalibratorRouteValid = true;
151  // set color of myTextFieldRouteID, depending if current value is valid or not
152  if (myEditedAdditional->getID() == myTextFieldRouteID->getText().text()) {
153  myTextFieldRouteID->setTextColor(FXRGB(0, 0, 0));
155  } else if (myEditedAdditional->isValid(SUMO_ATTR_ID, myTextFieldRouteID->getText().text())) {
156  myTextFieldRouteID->setTextColor(FXRGB(0, 0, 0));
158  } else {
159  myTextFieldRouteID->setTextColor(FXRGB(255, 0, 0));
160  myCalibratorRouteValid = false;
162  }
163  // set color of myTextFieldRouteEdges, depending if current value is valEdges or not
164  if (myEditedAdditional->isValid(SUMO_ATTR_EDGES, myTextFieldEdges->getText().text())) {
165  myTextFieldEdges->setTextColor(FXRGB(0, 0, 0));
167  } else {
168  myTextFieldEdges->setTextColor(FXRGB(255, 0, 0));
169  myCalibratorRouteValid = false;
171  }
172  // set color of myTextFieldColor, depending if current value is valid or not
173  if (myEditedAdditional->isValid(SUMO_ATTR_COLOR, myTextFieldColor->getText().text())) {
174  myTextFieldColor->setTextColor(FXRGB(0, 0, 0));
176  } else {
177  myTextFieldColor->setTextColor(FXRGB(255, 0, 0));
178  myCalibratorRouteValid = false;
180  }
181  return 1;
182 }
183 
184 
185 void
187  myTextFieldRouteID->setText(myEditedAdditional->getID().c_str());
190 }
191 
192 /****************************************************************************/
virtual bool isValid(SumoXMLAttr key, const std::string &value)=0
method for checking if the key and their conrrespond attribute are valids
void resetChanges()
reset changes did in this dialog.
FXTextField * myTextFieldColor
color of route
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.
virtual void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)=0
method for setting the attribute and letting the object perform additional changes ...
virtual std::string getAttribute(SumoXMLAttr key) const =0
void updateCalibratorRouteValues()
update data fields
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:258
long onCmdReset(FXObject *, FXSelector, void *)
event after press reset button
#define GUIDesignTextField
Definition: GUIDesigns.h:34
the edges of a route
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:49
#define GUIDesignUniformHorizontalFrame
design for horizontal frame used to pack another frames with a uniform width
Definition: GUIDesigns.h:267
bool myUpdatingElement
flag to indicate if additional are being created or modified (cannot be changed after open dialog) ...
invalid attribute
const std::string getID() const
function to support debugging
#define WRITE_DEBUG(msg)
Definition: MsgHandler.h:248
GNEAdditional * myEditedAdditional
pointer to edited aditional
#define GUIDesignTextFieldNCol
Num of column of text field.
Definition: GUIDesigns.h:46
GNEViewNet * getViewNet() const
Returns a pointer to GNEViewNet in which additional element is located.
void acceptChanges()
Accept changes did in this dialog.
An Element which don&#39;t belongs to GNENet but has influency in the simulation.
Definition: GNEAdditional.h:48
Dialog for edit Calibrator Routes.
const std::string & getTagStr() const
get tag assigned to this object in string format
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:157