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
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
62FXIMPLEMENT(GUIDialog_Options::InputString, FXHorizontalFrame, InputStringMap, ARRAYNUMBER(InputStringMap))
63FXIMPLEMENT(GUIDialog_Options::InputStringVector, FXHorizontalFrame, InputStringVectorMap, ARRAYNUMBER(InputStringVectorMap))
64FXIMPLEMENT(GUIDialog_Options::InputBool, FXHorizontalFrame, InputBoolMap, ARRAYNUMBER(InputBoolMap))
65FXIMPLEMENT(GUIDialog_Options::InputInt, FXHorizontalFrame, InputIntMap, ARRAYNUMBER(InputIntMap))
66FXIMPLEMENT(GUIDialog_Options::InputIntVector, FXHorizontalFrame, InputIntVectorMap, ARRAYNUMBER(InputIntVectorMap))
67FXIMPLEMENT(GUIDialog_Options::InputFloat, FXHorizontalFrame, InputFloatMap, ARRAYNUMBER(InputFloatMap))
68FXIMPLEMENT(GUIDialog_Options::InputFilename, FXHorizontalFrame, InputFilenameMap, ARRAYNUMBER(InputFilenameMap))
69
70// ===========================================================================
71// method definitions
72// ===========================================================================
73GUIDialog_Options::GUIDialog_Options(FXWindow* parent, const char* titleName, int width, int height) :
74 FXDialogBox(parent, titleName, GUIDesignDialogBox, 0, 0, width, height) {
76 new FXStatusBar(this, GUIDesignStatusBar);
77 FXVerticalFrame* contentFrame = new FXVerticalFrame(this, GUIDesignContentsFrame);
78 // create tabbook
79 FXTabBook* tabbook = new FXTabBook(contentFrame, nullptr, 0, GUIDesignTabBook);
80 // iterate over all topics
81 for (const auto& topic : oc.getSubTopics()) {
82 // ignore configuration
83 if (topic != "Configuration") {
84 new FXTabItem(tabbook, topic.c_str(), nullptr, TAB_LEFT_NORMAL);
85 FXScrollWindow* scrollTab = new FXScrollWindow(tabbook, LAYOUT_FILL_X | LAYOUT_FILL_Y);
86 FXVerticalFrame* tabContent = new FXVerticalFrame(scrollTab, FRAME_THICK | FRAME_RAISED | LAYOUT_FILL_X | LAYOUT_FILL_Y);
87 const std::vector<std::string> entries = oc.getSubTopicsEntries(topic);
88 for (const auto& entry : entries) {
89 if (entry != "geometry.remove" && entry != "edges.join" && entry != "geometry.split" && entry != "ramps.guess" && entry != "ramps.set") {
90 const std::string type = oc.getTypeName(entry);
91 if (type == "STR") {
92 new InputString(tabContent, entry);
93 } else if (type == "FILE") {
94 new InputFilename(tabContent, entry);
95 } else if (type == "BOOL") {
96 new InputBool(tabContent, entry);
97 } else if (type == "INT") {
98 new InputInt(tabContent, entry);
99 } else if (type == "FLOAT") {
100 new InputFloat(tabContent, entry);
101 } else if (type == "INT[]") {
102 new InputIntVector(tabContent, entry);
103 } else if (type == "STR[]") {
104 new InputStringVector(tabContent, entry);
105 }
106 }
107 }
108 }
109 }
110 // ok-button
111 new FXButton(contentFrame, TL("OK\t\tAccept settings"), GUIIconSubSys::getIcon(GUIIcon::ACCEPT), this, ID_ACCEPT, GUIDesignButtonOK);
112}
113
114
116
117// ===========================================================================
118// Option input classes method definitions
119// ===========================================================================
120
121GUIDialog_Options::InputString::InputString(FXComposite* parent, const std::string& name) :
122 FXHorizontalFrame(parent, LAYOUT_FILL_X),
123 myName(name) {
125 new FXLabel(this, (name + "\t\t" + oc.getDescription(name)).c_str());
126 myTextField = new FXTextField(this, 100, this, MID_GNE_SET_ATTRIBUTE, TEXTFIELD_NORMAL | LAYOUT_RIGHT, 0, 0, 0, 0, 4, 2, 0, 2);
127 myTextField->setText(oc.getString(name).c_str());
128}
129
130
131long
134 oc.resetWritable();
135 oc.set(myName, myTextField->getText().text());
136 return 1;
137}
138
139
140GUIDialog_Options::InputStringVector::InputStringVector(FXComposite* parent, const std::string& name) :
141 FXHorizontalFrame(parent, LAYOUT_FILL_X),
142 myName(name) {
144 new FXLabel(this, (name + "\t\t" + oc.getDescription(name)).c_str());
145 myTextField = new FXTextField(this, 100, this, MID_GNE_SET_ATTRIBUTE, TEXTFIELD_NORMAL | LAYOUT_RIGHT, 0, 0, 0, 0, 4, 2, 0, 2);
146 myTextField->setText(toString(oc.getStringVector(name)).c_str());
147}
148
149
150long
153 oc.resetWritable();
154 oc.set(myName, myTextField->getText().text());
155 return 1;
156}
157
158
159GUIDialog_Options::InputBool::InputBool(FXComposite* parent, const std::string& name) :
160 FXHorizontalFrame(parent, LAYOUT_FILL_X),
161 myName(name) {
163 new FXLabel(this, (name + "\t\t" + oc.getDescription(name)).c_str());
164 myCheck = new FXMenuCheck(this, "", this, MID_GNE_SET_ATTRIBUTE);
165 myCheck->setCheck(oc.getBool(name));
166}
167
168
169long
170GUIDialog_Options::InputBool::onCmdSetOption(FXObject*, FXSelector, void*) {
172 oc.resetWritable();
173 oc.set(myName, myCheck->getCheck() ? "true" : "false");
174 // special checks for Debug flags
175 if ((myName == "gui-testing-debug") && oc.isSet("gui-testing-debug")) {
176 MsgHandler::enableDebugMessages(oc.getBool("gui-testing-debug"));
177 }
178 if ((myName == "gui-testing-debug-gl") && oc.isSet("gui-testing-debug-gl")) {
179 MsgHandler::enableDebugGLMessages(oc.getBool("gui-testing-debug-gl"));
180 }
181 return 1;
182}
183
184
185GUIDialog_Options::InputInt::InputInt(FXComposite* parent, const std::string& name) :
186 FXHorizontalFrame(parent, LAYOUT_FILL_X),
187 myName(name) {
189 new FXLabel(this, (name + "\t\t" + oc.getDescription(name)).c_str());
190 myTextField = new FXTextField(this, 100, this, MID_GNE_SET_ATTRIBUTE, TEXTFIELD_INTEGER | LAYOUT_RIGHT, 0, 0, 0, 0, 4, 2, 0, 2);
191 myTextField->setText(toString(oc.getInt(name)).c_str());
192}
193
194
195long
196GUIDialog_Options::InputInt::onCmdSetOption(FXObject*, FXSelector, void*) {
198 oc.resetWritable();
199 oc.set(myName, myTextField->getText().text());
200 return 1;
201}
202
203
204GUIDialog_Options::InputIntVector::InputIntVector(FXComposite* parent, const std::string& name) :
205 FXHorizontalFrame(parent, LAYOUT_FILL_X),
206 myName(name) {
208 new FXLabel(this, (name + "\t\t" + oc.getDescription(name)).c_str());
209 myTextField = new FXTextField(this, 100, this, MID_GNE_SET_ATTRIBUTE, TEXTFIELD_NORMAL | LAYOUT_RIGHT, 0, 0, 0, 0, 4, 2, 0, 2);
210 myTextField->setText(toString(oc.getIntVector(name)).c_str());
211}
212
213
214long
216 try {
217 // check that int vector can be parsed
218 const auto intVector = StringTokenizer(myTextField->getText().text()).getVector();
219 for (const auto& intValue : intVector) {
220 StringUtils::toInt(intValue);
221 }
223 oc.resetWritable();
224 oc.set(myName, myTextField->getText().text());
225 myTextField->setTextColor(FXRGB(0, 0, 0));
226 } catch (...) {
227 myTextField->setTextColor(FXRGB(255, 0, 0));
228 }
229 return 1;
230}
231
232
233GUIDialog_Options::InputFloat::InputFloat(FXComposite* parent, const std::string& name) :
234 FXHorizontalFrame(parent, LAYOUT_FILL_X),
235 myName(name) {
237 new FXLabel(this, (name + "\t\t" + oc.getDescription(name)).c_str());
238 myTextField = new FXTextField(this, 100, this, MID_GNE_SET_ATTRIBUTE, TEXTFIELD_REAL | LAYOUT_RIGHT, 0, 0, 0, 0, 4, 2, 0, 2);
239 myTextField->setText(toString(oc.getFloat(name)).c_str());
240}
241
242
243long
246 oc.resetWritable();
247 oc.set(myName, myTextField->getText().text());
248 return 1;
249}
250
251
252GUIDialog_Options::InputFilename::InputFilename(FXComposite* parent, const std::string& name) :
253 FXHorizontalFrame(parent, LAYOUT_FILL_X),
254 myName(name) {
256 new FXLabel(this, (name + "\t\t" + oc.getDescription(name)).c_str());
257 myTextField = new FXTextField(this, 100, this, MID_GNE_SET_ATTRIBUTE, TEXTFIELD_NORMAL | LAYOUT_RIGHT, 0, 0, 0, 0, 4, 2, 0, 2);
258 myTextField->setText(oc.getString(name).c_str());
259}
260
261
262long
264 if (SUMOXMLDefinitions::isValidFilename(myTextField->getText().text())) {
266 oc.resetWritable();
267 oc.set(myName, myTextField->getText().text());
268 myTextField->setTextColor(FXRGB(0, 0, 0));
269 } else {
270 myTextField->setTextColor(FXRGB(255, 0, 0));
271 }
272 return 1;
273}
274
275/****************************************************************************/
@ MID_GNE_SET_ATTRIBUTE
attribute edited
Definition: GUIAppEnum.h:870
#define GUIDesignTabBook
desgin for TabBooks
Definition: GUIDesigns.h:680
#define GUIDesignContentsFrame
design for the main content frame of every frame/dialog
Definition: GUIDesigns.h:388
#define GUIDesignDialogBox
Definition: GUIDesigns.h:584
#define GUIDesignButtonOK
Definition: GUIDesigns.h:142
#define GUIDesignStatusBar
design used in status bar
Definition: GUIDesigns.h:435
FXDEFMAP(GUIDialog_Options::InputString) InputStringMap[]
#define TL(string)
Definition: MsgHandler.h:282
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:111
static void enableDebugMessages(bool enable)
enable/disable debug messages
Definition: MsgHandler.cpp:106
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)
int getInt(const std::string &name) const
Returns the int-value of the named option (only for Option_Integer)
const std::vector< std::string > & getSubTopics() const
return the list of subtopics
Definition: OptionsCont.h:641
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)
std::string getTypeName(const std::string name)
return the type name for the given option
Definition: OptionsCont.h:657
bool set(const std::string &name, const std::string &value, const bool append=false)
Sets the given value for the named option.
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:59
std::vector< std::string > getSubTopicsEntries(const std::string &subtopic) const
return the list of entries for the given subtopic
Definition: OptionsCont.h:647
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,...