Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/netedit/dialogs/GNEDialog.h
169678 views
1
/****************************************************************************/
2
// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3
// Copyright (C) 2006-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
/****************************************************************************/
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_CLOSE // rerun-abort/back buttons (used in run dialogs)
54
};
55
56
/// @brief Open dialog type
57
enum class OpenType {
58
MODAL, // Modal dialog
59
NON_MODAL // Non-modal dialog
60
};
61
62
/// @name Resize mode
63
enum class ResizeMode {
64
STATIC, // dialog is static (size cannot be edited)
65
RESIZABLE // dialog is resizable (in both directions)
66
};
67
68
/// @brief list of possible results when closing the dialog
69
enum class Result {
70
ACCEPT, // dialog was closed accepting changes (used in ok, accept, yes buttons)
71
CANCEL, // dialog was closed canceling changes (used in cancel, no buttons)
72
ABORT, // dialog was closed aborting changes (used in abort button)
73
};
74
75
/// @brief constructor for resizable dialogs
76
GNEDialog(GNEApplicationWindow* applicationWindow, const std::string& name,
77
GUIIcon titleIcon, DialogType type, Buttons buttons, OpenType openType,
78
ResizeMode resizeMode);
79
80
/// @brief constructor for resizable dialogs with layout explicit
81
GNEDialog(GNEApplicationWindow* applicationWindow, const std::string& name,
82
GUIIcon titleIcon, DialogType type, Buttons buttons, OpenType openType,
83
ResizeMode resizeMode, const int width, const int height);
84
85
/// @brief get result to indicate if this dialog was closed accepting or rejecting changes
86
Result getResult() const;
87
88
/// @brief get pointer to the application window
89
GNEApplicationWindow* getApplicationWindow() const;
90
91
/// @brief get content frame
92
FXVerticalFrame* getContentFrame() const;
93
94
/// @brief run internal test
95
virtual void runInternalTest(const InternalTestStep::DialogArgument* dialogArgument) = 0;
96
97
/// @name FOX-callbacks
98
/// @{
99
100
/// @brief called when accept or yes button is pressed (can be reimplemented in children)
101
virtual long onCmdAccept(FXObject*, FXSelector, void*);
102
103
/// @brief called when cancel or no button is pressed (can be reimplemented in children)
104
virtual long onCmdCancel(FXObject*, FXSelector, void*);
105
106
/// @brief called when abort is called either closing dialog or pressing abort button (can be reimplemented in children)
107
virtual long onCmdAbort(FXObject*, FXSelector, void*);
108
109
/// @brief called when reset button is pressed (must be reimplemented in children)
110
virtual long onCmdReset(FXObject*, FXSelector, void*);
111
112
/// @brief called when run button is pressed (must be reimplemented in children)
113
virtual long onCmdRun(FXObject*, FXSelector, void*);
114
115
/// @brief called when back button is pressed (must be reimplemented in children)
116
virtual long onCmdBack(FXObject*, FXSelector, void*);
117
118
/// @brief called when advanced button is pressed (must be reimplemented in children)
119
virtual long onCmdAdvanced(FXObject*, FXSelector, void*);
120
121
/// @brief called when user presses a key on the dialog
122
long onKeyPress(FXObject* obj, FXSelector sel, void* ptr);
123
124
/// @brief called when user releases a key on the dialog
125
long onKeyRelease(FXObject* obj, FXSelector sel, void* ptr);
126
127
/// @}
128
129
protected:
130
/// @brief FOX needs this
131
FOX_CONSTRUCTOR(GNEDialog)
132
133
/// @brief pointer to the main window
134
GNEApplicationWindow* myApplicationWindow = nullptr;
135
136
/// @brief content frame
137
FXVerticalFrame* myContentFrame = nullptr;
138
139
/// @brief accept button
140
FXButton* myAcceptButton = nullptr;
141
142
/// @brief cancel button
143
FXButton* myCancelButton = nullptr;
144
145
/// @brief abort button
146
FXButton* myAbortButton = nullptr;
147
148
/// @brief reset button
149
FXButton* myResetButton = nullptr;
150
151
/// @brief run button
152
FXButton* myRunButton = nullptr;
153
154
/// @brief back button
155
FXButton* myBackButton = nullptr;
156
157
/// @brief advanced button
158
FXButton* myAdvancedButton = nullptr;
159
160
/// @brief dialog type
161
DialogType myType = DialogType::DEFAULT;
162
163
/// @brief result to indicate if this dialog was closed accepting or rejecting changes
164
Result myResult = Result::CANCEL;
165
166
/// @brief open dialog
167
void openDialog(FXWindow* focusableElement = nullptr);
168
169
/// @brief close dialog accepting the changes
170
long closeDialogAccepting();
171
172
/// @brief close dialog declining the changes
173
long closeDialogCanceling();
174
175
/// @brief close dialog aborting the changes
176
long closeDialogAborting();
177
178
/// @brief update title
179
void updateTitle(const std::string& newTitle);
180
181
/// @brief update icon
182
void updateIcon(GUIIcon newIcon);
183
184
private:
185
/// @brief focus button, used for focusing the default button when dialog is opened
186
FXButton* myFocusButton = nullptr;
187
188
/// @brief open type
189
OpenType myOpenType;
190
191
/// @brief flag to indicate if this dialog is being tested using internal test
192
bool myTesting = false;
193
194
/// @brief build dialog
195
void buildDialog(GUIIcon titleIcon, Buttons buttons);
196
197
/// @brief Invalidated copy constructor.
198
GNEDialog(const GNEDialog&) = delete;
199
200
/// @brief Invalidated assignment operator
201
GNEDialog& operator=(const GNEDialog& src) = delete;
202
};
203
204