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