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
113long
114GNEDialog::onCmdAccept(FXObject*, FXSelector, void*) {
115 return closeDialogAccepting();
116}
117
118
119long
120GNEDialog::onCmdCancel(FXObject*, FXSelector, void*) {
121 return closeDialogCanceling();
122}
123
124
125long
126GNEDialog::onCmdAbort(FXObject*, FXSelector, void*) {
127 return closeDialogAborting();
128}
129
130
131long
132GNEDialog::onCmdReset(FXObject*, FXSelector, void*) {
133 throw ProcessError("onCmdReset function must be reimplemented in GNEDialog children");
134}
135
136
137long
138GNEDialog::onCmdRun(FXObject*, FXSelector, void*) {
139 throw ProcessError("onCmdRun function must be reimplemented in GNEDialog children");
140}
141
142
143long
144GNEDialog::onCmdBack(FXObject*, FXSelector, void*) {
145 throw ProcessError("onCmdBack function must be reimplemented in GNEDialog children");
146}
147
148
149long
150GNEDialog::onCmdAdvanced(FXObject*, FXSelector, void*) {
151 throw ProcessError("onCmdAdvanced function must be reimplemented in GNEDialog children");
152}
153
154
155long
156GNEDialog::onCmdCopy(FXObject*, FXSelector, void*) {
157 throw ProcessError("onCmdyCopy function must be reimplemented in GNEDialog children");
158}
159
160
161long
162GNEDialog::onCmdReport(FXObject*, FXSelector, void*) {
163 throw ProcessError("onCmdyReport function must be reimplemented in GNEDialog children");
164}
165
166
167long
168GNEDialog::onKeyPress(FXObject* obj, FXSelector sel, void* ptr) {
169 if (myTesting && (obj != myApplicationWindow->getInternalTest())) {
170 return 1;
171 } else {
172 // if ESC key is pressed, close dialog aborting
173 FXEvent* event = (FXEvent*)ptr;
174 if (event->code == KEY_Escape) {
175 return closeDialogAborting();
176 } else {
177 return FXDialogBox::onKeyPress(obj, sel, ptr);
178 }
179 }
180}
181
182
183long
184GNEDialog::onKeyRelease(FXObject* obj, FXSelector sel, void* ptr) {
185 if (myTesting && (obj != myApplicationWindow->getInternalTest())) {
186 return 1;
187 } else {
188 return FXDialogBox::onKeyRelease(obj, sel, ptr);
189 }
190}
191
192
193void
194GNEDialog::openDialog(FXWindow* focusableElement) {
195 // create dialog
196 create();
197 // check if set focus in button
198 if (focusableElement) {
199 focusableElement->setFocus();
200 } else {
201 myFocusButton->setFocus();
202 }
203 // show in the center of app
204 show(PLACEMENT_OWNER);
205 // continue depending on whether we are testing or not
206 const auto internalTest = myApplicationWindow->getInternalTest();
207 if (internalTest) {
208 myTesting = true;
209 bool closeDialog = false;
210 // execute every dialog step
211 while (internalTest->getCurrentStep() && !closeDialog &&
212 (internalTest->getCurrentStep()->getCategory() == InternalTestStep::Category::DIALOG) &&
213 (internalTest->getCurrentStep()->getDialogArgument()->getType() == myType)) {
214 // set next step
215 const auto testStep = internalTest->setNextStep();
216 // continue depending on the dialog argument action
217 switch (testStep->getDialogArgument()->getAction()) {
219 onCmdAccept(internalTest, 0, nullptr);
220 closeDialog = true;
221 break;
223 onCmdCancel(internalTest, 0, nullptr);
224 closeDialog = true;
225 break;
227 onCmdReset(internalTest, 0, nullptr);
228 break;
230 onCmdAbort(nullptr, 0, nullptr);
231 break;
232 default:
233 runInternalTest(testStep->getDialogArgument());
234 break;
235 }
236 }
237 } else {
238 myTesting = false;
239 // continue depending on the dialog type
241 // run modal dialog
242 getApp()->runModalFor(this);
243 }
244 }
245}
246
247
248long
250 // check if stopping modal dialog
251 if (!myTesting && (myOpenType == OpenType::MODAL)) {
252 getApp()->stopModal(this, TRUE);
253 }
254 // hide dialog
255 hide();
256 // set result
258 // restore focus to application window (to avoid problems in Linux)
259 myApplicationWindow->setFocus();
260 return 1;
261}
262
263
264long
266 // check if stopping modal dialog
267 if (!myTesting && (myOpenType == OpenType::MODAL)) {
268 getApp()->stopModal(this, TRUE);
269 }
270 // hide dialog
271 hide();
272 // set result
274 // restore focus to application window (to avoid problems in Linux)
275 myApplicationWindow->setFocus();
276 return 0;
277}
278
279
280long
282 // check if stopping modal dialog
283 if (!myTesting && (myOpenType == OpenType::MODAL)) {
284 getApp()->stopModal(this, TRUE);
285 }
286 // hide dialog
287 hide();
288 // set result
290 // restore focus to application window (to avoid problems in Linux)
291 myApplicationWindow->setFocus();
292 return 0;
293}
294
295
296void
297GNEDialog::updateTitle(const std::string& newTitle) {
298 setTitle(newTitle.c_str());
299}
300
301
302void
304 setIcon(GUIIconSubSys::getIcon(newIcon));
305}
306
307
308void
310 // set dialog icon
311 setIcon(GUIIconSubSys::getIcon(titleIcon));
312 // create main frame
313 auto mainFrame = new FXVerticalFrame(this, GUIDesignAuxiliarFrame);
314 // create content frame
315 myContentFrame = new FXVerticalFrame(mainFrame, GUIDesignDialogContentFrame);
316 // add separator
317 new FXHorizontalSeparator(mainFrame, GUIDesignHorizontalSeparator);
318 // Create frame for buttons
319 FXHorizontalFrame* buttonsFrame = new FXHorizontalFrame(mainFrame, GUIDesignDialogButtonsHorizontalFrame);
320 // add horizontal frame used to center buttons horizontally
321 new FXHorizontalFrame(buttonsFrame, GUIDesignAuxiliarHorizontalFrame);
322 // create buttons according to the type
323 switch (buttons) {
324 case Buttons::OK: {
325 // ok button
326 myAcceptButton = GUIDesigns::buildFXButton(buttonsFrame, TL("OK"), "", TL("OK"),
329 // set focus button
331 break;
332 }
333 case Buttons::YES_NO: {
334 // yes button
335 myAcceptButton = GUIDesigns::buildFXButton(buttonsFrame, TL("Yes"), "", TL("Yes"),
338 // no button
339 myCancelButton = GUIDesigns::buildFXButton(buttonsFrame, TL("No"), "", TL("No"),
342 // set focus button
344 break;
345 }
347 // yes button
348 myAcceptButton = GUIDesigns::buildFXButton(buttonsFrame, TL("Yes"), "", TL("Yes"),
351 // no button
352 myCancelButton = GUIDesigns::buildFXButton(buttonsFrame, TL("No"), "", TL("No"),
355 // cancel button
356 myAbortButton = GUIDesigns::buildFXButton(buttonsFrame, TL("Cancel"), "", TL("Cancel"),
359 // set focus button
361 break;
362 }
364 // save button
365 myAcceptButton = GUIDesigns::buildFXButton(buttonsFrame, TL("Save"), "", TL("Save"),
368 // don't save button
369 myCancelButton = GUIDesigns::buildFXButton(buttonsFrame, TL("Don't Save"), "", TL("Don't Save"),
372 // cancel button
373 myAbortButton = GUIDesigns::buildFXButton(buttonsFrame, TL("Cancel"), "", TL("Cancel"),
376 // set focus button
378 break;
379 }
380 case Buttons::ACCEPT: {
381 // accept button
382 myAcceptButton = GUIDesigns::buildFXButton(buttonsFrame, TL("Accept"), "", TL("Accept"),
385 // set focus button
387 break;
388 }
390 // accept button
391 myAcceptButton = GUIDesigns::buildFXButton(buttonsFrame, TL("Accept"), "", TL("Accept"),
394 // cancel button
395 myCancelButton = GUIDesigns::buildFXButton(buttonsFrame, TL("Cancel"), "", TL("Cancel"),
398 // set focus button
400 break;
401 }
403 // accept button
404 myAcceptButton = GUIDesigns::buildFXButton(buttonsFrame, TL("Accept"), "", TL("Accept"),
407 // cancel button
408 myCancelButton = GUIDesigns::buildFXButton(buttonsFrame, TL("Cancel"), "", TL("Cancel"),
411 // reset button
412 myResetButton = GUIDesigns::buildFXButton(buttonsFrame, TL("Reset"), "", TL("Reset changes"),
415 // set focus button
417 break;
418 }
420 // run button
421 myRunButton = GUIDesigns::buildFXButton(buttonsFrame, TL("Run"), "", TL("Run"),
424 // reset button
425 myCancelButton = GUIDesigns::buildFXButton(buttonsFrame, TL("Cancel"), "", TL("Cancel"),
428 // reset button
429 myResetButton = GUIDesigns::buildFXButton(buttonsFrame, TL("Reset"), "", TL("Reset changes"),
432 // set focus button
434 break;
435 }
437 // run button
438 myRunButton = GUIDesigns::buildFXButton(buttonsFrame, TL("Run"), "", TL("Run"),
441 // cancel button
442 myAdvancedButton = GUIDesigns::buildFXButton(buttonsFrame, TL("Advanced"), "", TL("Advanced options"),
445 // cancel button
446 myCancelButton = GUIDesigns::buildFXButton(buttonsFrame, TL("Cancel"), "", TL("Cancel"),
449 // set focus button
451 break;
452 }
454 // run/abort button
455 myRunButton = GUIDesigns::buildFXButton(buttonsFrame, TL("Rerun"), "", TL("Rerun tool"),
458 // back button
459 myBackButton = GUIDesigns::buildFXButton(buttonsFrame, TL("Back"), "", TL("Back to tool dialog"),
462 // cancel button
463 myAcceptButton = GUIDesigns::buildFXButton(buttonsFrame, TL("Close"), "", TL("Close"),
466 // set focus button
468 break;
469 }
471 // run/abort button
472 myAcceptButton = GUIDesigns::buildFXButton(buttonsFrame, TL("OK"), "", TL("OK"),
475 // copy button
476 myCopyButton = GUIDesigns::buildFXButton(buttonsFrame, TL("Copy"), "", TL("Copy error trace to clipboard"),
479 // cancel button
480 myReportButton = GUIDesigns::buildFXButton(buttonsFrame, TL("Report"), "", TL("Report bug to github"),
483 // set focus button
485 break;
486 }
487 default:
488 throw ProcessError("Invalid buttons combination in GNEDialog");
489 }
490 // add horizontal frame used to center buttons horizontally
491 new FXHorizontalFrame(buttonsFrame, GUIDesignAuxiliarHorizontalFrame);
492}
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:201
virtual void runInternalTest(const InternalTestStep::DialogArgument *dialogArgument)=0
run internal test
OpenType myOpenType
open type
Definition GNEDialog.h:204
bool myTesting
flag to indicate if this dialog is being tested using internal test
Definition GNEDialog.h:207
FXButton * myCopyButton
copy button
Definition GNEDialog.h:170
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:146
FXButton * myAbortButton
abort button
Definition GNEDialog.h:155
long closeDialogAborting()
close dialog aborting the changes
FXButton * myCancelButton
cancel button
Definition GNEDialog.h:152
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:167
GNEApplicationWindow * myApplicationWindow
FOX needs this.
Definition GNEDialog.h:143
FXButton * myResetButton
reset button
Definition GNEDialog.h:158
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:149
Result myResult
result to indicate if this dialog was closed accepting or rejecting changes
Definition GNEDialog.h:179
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:176
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:173
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:164
long onKeyPress(FXObject *obj, FXSelector sel, void *ptr)
called when user presses a key on the dialog
FXButton * myRunButton
run button
Definition GNEDialog.h:161
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