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-2020 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 
26 #include <utils/common/ToString.h>
30 
31 #include "GUIDialog_Options.h"
32 
33 
34 // ===========================================================================
35 // FOX callback mapping
36 // ===========================================================================
39 };
42 };
45 };
48 };
49 
50 // Object implementation
51 FXIMPLEMENT(GUIDialog_Options::InputString, FXHorizontalFrame, InputStringMap, ARRAYNUMBER(InputStringMap))
52 FXIMPLEMENT(GUIDialog_Options::InputBool, FXHorizontalFrame, InputBoolMap, ARRAYNUMBER(InputBoolMap))
53 FXIMPLEMENT(GUIDialog_Options::InputInt, FXHorizontalFrame, InputIntMap, ARRAYNUMBER(InputIntMap))
54 FXIMPLEMENT(GUIDialog_Options::InputFloat, FXHorizontalFrame, InputFloatMap, ARRAYNUMBER(InputFloatMap))
55 
56 // ===========================================================================
57 // method definitions
58 // ===========================================================================
59 GUIDialog_Options::GUIDialog_Options(FXWindow* parent, const char* titleName, int width, int height) :
60  FXDialogBox(parent, titleName, GUIDesignDialogBox, 0, 0, width, height) {
61  //new FXToolTip(getApp(), TOOLTIP_VARIABLE); // not working
63  new FXStatusBar(this, GUIDesignStatusBar);
64  FXVerticalFrame* contentFrame = new FXVerticalFrame(this, GUIDesignContentsFrame);
65 
66  FXTabBook* tabbook = new FXTabBook(contentFrame, nullptr, 0, GUIDesignTabBook);
67 
68  for (auto it_topic : oc.getSubTopics()) {
69  if (it_topic == "Configuration") {
70  continue;
71  }
72  new FXTabItem(tabbook, it_topic.c_str(), nullptr, TAB_LEFT_NORMAL);
73  FXScrollWindow* scrollTab = new FXScrollWindow(tabbook, LAYOUT_FILL_X | LAYOUT_FILL_Y);
74  FXVerticalFrame* tabContent = new FXVerticalFrame(scrollTab, FRAME_THICK | FRAME_RAISED | LAYOUT_FILL_X | LAYOUT_FILL_Y);
75  const std::vector<std::string> entries = oc.getSubTopicsEntries(it_topic);
76  for (auto it_opt : entries) {
77  if (it_opt != "geometry.remove" && it_opt != "edges.join" && it_opt != "geometry.split" && it_opt != "ramps.guess" && it_opt != "ramps.set") {
78  std::string type = oc.getTypeName(it_opt);
79  if (type == "STR" || type == "FILE") {
80  new InputString(tabContent, it_opt);
81  } else if (type == "BOOL") {
82  new InputBool(tabContent, it_opt);
83  } else if (type == "INT") {
84  new InputInt(tabContent, it_opt);
85  } else if (type == "FLOAT") {
86  new InputFloat(tabContent, it_opt);
87  }
88  // @todo missing types (type INT[] is only used in microsim)
89  }
90  }
91  }
92 
93  // ok-button
94  new FXButton(contentFrame, "OK\t\tAccept settings", GUIIconSubSys::getIcon(GUIIcon::ACCEPT), this, ID_ACCEPT, GUIDesignButtonOK);
95 }
96 
97 
99 
100 // ===========================================================================
101 // Option input classes method definitions
102 // ===========================================================================
103 GUIDialog_Options::InputString::InputString(FXComposite* parent, const std::string& name) :
104  FXHorizontalFrame(parent, LAYOUT_FILL_X),
105  myName(name) {
107  new FXLabel(this, (name + "\t\t" + oc.getDescription(name)).c_str());
108  myTextField = new FXTextField(this, 100, this, MID_GNE_SET_ATTRIBUTE, TEXTFIELD_NORMAL | LAYOUT_RIGHT, 0, 0, 0, 0, 4, 2, 0, 2);
109  myTextField->setText(oc.getString(name).c_str());
110 }
111 
112 
113 long
114 GUIDialog_Options::InputString::onCmdSetOption(FXObject*, FXSelector, void*) {
116  oc.resetWritable();
117  oc.set(myName, myTextField->getText().text());
118  return 1;
119 }
120 
121 
122 GUIDialog_Options::InputBool::InputBool(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  myCheck = new FXMenuCheck(this, "", this, MID_GNE_SET_ATTRIBUTE);
128  myCheck->setCheck(oc.getBool(name));
129 }
130 
131 
132 long
133 GUIDialog_Options::InputBool::onCmdSetOption(FXObject*, FXSelector, void*) {
135  oc.resetWritable();
136  oc.set(myName, myCheck->getCheck() ? "true" : "false");
137  // special checks for Debug flags
138  if ((myName == "gui-testing-debug") && oc.isSet("gui-testing-debug")) {
139  MsgHandler::enableDebugMessages(oc.getBool("gui-testing-debug"));
140  }
141  if ((myName == "gui-testing-debug-gl") && oc.isSet("gui-testing-debug-gl")) {
142  MsgHandler::enableDebugGLMessages(oc.getBool("gui-testing-debug-gl"));
143  }
144  return 1;
145 }
146 
147 
148 GUIDialog_Options::InputInt::InputInt(FXComposite* parent, const std::string& name) :
149  FXHorizontalFrame(parent, LAYOUT_FILL_X),
150  myName(name) {
152  new FXLabel(this, (name + "\t\t" + oc.getDescription(name)).c_str());
153  myTextField = new FXTextField(this, 100, this, MID_GNE_SET_ATTRIBUTE, TEXTFIELD_INTEGER | LAYOUT_RIGHT, 0, 0, 0, 0, 4, 2, 0, 2);
154  myTextField->setText(toString(oc.getInt(name)).c_str());
155 }
156 
157 
158 long
159 GUIDialog_Options::InputInt::onCmdSetOption(FXObject*, FXSelector, void*) {
161  oc.resetWritable();
162  oc.set(myName, myTextField->getText().text());
163  return 1;
164 }
165 
166 
167 GUIDialog_Options::InputFloat::InputFloat(FXComposite* parent, const std::string& name) :
168  FXHorizontalFrame(parent, LAYOUT_FILL_X),
169  myName(name) {
171  new FXLabel(this, (name + "\t\t" + oc.getDescription(name)).c_str());
172  myTextField = new FXTextField(this, 100, this, MID_GNE_SET_ATTRIBUTE, TEXTFIELD_REAL | LAYOUT_RIGHT, 0, 0, 0, 0, 4, 2, 0, 2);
173  myTextField->setText(toString(oc.getFloat(name)).c_str());
174 }
175 
176 
177 long
178 GUIDialog_Options::InputFloat::onCmdSetOption(FXObject*, FXSelector, void*) {
180  oc.resetWritable();
181  oc.set(myName, myTextField->getText().text());
182  return 1;
183 }
184 
185 
186 /****************************************************************************/
@ MID_GNE_SET_ATTRIBUTE
attribute edited
Definition: GUIAppEnum.h:717
#define GUIDesignTabBook
desgin for TabBooks
Definition: GUIDesigns.h:579
#define GUIDesignContentsFrame
design for the main content frame of every frame/dialog
Definition: GUIDesigns.h:322
#define GUIDesignDialogBox
Definition: GUIDesigns.h:494
#define GUIDesignButtonOK
Definition: GUIDesigns.h:115
#define GUIDesignStatusBar
design used in status bar
Definition: GUIDesigns.h:345
FXDEFMAP(GUIDialog_Options::InputString) InputStringMap[]
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:44
InputBool(FXComposite *parent, const std::string &name)
FOX-declaration.
long onCmdSetOption(FXObject *, FXSelector, void *)
try to set new attribute value
FXMenuCheck * myCheck
menu check
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
InputString(FXComposite *parent, const std::string &name)
FOX-declaration.
FXTextField * myTextField
text field
~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
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 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