Eclipse SUMO - Simulation of Urban MObility
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 
26 #include <utils/common/ToString.h>
32 
34 #include "GNEOptionsDialog.h"
35 
36 
37 #define MARGING 4
38 #define MINNAMEWIDTH 200
39 
40 // ===========================================================================
41 // FOX callback mapping
42 // ===========================================================================
43 
48 };
49 
52 };
53 
54 // Object implementation
55 FXIMPLEMENT_ABSTRACT(GNEOptionsDialogElements::InputOption, FXHorizontalFrame, InputOptionMap, ARRAYNUMBER(InputOptionMap))
56 FXIMPLEMENT_ABSTRACT(GNEOptionsDialogElements::InputFilename, GNEOptionsDialogElements::InputOption, InputFilenameMap, ARRAYNUMBER(InputFilenameMap))
57 
58 // ===========================================================================
59 // method definitions
60 // ===========================================================================
61 
62 // ---------------------------------------------------------------------------
63 // GNEOptionsDialogElements::InputOption - methods
64 // ---------------------------------------------------------------------------
65 
66 GNEOptionsDialogElements::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 
85 void
87  const int nameWidth = myNameLabel->getFont()->getTextWidth(myNameLabel->getText().text(), myNameLabel->getText().length() + MARGING);
88  if (nameWidth > MINNAMEWIDTH) {
89  myNameLabel->setWidth(nameWidth);
90  }
91 }
92 
93 
94 const std::string&
96  return myTopic;
97 }
98 
99 
100 const std::string
102  return StringUtils::to_lower_case(myName);
103 }
104 
105 
106 const std::string
108  return StringUtils::to_lower_case(myDescription);
109 }
110 
111 
112 long
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 
135 void
137  myStringTextField->setText(myGUIDialogOptions->myOptionsContainer.getString(myName).c_str());
138 }
139 
140 
141 void
143  myStringTextField->setText(myGUIDialogOptions->myOriginalOptionsContainer.getString(myName).c_str());
144 }
145 
146 
147 long
149  myGUIDialogOptions->myOptionsContainer.resetWritable();
150  myGUIDialogOptions->myOptionsContainer.set(myName, myStringTextField->getText().text());
151  myGUIDialogOptions->myOptionsModified = true;
152  return 1;
153 }
154 
155 
156 long
158  myStringTextField->setText(myDefaultValue.c_str());
159  return 1;
160 }
161 
162 
163 std::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 
177 void
179  myStringVectorTextField->setText(toString(myGUIDialogOptions->myOptionsContainer.getStringVector(myName)).c_str());
180 }
181 
182 
183 void
185  myStringVectorTextField->setText(toString(myGUIDialogOptions->myOriginalOptionsContainer.getStringVector(myName)).c_str());
186 }
187 
188 
189 long
191  myGUIDialogOptions->myOptionsContainer.resetWritable();
192  myGUIDialogOptions->myOptionsContainer.set(myName, myStringVectorTextField->getText().text());
193  myGUIDialogOptions->myOptionsModified = true;
194  return 1;
195 }
196 
197 
198 long
200  myStringVectorTextField->setText(myDefaultValue.c_str());
201  return 1;
202 }
203 
204 
205 std::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 
222 void
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 
234 void
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 
246 long
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 
268 long
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 
281 std::string
283  return myCheckButton->getCheck() ? "true" : "false";
284 }
285 
286 // ---------------------------------------------------------------------------
287 // GNEOptionsDialogElements::InputInt - methods
288 // ---------------------------------------------------------------------------
289 
290 GNEOptionsDialogElements::InputInt::InputInt(GNEOptionsDialog* GUIDialogOptions, FXComposite* parent,
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 
298 void
300  myIntTextField->setText(toString(myGUIDialogOptions->myOptionsContainer.getInt(myName)).c_str());
301 }
302 
303 
304 void
306  myIntTextField->setText(toString(myGUIDialogOptions->myOriginalOptionsContainer.getInt(myName)).c_str());
307 }
308 
309 
310 long
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 
323 long
325  myIntTextField->setText(myDefaultValue.c_str());
326  return 1;
327 }
328 
329 
330 std::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 
348 void
350  myIntVectorTextField->setText(toString(myGUIDialogOptions->myOptionsContainer.getIntVector(myName)).c_str());
351 }
352 
353 
354 void
356  myIntVectorTextField->setText(toString(myGUIDialogOptions->myOriginalOptionsContainer.getIntVector(myName)).c_str());
357 }
358 
359 
360 long
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 
379 long
381  myIntVectorTextField->setText(myDefaultValue.c_str());
382  return 1;
383 }
384 
385 
386 std::string
388  return myIntVectorTextField->getText().text();
389 }
390 
391 // ---------------------------------------------------------------------------
392 // GNEOptionsDialogElements::InputFloat - methods
393 // ---------------------------------------------------------------------------
394 
395 GNEOptionsDialogElements::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 
404 void
406  myFloatTextField->setText(toString(myGUIDialogOptions->myOptionsContainer.getFloat(myName)).c_str());
407 }
408 
409 
410 void
412  myFloatTextField->setText(toString(myGUIDialogOptions->myOriginalOptionsContainer.getFloat(myName)).c_str());
413 }
414 
415 
416 long
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 
430 long
432  myFloatTextField->setText(myDefaultValue.c_str());
433  return 1;
434 }
435 
436 
437 std::string
439  return myFloatTextField->getText().text();
440 }
441 
442 
443 std::string
444 GNEOptionsDialogElements::InputFloat::parseFloat(const std::string& value) const {
445  try {
446  return toString(StringUtils::toDouble(value));
447  } catch (...) {
448  return value;
449  }
450 }
451 
452 // ---------------------------------------------------------------------------
453 // GNEOptionsDialogElements::InputFilename - methods
454 // ---------------------------------------------------------------------------
455 
456 GNEOptionsDialogElements::InputFilename::InputFilename(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, defaultValue) {
459  myOpenFilenameButton = GUIDesigns::buildFXButton(myContentFrame, "", "", TL("Select filename"),
462  updateOption();
463 }
464 
465 
466 void
468  myFilenameTextField->setText(myGUIDialogOptions->myOptionsContainer.getString(myName).c_str());
469 }
470 
471 
472 void
474  myFilenameTextField->setText(myGUIDialogOptions->myOriginalOptionsContainer.getString(myName).c_str());
475 }
476 
477 
478 long
480  // get file
481  const auto file = GNEApplicationWindowHelper::openFileDialog(this, (myName.find("output") != std::string::npos), false);
482  // check that file is valid
483  if (file.size() > 0) {
484  myFilenameTextField->setText(file.c_str(), TRUE);
485  }
486  return 1;
487 }
488 
489 
490 long
492  if (SUMOXMLDefinitions::isValidFilename(myFilenameTextField->getText().text())) {
493  myGUIDialogOptions->myOptionsContainer.resetWritable();
494  myGUIDialogOptions->myOptionsContainer.set(myName, myFilenameTextField->getText().text());
495  myFilenameTextField->setTextColor(FXRGB(0, 0, 0));
496  myGUIDialogOptions->myOptionsModified = true;
497  } else {
498  myFilenameTextField->setTextColor(FXRGB(255, 0, 0));
499  }
500  return 1;
501 }
502 
503 
504 long
506  myFilenameTextField->setText(myDefaultValue.c_str());
507  return 1;
508 }
509 
510 
512 
513 
514 std::string
516  return myFilenameTextField->getText().text();
517 }
518 
519 /****************************************************************************/
FXDEFMAP(GNEOptionsDialogElements::InputOption) InputOptionMap[]
#define MARGING
#define MINNAMEWIDTH
@ MID_GNE_SET_ATTRIBUTE
attribute edited
Definition: GUIAppEnum.h:930
@ MID_GNE_SET_ATTRIBUTE_DIALOG
attribute edited trough dialog
Definition: GUIAppEnum.h:966
@ MID_GNE_RESET
reset element
Definition: GUIAppEnum.h:938
#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
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
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
Definition: GUIDesigns.cpp:128
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
Definition: MsgHandler.cpp:124
static void enableDebugMessages(bool enable)
enable/disable debug messages
Definition: MsgHandler.cpp:119
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.
Definition: StringUtils.cpp:77
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