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-2024 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#define MARGIN 4
38#define MINNAMEWIDTH 200
39
40// ===========================================================================
41// FOX callback mapping
42// ===========================================================================
43
49
53
54// Object implementation
55FXIMPLEMENT_ABSTRACT(GNEOptionsDialogElements::InputOption, FXHorizontalFrame, InputOptionMap, ARRAYNUMBER(InputOptionMap))
56FXIMPLEMENT_ABSTRACT(GNEOptionsDialogElements::InputFilename, GNEOptionsDialogElements::InputOption, InputFilenameMap, ARRAYNUMBER(InputFilenameMap))
57
58// ===========================================================================
59// method definitions
60// ===========================================================================
61
62// ---------------------------------------------------------------------------
63// GNEOptionsDialogElements::InputOption - methods
64// ---------------------------------------------------------------------------
65
66GNEOptionsDialogElements::InputOption::InputOption(GNEOptionsDialog* GUIDialogOptions, FXComposite* parent, const std::string& topic,
67 const std::string& name, const std::string& description, const std::string& defaultValue) :
68 FXHorizontalFrame(parent, GUIDesignAuxiliarHorizontalFrame),
69 myGUIDialogOptions(GUIDialogOptions),
70 myTopic(topic),
71 myName(name),
72 myDescription(description),
73 myDefaultValue(defaultValue) {
74 // build label with name (default width 150)
75 myNameLabel = new MFXLabelTooltip(this, myGUIDialogOptions->myGNEApp->getStaticTooltipMenu(), name.c_str(), nullptr, GUIDesignLabelThickedFixed(MINNAMEWIDTH));
76 // set description as tooltip
77 myNameLabel->setTipText(description.c_str());
78 // create content frame
79 myContentFrame = new FXHorizontalFrame(this, GUIDesignAuxiliarHorizontalFrame);
80 // Create reset button
81 myResetButton = GUIDesigns::buildFXButton(this, "", "", TL("Reset value"), GUIIconSubSys::getIcon(GUIIcon::RESET), this, MID_GNE_RESET, GUIDesignButtonIcon);
82}
83
84
85void
87 const int nameWidth = myNameLabel->getFont()->getTextWidth(myNameLabel->getText().text(), myNameLabel->getText().length() + MARGIN);
88 if (nameWidth > MINNAMEWIDTH) {
89 myNameLabel->setWidth(nameWidth);
90 }
91}
92
93
94const std::string&
96 return myTopic;
97}
98
99
100const std::string
104
105
106const std::string
110
111
112long
114 if (getValue() != myDefaultValue) {
115 myResetButton->enable();
116 } else {
117 myResetButton->disable();
118 }
119 return 1;
120}
121
122// ---------------------------------------------------------------------------
123// GNEOptionsDialogElements::InputString - methods
124// ---------------------------------------------------------------------------
125
127 const std::string& topic, const std::string& name, const std::string& description, const std::string& defaultValue) :
128 InputOption(GUIDialogOptions, parent, topic, name, description, defaultValue) {
131 updateOption();
132}
133
134
135void
137 myStringTextField->setText(myGUIDialogOptions->myOptionsContainer.getString(myName).c_str());
138}
139
140
141void
143 myStringTextField->setText(myGUIDialogOptions->myOriginalOptionsContainer.getString(myName).c_str());
144}
145
146
147long
149 myGUIDialogOptions->myOptionsContainer.resetWritable();
150 myGUIDialogOptions->myOptionsContainer.set(myName, myStringTextField->getText().text());
151 myGUIDialogOptions->myOptionsModified = true;
152 return 1;
153}
154
155
156long
158 myStringTextField->setText(myDefaultValue.c_str());
159 return 1;
160}
161
162
163std::string
165 return myStringTextField->getText().text();
166}
167
168
170 const std::string& topic, const std::string& name, const std::string& description, const std::string& defaultValue) :
171 InputOption(GUIDialogOptions, parent, topic, name, description, defaultValue) {
173 updateOption();
174}
175
176
177void
179 myStringVectorTextField->setText(toString(myGUIDialogOptions->myOptionsContainer.getStringVector(myName)).c_str());
180}
181
182
183void
185 myStringVectorTextField->setText(toString(myGUIDialogOptions->myOriginalOptionsContainer.getStringVector(myName)).c_str());
186}
187
188
189long
191 myGUIDialogOptions->myOptionsContainer.resetWritable();
192 myGUIDialogOptions->myOptionsContainer.set(myName, myStringVectorTextField->getText().text());
193 myGUIDialogOptions->myOptionsModified = true;
194 return 1;
195}
196
197
198long
200 myStringVectorTextField->setText(myDefaultValue.c_str());
201 return 1;
202}
203
204
205std::string
207 return myStringVectorTextField->getText().text();
208}
209
210// ---------------------------------------------------------------------------
211// GNEOptionsDialogElements::InputBool - methods
212// ---------------------------------------------------------------------------
213
215 const std::string& topic, const std::string& name, const std::string& description, const std::string& defaultValue) :
216 InputOption(GUIDialogOptions, parent, topic, name, description, defaultValue) {
218 updateOption();
219}
220
221
222void
224 if (myGUIDialogOptions->myOptionsContainer.getBool(myName)) {
225 myCheckButton->setCheck(TRUE);
226 myCheckButton->setText(TL("true"));
227 } else {
228 myCheckButton->setCheck(FALSE);
229 myCheckButton->setText(TL("false"));
230 }
231}
232
233
234void
236 if (myGUIDialogOptions->myOriginalOptionsContainer.getBool(myName)) {
237 myCheckButton->setCheck(TRUE);
238 myCheckButton->setText(TL("true"));
239 } else {
240 myCheckButton->setCheck(FALSE);
241 myCheckButton->setText(TL("false"));
242 }
243}
244
245
246long
248 myGUIDialogOptions->myOptionsContainer.resetWritable();
249 if (myCheckButton->getCheck()) {
250 myGUIDialogOptions->myOptionsContainer.set(myName, "true");
251 myCheckButton->setText(TL("true"));
252 } else {
253 myGUIDialogOptions->myOptionsContainer.set(myName, "false");
254 myCheckButton->setText(TL("false"));
255 }
256 myGUIDialogOptions->myOptionsModified = true;
257 // special checks for Debug flags
258 if ((myName == "gui-testing-debug") && myGUIDialogOptions->myOptionsContainer.isSet("gui-testing-debug")) {
259 MsgHandler::enableDebugMessages(myGUIDialogOptions->myOptionsContainer.getBool("gui-testing-debug"));
260 }
261 if ((myName == "gui-testing-debug-gl") && myGUIDialogOptions->myOptionsContainer.isSet("gui-testing-debug-gl")) {
262 MsgHandler::enableDebugGLMessages(myGUIDialogOptions->myOptionsContainer.getBool("gui-testing-debug-gl"));
263 }
264 return 1;
265}
266
267
268long
270 if (StringUtils::toBool(myDefaultValue)) {
271 myCheckButton->setCheck(TRUE);
272 myCheckButton->setText(TL("true"));
273 } else {
274 myCheckButton->setCheck(FALSE);
275 myCheckButton->setText(TL("false"));
276 }
277 return 1;
278}
279
280
281std::string
283 return myCheckButton->getCheck() ? "true" : "false";
284}
285
286// ---------------------------------------------------------------------------
287// GNEOptionsDialogElements::InputInt - methods
288// ---------------------------------------------------------------------------
289
291 const std::string& topic, const std::string& name, const std::string& description, const std::string& defaultValue) :
292 InputOption(GUIDialogOptions, parent, topic, name, description, defaultValue) {
294 updateOption();
295}
296
297
298void
300 myIntTextField->setText(toString(myGUIDialogOptions->myOptionsContainer.getInt(myName)).c_str());
301}
302
303
304void
306 myIntTextField->setText(toString(myGUIDialogOptions->myOriginalOptionsContainer.getInt(myName)).c_str());
307}
308
309
310long
312 if (myIntTextField->getText().empty()) {
313 myIntTextField->setText(myDefaultValue.c_str());
314 } else {
315 myGUIDialogOptions->myOptionsContainer.resetWritable();
316 myGUIDialogOptions->myOptionsContainer.set(myName, myIntTextField->getText().text());
317 myGUIDialogOptions->myOptionsModified = true;
318 }
319 return 1;
320}
321
322
323long
325 myIntTextField->setText(myDefaultValue.c_str());
326 return 1;
327}
328
329
330std::string
332 return myIntTextField->getText().text();
333}
334
335// ---------------------------------------------------------------------------
336// GNEOptionsDialogElements::InputIntVector - methods
337// ---------------------------------------------------------------------------
338
340 const std::string& topic, const std::string& name, const std::string& description, const std::string& defaultValue) :
341 InputOption(GUIDialogOptions, parent, topic, name, description, defaultValue) {
344 updateOption();
345}
346
347
348void
350 myIntVectorTextField->setText(toString(myGUIDialogOptions->myOptionsContainer.getIntVector(myName)).c_str());
351}
352
353
354void
356 myIntVectorTextField->setText(toString(myGUIDialogOptions->myOriginalOptionsContainer.getIntVector(myName)).c_str());
357}
358
359
360long
362 try {
363 // check that int vector can be parsed
364 const auto intVector = StringTokenizer(myIntVectorTextField->getText().text()).getVector();
365 for (const auto& intValue : intVector) {
366 StringUtils::toInt(intValue);
367 }
368 myGUIDialogOptions->myOptionsContainer.resetWritable();
369 myGUIDialogOptions->myOptionsContainer.set(myName, myIntVectorTextField->getText().text());
370 myIntVectorTextField->setTextColor(FXRGB(0, 0, 0));
371 myGUIDialogOptions->myOptionsModified = true;
372 } catch (...) {
373 myIntVectorTextField->setTextColor(FXRGB(255, 0, 0));
374 }
375 return 1;
376}
377
378
379long
381 myIntVectorTextField->setText(myDefaultValue.c_str());
382 return 1;
383}
384
385
386std::string
388 return myIntVectorTextField->getText().text();
389}
390
391// ---------------------------------------------------------------------------
392// GNEOptionsDialogElements::InputFloat - methods
393// ---------------------------------------------------------------------------
394
395GNEOptionsDialogElements::InputFloat::InputFloat(GNEOptionsDialog* GUIDialogOptions, FXComposite* parent, const std::string& topic,
396 const std::string& name, const std::string& description, const std::string& defaultValue) :
397 InputOption(GUIDialogOptions, parent, topic, name, description, parseFloat(defaultValue)) {
400 updateOption();
401}
402
403
404void
406 myFloatTextField->setText(toString(myGUIDialogOptions->myOptionsContainer.getFloat(myName)).c_str());
407}
408
409
410void
412 myFloatTextField->setText(toString(myGUIDialogOptions->myOriginalOptionsContainer.getFloat(myName)).c_str());
413}
414
415
416long
418 // avoid empty values
419 if (myFloatTextField->getText().empty()) {
420 myFloatTextField->setText(myDefaultValue.c_str());
421 } else {
422 myGUIDialogOptions->myOptionsContainer.resetWritable();
423 myGUIDialogOptions->myOptionsContainer.set(myName, myFloatTextField->getText().text());
424 myGUIDialogOptions->myOptionsModified = true;
425 }
426 return 1;
427}
428
429
430long
432 myFloatTextField->setText(myDefaultValue.c_str());
433 return 1;
434}
435
436
437std::string
439 return myFloatTextField->getText().text();
440}
441
442
443std::string
445 try {
446 return toString(StringUtils::toDouble(value));
447 } catch (...) {
448 return value;
449 }
450}
451
452// ---------------------------------------------------------------------------
453// GNEOptionsDialogElements::InputTime - methods
454// ---------------------------------------------------------------------------
455
456GNEOptionsDialogElements::InputTime::InputTime(GNEOptionsDialog* GUIDialogOptions, FXComposite* parent, const std::string& topic,
457 const std::string& name, const std::string& description, const std::string& defaultValue) :
458 InputOption(GUIDialogOptions, parent, topic, name, description, parseTime(defaultValue)) {
461 updateOption();
462}
463
464
465void
467 myTimeTextField->setText(toString(myGUIDialogOptions->myOptionsContainer.getString(myName)).c_str());
468}
469
470
471void
473 myTimeTextField->setText(toString(myGUIDialogOptions->myOriginalOptionsContainer.getString(myName)).c_str());
474}
475
476
477long
479 // avoid empty values
480 if (myTimeTextField->getText().empty()) {
481 myTimeTextField->setText(myDefaultValue.c_str());
482 } else {
483 myGUIDialogOptions->myOptionsContainer.resetWritable();
484 myGUIDialogOptions->myOptionsContainer.set(myName, myTimeTextField->getText().text());
485 myGUIDialogOptions->myOptionsModified = true;
486 }
487 return 1;
488}
489
490
491long
493 myTimeTextField->setText(myDefaultValue.c_str());
494 return 1;
495}
496
497
498std::string
500 return myTimeTextField->getText().text();
501}
502
503
504std::string
505GNEOptionsDialogElements::InputTime::parseTime(const std::string& value) const {
506 try {
507 return time2string(string2time(value));
508 } catch (...) {
509 return value;
510 }
511}
512
513// ---------------------------------------------------------------------------
514// GNEOptionsDialogElements::InputFilename - methods
515// ---------------------------------------------------------------------------
516
517GNEOptionsDialogElements::InputFilename::InputFilename(GNEOptionsDialog* GUIDialogOptions, FXComposite* parent, const std::string& topic,
518 const std::string& name, const std::string& description, const std::string& defaultValue) :
519 InputOption(GUIDialogOptions, parent, topic, name, description, defaultValue) {
523 updateOption();
524}
525
526
527void
529 myFilenameTextField->setText(myGUIDialogOptions->myOptionsContainer.getString(myName).c_str());
530}
531
532
533void
535 myFilenameTextField->setText(myGUIDialogOptions->myOriginalOptionsContainer.getString(myName).c_str());
536}
537
538
539long
541 // get file
542 const auto file = GNEApplicationWindowHelper::openFileDialog(this, (myName.find("output") != std::string::npos), false);
543 // check that file is valid
544 if (file.size() > 0) {
545 myFilenameTextField->setText(file.c_str(), TRUE);
546 }
547 return 1;
548}
549
550
551long
553 if (SUMOXMLDefinitions::isValidFilename(myFilenameTextField->getText().text())) {
554 myGUIDialogOptions->myOptionsContainer.resetWritable();
555 myGUIDialogOptions->myOptionsContainer.set(myName, myFilenameTextField->getText().text());
556 myFilenameTextField->setTextColor(FXRGB(0, 0, 0));
557 myGUIDialogOptions->myOptionsModified = true;
558 } else {
559 myFilenameTextField->setTextColor(FXRGB(255, 0, 0));
560 }
561 return 1;
562}
563
564
565long
567 myFilenameTextField->setText(myDefaultValue.c_str());
568 return 1;
569}
570
571
573
574
575std::string
577 return myFilenameTextField->getText().text();
578}
579
580/****************************************************************************/
FXDEFMAP(GNEOptionsDialogElements::InputOption) InputOptionMap[]
#define MINNAMEWIDTH
#define MARGIN
@ MID_GNE_SET_ATTRIBUTE
attribute edited
Definition GUIAppEnum.h:939
@ MID_GNE_SET_ATTRIBUTE_DIALOG
attribute edited trough dialog
Definition GUIAppEnum.h:975
@ MID_GNE_RESET
reset element
Definition GUIAppEnum.h:947
#define GUIDesignButtonIcon
button only with icon
Definition GUIDesigns.h:97
#define GUIDesignTextField
Definition GUIDesigns.h:65
#define GUIDesignAuxiliarHorizontalFrame
design for auxiliar (Without borders) horizontal frame used to pack another frames
Definition GUIDesigns.h:405
#define GUIDesignTextFieldNCol
Num of column of text field.
Definition GUIDesigns.h:80
#define GUIDesignCheckButton
checkButton placed in left position
Definition GUIDesigns.h:198
#define GUIDesignTextFieldRestricted(type)
text field extended over Frame with thick frame (int)
Definition GUIDesigns.h:68
#define GUIDesignLabelThickedFixed(width)
label thicked, icon before text, text centered and custom width
Definition GUIDesigns.h:258
@ OPEN
open icons
#define TL(string)
Definition MsgHandler.h:315
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:69
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 openFileDialog(FXWindow *window, bool save, bool multi)
open general file dialog