7 #include "item_conduct.h"
8 #include "item_exclusa.h"
10 #include "item_pump.h"
11 #include "item_union.h"
12 #include "item_drain.h"
17 #include <glibmm/thread.h>
19 #define INFINITO 99999999
21 Principal::Principal(BaseObjectType *co, const Glib::RefPtr<Gnome::Glade::Xml> &rg):Gtk::Window(co),refXml(rg)
23 Gtk::MenuItem *conect=0, *exit=0, *about=0, *mnu_prop=0, *mnu_disconnect=0;
24 Gtk::Button *btn_get=0, *bar_connect=0;
26 txt_target = txt_command = txt_args = 0;
28 lbl_cap_flujo = lbl_cap_extra = lbl_extra = lbl_nombre = lbl_color = lbl_flujo = 0;
29 btn_simulate = btn_pause = 0;
31 rg->get_widget("btn_pausa", btn_pause);
32 rg->get_widget("btn_simular", btn_simulate);
33 rg->get_widget("btn_activar", btn_activar);
34 rg->get_widget("color_preview", color_preview);
35 rg->get_widget("lbl_nombre", lbl_nombre);
36 rg->get_widget("lbl_extra", lbl_extra);
37 rg->get_widget("lbl_cap_extra", lbl_cap_extra);
38 rg->get_widget("lbl_cap_flujo", lbl_cap_flujo);
39 rg->get_widget("lbl_flujo", lbl_flujo);
40 rg->get_widget("mnu_file_connect", conect);
41 rg->get_widget("mnu_file_disconnect", mnu_disconnect);
42 rg->get_widget("mnu_file_exit", exit);
43 rg->get_widget("mnu_help_about", about);
44 rg->get_widget("mnu_prop", mnu_prop);
45 rg->get_widget_derived("dlg_property", dlg_property);
46 rg->get_widget_derived("dlgConectar", dlg_conectar);
47 rg->get_widget("btn_get", btn_get);
48 rg->get_widget("txt_view", txt_view);
49 rg->get_widget("txt_target", txt_target);
50 rg->get_widget("txt_command", txt_command);
51 rg->get_widget("txt_args", txt_args);
52 rg->get_widget("bar_connect", bar_connect);
53 rg->get_widget("work_place", work_place);
54 rg->get_widget("ico_conected", ico_conected);
56 work_place->signal_expose_event().connect( SigC::slot(*this, &Principal::on_workplace_expose_event) );
57 dlg_property->get_ok_button()->signal_clicked().connect( SigC::slot(*this, &Principal::on_dlg_property_ok) );
58 dlg_conectar->get_ok_button()->signal_clicked().connect( SigC::slot(*this, &Principal::on_dlg_connect_ok) );
59 mnu_prop->signal_activate().connect( SigC::slot(*this, &Principal::on_mnu_property));
60 mnu_disconnect->signal_activate().connect( SigC::slot(*this, &Principal::on_mnu_file_disconnect));
61 conect->signal_activate().connect( SigC::slot(*this, &Principal::on_mnu_file_connect));
62 bar_connect->signal_clicked().connect( SigC::slot(*this, &Principal::on_mnu_file_connect));
63 exit->signal_activate().connect( SigC::slot(*this, &Principal::on_mnu_file_exit));
64 about->signal_activate().connect( SigC::slot(*this, &Principal::on_mnu_help_about));
65 btn_get->signal_clicked().connect( SigC::slot(*this, &Principal::on_get_clicked) );
66 btn_activar->signal_clicked().connect( SigC::slot(*this, &Principal::on_btn_activar_clicked) );
67 btn_simulate->signal_clicked().connect( SigC::slot(*this, &Principal::on_btn_simulate_clicked) );
68 btn_pause->signal_clicked().connect( SigC::slot(*this, &Principal::on_btn_pause_clicked) );
71 is_xml_loaded = false;
73 update_ui.connect( SigC::slot(*this, &Principal::update_items_prop ) );
74 load_xml_dispatch.connect( SigC::slot(*this, &Principal::loadXML ) );
75 gc = Gdk::GC::create(get_window());
76 color_low = Gdk::Color("blue");
77 color_high = Gdk::Color("red");
78 Gtk::Widget::get_default_colormap()->alloc_color(color_low);
79 Gtk::Widget::get_default_colormap()->alloc_color(color_high);
82 Principal::~Principal()
87 // Espera a que termine realmente.
89 Glib::usleep(100000); // 0,1 segundo
93 void Principal::on_realize()
95 Gtk::Window::on_realize();
98 bool Principal::on_workplace_expose_event(GdkEventExpose *e)
100 Glib::RefPtr<Gdk::Window> window = work_place->get_window();
104 std::map<const std::string, ViewItem *>::iterator i;
105 for(i=mapItems.begin(); i!=mapItems.end(); i++) {
106 if (dynamic_cast<ViewAnd *>(i->second) || dynamic_cast<ViewOr *>(i->second) || dynamic_cast<ViewNot *>(i->second)) {
107 x1 = i->second->x + i->second->in_x;
108 y1 = i->second->y + i->second->in_y;
109 std::list<std::string>::iterator linea;
110 for(linea=i->second->in_lines.begin(); linea!=i->second->in_lines.end(); linea++) {
111 ViewItem *tmp = find_item(*linea);
112 x2 = tmp->x + tmp->out_x;
113 y2 = tmp->y + tmp->out_y;
114 if (tmp->get_open()) {
115 gc->set_foreground(color_high);
117 gc->set_foreground(color_low);
119 gc->set_line_attributes(3, Gdk::LINE_SOLID, Gdk::CAP_NOT_LAST, Gdk::JOIN_MITER);
120 window->draw_line(gc, x2+tmp->item_offset_x, y2+tmp->item_offset_y, x2+tmp->item_offset_x, y1+i->second->offset_y);
121 window->draw_line(gc, x2+tmp->item_offset_x, y1+i->second->offset_y, x1+i->second->offset_x, y1+i->second->offset_y);
122 window->draw_line(gc, x1, y1, x1+i->second->offset_x, y1+i->second->offset_y);
123 window->draw_line(gc, x2, y2, x2+tmp->item_offset_x, y2+tmp->item_offset_y);
125 x1 = i->second->x + i->second->out_x;
126 y1 = i->second->y + i->second->out_y;
127 for(linea=i->second->out_lines.begin(); linea!=i->second->out_lines.end(); linea++) {
128 ViewItem *tmp = find_item(*linea);
129 x2 = tmp->x + tmp->in_x;
130 y2 = tmp->y + tmp->in_y;
131 if (i->second->get_open()) {
132 gc->set_foreground(color_high);
134 gc->set_foreground(color_low);
136 gc->set_line_attributes(3, Gdk::LINE_SOLID, Gdk::CAP_NOT_LAST, Gdk::JOIN_MITER);
137 window->draw_line(gc, x1+i->second->offset_x, y1+i->second->offset_y, x1+i->second->offset_x, y2+tmp->item_offset_y);
138 window->draw_line(gc, x1+i->second->offset_x, y2+tmp->item_offset_y, x2+tmp->item_offset_x, y2+tmp->item_offset_y);
139 window->draw_line(gc, x1, y1, x1+i->second->offset_x, y1+i->second->offset_y);
140 window->draw_line(gc, x2, y2, x2+tmp->item_offset_x, y2+tmp->item_offset_y);
146 ViewItem *Principal::find_item(std::string &_name)
148 std::map<const std::string, ViewItem *>::iterator i;
149 for(i=mapItems.begin(); i!=mapItems.end(); i++) {
150 if (i->second->get_name() == _name) {
157 void Principal::on_dlg_connect_ok()
159 if (conexion == NULL) {
162 conexion = new PlaQui::Server::ControlClient(dlg_conectar->get_server_name(), dlg_conectar->get_server_port());
165 txt_view->get_buffer()->insert_at_cursor("NO SE PUDO CREAR OBJETO\n");
166 //delete conexion; XXX Si no me equivoco, si falla el
167 //constructor, no se reserva la memoria (el delete no va).
172 // Conecto las señales
173 conexion->signal_ok_received().connect( SigC::slot(*this, &Principal::on_conexion_ok) );
174 conexion->signal_error().connect( SigC::slot(*this, &Principal::on_conexion_fatal_error) );
175 conexion->signal_error_received().connect( SigC::slot(*this, &Principal::on_conexion_error) );
176 conexion->signal_finished().connect( SigC::slot(*this, &Principal::on_conexion_finished) );
177 conexion->signal_frame_received().connect(SigC::slot(*this, &Principal::on_conexion_frame));
178 // Lanzo la conexion!
180 txt_view->get_buffer()->insert_at_cursor("CONNECTED\n");
181 ico_conected->set( Gtk::Stock::YES , Gtk::IconSize(Gtk::ICON_SIZE_LARGE_TOOLBAR));
183 // Pido la planta por defecto
184 PlaQui::Server::Command c("plant", "get");
185 c.add_arg("default");
188 dlg_conectar->hide();
191 void Principal::on_mnu_file_exit()
193 on_mnu_file_disconnect();
197 bool Principal::on_delete_event(GdkEventAny *e)
203 void Principal::on_btn_activar_clicked()
205 if ((conexion == NULL) || (last_selected == NULL)) return;
207 PlaQui::Server::Command c("plant", "set");
208 c.add_arg("default");
209 c.add_arg(last_selected->get_name());
212 if (last_selected->get_open())
220 void Principal::on_mnu_file_disconnect()
222 if (conexion == NULL) return;
224 PlaQui::Server::Command c("transmission", "stop");
225 c.add_arg(conexion->get_host());
228 PlaQui::Server::Command c2("connection", "stop");
229 c2.add_arg(conexion->get_host());
230 c2.add_arg(conexion->get_port());
235 void Principal::on_mnu_file_connect()
237 dlg_conectar->show();
240 void Principal::on_mnu_help_about()
242 // preparo para leer el archivo ChangeLog
243 /* Glib::RefPtr<Gnome::Glade::Xml> xml;
245 Glib::RefPtr<Gtk::TextBuffer> log_buffer;
246 Glib::RefPtr<Glib::IOChannel> log_io;
248 log_buffer = Gtk::TextBuffer::create();
249 log_io = Glib::IOChannel::create_from_file("../ChangeLog", "r");
250 while (log_io->read_line(line) != Glib::IO_STATUS_EOF) {
251 log_buffer->insert_at_cursor(line);
255 xml = Gnome::Glade::Xml::create("client.glade", "dlgAbout");
257 catch(const Gnome::Glade::XmlError &ex) {
258 std::cerr << ex.what() << std::endl;
261 Gtk::Window *dlg = 0;
262 Gtk::Button *btn_cerrar = 0;
263 Gtk::TextView *txt_changelog = 0;
264 xml->get_widget("dlgAbout", dlg);
265 xml->get_widget("btn_close", btn_cerrar);
266 xml->get_widget("txt_changelog", txt_changelog);
267 btn_cerrar->signal_clicked().connect(SigC::slot(*dlg, &Gtk::Dialog::hide));
268 txt_changelog->set_buffer(log_buffer);
272 bool Principal::on_item_clicked(GdkEventButton *e, ViewItem *i)
275 txt_view->get_buffer()->insert_at_cursor("Selecciono ");
276 txt_view->get_buffer()->insert_at_cursor(i->get_name());
277 txt_view->get_buffer()->insert_at_cursor("\n");
283 void Principal::update_items_prop()
285 if (last_selected == NULL) return;
287 lbl_nombre->set_text(last_selected->get_name());
288 lbl_flujo->set_text(last_selected->get_actual_flow());
289 lbl_extra->set_text(last_selected->get_extra());
291 lbl_cap_flujo->set_text(last_selected->get_cap_flow());
292 lbl_cap_extra->set_text(last_selected->get_cap_extra());
294 color_preview->modify_bg(Gtk::STATE_NORMAL, last_selected->get_color());
295 color_preview->queue_draw();
297 // Mando a redibujar a todos los items
298 std::map<const std::string, ViewItem *>::iterator i;
299 for(i=mapItems.begin(); i!=mapItems.end(); i++) {
300 i->second->queue_draw();
302 work_place->queue_draw();
305 void Principal::on_conexion_frame(const std::string &frame)
307 if (conexion != NULL) {
308 read_status_xml(frame);
312 void Principal::on_conexion_finished()
314 txt_view->get_buffer()->insert_at_cursor("HANG UP\n");
315 ico_conected->set( Gtk::Stock::NO , Gtk::IconSize(Gtk::ICON_SIZE_LARGE_TOOLBAR));
318 std::map<const std::string, ViewItem *>::iterator i;
319 for(i=mapItems.begin(); i!=mapItems.end(); i++) {
325 void Principal::on_conexion_ok(const std::string &body)
327 /* lo paso a la carga del XML */
328 /* verifico que body este completo */
329 if ((body.find("</planta>")>0) && (body.find("<planta>")>0)) {
334 std::cout << body << std::endl;
335 txt_view->get_buffer()->insert_at_cursor("<IN>\n");
336 txt_view->get_buffer()->insert_at_cursor(Glib::locale_to_utf8(body));
337 txt_view->get_buffer()->insert_at_cursor("</IN>\n");
341 void Principal::on_conexion_fatal_error(const PlaQui::Server::ControlClient::Error& code, const std::string& desc)
347 txt_view->get_buffer()->insert_at_cursor("Error de red nro. ");
348 txt_view->get_buffer()->insert_at_cursor(s);
349 txt_view->get_buffer()->insert_at_cursor(": ");
350 txt_view->get_buffer()->insert_at_cursor(desc);
351 txt_view->get_buffer()->insert_at_cursor("\n");
354 void Principal::on_conexion_error(unsigned code, const std::string& desc)
360 txt_view->get_buffer()->insert_at_cursor("El server dice que hay error nro. ");
361 txt_view->get_buffer()->insert_at_cursor(s);
362 txt_view->get_buffer()->insert_at_cursor(": ");
363 txt_view->get_buffer()->insert_at_cursor(desc);
364 txt_view->get_buffer()->insert_at_cursor("\n");
367 void Principal::on_get_clicked()
369 if (conexion == NULL) {
370 txt_view->get_buffer()->insert_at_cursor("SIN CONEXION\n");
374 PlaQui::Server::Command command(txt_target->get_text(), txt_command->get_text());
375 command.add_arg( txt_args->get_text() );
376 txt_view->get_buffer()->insert_at_cursor("Enviando comando\n");
378 conexion->send(command);
381 txt_view->get_buffer()->insert_at_cursor("EXCEPTION EN conexion->send !!\n");
386 void Principal::loadXML()
389 if (is_xml_loaded) return;
391 /* Parseo de ejemplo de un XML desde archivo */
393 document = xmlParseMemory(xml_body.c_str(),xml_body.size());
394 if (document == NULL) {
395 std::cout << "EEERRRRRRROOOOOOOOOO" << std::endl;
398 is_xml_loaded = true;
399 /* bien, el archivo se parseo bien! */
400 xmlNodePtr nodo, items;
401 nodo = document->children;
403 if (strcmp((char *)nodo->name, "planta") == 0) {
404 items = nodo->children;
405 while (items != NULL) {
406 if (items->type == XML_ELEMENT_NODE) {
407 if (xmlStrcmp(items->name, BAD_CAST"bomba")==0) {
409 } else if (xmlStrcmp(items->name, BAD_CAST"codo")==0) {
411 } else if (xmlStrcmp(items->name, BAD_CAST"tubo")==0) {
413 } else if (xmlStrcmp(items->name, BAD_CAST"exclusa")==0) {
415 } else if (xmlStrcmp(items->name, BAD_CAST"tanque")==0) {
417 } else if (xmlStrcmp(items->name, BAD_CAST"empalme")==0) {
419 } else if (xmlStrcmp(items->name, BAD_CAST"drenaje")==0) {
421 } else if (xmlStrcmp(items->name, BAD_CAST"and")==0) {
423 } else if (xmlStrcmp(items->name, BAD_CAST"or")==0) {
425 } else if (xmlStrcmp(items->name, BAD_CAST"not")==0) {
434 xmlFreeDoc(document);
436 // Ya cargado el XML, mando un msg para empezar a recibir los frames!
437 PlaQui::Server::Command c("transmission", "start");
438 c.add_arg("default");
439 c.add_arg(conexion->get_host());
444 void Principal::loadNot(xmlNodePtr nodo)
446 std::string name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
447 std::string id = (char *)xmlGetProp(nodo, BAD_CAST"id");
448 int orientacion=0, x, y;
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 p = new ViewNot(name, orientacion);
457 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
458 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
459 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
460 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
461 } else if (xmlStrcmp(nodo->name, BAD_CAST"salida") == 0) {
462 p->out_lines.push_back((char *)XML_GET_CONTENT(nodo->children));
463 } else if (xmlStrcmp(nodo->name, BAD_CAST"entrada") == 0) {
464 p->in_lines.push_back((char *)XML_GET_CONTENT(nodo->children));
470 p->signal_button_press_event().connect(SigC::bind( SigC::slot(*this, &Principal::on_item_clicked), p) );
471 p->set_position(x,y);
472 work_place->put(*p, x, y);
474 // los agrego al hash
478 void Principal::loadOr(xmlNodePtr nodo)
480 std::string name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
481 std::string id = (char *)xmlGetProp(nodo, BAD_CAST"id");
482 int orientacion=0, x, y;
486 nodo = nodo->children;
487 while (nodo != NULL) {
488 if (nodo->type == XML_ELEMENT_NODE) {
489 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
490 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
491 p = new ViewOr(name, orientacion);
492 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
493 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
494 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
495 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
496 } else if (xmlStrcmp(nodo->name, BAD_CAST"salida") == 0) {
497 p->out_lines.push_back((char *)XML_GET_CONTENT(nodo->children));
498 } else if (xmlStrcmp(nodo->name, BAD_CAST"entrada") == 0) {
499 p->in_lines.push_back((char *)XML_GET_CONTENT(nodo->children));
505 p->signal_button_press_event().connect(SigC::bind( SigC::slot(*this, &Principal::on_item_clicked), p) );
506 p->set_position(x,y);
507 work_place->put(*p, x, y);
509 // los agrego al hash
513 void Principal::loadAnd(xmlNodePtr nodo)
515 std::string name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
516 std::string id = (char *)xmlGetProp(nodo, BAD_CAST"id");
517 int orientacion=0, x, y;
519 xmlNodePtr inicial = nodo;
523 nodo = nodo->children;
524 while (nodo != NULL) {
525 if (nodo->type == XML_ELEMENT_NODE) {
526 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
527 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
528 p = new ViewAnd(name, orientacion);
529 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
530 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
531 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
532 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
533 } else if (xmlStrcmp(nodo->name, BAD_CAST"salida") == 0) {
534 p->out_lines.push_back((char *)XML_GET_CONTENT(nodo->children));
535 } else if (xmlStrcmp(nodo->name, BAD_CAST"entrada") == 0) {
536 p->in_lines.push_back((char *)XML_GET_CONTENT(nodo->children));
542 p->signal_button_press_event().connect(SigC::bind( SigC::slot(*this, &Principal::on_item_clicked), p) );
543 p->set_position(x,y);
544 work_place->put(*p, x, y);
546 // los agrego al hash
550 void Principal::loadBomba(xmlNodePtr nodo)
552 Glib::ustring name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
553 int orientacion=0, x, y;
555 nodo = nodo->children;
556 while (nodo != NULL) {
557 if (nodo->type == XML_ELEMENT_NODE) {
558 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
559 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
560 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
561 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
562 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
563 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
569 // listo, ya recolecte todos los datos, ahora creo el objeto!
570 ViewPump *b = new ViewPump(name, orientacion);
571 b->signal_button_press_event().connect(SigC::bind( SigC::slot(*this, &Principal::on_item_clicked), b) );
572 b->set_position(x,y);
573 work_place->put(*b, x, y);
575 // los agrego al hash
579 void Principal::loadCodo(xmlNodePtr nodo)
581 std::string name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
582 int orientacion=0, x, y;
584 nodo = nodo->children;
585 while (nodo != NULL) {
586 if (nodo->type == XML_ELEMENT_NODE) {
587 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
588 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
589 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
590 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
591 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
592 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
598 // listo, ya recolecte todos los datos, ahora creo el objeto!
599 ViewItem *b = new ViewCodo(name, orientacion);
600 b->signal_button_press_event().connect(SigC::bind( SigC::slot(*this, &Principal::on_item_clicked), b) );
601 b->set_position(x,y);
602 work_place->put(*b, x, y);
604 // los agrego al hash
608 void Principal::loadConduct(xmlNodePtr nodo)
610 Glib::ustring name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
611 int orientacion=0, x, y;
613 nodo = nodo->children;
614 while (nodo != NULL) {
615 if (nodo->type == XML_ELEMENT_NODE) {
616 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
617 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
618 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
619 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
620 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
621 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
627 // listo, ya recolecte todos los datos, ahora creo el objeto!
628 ViewConduct *b = new ViewConduct(name, orientacion);
629 b->signal_button_press_event().connect(SigC::bind( SigC::slot(*this, &Principal::on_item_clicked), b) );
630 b->set_position(x,y);
631 work_place->put(*b, x, y);
633 // los agrego al hash
637 void Principal::loadExclusa(xmlNodePtr nodo)
639 Glib::ustring name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
640 int orientacion=0, x, y;
642 nodo = nodo->children;
643 while (nodo != NULL) {
644 if (nodo->type == XML_ELEMENT_NODE) {
645 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
646 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
647 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
648 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
649 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
650 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
656 // listo, ya recolecte todos los datos, ahora creo el objeto!
657 ViewExclusa *b = new ViewExclusa(name, orientacion);
658 b->signal_button_press_event().connect(SigC::bind( SigC::slot(*this, &Principal::on_item_clicked), b) );
659 b->set_position(x,y);
660 work_place->put(*b, x, y);
662 // los agrego al hash
666 void Principal::loadTank(xmlNodePtr nodo)
668 Glib::ustring name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
669 int orientacion=0, x, y;
671 nodo = nodo->children;
672 while (nodo != NULL) {
673 if (nodo->type == XML_ELEMENT_NODE) {
674 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
675 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
676 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
677 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
678 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
679 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
685 // listo, ya recolecte todos los datos, ahora creo el objeto!
686 ViewTank *b = new ViewTank(name, orientacion);
687 b->signal_button_press_event().connect(SigC::bind( SigC::slot(*this, &Principal::on_item_clicked), b) );
688 b->set_position(x,y);
689 work_place->put(*b, x, y);
691 // los agrego al hash
695 void Principal::loadUnion(xmlNodePtr nodo)
697 Glib::ustring name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
698 int orientacion=0, x, y;
700 nodo = nodo->children;
701 while (nodo != NULL) {
702 if (nodo->type == XML_ELEMENT_NODE) {
703 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
704 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
705 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
706 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
707 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
708 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
714 // listo, ya recolecte todos los datos, ahora creo el objeto!
715 ViewUnion *b = new ViewUnion(name, orientacion);
716 b->signal_button_release_event().connect(SigC::bind( SigC::slot(*this, &Principal::on_item_clicked), b) );
717 b->set_position(x,y);
718 work_place->put(*b, x, y);
720 // los agrego al hash
724 void Principal::loadDrain(xmlNodePtr nodo)
726 Glib::ustring name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
727 int orientacion=0, x, y;
729 nodo = nodo->children;
730 while (nodo != NULL) {
731 if (nodo->type == XML_ELEMENT_NODE) {
732 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
733 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
734 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
735 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
736 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
737 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
743 // listo, ya recolecte todos los datos, ahora creo el objeto!
744 ViewDrain *b = new ViewDrain(name, orientacion);
745 b->signal_button_release_event().connect(SigC::bind( SigC::slot(*this, &Principal::on_item_clicked), b) );
746 b->set_position(x,y);
747 work_place->put(*b, x, y);
749 // los agrego al hash
753 void Principal::read_status_xml(const std::string &frame)
755 std::string item_name;
757 document = xmlParseMemory(frame.c_str(),frame.size());
758 if (document == NULL) {
759 std::cout << "read_status_xml::no se creo documento" << std::endl;
763 xmlNodePtr nodo, items, props;
764 nodo = document->children;
768 if (strcmp((char *)nodo->name, "plantstatus") == 0) {
769 items = nodo->children;
770 while (items != NULL) {
771 if (items->type == XML_ELEMENT_NODE) {
774 if (xmlStrcmp(items->name, BAD_CAST"float")==0) {
775 tmp = get_float_from_xml(items->children);
776 item_name = (char *)xmlGetProp(items, BAD_CAST"name");
777 mapItems[item_name]->set_actual_flow(tmp);
778 } else if (xmlStrcmp(items->name, BAD_CAST"exclusa")==0) {
779 tmp_b = get_bool_from_xml(items->children);
780 item_name = (char *)xmlGetProp(items, BAD_CAST"name");
781 mapItems[item_name]->set_open(tmp_b);
782 } else if (xmlStrcmp(items->name, BAD_CAST"pump")==0) {
783 tmp_b = get_bool_from_xml(items->children);
784 item_name = (char *)xmlGetProp(items, BAD_CAST"name");
785 mapItems[item_name]->set_open(tmp_b);
786 } else if (xmlStrcmp(items->name, BAD_CAST"logic")==0) {
787 tmp_b = get_bool_from_xml(items->children);
788 item_name = (char *)xmlGetProp(items, BAD_CAST"name");
789 mapItems[item_name]->set_open(tmp_b);
790 } else if (xmlStrcmp(items->name, BAD_CAST"color")==0) {
791 item_name = (char *)xmlGetProp(items, BAD_CAST"name");
792 mapItems[item_name]->set_color( get_rgb_from_xml(items->children) );
793 } else if (xmlStrcmp(items->name, BAD_CAST"tank")==0) {
794 xmlNodePtr nodo_tmp = items->children;
797 while (nodo_tmp != NULL) {
798 if (nodo_tmp->type == XML_ELEMENT_NODE) {
799 if (xmlStrcmp(nodo_tmp->name, BAD_CAST"capacity")==0)
800 cap = atof( (char *)XML_GET_CONTENT(nodo_tmp->children) );
801 else if (xmlStrcmp(nodo_tmp->name, BAD_CAST"litros")==0)
802 lit= atof( (char *)XML_GET_CONTENT(nodo_tmp->children) );
804 nodo_tmp = nodo_tmp->next;
806 item_name = (char *)xmlGetProp(items, BAD_CAST"name");
807 mapItems[item_name]->set_actual_flow(cap);
808 mapItems[item_name]->set_extra(lit);
814 xmlFreeDoc(document);
820 Gdk::Color Principal::get_rgb_from_xml(xmlNodePtr nodo)
823 while (nodo != NULL) {
824 if (nodo->type == XML_ELEMENT_NODE) {
825 if (xmlStrcmp(nodo->name, BAD_CAST"r")==0)
826 r = atoi( (char *)XML_GET_CONTENT(nodo->children) );
827 if (xmlStrcmp(nodo->name, BAD_CAST"g")==0)
828 g = atoi( (char *)XML_GET_CONTENT(nodo->children) );
829 if (xmlStrcmp(nodo->name, BAD_CAST"b")==0)
830 b = atoi( (char *)XML_GET_CONTENT(nodo->children) );
834 r = static_cast<gushort>(65535 * (r / 255.0f));
835 g = static_cast<gushort>(65535 * (g / 255.0f));
836 b = static_cast<gushort>(65535 * (b / 255.0f));
843 float Principal::get_float_from_xml(xmlNodePtr nodo)
846 while (nodo != NULL) {
847 if (nodo->type == XML_ELEMENT_NODE) {
848 if (xmlStrcmp(nodo->name, BAD_CAST"actual_flow")==0) {
849 tmp = atof( (char *)XML_GET_CONTENT(nodo->children) );
855 if (tmp == INFINITO) tmp = 0;
859 bool Principal::get_bool_from_xml(xmlNodePtr nodo)
862 while (nodo != NULL) {
863 if (nodo->type == XML_ELEMENT_NODE) {
864 if (xmlStrcmp(nodo->name, BAD_CAST"active")==0) {
865 tmp = (char *)XML_GET_CONTENT(nodo->children);
871 return tmp == "true";
874 void Principal::on_mnu_property()
876 dlg_property->show();
879 void Principal::on_dlg_property_ok()
882 PlaQui::Server::Command c("plant", "set_frequency");
883 c.add_arg("default");
884 c.add_arg( dlg_property->get_velocity() );
888 dlg_property->hide();
891 void Principal::on_btn_simulate_clicked()
893 if (conexion == NULL) return;
895 PlaQui::Server::Command c("plant", "start");
896 c.add_arg("default");
900 void Principal::on_btn_pause_clicked()
902 if (conexion == NULL) return;
904 PlaQui::Server::Command c("plant", "stop");
905 c.add_arg("default");