Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/netedit/dialogs/GNEDialog.h
194340 views
1
/****************************************************************************/
2
// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3
// Copyright (C) 2006-2026 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
/****************************************************************************/
14
/// @file GNEDialog.h
15
/// @author Pablo Alvarez Lopez
16
/// @date Jul 2025
17
///
18
// Custom FXDialogBox used in Netedit that supports internal tests
19
/****************************************************************************/
20
#pragma once
21
#include <config.h>
22
23
#include <utils/gui/images/GUIIcons.h>
24
#include <utils/tests/InternalTestStep.h>
25
26
#include "GNEDialogEnum.h"
27
28
// ===========================================================================
29
// class declarations
30
// ===========================================================================
31
32
class GNEApplicationWindow;
33
34
// ===========================================================================
35
// class definitions
36
// ===========================================================================
37
38
class GNEDialog : protected FXDialogBox {
39
FXDECLARE_ABSTRACT(GNEDialog)
40
41
public:
42
/// @name basic dialog type
43
enum class Buttons {
44
OK, // ok button
45
YES_NO, // yes/no buttons
46
YES_NO_CANCEL, // yes/no/cancel buttons
47
ACCEPT, // accept button
48
ACCEPT_CANCEL, // accept/cancel buttons
49
ACCEPT_CANCEL_RESET, // accept/cancel/reset buttons
50
SAVE_DONTSAVE_CANCEL, // save/don't save/cancel buttons
51
RUN_CANCEL_RESET, // run/cancel/reset buttons (used in tools dialogs)
52
RUN_ADVANCED_CANCEL, // run/advanced/cancel buttons (used in tools dialogs)
53
RERUN_BACK_OK, // rerun-abort/back buttons (used in run dialogs)
54
OK_COPY_REPORT // ok, copy trace and report to github
55
};
56
57
/// @brief Open dialog type
58
enum class OpenType {
59
MODAL, // Modal dialog
60
NON_MODAL // Non-modal dialog
61
};
62
63
/// @name Resize mode
64
enum class ResizeMode {
65
STATIC, // dialog is static (size cannot be edited)
66
RESIZABLE // dialog is resizable (in both directions)
67
};
68
69
/// @brief list of possible results when closing the dialog
70
enum class Result {
71
ACCEPT, // dialog was closed accepting changes (used in ok, accept, yes buttons)
72
CANCEL, // dialog was closed canceling changes (used in cancel, no buttons)
73
ABORT, // dialog was closed aborting changes (used in abort button)
74
ACCEPT_ALL, // dialog was closed acepting all changes (used in ok, accept, yes buttons)
75
CANCEL_ALL, // dialog was closed canceling all changes (used in cancel, no buttons)
76
};
77
78
/// @brief basic constructor
79
GNEDialog(GNEApplicationWindow* applicationWindow,
80
const std::string& name, GUIIcon titleIcon, DialogType type, Buttons buttons,
81
OpenType openType, ResizeMode resizeMode);
82
83
/// @brief basic constructor with dialog parent
84
GNEDialog(GNEApplicationWindow* applicationWindow, GNEDialog* parentDialog,
85
const std::string& name, GUIIcon titleIcon, DialogType type, Buttons buttons,
86
OpenType openType, ResizeMode resizeMode);
87
88
/// @brief constructor with layout explicit
89
GNEDialog(GNEApplicationWindow* applicationWindow,
90
const std::string& name, GUIIcon titleIcon, DialogType type, Buttons buttons,
91
OpenType openType, ResizeMode resizeMode, const int width, const int height);
92
93
/// @brief constructor with layout explicit and dialog parent
94
GNEDialog(GNEApplicationWindow* applicationWindow, GNEDialog* parentDialog,
95
const std::string& name, GUIIcon titleIcon, DialogType type, Buttons buttons,
96
OpenType openType, ResizeMode resizeMode, const int width, const int height);
97
98
/// @brief get result to indicate if this dialog was closed accepting or rejecting changes
99
Result getResult() const;
100
101
/// @brief get pointer to the application window
102
GNEApplicationWindow* getApplicationWindow() const;
103
104
/// @brief get content frame
105
FXVerticalFrame* getContentFrame() const;
106
107
/// @brief run internal test
108
virtual void runInternalTest(const InternalTestStep::DialogArgument* dialogArgument) = 0;
109
110
/// @name FOX-callbacks
111
/// @{
112
113
/// @brief called when accept or yes button is pressed (can be reimplemented in children)
114
virtual long onCmdAccept(FXObject*, FXSelector, void*);
115
116
/// @brief called when cancel or no button is pressed (can be reimplemented in children)
117
virtual long onCmdCancel(FXObject*, FXSelector, void*);
118
119
/// @brief called when abort is called either closing dialog or pressing abort button (can be reimplemented in children)
120
virtual long onCmdAbort(FXObject*, FXSelector, void*);
121
122
/// @brief called when reset button is pressed (must be reimplemented in children depending of Buttons)
123
virtual long onCmdReset(FXObject*, FXSelector, void*);
124
125
/// @brief called when run button is pressed (must be reimplemented in children depending of Buttons)
126
virtual long onCmdRun(FXObject*, FXSelector, void*);
127
128
/// @brief called when back button is pressed (must be reimplemented in children depending of Buttons)
129
virtual long onCmdBack(FXObject*, FXSelector, void*);
130
131
/// @brief called when advanced button is pressed (must be reimplemented in children depending of Buttons)
132
virtual long onCmdAdvanced(FXObject*, FXSelector, void*);
133
134
/// @brief called when copy button is pressed (must be reimplemented in children depending of Buttons)
135
virtual long onCmdCopy(FXObject*, FXSelector, void*);
136
137
/// @brief called when report button is pressed (must be reimplemented in children depending of Buttons)
138
virtual long onCmdReport(FXObject*, FXSelector, void*);
139
140
/// @brief called when user presses a key on the dialog
141
long onKeyPress(FXObject* obj, FXSelector sel, void* ptr);
142
143
/// @brief called when user releases a key on the dialog
144
long onKeyRelease(FXObject* obj, FXSelector sel, void* ptr);
145
146
/// @}
147
148
protected:
149
/// @brief FOX needs this
150
FOX_CONSTRUCTOR(GNEDialog)
151
152
/// @brief pointer to the main window
153
GNEApplicationWindow* myApplicationWindow = nullptr;
154
155
/// @brief parent dialog used for restoring focus after closing dialog
156
GNEDialog* myParentDialog = nullptr;
157
158
/// @brief content frame
159
FXVerticalFrame* myContentFrame = nullptr;
160
161
/// @brief accept button
162
FXButton* myAcceptButton = nullptr;
163
164
/// @brief cancel button
165
FXButton* myCancelButton = nullptr;
166
167
/// @brief abort button
168
FXButton* myAbortButton = nullptr;
169
170
/// @brief reset button
171
FXButton* myResetButton = nullptr;
172
173
/// @brief run button
174
FXButton* myRunButton = nullptr;
175
176
/// @brief back button
177
FXButton* myBackButton = nullptr;
178
179
/// @brief advanced button
180
FXButton* myAdvancedButton = nullptr;
181
182
/// @brief copy button
183
FXButton* myCopyButton = nullptr;
184
185
/// @brief report button
186
FXButton* myReportButton = nullptr;
187
188
/// @brief dialog type
189
DialogType myType = DialogType::DEFAULT;
190
191
/// @brief result to indicate if this dialog was closed accepting or rejecting changes
192
Result myResult = Result::CANCEL;
193
194
/// @brief open dialog
195
void openDialog(FXWindow* focusableElement = nullptr);
196
197
/// @brief close dialog accepting the changes
198
long closeDialogAccepting();
199
200
/// @brief close dialog declining the changes
201
long closeDialogCanceling();
202
203
/// @brief close dialog aborting the changes
204
long closeDialogAborting();
205
206
/// @brief update title
207
void updateTitle(const std::string& newTitle);
208
209
/// @brief update icon
210
void updateIcon(GUIIcon newIcon);
211
212
private:
213
/// @brief focus button, used for focusing the default button when dialog is opened
214
FXButton* myFocusButton = nullptr;
215
216
/// @brief open type
217
OpenType myOpenType;
218
219
/// @brief flag to indicate if this dialog is being tested using internal test
220
bool myTesting = false;
221
222
/// @brief build dialog
223
void buildDialog(GUIIcon titleIcon, Buttons buttons);
224
225
/// @brief Invalidated copy constructor.
226
GNEDialog(const GNEDialog&) = delete;
227
228
/// @brief Invalidated assignment operator
229
GNEDialog& operator=(const GNEDialog& src) = delete;
230
};
231
232