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