6 #include "plaqui/server/string.h"
8 #include "item_conduct.h"
9 #include "item_exclusa.h"
10 #include "item_tank.h"
11 #include "item_pump.h"
12 #include "item_union.h"
13 #include "item_drain.h"
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(10000); // 10 milisegundos
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_received().connect( SigC::slot(*this, &Principal::on_conexion_error) );
159 conexion->signal_finished().connect( SigC::slot(*this, &Principal::on_conexion_finished) );
160 conexion->signal_frame_received().connect(SigC::slot(*this, &Principal::on_conexion_frame));
161 // Lanzo la conexion!
163 txt_view->get_buffer()->insert_at_cursor("CONNECTED\n");
164 ico_conected->set( Gtk::Stock::YES , Gtk::IconSize(Gtk::ICON_SIZE_LARGE_TOOLBAR));
166 // Pido la planta por defecto
167 PlaQui::Server::Command c("plant", "get");
168 c.add_arg("default");
171 dlg_conectar->hide();
174 void Principal::on_mnu_file_exit()
179 void Principal::on_btn_activar_clicked()
181 if ((conexion == NULL) || (last_selected == NULL)) return;
183 PlaQui::Server::Command c("plant", "set");
184 c.add_arg("default");
185 c.add_arg(last_selected->get_name());
188 if (last_selected->get_open())
196 void Principal::on_mnu_file_disconnect()
198 if (conexion == NULL) return;
200 PlaQui::Server::Command c("transmission", "stop");
201 c.add_arg(conexion->get_host());
204 PlaQui::Server::Command c2("connection", "stop");
205 c2.add_arg(conexion->get_host());
206 c2.add_arg(conexion->get_port());
211 void Principal::on_mnu_file_connect()
213 dlg_conectar->show();
216 void Principal::on_mnu_help_about()
218 // preparo para leer el archivo ChangeLog
219 /* Glib::RefPtr<Gnome::Glade::Xml> xml;
221 Glib::RefPtr<Gtk::TextBuffer> log_buffer;
222 Glib::RefPtr<Glib::IOChannel> log_io;
224 log_buffer = Gtk::TextBuffer::create();
225 log_io = Glib::IOChannel::create_from_file("../ChangeLog", "r");
226 while (log_io->read_line(line) != Glib::IO_STATUS_EOF) {
227 log_buffer->insert_at_cursor(line);
231 xml = Gnome::Glade::Xml::create("client.glade", "dlgAbout");
233 catch(const Gnome::Glade::XmlError &ex) {
234 std::cerr << ex.what() << std::endl;
237 Gtk::Window *dlg = 0;
238 Gtk::Button *btn_cerrar = 0;
239 Gtk::TextView *txt_changelog = 0;
240 xml->get_widget("dlgAbout", dlg);
241 xml->get_widget("btn_close", btn_cerrar);
242 xml->get_widget("txt_changelog", txt_changelog);
243 btn_cerrar->signal_clicked().connect(SigC::slot(*dlg, &Gtk::Dialog::hide));
244 txt_changelog->set_buffer(log_buffer);
248 bool Principal::on_item_clicked(GdkEventButton *e, ViewItem *i)
251 txt_view->get_buffer()->insert_at_cursor("Selecciono ");
252 txt_view->get_buffer()->insert_at_cursor(i->get_name());
253 txt_view->get_buffer()->insert_at_cursor("\n");
259 void Principal::update_items_prop()
261 if (last_selected == NULL) return;
263 lbl_nombre->set_text(last_selected->get_name());
264 lbl_flujo->set_text(last_selected->get_actual_flow());
265 lbl_extra->set_text(last_selected->get_extra());
267 lbl_cap_flujo->set_text(last_selected->get_cap_flow());
268 lbl_cap_extra->set_text(last_selected->get_cap_extra());
270 color_preview->modify_bg(Gtk::STATE_NORMAL, last_selected->get_color());
271 color_preview->queue_draw();
273 // Mando a redibujar a todos los items
274 std::map<const std::string, ViewItem *>::iterator i;
275 for(i=mapItems.begin(); i!=mapItems.end(); i++) {
276 i->second->queue_draw();
281 void Principal::on_conexion_frame(const std::string &frame)
283 if (conexion != NULL) {
284 read_status_xml(frame);
288 void Principal::on_conexion_finished()
290 txt_view->get_buffer()->insert_at_cursor("HANG UP\n");
291 ico_conected->set( Gtk::Stock::NO , Gtk::IconSize(Gtk::ICON_SIZE_LARGE_TOOLBAR));
294 std::map<const std::string, ViewItem *>::iterator i;
295 for(i=mapItems.begin(); i!=mapItems.end(); i++) {
301 void Principal::on_conexion_ok(const std::string &body)
303 /* lo paso a la carga del XML */
304 /* verifico que body este completo */
305 if ((body.find("</planta>")>0) && (body.find("<planta>")>0)) {
310 std::cout << body << std::endl;
311 txt_view->get_buffer()->insert_at_cursor("<IN>\n");
312 txt_view->get_buffer()->insert_at_cursor(Glib::locale_to_utf8(body));
313 txt_view->get_buffer()->insert_at_cursor("</IN>\n");
317 void Principal::on_conexion_error(unsigned code)
323 txt_view->get_buffer()->insert_at_cursor("El server dice que hay error : ");
324 txt_view->get_buffer()->insert_at_cursor(s);
325 txt_view->get_buffer()->insert_at_cursor("\n");
328 void Principal::on_get_clicked()
330 if (conexion == NULL) {
331 txt_view->get_buffer()->insert_at_cursor("SIN CONEXION\n");
335 PlaQui::Server::Command command(txt_target->get_text(), txt_command->get_text());
336 command.add_arg( txt_args->get_text() );
337 txt_view->get_buffer()->insert_at_cursor("Enviando comando\n");
339 conexion->send(command);
342 txt_view->get_buffer()->insert_at_cursor("EXCEPTION EN conexion->send !!\n");
347 void Principal::loadXML()
350 if (is_xml_loaded) return;
352 /* Parseo de ejemplo de un XML desde archivo */
354 document = xmlParseMemory(xml_body.c_str(),xml_body.size());
355 if (document == NULL) {
356 std::cout << "EEERRRRRRROOOOOOOOOO" << std::endl;
359 is_xml_loaded = true;
360 /* bien, el archivo se parseo bien! */
361 xmlNodePtr nodo, items;
362 nodo = document->children;
364 if (strcmp((char *)nodo->name, "planta") == 0) {
365 items = nodo->children;
366 while (items != NULL) {
367 if (items->type == XML_ELEMENT_NODE) {
368 if (xmlStrcmp(items->name, BAD_CAST"bomba")==0) {
370 } else if (xmlStrcmp(items->name, BAD_CAST"codo")==0) {
372 } else if (xmlStrcmp(items->name, BAD_CAST"tubo")==0) {
374 } else if (xmlStrcmp(items->name, BAD_CAST"exclusa")==0) {
376 } else if (xmlStrcmp(items->name, BAD_CAST"tanque")==0) {
378 } else if (xmlStrcmp(items->name, BAD_CAST"empalme")==0) {
380 } else if (xmlStrcmp(items->name, BAD_CAST"drenaje")==0) {
382 } else if (xmlStrcmp(items->name, BAD_CAST"and")==0) {
384 } else if (xmlStrcmp(items->name, BAD_CAST"or")==0) {
386 } else if (xmlStrcmp(items->name, BAD_CAST"not")==0) {
395 xmlFreeDoc(document);
397 // Ya cargado el XML, mando un msg para empezar a recibir los frames!
398 PlaQui::Server::Command c("transmission", "start");
399 c.add_arg("default");
400 c.add_arg(conexion->get_host());
405 void Principal::loadNot(xmlNodePtr nodo)
407 std::string name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
408 std::string id = (char *)xmlGetProp(nodo, BAD_CAST"id");
409 int orientacion=0, x, y;
412 nodo = nodo->children;
413 while (nodo != NULL) {
414 if (nodo->type == XML_ELEMENT_NODE) {
415 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
416 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
417 p = new ViewNot(name, orientacion);
418 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
419 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
420 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
421 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
422 } else if (xmlStrcmp(nodo->name, BAD_CAST"salida") == 0) {
423 p->out_lines.push_back((char *)XML_GET_CONTENT(nodo->children));
424 } else if (xmlStrcmp(nodo->name, BAD_CAST"entrada") == 0) {
425 p->in_lines.push_back((char *)XML_GET_CONTENT(nodo->children));
431 p->signal_button_press_event().connect(SigC::bind( SigC::slot(*this, &Principal::on_item_clicked), p) );
432 p->set_position(x,y);
433 work_place->put(*p, x, y);
435 // los agrego al hash
439 void Principal::loadOr(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;
447 nodo = nodo->children;
448 while (nodo != NULL) {
449 if (nodo->type == XML_ELEMENT_NODE) {
450 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
451 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
452 p = new ViewOr(name, orientacion);
453 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
454 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
455 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
456 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
457 } else if (xmlStrcmp(nodo->name, BAD_CAST"salida") == 0) {
458 p->out_lines.push_back((char *)XML_GET_CONTENT(nodo->children));
459 } else if (xmlStrcmp(nodo->name, BAD_CAST"entrada") == 0) {
460 p->in_lines.push_back((char *)XML_GET_CONTENT(nodo->children));
466 p->signal_button_press_event().connect(SigC::bind( SigC::slot(*this, &Principal::on_item_clicked), p) );
467 p->set_position(x,y);
468 work_place->put(*p, x, y);
470 // los agrego al hash
474 void Principal::loadAnd(xmlNodePtr nodo)
476 std::string name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
477 std::string id = (char *)xmlGetProp(nodo, BAD_CAST"id");
478 int orientacion=0, x, y;
480 xmlNodePtr inicial = nodo;
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 ViewAnd(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::loadBomba(xmlNodePtr nodo)
513 Glib::ustring name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
514 int orientacion=0, x, y;
516 nodo = nodo->children;
517 while (nodo != NULL) {
518 if (nodo->type == XML_ELEMENT_NODE) {
519 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
520 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
521 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
522 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
523 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
524 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
530 // listo, ya recolecte todos los datos, ahora creo el objeto!
531 ViewPump *b = new ViewPump(name, orientacion);
532 b->signal_button_press_event().connect(SigC::bind( SigC::slot(*this, &Principal::on_item_clicked), b) );
533 b->set_position(x,y);
534 work_place->put(*b, x, y);
536 // los agrego al hash
540 void Principal::loadCodo(xmlNodePtr nodo)
542 std::string name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
543 int orientacion=0, x, y;
545 nodo = nodo->children;
546 while (nodo != NULL) {
547 if (nodo->type == XML_ELEMENT_NODE) {
548 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
549 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
550 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
551 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
552 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
553 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
559 // listo, ya recolecte todos los datos, ahora creo el objeto!
560 ViewItem *b = new ViewCodo(name, orientacion);
561 b->signal_button_press_event().connect(SigC::bind( SigC::slot(*this, &Principal::on_item_clicked), b) );
562 b->set_position(x,y);
563 work_place->put(*b, x, y);
565 // los agrego al hash
569 void Principal::loadConduct(xmlNodePtr nodo)
571 Glib::ustring name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
572 int orientacion=0, x, y;
574 nodo = nodo->children;
575 while (nodo != NULL) {
576 if (nodo->type == XML_ELEMENT_NODE) {
577 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
578 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
579 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
580 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
581 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
582 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
588 // listo, ya recolecte todos los datos, ahora creo el objeto!
589 ViewConduct *b = new ViewConduct(name, orientacion);
590 b->signal_button_press_event().connect(SigC::bind( SigC::slot(*this, &Principal::on_item_clicked), b) );
591 b->set_position(x,y);
592 work_place->put(*b, x, y);
594 // los agrego al hash
598 void Principal::loadExclusa(xmlNodePtr nodo)
600 Glib::ustring name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
601 int orientacion=0, x, y;
603 nodo = nodo->children;
604 while (nodo != NULL) {
605 if (nodo->type == XML_ELEMENT_NODE) {
606 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
607 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
608 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
609 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
610 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
611 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
617 // listo, ya recolecte todos los datos, ahora creo el objeto!
618 ViewExclusa *b = new ViewExclusa(name, orientacion);
619 b->signal_button_press_event().connect(SigC::bind( SigC::slot(*this, &Principal::on_item_clicked), b) );
620 b->set_position(x,y);
621 work_place->put(*b, x, y);
623 // los agrego al hash
627 void Principal::loadTank(xmlNodePtr nodo)
629 Glib::ustring name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
630 int orientacion=0, x, y;
632 nodo = nodo->children;
633 while (nodo != NULL) {
634 if (nodo->type == XML_ELEMENT_NODE) {
635 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
636 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
637 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
638 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
639 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
640 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
646 // listo, ya recolecte todos los datos, ahora creo el objeto!
647 ViewTank *b = new ViewTank(name, orientacion);
648 b->signal_button_press_event().connect(SigC::bind( SigC::slot(*this, &Principal::on_item_clicked), b) );
649 b->set_position(x,y);
650 work_place->put(*b, x, y);
652 // los agrego al hash
656 void Principal::loadUnion(xmlNodePtr nodo)
658 Glib::ustring name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
659 int orientacion=0, x, y;
661 nodo = nodo->children;
662 while (nodo != NULL) {
663 if (nodo->type == XML_ELEMENT_NODE) {
664 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
665 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
666 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
667 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
668 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
669 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
675 // listo, ya recolecte todos los datos, ahora creo el objeto!
676 ViewUnion *b = new ViewUnion(name, orientacion);
677 b->signal_button_release_event().connect(SigC::bind( SigC::slot(*this, &Principal::on_item_clicked), b) );
678 b->set_position(x,y);
679 work_place->put(*b, x, y);
681 // los agrego al hash
685 void Principal::loadDrain(xmlNodePtr nodo)
687 Glib::ustring name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
688 int orientacion=0, x, y;
690 nodo = nodo->children;
691 while (nodo != NULL) {
692 if (nodo->type == XML_ELEMENT_NODE) {
693 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
694 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
695 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
696 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
697 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
698 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
704 // listo, ya recolecte todos los datos, ahora creo el objeto!
705 ViewDrain *b = new ViewDrain(name, orientacion);
706 b->signal_button_release_event().connect(SigC::bind( SigC::slot(*this, &Principal::on_item_clicked), b) );
707 b->set_position(x,y);
708 work_place->put(*b, x, y);
710 // los agrego al hash
714 void Principal::read_status_xml(const std::string &frame)
716 std::string item_name;
718 document = xmlParseMemory(frame.c_str(),frame.size());
719 if (document == NULL) {
720 std::cout << "read_status_xml::no se creo documento" << std::endl;
724 xmlNodePtr nodo, items, props;
725 nodo = document->children;
729 if (strcmp((char *)nodo->name, "plantstatus") == 0) {
730 items = nodo->children;
731 while (items != NULL) {
732 if (items->type == XML_ELEMENT_NODE) {
735 if (xmlStrcmp(items->name, BAD_CAST"float")==0) {
736 tmp = get_float_from_xml(items->children);
737 item_name = (char *)xmlGetProp(items, BAD_CAST"name");
738 mapItems[item_name]->set_actual_flow(tmp);
739 } else if (xmlStrcmp(items->name, BAD_CAST"exclusa")==0) {
740 tmp_b = get_bool_from_xml(items->children);
741 item_name = (char *)xmlGetProp(items, BAD_CAST"name");
742 mapItems[item_name]->set_open(tmp_b);
743 } else if (xmlStrcmp(items->name, BAD_CAST"pump")==0) {
744 tmp_b = get_bool_from_xml(items->children);
745 item_name = (char *)xmlGetProp(items, BAD_CAST"name");
746 mapItems[item_name]->set_open(tmp_b);
747 } else if (xmlStrcmp(items->name, BAD_CAST"color")==0) {
748 item_name = (char *)xmlGetProp(items, BAD_CAST"name");
749 mapItems[item_name]->set_color( get_rgb_from_xml(items->children) );
750 } else if (xmlStrcmp(items->name, BAD_CAST"tank")==0) {
751 xmlNodePtr nodo_tmp = items->children;
754 while (nodo_tmp != NULL) {
755 if (nodo_tmp->type == XML_ELEMENT_NODE) {
756 if (xmlStrcmp(nodo_tmp->name, BAD_CAST"capacity")==0)
757 cap = atof( (char *)XML_GET_CONTENT(nodo_tmp->children) );
758 else if (xmlStrcmp(nodo_tmp->name, BAD_CAST"litros")==0)
759 lit= atof( (char *)XML_GET_CONTENT(nodo_tmp->children) );
761 nodo_tmp = nodo_tmp->next;
763 item_name = (char *)xmlGetProp(items, BAD_CAST"name");
764 mapItems[item_name]->set_actual_flow(cap);
765 mapItems[item_name]->set_extra(lit);
771 xmlFreeDoc(document);
777 Gdk::Color Principal::get_rgb_from_xml(xmlNodePtr nodo)
780 while (nodo != NULL) {
781 if (nodo->type == XML_ELEMENT_NODE) {
782 if (xmlStrcmp(nodo->name, BAD_CAST"r")==0)
783 r = atoi( (char *)XML_GET_CONTENT(nodo->children) );
784 if (xmlStrcmp(nodo->name, BAD_CAST"g")==0)
785 g = atoi( (char *)XML_GET_CONTENT(nodo->children) );
786 if (xmlStrcmp(nodo->name, BAD_CAST"b")==0)
787 b = atoi( (char *)XML_GET_CONTENT(nodo->children) );
799 float Principal::get_float_from_xml(xmlNodePtr nodo)
802 while (nodo != NULL) {
803 if (nodo->type == XML_ELEMENT_NODE) {
804 if (xmlStrcmp(nodo->name, BAD_CAST"actual_flow")==0) {
805 tmp = atof( (char *)XML_GET_CONTENT(nodo->children) );
814 bool Principal::get_bool_from_xml(xmlNodePtr nodo)
817 while (nodo != NULL) {
818 if (nodo->type == XML_ELEMENT_NODE) {
819 if (xmlStrcmp(nodo->name, BAD_CAST"active")==0) {
820 tmp = (char *)XML_GET_CONTENT(nodo->children);
826 return tmp == "true";
829 void Principal::on_mnu_property()
831 dlg_property->show();
834 void Principal::on_dlg_property_ok()
837 PlaQui::Server::Command c("plant", "set_frequency");
838 c.add_arg("default");
839 c.add_arg( dlg_property->get_velocity() );
843 dlg_property->hide();
846 void Principal::on_btn_simulate_clicked()
848 if (conexion == NULL) return;
850 PlaQui::Server::Command c("plant", "start");
851 c.add_arg("default");
855 void Principal::on_btn_pause_clicked()
857 if (conexion == NULL) return;
859 PlaQui::Server::Command c("plant", "stop");
860 c.add_arg("default");