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