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 *bar_connect=0;
27 lbl_cap_flujo = lbl_cap_extra = lbl_extra = lbl_nombre = lbl_color = lbl_flujo = 0;
28 btn_simulate = btn_pause = 0;
30 anim_frames[0] = Gdk::Pixbuf::create_from_file(PACKAGE_DATA_DIR"/plaqui-client/pixmaps/anim_0.png");
31 anim_frames[1] = Gdk::Pixbuf::create_from_file(PACKAGE_DATA_DIR"/plaqui-client/pixmaps/anim_1.png");
32 anim_frames[2] = Gdk::Pixbuf::create_from_file(PACKAGE_DATA_DIR"/plaqui-client/pixmaps/anim_2.png");
33 anim_frames[3] = Gdk::Pixbuf::create_from_file(PACKAGE_DATA_DIR"/plaqui-client/pixmaps/anim_3.png");
34 anim_frames[4] = Gdk::Pixbuf::create_from_file(PACKAGE_DATA_DIR"/plaqui-client/pixmaps/anim_4.png");
38 rg->get_widget("anim_frames", anim);
39 anim->set(anim_frames[current_frame]);
41 rg->get_widget("btn_pausa", btn_pause);
42 rg->get_widget("btn_simular", btn_simulate);
43 rg->get_widget("btn_activar", btn_activar);
44 rg->get_widget("color_preview", color_preview);
45 rg->get_widget("lbl_nombre", lbl_nombre);
46 rg->get_widget("lbl_extra", lbl_extra);
47 rg->get_widget("lbl_cap_extra", lbl_cap_extra);
48 rg->get_widget("lbl_cap_flujo", lbl_cap_flujo);
49 rg->get_widget("lbl_flujo", lbl_flujo);
50 rg->get_widget("mnu_file_connect", conect);
51 rg->get_widget("mnu_file_disconnect", mnu_disconnect);
52 rg->get_widget("mnu_file_exit", exit);
53 rg->get_widget("mnu_help_about", about);
54 rg->get_widget("mnu_prop", mnu_prop);
55 rg->get_widget_derived("dlg_property", dlg_property);
56 rg->get_widget_derived("dlgConectar", dlg_conectar);
57 rg->get_widget("txt_view", txt_view);
58 rg->get_widget("bar_connect", bar_connect);
59 rg->get_widget("work_place", work_place);
60 rg->get_widget("ico_conected", ico_conected);
62 work_place->signal_expose_event().connect( SigC::slot(*this, &Principal::on_workplace_expose_event) );
63 dlg_property->get_ok_button()->signal_clicked().connect( SigC::slot(*this, &Principal::on_dlg_property_ok) );
64 dlg_conectar->get_ok_button()->signal_clicked().connect( SigC::slot(*this, &Principal::on_dlg_connect_ok) );
65 mnu_prop->signal_activate().connect( SigC::slot(*this, &Principal::on_mnu_property));
66 mnu_disconnect->signal_activate().connect( SigC::slot(*this, &Principal::on_mnu_file_disconnect));
67 conect->signal_activate().connect( SigC::slot(*this, &Principal::on_mnu_file_connect));
68 bar_connect->signal_clicked().connect( SigC::slot(*this, &Principal::on_mnu_file_connect));
69 exit->signal_activate().connect( SigC::slot(*this, &Principal::on_mnu_file_exit));
70 about->signal_activate().connect( SigC::slot(*this, &Principal::on_mnu_help_about));
71 btn_activar->signal_clicked().connect( SigC::slot(*this, &Principal::on_btn_activar_clicked) );
72 btn_simulate->signal_clicked().connect( SigC::slot(*this, &Principal::on_btn_simulate_clicked) );
73 btn_pause->signal_clicked().connect( SigC::slot(*this, &Principal::on_btn_pause_clicked) );
76 is_xml_loaded = false;
79 update_ui.connect( SigC::slot(*this, &Principal::update_items_prop ) );
80 load_xml_dispatch.connect( SigC::slot(*this, &Principal::loadXML ) );
81 gc = Gdk::GC::create(get_window());
82 color_low = Gdk::Color("blue");
83 color_high = Gdk::Color("red");
84 Gtk::Widget::get_default_colormap()->alloc_color(color_low);
85 Gtk::Widget::get_default_colormap()->alloc_color(color_high);
88 Principal::~Principal()
93 // Espera a que termine realmente.
95 Glib::usleep(100000); // 0,1 segundo
99 void Principal::on_realize()
101 Gtk::Window::on_realize();
104 bool Principal::on_workplace_expose_event(GdkEventExpose *e)
106 Glib::RefPtr<Gdk::Window> window = work_place->get_window();
110 std::map<const std::string, ViewItem *>::iterator i;
111 for(i=mapItems.begin(); i!=mapItems.end(); i++) {
112 if (dynamic_cast<ViewAnd *>(i->second) || dynamic_cast<ViewOr *>(i->second) || dynamic_cast<ViewNot *>(i->second)) {
113 x1 = i->second->x + i->second->in_x;
114 y1 = i->second->y + i->second->in_y;
115 std::list<std::string>::iterator linea;
116 for(linea=i->second->in_lines.begin(); linea!=i->second->in_lines.end(); linea++) {
117 ViewItem *tmp = find_item(*linea);
118 x2 = tmp->x + tmp->out_x;
119 y2 = tmp->y + tmp->out_y;
120 if (tmp->get_open()) {
121 gc->set_foreground(color_high);
123 gc->set_foreground(color_low);
125 gc->set_line_attributes(3, Gdk::LINE_SOLID, Gdk::CAP_NOT_LAST, Gdk::JOIN_MITER);
126 window->draw_line(gc, x2+tmp->item_offset_x, y2+tmp->item_offset_y, x2+tmp->item_offset_x, y1+i->second->offset_y);
127 window->draw_line(gc, x2+tmp->item_offset_x, y1+i->second->offset_y, x1+i->second->offset_x, y1+i->second->offset_y);
128 window->draw_line(gc, x1, y1, x1+i->second->offset_x, y1+i->second->offset_y);
129 window->draw_line(gc, x2, y2, x2+tmp->item_offset_x, y2+tmp->item_offset_y);
131 x1 = i->second->x + i->second->out_x;
132 y1 = i->second->y + i->second->out_y;
133 for(linea=i->second->out_lines.begin(); linea!=i->second->out_lines.end(); linea++) {
134 ViewItem *tmp = find_item(*linea);
135 x2 = tmp->x + tmp->in_x;
136 y2 = tmp->y + tmp->in_y;
137 if (i->second->get_open()) {
138 gc->set_foreground(color_high);
140 gc->set_foreground(color_low);
142 gc->set_line_attributes(3, Gdk::LINE_SOLID, Gdk::CAP_NOT_LAST, Gdk::JOIN_MITER);
143 window->draw_line(gc, x1+i->second->offset_x, y1+i->second->offset_y, x1+i->second->offset_x, y2+tmp->item_offset_y);
144 window->draw_line(gc, x1+i->second->offset_x, y2+tmp->item_offset_y, x2+tmp->item_offset_x, y2+tmp->item_offset_y);
145 window->draw_line(gc, x1, y1, x1+i->second->offset_x, y1+i->second->offset_y);
146 window->draw_line(gc, x2, y2, x2+tmp->item_offset_x, y2+tmp->item_offset_y);
152 ViewItem *Principal::find_item(std::string &_name)
154 std::map<const std::string, ViewItem *>::iterator i;
155 for(i=mapItems.begin(); i!=mapItems.end(); i++) {
156 if (i->second->get_name() == _name) {
163 void Principal::on_dlg_connect_ok()
165 if (conexion == NULL) {
168 conexion = new PlaQui::Server::ControlClient(dlg_conectar->get_server_name(), dlg_conectar->get_server_port());
171 txt_view->get_buffer()->insert_at_cursor("NO SE PUDO CREAR OBJETO\n");
172 //delete conexion; XXX Si no me equivoco, si falla el
173 //constructor, no se reserva la memoria (el delete no va).
178 // Conecto las señales
179 conexion->signal_ok_received().connect( SigC::slot(*this, &Principal::on_conexion_ok) );
180 conexion->signal_error().connect( SigC::slot(*this, &Principal::on_conexion_fatal_error) );
181 conexion->signal_error_received().connect( SigC::slot(*this, &Principal::on_conexion_error) );
182 conexion->signal_finished().connect( SigC::slot(*this, &Principal::on_conexion_finished) );
183 conexion->signal_frame_received().connect(SigC::slot(*this, &Principal::on_conexion_frame));
184 // Lanzo la conexion!
186 txt_view->get_buffer()->insert_at_cursor("CONNECTED\n");
187 ico_conected->set( Gtk::Stock::YES , Gtk::IconSize(Gtk::ICON_SIZE_LARGE_TOOLBAR));
189 // Pido la planta por defecto
190 PlaQui::Server::Command c("plant", "get");
191 c.add_arg("default");
194 dlg_conectar->hide();
197 void Principal::on_mnu_file_exit()
199 on_mnu_file_disconnect();
203 bool Principal::on_delete_event(GdkEventAny *e)
209 void Principal::on_btn_activar_clicked()
211 if ((conexion == NULL) || (last_selected == NULL)) return;
213 PlaQui::Server::Command c("plant", "set");
214 c.add_arg("default");
215 c.add_arg(last_selected->get_name());
218 if (last_selected->get_open())
226 void Principal::on_mnu_file_disconnect()
228 if (conexion == NULL) return;
230 PlaQui::Server::Command c("transmission", "stop");
231 c.add_arg(conexion->get_host());
234 PlaQui::Server::Command c2("connection", "stop");
235 c2.add_arg(conexion->get_host());
236 c2.add_arg(conexion->get_port());
241 void Principal::on_mnu_file_connect()
243 dlg_conectar->show();
246 void Principal::on_mnu_help_about()
248 // preparo para leer el archivo ChangeLog
249 /* Glib::RefPtr<Gnome::Glade::Xml> xml;
251 Glib::RefPtr<Gtk::TextBuffer> log_buffer;
252 Glib::RefPtr<Glib::IOChannel> log_io;
254 log_buffer = Gtk::TextBuffer::create();
255 log_io = Glib::IOChannel::create_from_file("../ChangeLog", "r");
256 while (log_io->read_line(line) != Glib::IO_STATUS_EOF) {
257 log_buffer->insert_at_cursor(line);
261 xml = Gnome::Glade::Xml::create("client.glade", "dlgAbout");
263 catch(const Gnome::Glade::XmlError &ex) {
264 std::cerr << ex.what() << std::endl;
267 Gtk::Window *dlg = 0;
268 Gtk::Button *btn_cerrar = 0;
269 Gtk::TextView *txt_changelog = 0;
270 xml->get_widget("dlgAbout", dlg);
271 xml->get_widget("btn_close", btn_cerrar);
272 xml->get_widget("txt_changelog", txt_changelog);
273 btn_cerrar->signal_clicked().connect(SigC::slot(*dlg, &Gtk::Dialog::hide));
274 txt_changelog->set_buffer(log_buffer);
278 bool Principal::on_item_clicked(GdkEventButton *e, ViewItem *i)
281 txt_view->get_buffer()->insert_at_cursor("Selecciono ");
282 txt_view->get_buffer()->insert_at_cursor(i->get_name());
283 txt_view->get_buffer()->insert_at_cursor("\n");
289 void Principal::update_items_prop()
291 if (last_selected != NULL) {
292 lbl_nombre->set_text(last_selected->get_name());
293 lbl_flujo->set_text(last_selected->get_actual_flow());
294 lbl_extra->set_text(last_selected->get_extra());
296 lbl_cap_flujo->set_text(last_selected->get_cap_flow());
297 lbl_cap_extra->set_text(last_selected->get_cap_extra());
299 color_preview->modify_bg(Gtk::STATE_NORMAL, last_selected->get_color());
300 color_preview->queue_draw();
305 if (current_frame > 4) {
308 anim->set(anim_frames[current_frame]);
311 // Mando a redibujar a todos los items
312 std::map<const std::string, ViewItem *>::iterator i;
313 for(i=mapItems.begin(); i!=mapItems.end(); i++) {
314 i->second->queue_draw();
316 work_place->queue_draw();
319 void Principal::on_conexion_frame(const std::string &frame)
321 if (conexion != NULL) {
322 read_status_xml(frame);
326 void Principal::on_conexion_finished()
328 txt_view->get_buffer()->insert_at_cursor("HANG UP\n");
329 ico_conected->set( Gtk::Stock::NO , Gtk::IconSize(Gtk::ICON_SIZE_LARGE_TOOLBAR));
332 std::map<const std::string, ViewItem *>::iterator i;
333 for(i=mapItems.begin(); i!=mapItems.end(); i++) {
339 void Principal::on_conexion_ok(const std::string &body)
341 /* lo paso a la carga del XML */
342 /* verifico que body este completo */
343 if ((body.find("</planta>")>0) && (body.find("<planta>")>0)) {
348 std::cout << body << std::endl;
349 txt_view->get_buffer()->insert_at_cursor("<IN>\n");
350 txt_view->get_buffer()->insert_at_cursor(Glib::locale_to_utf8(body));
351 txt_view->get_buffer()->insert_at_cursor("</IN>\n");
355 void Principal::on_conexion_fatal_error(const PlaQui::Server::ControlClient::Error& code, const std::string& desc)
361 txt_view->get_buffer()->insert_at_cursor("Error de red nro. ");
362 txt_view->get_buffer()->insert_at_cursor(s);
363 txt_view->get_buffer()->insert_at_cursor(": ");
364 txt_view->get_buffer()->insert_at_cursor(desc);
365 txt_view->get_buffer()->insert_at_cursor("\n");
368 void Principal::on_conexion_error(unsigned code, const std::string& desc)
374 txt_view->get_buffer()->insert_at_cursor("El server dice que hay error nro. ");
375 txt_view->get_buffer()->insert_at_cursor(s);
376 txt_view->get_buffer()->insert_at_cursor(": ");
377 txt_view->get_buffer()->insert_at_cursor(desc);
378 txt_view->get_buffer()->insert_at_cursor("\n");
381 void Principal::loadXML()
384 if (is_xml_loaded) return;
386 /* Parseo de ejemplo de un XML desde archivo */
388 document = xmlParseMemory(xml_body.c_str(),xml_body.size());
389 if (document == NULL) {
390 std::cout << "EEERRRRRRROOOOOOOOOO" << std::endl;
393 is_xml_loaded = true;
394 /* bien, el archivo se parseo bien! */
395 xmlNodePtr nodo, items;
396 nodo = document->children;
398 if (strcmp((char *)nodo->name, "planta") == 0) {
399 items = nodo->children;
400 while (items != NULL) {
401 if (items->type == XML_ELEMENT_NODE) {
402 if (xmlStrcmp(items->name, BAD_CAST"bomba")==0) {
404 } else if (xmlStrcmp(items->name, BAD_CAST"codo")==0) {
406 } else if (xmlStrcmp(items->name, BAD_CAST"tubo")==0) {
408 } else if (xmlStrcmp(items->name, BAD_CAST"exclusa")==0) {
410 } else if (xmlStrcmp(items->name, BAD_CAST"tanque")==0) {
412 } else if (xmlStrcmp(items->name, BAD_CAST"empalme")==0) {
414 } else if (xmlStrcmp(items->name, BAD_CAST"drenaje")==0) {
416 } else if (xmlStrcmp(items->name, BAD_CAST"and")==0) {
418 } else if (xmlStrcmp(items->name, BAD_CAST"or")==0) {
420 } else if (xmlStrcmp(items->name, BAD_CAST"not")==0) {
429 xmlFreeDoc(document);
431 // Ya cargado el XML, mando un msg para empezar a recibir los frames!
432 PlaQui::Server::Command c("transmission", "start");
433 c.add_arg("default");
434 c.add_arg(conexion->get_host());
439 void Principal::loadNot(xmlNodePtr nodo)
441 std::string name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
442 std::string id = (char *)xmlGetProp(nodo, BAD_CAST"id");
443 int orientacion=0, x, y;
446 nodo = nodo->children;
447 while (nodo != NULL) {
448 if (nodo->type == XML_ELEMENT_NODE) {
449 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
450 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
451 p = new ViewNot(name, orientacion);
452 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
453 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
454 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
455 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
456 } else if (xmlStrcmp(nodo->name, BAD_CAST"salida") == 0) {
457 p->out_lines.push_back((char *)XML_GET_CONTENT(nodo->children));
458 } else if (xmlStrcmp(nodo->name, BAD_CAST"entrada") == 0) {
459 p->in_lines.push_back((char *)XML_GET_CONTENT(nodo->children));
465 p->signal_button_press_event().connect(SigC::bind( SigC::slot(*this, &Principal::on_item_clicked), p) );
466 p->set_position(x,y);
467 work_place->put(*p, x, y);
469 // los agrego al hash
473 void Principal::loadOr(xmlNodePtr nodo)
475 std::string name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
476 std::string id = (char *)xmlGetProp(nodo, BAD_CAST"id");
477 int orientacion=0, x, y;
481 nodo = nodo->children;
482 while (nodo != NULL) {
483 if (nodo->type == XML_ELEMENT_NODE) {
484 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
485 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
486 p = new ViewOr(name, orientacion);
487 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
488 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
489 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
490 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
491 } else if (xmlStrcmp(nodo->name, BAD_CAST"salida") == 0) {
492 p->out_lines.push_back((char *)XML_GET_CONTENT(nodo->children));
493 } else if (xmlStrcmp(nodo->name, BAD_CAST"entrada") == 0) {
494 p->in_lines.push_back((char *)XML_GET_CONTENT(nodo->children));
500 p->signal_button_press_event().connect(SigC::bind( SigC::slot(*this, &Principal::on_item_clicked), p) );
501 p->set_position(x,y);
502 work_place->put(*p, x, y);
504 // los agrego al hash
508 void Principal::loadAnd(xmlNodePtr nodo)
510 std::string name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
511 std::string id = (char *)xmlGetProp(nodo, BAD_CAST"id");
512 int orientacion=0, x, y;
514 xmlNodePtr inicial = nodo;
518 nodo = nodo->children;
519 while (nodo != NULL) {
520 if (nodo->type == XML_ELEMENT_NODE) {
521 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
522 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
523 p = new ViewAnd(name, orientacion);
524 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
525 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
526 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
527 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
528 } else if (xmlStrcmp(nodo->name, BAD_CAST"salida") == 0) {
529 p->out_lines.push_back((char *)XML_GET_CONTENT(nodo->children));
530 } else if (xmlStrcmp(nodo->name, BAD_CAST"entrada") == 0) {
531 p->in_lines.push_back((char *)XML_GET_CONTENT(nodo->children));
537 p->signal_button_press_event().connect(SigC::bind( SigC::slot(*this, &Principal::on_item_clicked), p) );
538 p->set_position(x,y);
539 work_place->put(*p, x, y);
541 // los agrego al hash
545 void Principal::loadBomba(xmlNodePtr nodo)
547 Glib::ustring name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
548 int orientacion=0, x, y;
550 nodo = nodo->children;
551 while (nodo != NULL) {
552 if (nodo->type == XML_ELEMENT_NODE) {
553 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
554 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
555 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
556 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
557 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
558 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
564 // listo, ya recolecte todos los datos, ahora creo el objeto!
565 ViewPump *b = new ViewPump(name, orientacion);
566 b->signal_button_press_event().connect(SigC::bind( SigC::slot(*this, &Principal::on_item_clicked), b) );
567 b->set_position(x,y);
568 work_place->put(*b, x, y);
570 // los agrego al hash
574 void Principal::loadCodo(xmlNodePtr nodo)
576 std::string name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
577 int orientacion=0, x, y;
579 nodo = nodo->children;
580 while (nodo != NULL) {
581 if (nodo->type == XML_ELEMENT_NODE) {
582 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
583 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
584 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
585 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
586 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
587 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
593 // listo, ya recolecte todos los datos, ahora creo el objeto!
594 ViewItem *b = new ViewCodo(name, orientacion);
595 b->signal_button_press_event().connect(SigC::bind( SigC::slot(*this, &Principal::on_item_clicked), b) );
596 b->set_position(x,y);
597 work_place->put(*b, x, y);
599 // los agrego al hash
603 void Principal::loadConduct(xmlNodePtr nodo)
605 Glib::ustring name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
606 int orientacion=0, x, y;
608 nodo = nodo->children;
609 while (nodo != NULL) {
610 if (nodo->type == XML_ELEMENT_NODE) {
611 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
612 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
613 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
614 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
615 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
616 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
622 // listo, ya recolecte todos los datos, ahora creo el objeto!
623 ViewConduct *b = new ViewConduct(name, orientacion);
624 b->signal_button_press_event().connect(SigC::bind( SigC::slot(*this, &Principal::on_item_clicked), b) );
625 b->set_position(x,y);
626 work_place->put(*b, x, y);
628 // los agrego al hash
632 void Principal::loadExclusa(xmlNodePtr nodo)
634 Glib::ustring name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
635 int orientacion=0, x, y;
637 nodo = nodo->children;
638 while (nodo != NULL) {
639 if (nodo->type == XML_ELEMENT_NODE) {
640 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
641 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
642 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
643 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
644 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
645 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
651 // listo, ya recolecte todos los datos, ahora creo el objeto!
652 ViewExclusa *b = new ViewExclusa(name, orientacion);
653 b->signal_button_press_event().connect(SigC::bind( SigC::slot(*this, &Principal::on_item_clicked), b) );
654 b->set_position(x,y);
655 work_place->put(*b, x, y);
657 // los agrego al hash
661 void Principal::loadTank(xmlNodePtr nodo)
663 Glib::ustring name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
664 int orientacion=0, x, y;
666 nodo = nodo->children;
667 while (nodo != NULL) {
668 if (nodo->type == XML_ELEMENT_NODE) {
669 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
670 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
671 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
672 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
673 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
674 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
680 // listo, ya recolecte todos los datos, ahora creo el objeto!
681 ViewTank *b = new ViewTank(name, orientacion);
682 b->signal_button_press_event().connect(SigC::bind( SigC::slot(*this, &Principal::on_item_clicked), b) );
683 b->set_position(x,y);
684 work_place->put(*b, x, y);
686 // los agrego al hash
690 void Principal::loadUnion(xmlNodePtr nodo)
692 Glib::ustring name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
693 int orientacion=0, x, y;
695 nodo = nodo->children;
696 while (nodo != NULL) {
697 if (nodo->type == XML_ELEMENT_NODE) {
698 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
699 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
700 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
701 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
702 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
703 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
709 // listo, ya recolecte todos los datos, ahora creo el objeto!
710 ViewUnion *b = new ViewUnion(name, orientacion);
711 b->signal_button_release_event().connect(SigC::bind( SigC::slot(*this, &Principal::on_item_clicked), b) );
712 b->set_position(x,y);
713 work_place->put(*b, x, y);
715 // los agrego al hash
719 void Principal::loadDrain(xmlNodePtr nodo)
721 Glib::ustring name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
722 int orientacion=0, x, y;
724 nodo = nodo->children;
725 while (nodo != NULL) {
726 if (nodo->type == XML_ELEMENT_NODE) {
727 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
728 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
729 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
730 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
731 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
732 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
738 // listo, ya recolecte todos los datos, ahora creo el objeto!
739 ViewDrain *b = new ViewDrain(name, orientacion);
740 b->signal_button_release_event().connect(SigC::bind( SigC::slot(*this, &Principal::on_item_clicked), b) );
741 b->set_position(x,y);
742 work_place->put(*b, x, y);
744 // los agrego al hash
748 void Principal::read_status_xml(const std::string &frame)
750 std::string item_name;
752 document = xmlParseMemory(frame.c_str(),frame.size());
753 if (document == NULL) {
754 std::cout << "read_status_xml::no se creo documento" << std::endl;
758 xmlNodePtr nodo, items, props;
759 nodo = document->children;
763 if (strcmp((char *)nodo->name, "plantstatus") == 0) {
764 items = nodo->children;
765 while (items != NULL) {
766 if (items->type == XML_ELEMENT_NODE) {
769 if (xmlStrcmp(items->name, BAD_CAST"float")==0) {
770 tmp = get_float_from_xml(items->children);
771 item_name = (char *)xmlGetProp(items, BAD_CAST"name");
772 mapItems[item_name]->set_actual_flow(tmp);
773 } else if (xmlStrcmp(items->name, BAD_CAST"exclusa")==0) {
774 tmp_b = get_bool_from_xml(items->children);
775 item_name = (char *)xmlGetProp(items, BAD_CAST"name");
776 mapItems[item_name]->set_open(tmp_b);
777 } else if (xmlStrcmp(items->name, BAD_CAST"pump")==0) {
778 tmp_b = get_bool_from_xml(items->children);
779 item_name = (char *)xmlGetProp(items, BAD_CAST"name");
780 mapItems[item_name]->set_open(tmp_b);
781 } else if (xmlStrcmp(items->name, BAD_CAST"logic")==0) {
782 tmp_b = get_bool_from_xml(items->children);
783 item_name = (char *)xmlGetProp(items, BAD_CAST"name");
784 mapItems[item_name]->set_open(tmp_b);
785 } else if (xmlStrcmp(items->name, BAD_CAST"color")==0) {
786 item_name = (char *)xmlGetProp(items, BAD_CAST"name");
787 mapItems[item_name]->set_color( get_rgb_from_xml(items->children) );
788 } else if (xmlStrcmp(items->name, BAD_CAST"tank")==0) {
789 xmlNodePtr nodo_tmp = items->children;
792 while (nodo_tmp != NULL) {
793 if (nodo_tmp->type == XML_ELEMENT_NODE) {
794 if (xmlStrcmp(nodo_tmp->name, BAD_CAST"capacity")==0)
795 cap = atof( (char *)XML_GET_CONTENT(nodo_tmp->children) );
796 else if (xmlStrcmp(nodo_tmp->name, BAD_CAST"litros")==0)
797 lit= atof( (char *)XML_GET_CONTENT(nodo_tmp->children) );
799 nodo_tmp = nodo_tmp->next;
801 item_name = (char *)xmlGetProp(items, BAD_CAST"name");
802 mapItems[item_name]->set_actual_flow(cap);
803 mapItems[item_name]->set_extra(lit);
809 xmlFreeDoc(document);
815 Gdk::Color Principal::get_rgb_from_xml(xmlNodePtr nodo)
818 while (nodo != NULL) {
819 if (nodo->type == XML_ELEMENT_NODE) {
820 if (xmlStrcmp(nodo->name, BAD_CAST"r")==0)
821 r = atoi( (char *)XML_GET_CONTENT(nodo->children) );
822 if (xmlStrcmp(nodo->name, BAD_CAST"g")==0)
823 g = atoi( (char *)XML_GET_CONTENT(nodo->children) );
824 if (xmlStrcmp(nodo->name, BAD_CAST"b")==0)
825 b = atoi( (char *)XML_GET_CONTENT(nodo->children) );
829 r = static_cast<gushort>(65535 * (r / 255.0f));
830 g = static_cast<gushort>(65535 * (g / 255.0f));
831 b = static_cast<gushort>(65535 * (b / 255.0f));
838 float Principal::get_float_from_xml(xmlNodePtr nodo)
841 while (nodo != NULL) {
842 if (nodo->type == XML_ELEMENT_NODE) {
843 if (xmlStrcmp(nodo->name, BAD_CAST"actual_flow")==0) {
844 tmp = atof( (char *)XML_GET_CONTENT(nodo->children) );
850 if (tmp == INFINITO) tmp = 0;
854 bool Principal::get_bool_from_xml(xmlNodePtr nodo)
857 while (nodo != NULL) {
858 if (nodo->type == XML_ELEMENT_NODE) {
859 if (xmlStrcmp(nodo->name, BAD_CAST"active")==0) {
860 tmp = (char *)XML_GET_CONTENT(nodo->children);
866 return tmp == "true";
869 void Principal::on_mnu_property()
871 dlg_property->show();
874 void Principal::on_dlg_property_ok()
877 PlaQui::Server::Command c("plant", "set_frequency");
878 c.add_arg("default");
879 c.add_arg( dlg_property->get_velocity() );
883 dlg_property->hide();
886 void Principal::on_btn_simulate_clicked()
888 if (conexion == NULL) return;
890 PlaQui::Server::Command c("plant", "start");
891 c.add_arg("default");
896 void Principal::on_btn_pause_clicked()
898 if (conexion == NULL) return;
900 PlaQui::Server::Command c("plant", "stop");
901 c.add_arg("default");