Eclipse SUMO - Simulation of Urban MObility
GUIDialog_Options.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2022 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 // The "About" - dialog for NETEDIT, (adapted from GUIDialog_AboutSUMO)
19 /****************************************************************************/
20 #include <config.h>
21 
25 #include <utils/common/ToString.h>
32 
33 #include "GUIDialog_Options.h"
34 
35 
36 // ===========================================================================
37 // FOX callback mapping
38 // ===========================================================================
41 };
44 };
47 };
50 };
53 };
56 };
59 };
60 
61 // Object implementation
62 FXIMPLEMENT(GUIDialog_Options::InputString, FXHorizontalFrame, InputStringMap, ARRAYNUMBER(InputStringMap))
63 FXIMPLEMENT(GUIDialog_Options::InputStringVector, FXHorizontalFrame, InputStringVectorMap, ARRAYNUMBER(InputStringVectorMap))
64 FXIMPLEMENT(GUIDialog_Options::InputBool, FXHorizontalFrame, InputBoolMap, ARRAYNUMBER(InputBoolMap))
65 FXIMPLEMENT(GUIDialog_Options::InputInt, FXHorizontalFrame, InputIntMap, ARRAYNUMBER(InputIntMap))
66 FXIMPLEMENT(GUIDialog_Options::InputIntVector, FXHorizontalFrame, InputIntVectorMap, ARRAYNUMBER(InputIntVectorMap))
67 FXIMPLEMENT(GUIDialog_Options::InputFloat, FXHorizontalFrame, InputFloatMap, ARRAYNUMBER(InputFloatMap))
68 FXIMPLEMENT(GUIDialog_Options::InputFilename, FXHorizontalFrame, InputFilenameMap, ARRAYNUMBER(InputFilenameMap))
69 
70 // ===========================================================================
71 // method definitions
72 // ===========================================================================
73 GUIDialog_Options::GUIDialog_Options(FXWindow* parent, const char* titleName, int width, int height) :
74  FXDialogBox(parent, titleName, GUIDesignDialogBox, 0, 0, width, height) {
75  //new FXToolTip(getApp(), TOOLTIP_VARIABLE); // not working
77  new FXStatusBar(this, GUIDesignStatusBar);
78  FXVerticalFrame* contentFrame = new FXVerticalFrame(this, GUIDesignContentsFrame);
79  // create tabbook
80  FXTabBook* tabbook = new FXTabBook(contentFrame, nullptr, 0, GUIDesignTabBook);
81  // iterate over all topics
82  for (const auto& topic : oc.getSubTopics()) {
83  // ignore configuration
84  if (topic != "Configuration") {
85  new FXTabItem(tabbook, topic.c_str(), nullptr, TAB_LEFT_NORMAL);
86  FXScrollWindow* scrollTab = new FXScrollWindow(tabbook, LAYOUT_FILL_X | LAYOUT_FILL_Y);
87  FXVerticalFrame* tabContent = new FXVerticalFrame(scrollTab, FRAME_THICK | FRAME_RAISED | LAYOUT_FILL_X | LAYOUT_FILL_Y);
88  const std::vector<std::string> entries = oc.getSubTopicsEntries(topic);
89  for (const auto& entry : entries) {
90  if (entry != "geometry.remove" && entry != "edges.join" && entry != "geometry.split" && entry != "ramps.guess" && entry != "ramps.set") {
91  const std::string type = oc.getTypeName(entry);
92  if (type == "STR") {
93  new InputString(tabContent, entry);
94  } else if (type == "FILE") {
95  new InputFilename(tabContent, entry);
96  } else if (type == "BOOL") {
97  new InputBool(tabContent, entry);
98  } else if (type == "INT") {
99  new InputInt(tabContent, entry);
100  } else if (type == "FLOAT") {
101  new InputFloat(tabContent, entry);
102  } else if (type == "INT[]") {
103  new InputIntVector(tabContent, entry);
104  } else if (type == "STR[]") {
105  new InputStringVector(tabContent, entry);
106  }
107  }
108  }
109  }
110  }
111  // ok-button
112  new FXButton(contentFrame, "OK\t\tAccept settings", GUIIconSubSys::getIcon(GUIIcon::ACCEPT), this, ID_ACCEPT, GUIDesignButtonOK);
113 }
114 
115 
117 
118 // ===========================================================================
119 // Option input classes method definitions
120 // ===========================================================================
121 
122 GUIDialog_Options::InputString::InputString(FXComposite* parent, const std::string& name) :
123  FXHorizontalFrame(parent, LAYOUT_FILL_X),
124  myName(name) {
126  new FXLabel(this, (name + "\t\t" + oc.getDescription(name)).c_str());
127  myTextField = new FXTextField(this, 100, this, MID_GNE_SET_ATTRIBUTE, TEXTFIELD_NORMAL | LAYOUT_RIGHT, 0, 0, 0, 0, 4, 2, 0, 2);
128  myTextField->setText(oc.getString(name).c_str());
129 }
130 
131 
132 long
133 GUIDialog_Options::InputString::onCmdSetOption(FXObject*, FXSelector, void*) {
135  oc.resetWritable();
136  oc.set(myName, myTextField->getText().text());
137  return 1;
138 }
139 
140 
141 GUIDialog_Options::InputStringVector::InputStringVector(FXComposite* parent, const std::string& name) :
142  FXHorizontalFrame(parent, LAYOUT_FILL_X),
143  myName(name) {
145  new FXLabel(this, (name + "\t\t" + oc.getDescription(name)).c_str());
146  myTextField = new FXTextField(this, 100, this, MID_GNE_SET_ATTRIBUTE, TEXTFIELD_NORMAL | LAYOUT_RIGHT, 0, 0, 0, 0, 4, 2, 0, 2);
147  myTextField->setText(toString(oc.getStringVector(name)).c_str());
148 }
149 
150 
151 long
154  oc.resetWritable();
155  oc.set(myName, myTextField->getText().text());
156  return 1;
157 }
158 
159 
160 GUIDialog_Options::InputBool::InputBool(FXComposite* parent, const std::string& name) :
161  FXHorizontalFrame(parent, LAYOUT_FILL_X),
162  myName(name) {
164  new FXLabel(this, (name + "\t\t" + oc.getDescription(name)).c_str());
165  myCheck = new FXMenuCheck(this, "", this, MID_GNE_SET_ATTRIBUTE);
166  myCheck->setCheck(oc.getBool(name));
167 }
168 
169 
170 long
171 GUIDialog_Options::InputBool::onCmdSetOption(FXObject*, FXSelector, void*) {
173  oc.resetWritable();
174  oc.set(myName, myCheck->getCheck() ? "true" : "false");
175  // special checks for Debug flags
176  if ((myName == "gui-testing-debug") && oc.isSet("gui-testing-debug")) {
177  MsgHandler::enableDebugMessages(oc.getBool("gui-testing-debug"));
178  }
179  if ((myName == "gui-testing-debug-gl") && oc.isSet("gui-testing-debug-gl")) {
180  MsgHandler::enableDebugGLMessages(oc.getBool("gui-testing-debug-gl"));
181  }
182  return 1;
183 }
184 
185 
186 GUIDialog_Options::InputInt::InputInt(FXComposite* parent, const std::string& name) :
187  FXHorizontalFrame(parent, LAYOUT_FILL_X),
188  myName(name) {
190  new FXLabel(this, (name + "\t\t" + oc.getDescription(name)).c_str());
191  myTextField = new FXTextField(this, 100, this, MID_GNE_SET_ATTRIBUTE, TEXTFIELD_INTEGER | LAYOUT_RIGHT, 0, 0, 0, 0, 4, 2, 0, 2);
192  myTextField->setText(toString(oc.getInt(name)).c_str());
193 }
194 
195 
196 long
197 GUIDialog_Options::InputInt::onCmdSetOption(FXObject*, FXSelector, void*) {
199  oc.resetWritable();
200  oc.set(myName, myTextField->getText().text());
201  return 1;
202 }
203 
204 
205 GUIDialog_Options::InputIntVector::InputIntVector(FXComposite* parent, const std::string& name) :
206  FXHorizontalFrame(parent, LAYOUT_FILL_X),
207  myName(name) {
209  new FXLabel(this, (name + "\t\t" + oc.getDescription(name)).c_str());
210  myTextField = new FXTextField(this, 100, this, MID_GNE_SET_ATTRIBUTE, TEXTFIELD_NORMAL | LAYOUT_RIGHT, 0, 0, 0, 0, 4, 2, 0, 2);
211  myTextField->setText(toString(oc.getIntVector(name)).c_str());
212 }
213 
214 
215 long
217  try {
218  // check that int vector can be parsed
219  const auto intVector = StringTokenizer(myTextField->getText().text()).getVector();
220  for (const auto& intValue : intVector) {
221  StringUtils::toInt(intValue);
222  }
224  oc.resetWritable();
225  oc.set(myName, myTextField->getText().text());
226  myTextField->setTextColor(FXRGB(0, 0, 0));
227  } catch (...) {
228  myTextField->setTextColor(FXRGB(255, 0, 0));
229  }
230  return 1;
231 }
232 
233 
234 GUIDialog_Options::InputFloat::InputFloat(FXComposite* parent, const std::string& name) :
235  FXHorizontalFrame(parent, LAYOUT_FILL_X),
236  myName(name) {
238  new FXLabel(this, (name + "\t\t" + oc.getDescription(name)).c_str());
239  myTextField = new FXTextField(this, 100, this, MID_GNE_SET_ATTRIBUTE, TEXTFIELD_REAL | LAYOUT_RIGHT, 0, 0, 0, 0, 4, 2, 0, 2);
240  myTextField->setText(toString(oc.getFloat(name)).c_str());
241 }
242 
243 
244 long
245 GUIDialog_Options::InputFloat::onCmdSetOption(FXObject*, FXSelector, void*) {
247  oc.resetWritable();
248  oc.set(myName, myTextField->getText().text());
249  return 1;
250 }
251 
252 
253 GUIDialog_Options::InputFilename::InputFilename(FXComposite* parent, const std::string& name) :
254  FXHorizontalFrame(parent, LAYOUT_FILL_X),
255  myName(name) {
257  new FXLabel(this, (name + "\t\t" + oc.getDescription(name)).c_str());
258  myTextField = new FXTextField(this, 100, this, MID_GNE_SET_ATTRIBUTE, TEXTFIELD_NORMAL | LAYOUT_RIGHT, 0, 0, 0, 0, 4, 2, 0, 2);
259  myTextField->setText(oc.getString(name).c_str());
260 }
261 
262 
263 long
265  if (SUMOXMLDefinitions::isValidFilename(myTextField->getText().text())) {
267  oc.resetWritable();
268  oc.set(myName, myTextField->getText().text());
269  myTextField->setTextColor(FXRGB(0, 0, 0));
270  } else {
271  myTextField->setTextColor(FXRGB(255, 0, 0));
272  }
273  return 1;
274 }
275 
276 /****************************************************************************/
@ MID_GNE_SET_ATTRIBUTE
attribute edited
Definition: GUIAppEnum.h:797
#define GUIDesignTabBook
desgin for TabBooks
Definition: GUIDesigns.h:627
#define GUIDesignContentsFrame
design for the main content frame of every frame/dialog
Definition: GUIDesigns.h:352
#define GUIDesignDialogBox
Definition: GUIDesigns.h:527
#define GUIDesignButtonOK
Definition: GUIDesigns.h:124
#define GUIDesignStatusBar
design used in status bar
Definition: GUIDesigns.h:378
FXDEFMAP(GUIDialog_Options::InputString) InputStringMap[]
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:46
InputBool(FXComposite *parent, const std::string &name)
FOX-declaration.
long onCmdSetOption(FXObject *, FXSelector, void *)
try to set new attribute value
FXMenuCheck * myCheck
menu check
InputFilename(FXComposite *parent, const std::string &name)
FOX-declaration.
long onCmdSetOption(FXObject *, FXSelector, void *)
try to set new attribute value
FXTextField * myTextField
text field
long onCmdSetOption(FXObject *, FXSelector, void *)
try to set new attribute value
InputFloat(FXComposite *parent, const std::string &name)
FOX-declaration.
FXTextField * myTextField
text field
long onCmdSetOption(FXObject *, FXSelector, void *)
try to set new attribute value
FXTextField * myTextField
text field
InputInt(FXComposite *parent, const std::string &name)
FOX-declaration.
long onCmdSetOption(FXObject *, FXSelector, void *)
try to set new attribute value
FXTextField * myTextField
text field
InputIntVector(FXComposite *parent, const std::string &name)
FOX-declaration.
long onCmdSetOption(FXObject *, FXSelector, void *)
try to set new attribute value
InputString(FXComposite *parent, const std::string &name)
FOX-declaration.
FXTextField * myTextField
text field
InputStringVector(FXComposite *parent, const std::string &name)
FOX-declaration.
long onCmdSetOption(FXObject *, FXSelector, void *)
try to set new attribute value
~GUIDialog_Options()
Destructor.
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:112
static void enableDebugMessages(bool enable)
enable/disable debug messages
Definition: MsgHandler.cpp:107
A storage for options typed value containers)
Definition: OptionsCont.h:89
bool isSet(const std::string &name, bool failOnNonExistant=true) const
Returns the information whether the named option is set.
double getFloat(const std::string &name) const
Returns the double-value of the named option (only for Option_Float)
bool set(const std::string &name, const std::string &value)
Sets the given value for the named option.
int getInt(const std::string &name) const
Returns the int-value of the named option (only for Option_Integer)
std::vector< std::string > getSubTopicsEntries(const std::string &subtopic) const
return the list of entries for the given subtopic
Definition: OptionsCont.h:654
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)
const std::vector< std::string > & getSubTopics() const
return the list of subtopics
Definition: OptionsCont.h:648
std::string getTypeName(const std::string name)
return the type name for the given option
Definition: OptionsCont.h:664
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
const StringVector & getStringVector(const std::string &name) const
Returns the list of string-value of the named option (only for Option_StringVector)
const std::string & getDescription(const std::string &name) const
Returns the option description.
void resetWritable()
Resets all options to be writeable.
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:58
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 int toInt(const std::string &sData)
converts a string into the integer value described by it by calling the char-type converter,...