Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
GNEOptionsDialogElements.cpp
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3// Copyright (C) 2001-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// A Dialog for setting options (see OptionsCont)
19/****************************************************************************/
20#include <config.h>
21
32
34#include "GNEOptionsDialog.h"
35
36// ===========================================================================
37// Defines
38// ===========================================================================
39
40#define MARGIN 4
41#define MINNAMEWIDTH 200
42
43// ===========================================================================
44// FOX callback mapping
45// ===========================================================================
46
52
56
57// Object implementation
58FXIMPLEMENT_ABSTRACT(GNEOptionsDialogElements::InputOption, FXHorizontalFrame, InputOptionMap, ARRAYNUMBER(InputOptionMap))
59FXIMPLEMENT_ABSTRACT(GNEOptionsDialogElements::InputFilename, GNEOptionsDialogElements::InputOption, InputFilenameMap, ARRAYNUMBER(InputFilenameMap))
60
61// ===========================================================================
62// method definitions
63// ===========================================================================
64
65// ---------------------------------------------------------------------------
66// GNEOptionsDialogElements::InputOption - methods
67// ---------------------------------------------------------------------------
68
69GNEOptionsDialogElements::InputOption::InputOption(GNEOptionsDialog* GUIDialogOptions, FXComposite* parent, const std::string& topic,
70 const std::string& name, const std::string& description, const std::string& defaultValue) :
71 FXHorizontalFrame(parent, GUIDesignAuxiliarHorizontalFrame),
72 myGUIDialogOptions(GUIDialogOptions),
73 myTopic(topic),
74 myName(name),
75 myDescription(description),
76 myDefaultValue(defaultValue) {
77 // build label with name (default width 150)
78 myNameLabel = new MFXLabelTooltip(this, myGUIDialogOptions->myGNEApp->getStaticTooltipMenu(), name.c_str(), nullptr, GUIDesignLabelThickedFixed(MINNAMEWIDTH));
79 // set description as tooltip
80 myNameLabel->setTipText(description.c_str());
81 // create content frame
82 myContentFrame = new FXHorizontalFrame(this, GUIDesignAuxiliarHorizontalFrame);
83 // Create reset button
84 myResetButton = GUIDesigns::buildFXButton(this, "", "", TL("Reset value"), GUIIconSubSys::getIcon(GUIIcon::RESET), this, MID_GNE_RESET, GUIDesignButtonIcon);
85}
86
87
88void
90 const int nameWidth = myNameLabel->getFont()->getTextWidth(myNameLabel->getText().text(), myNameLabel->getText().length() + MARGIN);
91 if (nameWidth > MINNAMEWIDTH) {
92 myNameLabel->setWidth(nameWidth);
93 }
94}
95
96
97const std::string&
99 return myTopic;
100}
101
102
103const std::string
107
108
109const std::string
113
114
115long
117 if (getValue() != myDefaultValue) {
118 myResetButton->enable();
119 } else {
120 myResetButton->disable();
121 }
122 return 1;
123}
124
125// ---------------------------------------------------------------------------
126// GNEOptionsDialogElements::InputString - methods
127// ---------------------------------------------------------------------------
128
130 const std::string& topic, const std::string& name, const std::string& description, const std::string& defaultValue) :
131 InputOption(GUIDialogOptions, parent, topic, name, description, defaultValue) {
134 updateOption();
135}
136
137
138void
140 myStringTextField->setText(myGUIDialogOptions->myOptionsContainer.getString(myName).c_str());
141}
142
143
144void
146 myStringTextField->setText(myGUIDialogOptions->myOriginalOptionsContainer.getString(myName).c_str());
147}
148
149
150long
152 myGUIDialogOptions->myOptionsContainer.resetWritable();
153 myGUIDialogOptions->myOptionsContainer.set(myName, myStringTextField->getText().text());
154 myGUIDialogOptions->myOptionsModified = true;
155 return 1;
156}
157
158
159long
161 myStringTextField->setText(myDefaultValue.c_str());
162 return 1;
163}
164
165
166std::string
168 return myStringTextField->getText().text();
169}
170
171
173 const std::string& topic, const std::string& name, const std::string& description, const std::string& defaultValue) :
174 InputOption(GUIDialogOptions, parent, topic, name, description, defaultValue) {
176 updateOption();
177}
178
179
180void
182 myStringVectorTextField->setText(toString(myGUIDialogOptions->myOptionsContainer.getStringVector(myName)).c_str());
183}
184
185
186void
188 myStringVectorTextField->setText(toString(myGUIDialogOptions->myOriginalOptionsContainer.getStringVector(myName)).c_str());
189}
190
191
192long
194 myGUIDialogOptions->myOptionsContainer.resetWritable();
195 myGUIDialogOptions->myOptionsContainer.set(myName, myStringVectorTextField->getText().text());
196 myGUIDialogOptions->myOptionsModified = true;
197 return 1;
198}
199
200
201long
203 myStringVectorTextField->setText(myDefaultValue.c_str());
204 return 1;
205}
206
207
208std::string
210 return myStringVectorTextField->getText().text();
211}
212
213// ---------------------------------------------------------------------------
214// GNEOptionsDialogElements::InputBool - methods
215// ---------------------------------------------------------------------------
216
218 const std::string& topic, const std::string& name, const std::string& description, const std::string& defaultValue) :
219 InputOption(GUIDialogOptions, parent, topic, name, description, defaultValue) {
221 updateOption();
222}
223
224
225void
227 if (myGUIDialogOptions->myOptionsContainer.getBool(myName)) {
228 myCheckButton->setCheck(TRUE);
229 myCheckButton->setText(TL("true"));
230 } else {
231 myCheckButton->setCheck(FALSE);
232 myCheckButton->setText(TL("false"));
233 }
234}
235
236
237void
239 if (myGUIDialogOptions->myOriginalOptionsContainer.getBool(myName)) {
240 myCheckButton->setCheck(TRUE);
241 myCheckButton->setText(TL("true"));
242 } else {
243 myCheckButton->setCheck(FALSE);
244 myCheckButton->setText(TL("false"));
245 }
246}
247
248
249long
251 myGUIDialogOptions->myOptionsContainer.resetWritable();
252 if (myCheckButton->getCheck()) {
253 myGUIDialogOptions->myOptionsContainer.set(myName, "true");
254 myCheckButton->setText(TL("true"));
255 } else {
256 myGUIDialogOptions->myOptionsContainer.set(myName, "false");
257 myCheckButton->setText(TL("false"));
258 }
259 myGUIDialogOptions->myOptionsModified = true;
260 // special checks for Debug flags
261 if ((myName == "gui-testing-debug") && myGUIDialogOptions->myOptionsContainer.isSet("gui-testing-debug")) {
262 MsgHandler::enableDebugMessages(myGUIDialogOptions->myOptionsContainer.getBool("gui-testing-debug"));
263 }
264 if ((myName == "gui-testing-debug-gl") && myGUIDialogOptions->myOptionsContainer.isSet("gui-testing-debug-gl")) {
265 MsgHandler::enableDebugGLMessages(myGUIDialogOptions->myOptionsContainer.getBool("gui-testing-debug-gl"));
266 }
267 return 1;
268}
269
270
271long
273 if (StringUtils::toBool(myDefaultValue)) {
274 myCheckButton->setCheck(TRUE);
275 myCheckButton->setText(TL("true"));
276 } else {
277 myCheckButton->setCheck(FALSE);
278 myCheckButton->setText(TL("false"));
279 }
280 return 1;
281}
282
283
284std::string
286 return myCheckButton->getCheck() ? "true" : "false";
287}
288
289// ---------------------------------------------------------------------------
290// GNEOptionsDialogElements::InputInt - methods
291// ---------------------------------------------------------------------------
292
294 const std::string& topic, const std::string& name, const std::string& description, const std::string& defaultValue) :
295 InputOption(GUIDialogOptions, parent, topic, name, description, defaultValue) {
297 updateOption();
298}
299
300
301void
303 myIntTextField->setText(toString(myGUIDialogOptions->myOptionsContainer.getInt(myName)).c_str());
304}
305
306
307void
309 myIntTextField->setText(toString(myGUIDialogOptions->myOriginalOptionsContainer.getInt(myName)).c_str());
310}
311
312
313long
315 if (myIntTextField->getText().empty()) {
316 myIntTextField->setText(myDefaultValue.c_str());
317 } else {
318 myGUIDialogOptions->myOptionsContainer.resetWritable();
319 myGUIDialogOptions->myOptionsContainer.set(myName, myIntTextField->getText().text());
320 myGUIDialogOptions->myOptionsModified = true;
321 }
322 return 1;
323}
324
325
326long
328 myIntTextField->setText(myDefaultValue.c_str());
329 return 1;
330}
331
332
333std::string
335 return myIntTextField->getText().text();
336}
337
338// ---------------------------------------------------------------------------
339// GNEOptionsDialogElements::InputIntVector - methods
340// ---------------------------------------------------------------------------
341
343 const std::string& topic, const std::string& name, const std::string& description, const std::string& defaultValue) :
344 InputOption(GUIDialogOptions, parent, topic, name, description, defaultValue) {
347 updateOption();
348}
349
350
351void
353 myIntVectorTextField->setText(toString(myGUIDialogOptions->myOptionsContainer.getIntVector(myName)).c_str());
354}
355
356
357void
359 myIntVectorTextField->setText(toString(myGUIDialogOptions->myOriginalOptionsContainer.getIntVector(myName)).c_str());
360}
361
362
363long
365 try {
366 // check that int vector can be parsed
367 const auto intVector = StringTokenizer(myIntVectorTextField->getText().text()).getVector();
368 for (const auto& intValue : intVector) {
369 StringUtils::toInt(intValue);
370 }
371 myGUIDialogOptions->myOptionsContainer.resetWritable();
372 myGUIDialogOptions->myOptionsContainer.set(myName, myIntVectorTextField->getText().text());
373 myIntVectorTextField->setTextColor(FXRGB(0, 0, 0));
374 myGUIDialogOptions->myOptionsModified = true;
375 } catch (...) {
376 myIntVectorTextField->setTextColor(FXRGB(255, 0, 0));
377 }
378 return 1;
379}
380
381
382long
384 myIntVectorTextField->setText(myDefaultValue.c_str());
385 return 1;
386}
387
388
389std::string
391 return myIntVectorTextField->getText().text();
392}
393
394// ---------------------------------------------------------------------------
395// GNEOptionsDialogElements::InputFloat - methods
396// ---------------------------------------------------------------------------
397
398GNEOptionsDialogElements::InputFloat::InputFloat(GNEOptionsDialog* GUIDialogOptions, FXComposite* parent, const std::string& topic,
399 const std::string& name, const std::string& description, const std::string& defaultValue) :
400 InputOption(GUIDialogOptions, parent, topic, name, description, parseFloat(defaultValue)) {
403 updateOption();
404}
405
406
407void
409 myFloatTextField->setText(toString(myGUIDialogOptions->myOptionsContainer.getFloat(myName)).c_str());
410}
411
412
413void
415 myFloatTextField->setText(toString(myGUIDialogOptions->myOriginalOptionsContainer.getFloat(myName)).c_str());
416}
417
418
419long
421 // avoid empty values
422 if (myFloatTextField->getText().empty()) {
423 myFloatTextField->setText(myDefaultValue.c_str());
424 } else {
425 myGUIDialogOptions->myOptionsContainer.resetWritable();
426 myGUIDialogOptions->myOptionsContainer.set(myName, myFloatTextField->getText().text());
427 myGUIDialogOptions->myOptionsModified = true;
428 }
429 return 1;
430}
431
432
433long
435 myFloatTextField->setText(myDefaultValue.c_str());
436 return 1;
437}
438
439
440std::string
442 return myFloatTextField->getText().text();
443}
444
445
446std::string
448 try {
449 return toString(StringUtils::toDouble(value));
450 } catch (...) {
451 return value;
452 }
453}
454
455// ---------------------------------------------------------------------------
456// GNEOptionsDialogElements::InputTime - methods
457// ---------------------------------------------------------------------------
458
459GNEOptionsDialogElements::InputTime::InputTime(GNEOptionsDialog* GUIDialogOptions, FXComposite* parent, const std::string& topic,
460 const std::string& name, const std::string& description, const std::string& defaultValue) :
461 InputOption(GUIDialogOptions, parent, topic, name, description, parseTime(defaultValue)) {
464 updateOption();
465}
466
467
468void
470 myTimeTextField->setText(toString(myGUIDialogOptions->myOptionsContainer.getString(myName)).c_str());
471}
472
473
474void
476 myTimeTextField->setText(toString(myGUIDialogOptions->myOriginalOptionsContainer.getString(myName)).c_str());
477}
478
479
480long
482 // avoid empty values
483 if (myTimeTextField->getText().empty()) {
484 myTimeTextField->setText(myDefaultValue.c_str());
485 } else {
486 myGUIDialogOptions->myOptionsContainer.resetWritable();
487 myGUIDialogOptions->myOptionsContainer.set(myName, myTimeTextField->getText().text());
488 myGUIDialogOptions->myOptionsModified = true;
489 }
490 return 1;
491}
492
493
494long
496 myTimeTextField->setText(myDefaultValue.c_str());
497 return 1;
498}
499
500
501std::string
503 return myTimeTextField->getText().text();
504}
505
506
507std::string
508GNEOptionsDialogElements::InputTime::parseTime(const std::string& value) const {
509 try {
510 return time2string(string2time(value));
511 } catch (...) {
512 return value;
513 }
514}
515
516// ---------------------------------------------------------------------------
517// GNEOptionsDialogElements::InputFilename - methods
518// ---------------------------------------------------------------------------
519
520GNEOptionsDialogElements::InputFilename::InputFilename(GNEOptionsDialog* GUIDialogOptions, FXComposite* parent, const std::string& topic,
521 const std::string& name, const std::string& description, const std::string& defaultValue) :
522 InputOption(GUIDialogOptions, parent, topic, name, description, defaultValue) {
526 updateOption();
527}
528
529
530void
532 myFilenameTextField->setText(myGUIDialogOptions->myOptionsContainer.getString(myName).c_str());
533}
534
535
536void
538 myFilenameTextField->setText(myGUIDialogOptions->myOriginalOptionsContainer.getString(myName).c_str());
539}
540
541
542long
544 // get file
545 const auto file = GNEApplicationWindowHelper::openXMLFileDialog(this, (myName.find("output") != std::string::npos), false);
546 // check that file is valid
547 if (file.size() > 0) {
548 myFilenameTextField->setText(file.c_str(), TRUE);
549 }
550 return 1;
551}
552
553
554long
556 if (SUMOXMLDefinitions::isValidFilename(myFilenameTextField->getText().text())) {
557 myGUIDialogOptions->myOptionsContainer.resetWritable();
558 myGUIDialogOptions->myOptionsContainer.set(myName, myFilenameTextField->getText().text());
559 myFilenameTextField->setTextColor(FXRGB(0, 0, 0));
560 myGUIDialogOptions->myOptionsModified = true;
561 } else {
562 myFilenameTextField->setTextColor(FXRGB(255, 0, 0));
563 }
564 return 1;
565}
566
567
568long
570 myFilenameTextField->setText(myDefaultValue.c_str());
571 return 1;
572}
573
574
576
577
578std::string
580 return myFilenameTextField->getText().text();
581}
582
583/****************************************************************************/
FXDEFMAP(GNEOptionsDialogElements::InputOption) InputOptionMap[]
#define MINNAMEWIDTH
#define MARGIN
@ MID_GNE_SET_ATTRIBUTE
attribute edited
Definition GUIAppEnum.h:991
@ MID_GNE_SET_ATTRIBUTE_DIALOG
attribute edited trough dialog
@ MID_GNE_RESET
reset element
Definition GUIAppEnum.h:999
#define GUIDesignButtonIcon
button only with icon
Definition GUIDesigns.h:91
#define GUIDesignTextField
Definition GUIDesigns.h:59
#define GUIDesignAuxiliarHorizontalFrame
design for auxiliar (Without borders) horizontal frame used to pack another frames
Definition GUIDesigns.h:399
#define GUIDesignTextFieldNCol
Num of column of text field.
Definition GUIDesigns.h:74
#define GUIDesignCheckButton
checkButton placed in left position
Definition GUIDesigns.h:192
#define GUIDesignTextFieldRestricted(type)
text field extended over Frame with thick frame (int)
Definition GUIDesigns.h:62
#define GUIDesignLabelThickedFixed(width)
label thicked, icon before text, text centered and custom width
Definition GUIDesigns.h:252
@ OPEN
open icons
#define TL(string)
Definition MsgHandler.h:305
SUMOTime string2time(const std::string &r)
convert string to SUMOTime
Definition SUMOTime.cpp:46
std::string time2string(SUMOTime t, bool humanReadable)
convert SUMOTime to string (independently of global format setting)
Definition SUMOTime.cpp:91
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition ToString.h:46
long onCmdResetOption(FXObject *, FXSelector, void *)
called when user press reset button
InputBool(GNEOptionsDialog *GUIDialogOptions, FXComposite *parent, const std::string &topic, const std::string &name, const std::string &description, const std::string &defaultValue)
constructor
long onCmdSetOption(FXObject *, FXSelector, void *)
called when user set value in textField/button/checkBox
long onCmdOpenDialog(FXObject *, FXSelector, void *)
called when user press open dialog button
long onCmdResetOption(FXObject *, FXSelector, void *)
called when user press reset button
long onCmdSetOption(FXObject *, FXSelector, void *)
called when user set value in textField/button/checkBox
FXButton * myOpenFilenameButton
open filename button
InputFloat(GNEOptionsDialog *GUIDialogOptions, FXComposite *parent, const std::string &topic, const std::string &name, const std::string &description, const std::string &defaultValue)
constructor
std::string parseFloat(const std::string &value) const
parse float xx to xx.00
long onCmdSetOption(FXObject *, FXSelector, void *)
called when user set value in textField/button/checkBox
long onCmdResetOption(FXObject *, FXSelector, void *)
called when user press reset button
long onCmdResetOption(FXObject *, FXSelector, void *)
called when user press reset button
InputInt(GNEOptionsDialog *GUIDialogOptions, FXComposite *parent, const std::string &topic, const std::string &name, const std::string &description, const std::string &defaultValue)
long onCmdSetOption(FXObject *, FXSelector, void *)
called when user set value in textField/button/checkBox
InputIntVector(GNEOptionsDialog *GUIDialogOptions, FXComposite *parent, const std::string &topic, const std::string &name, const std::string &description, const std::string &defaultValue)
long onCmdSetOption(FXObject *, FXSelector, void *)
called when user set value in textField/button/checkBox
long onCmdResetOption(FXObject *, FXSelector, void *)
called when user press reset button
virtual long onCmdResetOption(FXObject *, FXSelector, void *)=0
called when user press reset button
GNEOptionsDialog * myGUIDialogOptions
FOX needs this.
const std::string & getTopic() const
get topic
const std::string getNameLower() const
get name (Lower)
long onUpdResetOption(FXObject *, FXSelector, void *)
update reset button
const std::string getDescriptionLower() const
get description (Lower)
MFXLabelTooltip * myNameLabel
tooltip label for name
virtual long onCmdSetOption(FXObject *, FXSelector, void *)=0
called when user set value in textField/button/checkBox
FXHorizontalFrame * myContentFrame
content frame
long onCmdSetOption(FXObject *, FXSelector, void *)
called when user set value in textField/button/checkBox
long onCmdResetOption(FXObject *, FXSelector, void *)
called when user press reset button
InputString(GNEOptionsDialog *GUIDialogOptions, FXComposite *parent, const std::string &topic, const std::string &name, const std::string &description, const std::string &defaultValue)
constructor
InputStringVector(GNEOptionsDialog *GUIDialogOptions, FXComposite *parent, const std::string &topic, const std::string &name, const std::string &description, const std::string &defaultValue)
constructor
long onCmdResetOption(FXObject *, FXSelector, void *)
called when user press reset button
long onCmdSetOption(FXObject *, FXSelector, void *)
called when user set value in textField/button/checkBox
long onCmdResetOption(FXObject *, FXSelector, void *)
called when user press reset button
long onCmdSetOption(FXObject *, FXSelector, void *)
called when user set value in textField/button/checkBox
std::string parseTime(const std::string &value) const
parse float xx to xx.00
InputTime(GNEOptionsDialog *GUIDialogOptions, FXComposite *parent, const std::string &topic, const std::string &name, const std::string &description, const std::string &defaultValue)
constructor
OptionsCont & myOptionsContainer
reference to edited Option container
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
static void enableDebugGLMessages(bool enable)
enable/disable gl-debug messages
static void enableDebugMessages(bool enable)
enable/disable debug messages
double getFloat(const std::string &name) const
Returns the double-value of the named option (only for Option_Float)
const IntVector & getIntVector(const std::string &name) const
Returns the list of integer-value of the named option (only for Option_IntVector)
std::string getString(const std::string &name) const
Returns the string-value of the named option (only for Option_String)
static bool isValidFilename(const std::string &value)
whether the given string is a valid attribute for a filename (for example, a name)
std::vector< std::string > getVector()
return vector of strings
static std::string to_lower_case(const std::string &str)
Transfers the content to lower case.
static double toDouble(const std::string &sData)
converts a string into the double value described by it by calling the char-type converter
static int toInt(const std::string &sData)
converts a string into the integer value described by it by calling the char-type converter,...
static bool toBool(const std::string &sData)
converts a string into the bool value described by it by calling the char-type converter
Definition json.hpp:4471
static std::string openXMLFileDialog(FXWindow *window, bool save, bool multi)
open xml file dialog