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());
76 Principal::~Principal()
81 // Espera a que termine realmente.
83 Glib::usleep(100000); // 0,1 segundo
87 void Principal::on_realize()
89 Gtk::Window::on_realize();
92 bool Principal::on_workplace_expose_event(GdkEventExpose *e)
94 Glib::RefPtr<Gdk::Window> window = work_place->get_window();
98 std::map<const std::string, ViewItem *>::iterator i;
99 for(i=mapItems.begin(); i!=mapItems.end(); i++) {
100 if (dynamic_cast<ViewAnd *>(i->second) || dynamic_cast<ViewOr *>(i->second) || dynamic_cast<ViewNot *>(i->second)) {
101 x1 = i->second->x + i->second->in_x;
102 y1 = i->second->y + i->second->in_y;
103 std::list<std::string>::iterator linea;
104 for(linea=i->second->in_lines.begin(); linea!=i->second->in_lines.end(); linea++) {
105 ViewItem *tmp = find_item(*linea);
106 x2 = tmp->x + tmp->out_x;
107 y2 = tmp->y + tmp->out_y;
108 gc->set_line_attributes(3, Gdk::LINE_SOLID, Gdk::CAP_NOT_LAST, Gdk::JOIN_MITER);
109 window->draw_line(gc, x2+tmp->item_offset_x, y2+tmp->item_offset_y, x2+tmp->item_offset_x, y1+i->second->offset_y);
110 window->draw_line(gc, x2+tmp->item_offset_x, y1+i->second->offset_y, x1+i->second->offset_x, y1+i->second->offset_y);
111 window->draw_line(gc, x1, y1, x1+i->second->offset_x, y1+i->second->offset_y);
112 window->draw_line(gc, x2, y2, x2+tmp->item_offset_x, y2+tmp->item_offset_y);
114 x1 = i->second->x + i->second->out_x;
115 y1 = i->second->y + i->second->out_y;
116 for(linea=i->second->out_lines.begin(); linea!=i->second->out_lines.end(); linea++) {
117 ViewItem *tmp = find_item(*linea);
118 x2 = tmp->x + tmp->in_x;
119 y2 = tmp->y + tmp->in_y;
120 gc->set_line_attributes(3, Gdk::LINE_SOLID, Gdk::CAP_NOT_LAST, Gdk::JOIN_MITER);
121 window->draw_line(gc, x1+i->second->offset_x, y1+i->second->offset_y, x1+i->second->offset_x, y2+tmp->item_offset_y);
122 window->draw_line(gc, x1+i->second->offset_x, y2+tmp->item_offset_y, x2+tmp->item_offset_x, y2+tmp->item_offset_y);
123 window->draw_line(gc, x1, y1, x1+i->second->offset_x, y1+i->second->offset_y);
124 window->draw_line(gc, x2, y2, x2+tmp->item_offset_x, y2+tmp->item_offset_y);
130 ViewItem *Principal::find_item(std::string &_name)
132 std::map<const std::string, ViewItem *>::iterator i;
133 for(i=mapItems.begin(); i!=mapItems.end(); i++) {
134 if (i->second->get_name() == _name) {
141 void Principal::on_dlg_connect_ok()
143 if (conexion == NULL) {
146 conexion = new PlaQui::Server::ControlClient(dlg_conectar->get_server_name(), dlg_conectar->get_server_port());
149 txt_view->get_buffer()->insert_at_cursor("NO SE PUDO CREAR OBJETO\n");
150 //delete conexion; XXX Si no me equivoco, si falla el
151 //constructor, no se reserva la memoria (el delete no va).
156 // Conecto las señales
157 conexion->signal_ok_received().connect( SigC::slot(*this, &Principal::on_conexion_ok) );
158 conexion->signal_error().connect( SigC::slot(*this, &Principal::on_conexion_fatal_error) );
159 conexion->signal_error_received().connect( SigC::slot(*this, &Principal::on_conexion_error) );
160 conexion->signal_finished().connect( SigC::slot(*this, &Principal::on_conexion_finished) );
161 conexion->signal_frame_received().connect(SigC::slot(*this, &Principal::on_conexion_frame));
162 // Lanzo la conexion!
164 txt_view->get_buffer()->insert_at_cursor("CONNECTED\n");
165 ico_conected->set( Gtk::Stock::YES , Gtk::IconSize(Gtk::ICON_SIZE_LARGE_TOOLBAR));
167 // Pido la planta por defecto
168 PlaQui::Server::Command c("plant", "get");
169 c.add_arg("default");
172 dlg_conectar->hide();
175 void Principal::on_mnu_file_exit()
177 on_mnu_file_disconnect();
181 bool Principal::on_delete_event(GdkEventAny *e)
187 void Principal::on_btn_activar_clicked()
189 if ((conexion == NULL) || (last_selected == NULL)) return;
191 PlaQui::Server::Command c("plant", "set");
192 c.add_arg("default");
193 c.add_arg(last_selected->get_name());
196 if (last_selected->get_open())
204 void Principal::on_mnu_file_disconnect()
206 if (conexion == NULL) return;
208 PlaQui::Server::Command c("transmission", "stop");
209 c.add_arg(conexion->get_host());
212 PlaQui::Server::Command c2("connection", "stop");
213 c2.add_arg(conexion->get_host());
214 c2.add_arg(conexion->get_port());
219 void Principal::on_mnu_file_connect()
221 dlg_conectar->show();
224 void Principal::on_mnu_help_about()
226 // preparo para leer el archivo ChangeLog
227 /* Glib::RefPtr<Gnome::Glade::Xml> xml;
229 Glib::RefPtr<Gtk::TextBuffer> log_buffer;
230 Glib::RefPtr<Glib::IOChannel> log_io;
232 log_buffer = Gtk::TextBuffer::create();
233 log_io = Glib::IOChannel::create_from_file("../ChangeLog", "r");
234 while (log_io->read_line(line) != Glib::IO_STATUS_EOF) {
235 log_buffer->insert_at_cursor(line);
239 xml = Gnome::Glade::Xml::create("client.glade", "dlgAbout");
241 catch(const Gnome::Glade::XmlError &ex) {
242 std::cerr << ex.what() << std::endl;
245 Gtk::Window *dlg = 0;
246 Gtk::Button *btn_cerrar = 0;
247 Gtk::TextView *txt_changelog = 0;
248 xml->get_widget("dlgAbout", dlg);
249 xml->get_widget("btn_close", btn_cerrar);
250 xml->get_widget("txt_changelog", txt_changelog);
251 btn_cerrar->signal_clicked().connect(SigC::slot(*dlg, &Gtk::Dialog::hide));
252 txt_changelog->set_buffer(log_buffer);
256 bool Principal::on_item_clicked(GdkEventButton *e, ViewItem *i)
259 txt_view->get_buffer()->insert_at_cursor("Selecciono ");
260 txt_view->get_buffer()->insert_at_cursor(i->get_name());
261 txt_view->get_buffer()->insert_at_cursor("\n");
267 void Principal::update_items_prop()
269 if (last_selected == NULL) return;
271 lbl_nombre->set_text(last_selected->get_name());
272 lbl_flujo->set_text(last_selected->get_actual_flow());
273 lbl_extra->set_text(last_selected->get_extra());
275 lbl_cap_flujo->set_text(last_selected->get_cap_flow());
276 lbl_cap_extra->set_text(last_selected->get_cap_extra());
278 color_preview->modify_bg(Gtk::STATE_NORMAL, last_selected->get_color());
279 color_preview->queue_draw();
281 // Mando a redibujar a todos los items
282 std::map<const std::string, ViewItem *>::iterator i;
283 for(i=mapItems.begin(); i!=mapItems.end(); i++) {
284 i->second->queue_draw();
289 void Principal::on_conexion_frame(const std::string &frame)
291 if (conexion != NULL) {
292 read_status_xml(frame);
296 void Principal::on_conexion_finished()
298 txt_view->get_buffer()->insert_at_cursor("HANG UP\n");
299 ico_conected->set( Gtk::Stock::NO , Gtk::IconSize(Gtk::ICON_SIZE_LARGE_TOOLBAR));
302 std::map<const std::string, ViewItem *>::iterator i;
303 for(i=mapItems.begin(); i!=mapItems.end(); i++) {
309 void Principal::on_conexion_ok(const std::string &body)
311 /* lo paso a la carga del XML */
312 /* verifico que body este completo */
313 if ((body.find("</planta>")>0) && (body.find("<planta>")>0)) {
318 std::cout << body << std::endl;
319 txt_view->get_buffer()->insert_at_cursor("<IN>\n");
320 txt_view->get_buffer()->insert_at_cursor(Glib::locale_to_utf8(body));
321 txt_view->get_buffer()->insert_at_cursor("</IN>\n");
325 void Principal::on_conexion_fatal_error(const PlaQui::Server::ControlClient::Error& code, const std::string& desc)
331 txt_view->get_buffer()->insert_at_cursor("Error de red nro. ");
332 txt_view->get_buffer()->insert_at_cursor(s);
333 txt_view->get_buffer()->insert_at_cursor(": ");
334 txt_view->get_buffer()->insert_at_cursor(desc);
335 txt_view->get_buffer()->insert_at_cursor("\n");
338 void Principal::on_conexion_error(unsigned code, const std::string& desc)
344 txt_view->get_buffer()->insert_at_cursor("El server dice que hay error nro. ");
345 txt_view->get_buffer()->insert_at_cursor(s);
346 txt_view->get_buffer()->insert_at_cursor(": ");
347 txt_view->get_buffer()->insert_at_cursor(desc);
348 txt_view->get_buffer()->insert_at_cursor("\n");
351 void Principal::on_get_clicked()
353 if (conexion == NULL) {
354 txt_view->get_buffer()->insert_at_cursor("SIN CONEXION\n");
358 PlaQui::Server::Command command(txt_target->get_text(), txt_command->get_text());
359 command.add_arg( txt_args->get_text() );
360 txt_view->get_buffer()->insert_at_cursor("Enviando comando\n");
362 conexion->send(command);
365 txt_view->get_buffer()->insert_at_cursor("EXCEPTION EN conexion->send !!\n");
370 void Principal::loadXML()
373 if (is_xml_loaded) return;
375 /* Parseo de ejemplo de un XML desde archivo */
377 document = xmlParseMemory(xml_body.c_str(),xml_body.size());
378 if (document == NULL) {
379 std::cout << "EEERRRRRRROOOOOOOOOO" << std::endl;
382 is_xml_loaded = true;
383 /* bien, el archivo se parseo bien! */
384 xmlNodePtr nodo, items;
385 nodo = document->children;
387 if (strcmp((char *)nodo->name, "planta") == 0) {
388 items = nodo->children;
389 while (items != NULL) {
390 if (items->type == XML_ELEMENT_NODE) {
391 if (xmlStrcmp(items->name, BAD_CAST"bomba")==0) {
393 } else if (xmlStrcmp(items->name, BAD_CAST"codo")==0) {
395 } else if (xmlStrcmp(items->name, BAD_CAST"tubo")==0) {
397 } else if (xmlStrcmp(items->name, BAD_CAST"exclusa")==0) {
399 } else if (xmlStrcmp(items->name, BAD_CAST"tanque")==0) {
401 } else if (xmlStrcmp(items->name, BAD_CAST"empalme")==0) {
403 } else if (xmlStrcmp(items->name, BAD_CAST"drenaje")==0) {
405 } else if (xmlStrcmp(items->name, BAD_CAST"and")==0) {
407 } else if (xmlStrcmp(items->name, BAD_CAST"or")==0) {
409 } else if (xmlStrcmp(items->name, BAD_CAST"not")==0) {
418 xmlFreeDoc(document);
420 // Ya cargado el XML, mando un msg para empezar a recibir los frames!
421 PlaQui::Server::Command c("transmission", "start");
422 c.add_arg("default");
423 c.add_arg(conexion->get_host());
428 void Principal::loadNot(xmlNodePtr nodo)
430 std::string name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
431 std::string id = (char *)xmlGetProp(nodo, BAD_CAST"id");
432 int orientacion=0, x, y;
435 nodo = nodo->children;
436 while (nodo != NULL) {
437 if (nodo->type == XML_ELEMENT_NODE) {
438 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
439 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
440 p = new ViewNot(name, orientacion);
441 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
442 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
443 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
444 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
445 } else if (xmlStrcmp(nodo->name, BAD_CAST"salida") == 0) {
446 p->out_lines.push_back((char *)XML_GET_CONTENT(nodo->children));
447 } else if (xmlStrcmp(nodo->name, BAD_CAST"entrada") == 0) {
448 p->in_lines.push_back((char *)XML_GET_CONTENT(nodo->children));
454 p->signal_button_press_event().connect(SigC::bind( SigC::slot(*this, &Principal::on_item_clicked), p) );
455 p->set_position(x,y);
456 work_place->put(*p, x, y);
458 // los agrego al hash
462 void Principal::loadOr(xmlNodePtr nodo)
464 std::string name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
465 std::string id = (char *)xmlGetProp(nodo, BAD_CAST"id");
466 int orientacion=0, x, y;
470 nodo = nodo->children;
471 while (nodo != NULL) {
472 if (nodo->type == XML_ELEMENT_NODE) {
473 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
474 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
475 p = new ViewOr(name, orientacion);
476 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
477 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
478 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
479 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
480 } else if (xmlStrcmp(nodo->name, BAD_CAST"salida") == 0) {
481 p->out_lines.push_back((char *)XML_GET_CONTENT(nodo->children));
482 } else if (xmlStrcmp(nodo->name, BAD_CAST"entrada") == 0) {
483 p->in_lines.push_back((char *)XML_GET_CONTENT(nodo->children));
489 p->signal_button_press_event().connect(SigC::bind( SigC::slot(*this, &Principal::on_item_clicked), p) );
490 p->set_position(x,y);
491 work_place->put(*p, x, y);
493 // los agrego al hash
497 void Principal::loadAnd(xmlNodePtr nodo)
499 std::string name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
500 std::string id = (char *)xmlGetProp(nodo, BAD_CAST"id");
501 int orientacion=0, x, y;
503 xmlNodePtr inicial = nodo;
507 nodo = nodo->children;
508 while (nodo != NULL) {
509 if (nodo->type == XML_ELEMENT_NODE) {
510 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
511 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
512 p = new ViewAnd(name, orientacion);
513 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
514 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
515 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
516 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
517 } else if (xmlStrcmp(nodo->name, BAD_CAST"salida") == 0) {
518 p->out_lines.push_back((char *)XML_GET_CONTENT(nodo->children));
519 } else if (xmlStrcmp(nodo->name, BAD_CAST"entrada") == 0) {
520 p->in_lines.push_back((char *)XML_GET_CONTENT(nodo->children));
526 p->signal_button_press_event().connect(SigC::bind( SigC::slot(*this, &Principal::on_item_clicked), p) );
527 p->set_position(x,y);
528 work_place->put(*p, x, y);
530 // los agrego al hash
534 void Principal::loadBomba(xmlNodePtr nodo)
536 Glib::ustring name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
537 int orientacion=0, x, y;
539 nodo = nodo->children;
540 while (nodo != NULL) {
541 if (nodo->type == XML_ELEMENT_NODE) {
542 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
543 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
544 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
545 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
546 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
547 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
553 // listo, ya recolecte todos los datos, ahora creo el objeto!
554 ViewPump *b = new ViewPump(name, orientacion);
555 b->signal_button_press_event().connect(SigC::bind( SigC::slot(*this, &Principal::on_item_clicked), b) );
556 b->set_position(x,y);
557 work_place->put(*b, x, y);
559 // los agrego al hash
563 void Principal::loadCodo(xmlNodePtr nodo)
565 std::string name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
566 int orientacion=0, x, y;
568 nodo = nodo->children;
569 while (nodo != NULL) {
570 if (nodo->type == XML_ELEMENT_NODE) {
571 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
572 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
573 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
574 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
575 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
576 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
582 // listo, ya recolecte todos los datos, ahora creo el objeto!
583 ViewItem *b = new ViewCodo(name, orientacion);
584 b->signal_button_press_event().connect(SigC::bind( SigC::slot(*this, &Principal::on_item_clicked), b) );
585 b->set_position(x,y);
586 work_place->put(*b, x, y);
588 // los agrego al hash
592 void Principal::loadConduct(xmlNodePtr nodo)
594 Glib::ustring name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
595 int orientacion=0, x, y;
597 nodo = nodo->children;
598 while (nodo != NULL) {
599 if (nodo->type == XML_ELEMENT_NODE) {
600 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
601 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
602 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
603 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
604 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
605 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
611 // listo, ya recolecte todos los datos, ahora creo el objeto!
612 ViewConduct *b = new ViewConduct(name, orientacion);
613 b->signal_button_press_event().connect(SigC::bind( SigC::slot(*this, &Principal::on_item_clicked), b) );
614 b->set_position(x,y);
615 work_place->put(*b, x, y);
617 // los agrego al hash
621 void Principal::loadExclusa(xmlNodePtr nodo)
623 Glib::ustring name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
624 int orientacion=0, x, y;
626 nodo = nodo->children;
627 while (nodo != NULL) {
628 if (nodo->type == XML_ELEMENT_NODE) {
629 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
630 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
631 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
632 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
633 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
634 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
640 // listo, ya recolecte todos los datos, ahora creo el objeto!
641 ViewExclusa *b = new ViewExclusa(name, orientacion);
642 b->signal_button_press_event().connect(SigC::bind( SigC::slot(*this, &Principal::on_item_clicked), b) );
643 b->set_position(x,y);
644 work_place->put(*b, x, y);
646 // los agrego al hash
650 void Principal::loadTank(xmlNodePtr nodo)
652 Glib::ustring name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
653 int orientacion=0, x, y;
655 nodo = nodo->children;
656 while (nodo != NULL) {
657 if (nodo->type == XML_ELEMENT_NODE) {
658 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
659 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
660 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
661 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
662 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
663 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
669 // listo, ya recolecte todos los datos, ahora creo el objeto!
670 ViewTank *b = new ViewTank(name, orientacion);
671 b->signal_button_press_event().connect(SigC::bind( SigC::slot(*this, &Principal::on_item_clicked), b) );
672 b->set_position(x,y);
673 work_place->put(*b, x, y);
675 // los agrego al hash
679 void Principal::loadUnion(xmlNodePtr nodo)
681 Glib::ustring name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
682 int orientacion=0, x, y;
684 nodo = nodo->children;
685 while (nodo != NULL) {
686 if (nodo->type == XML_ELEMENT_NODE) {
687 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
688 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
689 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
690 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
691 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
692 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
698 // listo, ya recolecte todos los datos, ahora creo el objeto!
699 ViewUnion *b = new ViewUnion(name, orientacion);
700 b->signal_button_release_event().connect(SigC::bind( SigC::slot(*this, &Principal::on_item_clicked), b) );
701 b->set_position(x,y);
702 work_place->put(*b, x, y);
704 // los agrego al hash
708 void Principal::loadDrain(xmlNodePtr nodo)
710 Glib::ustring name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
711 int orientacion=0, x, y;
713 nodo = nodo->children;
714 while (nodo != NULL) {
715 if (nodo->type == XML_ELEMENT_NODE) {
716 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
717 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
718 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
719 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
720 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
721 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
727 // listo, ya recolecte todos los datos, ahora creo el objeto!
728 ViewDrain *b = new ViewDrain(name, orientacion);
729 b->signal_button_release_event().connect(SigC::bind( SigC::slot(*this, &Principal::on_item_clicked), b) );
730 b->set_position(x,y);
731 work_place->put(*b, x, y);
733 // los agrego al hash
737 void Principal::read_status_xml(const std::string &frame)
739 std::string item_name;
741 document = xmlParseMemory(frame.c_str(),frame.size());
742 if (document == NULL) {
743 std::cout << "read_status_xml::no se creo documento" << std::endl;
747 xmlNodePtr nodo, items, props;
748 nodo = document->children;
752 if (strcmp((char *)nodo->name, "plantstatus") == 0) {
753 items = nodo->children;
754 while (items != NULL) {
755 if (items->type == XML_ELEMENT_NODE) {
758 if (xmlStrcmp(items->name, BAD_CAST"float")==0) {
759 tmp = get_float_from_xml(items->children);
760 item_name = (char *)xmlGetProp(items, BAD_CAST"name");
761 mapItems[item_name]->set_actual_flow(tmp);
762 } else if (xmlStrcmp(items->name, BAD_CAST"exclusa")==0) {
763 tmp_b = get_bool_from_xml(items->children);
764 item_name = (char *)xmlGetProp(items, BAD_CAST"name");
765 mapItems[item_name]->set_open(tmp_b);
766 } else if (xmlStrcmp(items->name, BAD_CAST"pump")==0) {
767 tmp_b = get_bool_from_xml(items->children);
768 item_name = (char *)xmlGetProp(items, BAD_CAST"name");
769 mapItems[item_name]->set_open(tmp_b);
770 } else if (xmlStrcmp(items->name, BAD_CAST"color")==0) {
771 item_name = (char *)xmlGetProp(items, BAD_CAST"name");
772 mapItems[item_name]->set_color( get_rgb_from_xml(items->children) );
773 } else if (xmlStrcmp(items->name, BAD_CAST"tank")==0) {
774 xmlNodePtr nodo_tmp = items->children;
777 while (nodo_tmp != NULL) {
778 if (nodo_tmp->type == XML_ELEMENT_NODE) {
779 if (xmlStrcmp(nodo_tmp->name, BAD_CAST"capacity")==0)
780 cap = atof( (char *)XML_GET_CONTENT(nodo_tmp->children) );
781 else if (xmlStrcmp(nodo_tmp->name, BAD_CAST"litros")==0)
782 lit= atof( (char *)XML_GET_CONTENT(nodo_tmp->children) );
784 nodo_tmp = nodo_tmp->next;
786 item_name = (char *)xmlGetProp(items, BAD_CAST"name");
787 mapItems[item_name]->set_actual_flow(cap);
788 mapItems[item_name]->set_extra(lit);
794 xmlFreeDoc(document);
800 Gdk::Color Principal::get_rgb_from_xml(xmlNodePtr nodo)
803 while (nodo != NULL) {
804 if (nodo->type == XML_ELEMENT_NODE) {
805 if (xmlStrcmp(nodo->name, BAD_CAST"r")==0)
806 r = atoi( (char *)XML_GET_CONTENT(nodo->children) );
807 if (xmlStrcmp(nodo->name, BAD_CAST"g")==0)
808 g = atoi( (char *)XML_GET_CONTENT(nodo->children) );
809 if (xmlStrcmp(nodo->name, BAD_CAST"b")==0)
810 b = atoi( (char *)XML_GET_CONTENT(nodo->children) );
822 float Principal::get_float_from_xml(xmlNodePtr nodo)
825 while (nodo != NULL) {
826 if (nodo->type == XML_ELEMENT_NODE) {
827 if (xmlStrcmp(nodo->name, BAD_CAST"actual_flow")==0) {
828 tmp = atof( (char *)XML_GET_CONTENT(nodo->children) );
837 bool Principal::get_bool_from_xml(xmlNodePtr nodo)
840 while (nodo != NULL) {
841 if (nodo->type == XML_ELEMENT_NODE) {
842 if (xmlStrcmp(nodo->name, BAD_CAST"active")==0) {
843 tmp = (char *)XML_GET_CONTENT(nodo->children);
849 return tmp == "true";
852 void Principal::on_mnu_property()
854 dlg_property->show();
857 void Principal::on_dlg_property_ok()
860 PlaQui::Server::Command c("plant", "set_frequency");
861 c.add_arg("default");
862 c.add_arg( dlg_property->get_velocity() );
866 dlg_property->hide();
869 void Principal::on_btn_simulate_clicked()
871 if (conexion == NULL) return;
873 PlaQui::Server::Command c("plant", "start");
874 c.add_arg("default");
878 void Principal::on_btn_pause_clicked()
880 if (conexion == NULL) return;
882 PlaQui::Server::Command c("plant", "stop");
883 c.add_arg("default");