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