SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
GNEDialog_Wizard.cpp
Go to the documentation of this file.
1 /****************************************************************************/
7 // The "About" - dialog for NETEDIT, (adapted from GUIDialog_AboutSUMO)
8 /****************************************************************************/
9 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
10 // Copyright (C) 2001-2016 DLR (http://www.dlr.de/) and contributors
11 /****************************************************************************/
12 //
13 // This file is part of SUMO.
14 // SUMO is free software: you can redistribute it and/or modify
15 // it under the terms of the GNU General Public License as published by
16 // the Free Software Foundation, either version 3 of the License, or
17 // (at your option) any later version.
18 //
19 /****************************************************************************/
20 
21 
22 // ===========================================================================
23 // included modules
24 // ===========================================================================
25 #ifdef _MSC_VER
26 #include <windows_config.h>
27 #else
28 #include <config.h>
29 #endif
30 
31 #ifdef HAVE_VERSION_H
32 #include <version.h>
33 #endif
34 
39 #include <utils/common/ToString.h>
40 #include "GNEDialog_Wizard.h"
41 
42 #ifdef CHECK_MEMORY_LEAKS
43 #include <foreign/nvwa/debug_new.h>
44 #endif // CHECK_MEMORY_LEAKS
45 
46 
47 // ===========================================================================
48 // FOX callback mapping
49 // ===========================================================================
50 FXDEFMAP(GNEDialog_Wizard::InputString) InputStringMap[] = {
52 };
53 FXDEFMAP(GNEDialog_Wizard::InputBool) InputBoolMap[] = {
55 };
56 FXDEFMAP(GNEDialog_Wizard::InputInt) InputIntMap[] = {
58 };
59 FXDEFMAP(GNEDialog_Wizard::InputFloat) InputFloatMap[] = {
61 };
62 
63 // Object implementation
64 FXIMPLEMENT(GNEDialog_Wizard::InputString, FXHorizontalFrame, InputStringMap, ARRAYNUMBER(InputStringMap))
65 FXIMPLEMENT(GNEDialog_Wizard::InputBool, FXHorizontalFrame, InputBoolMap, ARRAYNUMBER(InputBoolMap))
66 FXIMPLEMENT(GNEDialog_Wizard::InputInt, FXHorizontalFrame, InputIntMap, ARRAYNUMBER(InputIntMap))
67 FXIMPLEMENT(GNEDialog_Wizard::InputFloat, FXHorizontalFrame, InputFloatMap, ARRAYNUMBER(InputFloatMap))
68 
69 // ===========================================================================
70 // method definitions
71 // ===========================================================================
72 GNEDialog_Wizard::GNEDialog_Wizard(FXWindow* parent, const char* name, int width, int height) :
73  FXDialogBox(parent, name, DECOR_CLOSE | DECOR_TITLE, 0, 0, width, height) {
75  FXVerticalFrame* contentFrame = new FXVerticalFrame(this, LAYOUT_FILL_X | LAYOUT_FILL_Y);
76 
77  FXTabBook* tabbook = new FXTabBook(
78  contentFrame, 0, 0, TABBOOK_LEFTTABS | PACK_UNIFORM_WIDTH | PACK_UNIFORM_HEIGHT | LAYOUT_FILL_X | LAYOUT_FILL_Y | LAYOUT_RIGHT);
79 
80  const std::vector<std::string>& topics = oc.getSubTopics();
81  for (std::vector<std::string>::const_iterator it_topic = topics.begin(); it_topic != topics.end(); it_topic++) {
82  std::string topic = *it_topic;
83  if (topic == "Configuration") {
84  continue;
85  }
86  new FXTabItem(tabbook, topic.c_str(), NULL, TAB_LEFT_NORMAL);
87  FXScrollWindow* scrollTab = new FXScrollWindow(tabbook, LAYOUT_FILL_X | LAYOUT_FILL_Y);
88  FXVerticalFrame* tabContent = new FXVerticalFrame(scrollTab, FRAME_THICK | FRAME_RAISED | LAYOUT_FILL_X | LAYOUT_FILL_Y);
89  const std::vector<std::string> entries = oc.getSubTopicsEntries(topic);
90  for (std::vector<std::string>::const_iterator it_opt = entries.begin(); it_opt != entries.end(); it_opt++) {
91  std::string name = *it_opt;
92  std::string type = oc.getTypeName(name);
93  if (type == "STR" || type == "FILE") {
94  new InputString(tabContent, name);
95  } else if (type == "BOOL") {
96  new InputBool(tabContent, name);
97  } else if (type == "INT") {
98  new InputInt(tabContent, name);
99  } else if (type == "FLOAT") {
100  new InputFloat(tabContent, name);
101  }
102  // @todo missing types (type INT[] is only used in microsim)
103  }
104  }
105 
106  // ok-button
107  new FXButton(contentFrame, "OK\t\tContine with the import.", 0, this, ID_ACCEPT, LAYOUT_FIX_WIDTH | LAYOUT_CENTER_X | JUSTIFY_CENTER_X | FRAME_THICK | FRAME_RAISED, 0, 0, 50, 30);
108 }
109 
110 
112 
113 // ===========================================================================
114 // Option input classes method definitions
115 // ===========================================================================
116 GNEDialog_Wizard::InputString::InputString(FXComposite* parent, const std::string& name) :
117  FXHorizontalFrame(parent, LAYOUT_FILL_X),
118  myName(name) {
120  new FXLabel(this, name.c_str());
121  myTextField = new FXTextField(this, 100, this, MID_GNE_SET_ATTRIBUTE, TEXTFIELD_NORMAL | LAYOUT_RIGHT, 0, 0, 0, 0, 4, 2, 0, 2);
122  myTextField->setText(oc.getString(name).c_str());
123 }
124 
125 
126 long
127 GNEDialog_Wizard::InputString::onCmdSetOption(FXObject*, FXSelector, void*) {
129  oc.resetWritable();
130  oc.set(myName, myTextField->getText().text());
131  return 1;
132 }
133 
134 
135 GNEDialog_Wizard::InputBool::InputBool(FXComposite* parent, const std::string& name) :
136  FXHorizontalFrame(parent, LAYOUT_FILL_X),
137  myName(name) {
139  new FXLabel(this, name.c_str());
140  myCheck = new FXMenuCheck(this, "", this, MID_GNE_SET_ATTRIBUTE);
141  myCheck->setCheck(oc.getBool(name));
142 }
143 
144 
145 long
146 GNEDialog_Wizard::InputBool::onCmdSetOption(FXObject*, FXSelector, void*) {
148  oc.resetWritable();
149  oc.set(myName, myCheck->getCheck() ? "true" : "false");
150  return 1;
151 }
152 
153 
154 GNEDialog_Wizard::InputInt::InputInt(FXComposite* parent, const std::string& name) :
155  FXHorizontalFrame(parent, LAYOUT_FILL_X),
156  myName(name) {
158  new FXLabel(this, name.c_str());
159  myTextField = new FXTextField(this, 100, this, MID_GNE_SET_ATTRIBUTE, TEXTFIELD_INTEGER | LAYOUT_RIGHT, 0, 0, 0, 0, 4, 2, 0, 2);
160  myTextField->setText(toString(oc.getInt(name)).c_str());
161 }
162 
163 
164 long
165 GNEDialog_Wizard::InputInt::onCmdSetOption(FXObject*, FXSelector, void*) {
167  oc.resetWritable();
168  oc.set(myName, myTextField->getText().text());
169  return 1;
170 }
171 
172 
173 GNEDialog_Wizard::InputFloat::InputFloat(FXComposite* parent, const std::string& name) :
174  FXHorizontalFrame(parent, LAYOUT_FILL_X),
175  myName(name) {
177  new FXLabel(this, name.c_str());
178  myTextField = new FXTextField(this, 100, this, MID_GNE_SET_ATTRIBUTE, TEXTFIELD_REAL | LAYOUT_RIGHT, 0, 0, 0, 0, 4, 2, 0, 2);
179  myTextField->setText(toString(oc.getFloat(name)).c_str());
180 }
181 
182 
183 long
184 GNEDialog_Wizard::InputFloat::onCmdSetOption(FXObject*, FXSelector, void*) {
186  oc.resetWritable();
187  oc.set(myName, myTextField->getText().text());
188  return 1;
189 }
190 
191 
192 /****************************************************************************/
FXDEFMAP(GNEDialog_Wizard::InputString) InputStringMap[]
const std::vector< std::string > & getSubTopics() const
return the list of subtopics
Definition: OptionsCont.h:635
void resetWritable()
Resets all options to be writeable.
FXMenuCheck * myCheck
menu check
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
~GNEDialog_Wizard()
Destructor.
long onCmdSetOption(FXObject *, FXSelector, void *)
try to set new attribute value
SUMOReal getFloat(const std::string &name) const
Returns the SUMOReal-value of the named option (only for Option_Float)
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:69
std::string getTypeName(const std::string name)
return the type name for the given option
Definition: OptionsCont.h:651
std::string getString(const std::string &name) const
Returns the string-value of the named option (only for Option_String)
std::string toString(const T &t, std::streamsize accuracy=OUTPUT_ACCURACY)
Definition: ToString.h:55
FXTextField * myTextField
text field
long onCmdSetOption(FXObject *, FXSelector, void *)
try to set new attribute value
FXTextField * myTextField
text field
bool set(const std::string &name, const std::string &value)
Sets the given value for the named option.
A storage for options typed value containers)
Definition: OptionsCont.h:99
long onCmdSetOption(FXObject *, FXSelector, void *)
try to set new attribute value
std::vector< std::string > getSubTopicsEntries(const std::string &subtopic) const
return the list of entries for the given subtopic
Definition: OptionsCont.h:641
FXTextField * myTextField
text field
int getInt(const std::string &name) const
Returns the int-value of the named option (only for Option_Integer)
long onCmdSetOption(FXObject *, FXSelector, void *)
try to set new attribute value