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, *server_stop=0;
24 Gtk::Button *bar_connect=0, *close_about=0;
25 Gtk::Image *plaqui_logo;
28 lbl_cap_flujo = lbl_cap_extra = lbl_extra = lbl_nombre = lbl_color = lbl_flujo = 0;
29 btn_simulate = btn_pause = 0;
31 anim_frames[0] = Gdk::Pixbuf::create_from_file(PACKAGE_DATA_DIR"/plaqui-client/pixmaps/anim_0.png");
32 anim_frames[1] = Gdk::Pixbuf::create_from_file(PACKAGE_DATA_DIR"/plaqui-client/pixmaps/anim_1.png");
33 anim_frames[2] = Gdk::Pixbuf::create_from_file(PACKAGE_DATA_DIR"/plaqui-client/pixmaps/anim_2.png");
34 anim_frames[3] = Gdk::Pixbuf::create_from_file(PACKAGE_DATA_DIR"/plaqui-client/pixmaps/anim_3.png");
35 anim_frames[4] = Gdk::Pixbuf::create_from_file(PACKAGE_DATA_DIR"/plaqui-client/pixmaps/anim_4.png");
36 anim_frames[5] = Gdk::Pixbuf::create_from_file(PACKAGE_DATA_DIR"/plaqui-client/pixmaps/anim_5.png");
37 anim_frames[6] = Gdk::Pixbuf::create_from_file(PACKAGE_DATA_DIR"/plaqui-client/pixmaps/anim_6.png");
38 anim_frames[7] = Gdk::Pixbuf::create_from_file(PACKAGE_DATA_DIR"/plaqui-client/pixmaps/anim_7.png");
41 plaqui_logo = anim = 0;
42 rg->get_widget("plaqui_logo", plaqui_logo);
43 plaqui_logo->set(PACKAGE_DATA_DIR"/plaqui-client/pixmaps/logo.png");
45 rg->get_widget("anim_frames", anim);
46 anim->set(anim_frames[current_frame]);
48 rg->get_widget("close_about", close_about);
49 rg->get_widget("dlgAbout", dlg_about);
50 rg->get_widget("btn_pausa", btn_pause);
51 rg->get_widget("btn_simular", btn_simulate);
52 rg->get_widget("btn_activar", btn_activar);
53 rg->get_widget("color_preview", color_preview);
54 rg->get_widget("lbl_nombre", lbl_nombre);
55 rg->get_widget("lbl_extra", lbl_extra);
56 rg->get_widget("lbl_cap_extra", lbl_cap_extra);
57 rg->get_widget("lbl_cap_flujo", lbl_cap_flujo);
58 rg->get_widget("lbl_flujo", lbl_flujo);
59 rg->get_widget("mnu_file_connect", conect);
60 rg->get_widget("mnu_file_disconnect", mnu_disconnect);
61 rg->get_widget("mnu_file_exit", exit);
62 rg->get_widget("mnu_help_about", about);
63 rg->get_widget("mnu_server_stop", server_stop);
64 rg->get_widget("mnu_prop", mnu_prop);
65 rg->get_widget_derived("dlg_property", dlg_property);
66 rg->get_widget_derived("dlgConectar", dlg_conectar);
67 rg->get_widget("txt_view", txt_view);
68 rg->get_widget("bar_connect", bar_connect);
69 rg->get_widget("work_place", work_place);
70 rg->get_widget("ico_conected", ico_conected);
72 work_place->signal_expose_event().connect( SigC::slot(*this, &Principal::on_workplace_expose_event) );
73 dlg_property->get_ok_button()->signal_clicked().connect( SigC::slot(*this, &Principal::on_dlg_property_ok) );
74 dlg_conectar->get_ok_button()->signal_clicked().connect( SigC::slot(*this, &Principal::on_dlg_connect_ok) );
75 mnu_prop->signal_activate().connect( SigC::slot(*this, &Principal::on_mnu_property));
76 mnu_disconnect->signal_activate().connect( SigC::slot(*this, &Principal::on_mnu_file_disconnect));
77 server_stop->signal_activate().connect( SigC::slot(*this, &Principal::on_mnu_server_stop_activate));
78 conect->signal_activate().connect( SigC::slot(*this, &Principal::on_mnu_file_connect));
79 bar_connect->signal_clicked().connect( SigC::slot(*this, &Principal::on_mnu_file_connect));
80 exit->signal_activate().connect( SigC::slot(*this, &Principal::on_mnu_file_exit));
81 about->signal_activate().connect( SigC::slot(*this, &Principal::on_mnu_help_about));
82 btn_activar->signal_clicked().connect( SigC::slot(*this, &Principal::on_btn_activar_clicked) );
83 btn_simulate->signal_clicked().connect( SigC::slot(*this, &Principal::on_btn_simulate_clicked) );
84 btn_pause->signal_clicked().connect( SigC::slot(*this, &Principal::on_btn_pause_clicked) );
85 close_about->signal_clicked().connect( SigC::slot(*dlg_about, &Gtk::Widget::hide) );
88 is_xml_loaded = false;
91 update_ui.connect( SigC::slot(*this, &Principal::update_items_prop ) );
92 load_xml_dispatch.connect( SigC::slot(*this, &Principal::loadXML ) );
93 gc = Gdk::GC::create(get_window());
94 color_low = Gdk::Color("blue");
95 color_high = Gdk::Color("red");
96 Gtk::Widget::get_default_colormap()->alloc_color(color_low);
97 Gtk::Widget::get_default_colormap()->alloc_color(color_high);
100 Principal::~Principal()
104 void Principal::on_realize()
106 Gtk::Window::on_realize();
109 bool Principal::on_workplace_expose_event(GdkEventExpose *e)
111 Glib::RefPtr<Gdk::Window> window = work_place->get_window();
115 std::map<const std::string, ViewItem *>::iterator i;
116 for(i=mapItems.begin(); i!=mapItems.end(); i++) {
117 if (dynamic_cast<ViewAnd *>(i->second) || dynamic_cast<ViewOr *>(i->second) || dynamic_cast<ViewNot *>(i->second)) {
118 x1 = i->second->x + i->second->in_x;
119 y1 = i->second->y + i->second->in_y;
120 std::list<t_Linea>::iterator linea;
121 for(linea=i->second->in_lines.begin(); linea!=i->second->in_lines.end(); linea++) {
122 ViewItem *tmp = find_item(linea->dst);
123 /* Si este item es un tanque */
124 if (linea->is_tank) {
125 if (linea->is_tank_lower) {
126 x2 = tmp->x + tmp->out_x;
127 y2 = tmp->y + tmp->out_y;
128 if (dynamic_cast<ViewTank *>(tmp)->get_out_inf()) {
129 gc->set_foreground(color_high);
131 gc->set_foreground(color_low);
134 x2 = tmp->x + tmp->in_x;
135 y2 = tmp->y + tmp->in_y;
136 if (dynamic_cast<ViewTank *>(tmp)->get_out_sup()) {
137 gc->set_foreground(color_high);
139 gc->set_foreground(color_low);
143 x2 = tmp->x + tmp->out_x;
144 y2 = tmp->y + tmp->out_y;
145 if (tmp->get_open()) {
146 gc->set_foreground(color_high);
148 gc->set_foreground(color_low);
151 gc->set_line_attributes(3, Gdk::LINE_SOLID, Gdk::CAP_NOT_LAST, Gdk::JOIN_MITER);
152 window->draw_line(gc, x2+tmp->item_offset_x, y2+tmp->item_offset_y, x2+tmp->item_offset_x, y1+i->second->offset_y);
153 window->draw_line(gc, x2+tmp->item_offset_x, y1+i->second->offset_y, x1+i->second->offset_x, y1+i->second->offset_y);
154 window->draw_line(gc, x1, y1, x1+i->second->offset_x, y1+i->second->offset_y);
155 window->draw_line(gc, x2, y2, x2+tmp->item_offset_x, y2+tmp->item_offset_y);
157 x1 = i->second->x + i->second->out_x;
158 y1 = i->second->y + i->second->out_y;
159 for(linea=i->second->out_lines.begin(); linea!=i->second->out_lines.end(); linea++) {
160 ViewItem *tmp = find_item(linea->dst);
161 x2 = tmp->x + tmp->in_x;
162 y2 = tmp->y + tmp->in_y;
163 if (i->second->get_open()) {
164 gc->set_foreground(color_high);
166 gc->set_foreground(color_low);
168 gc->set_line_attributes(3, Gdk::LINE_SOLID, Gdk::CAP_NOT_LAST, Gdk::JOIN_MITER);
169 window->draw_line(gc, x1+i->second->offset_x, y1+i->second->offset_y, x1+i->second->offset_x, y2+tmp->item_offset_y);
170 window->draw_line(gc, x1+i->second->offset_x, y2+tmp->item_offset_y, x2+tmp->item_offset_x, y2+tmp->item_offset_y);
171 window->draw_line(gc, x1, y1, x1+i->second->offset_x, y1+i->second->offset_y);
172 window->draw_line(gc, x2, y2, x2+tmp->item_offset_x, y2+tmp->item_offset_y);
178 ViewItem *Principal::find_item(std::string &_name)
180 std::map<const std::string, ViewItem *>::iterator i;
181 for(i=mapItems.begin(); i!=mapItems.end(); i++) {
182 if (i->second->get_name() == _name) {
189 void Principal::on_dlg_connect_ok()
191 if (conexion == NULL) {
194 conexion = new PlaQui::Server::ControlClient(dlg_conectar->get_server_name(), dlg_conectar->get_server_port());
197 txt_view->get_buffer()->insert_at_cursor("NO SE PUDO CREAR OBJETO\n");
198 //delete conexion; XXX Si no me equivoco, si falla el
199 //constructor, no se reserva la memoria (el delete no va).
204 // Conecto las señales
205 conexion->signal_ok_received().connect( SigC::slot(*this, &Principal::on_conexion_ok) );
206 conexion->signal_error().connect( SigC::slot(*this, &Principal::on_conexion_fatal_error) );
207 conexion->signal_error_received().connect( SigC::slot(*this, &Principal::on_conexion_error) );
208 conexion->signal_finished().connect( SigC::slot(*this, &Principal::on_conexion_finished) );
209 conexion->signal_frame_received().connect(SigC::slot(*this, &Principal::on_conexion_frame));
210 // Lanzo la conexion!
212 txt_view->get_buffer()->insert_at_cursor("CONNECTED\n");
213 ico_conected->set( Gtk::Stock::YES , Gtk::IconSize(Gtk::ICON_SIZE_LARGE_TOOLBAR));
215 // Pido la planta por defecto
216 PlaQui::Server::Command c("plant", "get");
217 c.add_arg("default");
220 dlg_conectar->hide();
223 void Principal::on_mnu_file_exit()
225 on_mnu_file_disconnect();
229 // Espera a que termine realmente.
231 Glib::usleep(100000); // 0,1 segundo
236 bool Principal::on_delete_event(GdkEventAny *e)
242 void Principal::on_mnu_server_stop_activate()
244 if (conexion == NULL) return;
246 PlaQui::Server::Command c("server", "stop");
250 void Principal::on_btn_activar_clicked()
252 if ((conexion == NULL) || (last_selected == NULL)) return;
254 PlaQui::Server::Command c("plant", "set");
255 c.add_arg("default");
256 c.add_arg(last_selected->get_name());
259 if (last_selected->get_open())
267 void Principal::on_mnu_file_disconnect()
269 if (conexion == NULL) return;
271 PlaQui::Server::Command c("transmission", "stop");
272 c.add_arg(conexion->get_host());
275 PlaQui::Server::Command c2("connection", "stop");
276 c2.add_arg(conexion->get_host());
277 c2.add_arg(conexion->get_port());
281 void Principal::on_mnu_file_connect()
283 dlg_conectar->show();
286 void Principal::on_mnu_help_about()
291 bool Principal::on_item_clicked(GdkEventButton *e, ViewItem *i)
294 txt_view->get_buffer()->insert_at_cursor("Selecciono ");
295 txt_view->get_buffer()->insert_at_cursor(i->get_name());
296 txt_view->get_buffer()->insert_at_cursor("\n");
302 void Principal::update_items_prop()
304 if (last_selected != NULL) {
305 lbl_nombre->set_text(last_selected->get_name());
306 lbl_flujo->set_text(last_selected->get_actual_flow());
307 lbl_extra->set_text(last_selected->get_extra());
309 lbl_cap_flujo->set_text(last_selected->get_cap_flow());
310 lbl_cap_extra->set_text(last_selected->get_cap_extra());
312 color_preview->modify_bg(Gtk::STATE_NORMAL, last_selected->get_color());
313 color_preview->queue_draw();
318 if (current_frame > 7) {
321 anim->set(anim_frames[current_frame]);
324 // Mando a redibujar a todos los items
325 std::map<const std::string, ViewItem *>::iterator i;
326 for(i=mapItems.begin(); i!=mapItems.end(); i++) {
327 i->second->queue_draw();
329 work_place->queue_draw();
332 void Principal::on_conexion_frame(const std::string &frame)
334 if (conexion != NULL) {
335 read_status_xml(frame);
339 void Principal::on_conexion_finished()
341 txt_view->get_buffer()->insert_at_cursor("HANG UP\n");
342 ico_conected->set( Gtk::Stock::NO , Gtk::IconSize(Gtk::ICON_SIZE_LARGE_TOOLBAR));
345 std::map<const std::string, ViewItem *>::iterator i;
346 for(i=mapItems.begin(); i!=mapItems.end(); i++) {
350 is_xml_loaded = false;
353 void Principal::on_conexion_ok(const std::string &body)
355 /* lo paso a la carga del XML */
356 /* verifico que body este completo */
357 if ((body.find("</planta>")>0) && (body.find("<planta>")>0)) {
362 std::cout << body << std::endl;
363 txt_view->get_buffer()->insert_at_cursor("<IN>\n");
364 txt_view->get_buffer()->insert_at_cursor(Glib::locale_to_utf8(body));
365 txt_view->get_buffer()->insert_at_cursor("</IN>\n");
369 void Principal::on_conexion_fatal_error(const PlaQui::Server::ControlClient::Error& code, const std::string& desc)
375 txt_view->get_buffer()->insert_at_cursor("Error de red nro. ");
376 txt_view->get_buffer()->insert_at_cursor(s);
377 txt_view->get_buffer()->insert_at_cursor(": ");
378 txt_view->get_buffer()->insert_at_cursor(desc);
379 txt_view->get_buffer()->insert_at_cursor("\n");
382 void Principal::on_conexion_error(unsigned code, const std::string& desc)
388 txt_view->get_buffer()->insert_at_cursor("El server dice que hay error nro. ");
389 txt_view->get_buffer()->insert_at_cursor(s);
390 txt_view->get_buffer()->insert_at_cursor(": ");
391 txt_view->get_buffer()->insert_at_cursor(desc);
392 txt_view->get_buffer()->insert_at_cursor("\n");
395 void Principal::loadXML()
398 if (is_xml_loaded) return;
400 /* Parseo de ejemplo de un XML desde archivo */
402 document = xmlParseMemory(xml_body.c_str(),xml_body.size());
403 if (document == NULL) {
404 std::cout << "EEERRRRRRROOOOOOOOOO" << std::endl;
407 is_xml_loaded = true;
408 /* bien, el archivo se parseo bien! */
409 xmlNodePtr nodo, items;
410 nodo = document->children;
412 if (strcmp((char *)nodo->name, "planta") == 0) {
413 items = nodo->children;
414 while (items != NULL) {
415 if (items->type == XML_ELEMENT_NODE) {
416 if (xmlStrcmp(items->name, BAD_CAST"bomba")==0) {
418 } else if (xmlStrcmp(items->name, BAD_CAST"codo")==0) {
420 } else if (xmlStrcmp(items->name, BAD_CAST"tubo")==0) {
422 } else if (xmlStrcmp(items->name, BAD_CAST"exclusa")==0) {
424 } else if (xmlStrcmp(items->name, BAD_CAST"tanque")==0) {
426 } else if (xmlStrcmp(items->name, BAD_CAST"empalme")==0) {
428 } else if (xmlStrcmp(items->name, BAD_CAST"drenaje")==0) {
430 } else if (xmlStrcmp(items->name, BAD_CAST"and")==0) {
432 } else if (xmlStrcmp(items->name, BAD_CAST"or")==0) {
434 } else if (xmlStrcmp(items->name, BAD_CAST"not")==0) {
443 xmlFreeDoc(document);
445 // Ya cargado el XML, mando un msg para empezar a recibir los frames!
446 PlaQui::Server::Command c("transmission", "start");
447 c.add_arg("default");
448 c.add_arg(conexion->get_host());
453 void Principal::loadNot(xmlNodePtr nodo)
455 std::string name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
456 std::string id = (char *)xmlGetProp(nodo, BAD_CAST"id");
457 int orientacion=0, x, y;
461 nodo = nodo->children;
462 while (nodo != NULL) {
463 if (nodo->type == XML_ELEMENT_NODE) {
464 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
465 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
466 p = new ViewNot(name, orientacion);
467 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
468 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
469 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
470 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
471 } else if (xmlStrcmp(nodo->name, BAD_CAST"salida") == 0) {
472 linea.dst = (char *)XML_GET_CONTENT(nodo->children);
473 p->out_lines.push_back(linea);
474 } else if (xmlStrcmp(nodo->name, BAD_CAST"entrada") == 0) {
475 linea.dst = (char *)XML_GET_CONTENT(nodo->children);
476 linea.is_tank = false;
477 if (dynamic_cast<ViewTank *>(find_item(linea.dst)) != NULL) {
478 linea.is_tank = true;
479 linea.is_tank_lower = false;
480 if (xmlStrcmp(xmlGetProp(nodo, BAD_CAST"id"), BAD_CAST"inferior")==0)
481 linea.is_tank_lower = true;
483 p->in_lines.push_back(linea);
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::loadOr(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;
506 nodo = nodo->children;
507 while (nodo != NULL) {
508 if (nodo->type == XML_ELEMENT_NODE) {
509 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
510 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
511 p = new ViewOr(name, orientacion);
512 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
513 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
514 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
515 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
516 } else if (xmlStrcmp(nodo->name, BAD_CAST"salida") == 0) {
517 linea.dst = (char *)XML_GET_CONTENT(nodo->children);
518 p->out_lines.push_back(linea);
519 } else if (xmlStrcmp(nodo->name, BAD_CAST"entrada") == 0) {
520 linea.dst = (char *)XML_GET_CONTENT(nodo->children);
521 linea.is_tank = false;
522 if (dynamic_cast<ViewTank *>(find_item(linea.dst)) != NULL) {
523 linea.is_tank = true;
524 linea.is_tank_lower = false;
525 if (xmlStrcmp(xmlGetProp(nodo, BAD_CAST"id"), BAD_CAST"inferior")==0)
526 linea.is_tank_lower = true;
528 p->in_lines.push_back(linea);
534 p->signal_button_press_event().connect(SigC::bind( SigC::slot(*this, &Principal::on_item_clicked), p) );
535 p->set_position(x,y);
536 work_place->put(*p, x, y);
538 // los agrego al hash
542 void Principal::loadAnd(xmlNodePtr nodo)
544 std::string name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
545 std::string id = (char *)xmlGetProp(nodo, BAD_CAST"id");
546 int orientacion=0, x, y;
548 xmlNodePtr inicial = nodo;
552 nodo = nodo->children;
553 while (nodo != NULL) {
554 if (nodo->type == XML_ELEMENT_NODE) {
555 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
556 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
557 p = new ViewAnd(name, orientacion);
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) );
562 } else if (xmlStrcmp(nodo->name, BAD_CAST"salida") == 0) {
563 linea.dst = (char *)XML_GET_CONTENT(nodo->children);
564 p->out_lines.push_back(linea);
565 } else if (xmlStrcmp(nodo->name, BAD_CAST"entrada") == 0) {
566 linea.dst = (char *)XML_GET_CONTENT(nodo->children);
567 linea.is_tank = false;
568 if (dynamic_cast<ViewTank *>(find_item(linea.dst)) != NULL) {
569 linea.is_tank = true;
570 linea.is_tank_lower = false;
571 if (xmlStrcmp(xmlGetProp(nodo, BAD_CAST"id"), BAD_CAST"inferior")==0)
572 linea.is_tank_lower = true;
574 p->in_lines.push_back(linea);
580 p->signal_button_press_event().connect(SigC::bind( SigC::slot(*this, &Principal::on_item_clicked), p) );
581 p->set_position(x,y);
582 work_place->put(*p, x, y);
584 // los agrego al hash
588 void Principal::loadBomba(xmlNodePtr nodo)
590 Glib::ustring name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
591 int orientacion=0, x, y;
593 nodo = nodo->children;
594 while (nodo != NULL) {
595 if (nodo->type == XML_ELEMENT_NODE) {
596 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
597 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
598 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
599 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
600 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
601 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
607 // listo, ya recolecte todos los datos, ahora creo el objeto!
608 ViewPump *b = new ViewPump(name, orientacion);
609 b->signal_button_press_event().connect(SigC::bind( SigC::slot(*this, &Principal::on_item_clicked), b) );
610 b->set_position(x,y);
611 work_place->put(*b, x, y);
613 // los agrego al hash
617 void Principal::loadCodo(xmlNodePtr nodo)
619 std::string name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
620 int orientacion=0, x, y;
622 nodo = nodo->children;
623 while (nodo != NULL) {
624 if (nodo->type == XML_ELEMENT_NODE) {
625 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
626 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
627 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
628 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
629 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
630 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
636 // listo, ya recolecte todos los datos, ahora creo el objeto!
637 ViewItem *b = new ViewCodo(name, orientacion);
638 b->signal_button_press_event().connect(SigC::bind( SigC::slot(*this, &Principal::on_item_clicked), b) );
639 b->set_position(x,y);
640 work_place->put(*b, x, y);
642 // los agrego al hash
646 void Principal::loadConduct(xmlNodePtr nodo)
648 Glib::ustring name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
649 int orientacion=0, x, y;
651 nodo = nodo->children;
652 while (nodo != NULL) {
653 if (nodo->type == XML_ELEMENT_NODE) {
654 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
655 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
656 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
657 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
658 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
659 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
665 // listo, ya recolecte todos los datos, ahora creo el objeto!
666 ViewConduct *b = new ViewConduct(name, orientacion);
667 b->signal_button_press_event().connect(SigC::bind( SigC::slot(*this, &Principal::on_item_clicked), b) );
668 b->set_position(x,y);
669 work_place->put(*b, x, y);
671 // los agrego al hash
675 void Principal::loadExclusa(xmlNodePtr nodo)
677 Glib::ustring name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
678 int orientacion=0, x, y;
680 nodo = nodo->children;
681 while (nodo != NULL) {
682 if (nodo->type == XML_ELEMENT_NODE) {
683 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
684 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
685 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
686 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
687 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
688 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
694 // listo, ya recolecte todos los datos, ahora creo el objeto!
695 ViewExclusa *b = new ViewExclusa(name, orientacion);
696 b->signal_button_press_event().connect(SigC::bind( SigC::slot(*this, &Principal::on_item_clicked), b) );
697 b->set_position(x,y);
698 work_place->put(*b, x, y);
700 // los agrego al hash
704 void Principal::loadTank(xmlNodePtr nodo)
706 Glib::ustring name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
707 int orientacion=0, x, y;
709 nodo = nodo->children;
710 while (nodo != NULL) {
711 if (nodo->type == XML_ELEMENT_NODE) {
712 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
713 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
714 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
715 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
716 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
717 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
723 // listo, ya recolecte todos los datos, ahora creo el objeto!
724 ViewTank *b = new ViewTank(name, orientacion);
725 b->signal_button_press_event().connect(SigC::bind( SigC::slot(*this, &Principal::on_item_clicked), b) );
726 b->set_position(x,y);
727 work_place->put(*b, x, y);
729 // los agrego al hash
733 void Principal::loadUnion(xmlNodePtr nodo)
735 Glib::ustring name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
736 int orientacion=0, x, y;
738 nodo = nodo->children;
739 while (nodo != NULL) {
740 if (nodo->type == XML_ELEMENT_NODE) {
741 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
742 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
743 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
744 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
745 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
746 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
752 // listo, ya recolecte todos los datos, ahora creo el objeto!
753 ViewUnion *b = new ViewUnion(name, orientacion);
754 b->signal_button_release_event().connect(SigC::bind( SigC::slot(*this, &Principal::on_item_clicked), b) );
755 b->set_position(x,y);
756 work_place->put(*b, x, y);
758 // los agrego al hash
762 void Principal::loadDrain(xmlNodePtr nodo)
764 Glib::ustring name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
765 int orientacion=0, x, y;
767 nodo = nodo->children;
768 while (nodo != NULL) {
769 if (nodo->type == XML_ELEMENT_NODE) {
770 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
771 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
772 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
773 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
774 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
775 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
781 // listo, ya recolecte todos los datos, ahora creo el objeto!
782 ViewDrain *b = new ViewDrain(name, orientacion);
783 b->signal_button_release_event().connect(SigC::bind( SigC::slot(*this, &Principal::on_item_clicked), b) );
784 b->set_position(x,y);
785 work_place->put(*b, x, y);
787 // los agrego al hash
791 void Principal::read_status_xml(const std::string &frame)
793 std::string item_name;
795 document = xmlParseMemory(frame.c_str(),frame.size());
796 if (document == NULL) {
797 std::cout << "read_status_xml::no se creo documento" << std::endl;
801 xmlNodePtr nodo, items, props;
802 nodo = document->children;
806 if (strcmp((char *)nodo->name, "plantstatus") == 0) {
807 items = nodo->children;
808 while (items != NULL) {
809 if (items->type == XML_ELEMENT_NODE) {
812 if (xmlStrcmp(items->name, BAD_CAST"float")==0) {
813 tmp = get_float_from_xml(items->children);
814 item_name = (char *)xmlGetProp(items, BAD_CAST"name");
815 mapItems[item_name]->set_actual_flow(tmp);
816 } else if (xmlStrcmp(items->name, BAD_CAST"exclusa")==0) {
817 tmp_b = get_bool_from_xml(items->children);
818 item_name = (char *)xmlGetProp(items, BAD_CAST"name");
819 mapItems[item_name]->set_open(tmp_b);
820 } else if (xmlStrcmp(items->name, BAD_CAST"pump")==0) {
821 tmp_b = get_bool_from_xml(items->children);
822 item_name = (char *)xmlGetProp(items, BAD_CAST"name");
823 mapItems[item_name]->set_open(tmp_b);
824 } else if (xmlStrcmp(items->name, BAD_CAST"logic")==0) {
825 tmp_b = get_bool_from_xml(items->children);
826 item_name = (char *)xmlGetProp(items, BAD_CAST"name");
827 mapItems[item_name]->set_open(tmp_b);
828 } else if (xmlStrcmp(items->name, BAD_CAST"color")==0) {
829 item_name = (char *)xmlGetProp(items, BAD_CAST"name");
830 mapItems[item_name]->set_color( get_rgb_from_xml(items->children) );
831 } else if (xmlStrcmp(items->name, BAD_CAST"tank")==0) {
832 xmlNodePtr nodo_tmp = items->children;
836 while (nodo_tmp != NULL) {
837 if (nodo_tmp->type == XML_ELEMENT_NODE) {
838 if (xmlStrcmp(nodo_tmp->name, BAD_CAST"capacity")==0)
839 cap = atof( (char *)XML_GET_CONTENT(nodo_tmp->children) );
840 else if (xmlStrcmp(nodo_tmp->name, BAD_CAST"litros")==0)
841 lit= atof( (char *)XML_GET_CONTENT(nodo_tmp->children) );
842 else if (xmlStrcmp(nodo_tmp->name, BAD_CAST"salida")==0) {
843 if (xmlStrcmp(xmlGetProp(items, BAD_CAST"id"), BAD_CAST"inferior")==0) {
844 b_inf = get_bool_from_xml(nodo_tmp->children);
846 b_sup = get_bool_from_xml(nodo_tmp->children);
850 nodo_tmp = nodo_tmp->next;
852 item_name = (char *)xmlGetProp(items, BAD_CAST"name");
853 mapItems[item_name]->set_actual_flow(cap);
854 mapItems[item_name]->set_extra(lit);
855 dynamic_cast<ViewTank *>(mapItems[item_name])->set_out_sup(b_sup);
856 dynamic_cast<ViewTank *>(mapItems[item_name])->set_out_inf(b_inf);
862 xmlFreeDoc(document);
868 Gdk::Color Principal::get_rgb_from_xml(xmlNodePtr nodo)
871 while (nodo != NULL) {
872 if (nodo->type == XML_ELEMENT_NODE) {
873 if (xmlStrcmp(nodo->name, BAD_CAST"r")==0)
874 r = atoi( (char *)XML_GET_CONTENT(nodo->children) );
875 if (xmlStrcmp(nodo->name, BAD_CAST"g")==0)
876 g = atoi( (char *)XML_GET_CONTENT(nodo->children) );
877 if (xmlStrcmp(nodo->name, BAD_CAST"b")==0)
878 b = atoi( (char *)XML_GET_CONTENT(nodo->children) );
882 r = static_cast<gushort>(65535 * (r / 255.0f));
883 g = static_cast<gushort>(65535 * (g / 255.0f));
884 b = static_cast<gushort>(65535 * (b / 255.0f));
891 float Principal::get_float_from_xml(xmlNodePtr nodo)
894 while (nodo != NULL) {
895 if (nodo->type == XML_ELEMENT_NODE) {
896 if (xmlStrcmp(nodo->name, BAD_CAST"actual_flow")==0) {
897 tmp = atof( (char *)XML_GET_CONTENT(nodo->children) );
903 if (tmp == INFINITO) tmp = 0;
907 bool Principal::get_bool_from_xml(xmlNodePtr nodo)
910 while (nodo != NULL) {
911 if (nodo->type == XML_ELEMENT_NODE) {
912 if (xmlStrcmp(nodo->name, BAD_CAST"active")==0) {
913 tmp = (char *)XML_GET_CONTENT(nodo->children);
919 return tmp == "true";
922 void Principal::on_mnu_property()
924 dlg_property->show();
927 void Principal::on_dlg_property_ok()
930 PlaQui::Server::Command c("plant", "set_frequency");
931 c.add_arg("default");
932 c.add_arg( dlg_property->get_velocity() );
936 dlg_property->hide();
939 void Principal::on_btn_simulate_clicked()
941 if (conexion == NULL) return;
943 PlaQui::Server::Command c("plant", "start");
944 c.add_arg("default");
949 void Principal::on_btn_pause_clicked()
951 if (conexion == NULL) return;
953 PlaQui::Server::Command c("plant", "stop");
954 c.add_arg("default");