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
60GNEDialog::GNEDialog(GNEApplicationWindow* applicationWindow, const std::string& name,
61 GUIIcon titleIcon, DialogType type, Buttons buttons, OpenType openType,
62 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, const std::string& name,
77 GUIIcon titleIcon, DialogType type, Buttons buttons, OpenType openType,
78 ResizeMode resizeMode, const int width, const int height) :
79 FXDialogBox(applicationWindow->getApp(), name.c_str(),
81 0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
82 myApplicationWindow(applicationWindow),
83 myType(type),
84 myOpenType(openType) {
85 // build dialog only if applicationWindow was created
86 if (applicationWindow->id()) {
87 // build dialog
88 buildDialog(titleIcon, buttons);
89 // set explicit size
90 resize(width, height);
91 }
92}
93
94
97 return myResult;
98}
99
100
105
106
107FXVerticalFrame*
111
112
113void
115 myRestoringFocusWindow = window;
116}
117
118
119long
120GNEDialog::onCmdAccept(FXObject*, FXSelector, void*) {
121 return closeDialogAccepting();
122}
123
124
125long
126GNEDialog::onCmdCancel(FXObject*, FXSelector, void*) {
127 return closeDialogCanceling();
128}
129
130
131long
132GNEDialog::onCmdAbort(FXObject*, FXSelector, void*) {
133 return closeDialogAborting();
134}
135
136
137long
138GNEDialog::onCmdReset(FXObject*, FXSelector, void*) {
139 throw ProcessError("onCmdReset function must be reimplemented in GNEDialog children");
140}
141
142
143long
144GNEDialog::onCmdRun(FXObject*, FXSelector, void*) {
145 throw ProcessError("onCmdRun function must be reimplemented in GNEDialog children");
146}
147
148
149long
150GNEDialog::onCmdBack(FXObject*, FXSelector, void*) {
151 throw ProcessError("onCmdBack function must be reimplemented in GNEDialog children");
152}
153
154
155long
156GNEDialog::onCmdAdvanced(FXObject*, FXSelector, void*) {
157 throw ProcessError("onCmdAdvanced function must be reimplemented in GNEDialog children");
158}
159
160
161long
162GNEDialog::onCmdCopy(FXObject*, FXSelector, void*) {
163 throw ProcessError("onCmdyCopy function must be reimplemented in GNEDialog children");
164}
165
166
167long
168GNEDialog::onCmdReport(FXObject*, FXSelector, void*) {
169 throw ProcessError("onCmdyReport function must be reimplemented in GNEDialog children");
170}
171
172
173long
174GNEDialog::onKeyPress(FXObject* obj, FXSelector sel, void* ptr) {
175 if (myTesting && (obj != myApplicationWindow->getInternalTest())) {
176 return 1;
177 } else {
178 // if ESC key is pressed, close dialog aborting
179 FXEvent* event = (FXEvent*)ptr;
180 if (event->code == KEY_Escape) {
181 return closeDialogAborting();
182 } else {
183 return FXDialogBox::onKeyPress(obj, sel, ptr);
184 }
185 }
186}
187
188
189long
190GNEDialog::onKeyRelease(FXObject* obj, FXSelector sel, void* ptr) {
191 if (myTesting && (obj != myApplicationWindow->getInternalTest())) {
192 return 1;
193 } else {
194 return FXDialogBox::onKeyRelease(obj, sel, ptr);
195 }
196}
197
198
199void
200GNEDialog::openDialog(FXWindow* focusableElement) {
201 // create dialog
202 create();
203 // check if set focus in button
204 if (focusableElement) {
205 focusableElement->setFocus();
206 } else {
207 myFocusButton->setFocus();
208 }
209 // show in the center of app
210 show(PLACEMENT_OWNER);
211 // continue depending on whether we are testing or not
212 const auto internalTest = myApplicationWindow->getInternalTest();
213 if (internalTest) {
214 myTesting = true;
215 bool closeDialog = false;
216 // execute every dialog step
217 while (internalTest->getCurrentStep() && !closeDialog &&
218 (internalTest->getCurrentStep()->getCategory() == InternalTestStep::Category::DIALOG) &&
219 (internalTest->getCurrentStep()->getDialogArgument()->getType() == myType)) {
220 // set next step
221 const auto testStep = internalTest->setNextStep();
222 // continue depending on the dialog argument action
223 switch (testStep->getDialogArgument()->getAction()) {
225 onCmdAccept(internalTest, 0, nullptr);
226 closeDialog = true;
227 break;
229 onCmdCancel(internalTest, 0, nullptr);
230 closeDialog = true;
231 break;
233 onCmdReset(internalTest, 0, nullptr);
234 break;
236 onCmdAbort(nullptr, 0, nullptr);
237 break;
238 default:
239 runInternalTest(testStep->getDialogArgument());
240 break;
241 }
242 }
243 } else {
244 myTesting = false;
245 // continue depending on the dialog type
247 // run modal dialog
248 getApp()->runModalFor(this);
249 }
250 }
251}
252
253
254long
256 // check if stopping modal dialog
257 if (!myTesting && (myOpenType == OpenType::MODAL)) {
258 getApp()->stopModal(this, TRUE);
259 }
260 // hide dialog
261 hide();
262 // set result
264 // restore focus
266 myRestoringFocusWindow->setFocus();
267 } else {
268 myApplicationWindow->setFocus();
269 }
270 return 1;
271}
272
273
274long
276 // check if stopping modal dialog
277 if (!myTesting && (myOpenType == OpenType::MODAL)) {
278 getApp()->stopModal(this, TRUE);
279 }
280 // hide dialog
281 hide();
282 // set result
284 // restore focus
286 myRestoringFocusWindow->setFocus();
287 } else {
288 myApplicationWindow->setFocus();
289 }
290 return 0;
291}
292
293
294long
296 // check if stopping modal dialog
297 if (!myTesting && (myOpenType == OpenType::MODAL)) {
298 getApp()->stopModal(this, TRUE);
299 }
300 // hide dialog
301 hide();
302 // set result
304 // restore focus
306 myRestoringFocusWindow->setFocus();
307 } else {
308 myApplicationWindow->setFocus();
309 }
310 return 0;
311}
312
313
314void
315GNEDialog::updateTitle(const std::string& newTitle) {
316 setTitle(newTitle.c_str());
317}
318
319
320void
322 setIcon(GUIIconSubSys::getIcon(newIcon));
323}
324
325
326void
328 // set dialog icon
329 setIcon(GUIIconSubSys::getIcon(titleIcon));
330 // create main frame
331 auto mainFrame = new FXVerticalFrame(this, GUIDesignAuxiliarFrame);
332 // create content frame
333 myContentFrame = new FXVerticalFrame(mainFrame, GUIDesignDialogContentFrame);
334 // add separator
335 new FXHorizontalSeparator(mainFrame, GUIDesignHorizontalSeparator);
336 // Create frame for buttons
337 FXHorizontalFrame* buttonsFrame = new FXHorizontalFrame(mainFrame, GUIDesignDialogButtonsHorizontalFrame);
338 // add horizontal frame used to center buttons horizontally
339 new FXHorizontalFrame(buttonsFrame, GUIDesignAuxiliarHorizontalFrame);
340 // create buttons according to the type
341 switch (buttons) {
342 case Buttons::OK: {
343 // ok button
344 myAcceptButton = GUIDesigns::buildFXButton(buttonsFrame, TL("OK"), "", TL("OK"),
347 // set focus button
349 break;
350 }
351 case Buttons::YES_NO: {
352 // yes button
353 myAcceptButton = GUIDesigns::buildFXButton(buttonsFrame, TL("Yes"), "", TL("Yes"),
356 // no button
357 myCancelButton = GUIDesigns::buildFXButton(buttonsFrame, TL("No"), "", TL("No"),
360 // set focus button
362 break;
363 }
365 // yes button
366 myAcceptButton = GUIDesigns::buildFXButton(buttonsFrame, TL("Yes"), "", TL("Yes"),
369 // no button
370 myCancelButton = GUIDesigns::buildFXButton(buttonsFrame, TL("No"), "", TL("No"),
373 // cancel button
374 myAbortButton = GUIDesigns::buildFXButton(buttonsFrame, TL("Cancel"), "", TL("Cancel"),
377 // set focus button
379 break;
380 }
382 // save button
383 myAcceptButton = GUIDesigns::buildFXButton(buttonsFrame, TL("Save"), "", TL("Save"),
386 // don't save button
387 myCancelButton = GUIDesigns::buildFXButton(buttonsFrame, TL("Don't Save"), "", TL("Don't Save"),
390 // cancel button
391 myAbortButton = GUIDesigns::buildFXButton(buttonsFrame, TL("Cancel"), "", TL("Cancel"),
394 // set focus button
396 break;
397 }
398 case Buttons::ACCEPT: {
399 // accept button
400 myAcceptButton = GUIDesigns::buildFXButton(buttonsFrame, TL("Accept"), "", TL("Accept"),
403 // set focus button
405 break;
406 }
408 // accept button
409 myAcceptButton = GUIDesigns::buildFXButton(buttonsFrame, TL("Accept"), "", TL("Accept"),
412 // cancel button
413 myCancelButton = GUIDesigns::buildFXButton(buttonsFrame, TL("Cancel"), "", TL("Cancel"),
416 // set focus button
418 break;
419 }
421 // accept button
422 myAcceptButton = GUIDesigns::buildFXButton(buttonsFrame, TL("Accept"), "", TL("Accept"),
425 // cancel button
426 myCancelButton = GUIDesigns::buildFXButton(buttonsFrame, TL("Cancel"), "", TL("Cancel"),
429 // reset button
430 myResetButton = GUIDesigns::buildFXButton(buttonsFrame, TL("Reset"), "", TL("Reset changes"),
433 // set focus button
435 break;
436 }
438 // run button
439 myRunButton = GUIDesigns::buildFXButton(buttonsFrame, TL("Run"), "", TL("Run"),
442 // reset button
443 myCancelButton = GUIDesigns::buildFXButton(buttonsFrame, TL("Cancel"), "", TL("Cancel"),
446 // reset button
447 myResetButton = GUIDesigns::buildFXButton(buttonsFrame, TL("Reset"), "", TL("Reset changes"),
450 // set focus button
452 break;
453 }
455 // run button
456 myRunButton = GUIDesigns::buildFXButton(buttonsFrame, TL("Run"), "", TL("Run"),
459 // cancel button
460 myAdvancedButton = GUIDesigns::buildFXButton(buttonsFrame, TL("Advanced"), "", TL("Advanced options"),
463 // cancel button
464 myCancelButton = GUIDesigns::buildFXButton(buttonsFrame, TL("Cancel"), "", TL("Cancel"),
467 // set focus button
469 break;
470 }
472 // run/abort button
473 myRunButton = GUIDesigns::buildFXButton(buttonsFrame, TL("Rerun"), "", TL("Rerun tool"),
476 // back button
477 myBackButton = GUIDesigns::buildFXButton(buttonsFrame, TL("Back"), "", TL("Back to tool dialog"),
480 // cancel button
481 myAcceptButton = GUIDesigns::buildFXButton(buttonsFrame, TL("OK"), "", TL("OK"),
484 // set focus button
486 break;
487 }
489 // run/abort button
490 myAcceptButton = GUIDesigns::buildFXButton(buttonsFrame, TL("OK"), "", TL("OK"),
493 // copy button
494 myCopyButton = GUIDesigns::buildFXButton(buttonsFrame, TL("Copy"), "", TL("Copy error trace to clipboard"),
497 // cancel button
498 myReportButton = GUIDesigns::buildFXButton(buttonsFrame, TL("Report"), "", TL("Report bug to github"),
501 // set focus button
503 break;
504 }
505 default:
506 throw ProcessError("Invalid buttons combination in GNEDialog");
507 }
508 // add horizontal frame used to center buttons horizontally
509 new FXHorizontalFrame(buttonsFrame, GUIDesignAuxiliarHorizontalFrame);
510}
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
The main window of Netedit.
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:207
virtual void runInternalTest(const InternalTestStep::DialogArgument *dialogArgument)=0
run internal test
OpenType myOpenType
open type
Definition GNEDialog.h:210
bool myTesting
flag to indicate if this dialog is being tested using internal test
Definition GNEDialog.h:213
FXButton * myCopyButton
copy button
Definition GNEDialog.h:176
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:152
FXButton * myAbortButton
abort button
Definition GNEDialog.h:161
long closeDialogAborting()
close dialog aborting the changes
void setRestoringFocusWindow(FXWindow *window)
wet FXWindows uses for restoring focus
FXButton * myCancelButton
cancel button
Definition GNEDialog.h:158
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
Definition GNEDialog.cpp:96
FXButton * myAdvancedButton
advanced button
Definition GNEDialog.h:173
GNEApplicationWindow * myApplicationWindow
FOX needs this.
Definition GNEDialog.h:146
FXButton * myResetButton
reset button
Definition GNEDialog.h:164
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:155
Result myResult
result to indicate if this dialog was closed accepting or rejecting changes
Definition GNEDialog.h:185
long closeDialogAccepting()
close dialog accepting the changes
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:182
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:179
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:170
long onKeyPress(FXObject *obj, FXSelector sel, void *ptr)
called when user presses a key on the dialog
FXButton * myRunButton
run button
Definition GNEDialog.h:167
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)
FXWindow * myRestoringFocusWindow
FXWindows that restoring focus window.
Definition GNEDialog.h:149
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