Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
GNERouteDialog.cpp
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3// Copyright (C) 2001-2024 German Aerospace Center (DLR) and others.
4// This program and the accompanying materials are made available under the
5// terms of the Eclipse Public License 2.0 which is available at
6// https://www.eclipse.org/legal/epl-2.0/
7// This Source Code may also be made available under the following Secondary
8// Licenses when the conditions for such availability set forth in the Eclipse
9// Public License 2.0 are satisfied: GNU General Public License, version 2
10// or later which is available at
11// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13/****************************************************************************/
18// Dialog for edit calibrator routes
19/****************************************************************************/
20
24#include <netedit/GNENet.h>
25#include <netedit/GNEViewNet.h>
26#include <netedit/GNEUndoList.h>
27
28#include "GNERouteDialog.h"
29
30
31// ===========================================================================
32// FOX callback mapping
33// ===========================================================================
34
35FXDEFMAP(GNERouteDialog) GNERouteDialogMap[] = {
37};
38
39// Object implementation
40FXIMPLEMENT(GNERouteDialog, GNEDemandElementDialog, GNERouteDialogMap, ARRAYNUMBER(GNERouteDialogMap))
41
42// ===========================================================================
43// member method definitions
44// ===========================================================================
45
46GNERouteDialog::GNERouteDialog(GNEDemandElement* editedCalibratorRoute, bool updatingElement) :
47 GNEDemandElementDialog(editedCalibratorRoute, updatingElement, 400, 120),
48 myCalibratorRouteValid(true) {
49 // change default header
50 std::string typeOfOperation = + " for ";
51 changeDemandElementDialogHeader(myUpdatingElement ? "Edit " + myEditedDemandElement->getTagStr() + " of " : "Create " + myEditedDemandElement->getTagStr());
52
53 // Create auxiliar frames for data
54 FXHorizontalFrame* columns = new FXHorizontalFrame(myContentFrame, GUIDesignUniformHorizontalFrame);
55 FXVerticalFrame* columnLeft = new FXVerticalFrame(columns, GUIDesignAuxiliarFrame);
56 FXVerticalFrame* columnRight = new FXVerticalFrame(columns, GUIDesignAuxiliarFrame);
57
58 // create ID's elements
59 new FXLabel(columnLeft, toString(SUMO_ATTR_ID).c_str(), nullptr, GUIDesignLabelThick(JUSTIFY_NORMAL));
60 myTextFieldRouteID = new FXTextField(columnRight, GUIDesignTextFieldNCol, this, MID_GNE_SET_ATTRIBUTE, GUIDesignTextField);
61
62 // create list of edge's elements
63 new FXLabel(columnLeft, toString(SUMO_ATTR_EDGES).c_str(), nullptr, GUIDesignLabelThick(JUSTIFY_NORMAL));
64 myTextFieldEdges = new FXTextField(columnRight, GUIDesignTextFieldNCol, this, MID_GNE_SET_ATTRIBUTE, GUIDesignTextField);
65
66 // create color's elements
67 new FXLabel(columnLeft, toString(SUMO_ATTR_COLOR).c_str(), nullptr, GUIDesignLabelThick(JUSTIFY_NORMAL));
68 myTextFieldColor = new FXTextField(columnRight, GUIDesignTextFieldNCol, this, MID_GNE_SET_ATTRIBUTE, GUIDesignTextField);
69
70 // update tables
71 updateCalibratorRouteValues();
72
73 // start a undo list for editing local to this demand element
74 initChanges();
75
76 // add element if we aren't updating an existent element
77 if (!myUpdatingElement) {
78 myEditedDemandElement->getNet()->getViewNet()->getUndoList()->add(new GNEChange_DemandElement(myEditedDemandElement, true), true);
79 // Routes are created without edges
80 myCalibratorRouteValid = false;
81 myInvalidAttr = SUMO_ATTR_EDGES;
82 }
83
84 // open as modal dialog
85 openAsModalDialog();
86}
87
88
90
91
92long
93GNERouteDialog::onCmdAccept(FXObject*, FXSelector, void*) {
95 // write warning if netedit is running in testing mode
96 WRITE_DEBUG("Opening FXMessageBox of type 'warning'");
97 std::string operation1 = myUpdatingElement ? ("updating") : ("creating");
98 std::string operation2 = myUpdatingElement ? ("updated") : ("created");
99 std::string tagString = myEditedDemandElement->getTagStr();
100 // open warning dialog box
101 FXMessageBox::warning(getApp(), MBOX_OK,
102 ("Error " + operation1 + " " + tagString).c_str(), "%s",
103 (tagString + " cannot be " + operation2 + " because parameter " + toString(myInvalidAttr) + " is invalid.").c_str());
104 // write warning if netedit is running in testing mode
105 WRITE_DEBUG("Closed FXMessageBox of type 'warning' with 'OK'");
106 return 0;
107 } else {
108 // accept changes before closing dialog
110 // stop dialog successfully
111 getApp()->stopModal(this, TRUE);
112 return 1;
113 }
114}
115
116
117long
118GNERouteDialog::onCmdCancel(FXObject*, FXSelector, void*) {
119 // cancel changes
121 // Stop Modal
122 getApp()->stopModal(this, FALSE);
123 return 1;
124}
125
126
127long
128GNERouteDialog::onCmdReset(FXObject*, FXSelector, void*) {
129 // reset changes
130 resetChanges();
131 // update fields
133 return 1;
134}
135
136
137long
138GNERouteDialog::onCmdSetVariable(FXObject*, FXSelector, void*) {
139 // At start we assumed, that all values are valid
142 // set color of myTextFieldRouteID, depending if current value is valid or not
143 if (myEditedDemandElement->getID() == myTextFieldRouteID->getText().text()) {
144 myTextFieldRouteID->setTextColor(FXRGB(0, 0, 0));
146 } else if (myEditedDemandElement->isValid(SUMO_ATTR_ID, myTextFieldRouteID->getText().text())) {
147 myTextFieldRouteID->setTextColor(FXRGB(0, 0, 0));
149 } else {
150 myTextFieldRouteID->setTextColor(FXRGB(255, 0, 0));
153 }
154 // set color of myTextFieldRouteEdges, depending if current value is valEdges or not
156 myTextFieldEdges->setTextColor(FXRGB(0, 0, 0));
158 } else {
159 myTextFieldEdges->setTextColor(FXRGB(255, 0, 0));
162 }
163 // set color of myTextFieldColor, depending if current value is valid or not
165 myTextFieldColor->setTextColor(FXRGB(0, 0, 0));
167 } else {
168 myTextFieldColor->setTextColor(FXRGB(255, 0, 0));
171 }
172 return 1;
173}
174
175
176void
182
183
184/****************************************************************************/
FXDEFMAP(GNERouteDialog) GNERouteDialogMap[]
@ MID_GNE_SET_ATTRIBUTE
attribute edited
Definition GUIAppEnum.h:939
#define GUIDesignTextField
Definition GUIDesigns.h:65
#define GUIDesignTextFieldNCol
Num of column of text field.
Definition GUIDesigns.h:80
#define GUIDesignUniformHorizontalFrame
design for horizontal frame used to pack another frames with a uniform width
Definition GUIDesigns.h:414
#define GUIDesignLabelThick(justify)
label extended over frame with thick and with text justify to left
Definition GUIDesigns.h:255
#define GUIDesignAuxiliarFrame
design for auxiliar (Without borders) frame extended in all directions
Definition GUIDesigns.h:396
#define WRITE_DEBUG(msg)
Definition MsgHandler.h:306
@ SUMO_ATTR_EDGES
the edges of a route
@ SUMO_ATTR_COLOR
A color information.
@ SUMO_ATTR_ID
@ SUMO_ATTR_NOTHING
invalid attribute, must be the last one
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition ToString.h:46
const std::string getID() const
get ID (all Attribute Carriers have one)
const std::string & getTagStr() const
get tag assigned to this object in string format
GNENet * getNet() const
get pointer to net
Dialog to edit sequences, parameters, etc.. of DemandElements.
void acceptChanges()
Accept changes did in this dialog.
GNEDemandElement * myEditedDemandElement
pointer to edited additional
bool myUpdatingElement
flag to indicate if additional are being created or modified (cannot be changed after open dialog)
void cancelChanges()
Cancel changes did in this dialog.
void resetChanges()
reset changes did in this dialog.
virtual std::string getAttribute(SumoXMLAttr key) const =0
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
virtual bool isValid(SumoXMLAttr key, const std::string &value)=0
method for checking if the key and their conrrespond attribute are valids
GNEViewNet * getViewNet() const
get view net
Definition GNENet.cpp:2155
Dialog for editing Calibrator Routes.
SumoXMLAttr myInvalidAttr
current sumo attribute invalid
FXTextField * myTextFieldRouteID
route ID
long onCmdReset(FXObject *, FXSelector, void *)
event after press reset button
long onCmdSetVariable(FXObject *, FXSelector, void *)
event after change value
bool myCalibratorRouteValid
flag to check if current calibrator vehicleType is valid
FXTextField * myTextFieldEdges
list of edges (string)
long onCmdAccept(FXObject *, FXSelector, void *)
FXTextField * myTextFieldColor
color of route
void updateCalibratorRouteValues()
update data fields
long onCmdCancel(FXObject *, FXSelector, void *)
event after press cancel button
~GNERouteDialog()
destructor
GNEUndoList * getUndoList() const
get the undoList object