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 // abort dialog
44 FXMAPFUNC(SEL_CLOSE, 0, GNEDialog::onCmdAbort),
45 FXMAPFUNC(SEL_COMMAND, MID_HOTKEY_ESC, GNEDialog::onCmdAbort),
46 FXMAPFUNC(SEL_CHORE, MID_GNE_ABORT, GNEDialog::onCmdAbort),
47 FXMAPFUNC(SEL_TIMEOUT, MID_GNE_ABORT, GNEDialog::onCmdAbort),
48 FXMAPFUNC(SEL_COMMAND, MID_GNE_ABORT, GNEDialog::onCmdAbort),
49};
50
51// Object implementation
52FXIMPLEMENT_ABSTRACT(GNEDialog, FXDialogBox, MFXDialogBoxMap, ARRAYNUMBER(MFXDialogBoxMap))
53
54// ===========================================================================
55// method definitions
56// ===========================================================================
57
58GNEDialog::GNEDialog(GNEApplicationWindow* applicationWindow, const std::string& name,
59 GUIIcon titleIcon, Buttons buttons, OpenType openType,
60 ResizeMode resizeMode) :
61 FXDialogBox(applicationWindow->getApp(), name.c_str(),
63 0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
64 myApplicationWindow(applicationWindow),
65 myOpenType(openType) {
66 // build dialog
67 buildDialog(titleIcon, buttons);
68}
69
70
71GNEDialog::GNEDialog(GNEApplicationWindow* applicationWindow, const std::string& name,
72 GUIIcon titleIcon, Buttons buttons, OpenType openType,
73 ResizeMode resizeMode, const int width, const int height) :
74 FXDialogBox(applicationWindow->getApp(), name.c_str(),
76 0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
77 myApplicationWindow(applicationWindow),
78 myOpenType(openType) {
79 // build dialog
80 buildDialog(titleIcon, buttons);
81 // set explicit size
82 resize(width, height);
83}
84
85
88 return myResult;
89}
90
91
96
97
98FXVerticalFrame*
100 return myContentFrame;
101}
102
103
104long
105GNEDialog::onCmdAccept(FXObject*, FXSelector, void*) {
106 return closeDialogAccepting();
107}
108
109
110long
111GNEDialog::onCmdCancel(FXObject*, FXSelector, void*) {
112 return closeDialogCanceling();
113}
114
115
116long
117GNEDialog::onCmdAbort(FXObject*, FXSelector, void*) {
118 return closeDialogAborting();
119}
120
121
122long
123GNEDialog::onCmdReset(FXObject*, FXSelector, void*) {
124 throw ProcessError("onCmdReset function must be reimplemented in GNEDialog children");
125}
126
127
128long
129GNEDialog::onCmdRun(FXObject*, FXSelector, void*) {
130 throw ProcessError("onCmdRun function must be reimplemented in GNEDialog children");
131}
132
133
134long
135GNEDialog::onCmdBack(FXObject*, FXSelector, void*) {
136 throw ProcessError("onCmdBack function must be reimplemented in GNEDialog children");
137}
138
139
140long
141GNEDialog::onCmdAdvanced(FXObject*, FXSelector, void*) {
142 throw ProcessError("onCmdAdvanced function must be reimplemented in GNEDialog children");
143}
144
145
146long
147GNEDialog::onKeyPress(FXObject* obj, FXSelector sel, void* ptr) {
148 if (myTesting && (obj != myApplicationWindow->getInternalTest())) {
149 return 1;
150 } else {
151 // if ESC key is pressed, close dialog aborting
152 FXEvent* event = (FXEvent*)ptr;
153 if (event->code == KEY_Escape) {
154 return closeDialogAborting();
155 } else {
156 return FXDialogBox::onKeyPress(obj, sel, ptr);
157 }
158 }
159}
160
161
162long
163GNEDialog::onKeyRelease(FXObject* obj, FXSelector sel, void* ptr) {
164 if (myTesting && (obj != myApplicationWindow->getInternalTest())) {
165 return 1;
166 } else {
167 return FXDialogBox::onKeyRelease(obj, sel, ptr);
168 }
169}
170
171
172void
173GNEDialog::openDialog(FXWindow* focusableElement) {
174 // create dialog
175 create();
176 // check if set focus in button
177 if (focusableElement) {
178 focusableElement->setFocus();
179 } else {
180 myFocusButton->setFocus();
181 }
182 // show in the center of app
183 show(PLACEMENT_OWNER);
184 // continue depending on whether we are testing or not
185 const auto internalTest = myApplicationWindow->getInternalTest();
186 if (internalTest) {
187 myTesting = true;
188 // execute every dialog step
189 while (internalTest->getCurrentStep() && internalTest->getCurrentStep()->getCategory() == InternalTestStep::Category::DIALOG) {
190 // get current step and set next step
191 const auto testStep = internalTest->setNextStep();
192 // continue depending on the dialog argument action
193 switch (testStep->getDialogArgument()->getBasicAction()) {
195 onCmdAccept(internalTest, 0, nullptr);
196 break;
198 onCmdCancel(internalTest, 0, nullptr);
199 break;
201 onCmdReset(internalTest, 0, nullptr);
202 break;
204 onCmdAbort(nullptr, 0, nullptr);
205 break;
206 default:
207 if (testStep->getDialogArgument()->getCustomAction().size() > 0) {
208 runInternalTest(testStep->getDialogArgument());
209 } else {
210 handle(internalTest, testStep->getSelector(), testStep->getEvent());
211 }
212 break;
213 }
214 }
215 } else {
216 myTesting = false;
217 // continue depending on the dialog type
219 // run modal dialog
220 getApp()->runModalFor(this);
221 }
222 }
223}
224
225
226long
228 // check if stopping modal dialog
229 if (!myTesting && (myOpenType == OpenType::MODAL)) {
230 getApp()->stopModal(this, TRUE);
231 }
232 // hide dialog
233 hide();
234 // set result
236 // restore focus to application window (to avoid problems in Linux)
237 myApplicationWindow->setFocus();
238 return 1;
239}
240
241
242long
244 // check if stopping modal dialog
245 if (!myTesting && (myOpenType == OpenType::MODAL)) {
246 getApp()->stopModal(this, TRUE);
247 }
248 // hide dialog
249 hide();
250 // set result
252 // restore focus to application window (to avoid problems in Linux)
253 myApplicationWindow->setFocus();
254 return 0;
255}
256
257
258long
260 // check if stopping modal dialog
261 if (!myTesting && (myOpenType == OpenType::MODAL)) {
262 getApp()->stopModal(this, TRUE);
263 }
264 // hide dialog
265 hide();
266 // set result
268 // restore focus to application window (to avoid problems in Linux)
269 myApplicationWindow->setFocus();
270 return 0;
271}
272
273
274void
275GNEDialog::updateTitle(const std::string& newTitle) {
276 setTitle(newTitle.c_str());
277}
278
279
280void
282 setIcon(GUIIconSubSys::getIcon(newIcon));
283}
284
285
286void
288 // set dialog icon
289 setIcon(GUIIconSubSys::getIcon(titleIcon));
290 // create main frame
291 auto mainFrame = new FXVerticalFrame(this, GUIDesignAuxiliarFrame);
292 // create content frame
293 myContentFrame = new FXVerticalFrame(mainFrame, GUIDesignDialogContentFrame);
294 // add separator
295 new FXHorizontalSeparator(mainFrame, GUIDesignHorizontalSeparator);
296 // Create frame for buttons
297 FXHorizontalFrame* buttonsFrame = new FXHorizontalFrame(mainFrame, GUIDesignDialogButtonsHorizontalFrame);
298 // add horizontal frame used to center buttons horizontally
299 new FXHorizontalFrame(buttonsFrame, GUIDesignAuxiliarHorizontalFrame);
300 // create buttons according to the type
301 switch (buttons) {
302 case Buttons::OK: {
303 // ok button
304 myAcceptButton = GUIDesigns::buildFXButton(buttonsFrame, TL("OK"), "", TL("OK"),
307 // set focus button
309 break;
310 }
311 case Buttons::YES_NO: {
312 // yes button
313 myAcceptButton = GUIDesigns::buildFXButton(buttonsFrame, TL("Yes"), "", TL("Yes"),
316 // no button
317 myCancelButton = GUIDesigns::buildFXButton(buttonsFrame, TL("No"), "", TL("No"),
320 // set focus button
322 break;
323 }
325 // yes button
326 myAcceptButton = GUIDesigns::buildFXButton(buttonsFrame, TL("Yes"), "", TL("Yes"),
329 // no button
330 myCancelButton = GUIDesigns::buildFXButton(buttonsFrame, TL("No"), "", TL("No"),
333 // cancel button
334 myAbortButton = GUIDesigns::buildFXButton(buttonsFrame, TL("Cancel"), "", TL("Cancel"),
337 // set focus button
339 break;
340 }
342 // save button
343 myAcceptButton = GUIDesigns::buildFXButton(buttonsFrame, TL("Save"), "", TL("Save"),
346 // don't save button
347 myCancelButton = GUIDesigns::buildFXButton(buttonsFrame, TL("Don't Save"), "", TL("Don't Save"),
350 // cancel button
351 myAbortButton = GUIDesigns::buildFXButton(buttonsFrame, TL("Cancel"), "", TL("Cancel"),
354 // set focus button
356 break;
357 }
358 case Buttons::ACCEPT: {
359 // accept button
360 myAcceptButton = GUIDesigns::buildFXButton(buttonsFrame, TL("Accept"), "", TL("Accept"),
363 // set focus button
365 break;
366 }
368 // accept button
369 myAcceptButton = GUIDesigns::buildFXButton(buttonsFrame, TL("Accept"), "", TL("Accept"),
372 // cancel button
373 myCancelButton = GUIDesigns::buildFXButton(buttonsFrame, TL("Cancel"), "", TL("Cancel"),
376 // set focus button
378 break;
379 }
381 // accept button
382 myAcceptButton = GUIDesigns::buildFXButton(buttonsFrame, TL("Accept"), "", TL("Accept"),
385 // cancel button
386 myCancelButton = GUIDesigns::buildFXButton(buttonsFrame, TL("Cancel"), "", TL("Cancel"),
389 // reset button
390 myResetButton = GUIDesigns::buildFXButton(buttonsFrame, TL("Reset"), "", TL("Reset changes"),
393 // set focus button
395 break;
396 }
398 // run button
399 myRunButton = GUIDesigns::buildFXButton(buttonsFrame, TL("Run"), "", TL("Run"),
402 // reset button
403 myCancelButton = GUIDesigns::buildFXButton(buttonsFrame, TL("Cancel"), "", TL("Cancel"),
406 // reset button
407 myResetButton = GUIDesigns::buildFXButton(buttonsFrame, TL("Reset"), "", TL("Reset changes"),
410 // set focus button
412 break;
413 }
415 // run button
416 myRunButton = GUIDesigns::buildFXButton(buttonsFrame, TL("Run"), "", TL("Run"),
419 // cancel button
420 myAdvancedButton = GUIDesigns::buildFXButton(buttonsFrame, TL("Advanced"), "", TL("Advanced options"),
423 // cancel button
424 myCancelButton = GUIDesigns::buildFXButton(buttonsFrame, TL("Cancel"), "", TL("Cancel"),
427 // set focus button
429 break;
430 }
432 // run/abort button
433 myRunButton = GUIDesigns::buildFXButton(buttonsFrame, TL("Rerun"), "", TL("Rerun tool"),
436 // back button
437 myBackButton = GUIDesigns::buildFXButton(buttonsFrame, TL("Back"), "", TL("Back to tool dialog"),
440 // cancel button
441 myAcceptButton = GUIDesigns::buildFXButton(buttonsFrame, TL("Close"), "", TL("Close"),
444 // set focus button
446 break;
447 }
448 default:
449 throw ProcessError("Invalid buttons combination in GNEDialog");
450 }
451 // add horizontal frame used to center buttons horizontally
452 new FXHorizontalFrame(buttonsFrame, GUIDesignAuxiliarHorizontalFrame);
453}
FXDEFMAP(GNEDialog) MFXDialogBoxMap[]
@ 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:284
@ 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:305
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)
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:181
virtual void runInternalTest(const InternalTestStep::DialogArgument *dialogArgument)=0
run internal test
OpenType myOpenType
open type
Definition GNEDialog.h:184
bool myTesting
flag to indicate if this dialog is being tested using internal test
Definition GNEDialog.h:187
virtual long onCmdBack(FXObject *, FXSelector, void *)
called when back button is pressed (must be reimplemented in children)
FXVerticalFrame * myContentFrame
content frame
Definition GNEDialog.h:135
FXButton * myAbortButton
abort button
Definition GNEDialog.h:144
long closeDialogAborting()
close dialog aborting the changes
FXButton * myCancelButton
cancel button
Definition GNEDialog.h:141
FXVerticalFrame * getContentFrame() const
get content frame
Definition GNEDialog.cpp:99
GNEApplicationWindow * getApplicationWindow() const
get pointer to the application window
Definition GNEDialog.cpp:93
Result getResult() const
get result to indicate if this dialog was closed accepting or rejecting changes
Definition GNEDialog.cpp:87
FXButton * myAdvancedButton
advanced button
Definition GNEDialog.h:156
GNEApplicationWindow * myApplicationWindow
FOX needs this.
Definition GNEDialog.h:132
FXButton * myResetButton
reset button
Definition GNEDialog.h:147
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:67
FXButton * myAcceptButton
accept button
Definition GNEDialog.h:138
Result myResult
result to indicate if this dialog was closed accepting or rejecting changes
Definition GNEDialog.h:159
long closeDialogAccepting()
close dialog accepting the changes
virtual long onCmdAdvanced(FXObject *, FXSelector, void *)
called when advanced button is pressed (must be reimplemented in children)
OpenType
Open dialog type.
Definition GNEDialog.h:55
virtual long onCmdAbort(FXObject *, FXSelector, void *)
called when abort is called either closing dialog or pressing abort button (can be reimplemented in c...
FXButton * myBackButton
back button
Definition GNEDialog.h:153
GNEDialog(GNEApplicationWindow *applicationWindow, const std::string &name, GUIIcon titleIcon, Buttons buttons, OpenType openType, ResizeMode resizeMode)
constructor for resizable dialogs
Definition GNEDialog.cpp:58
long onKeyPress(FXObject *obj, FXSelector sel, void *ptr)
called when user presses a key on the dialog
FXButton * myRunButton
run button
Definition GNEDialog.h:150
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)
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