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