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 /****************************************************************************/
GNEDemandElementDialog::acceptChanges
void acceptChanges()
Accept changes did in this dialog.
Definition: GNEDemandElementDialog.cpp:125
GNEDemandElement
An Element which don't belongs to GNENet but has influency in the simulation.
Definition: GNEDemandElement.h:54
GUIDesignTextFieldNCol
#define GUIDesignTextFieldNCol
Num of column of text field.
Definition: GUIDesigns.h:58
GNEChange_DemandElement
Definition: GNEChange_DemandElement.h:46
GNEAttributeCarrier::getID
const std::string getID() const
function to support debugging
Definition: GNEAttributeCarrier.cpp:1187
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:295
SUMO_ATTR_COLOR
A color information.
Definition: SUMOXMLDefinitions.h:701
SUMO_ATTR_ID
Definition: SUMOXMLDefinitions.h:379
GNEDemandElement::getViewNet
GNEViewNet * getViewNet() const
Returns a pointer to GNEViewNet in which demand element element is located.
Definition: GNEDemandElement.cpp:408
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:34
GNEDemandElementDialog::cancelChanges
void cancelChanges()
Cancel changes did in this dialog.
Definition: GNEDemandElementDialog.cpp:136
GUIAppEnum.h
GNERoute.h
GNERouteDialog::onCmdAccept
long onCmdAccept(FXObject *, FXSelector, void *)
Definition: GNERouteDialog.cpp:95
GNEDemandElementDialog
Dialog to edit sequences, parameters, etc.. of DemandElements.
Definition: GNEDemandElementDialog.h:45
GNEDemandElement::getAttribute
virtual std::string getAttribute(SumoXMLAttr key) const =0
SUMO_ATTR_NOTHING
invalid attribute
Definition: SUMOXMLDefinitions.h:375
GNEViewNet.h
SUMO_ATTR_EDGES
the edges of a route
Definition: SUMOXMLDefinitions.h:428
GNERouteDialog::onCmdCancel
long onCmdCancel(FXObject *, FXSelector, void *)
event after press cancel button
Definition: GNERouteDialog.cpp:120
GNERouteDialog::myTextFieldRouteID
FXTextField * myTextFieldRouteID
route ID
Definition: GNERouteDialog.h:80
GNEViewNet::getUndoList
GNEUndoList * getUndoList() const
get the undoList object
Definition: GNEViewNet.cpp:933
GNERouteDialog::myTextFieldColor
FXTextField * myTextFieldColor
color of route
Definition: GNERouteDialog.h:86
GNERouteDialog::myInvalidAttr
SumoXMLAttr myInvalidAttr
current sumo attribute invalid
Definition: GNERouteDialog.h:77
GNEDemandElementDialog::myUpdatingElement
bool myUpdatingElement
flag to indicate if additional are being created or modified (cannot be changed after open dialog)
Definition: GNEDemandElementDialog.h:86
GNERouteDialog::onCmdReset
long onCmdReset(FXObject *, FXSelector, void *)
event after press reset button
Definition: GNERouteDialog.cpp:130
GNEDemandElementDialog::myEditedDemandElement
GNEDemandElement * myEditedDemandElement
pointer to edited aditional
Definition: GNEDemandElementDialog.h:83
GNERouteDialog::updateCalibratorRouteValues
void updateCalibratorRouteValues()
update data fields
Definition: GNERouteDialog.cpp:179
GNERouteDialog
Dialog for edit Calibrator Routes.
Definition: GNERouteDialog.h:43
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:91
toString
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:48
GNERouteDialog::onCmdSetVariable
long onCmdSetVariable(FXObject *, FXSelector, void *)
event after change value
Definition: GNERouteDialog.cpp:140
GUIDesignLabelLeftThick
#define GUIDesignLabelLeftThick
label extended over frame with thick and with text justify to left and height of 23
Definition: GUIDesigns.h:177
MID_GNE_CALIBRATORDIALOG_SET_VARIABLE
set new variable
Definition: GUIAppEnum.h:1013
GNEDemandElementDialog::resetChanges
void resetChanges()
reset changes did in this dialog.
Definition: GNEDemandElementDialog.cpp:142
GUIDesignAuxiliarFrame
#define GUIDesignAuxiliarFrame
design for auxiliar (Without borders) frames used to pack another frames extended in all directions
Definition: GUIDesigns.h:286
GNERouteDialog.h
config.h
GNERouteDialog::myTextFieldEdges
FXTextField * myTextFieldEdges
list of edges (string)
Definition: GNERouteDialog.h:83
GNEAttributeCarrier::getTagStr
const std::string & getTagStr() const
get tag assigned to this object in string format
Definition: GNEAttributeCarrier.cpp:1165
GNERouteDialog::myCalibratorRouteValid
bool myCalibratorRouteValid
flag to check if current calibrator vehicleType is valid
Definition: GNERouteDialog.h:74
WRITE_DEBUG
#define WRITE_DEBUG(msg)
Definition: MsgHandler.h:246
GNEUndoList.h