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-2019 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
14 // The "About" - dialog for NETEDIT, (adapted from GUIDialog_AboutSUMO)
15 /****************************************************************************/
16 
17 
18 // ===========================================================================
19 // included modules
20 // ===========================================================================
21 #include <config.h>
22 
27 #include <utils/common/ToString.h>
31 
32 #include "GUIDialog_Options.h"
33 
34 
35 // ===========================================================================
36 // FOX callback mapping
37 // ===========================================================================
38 FXDEFMAP(GUIDialog_Options::InputString) InputStringMap[] = {
40 };
41 FXDEFMAP(GUIDialog_Options::InputBool) InputBoolMap[] = {
43 };
44 FXDEFMAP(GUIDialog_Options::InputInt) InputIntMap[] = {
46 };
47 FXDEFMAP(GUIDialog_Options::InputFloat) InputFloatMap[] = {
49 };
50 
51 // Object implementation
52 FXIMPLEMENT(GUIDialog_Options::InputString, FXHorizontalFrame, InputStringMap, ARRAYNUMBER(InputStringMap))
53 FXIMPLEMENT(GUIDialog_Options::InputBool, FXHorizontalFrame, InputBoolMap, ARRAYNUMBER(InputBoolMap))
54 FXIMPLEMENT(GUIDialog_Options::InputInt, FXHorizontalFrame, InputIntMap, ARRAYNUMBER(InputIntMap))
55 FXIMPLEMENT(GUIDialog_Options::InputFloat, FXHorizontalFrame, InputFloatMap, ARRAYNUMBER(InputFloatMap))
56 
57 // ===========================================================================
58 // method definitions
59 // ===========================================================================
60 GUIDialog_Options::GUIDialog_Options(FXWindow* parent, const char* titleName, int width, int height) :
61  FXDialogBox(parent, titleName, GUIDesignDialogBox, 0, 0, width, height) {
62  //new FXToolTip(getApp(), TOOLTIP_VARIABLE); // not working
64  new FXStatusBar(this, GUIDesignStatusBar);
65  FXVerticalFrame* contentFrame = new FXVerticalFrame(this, GUIDesignContentsFrame);
66 
67  FXTabBook* tabbook = new FXTabBook(contentFrame, nullptr, 0, GUIDesignTabBook);
68 
69  for (auto it_topic : oc.getSubTopics()) {
70  if (it_topic == "Configuration") {
71  continue;
72  }
73  new FXTabItem(tabbook, it_topic.c_str(), nullptr, TAB_LEFT_NORMAL);
74  FXScrollWindow* scrollTab = new FXScrollWindow(tabbook, LAYOUT_FILL_X | LAYOUT_FILL_Y);
75  FXVerticalFrame* tabContent = new FXVerticalFrame(scrollTab, FRAME_THICK | FRAME_RAISED | LAYOUT_FILL_X | LAYOUT_FILL_Y);
76  const std::vector<std::string> entries = oc.getSubTopicsEntries(it_topic);
77  for (auto it_opt : entries) {
78  if (it_opt != "geometry.remove" && it_opt != "edges.join" && it_opt != "geometry.split" && it_opt != "ramps.guess" && it_opt != "ramps.set") {
79  std::string type = oc.getTypeName(it_opt);
80  if (type == "STR" || type == "FILE") {
81  new InputString(tabContent, it_opt);
82  } else if (type == "BOOL") {
83  new InputBool(tabContent, it_opt);
84  } else if (type == "INT") {
85  new InputInt(tabContent, it_opt);
86  } else if (type == "FLOAT") {
87  new InputFloat(tabContent, it_opt);
88  }
89  // @todo missing types (type INT[] is only used in microsim)
90  }
91  }
92  }
93 
94  // ok-button
95  new FXButton(contentFrame, "OK\t\tAccept settings", GUIIconSubSys::getIcon(ICON_ACCEPT), this, ID_ACCEPT, GUIDesignButtonOK);
96 }
97 
98 
100 
101 // ===========================================================================
102 // Option input classes method definitions
103 // ===========================================================================
104 GUIDialog_Options::InputString::InputString(FXComposite* parent, const std::string& name) :
105  FXHorizontalFrame(parent, LAYOUT_FILL_X),
106  myName(name) {
108  new FXLabel(this, (name + "\t\t" + oc.getDescription(name)).c_str());
109  myTextField = new FXTextField(this, 100, this, MID_GNE_SET_ATTRIBUTE, TEXTFIELD_NORMAL | LAYOUT_RIGHT, 0, 0, 0, 0, 4, 2, 0, 2);
110  myTextField->setText(oc.getString(name).c_str());
111 }
112 
113 
114 long
115 GUIDialog_Options::InputString::onCmdSetOption(FXObject*, FXSelector, void*) {
117  oc.resetWritable();
118  oc.set(myName, myTextField->getText().text());
119  return 1;
120 }
121 
122 
123 GUIDialog_Options::InputBool::InputBool(FXComposite* parent, const std::string& name) :
124  FXHorizontalFrame(parent, LAYOUT_FILL_X),
125  myName(name) {
127  new FXLabel(this, (name + "\t\t" + oc.getDescription(name)).c_str());
128  myCheck = new FXMenuCheck(this, "", this, MID_GNE_SET_ATTRIBUTE);
129  myCheck->setCheck(oc.getBool(name));
130 }
131 
132 
133 long
134 GUIDialog_Options::InputBool::onCmdSetOption(FXObject*, FXSelector, void*) {
136  oc.resetWritable();
137  oc.set(myName, myCheck->getCheck() ? "true" : "false");
138  // special checks for Debug flags
139  if ((myName == "gui-testing-debug") && oc.isSet("gui-testing-debug")) {
140  MsgHandler::enableDebugMessages(oc.getBool("gui-testing-debug"));
141  }
142  if ((myName == "gui-testing-debug-gl") && oc.isSet("gui-testing-debug-gl")) {
143  MsgHandler::enableDebugGLMessages(oc.getBool("gui-testing-debug-gl"));
144  }
145  return 1;
146 }
147 
148 
149 GUIDialog_Options::InputInt::InputInt(FXComposite* parent, const std::string& name) :
150  FXHorizontalFrame(parent, LAYOUT_FILL_X),
151  myName(name) {
153  new FXLabel(this, (name + "\t\t" + oc.getDescription(name)).c_str());
154  myTextField = new FXTextField(this, 100, this, MID_GNE_SET_ATTRIBUTE, TEXTFIELD_INTEGER | LAYOUT_RIGHT, 0, 0, 0, 0, 4, 2, 0, 2);
155  myTextField->setText(toString(oc.getInt(name)).c_str());
156 }
157 
158 
159 long
160 GUIDialog_Options::InputInt::onCmdSetOption(FXObject*, FXSelector, void*) {
162  oc.resetWritable();
163  oc.set(myName, myTextField->getText().text());
164  return 1;
165 }
166 
167 
168 GUIDialog_Options::InputFloat::InputFloat(FXComposite* parent, const std::string& name) :
169  FXHorizontalFrame(parent, LAYOUT_FILL_X),
170  myName(name) {
172  new FXLabel(this, (name + "\t\t" + oc.getDescription(name)).c_str());
173  myTextField = new FXTextField(this, 100, this, MID_GNE_SET_ATTRIBUTE, TEXTFIELD_REAL | LAYOUT_RIGHT, 0, 0, 0, 0, 4, 2, 0, 2);
174  myTextField->setText(toString(oc.getFloat(name)).c_str());
175 }
176 
177 
178 long
179 GUIDialog_Options::InputFloat::onCmdSetOption(FXObject*, FXSelector, void*) {
181  oc.resetWritable();
182  oc.set(myName, myTextField->getText().text());
183  return 1;
184 }
185 
186 
187 /****************************************************************************/
OptionsCont::isSet
bool isSet(const std::string &name, bool failOnNonExistant=true) const
Returns the information whether the named option is set.
Definition: OptionsCont.cpp:135
ICON_ACCEPT
Definition: GUIIcons.h:386
OptionsCont::getInt
int getInt(const std::string &name) const
Returns the int-value of the named option (only for Option_Integer)
Definition: OptionsCont.cpp:215
ToString.h
OptionsCont.h
OptionsCont::resetWritable
void resetWritable()
Resets all options to be writeable.
Definition: OptionsCont.cpp:441
OptionsCont::set
bool set(const std::string &name, const std::string &value)
Sets the given value for the named option.
Definition: OptionsCont.cpp:241
MsgHandler.h
GUIDesignStatusBar
#define GUIDesignStatusBar
design used in status bar
Definition: GUIDesigns.h:304
GUIDialog_Options::InputInt
Definition: GUIDialog_Options.h:96
OptionsCont::getString
std::string getString(const std::string &name) const
Returns the string-value of the named option (only for Option_String)
Definition: OptionsCont.cpp:201
GUIDesignButtonOK
#define GUIDesignButtonOK
Definition: GUIDesigns.h:98
OptionsCont::getSubTopics
const std::vector< std::string > & getSubTopics() const
return the list of subtopics
Definition: OptionsCont.h:637
OptionsCont::getBool
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
Definition: OptionsCont.cpp:222
OptionsCont::getOptions
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:57
GUIDialog_Options::InputBool::myCheck
FXMenuCheck * myCheck
menu check
Definition: GUIDialog_Options.h:92
OptionsCont::getDescription
const std::string & getDescription(const std::string &name) const
Returns the option description.
Definition: OptionsCont.cpp:295
GUIDesigns.h
MID_GNE_SET_ATTRIBUTE
attribute edited
Definition: GUIAppEnum.h:646
GUIIconSubSys::getIcon
static FXIcon * getIcon(GUIIcon which)
returns a icon previously defined in the enum GUIIcon
Definition: GUIIconSubSys.cpp:609
GUIAppEnum.h
MsgHandler::enableDebugGLMessages
static void enableDebugGLMessages(bool enable)
enable/disable gl-debug messages
Definition: MsgHandler.cpp:113
GUIDesignContentsFrame
#define GUIDesignContentsFrame
design for the main content frame of every frame/dialog
Definition: GUIDesigns.h:282
GUIDialog_Options::InputFloat::onCmdSetOption
long onCmdSetOption(FXObject *, FXSelector, void *)
try to set new attribute value
Definition: GUIDialog_Options.cpp:179
GUIDialog_Options::InputString::InputString
InputString(FXComposite *parent, const std::string &name)
FOX-declaration.
Definition: GUIDialog_Options.cpp:104
GUIIOGlobals.h
OptionsCont
A storage for options typed value containers)
Definition: OptionsCont.h:89
FXDEFMAP
FXDEFMAP(GUIDialog_Options::InputString) InputStringMap[]
GUIIconSubSys.h
GUIDialog_Options::~GUIDialog_Options
~GUIDialog_Options()
Destructor.
Definition: GUIDialog_Options.cpp:99
OptionsCont::getFloat
double getFloat(const std::string &name) const
Returns the double-value of the named option (only for Option_Float)
Definition: OptionsCont.cpp:208
toString
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:47
GUIDialog_Options::InputBool::InputBool
InputBool(FXComposite *parent, const std::string &name)
FOX-declaration.
Definition: GUIDialog_Options.cpp:123
GUIDesignTabBook
#define GUIDesignTabBook
desgin for TabBooks
Definition: GUIDesigns.h:525
GUIDialog_Options::InputBool::onCmdSetOption
long onCmdSetOption(FXObject *, FXSelector, void *)
try to set new attribute value
Definition: GUIDialog_Options.cpp:134
OptionsCont::getTypeName
std::string getTypeName(const std::string name)
return the type name for the given option
Definition: OptionsCont.h:653
GUIDialog_Options::InputInt::myTextField
FXTextField * myTextField
text field
Definition: GUIDialog_Options.h:115
OptionsCont::getSubTopicsEntries
std::vector< std::string > getSubTopicsEntries(const std::string &subtopic) const
return the list of entries for the given subtopic
Definition: OptionsCont.h:643
GUIDialog_Options::InputFloat
Definition: GUIDialog_Options.h:118
config.h
GUIDialog_Options
Definition: GUIDialog_Options.h:35
GUIDialog_Options::InputInt::InputInt
InputInt(FXComposite *parent, const std::string &name)
FOX-declaration.
Definition: GUIDialog_Options.cpp:149
GUIDialog_Options::InputInt::onCmdSetOption
long onCmdSetOption(FXObject *, FXSelector, void *)
try to set new attribute value
Definition: GUIDialog_Options.cpp:160
GUIDialog_Options.h
GUIDialog_Options::InputString::onCmdSetOption
long onCmdSetOption(FXObject *, FXSelector, void *)
try to set new attribute value
Definition: GUIDialog_Options.cpp:115
GUIDialog_Options::InputString
Definition: GUIDialog_Options.h:52
GUIDialog_Options::InputFloat::InputFloat
InputFloat(FXComposite *parent, const std::string &name)
FOX-declaration.
Definition: GUIDialog_Options.cpp:168
GUIDialog_Options::InputString::myTextField
FXTextField * myTextField
text field
Definition: GUIDialog_Options.h:71
GUIDesignDialogBox
#define GUIDesignDialogBox
Definition: GUIDesigns.h:433
GUIDialog_Options::InputBool
Definition: GUIDialog_Options.h:74
GUIDialog_Options::InputFloat::myTextField
FXTextField * myTextField
text field
Definition: GUIDialog_Options.h:137
MsgHandler::enableDebugMessages
static void enableDebugMessages(bool enable)
enable/disable debug messages
Definition: MsgHandler.cpp:108