Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
GNEDialog.cpp
Go to the documentation of this file.
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/****************************************************************************/
18// Custom FXDialogBox used in Netedit that supports internal tests
19/****************************************************************************/
20
21#include <fxkeys.h>
25
26#include "GNEDialog.h"
27
28// ===========================================================================
29// FOX callback mapping
30// ===========================================================================
31
32FXDEFMAP(GNEDialog) MFXDialogBoxMap[] = {
33 // interaction
34 FXMAPFUNC(SEL_KEYPRESS, 0, GNEDialog::onKeyPress),
35 FXMAPFUNC(SEL_KEYRELEASE, 0, GNEDialog::onKeyRelease),
36 // buttons
37 FXMAPFUNC(SEL_COMMAND, MID_GNE_BUTTON_ACCEPT, GNEDialog::onCmdAccept),
38 FXMAPFUNC(SEL_COMMAND, MID_GNE_BUTTON_CANCEL, GNEDialog::onCmdCancel),
39 FXMAPFUNC(SEL_COMMAND, MID_GNE_BUTTON_RESET, GNEDialog::onCmdReset),
40 FXMAPFUNC(SEL_COMMAND, MID_GNE_BUTTON_RUN, GNEDialog::onCmdRun),
41 FXMAPFUNC(SEL_COMMAND, MID_GNE_BUTTON_BACK, GNEDialog::onCmdBack),
43 FXMAPFUNC(SEL_COMMAND, MID_GNE_BUTTON_COPY, GNEDialog::onCmdCopy),
44 FXMAPFUNC(SEL_COMMAND, MID_GNE_BUTTON_REPORT, GNEDialog::onCmdReport),
45 // abort dialog
46 FXMAPFUNC(SEL_CLOSE, 0, GNEDialog::onCmdAbort),
47 FXMAPFUNC(SEL_COMMAND, MID_HOTKEY_ESC, GNEDialog::onCmdAbort),
48 FXMAPFUNC(SEL_CHORE, MID_GNE_ABORT, GNEDialog::onCmdAbort),
49 FXMAPFUNC(SEL_TIMEOUT, MID_GNE_ABORT, GNEDialog::onCmdAbort),
50 FXMAPFUNC(SEL_COMMAND, MID_GNE_ABORT, GNEDialog::onCmdAbort),
51};
52
53// Object implementation
54FXIMPLEMENT_ABSTRACT(GNEDialog, FXDialogBox, MFXDialogBoxMap, ARRAYNUMBER(MFXDialogBoxMap))
55
56// ===========================================================================
57// method definitions
58// ===========================================================================
59
61 const std::string& name, GUIIcon titleIcon, DialogType type, Buttons buttons,
62 OpenType openType, ResizeMode resizeMode) :
63 FXDialogBox(applicationWindow->getApp(), name.c_str(),
65 0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
66 myApplicationWindow(applicationWindow),
67 myType(type),
68 myOpenType(openType) {
69 // build dialog only if applicationWindow was created
70 if (applicationWindow->id()) {
71 buildDialog(titleIcon, buttons);
72 }
73}
74
75
76GNEDialog::GNEDialog(GNEApplicationWindow* applicationWindow, GNEDialog* parentDialog,
77 const std::string& name, GUIIcon titleIcon, DialogType type, Buttons buttons,
78 OpenType openType, ResizeMode resizeMode) :
79 FXDialogBox(applicationWindow->getApp(), name.c_str(),
81 0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
82 myApplicationWindow(applicationWindow),
83 myParentDialog(parentDialog),
84 myType(type),
85 myOpenType(openType) {
86 // build dialog only if applicationWindow was created
87 if (applicationWindow->id()) {
88 buildDialog(titleIcon, buttons);
89 }
90}
91
92
93GNEDialog::GNEDialog(GNEApplicationWindow* applicationWindow, const std::string& name,
94 GUIIcon titleIcon, DialogType type, Buttons buttons, OpenType openType,
95 ResizeMode resizeMode, const int width, const int height) :
96 FXDialogBox(applicationWindow->getApp(), name.c_str(),
98 0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
99 myApplicationWindow(applicationWindow),
100 myType(type),
101 myOpenType(openType) {
102 // build dialog only if applicationWindow was created
103 if (applicationWindow->id()) {
104 // build dialog
105 buildDialog(titleIcon, buttons);
106 // set explicit size
107 resize(width, height);
108 }
109}
110
111
112GNEDialog::GNEDialog(GNEApplicationWindow* applicationWindow, GNEDialog* parentDialog,
113 const std::string& name, GUIIcon titleIcon, DialogType type, Buttons buttons,
114 OpenType openType, ResizeMode resizeMode, const int width, const int height) :
115 FXDialogBox(applicationWindow->getApp(), name.c_str(),
117 0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
118 myApplicationWindow(applicationWindow),
119 myParentDialog(parentDialog),
120 myType(type),
121 myOpenType(openType) {
122 // build dialog only if applicationWindow was created
123 if (applicationWindow->id()) {
124 // build dialog
125 buildDialog(titleIcon, buttons);
126 // set explicit size
127 resize(width, height);
128 }
129}
130
131
134 return myResult;
135}
136
137
142
143
144FXVerticalFrame*
148
149
150long
151GNEDialog::onCmdAccept(FXObject*, FXSelector, void*) {
152 return closeDialogAccepting();
153}
154
155
156long
157GNEDialog::onCmdCancel(FXObject*, FXSelector, void*) {
158 return closeDialogCanceling();
159}
160
161
162long
163GNEDialog::onCmdAbort(FXObject*, FXSelector, void*) {
164 return closeDialogAborting();
165}
166
167
168long
169GNEDialog::onCmdReset(FXObject*, FXSelector, void*) {
170 throw ProcessError("onCmdReset function must be reimplemented in GNEDialog children");
171}
172
173
174long
175GNEDialog::onCmdRun(FXObject*, FXSelector, void*) {
176 throw ProcessError("onCmdRun function must be reimplemented in GNEDialog children");
177}
178
179
180long
181GNEDialog::onCmdBack(FXObject*, FXSelector, void*) {
182 throw ProcessError("onCmdBack function must be reimplemented in GNEDialog children");
183}
184
185
186long
187GNEDialog::onCmdAdvanced(FXObject*, FXSelector, void*) {
188 throw ProcessError("onCmdAdvanced function must be reimplemented in GNEDialog children");
189}
190
191
192long
193GNEDialog::onCmdCopy(FXObject*, FXSelector, void*) {
194 throw ProcessError("onCmdyCopy function must be reimplemented in GNEDialog children");
195}
196
197
198long
199GNEDialog::onCmdReport(FXObject*, FXSelector, void*) {
200 throw ProcessError("onCmdyReport function must be reimplemented in GNEDialog children");
201}
202
203
204long
205GNEDialog::onKeyPress(FXObject* obj, FXSelector sel, void* ptr) {
206 if (myTesting && (obj != myApplicationWindow->getInternalTest())) {
207 return 1;
208 } else {
209 // if ESC key is pressed, close dialog aborting
210 FXEvent* event = (FXEvent*)ptr;
211 if (event->code == KEY_Escape) {
212 return closeDialogAborting();
213 } else if (event->code == KEY_Return) {
214 if (myAcceptButton->hasFocus()) {
215 return closeDialogAccepting();
216 } else if (myCancelButton->hasFocus()) {
217 return closeDialogCanceling();
218 } else if (myAbortButton && myAbortButton->hasFocus()) {
219 return closeDialogAborting();
220 }
221 }
222 return FXDialogBox::onKeyPress(obj, sel, ptr);
223 }
224}
225
226
227long
228GNEDialog::onKeyRelease(FXObject* obj, FXSelector sel, void* ptr) {
229 if (myTesting && (obj != myApplicationWindow->getInternalTest())) {
230 return 1;
231 } else {
232 return FXDialogBox::onKeyRelease(obj, sel, ptr);
233 }
234}
235
236
237void
238GNEDialog::openDialog(FXWindow* focusableElement) {
239 // create dialog
240 create();
241 // check if set focus in button
242 if (focusableElement) {
243 focusableElement->setFocus();
244 } else {
245 myFocusButton->setFocus();
246 }
247 // show in the center of app
248 show(PLACEMENT_OWNER);
249 // continue depending on whether we are testing or not
250 const auto internalTest = myApplicationWindow->getInternalTest();
251 if (internalTest) {
252 myTesting = true;
253 bool closeDialog = false;
254 // execute every dialog step
255 while (internalTest->getCurrentStep() && !closeDialog &&
256 (internalTest->getCurrentStep()->getCategory() == InternalTestStep::Category::DIALOG) &&
257 (internalTest->getCurrentStep()->getDialogArgument()->getType() == myType)) {
258 // set next step
259 const auto testStep = internalTest->setNextStep();
260 // continue depending on the dialog argument action
261 switch (testStep->getDialogArgument()->getAction()) {
263 onCmdAccept(internalTest, 0, nullptr);
264 closeDialog = true;
265 break;
267 onCmdCancel(internalTest, 0, nullptr);
268 closeDialog = true;
269 break;
271 onCmdReset(internalTest, 0, nullptr);
272 break;
274 onCmdAbort(nullptr, 0, nullptr);
275 break;
276 default:
277 runInternalTest(testStep->getDialogArgument());
278 break;
279 }
280 }
281 } else {
282 myTesting = false;
283 // continue depending on the dialog type
285 // run modal dialog
286 getApp()->runModalFor(this);
287 }
288 }
289}
290
291
292long
294 // check if stopping modal dialog
295 if (!myTesting && (myOpenType == OpenType::MODAL)) {
296 getApp()->stopModal(this, TRUE);
297 }
298 // hide dialog
299 hide();
300 // set result
302 // restore focus
303 if (myParentDialog) {
304 myParentDialog->setFocus();
305 } else {
306 myApplicationWindow->setFocus();
307 }
308 return 1;
309}
310
311
312long
314 // check if stopping modal dialog
315 if (!myTesting && (myOpenType == OpenType::MODAL)) {
316 getApp()->stopModal(this, TRUE);
317 }
318 // hide dialog
319 hide();
320 // set result
322 // restore focus
323 if (myParentDialog) {
324 myParentDialog->setFocus();
325 } else {
326 myApplicationWindow->setFocus();
327 }
328 return 0;
329}
330
331
332long
334 // check if stopping modal dialog
335 if (!myTesting && (myOpenType == OpenType::MODAL)) {
336 getApp()->stopModal(this, TRUE);
337 }
338 // hide dialog
339 hide();
340 // set result
342 // restore focus
343 if (myParentDialog) {
344 myParentDialog->setFocus();
345 } else {
346 myApplicationWindow->setFocus();
347 }
348 return 0;
349}
350
351
352void
353GNEDialog::updateTitle(const std::string& newTitle) {
354 setTitle(newTitle.c_str());
355}
356
357
358void
360 setIcon(GUIIconSubSys::getIcon(newIcon));
361}
362
363
364void
366 // set dialog icon
367 setIcon(GUIIconSubSys::getIcon(titleIcon));
368 // create main frame
369 auto mainFrame = new FXVerticalFrame(this, GUIDesignAuxiliarFrame);
370 // create content frame
371 myContentFrame = new FXVerticalFrame(mainFrame, GUIDesignDialogContentFrame);
372 // add separator
373 new FXHorizontalSeparator(mainFrame, GUIDesignHorizontalSeparator);
374 // Create frame for buttons
375 FXHorizontalFrame* buttonsFrame = new FXHorizontalFrame(mainFrame, GUIDesignDialogButtonsHorizontalFrame);
376 // add horizontal frame used to center buttons horizontally
377 new FXHorizontalFrame(buttonsFrame, GUIDesignAuxiliarHorizontalFrame);
378 // create buttons according to the type
379 switch (buttons) {
380 case Buttons::OK: {
381 // ok button
382 myAcceptButton = GUIDesigns::buildFXButton(buttonsFrame, TL("OK"), "", TL("OK"),
385 // set focus button
387 break;
388 }
389 case Buttons::YES_NO: {
390 // yes button
391 myAcceptButton = GUIDesigns::buildFXButton(buttonsFrame, TL("Yes"), "", TL("Yes"),
394 // no button
395 myCancelButton = GUIDesigns::buildFXButton(buttonsFrame, TL("No"), "", TL("No"),
398 // set focus button
400 break;
401 }
403 // yes button
404 myAcceptButton = GUIDesigns::buildFXButton(buttonsFrame, TL("Yes"), "", TL("Yes"),
407 // no button
408 myCancelButton = GUIDesigns::buildFXButton(buttonsFrame, TL("No"), "", TL("No"),
411 // cancel button
412 myAbortButton = GUIDesigns::buildFXButton(buttonsFrame, TL("Cancel"), "", TL("Cancel"),
415 // set focus button
417 break;
418 }
420 // save button
421 myAcceptButton = GUIDesigns::buildFXButton(buttonsFrame, TL("Save"), "", TL("Save"),
424 // don't save button
425 myCancelButton = GUIDesigns::buildFXButton(buttonsFrame, TL("Don't Save"), "", TL("Don't Save"),
428 // cancel button
429 myAbortButton = GUIDesigns::buildFXButton(buttonsFrame, TL("Cancel"), "", TL("Cancel"),
432 // set focus button
434 break;
435 }
436 case Buttons::ACCEPT: {
437 // accept button
438 myAcceptButton = GUIDesigns::buildFXButton(buttonsFrame, TL("Accept"), "", TL("Accept"),
441 // set focus button
443 break;
444 }
446 // accept button
447 myAcceptButton = GUIDesigns::buildFXButton(buttonsFrame, TL("Accept"), "", TL("Accept"),
450 // cancel button
451 myCancelButton = GUIDesigns::buildFXButton(buttonsFrame, TL("Cancel"), "", TL("Cancel"),
454 // set focus button
456 break;
457 }
459 // accept button
460 myAcceptButton = GUIDesigns::buildFXButton(buttonsFrame, TL("Accept"), "", TL("Accept"),
463 // cancel button
464 myCancelButton = GUIDesigns::buildFXButton(buttonsFrame, TL("Cancel"), "", TL("Cancel"),
467 // reset button
468 myResetButton = GUIDesigns::buildFXButton(buttonsFrame, TL("Reset"), "", TL("Reset changes"),
471 // set focus button
473 break;
474 }
476 // run button
477 myRunButton = GUIDesigns::buildFXButton(buttonsFrame, TL("Run"), "", TL("Run"),
480 // reset button
481 myCancelButton = GUIDesigns::buildFXButton(buttonsFrame, TL("Cancel"), "", TL("Cancel"),
484 // reset button
485 myResetButton = GUIDesigns::buildFXButton(buttonsFrame, TL("Reset"), "", TL("Reset changes"),
488 // set focus button
490 break;
491 }
493 // run button
494 myRunButton = GUIDesigns::buildFXButton(buttonsFrame, TL("Run"), "", TL("Run"),
497 // cancel button
498 myAdvancedButton = GUIDesigns::buildFXButton(buttonsFrame, TL("Advanced"), "", TL("Advanced options"),
501 // cancel button
502 myCancelButton = GUIDesigns::buildFXButton(buttonsFrame, TL("Cancel"), "", TL("Cancel"),
505 // set focus button
507 break;
508 }
510 // run/abort button
511 myRunButton = GUIDesigns::buildFXButton(buttonsFrame, TL("Rerun"), "", TL("Rerun tool"),
514 // back button
515 myBackButton = GUIDesigns::buildFXButton(buttonsFrame, TL("Back"), "", TL("Back to tool dialog"),
518 // cancel button
519 myAcceptButton = GUIDesigns::buildFXButton(buttonsFrame, TL("OK"), "", TL("OK"),
522 // set focus button
524 break;
525 }
527 // run/abort button
528 myAcceptButton = GUIDesigns::buildFXButton(buttonsFrame, TL("OK"), "", TL("OK"),
531 // copy button
532 myCopyButton = GUIDesigns::buildFXButton(buttonsFrame, TL("Copy"), "", TL("Copy error trace to clipboard"),
535 // cancel button
536 myReportButton = GUIDesigns::buildFXButton(buttonsFrame, TL("Report"), "", TL("Report bug to github"),
539 // set focus button
541 break;
542 }
543 default:
544 throw ProcessError("Invalid buttons combination in GNEDialog");
545 }
546 // add horizontal frame used to center buttons horizontally
547 new FXHorizontalFrame(buttonsFrame, GUIDesignAuxiliarHorizontalFrame);
548}
FXDEFMAP(GNEDialog) MFXDialogBoxMap[]
DialogType
@ MID_GNE_BUTTON_COPY
copy
@ MID_GNE_BUTTON_REPORT
report
@ MID_GNE_BUTTON_RUN
run button
@ MID_GNE_BUTTON_CANCEL
cancel button
@ MID_GNE_BUTTON_RESET
reset button
@ MID_HOTKEY_ESC
hot key <ESC> abort current edit operation
Definition GUIAppEnum.h:286
@ MID_GNE_BUTTON_ADVANCED
advanced button
@ MID_GNE_BUTTON_BACK
back button
@ MID_GNE_BUTTON_ACCEPT
accept button
@ MID_GNE_ABORT
abort lane path creation
#define GUIDesignGNEDialogResizable
design for GNEDialogs resizable
Definition GUIDesigns.h:327
#define GUIDesignDialogContentFrame
design for content frame used in dialog
Definition GUIDesigns.h:418
#define GUIDesignGNEDialogStaticExplicit
design for GNEDialogs explicit
Definition GUIDesigns.h:324
#define GUIDesignAuxiliarHorizontalFrame
design for auxiliar (Without borders) horizontal frame used to pack another frames
Definition GUIDesigns.h:430
#define GUIDesignGNEDialogStatic
Definition GUIDesigns.h:321
#define GUIDesignDialogButtonsHorizontalFrame
design for content frame used in dialog
Definition GUIDesigns.h:427
#define GUIDesignHorizontalSeparator
Definition GUIDesigns.h:494
#define GUIDesignAuxiliarFrame
design for auxiliar (Without borders) frame extended in all directions
Definition GUIDesigns.h:409
#define GUIDesignButtonDialog
Definition GUIDesigns.h:174
#define GUIDesignGNEDialogResizableExplicit
design for GNEDialogs resizable with explicit layout
Definition GUIDesigns.h:330
GUIIcon
An enumeration of icons used by the gui applications.
Definition GUIIcons.h:33
@ SAVE
save icons
#define TL(string)
Definition MsgHandler.h:304
GNEInternalTest * getInternalTest() const
get netedit test system
virtual long onCmdRun(FXObject *, FXSelector, void *)
called when run button is pressed (must be reimplemented in children depending of Buttons)
void buildDialog(GUIIcon titleIcon, Buttons buttons)
build dialog
FXButton * myFocusButton
focus button, used for focusing the default button when dialog is opened
Definition GNEDialog.h:214
virtual void runInternalTest(const InternalTestStep::DialogArgument *dialogArgument)=0
run internal test
OpenType myOpenType
open type
Definition GNEDialog.h:217
bool myTesting
flag to indicate if this dialog is being tested using internal test
Definition GNEDialog.h:220
FXButton * myCopyButton
copy button
Definition GNEDialog.h:183
virtual long onCmdBack(FXObject *, FXSelector, void *)
called when back button is pressed (must be reimplemented in children depending of Buttons)
FXVerticalFrame * myContentFrame
content frame
Definition GNEDialog.h:159
FXButton * myAbortButton
abort button
Definition GNEDialog.h:168
long closeDialogAborting()
close dialog aborting the changes
FXButton * myCancelButton
cancel button
Definition GNEDialog.h:165
FXVerticalFrame * getContentFrame() const
get content frame
GNEApplicationWindow * getApplicationWindow() const
get pointer to the application window
Result getResult() const
get result to indicate if this dialog was closed accepting or rejecting changes
FXButton * myAdvancedButton
advanced button
Definition GNEDialog.h:180
GNEApplicationWindow * myApplicationWindow
FOX needs this.
Definition GNEDialog.h:153
FXButton * myResetButton
reset button
Definition GNEDialog.h:171
void updateIcon(GUIIcon newIcon)
update icon
long onKeyRelease(FXObject *obj, FXSelector sel, void *ptr)
called when user releases a key on the dialog
void openDialog(FXWindow *focusableElement=nullptr)
open dialog
Result
list of possible results when closing the dialog
Definition GNEDialog.h:70
FXButton * myAcceptButton
accept button
Definition GNEDialog.h:162
Result myResult
result to indicate if this dialog was closed accepting or rejecting changes
Definition GNEDialog.h:192
long closeDialogAccepting()
close dialog accepting the changes
GNEDialog * myParentDialog
parent dialog used for restoring focus after closing dialog
Definition GNEDialog.h:156
virtual long onCmdAdvanced(FXObject *, FXSelector, void *)
called when advanced button is pressed (must be reimplemented in children depending of Buttons)
OpenType
Open dialog type.
Definition GNEDialog.h:58
DialogType myType
dialog type
Definition GNEDialog.h:189
virtual long onCmdAbort(FXObject *, FXSelector, void *)
called when abort is called either closing dialog or pressing abort button (can be reimplemented in c...
FXButton * myReportButton
report button
Definition GNEDialog.h:186
GNEDialog(GNEApplicationWindow *applicationWindow, const std::string &name, GUIIcon titleIcon, DialogType type, Buttons buttons, OpenType openType, ResizeMode resizeMode)
basic constructor
Definition GNEDialog.cpp:60
FXButton * myBackButton
back button
Definition GNEDialog.h:177
long onKeyPress(FXObject *obj, FXSelector sel, void *ptr)
called when user presses a key on the dialog
FXButton * myRunButton
run button
Definition GNEDialog.h:174
virtual long onCmdReport(FXObject *, FXSelector, void *)
called when report button is pressed (must be reimplemented in children depending of Buttons)
virtual long onCmdCopy(FXObject *, FXSelector, void *)
called when copy button is pressed (must be reimplemented in children depending of Buttons)
virtual long onCmdAccept(FXObject *, FXSelector, void *)
called when accept or yes button is pressed (can be reimplemented in children)
long closeDialogCanceling()
close dialog declining the changes
virtual long onCmdCancel(FXObject *, FXSelector, void *)
called when cancel or no button is pressed (can be reimplemented in children)
void updateTitle(const std::string &newTitle)
update title
virtual long onCmdReset(FXObject *, FXSelector, void *)
called when reset button is pressed (must be reimplemented in children depending of Buttons)
static FXButton * buildFXButton(FXComposite *p, const std::string &text, const std::string &tip, const std::string &help, FXIcon *ic, FXObject *tgt, FXSelector sel, FXuint opts=BUTTON_NORMAL, FXint x=0, FXint y=0, FXint w=0, FXint h=0, FXint pl=DEFAULT_PAD, FXint pr=DEFAULT_PAD, FXint pt=DEFAULT_PAD, FXint pb=DEFAULT_PAD)
build button
static FXIcon * getIcon(const GUIIcon which)
returns a icon previously defined in the enum GUIIcon
InternalTestStep * setNextStep()
get current step and set next step
Definition json.hpp:4471