CEBL  2.1
TabClassifiers.cpp
Go to the documentation of this file.
1 
7 #include "TabClassifiers.hpp"
8 
9 //----------------------------------------------------------------------
10 // Constructors / Destructor
11 
13 {
14 
15 }
16 
17 
18 //----------------------------------------------------------------------
19 // Create the GUI
20 
21 
23 {
24  //add title
25  GtkWidget *title = gtk_label_new("");
26  gtk_label_set_markup(GTK_LABEL(title),view->getString("ClassifierTitle"));
27  TabAdd(title);
28  TabAdd(gtk_hseparator_new());
29 
30 
31  //-------------------------------------------------
32  //Classifier Selection
33  GtkWidget *hbox_classifiers = gtk_hbox_new(false, 0);
34 
35  this->updating_view = false;
36  this->num_classifiers = 0;
37  this->selected_classifier = "";
38  combo_classifiers = gtk_combo_box_new_text();
39 
40  //configure the combo box and add callback
41  gtk_combo_box_set_active(GTK_COMBO_BOX(combo_classifiers),0);
42  g_signal_connect(G_OBJECT(combo_classifiers),
43  "changed",
44  G_CALLBACK(CB_ChangeClassifier),
45  (gpointer) this);
46 
47  gtk_box_pack_start(GTK_BOX(hbox_classifiers), combo_classifiers, false, false, 0);
48 
49  //trained check box
50  check_classifier_trained =
51  gtk_check_button_new_with_label(view->getString("ClassifiersStr1"));
52  gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(check_classifier_trained),
53  false);
54  gtk_widget_set_sensitive(check_classifier_trained,false);
55 
56  gtk_box_pack_end(GTK_BOX(hbox_classifiers),check_classifier_trained,
57  false, false, 0);
58 
59 
60 
61  TabAdd(hbox_classifiers);
62 
63  //create space for widget panel
64  panel_box = gtk_hbox_new(false, 0);
65  panel = NULL;
66 
67  TabFrameAdd(panel_box,view->getString("ClassifiersStr2"));
68 
69 
70  updateView();
71  if(gtk_combo_box_get_active(GTK_COMBO_BOX(combo_classifiers))==-1)
72  gtk_combo_box_set_active(GTK_COMBO_BOX(combo_classifiers),0);
73 }
74 
75 
76 
77 //update view from model
78 
80 {
81 
82  //set flag to indicate process of updating view
83  //in order to stop callbacks from triggering
84  this->updating_view = true;
85 
86  //get information from model about classifiers
87  CEBLModel * model = getView()->getModel();
88  std::vector<string> names = model->classifiersGetNameList();
89  std::vector<string> paths = model->classifiersGetPathList();
90  string model_selected_classifier = model->classifiersGetSelected();
91 
92 
93  {
94  this->selected_classifier = model_selected_classifier;
95  this->classifier_names = names;
96  for(int i = this->num_classifiers-1; i >= 0; i--)
97  {
98  gtk_combo_box_remove_text(GTK_COMBO_BOX(combo_classifiers),i);
99  }
100  this->num_classifiers = names.size();
101 
102  // add in all classifiers
103 
104  for(unsigned int i=0;i<names.size();i++)
105  {
106  gtk_combo_box_append_text(GTK_COMBO_BOX(combo_classifiers),names[i].c_str());
107  if(names[i]==model_selected_classifier)
108  {
109  gtk_combo_box_set_active(GTK_COMBO_BOX(combo_classifiers),i);
110  }
111  }
112  //set trained checked button
113  gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(check_classifier_trained),
114  model->classifierIsTrained());
115 
116  // create panel
117  if (this->panel != NULL)
118  {
119  gtk_container_remove(GTK_CONTAINER(this->panel_box),this->panel->getContainer());
120  delete this->panel;
121  this->panel = NULL;
122  }
123 
124  //update panel
125  if(model_selected_classifier != "")
126  {
127  try
128  {
129  std::map<std::string, CEBL::Param> params = model->classifierGetParams(model_selected_classifier);
130  this->panel = new WidgetPanel(params);
131  }
132  catch(...)
133  {
134  this->panel = NULL;
135  cerr << "ERROR: exception occurred when trying to get parameters for classifier.\n";
136  }
137  }
138  if (this->panel != NULL)
139  {
140  gtk_container_add(GTK_CONTAINER(this->panel_box),this->panel->getContainer());
141  gtk_widget_show_all(this->panel_box);
142 
143  }
144  }//end of conditional concerning whether update should occur
145  this->updating_view = false;
146 }
147 
148 
149 //update the model from the widgets
151 {
152  // set the selected classifiers's params
153  if(this->panel != NULL){
154  this->getView()->getModel()->classifierSetParams(this->panel->getParams());
155  }
156 }
157 
158 //----------------------------------------------------------------------
159 // CALLBACKS
160 
161 
162 void TabClassifiers::CB_ChangeClassifier(GtkWidget *w, gpointer data)
163 {
164  TabClassifiers* tab = (TabClassifiers*)data;
165 
166  //as long as the update view is not currently running,
167  //set the model's selected classifier to the selected classifier
168  //in combo box
169  if(tab->num_classifiers > 0 && !tab->updating_view)
170  {
171  string classifier = gtk_combo_box_get_active_text(GTK_COMBO_BOX(tab->combo_classifiers));
172  try
173  {
174  if(classifier != tab->selected_classifier)
175  {
176  // set the previously selected classifier's params
177  if(tab->panel != NULL){
178  tab->getView()->getModel()->classifierSetParams(tab->panel->getParams());
179  }
180  // set the selected classifier in the model
181  tab->getView()->getModel()->classifiersSetSelected(classifier);
182 
183  }
184  }
185  catch(...)
186  {
187  cerr << "Error selecting classifier.\n";
188  }
189  tab->updateView();
190  tab->getView()->updateInfoBar();
191  }
192 
193 }
194 
195 
196 
197