]> git.llucax.com Git - z.facultad/75.42/plaqui.git/blob - Client/src/principal.cpp
Se agrega docs de instalación.
[z.facultad/75.42/plaqui.git] / Client / src / principal.cpp
1
2 #include "principal.h"
3 #include <iostream>
4 #include <sstream>
5 #include <string>
6 #include "plaqui/server/string.h"
7 #include "item_codo.h"
8 #include "item_conduct.h"
9 #include "item_exclusa.h"
10 #include "item_tank.h"
11 #include "item_pump.h"
12 #include "item_union.h"
13 #include "item_drain.h"
14 #include <unistd.h>
15
16 Principal::Principal(BaseObjectType *co, const Glib::RefPtr<Gnome::Glade::Xml> &rg):Gtk::Window(co),refXml(rg)
17 {
18         Gtk::MenuItem *conect=0, *exit=0, *about=0, *mnu_prop=0, *mnu_disconnect=0;
19         Gtk::Button *btn_get=0, *bar_connect=0;
20         txt_view = 0;
21         txt_target = txt_command = txt_args = 0;
22         work_place = 0;
23         lbl_cap_flujo = lbl_cap_extra = lbl_extra = lbl_nombre = lbl_color = lbl_flujo = 0;
24
25         rg->get_widget("btn_activar", btn_activar);
26         rg->get_widget("color_preview", color_preview);
27         rg->get_widget("lbl_nombre", lbl_nombre);
28         rg->get_widget("lbl_extra", lbl_extra);
29         rg->get_widget("lbl_cap_extra", lbl_cap_extra);
30         rg->get_widget("lbl_cap_flujo", lbl_cap_flujo);
31         rg->get_widget("lbl_flujo", lbl_flujo);
32         rg->get_widget("mnu_file_connect", conect);
33         rg->get_widget("mnu_file_disconnect", mnu_disconnect);
34         rg->get_widget("mnu_file_exit", exit);
35         rg->get_widget("mnu_help_about", about);
36         rg->get_widget("mnu_prop", mnu_prop);
37         rg->get_widget_derived("dlgConectar", dlg_conectar);
38         rg->get_widget("btn_get", btn_get);
39         rg->get_widget("txt_view", txt_view);
40         rg->get_widget("txt_target", txt_target);
41         rg->get_widget("txt_command", txt_command);
42         rg->get_widget("txt_args", txt_args);
43         rg->get_widget("bar_connect", bar_connect);
44         rg->get_widget("work_place", work_place);
45         rg->get_widget("ico_conected", ico_conected);
46
47         dlg_conectar->get_ok_button()->signal_clicked().connect( SigC::slot(*this, &Principal::on_dlg_connect_ok) );
48         mnu_disconnect->signal_activate().connect( SigC::slot(*this, &Principal::on_mnu_file_disconnect));
49         conect->signal_activate().connect( SigC::slot(*this, &Principal::on_mnu_file_connect));
50         bar_connect->signal_clicked().connect( SigC::slot(*this, &Principal::on_mnu_file_connect));
51         exit->signal_activate().connect( SigC::slot(*this, &Principal::on_mnu_file_exit));
52         about->signal_activate().connect( SigC::slot(*this, &Principal::on_mnu_help_about));
53         btn_get->signal_clicked().connect( SigC::slot(*this, &Principal::on_get_clicked) );
54         btn_activar->signal_clicked().connect( SigC::slot(*this, &Principal::on_btn_activar_clicked) );
55
56         conexion = NULL;
57         is_xml_loaded = false;
58         last_selected = NULL;
59         update_ui.connect( SigC::slot(*this, &Principal::update_items_prop ) );
60         load_xml_dispatch.connect( SigC::slot(*this, &Principal::loadXML ) );
61 }
62
63 Principal::~Principal()
64 {
65         if (conexion != NULL)
66                 delete conexion;
67 }
68
69 void Principal::on_dlg_connect_ok()
70 {
71         if (conexion == NULL) {
72                 // Creo la conexion
73                 try {
74                         conexion = new PlaQui::Server::ControlClient(dlg_conectar->get_server_name(), dlg_conectar->get_server_port());
75                 }
76                 catch (...) {
77                         txt_view->get_buffer()->insert_at_cursor("NO SE PUDO CREAR OBJETO\n");
78                         delete conexion;
79                         conexion == NULL;
80                         return;
81                 }
82
83                 // Conecto las señales
84                 conexion->signal_ok_received().connect( SigC::slot(*this, &Principal::on_conexion_ok) );
85                 conexion->signal_error_received().connect( SigC::slot(*this, &Principal::on_conexion_error) );
86                 conexion->signal_connected().connect( SigC::slot(*this, &Principal::on_conexion_connected) );
87                 conexion->signal_finished().connect( SigC::slot(*this, &Principal::on_conexion_finished) );
88                 conexion->signal_frame_received().connect(SigC::slot(*this, &Principal::on_conexion_frame));
89                 // Lanzo la conexion!
90                 conexion->run();
91         } else {
92                 txt_view->get_buffer()->insert_at_cursor("YA ESTAS CONECTADO\n");
93         }
94         dlg_conectar->hide();
95 }
96
97 void Principal::on_mnu_file_exit()
98 {
99         Gtk::Main::quit();
100 }
101
102 void Principal::on_btn_activar_clicked()
103 {
104         if ((conexion == NULL) || (last_selected == NULL)) return;
105
106         PlaQui::Server::Command c("plant", "set");
107         c.add_arg("default");
108         c.add_arg(last_selected->get_name());
109         c.add_arg("open");
110         
111         if (last_selected->get_open())
112                 c.add_arg("false");
113         else
114                 c.add_arg("true");
115
116         conexion->send(c);
117 }
118
119 void Principal::on_mnu_file_disconnect()
120 {
121         if (conexion == NULL) return;
122
123         PlaQui::Server::Command c("connection", "stop");
124         c.add_arg(conexion->get_host());
125         c.add_arg("7522");
126         conexion->send(c);
127 }
128
129 void Principal::on_mnu_file_connect()
130 {
131         dlg_conectar->show();
132 }
133
134 void Principal::on_mnu_help_about()
135 {
136         // preparo para leer el archivo ChangeLog
137 /*      Glib::RefPtr<Gnome::Glade::Xml> xml;
138         Glib::ustring line;
139         Glib::RefPtr<Gtk::TextBuffer> log_buffer;
140         Glib::RefPtr<Glib::IOChannel> log_io;
141
142         log_buffer = Gtk::TextBuffer::create();
143         log_io = Glib::IOChannel::create_from_file("../ChangeLog", "r");
144         while (log_io->read_line(line) != Glib::IO_STATUS_EOF) {
145                 log_buffer->insert_at_cursor(line);
146         }
147
148         try {
149                 xml = Gnome::Glade::Xml::create("client.glade", "dlgAbout");
150         }
151         catch(const Gnome::Glade::XmlError &ex) {
152                 std::cerr << ex.what() << std::endl;
153                 return;
154         }
155         Gtk::Window *dlg = 0;
156         Gtk::Button *btn_cerrar = 0;
157         Gtk::TextView *txt_changelog = 0;
158         xml->get_widget("dlgAbout", dlg);
159         xml->get_widget("btn_close", btn_cerrar);
160         xml->get_widget("txt_changelog", txt_changelog);
161         btn_cerrar->signal_clicked().connect(SigC::slot(*dlg, &Gtk::Dialog::hide));
162         txt_changelog->set_buffer(log_buffer);
163         dlg->show();*/
164 }
165
166 bool Principal::on_item_clicked(GdkEventButton *e, ViewItem *i)
167 {
168         
169         txt_view->get_buffer()->insert_at_cursor("Selecciono ");
170         txt_view->get_buffer()->insert_at_cursor(i->get_name());
171         txt_view->get_buffer()->insert_at_cursor("\n");
172
173         last_selected = i;
174         update_items_prop();
175 }
176
177 void Principal::update_items_prop()
178 {
179         if (last_selected == NULL) return;
180
181         lbl_nombre->set_text(last_selected->get_name());
182         lbl_flujo->set_text(last_selected->get_actual_flow());
183         lbl_extra->set_text(last_selected->get_extra());
184
185         lbl_cap_flujo->set_text(last_selected->get_cap_flow());
186         lbl_cap_extra->set_text(last_selected->get_cap_extra());
187
188         color_preview->modify_bg(Gtk::STATE_NORMAL, last_selected->get_color());
189         color_preview->queue_draw();
190 }
191
192 void Principal::on_conexion_connected()
193 {
194         txt_view->get_buffer()->insert_at_cursor("CONNECTED\n");
195         ico_conected->set( Gtk::Stock::YES , Gtk::IconSize(Gtk::ICON_SIZE_LARGE_TOOLBAR));
196
197         // Pido la planta por defecto
198         if (conexion != NULL) {
199                 PlaQui::Server::Command c("plant", "get");
200                 c.add_arg("default");
201                 conexion->send(c);
202         }
203 }
204
205 void Principal::on_conexion_frame(const std::string &frame)
206 {
207         if (conexion != NULL) {
208                 read_status_xml(frame);
209         }
210 }
211
212 void Principal::on_conexion_finished()
213 {
214         txt_view->get_buffer()->insert_at_cursor("HANG UP\n");
215         ico_conected->set( Gtk::Stock::NO , Gtk::IconSize(Gtk::ICON_SIZE_LARGE_TOOLBAR));
216         conexion = NULL;
217 }
218
219 void Principal::on_conexion_ok(const std::string &body)
220 {
221         /* lo paso a la carga del XML */
222         /* verifico que body este completo */
223         if ((body.find("</planta>")>0) && (body.find("<planta>")>0)) {
224                 //loadXML(body);
225                 xml_body = body;
226                 load_xml_dispatch();
227         } else {
228                 std::cout << body << std::endl;
229                 txt_view->get_buffer()->insert_at_cursor("<IN>\n");
230                 txt_view->get_buffer()->insert_at_cursor(Glib::locale_to_utf8(body));
231                 txt_view->get_buffer()->insert_at_cursor("</IN>\n");
232         }
233 }
234
235 void Principal::on_conexion_error(unsigned code)
236 {
237         std::stringstream a;
238         std::string s;
239         a << code;
240         a >> s;
241         txt_view->get_buffer()->insert_at_cursor("El server dice que hay error : ");
242         txt_view->get_buffer()->insert_at_cursor(s);
243         txt_view->get_buffer()->insert_at_cursor("\n");
244 }
245
246 void Principal::on_get_clicked()
247 {
248         if (conexion == NULL) {
249                 txt_view->get_buffer()->insert_at_cursor("SIN CONEXION\n");
250                 return;
251         }
252         
253         PlaQui::Server::Command command(txt_target->get_text(), txt_command->get_text());
254         command.add_arg( txt_args->get_text() );
255         txt_view->get_buffer()->insert_at_cursor("Enviando comando\n");
256         try {
257                 conexion->send(command);
258         }
259         catch (...) {
260                 txt_view->get_buffer()->insert_at_cursor("EXCEPTION EN conexion->send !!\n");
261         }
262
263 }
264
265 void Principal::loadXML()
266 {
267         // ya lo cargue
268         if (is_xml_loaded) return;
269
270         /* Parseo de ejemplo de un XML desde archivo */
271         xmlDocPtr document;
272         document = xmlParseMemory(xml_body.c_str(),xml_body.size());
273         if (document == NULL) {
274                 std::cout << "EEERRRRRRROOOOOOOOOO" << std::endl;
275                 return;
276         }
277         is_xml_loaded = true;
278         /* bien, el archivo se parseo bien! */
279         xmlNodePtr nodo, items;
280         nodo = document->children;
281
282         if (strcmp((char *)nodo->name, "planta") == 0) {
283                 items = nodo->children;
284                 while (items != NULL) {
285                         if (items->type == XML_ELEMENT_NODE) {
286                                 if (xmlStrcmp(items->name, BAD_CAST"bomba")==0) {
287                                         loadBomba(items);
288                                 } else if (xmlStrcmp(items->name, BAD_CAST"codo")==0) {
289                                         loadCodo(items);
290                                 } else if (xmlStrcmp(items->name, BAD_CAST"tubo")==0) {
291                                         loadConduct(items);
292                                 } else if (xmlStrcmp(items->name, BAD_CAST"exclusa")==0) {
293                                         loadExclusa(items);
294                                 } else if (xmlStrcmp(items->name, BAD_CAST"tanque")==0) {
295                                         loadTank(items);
296                                 } else if (xmlStrcmp(items->name, BAD_CAST"empalme")==0) {
297                                         loadUnion(items);
298                                 } else if (xmlStrcmp(items->name, BAD_CAST"drenaje")==0) {
299                                         loadDrain(items);
300                                 }
301
302                         }
303                         items = items->next;
304                 }
305         }
306
307         // Ya cargado el XML, mando un msg para empezar a recibir los frames!
308         PlaQui::Server::Command c("transmission", "start");
309         c.add_arg("default");
310         c.add_arg(conexion->get_host());
311         c.add_arg("7528");
312         conexion->send(c);
313 }
314
315 void Principal::loadBomba(xmlNodePtr nodo)
316 {
317         Glib::ustring name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
318         int orientacion=0, x, y;
319
320         nodo = nodo->children;
321         while (nodo != NULL) {
322                 if (nodo->type == XML_ELEMENT_NODE) {
323                         if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
324                                 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
325                         } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
326                                 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
327                         } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
328                                 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
329                         }
330                 }
331                 nodo = nodo->next;
332         }
333
334         // listo, ya recolecte todos los datos, ahora creo el objeto!
335         ViewPump *b = new ViewPump(name, orientacion);
336         b->signal_button_press_event().connect(SigC::bind( SigC::slot(*this, &Principal::on_item_clicked), b) );
337         b->set_position(x,y);
338         work_place->put(*b, x, y);
339         b->show();
340         // los agrego al hash
341         mapItems[name] = b;
342 }
343
344 void Principal::loadCodo(xmlNodePtr nodo)
345 {
346         std::string name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
347         int orientacion=0, x, y;
348
349         nodo = nodo->children;
350         while (nodo != NULL) {
351                 if (nodo->type == XML_ELEMENT_NODE) {
352                         if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
353                                 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
354                         } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
355                                 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
356                         } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
357                                 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
358                         }
359                 }
360                 nodo = nodo->next;
361         }
362
363         // listo, ya recolecte todos los datos, ahora creo el objeto!
364         ViewItem *b = new ViewCodo(name, orientacion);
365         b->signal_button_press_event().connect(SigC::bind( SigC::slot(*this, &Principal::on_item_clicked), b) );
366         b->set_position(x,y);
367         work_place->put(*b, x, y);
368         b->show();
369         // los agrego al hash
370         mapItems[name] = b;
371 }
372
373 void Principal::loadConduct(xmlNodePtr nodo)
374 {
375         Glib::ustring name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
376         int orientacion=0, x, y;
377
378         nodo = nodo->children;
379         while (nodo != NULL) {
380                 if (nodo->type == XML_ELEMENT_NODE) {
381                         if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
382                                 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
383                         } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
384                                 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
385                         } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
386                                 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
387                         }
388                 }
389                 nodo = nodo->next;
390         }
391
392         // listo, ya recolecte todos los datos, ahora creo el objeto!
393         ViewConduct *b = new ViewConduct(name, orientacion);
394         b->signal_button_press_event().connect(SigC::bind( SigC::slot(*this, &Principal::on_item_clicked), b) );
395         b->set_position(x,y);
396         work_place->put(*b, x, y);
397         b->show();
398         // los agrego al hash
399         mapItems[name] = b;
400 }
401
402 void Principal::loadExclusa(xmlNodePtr nodo)
403 {
404         Glib::ustring name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
405         int orientacion=0, x, y;
406
407         nodo = nodo->children;
408         while (nodo != NULL) {
409                 if (nodo->type == XML_ELEMENT_NODE) {
410                         if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
411                                 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
412                         } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
413                                 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
414                         } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
415                                 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
416                         }
417                 }
418                 nodo = nodo->next;
419         }
420
421         // listo, ya recolecte todos los datos, ahora creo el objeto!
422         ViewExclusa *b = new ViewExclusa(name, orientacion);
423         b->signal_button_press_event().connect(SigC::bind( SigC::slot(*this, &Principal::on_item_clicked), b) );
424         b->set_position(x,y);
425         work_place->put(*b, x, y);
426         b->show();
427         // los agrego al hash
428         mapItems[name] = b;
429 }
430
431 void Principal::loadTank(xmlNodePtr nodo)
432 {
433         Glib::ustring name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
434         int orientacion=0, x, y;
435
436         nodo = nodo->children;
437         while (nodo != NULL) {
438                 if (nodo->type == XML_ELEMENT_NODE) {
439                         if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
440                                 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
441                         } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
442                                 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
443                         } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
444                                 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
445                         }
446                 }
447                 nodo = nodo->next;
448         }
449
450         // listo, ya recolecte todos los datos, ahora creo el objeto!
451         ViewTank *b = new ViewTank(name, orientacion);
452         b->signal_button_press_event().connect(SigC::bind( SigC::slot(*this, &Principal::on_item_clicked), b) );
453         b->set_position(x,y);
454         work_place->put(*b, x, y);
455         b->show();
456         // los agrego al hash
457         mapItems[name] = b;
458 }
459
460 void Principal::loadUnion(xmlNodePtr nodo)
461 {
462         Glib::ustring name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
463         int orientacion=0, x, y;
464
465         nodo = nodo->children;
466         while (nodo != NULL) {
467                 if (nodo->type == XML_ELEMENT_NODE) {
468                         if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
469                                 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
470                         } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
471                                 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
472                         } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
473                                 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
474                         }
475                 }
476                 nodo = nodo->next;
477         }
478
479         // listo, ya recolecte todos los datos, ahora creo el objeto!
480         ViewUnion *b = new ViewUnion(name, orientacion);
481         b->signal_button_release_event().connect(SigC::bind( SigC::slot(*this, &Principal::on_item_clicked), b) );
482         b->set_position(x,y);
483         work_place->put(*b, x, y);
484         b->show();
485         // los agrego al hash
486         mapItems[name] = b;
487 }
488
489 void Principal::loadDrain(xmlNodePtr nodo)
490 {
491         Glib::ustring name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
492         int orientacion=0, x, y;
493
494         nodo = nodo->children;
495         while (nodo != NULL) {
496                 if (nodo->type == XML_ELEMENT_NODE) {
497                         if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
498                                 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
499                         } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
500                                 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
501                         } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
502                                 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
503                         }
504                 }
505                 nodo = nodo->next;
506         }
507
508         // listo, ya recolecte todos los datos, ahora creo el objeto!
509         ViewDrain *b = new ViewDrain(name, orientacion);
510         b->signal_button_release_event().connect(SigC::bind( SigC::slot(*this, &Principal::on_item_clicked), b) );
511         b->set_position(x,y);
512         work_place->put(*b, x, y);
513         b->show();
514         // los agrego al hash
515         mapItems[name] = b;
516 }
517
518 void Principal::read_status_xml(const std::string &frame)
519 {
520         std::string item_name;
521         xmlDocPtr document;
522         document = xmlParseMemory(frame.c_str(),frame.size());
523         if (document == NULL) {
524                 std::cout << "read_status_xml::no se creo documento" << std::endl;
525                 return;
526         }
527         
528         xmlNodePtr nodo, items, props;
529         nodo = document->children;
530         float tmp;
531         bool tmp_b;
532
533         if (strcmp((char *)nodo->name, "plantstatus") == 0) {
534                 items = nodo->children;
535                 while (items != NULL) {
536                         if (items->type == XML_ELEMENT_NODE) {
537                                 tmp = -1;
538                                 item_name = "";
539                                 if (xmlStrcmp(items->name, BAD_CAST"float")==0) {
540                                         tmp = get_float_from_xml(items->children);
541                                         item_name = (char *)xmlGetProp(items, BAD_CAST"name");
542                                         mapItems[item_name]->set_actual_flow(tmp);
543                                 } else if (xmlStrcmp(items->name, BAD_CAST"exclusa")==0) {
544                                         tmp_b = get_bool_from_xml(items->children);
545                                         item_name = (char *)xmlGetProp(items, BAD_CAST"name");
546                                         mapItems[item_name]->set_open(tmp_b);
547                                 } else if (xmlStrcmp(items->name, BAD_CAST"pump")==0) {
548                                         tmp_b = get_bool_from_xml(items->children);
549                                         item_name = (char *)xmlGetProp(items, BAD_CAST"name");
550                                         mapItems[item_name]->set_open(tmp_b);
551                                 }  else if (xmlStrcmp(items->name, BAD_CAST"color")==0) {
552                                         item_name = (char *)xmlGetProp(items, BAD_CAST"name");
553                                         mapItems[item_name]->set_color( get_rgb_from_xml(items->children) );
554                                 } else if (xmlStrcmp(items->name, BAD_CAST"tank")==0) {
555                                         xmlNodePtr nodo_tmp = items->children;
556                                         float cap, lit;
557                                         cap = lit = -1;
558                                         while (nodo_tmp != NULL) {
559                                                 if (nodo_tmp->type == XML_ELEMENT_NODE) {
560                                                         if (xmlStrcmp(nodo_tmp->name, BAD_CAST"capacity")==0)
561                                                                 cap = atof( (char *)XML_GET_CONTENT(nodo_tmp->children) );
562                                                         else if (xmlStrcmp(nodo_tmp->name, BAD_CAST"litros")==0)
563                                                                 lit= atof( (char *)XML_GET_CONTENT(nodo_tmp->children) );
564                                                 }
565                                                 nodo_tmp = nodo_tmp->next;
566                                         }
567                                         item_name = (char *)xmlGetProp(items, BAD_CAST"name");
568                                         mapItems[item_name]->set_actual_flow(cap);
569                                         mapItems[item_name]->set_extra(lit);
570                                 }
571                         }
572                         items = items->next;
573                 }
574
575                 // Actualizo la UI
576                 update_ui();
577         }
578 }
579
580 Gdk::Color Principal::get_rgb_from_xml(xmlNodePtr nodo)
581 {
582         unsigned r,g,b;
583         while (nodo != NULL) {
584                 if (nodo->type == XML_ELEMENT_NODE) {
585                         if (xmlStrcmp(nodo->name, BAD_CAST"r")==0)
586                                 r = atoi( (char *)XML_GET_CONTENT(nodo->children) );
587                         if (xmlStrcmp(nodo->name, BAD_CAST"g")==0)
588                                 g = atoi( (char *)XML_GET_CONTENT(nodo->children) );
589                         if (xmlStrcmp(nodo->name, BAD_CAST"b")==0)
590                                 b = atoi( (char *)XML_GET_CONTENT(nodo->children) );
591                 }
592                 nodo = nodo->next;
593         }
594         r = 65535 * r / 255;
595         g = 65535 * g / 255;
596         b = 65535 * b / 255;
597         Gdk::Color c;
598         c.set_rgb(r,g,b);
599
600         return c;
601 }
602 float Principal::get_float_from_xml(xmlNodePtr nodo)
603 {
604         float tmp = -1;
605         while (nodo != NULL) {
606                 if (nodo->type == XML_ELEMENT_NODE) {
607                         if (xmlStrcmp(nodo->name, BAD_CAST"actual_flow")==0) {
608                                 tmp = atof( (char *)XML_GET_CONTENT(nodo->children) );
609                                 break;
610                         }
611                 }
612                 nodo = nodo->next;
613         }
614         return tmp;
615 }
616
617 bool Principal::get_bool_from_xml(xmlNodePtr nodo)
618 {
619         std::string tmp;
620         while (nodo != NULL) {
621                 if (nodo->type == XML_ELEMENT_NODE) {
622                         if (xmlStrcmp(nodo->name, BAD_CAST"active")==0) {
623                                 tmp = (char *)XML_GET_CONTENT(nodo->children);
624                                 break;
625                         }
626                 }
627                 nodo = nodo->next;
628         }
629         return tmp == "true";
630 }
631