A Discrete-Event Network Simulator
API
gtk-config-store.cc
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or modify
3  * it under the terms of the GNU General Public License version 2 as
4  * published by the Free Software Foundation;
5  *
6  * This program is distributed in the hope that it will be useful,
7  * but WITHOUT ANY WARRANTY; without even the implied warranty of
8  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9  * GNU General Public License for more details.
10  *
11  * You should have received a copy of the GNU General Public License
12  * along with this program; if not, write to the Free Software
13  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
14  *
15  * Authors: Faker Moatamri <faker.moatamri@sophia.inria.fr>
16  * Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
17  */
18 
19 #include "gtk-config-store.h"
20 
21 #include "display-functions.h"
22 #include "raw-text-config.h"
23 
24 #include "ns3/log.h"
25 
26 #include <fstream>
27 
28 namespace ns3
29 {
30 
31 NS_LOG_COMPONENT_DEFINE("GtkconfigStore");
32 
34 {
35 }
36 
37 void
39 {
40  // this function should be called before running the script to enable the user
41  // to configure the default values for the objects he wants to use
42  GtkWidget* window;
43  GtkWidget* view;
44  GtkWidget* scroll;
45 
46  gtk_init(nullptr, nullptr);
47  window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
48  gtk_window_set_title(GTK_WINDOW(window), "ns-3 Default attributes.");
49  gtk_window_set_default_size(GTK_WINDOW(window), 600, 600);
50 
51  g_signal_connect(window, "delete_event", (GCallback)delete_event_callback, window);
52  GtkTreeStore* model = gtk_tree_store_new(COL_LAST, G_TYPE_POINTER);
53  ModelTypeidCreator creator;
54  creator.Build(model);
55 
56  view = create_view_config_default(model);
57  scroll = gtk_scrolled_window_new(nullptr, nullptr);
58  gtk_container_add(GTK_CONTAINER(scroll), view);
59 
60  GtkWidget* vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 5);
61  gtk_box_pack_start(GTK_BOX(vbox), scroll, TRUE, TRUE, 0);
62  gtk_box_pack_end(GTK_BOX(vbox), gtk_separator_new(GTK_ORIENTATION_HORIZONTAL), FALSE, FALSE, 0);
63  GtkWidget* hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 5);
64  gtk_box_pack_end(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
65  GtkWidget* save = gtk_button_new_with_label("Save");
66  g_signal_connect(save, "clicked", (GCallback)save_clicked_default, window);
67  gtk_box_pack_end(GTK_BOX(hbox), save, FALSE, FALSE, 0);
68  GtkWidget* load = gtk_button_new_with_label("Load");
69  g_signal_connect(load, "clicked", (GCallback)load_clicked_default, window);
70  gtk_box_pack_end(GTK_BOX(hbox), load, FALSE, FALSE, 0);
71  GtkWidget* exit = gtk_button_new_with_label("Run Simulation");
72  g_signal_connect(exit, "clicked", (GCallback)exit_clicked_callback, window);
73  gtk_box_pack_end(GTK_BOX(hbox), exit, FALSE, FALSE, 0);
74 
75  gtk_container_add(GTK_CONTAINER(window), vbox);
76 
77  gtk_widget_show_all(window);
78 
79  gtk_main();
80 
81  gtk_tree_model_foreach(GTK_TREE_MODEL(model), clean_model_callback_config_default, nullptr);
82 
83  gtk_widget_destroy(window);
84 }
85 
86 void
88 {
89  GtkWidget* window;
90  GtkWidget* view;
91  GtkWidget* scroll;
92 
93  gtk_init(nullptr, nullptr);
94 
95  window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
96  gtk_window_set_title(GTK_WINDOW(window), "ns-3 Object attributes.");
97  gtk_window_set_default_size(GTK_WINDOW(window), 600, 600);
98 
99  g_signal_connect(window, "delete_event", (GCallback)delete_event_callback, window);
100 
101  GtkTreeStore* model = gtk_tree_store_new(COL_LAST, G_TYPE_POINTER);
102  ModelCreator creator;
103  creator.Build(model);
104 
105  view = create_view(model);
106  scroll = gtk_scrolled_window_new(nullptr, nullptr);
107  gtk_container_add(GTK_CONTAINER(scroll), view);
108 
109  GtkWidget* vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 5);
110  gtk_box_pack_start(GTK_BOX(vbox), scroll, TRUE, TRUE, 0);
111  gtk_box_pack_end(GTK_BOX(vbox), gtk_separator_new(GTK_ORIENTATION_HORIZONTAL), FALSE, FALSE, 0);
112  GtkWidget* hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 5);
113  gtk_box_pack_end(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
114  GtkWidget* save = gtk_button_new_with_label("Save");
115  g_signal_connect(save, "clicked", (GCallback)save_clicked_attribute, window);
116  gtk_box_pack_end(GTK_BOX(hbox), save, FALSE, FALSE, 0);
117  GtkWidget* load = gtk_button_new_with_label("Load");
118  g_signal_connect(load, "clicked", (GCallback)load_clicked_attribute, window);
119  gtk_box_pack_end(GTK_BOX(hbox), load, FALSE, FALSE, 0);
120  GtkWidget* exit = gtk_button_new_with_label("Run Simulation");
121  g_signal_connect(exit, "clicked", (GCallback)exit_clicked_callback, window);
122  gtk_box_pack_end(GTK_BOX(hbox), exit, FALSE, FALSE, 0);
123 
124  gtk_container_add(GTK_CONTAINER(window), vbox);
125 
126  gtk_widget_show_all(window);
127 
128  gtk_main();
129 
130  gtk_tree_model_foreach(GTK_TREE_MODEL(model), clean_model_callback, nullptr);
131 
132  gtk_widget_destroy(window);
133 }
134 
135 } // namespace ns3
void ConfigureDefaults()
Process default values.
void ConfigureAttributes()
Process attribute values.
ModelCreator class.
void Build(GtkTreeStore *treestore)
Allocate attribute tree.
ModelTypeIdCreator class.
void Build(GtkTreeStore *treestore)
This method will iterate on typeIds having default attributes and create a model for them,...
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
Every class exported by the ns3 library is enclosed in the ns3 namespace.
gboolean clean_model_callback(GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, gpointer data)
Delete the tree model contents.
void save_clicked_attribute(GtkButton *button, gpointer user_data)
This is the action done when the user presses on the save button for the Attributes.
gboolean delete_event_callback(GtkWidget *widget, GdkEvent *event, gpointer user_data)
Exit the application.
void exit_clicked_callback(GtkButton *button, gpointer user_data)
Exit the window when exit button is pressed.
GtkWidget * create_view_config_default(GtkTreeStore *model)
This is the main view opening the widget, getting tooltips and drawing the tree of attributes.
gboolean clean_model_callback_config_default(GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, gpointer data)
Delete the tree model contents.
GtkWidget * create_view(GtkTreeStore *model)
This is the main view opening the widget, getting tooltips and drawing the tree of attributes....
void save_clicked_default(GtkButton *button, gpointer user_data)
This is the action done when the user presses on the save button for the Default attributes.
void load_clicked_default(GtkButton *button, gpointer user_data)
If the user presses the button load, it will load the config file into memory for the Default attribu...
void load_clicked_attribute(GtkButton *button, gpointer user_data)
If the user presses the button load, it will load the config file into memory for the Attributes.