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-2025 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
22#include <netedit/GNENet.h>
23#include <netedit/GNEViewNet.h>
24#include <netedit/GNEUndoList.h>
27
28#include "GNERouteDialog.h"
29
30// ===========================================================================
31// FOX callback mapping
32// ===========================================================================
33
34FXDEFMAP(GNERouteDialog) GNERouteDialogMap[] = {
36};
37
38// Object implementation
39FXIMPLEMENT(GNERouteDialog, GNEDemandElementDialog, GNERouteDialogMap, ARRAYNUMBER(GNERouteDialogMap))
40
41// ===========================================================================
42// member method definitions
43// ===========================================================================
44
45GNERouteDialog::GNERouteDialog(GNEDemandElement* editedCalibratorRoute, bool updatingElement) :
46 GNEDemandElementDialog(editedCalibratorRoute, updatingElement, 400, 120),
47 myCalibratorRouteValid(true) {
48 // change default header
49 std::string typeOfOperation = + " for ";
50 changeDemandElementDialogHeader(myUpdatingElement ? "Edit " + myEditedDemandElement->getTagStr() + " of " : "Create " + myEditedDemandElement->getTagStr());
51
52 // Create auxiliar frames for data
53 FXHorizontalFrame* columns = new FXHorizontalFrame(myContentFrame, GUIDesignUniformHorizontalFrame);
54 FXVerticalFrame* columnLeft = new FXVerticalFrame(columns, GUIDesignAuxiliarFrame);
55 FXVerticalFrame* columnRight = new FXVerticalFrame(columns, GUIDesignAuxiliarFrame);
56
57 // create ID's elements
58 new FXLabel(columnLeft, toString(SUMO_ATTR_ID).c_str(), nullptr, GUIDesignLabelThick(JUSTIFY_NORMAL));
59 myTextFieldRouteID = new FXTextField(columnRight, GUIDesignTextFieldNCol, this, MID_GNE_SET_ATTRIBUTE, GUIDesignTextField);
60
61 // create list of edge's elements
62 new FXLabel(columnLeft, toString(SUMO_ATTR_EDGES).c_str(), nullptr, GUIDesignLabelThick(JUSTIFY_NORMAL));
63 myTextFieldEdges = new FXTextField(columnRight, GUIDesignTextFieldNCol, this, MID_GNE_SET_ATTRIBUTE, GUIDesignTextField);
64
65 // create color's elements
66 new FXLabel(columnLeft, toString(SUMO_ATTR_COLOR).c_str(), nullptr, GUIDesignLabelThick(JUSTIFY_NORMAL));
67 myTextFieldColor = new FXTextField(columnRight, GUIDesignTextFieldNCol, this, MID_GNE_SET_ATTRIBUTE, GUIDesignTextField);
68
69 // update tables
70 updateCalibratorRouteValues();
71
72 // start a undo list for editing local to this demand element
73 initChanges();
74
75 // add element if we aren't updating an existent element
76 if (!myUpdatingElement) {
77 myEditedDemandElement->getNet()->getViewNet()->getUndoList()->add(new GNEChange_DemandElement(myEditedDemandElement, true), true);
78 // Routes are created without edges
79 myCalibratorRouteValid = false;
80 myInvalidAttr = SUMO_ATTR_EDGES;
81 }
82
83 // open as modal dialog
84 openAsModalDialog();
85}
86
87
89
90
91long
92GNERouteDialog::onCmdAccept(FXObject*, FXSelector, void*) {
94 std::string operation1 = myUpdatingElement ? ("updating") : ("creating");
95 std::string operation2 = myUpdatingElement ? ("updated") : ("created");
96 std::string tagString = myEditedDemandElement->getTagStr();
97 // open warning dialog box
98 FXMessageBox::warning(getApp(), MBOX_OK,
99 ("Error " + operation1 + " " + tagString).c_str(), "%s",
100 (tagString + " cannot be " + operation2 + " because parameter " + toString(myInvalidAttr) + " is invalid.").c_str());
101 return 0;
102 } else {
103 // accept changes before closing dialog
105 // stop dialog successfully
106 getApp()->stopModal(this, TRUE);
107 return 1;
108 }
109}
110
111
112long
113GNERouteDialog::onCmdCancel(FXObject*, FXSelector, void*) {
114 // cancel changes
116 // Stop Modal
117 getApp()->stopModal(this, FALSE);
118 return 1;
119}
120
121
122long
123GNERouteDialog::onCmdReset(FXObject*, FXSelector, void*) {
124 // reset changes
125 resetChanges();
126 // update fields
128 return 1;
129}
130
131
132long
133GNERouteDialog::onCmdSetVariable(FXObject*, FXSelector, void*) {
134 // At start we assumed, that all values are valid
137 // set color of myTextFieldRouteID, depending if current value is valid or not
138 if (myEditedDemandElement->getID() == myTextFieldRouteID->getText().text()) {
139 myTextFieldRouteID->setTextColor(FXRGB(0, 0, 0));
141 } else if (myEditedDemandElement->isValid(SUMO_ATTR_ID, myTextFieldRouteID->getText().text())) {
142 myTextFieldRouteID->setTextColor(FXRGB(0, 0, 0));
144 } else {
145 myTextFieldRouteID->setTextColor(FXRGB(255, 0, 0));
148 }
149 // set color of myTextFieldRouteEdges, depending if current value is valEdges or not
151 myTextFieldEdges->setTextColor(FXRGB(0, 0, 0));
153 } else {
154 myTextFieldEdges->setTextColor(FXRGB(255, 0, 0));
157 }
158 // set color of myTextFieldColor, depending if current value is valid or not
160 myTextFieldColor->setTextColor(FXRGB(0, 0, 0));
162 } else {
163 myTextFieldColor->setTextColor(FXRGB(255, 0, 0));
166 }
167 return 1;
168}
169
170
171void
177
178
179/****************************************************************************/
FXDEFMAP(GNERouteDialog) GNERouteDialogMap[]
@ MID_GNE_SET_ATTRIBUTE
attribute edited
Definition GUIAppEnum.h:991
#define GUIDesignTextField
Definition GUIDesigns.h:59
#define GUIDesignTextFieldNCol
Num of column of text field.
Definition GUIDesigns.h:74
#define GUIDesignUniformHorizontalFrame
design for horizontal frame used to pack another frames with a uniform width
Definition GUIDesigns.h:411
#define GUIDesignLabelThick(justify)
label extended over frame with thick and with text justify to left
Definition GUIDesigns.h:249
#define GUIDesignAuxiliarFrame
design for auxiliar (Without borders) frame extended in all directions
Definition GUIDesigns.h:390
@ 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:2195
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