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 /****************************************************************************/
15 // The "About" - dialog for NETEDIT, (adapted from GUIDialog_AboutSUMO)
16 /****************************************************************************/
17 
18 
19 // ===========================================================================
20 // included modules
21 // ===========================================================================
22 #include <config.h>
23 
28 #include <utils/common/ToString.h>
32 
33 #include "GUIDialog_Options.h"
34 
35 
36 // ===========================================================================
37 // FOX callback mapping
38 // ===========================================================================
39 FXDEFMAP(GUIDialog_Options::InputString) InputStringMap[] = {
41 };
42 FXDEFMAP(GUIDialog_Options::InputBool) InputBoolMap[] = {
44 };
45 FXDEFMAP(GUIDialog_Options::InputInt) InputIntMap[] = {
47 };
48 FXDEFMAP(GUIDialog_Options::InputFloat) InputFloatMap[] = {
50 };
51 
52 // Object implementation
53 FXIMPLEMENT(GUIDialog_Options::InputString, FXHorizontalFrame, InputStringMap, ARRAYNUMBER(InputStringMap))
54 FXIMPLEMENT(GUIDialog_Options::InputBool, FXHorizontalFrame, InputBoolMap, ARRAYNUMBER(InputBoolMap))
55 FXIMPLEMENT(GUIDialog_Options::InputInt, FXHorizontalFrame, InputIntMap, ARRAYNUMBER(InputIntMap))
56 FXIMPLEMENT(GUIDialog_Options::InputFloat, FXHorizontalFrame, InputFloatMap, ARRAYNUMBER(InputFloatMap))
57 
58 // ===========================================================================
59 // method definitions
60 // ===========================================================================
61 GUIDialog_Options::GUIDialog_Options(FXWindow* parent, const char* titleName, int width, int height) :
62  FXDialogBox(parent, titleName, GUIDesignDialogBox, 0, 0, width, height) {
63  //new FXToolTip(getApp(), TOOLTIP_VARIABLE); // not working
65  new FXStatusBar(this, GUIDesignStatusBar);
66  FXVerticalFrame* contentFrame = new FXVerticalFrame(this, GUIDesignContentsFrame);
67 
68  FXTabBook* tabbook = new FXTabBook(contentFrame, nullptr, 0, GUIDesignTabBook);
69 
70  for (auto it_topic : oc.getSubTopics()) {
71  if (it_topic == "Configuration") {
72  continue;
73  }
74  new FXTabItem(tabbook, it_topic.c_str(), nullptr, TAB_LEFT_NORMAL);
75  FXScrollWindow* scrollTab = new FXScrollWindow(tabbook, LAYOUT_FILL_X | LAYOUT_FILL_Y);
76  FXVerticalFrame* tabContent = new FXVerticalFrame(scrollTab, FRAME_THICK | FRAME_RAISED | LAYOUT_FILL_X | LAYOUT_FILL_Y);
77  const std::vector<std::string> entries = oc.getSubTopicsEntries(it_topic);
78  for (auto it_opt : entries) {
79  if (it_opt != "geometry.remove" && it_opt != "edges.join" && it_opt != "geometry.split" && it_opt != "ramps.guess" && it_opt != "ramps.set") {
80  std::string type = oc.getTypeName(it_opt);
81  if (type == "STR" || type == "FILE") {
82  new InputString(tabContent, it_opt);
83  } else if (type == "BOOL") {
84  new InputBool(tabContent, it_opt);
85  } else if (type == "INT") {
86  new InputInt(tabContent, it_opt);
87  } else if (type == "FLOAT") {
88  new InputFloat(tabContent, it_opt);
89  }
90  // @todo missing types (type INT[] is only used in microsim)
91  }
92  }
93  }
94 
95  // ok-button
96  new FXButton(contentFrame, "OK\t\tAccept settings", GUIIconSubSys::getIcon(ICON_ACCEPT), this, ID_ACCEPT, GUIDesignButtonOK);
97 }
98 
99 
101 
102 // ===========================================================================
103 // Option input classes method definitions
104 // ===========================================================================
105 GUIDialog_Options::InputString::InputString(FXComposite* parent, const std::string& name) :
106  FXHorizontalFrame(parent, LAYOUT_FILL_X),
107  myName(name) {
109  new FXLabel(this, (name + "\t\t" + oc.getDescription(name)).c_str());
110  myTextField = new FXTextField(this, 100, this, MID_GNE_SET_ATTRIBUTE, TEXTFIELD_NORMAL | LAYOUT_RIGHT, 0, 0, 0, 0, 4, 2, 0, 2);
111  myTextField->setText(oc.getString(name).c_str());
112 }
113 
114 
115 long
116 GUIDialog_Options::InputString::onCmdSetOption(FXObject*, FXSelector, void*) {
118  oc.resetWritable();
119  oc.set(myName, myTextField->getText().text());
120  return 1;
121 }
122 
123 
124 GUIDialog_Options::InputBool::InputBool(FXComposite* parent, const std::string& name) :
125  FXHorizontalFrame(parent, LAYOUT_FILL_X),
126  myName(name) {
128  new FXLabel(this, (name + "\t\t" + oc.getDescription(name)).c_str());
129  myCheck = new FXMenuCheck(this, "", this, MID_GNE_SET_ATTRIBUTE);
130  myCheck->setCheck(oc.getBool(name));
131 }
132 
133 
134 long
135 GUIDialog_Options::InputBool::onCmdSetOption(FXObject*, FXSelector, void*) {
137  oc.resetWritable();
138  oc.set(myName, myCheck->getCheck() ? "true" : "false");
139  // special checks for Debug flags
140  if ((myName == "gui-testing-debug") && oc.isSet("gui-testing-debug")) {
141  MsgHandler::enableDebugMessages(oc.getBool("gui-testing-debug"));
142  }
143  if ((myName == "gui-testing-debug-gl") && oc.isSet("gui-testing-debug-gl")) {
144  MsgHandler::enableDebugGLMessages(oc.getBool("gui-testing-debug-gl"));
145  }
146  return 1;
147 }
148 
149 
150 GUIDialog_Options::InputInt::InputInt(FXComposite* parent, const std::string& name) :
151  FXHorizontalFrame(parent, LAYOUT_FILL_X),
152  myName(name) {
154  new FXLabel(this, (name + "\t\t" + oc.getDescription(name)).c_str());
155  myTextField = new FXTextField(this, 100, this, MID_GNE_SET_ATTRIBUTE, TEXTFIELD_INTEGER | LAYOUT_RIGHT, 0, 0, 0, 0, 4, 2, 0, 2);
156  myTextField->setText(toString(oc.getInt(name)).c_str());
157 }
158 
159 
160 long
161 GUIDialog_Options::InputInt::onCmdSetOption(FXObject*, FXSelector, void*) {
163  oc.resetWritable();
164  oc.set(myName, myTextField->getText().text());
165  return 1;
166 }
167 
168 
169 GUIDialog_Options::InputFloat::InputFloat(FXComposite* parent, const std::string& name) :
170  FXHorizontalFrame(parent, LAYOUT_FILL_X),
171  myName(name) {
173  new FXLabel(this, (name + "\t\t" + oc.getDescription(name)).c_str());
174  myTextField = new FXTextField(this, 100, this, MID_GNE_SET_ATTRIBUTE, TEXTFIELD_REAL | LAYOUT_RIGHT, 0, 0, 0, 0, 4, 2, 0, 2);
175  myTextField->setText(toString(oc.getFloat(name)).c_str());
176 }
177 
178 
179 long
180 GUIDialog_Options::InputFloat::onCmdSetOption(FXObject*, FXSelector, void*) {
182  oc.resetWritable();
183  oc.set(myName, myTextField->getText().text());
184  return 1;
185 }
186 
187 
188 /****************************************************************************/
OptionsCont::isSet
bool isSet(const std::string &name, bool failOnNonExistant=true) const
Returns the information whether the named option is set.
Definition: OptionsCont.cpp:136
GUIDialog_Options::InputBool::InputBool
InputBool()
FOX needs this.
Definition: GUIDialog_Options.h:89
ICON_ACCEPT
Definition: GUIIcons.h:380
OptionsCont::getInt
int getInt(const std::string &name) const
Returns the int-value of the named option (only for Option_Integer)
Definition: OptionsCont.cpp:216
ToString.h
GUIDialog_Options::InputString::InputString
InputString()
FOX needs this.
Definition: GUIDialog_Options.h:66
OptionsCont.h
OptionsCont::resetWritable
void resetWritable()
Resets all options to be writeable.
Definition: OptionsCont.cpp:445
OptionsCont::set
bool set(const std::string &name, const std::string &value)
Sets the given value for the named option.
Definition: OptionsCont.cpp:244
MsgHandler.h
GUIDesignStatusBar
#define GUIDesignStatusBar
design used in status bar
Definition: GUIDesigns.h:320
GUIDialog_Options::InputInt
Definition: GUIDialog_Options.h:99
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:202
GUIDesignButtonOK
#define GUIDesignButtonOK
Definition: GUIDesigns.h:114
OptionsCont::getSubTopics
const std::vector< std::string > & getSubTopics() const
return the list of subtopics
Definition: OptionsCont.h:653
OptionsCont::getBool
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
Definition: OptionsCont.cpp:223
OptionsCont::getOptions
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:58
GUIDialog_Options::InputBool::myCheck
FXMenuCheck * myCheck
menu check
Definition: GUIDialog_Options.h:95
GUIDialog_Options::InputFloat::InputFloat
InputFloat()
FOX needs this.
Definition: GUIDialog_Options.h:135
OptionsCont::getDescription
const std::string & getDescription(const std::string &name) const
Returns the option description.
Definition: OptionsCont.cpp:298
GUIDesigns.h
MID_GNE_SET_ATTRIBUTE
attribute edited
Definition: GUIAppEnum.h:619
GUIIconSubSys::getIcon
static FXIcon * getIcon(GUIIcon which)
returns a icon previously defined in the enum GUIIcon
Definition: GUIIconSubSys.cpp:602
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:298
GUIDialog_Options::InputFloat::onCmdSetOption
long onCmdSetOption(FXObject *, FXSelector, void *)
try to set new attribute value
Definition: GUIDialog_Options.cpp:180
GUIIOGlobals.h
OptionsCont
A storage for options typed value containers)
Definition: OptionsCont.h:90
FXDEFMAP
FXDEFMAP(GUIDialog_Options::InputString) InputStringMap[]
GUIIconSubSys.h
GUIDialog_Options::~GUIDialog_Options
~GUIDialog_Options()
Destructor.
Definition: GUIDialog_Options.cpp:100
OptionsCont::getFloat
double getFloat(const std::string &name) const
Returns the double-value of the named option (only for Option_Float)
Definition: OptionsCont.cpp:209
toString
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:48
GUIDesignTabBook
#define GUIDesignTabBook
desgin for TabBooks
Definition: GUIDesigns.h:541
GUIDialog_Options::InputBool::onCmdSetOption
long onCmdSetOption(FXObject *, FXSelector, void *)
try to set new attribute value
Definition: GUIDialog_Options.cpp:135
OptionsCont::getTypeName
std::string getTypeName(const std::string name)
return the type name for the given option
Definition: OptionsCont.h:669
GUIDialog_Options::InputInt::myTextField
FXTextField * myTextField
text field
Definition: GUIDialog_Options.h:119
OptionsCont::getSubTopicsEntries
std::vector< std::string > getSubTopicsEntries(const std::string &subtopic) const
return the list of entries for the given subtopic
Definition: OptionsCont.h:659
GUIDialog_Options::InputFloat
Definition: GUIDialog_Options.h:122
config.h
GUIDialog_Options
Definition: GUIDialog_Options.h:36
GUIDialog_Options::InputInt::onCmdSetOption
long onCmdSetOption(FXObject *, FXSelector, void *)
try to set new attribute value
Definition: GUIDialog_Options.cpp:161
GUIDialog_Options.h
GUIDialog_Options::InputString::onCmdSetOption
long onCmdSetOption(FXObject *, FXSelector, void *)
try to set new attribute value
Definition: GUIDialog_Options.cpp:116
GUIDialog_Options::InputString
Definition: GUIDialog_Options.h:53
GUIDialog_Options::InputInt::InputInt
InputInt()
FOX needs this.
Definition: GUIDialog_Options.h:112
GUIDialog_Options::InputString::myTextField
FXTextField * myTextField
text field
Definition: GUIDialog_Options.h:73
GUIDesignDialogBox
#define GUIDesignDialogBox
Definition: GUIDesigns.h:449
GUIDialog_Options::InputBool
Definition: GUIDialog_Options.h:76
GUIDialog_Options::InputFloat::myTextField
FXTextField * myTextField
text field
Definition: GUIDialog_Options.h:142
MsgHandler::enableDebugMessages
static void enableDebugMessages(bool enable)
enable/disable debug messages
Definition: MsgHandler.cpp:108