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 Principal::Principal(BaseObjectType *co, const Glib::RefPtr<Gnome::Glade::Xml> &rg):Gtk::Window(co),refXml(rg)
21 Gtk::MenuItem *conect=0, *exit=0, *about=0, *mnu_prop=0, *mnu_disconnect=0;
22 Gtk::Button *btn_get=0, *bar_connect=0;
24 txt_target = txt_command = txt_args = 0;
26 lbl_cap_flujo = lbl_cap_extra = lbl_extra = lbl_nombre = lbl_color = lbl_flujo = 0;
27 btn_simulate = btn_pause = 0;
29 rg->get_widget("btn_pausa", btn_pause);
30 rg->get_widget("btn_simular", btn_simulate);
31 rg->get_widget("btn_activar", btn_activar);
32 rg->get_widget("color_preview", color_preview);
33 rg->get_widget("lbl_nombre", lbl_nombre);
34 rg->get_widget("lbl_extra", lbl_extra);
35 rg->get_widget("lbl_cap_extra", lbl_cap_extra);
36 rg->get_widget("lbl_cap_flujo", lbl_cap_flujo);
37 rg->get_widget("lbl_flujo", lbl_flujo);
38 rg->get_widget("mnu_file_connect", conect);
39 rg->get_widget("mnu_file_disconnect", mnu_disconnect);
40 rg->get_widget("mnu_file_exit", exit);
41 rg->get_widget("mnu_help_about", about);
42 rg->get_widget("mnu_prop", mnu_prop);
43 rg->get_widget_derived("dlg_property", dlg_property);
44 rg->get_widget_derived("dlgConectar", dlg_conectar);
45 rg->get_widget("btn_get", btn_get);
46 rg->get_widget("txt_view", txt_view);
47 rg->get_widget("txt_target", txt_target);
48 rg->get_widget("txt_command", txt_command);
49 rg->get_widget("txt_args", txt_args);
50 rg->get_widget("bar_connect", bar_connect);
51 rg->get_widget("work_place", work_place);
52 rg->get_widget("ico_conected", ico_conected);
54 work_place->signal_expose_event().connect( SigC::slot(*this, &Principal::on_workplace_expose_event) );
55 dlg_property->get_ok_button()->signal_clicked().connect( SigC::slot(*this, &Principal::on_dlg_property_ok) );
56 dlg_conectar->get_ok_button()->signal_clicked().connect( SigC::slot(*this, &Principal::on_dlg_connect_ok) );
57 mnu_prop->signal_activate().connect( SigC::slot(*this, &Principal::on_mnu_property));
58 mnu_disconnect->signal_activate().connect( SigC::slot(*this, &Principal::on_mnu_file_disconnect));
59 conect->signal_activate().connect( SigC::slot(*this, &Principal::on_mnu_file_connect));
60 bar_connect->signal_clicked().connect( SigC::slot(*this, &Principal::on_mnu_file_connect));
61 exit->signal_activate().connect( SigC::slot(*this, &Principal::on_mnu_file_exit));
62 about->signal_activate().connect( SigC::slot(*this, &Principal::on_mnu_help_about));
63 btn_get->signal_clicked().connect( SigC::slot(*this, &Principal::on_get_clicked) );
64 btn_activar->signal_clicked().connect( SigC::slot(*this, &Principal::on_btn_activar_clicked) );
65 btn_simulate->signal_clicked().connect( SigC::slot(*this, &Principal::on_btn_simulate_clicked) );
66 btn_pause->signal_clicked().connect( SigC::slot(*this, &Principal::on_btn_pause_clicked) );
69 is_xml_loaded = false;
71 update_ui.connect( SigC::slot(*this, &Principal::update_items_prop ) );
72 load_xml_dispatch.connect( SigC::slot(*this, &Principal::loadXML ) );
73 gc = Gdk::GC::create(get_window());
74 color_low = Gdk::Color("blue");
75 color_high = Gdk::Color("red");
76 Gtk::Widget::get_default_colormap()->alloc_color(color_low);
77 Gtk::Widget::get_default_colormap()->alloc_color(color_high);
80 Principal::~Principal()
85 // Espera a que termine realmente.
87 Glib::usleep(100000); // 0,1 segundo
91 void Principal::on_realize()
93 Gtk::Window::on_realize();
96 bool Principal::on_workplace_expose_event(GdkEventExpose *e)
98 Glib::RefPtr<Gdk::Window> window = work_place->get_window();
102 std::map<const std::string, ViewItem *>::iterator i;
103 for(i=mapItems.begin(); i!=mapItems.end(); i++) {
104 if (dynamic_cast<ViewAnd *>(i->second) || dynamic_cast<ViewOr *>(i->second) || dynamic_cast<ViewNot *>(i->second)) {
105 x1 = i->second->x + i->second->in_x;
106 y1 = i->second->y + i->second->in_y;
107 std::list<std::string>::iterator linea;
108 for(linea=i->second->in_lines.begin(); linea!=i->second->in_lines.end(); linea++) {
109 ViewItem *tmp = find_item(*linea);
110 x2 = tmp->x + tmp->out_x;
111 y2 = tmp->y + tmp->out_y;
112 if (tmp->get_open()) {
113 gc->set_foreground(color_high);
115 gc->set_foreground(color_low);
117 gc->set_line_attributes(3, Gdk::LINE_SOLID, Gdk::CAP_NOT_LAST, Gdk::JOIN_MITER);
118 window->draw_line(gc, x2+tmp->item_offset_x, y2+tmp->item_offset_y, x2+tmp->item_offset_x, y1+i->second->offset_y);
119 window->draw_line(gc, x2+tmp->item_offset_x, y1+i->second->offset_y, x1+i->second->offset_x, y1+i->second->offset_y);
120 window->draw_line(gc, x1, y1, x1+i->second->offset_x, y1+i->second->offset_y);
121 window->draw_line(gc, x2, y2, x2+tmp->item_offset_x, y2+tmp->item_offset_y);
123 x1 = i->second->x + i->second->out_x;
124 y1 = i->second->y + i->second->out_y;
125 for(linea=i->second->out_lines.begin(); linea!=i->second->out_lines.end(); linea++) {
126 ViewItem *tmp = find_item(*linea);
127 x2 = tmp->x + tmp->in_x;
128 y2 = tmp->y + tmp->in_y;
129 if (i->second->get_open()) {
130 gc->set_foreground(color_high);
132 gc->set_foreground(color_low);
134 gc->set_line_attributes(3, Gdk::LINE_SOLID, Gdk::CAP_NOT_LAST, Gdk::JOIN_MITER);
135 window->draw_line(gc, x1+i->second->offset_x, y1+i->second->offset_y, x1+i->second->offset_x, y2+tmp->item_offset_y);
136 window->draw_line(gc, x1+i->second->offset_x, y2+tmp->item_offset_y, x2+tmp->item_offset_x, y2+tmp->item_offset_y);
137 window->draw_line(gc, x1, y1, x1+i->second->offset_x, y1+i->second->offset_y);
138 window->draw_line(gc, x2, y2, x2+tmp->item_offset_x, y2+tmp->item_offset_y);
144 ViewItem *Principal::find_item(std::string &_name)
146 std::map<const std::string, ViewItem *>::iterator i;
147 for(i=mapItems.begin(); i!=mapItems.end(); i++) {
148 if (i->second->get_name() == _name) {
155 void Principal::on_dlg_connect_ok()
157 if (conexion == NULL) {
160 conexion = new PlaQui::Server::ControlClient(dlg_conectar->get_server_name(), dlg_conectar->get_server_port());
163 txt_view->get_buffer()->insert_at_cursor("NO SE PUDO CREAR OBJETO\n");
164 //delete conexion; XXX Si no me equivoco, si falla el
165 //constructor, no se reserva la memoria (el delete no va).
170 // Conecto las señales
171 conexion->signal_ok_received().connect( SigC::slot(*this, &Principal::on_conexion_ok) );
172 conexion->signal_error().connect( SigC::slot(*this, &Principal::on_conexion_fatal_error) );
173 conexion->signal_error_received().connect( SigC::slot(*this, &Principal::on_conexion_error) );
174 conexion->signal_finished().connect( SigC::slot(*this, &Principal::on_conexion_finished) );
175 conexion->signal_frame_received().connect(SigC::slot(*this, &Principal::on_conexion_frame));
176 // Lanzo la conexion!
178 txt_view->get_buffer()->insert_at_cursor("CONNECTED\n");
179 ico_conected->set( Gtk::Stock::YES , Gtk::IconSize(Gtk::ICON_SIZE_LARGE_TOOLBAR));
181 // Pido la planta por defecto
182 PlaQui::Server::Command c("plant", "get");
183 c.add_arg("default");
186 dlg_conectar->hide();
189 void Principal::on_mnu_file_exit()
191 on_mnu_file_disconnect();
195 bool Principal::on_delete_event(GdkEventAny *e)
201 void Principal::on_btn_activar_clicked()
203 if ((conexion == NULL) || (last_selected == NULL)) return;
205 PlaQui::Server::Command c("plant", "set");
206 c.add_arg("default");
207 c.add_arg(last_selected->get_name());
210 if (last_selected->get_open())
218 void Principal::on_mnu_file_disconnect()
220 if (conexion == NULL) return;
222 PlaQui::Server::Command c("transmission", "stop");
223 c.add_arg(conexion->get_host());
226 PlaQui::Server::Command c2("connection", "stop");
227 c2.add_arg(conexion->get_host());
228 c2.add_arg(conexion->get_port());
233 void Principal::on_mnu_file_connect()
235 dlg_conectar->show();
238 void Principal::on_mnu_help_about()
240 // preparo para leer el archivo ChangeLog
241 /* Glib::RefPtr<Gnome::Glade::Xml> xml;
243 Glib::RefPtr<Gtk::TextBuffer> log_buffer;
244 Glib::RefPtr<Glib::IOChannel> log_io;
246 log_buffer = Gtk::TextBuffer::create();
247 log_io = Glib::IOChannel::create_from_file("../ChangeLog", "r");
248 while (log_io->read_line(line) != Glib::IO_STATUS_EOF) {
249 log_buffer->insert_at_cursor(line);
253 xml = Gnome::Glade::Xml::create("client.glade", "dlgAbout");
255 catch(const Gnome::Glade::XmlError &ex) {
256 std::cerr << ex.what() << std::endl;
259 Gtk::Window *dlg = 0;
260 Gtk::Button *btn_cerrar = 0;
261 Gtk::TextView *txt_changelog = 0;
262 xml->get_widget("dlgAbout", dlg);
263 xml->get_widget("btn_close", btn_cerrar);
264 xml->get_widget("txt_changelog", txt_changelog);
265 btn_cerrar->signal_clicked().connect(SigC::slot(*dlg, &Gtk::Dialog::hide));
266 txt_changelog->set_buffer(log_buffer);
270 bool Principal::on_item_clicked(GdkEventButton *e, ViewItem *i)
273 txt_view->get_buffer()->insert_at_cursor("Selecciono ");
274 txt_view->get_buffer()->insert_at_cursor(i->get_name());
275 txt_view->get_buffer()->insert_at_cursor("\n");
281 void Principal::update_items_prop()
283 if (last_selected == NULL) return;
285 lbl_nombre->set_text(last_selected->get_name());
286 lbl_flujo->set_text(last_selected->get_actual_flow());
287 lbl_extra->set_text(last_selected->get_extra());
289 lbl_cap_flujo->set_text(last_selected->get_cap_flow());
290 lbl_cap_extra->set_text(last_selected->get_cap_extra());
292 color_preview->modify_bg(Gtk::STATE_NORMAL, last_selected->get_color());
293 color_preview->queue_draw();
295 // Mando a redibujar a todos los items
296 std::map<const std::string, ViewItem *>::iterator i;
297 for(i=mapItems.begin(); i!=mapItems.end(); i++) {
298 i->second->queue_draw();
300 work_place->queue_draw();
303 void Principal::on_conexion_frame(const std::string &frame)
305 if (conexion != NULL) {
306 read_status_xml(frame);
310 void Principal::on_conexion_finished()
312 txt_view->get_buffer()->insert_at_cursor("HANG UP\n");
313 ico_conected->set( Gtk::Stock::NO , Gtk::IconSize(Gtk::ICON_SIZE_LARGE_TOOLBAR));
316 std::map<const std::string, ViewItem *>::iterator i;
317 for(i=mapItems.begin(); i!=mapItems.end(); i++) {
323 void Principal::on_conexion_ok(const std::string &body)
325 /* lo paso a la carga del XML */
326 /* verifico que body este completo */
327 if ((body.find("</planta>")>0) && (body.find("<planta>")>0)) {
332 std::cout << body << std::endl;
333 txt_view->get_buffer()->insert_at_cursor("<IN>\n");
334 txt_view->get_buffer()->insert_at_cursor(Glib::locale_to_utf8(body));
335 txt_view->get_buffer()->insert_at_cursor("</IN>\n");
339 void Principal::on_conexion_fatal_error(const PlaQui::Server::ControlClient::Error& code, const std::string& desc)
345 txt_view->get_buffer()->insert_at_cursor("Error de red nro. ");
346 txt_view->get_buffer()->insert_at_cursor(s);
347 txt_view->get_buffer()->insert_at_cursor(": ");
348 txt_view->get_buffer()->insert_at_cursor(desc);
349 txt_view->get_buffer()->insert_at_cursor("\n");
352 void Principal::on_conexion_error(unsigned code, const std::string& desc)
358 txt_view->get_buffer()->insert_at_cursor("El server dice que hay error nro. ");
359 txt_view->get_buffer()->insert_at_cursor(s);
360 txt_view->get_buffer()->insert_at_cursor(": ");
361 txt_view->get_buffer()->insert_at_cursor(desc);
362 txt_view->get_buffer()->insert_at_cursor("\n");
365 void Principal::on_get_clicked()
367 if (conexion == NULL) {
368 txt_view->get_buffer()->insert_at_cursor("SIN CONEXION\n");
372 PlaQui::Server::Command command(txt_target->get_text(), txt_command->get_text());
373 command.add_arg( txt_args->get_text() );
374 txt_view->get_buffer()->insert_at_cursor("Enviando comando\n");
376 conexion->send(command);
379 txt_view->get_buffer()->insert_at_cursor("EXCEPTION EN conexion->send !!\n");
384 void Principal::loadXML()
387 if (is_xml_loaded) return;
389 /* Parseo de ejemplo de un XML desde archivo */
391 document = xmlParseMemory(xml_body.c_str(),xml_body.size());
392 if (document == NULL) {
393 std::cout << "EEERRRRRRROOOOOOOOOO" << std::endl;
396 is_xml_loaded = true;
397 /* bien, el archivo se parseo bien! */
398 xmlNodePtr nodo, items;
399 nodo = document->children;
401 if (strcmp((char *)nodo->name, "planta") == 0) {
402 items = nodo->children;
403 while (items != NULL) {
404 if (items->type == XML_ELEMENT_NODE) {
405 if (xmlStrcmp(items->name, BAD_CAST"bomba")==0) {
407 } else if (xmlStrcmp(items->name, BAD_CAST"codo")==0) {
409 } else if (xmlStrcmp(items->name, BAD_CAST"tubo")==0) {
411 } else if (xmlStrcmp(items->name, BAD_CAST"exclusa")==0) {
413 } else if (xmlStrcmp(items->name, BAD_CAST"tanque")==0) {
415 } else if (xmlStrcmp(items->name, BAD_CAST"empalme")==0) {
417 } else if (xmlStrcmp(items->name, BAD_CAST"drenaje")==0) {
419 } else if (xmlStrcmp(items->name, BAD_CAST"and")==0) {
421 } else if (xmlStrcmp(items->name, BAD_CAST"or")==0) {
423 } else if (xmlStrcmp(items->name, BAD_CAST"not")==0) {
432 xmlFreeDoc(document);
434 // Ya cargado el XML, mando un msg para empezar a recibir los frames!
435 PlaQui::Server::Command c("transmission", "start");
436 c.add_arg("default");
437 c.add_arg(conexion->get_host());
442 void Principal::loadNot(xmlNodePtr nodo)
444 std::string name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
445 std::string id = (char *)xmlGetProp(nodo, BAD_CAST"id");
446 int orientacion=0, x, y;
449 nodo = nodo->children;
450 while (nodo != NULL) {
451 if (nodo->type == XML_ELEMENT_NODE) {
452 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
453 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
454 p = new ViewNot(name, orientacion);
455 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
456 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
457 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
458 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
459 } else if (xmlStrcmp(nodo->name, BAD_CAST"salida") == 0) {
460 p->out_lines.push_back((char *)XML_GET_CONTENT(nodo->children));
461 } else if (xmlStrcmp(nodo->name, BAD_CAST"entrada") == 0) {
462 p->in_lines.push_back((char *)XML_GET_CONTENT(nodo->children));
468 p->signal_button_press_event().connect(SigC::bind( SigC::slot(*this, &Principal::on_item_clicked), p) );
469 p->set_position(x,y);
470 work_place->put(*p, x, y);
472 // los agrego al hash
476 void Principal::loadOr(xmlNodePtr nodo)
478 std::string name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
479 std::string id = (char *)xmlGetProp(nodo, BAD_CAST"id");
480 int orientacion=0, x, y;
484 nodo = nodo->children;
485 while (nodo != NULL) {
486 if (nodo->type == XML_ELEMENT_NODE) {
487 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
488 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
489 p = new ViewOr(name, orientacion);
490 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
491 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
492 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
493 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
494 } else if (xmlStrcmp(nodo->name, BAD_CAST"salida") == 0) {
495 p->out_lines.push_back((char *)XML_GET_CONTENT(nodo->children));
496 } else if (xmlStrcmp(nodo->name, BAD_CAST"entrada") == 0) {
497 p->in_lines.push_back((char *)XML_GET_CONTENT(nodo->children));
503 p->signal_button_press_event().connect(SigC::bind( SigC::slot(*this, &Principal::on_item_clicked), p) );
504 p->set_position(x,y);
505 work_place->put(*p, x, y);
507 // los agrego al hash
511 void Principal::loadAnd(xmlNodePtr nodo)
513 std::string name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
514 std::string id = (char *)xmlGetProp(nodo, BAD_CAST"id");
515 int orientacion=0, x, y;
517 xmlNodePtr inicial = nodo;
521 nodo = nodo->children;
522 while (nodo != NULL) {
523 if (nodo->type == XML_ELEMENT_NODE) {
524 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
525 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
526 p = new ViewAnd(name, orientacion);
527 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
528 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
529 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
530 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
531 } else if (xmlStrcmp(nodo->name, BAD_CAST"salida") == 0) {
532 p->out_lines.push_back((char *)XML_GET_CONTENT(nodo->children));
533 } else if (xmlStrcmp(nodo->name, BAD_CAST"entrada") == 0) {
534 p->in_lines.push_back((char *)XML_GET_CONTENT(nodo->children));
540 p->signal_button_press_event().connect(SigC::bind( SigC::slot(*this, &Principal::on_item_clicked), p) );
541 p->set_position(x,y);
542 work_place->put(*p, x, y);
544 // los agrego al hash
548 void Principal::loadBomba(xmlNodePtr nodo)
550 Glib::ustring name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
551 int orientacion=0, x, y;
553 nodo = nodo->children;
554 while (nodo != NULL) {
555 if (nodo->type == XML_ELEMENT_NODE) {
556 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
557 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
558 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
559 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
560 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
561 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
567 // listo, ya recolecte todos los datos, ahora creo el objeto!
568 ViewPump *b = new ViewPump(name, orientacion);
569 b->signal_button_press_event().connect(SigC::bind( SigC::slot(*this, &Principal::on_item_clicked), b) );
570 b->set_position(x,y);
571 work_place->put(*b, x, y);
573 // los agrego al hash
577 void Principal::loadCodo(xmlNodePtr nodo)
579 std::string name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
580 int orientacion=0, x, y;
582 nodo = nodo->children;
583 while (nodo != NULL) {
584 if (nodo->type == XML_ELEMENT_NODE) {
585 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
586 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
587 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
588 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
589 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
590 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
596 // listo, ya recolecte todos los datos, ahora creo el objeto!
597 ViewItem *b = new ViewCodo(name, orientacion);
598 b->signal_button_press_event().connect(SigC::bind( SigC::slot(*this, &Principal::on_item_clicked), b) );
599 b->set_position(x,y);
600 work_place->put(*b, x, y);
602 // los agrego al hash
606 void Principal::loadConduct(xmlNodePtr nodo)
608 Glib::ustring name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
609 int orientacion=0, x, y;
611 nodo = nodo->children;
612 while (nodo != NULL) {
613 if (nodo->type == XML_ELEMENT_NODE) {
614 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
615 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
616 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
617 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
618 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
619 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
625 // listo, ya recolecte todos los datos, ahora creo el objeto!
626 ViewConduct *b = new ViewConduct(name, orientacion);
627 b->signal_button_press_event().connect(SigC::bind( SigC::slot(*this, &Principal::on_item_clicked), b) );
628 b->set_position(x,y);
629 work_place->put(*b, x, y);
631 // los agrego al hash
635 void Principal::loadExclusa(xmlNodePtr nodo)
637 Glib::ustring name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
638 int orientacion=0, x, y;
640 nodo = nodo->children;
641 while (nodo != NULL) {
642 if (nodo->type == XML_ELEMENT_NODE) {
643 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
644 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
645 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
646 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
647 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
648 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
654 // listo, ya recolecte todos los datos, ahora creo el objeto!
655 ViewExclusa *b = new ViewExclusa(name, orientacion);
656 b->signal_button_press_event().connect(SigC::bind( SigC::slot(*this, &Principal::on_item_clicked), b) );
657 b->set_position(x,y);
658 work_place->put(*b, x, y);
660 // los agrego al hash
664 void Principal::loadTank(xmlNodePtr nodo)
666 Glib::ustring name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
667 int orientacion=0, x, y;
669 nodo = nodo->children;
670 while (nodo != NULL) {
671 if (nodo->type == XML_ELEMENT_NODE) {
672 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
673 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
674 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
675 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
676 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
677 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
683 // listo, ya recolecte todos los datos, ahora creo el objeto!
684 ViewTank *b = new ViewTank(name, orientacion);
685 b->signal_button_press_event().connect(SigC::bind( SigC::slot(*this, &Principal::on_item_clicked), b) );
686 b->set_position(x,y);
687 work_place->put(*b, x, y);
689 // los agrego al hash
693 void Principal::loadUnion(xmlNodePtr nodo)
695 Glib::ustring name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
696 int orientacion=0, x, y;
698 nodo = nodo->children;
699 while (nodo != NULL) {
700 if (nodo->type == XML_ELEMENT_NODE) {
701 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
702 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
703 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
704 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
705 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
706 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
712 // listo, ya recolecte todos los datos, ahora creo el objeto!
713 ViewUnion *b = new ViewUnion(name, orientacion);
714 b->signal_button_release_event().connect(SigC::bind( SigC::slot(*this, &Principal::on_item_clicked), b) );
715 b->set_position(x,y);
716 work_place->put(*b, x, y);
718 // los agrego al hash
722 void Principal::loadDrain(xmlNodePtr nodo)
724 Glib::ustring name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
725 int orientacion=0, x, y;
727 nodo = nodo->children;
728 while (nodo != NULL) {
729 if (nodo->type == XML_ELEMENT_NODE) {
730 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
731 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
732 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
733 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
734 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
735 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
741 // listo, ya recolecte todos los datos, ahora creo el objeto!
742 ViewDrain *b = new ViewDrain(name, orientacion);
743 b->signal_button_release_event().connect(SigC::bind( SigC::slot(*this, &Principal::on_item_clicked), b) );
744 b->set_position(x,y);
745 work_place->put(*b, x, y);
747 // los agrego al hash
751 void Principal::read_status_xml(const std::string &frame)
753 std::string item_name;
755 document = xmlParseMemory(frame.c_str(),frame.size());
756 if (document == NULL) {
757 std::cout << "read_status_xml::no se creo documento" << std::endl;
761 xmlNodePtr nodo, items, props;
762 nodo = document->children;
766 if (strcmp((char *)nodo->name, "plantstatus") == 0) {
767 items = nodo->children;
768 while (items != NULL) {
769 if (items->type == XML_ELEMENT_NODE) {
772 if (xmlStrcmp(items->name, BAD_CAST"float")==0) {
773 tmp = get_float_from_xml(items->children);
774 item_name = (char *)xmlGetProp(items, BAD_CAST"name");
775 mapItems[item_name]->set_actual_flow(tmp);
776 } else if (xmlStrcmp(items->name, BAD_CAST"exclusa")==0) {
777 tmp_b = get_bool_from_xml(items->children);
778 item_name = (char *)xmlGetProp(items, BAD_CAST"name");
779 mapItems[item_name]->set_open(tmp_b);
780 } else if (xmlStrcmp(items->name, BAD_CAST"pump")==0) {
781 tmp_b = get_bool_from_xml(items->children);
782 item_name = (char *)xmlGetProp(items, BAD_CAST"name");
783 mapItems[item_name]->set_open(tmp_b);
784 } else if (xmlStrcmp(items->name, BAD_CAST"logic")==0) {
785 tmp_b = get_bool_from_xml(items->children);
786 item_name = (char *)xmlGetProp(items, BAD_CAST"name");
787 mapItems[item_name]->set_open(tmp_b);
788 } else if (xmlStrcmp(items->name, BAD_CAST"color")==0) {
789 item_name = (char *)xmlGetProp(items, BAD_CAST"name");
790 mapItems[item_name]->set_color( get_rgb_from_xml(items->children) );
791 } else if (xmlStrcmp(items->name, BAD_CAST"tank")==0) {
792 xmlNodePtr nodo_tmp = items->children;
795 while (nodo_tmp != NULL) {
796 if (nodo_tmp->type == XML_ELEMENT_NODE) {
797 if (xmlStrcmp(nodo_tmp->name, BAD_CAST"capacity")==0)
798 cap = atof( (char *)XML_GET_CONTENT(nodo_tmp->children) );
799 else if (xmlStrcmp(nodo_tmp->name, BAD_CAST"litros")==0)
800 lit= atof( (char *)XML_GET_CONTENT(nodo_tmp->children) );
802 nodo_tmp = nodo_tmp->next;
804 item_name = (char *)xmlGetProp(items, BAD_CAST"name");
805 mapItems[item_name]->set_actual_flow(cap);
806 mapItems[item_name]->set_extra(lit);
812 xmlFreeDoc(document);
818 Gdk::Color Principal::get_rgb_from_xml(xmlNodePtr nodo)
821 while (nodo != NULL) {
822 if (nodo->type == XML_ELEMENT_NODE) {
823 if (xmlStrcmp(nodo->name, BAD_CAST"r")==0)
824 r = atoi( (char *)XML_GET_CONTENT(nodo->children) );
825 if (xmlStrcmp(nodo->name, BAD_CAST"g")==0)
826 g = atoi( (char *)XML_GET_CONTENT(nodo->children) );
827 if (xmlStrcmp(nodo->name, BAD_CAST"b")==0)
828 b = atoi( (char *)XML_GET_CONTENT(nodo->children) );
832 r = static_cast<gushort>(65535 * (r / 255.0f));
833 g = static_cast<gushort>(65535 * (g / 255.0f));
834 b = static_cast<gushort>(65535 * (b / 255.0f));
841 float Principal::get_float_from_xml(xmlNodePtr nodo)
844 while (nodo != NULL) {
845 if (nodo->type == XML_ELEMENT_NODE) {
846 if (xmlStrcmp(nodo->name, BAD_CAST"actual_flow")==0) {
847 tmp = atof( (char *)XML_GET_CONTENT(nodo->children) );
856 bool Principal::get_bool_from_xml(xmlNodePtr nodo)
859 while (nodo != NULL) {
860 if (nodo->type == XML_ELEMENT_NODE) {
861 if (xmlStrcmp(nodo->name, BAD_CAST"active")==0) {
862 tmp = (char *)XML_GET_CONTENT(nodo->children);
868 return tmp == "true";
871 void Principal::on_mnu_property()
873 dlg_property->show();
876 void Principal::on_dlg_property_ok()
879 PlaQui::Server::Command c("plant", "set_frequency");
880 c.add_arg("default");
881 c.add_arg( dlg_property->get_velocity() );
885 dlg_property->hide();
888 void Principal::on_btn_simulate_clicked()
890 if (conexion == NULL) return;
892 PlaQui::Server::Command c("plant", "start");
893 c.add_arg("default");
897 void Principal::on_btn_pause_clicked()
899 if (conexion == NULL) return;
901 PlaQui::Server::Command c("plant", "stop");
902 c.add_arg("default");