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::MenuItem *mnu_simular=0, *mnu_pausar=0;
25 Gtk::Button *bar_connect=0, *close_about=0;
26 Gtk::Image *plaqui_logo;
27 Gtk::Label *lbl_plaqui_version;
31 lbl_cap_flujo = lbl_cap_extra = lbl_extra = lbl_nombre = lbl_color = lbl_flujo = 0;
32 btn_simulate = btn_pause = 0;
34 anim_frames[0] = Gdk::Pixbuf::create_from_file(PACKAGE_DATA_DIR"/plaqui-client/pixmaps/anim_0.png");
35 anim_frames[1] = Gdk::Pixbuf::create_from_file(PACKAGE_DATA_DIR"/plaqui-client/pixmaps/anim_1.png");
36 anim_frames[2] = Gdk::Pixbuf::create_from_file(PACKAGE_DATA_DIR"/plaqui-client/pixmaps/anim_2.png");
37 anim_frames[3] = Gdk::Pixbuf::create_from_file(PACKAGE_DATA_DIR"/plaqui-client/pixmaps/anim_3.png");
38 anim_frames[4] = Gdk::Pixbuf::create_from_file(PACKAGE_DATA_DIR"/plaqui-client/pixmaps/anim_4.png");
39 anim_frames[5] = Gdk::Pixbuf::create_from_file(PACKAGE_DATA_DIR"/plaqui-client/pixmaps/anim_5.png");
40 anim_frames[6] = Gdk::Pixbuf::create_from_file(PACKAGE_DATA_DIR"/plaqui-client/pixmaps/anim_6.png");
41 anim_frames[7] = Gdk::Pixbuf::create_from_file(PACKAGE_DATA_DIR"/plaqui-client/pixmaps/anim_7.png");
44 plaqui_logo = anim = 0;
45 lbl_plaqui_version = 0;
46 rg->get_widget("lbl_plaqui_version", lbl_plaqui_version);
47 rg->get_widget("plaqui_logo", plaqui_logo);
48 plaqui_logo->set(PACKAGE_DATA_DIR"/plaqui-client/pixmaps/logo.png");
50 rg->get_widget("plaqui_logo", plaqui_logo);
51 // Calculo número de revisión.
52 std::string rev = "$Rev$";
53 rev = rev.substr(6, rev.length() - 8);
54 std::string s = "PlaQui Client versión " VERSION " (revisión ";
57 lbl_plaqui_version->set_text(Glib::locale_to_utf8(s));
60 lbl_plaqui_version->set_text("PlaQui Client");
63 rg->get_widget("anim_frames", anim);
64 anim->set(anim_frames[current_frame]);
66 rg->get_widget("close_about", close_about);
67 rg->get_widget("dlgAbout", dlg_about);
68 rg->get_widget("mnu_pausar", mnu_pausar);
69 rg->get_widget("btn_pausa", btn_pause);
70 rg->get_widget("mnu_simular", mnu_simular);
71 rg->get_widget("btn_simular", btn_simulate);
72 rg->get_widget("btn_activar", btn_activar);
73 rg->get_widget("color_preview", color_preview);
74 rg->get_widget("lbl_nombre", lbl_nombre);
75 rg->get_widget("lbl_extra", lbl_extra);
76 rg->get_widget("lbl_cap_extra", lbl_cap_extra);
77 rg->get_widget("lbl_cap_flujo", lbl_cap_flujo);
78 rg->get_widget("lbl_flujo", lbl_flujo);
79 rg->get_widget("mnu_file_connect", conect);
80 rg->get_widget("mnu_file_disconnect", mnu_disconnect);
81 rg->get_widget("mnu_file_exit", exit);
82 rg->get_widget("mnu_help_about", about);
83 rg->get_widget("mnu_server_stop", server_stop);
84 rg->get_widget("mnu_prop", mnu_prop);
85 rg->get_widget_derived("dlg_property", dlg_property);
86 rg->get_widget_derived("dlgConectar", dlg_conectar);
87 rg->get_widget("txt_view", txt_view);
88 rg->get_widget("bar_connect", bar_connect);
89 rg->get_widget("work_place", work_place);
90 rg->get_widget("ico_conected", ico_conected);
92 work_place->signal_expose_event().connect( SigC::slot(*this, &Principal::on_workplace_expose_event) );
93 dlg_property->get_ok_button()->signal_clicked().connect( SigC::slot(*this, &Principal::on_dlg_property_ok) );
94 dlg_conectar->get_ok_button()->signal_clicked().connect( SigC::slot(*this, &Principal::on_dlg_connect_ok) );
95 mnu_prop->signal_activate().connect( SigC::slot(*this, &Principal::on_mnu_property));
96 mnu_disconnect->signal_activate().connect( SigC::slot(*this, &Principal::on_mnu_file_disconnect));
97 server_stop->signal_activate().connect( SigC::slot(*this, &Principal::on_mnu_server_stop_activate));
98 conect->signal_activate().connect( SigC::slot(*this, &Principal::on_mnu_file_connect));
99 bar_connect->signal_clicked().connect( SigC::slot(*this, &Principal::on_mnu_file_connect));
100 exit->signal_activate().connect( SigC::slot(*this, &Principal::on_mnu_file_exit));
101 about->signal_activate().connect( SigC::slot(*this, &Principal::on_mnu_help_about));
102 btn_activar->signal_clicked().connect( SigC::slot(*this, &Principal::on_btn_activar_clicked) );
103 mnu_simular->signal_activate().connect( SigC::slot(*this, &Principal::on_btn_simulate_clicked) );
104 btn_simulate->signal_clicked().connect( SigC::slot(*this, &Principal::on_btn_simulate_clicked) );
105 mnu_pausar->signal_activate().connect( SigC::slot(*this, &Principal::on_btn_pause_clicked) );
106 btn_pause->signal_clicked().connect( SigC::slot(*this, &Principal::on_btn_pause_clicked) );
107 close_about->signal_clicked().connect( SigC::slot(*dlg_about, &Gtk::Widget::hide) );
110 is_xml_loaded = false;
111 last_selected = NULL;
113 update_ui.connect( SigC::slot(*this, &Principal::update_items_prop ) );
114 load_xml_dispatch.connect( SigC::slot(*this, &Principal::loadXML ) );
115 gc = Gdk::GC::create(get_window());
116 color_low = Gdk::Color("blue");
117 color_high = Gdk::Color("red");
118 Gtk::Widget::get_default_colormap()->alloc_color(color_low);
119 Gtk::Widget::get_default_colormap()->alloc_color(color_high);
120 txt_view->set_editable(false);
123 Principal::~Principal()
127 void Principal::on_realize()
129 Gtk::Window::on_realize();
132 bool Principal::on_workplace_expose_event(GdkEventExpose *e)
134 Glib::RefPtr<Gdk::Window> window = work_place->get_window();
138 std::map<const std::string, ViewItem *>::iterator i;
139 for(i=mapItems.begin(); i!=mapItems.end(); i++) {
140 if (dynamic_cast<ViewAnd *>(i->second) || dynamic_cast<ViewOr *>(i->second) || dynamic_cast<ViewNot *>(i->second)) {
141 x1 = i->second->x + i->second->in_x;
142 y1 = i->second->y + i->second->in_y;
143 std::list<t_Linea>::iterator linea;
144 for(linea=i->second->in_lines.begin(); linea!=i->second->in_lines.end(); linea++) {
145 ViewItem *tmp = find_item(linea->dst);
146 /* Si este item es un tanque */
147 if (linea->is_tank) {
148 if (linea->is_tank_lower) {
149 x2 = tmp->x + tmp->out_x;
150 y2 = tmp->y + tmp->out_y;
151 if (dynamic_cast<ViewTank *>(tmp)->get_out_inf()) {
152 gc->set_foreground(color_high);
154 gc->set_foreground(color_low);
157 x2 = tmp->x + tmp->in_x;
158 y2 = tmp->y + tmp->in_y;
159 if (dynamic_cast<ViewTank *>(tmp)->get_out_sup()) {
160 gc->set_foreground(color_high);
162 gc->set_foreground(color_low);
166 x2 = tmp->x + tmp->out_x;
167 y2 = tmp->y + tmp->out_y;
168 if (tmp->get_open()) {
169 gc->set_foreground(color_high);
171 gc->set_foreground(color_low);
174 gc->set_line_attributes(3, Gdk::LINE_SOLID, Gdk::CAP_NOT_LAST, Gdk::JOIN_MITER);
175 window->draw_line(gc, x2+tmp->item_offset_x, y2+tmp->item_offset_y, x2+tmp->item_offset_x, y1+i->second->offset_y);
176 window->draw_line(gc, x2+tmp->item_offset_x, y1+i->second->offset_y, x1+i->second->offset_x, y1+i->second->offset_y);
177 window->draw_line(gc, x1, y1, x1+i->second->offset_x, y1+i->second->offset_y);
178 window->draw_line(gc, x2, y2, x2+tmp->item_offset_x, y2+tmp->item_offset_y);
180 x1 = i->second->x + i->second->out_x;
181 y1 = i->second->y + i->second->out_y;
182 for(linea=i->second->out_lines.begin(); linea!=i->second->out_lines.end(); linea++) {
183 ViewItem *tmp = find_item(linea->dst);
184 x2 = tmp->x + tmp->in_x;
185 y2 = tmp->y + tmp->in_y;
186 if (i->second->get_open()) {
187 gc->set_foreground(color_high);
189 gc->set_foreground(color_low);
191 gc->set_line_attributes(3, Gdk::LINE_SOLID, Gdk::CAP_NOT_LAST, Gdk::JOIN_MITER);
192 window->draw_line(gc, x1+i->second->offset_x, y1+i->second->offset_y, x1+i->second->offset_x, y2+tmp->item_offset_y);
193 window->draw_line(gc, x1+i->second->offset_x, y2+tmp->item_offset_y, x2+tmp->item_offset_x, y2+tmp->item_offset_y);
194 window->draw_line(gc, x1, y1, x1+i->second->offset_x, y1+i->second->offset_y);
195 window->draw_line(gc, x2, y2, x2+tmp->item_offset_x, y2+tmp->item_offset_y);
201 ViewItem *Principal::find_item(std::string &_name)
203 std::map<const std::string, ViewItem *>::iterator i;
204 for(i=mapItems.begin(); i!=mapItems.end(); i++) {
205 if (i->second->get_name() == _name) {
212 void Principal::on_dlg_connect_ok()
214 if (conexion == NULL) {
217 conexion = new PlaQui::Server::ControlClient(dlg_conectar->get_server_name(), dlg_conectar->get_server_port());
220 txt_view->get_buffer()->insert(txt_view->get_buffer()->begin(), "NO SE PUDO CONECTAR\n");
221 //delete conexion; XXX Si no me equivoco, si falla el
222 //constructor, no se reserva la memoria (el delete no va).
225 dlg_conectar->hide();
229 // Conecto las señales
230 conexion->signal_ok_received().connect( SigC::slot(*this, &Principal::on_conexion_ok) );
231 conexion->signal_error().connect( SigC::slot(*this, &Principal::on_conexion_fatal_error) );
232 conexion->signal_error_received().connect( SigC::slot(*this, &Principal::on_conexion_error) );
233 conexion->signal_finished().connect( SigC::slot(*this, &Principal::on_conexion_finished) );
234 conexion->signal_frame_received().connect(SigC::slot(*this, &Principal::on_conexion_frame));
235 // Lanzo la conexion!
237 txt_view->get_buffer()->insert(txt_view->get_buffer()->begin(),"CONNECTED\n");
238 ico_conected->set( Gtk::Stock::YES , Gtk::IconSize(Gtk::ICON_SIZE_LARGE_TOOLBAR));
240 // Pido la planta por defecto
241 PlaQui::Server::Command c("plant", "get");
242 c.add_arg("default");
245 dlg_conectar->hide();
248 void Principal::on_mnu_file_exit()
250 on_mnu_file_disconnect();
254 // Espera a que termine realmente.
256 Glib::usleep(100000); // 0,1 segundo
261 bool Principal::on_delete_event(GdkEventAny *e)
267 void Principal::on_mnu_server_stop_activate()
269 if (conexion == NULL) return;
271 PlaQui::Server::Command c("server", "stop");
275 void Principal::on_btn_activar_clicked()
277 if ((conexion == NULL) || (last_selected == NULL)) return;
279 PlaQui::Server::Command c("plant", "set");
280 c.add_arg("default");
281 c.add_arg(last_selected->get_name());
284 if (last_selected->get_open())
292 void Principal::on_mnu_file_disconnect()
294 if (conexion == NULL) return;
296 PlaQui::Server::Command c("transmission", "stop");
297 c.add_arg(conexion->get_host());
300 PlaQui::Server::Command c2("connection", "stop");
301 c2.add_arg(conexion->get_host());
302 c2.add_arg(conexion->get_port());
306 void Principal::on_mnu_file_connect()
308 dlg_conectar->show();
311 void Principal::on_mnu_help_about()
316 bool Principal::on_item_clicked(GdkEventButton *e, ViewItem *i)
319 s = "Selecciono "+i->get_name()+"\n";
320 txt_view->get_buffer()->insert(txt_view->get_buffer()->begin(), s);
326 void Principal::update_items_prop()
328 if (last_selected != NULL) {
329 lbl_nombre->set_text(last_selected->get_name());
330 lbl_flujo->set_text(last_selected->get_actual_flow());
331 lbl_extra->set_text(last_selected->get_extra());
333 lbl_cap_flujo->set_text(last_selected->get_cap_flow());
334 lbl_cap_extra->set_text(last_selected->get_cap_extra());
336 color_preview->modify_bg(Gtk::STATE_NORMAL, last_selected->get_color());
337 color_preview->queue_draw();
342 if (current_frame > 7) {
345 anim->set(anim_frames[current_frame]);
348 // Mando a redibujar a todos los items
349 std::map<const std::string, ViewItem *>::iterator i;
350 for(i=mapItems.begin(); i!=mapItems.end(); i++) {
351 i->second->queue_draw();
353 work_place->queue_draw();
356 void Principal::on_conexion_frame(const std::string &frame)
358 if (conexion != NULL) {
359 read_status_xml(frame);
363 void Principal::on_conexion_finished()
365 txt_view->get_buffer()->insert(txt_view->get_buffer()->begin(),"HANG UP\n");
366 ico_conected->set( Gtk::Stock::NO , Gtk::IconSize(Gtk::ICON_SIZE_LARGE_TOOLBAR));
369 std::map<const std::string, ViewItem *>::iterator i;
370 for(i=mapItems.begin(); i!=mapItems.end(); i++) {
374 is_xml_loaded = false;
377 void Principal::on_conexion_ok(const std::string &body)
379 /* lo paso a la carga del XML */
380 /* verifico que body este completo */
381 if ((body.find("</planta>")>0) && (body.find("<planta>")>0)) {
387 s = "<IN>\n"+Glib::locale_to_utf8(body)+"\n</IN>\n";
390 s = "NO SE PUDO CONVERTIR MENSAJE A UTF8";
392 txt_view->get_buffer()->insert(txt_view->get_buffer()->begin(),s);
396 void Principal::on_conexion_fatal_error(const PlaQui::Server::ControlClient::Error& code, const std::string& desc)
403 st = "Error de red nro. "+s+": "+desc+"\n";
404 txt_view->get_buffer()->insert(txt_view->get_buffer()->begin(),st);
407 void Principal::on_conexion_error(unsigned code, const std::string& desc)
414 st = "El server dice que hay error nro. "+s+": "+desc+"\n";
415 txt_view->get_buffer()->insert(txt_view->get_buffer()->begin(),st);
418 void Principal::loadXML()
421 if (is_xml_loaded) return;
423 /* Parseo de ejemplo de un XML desde archivo */
425 document = xmlParseMemory(xml_body.c_str(),xml_body.size());
426 if (document == NULL) {
427 txt_view->get_buffer()->insert(txt_view->get_buffer()->begin(),"No se pudo cargar XML enviado por el servidor.");
428 is_xml_loaded = false;
431 is_xml_loaded = true;
432 /* bien, el archivo se parseo bien! */
433 xmlNodePtr nodo, items;
434 nodo = document->children;
436 if (strcmp((char *)nodo->name, "planta") == 0) {
437 items = nodo->children;
438 while (items != NULL) {
439 if (items->type == XML_ELEMENT_NODE) {
440 if (xmlStrcmp(items->name, BAD_CAST"bomba")==0) {
442 } else if (xmlStrcmp(items->name, BAD_CAST"codo")==0) {
444 } else if (xmlStrcmp(items->name, BAD_CAST"tubo")==0) {
446 } else if (xmlStrcmp(items->name, BAD_CAST"exclusa")==0) {
448 } else if (xmlStrcmp(items->name, BAD_CAST"tanque")==0) {
450 } else if (xmlStrcmp(items->name, BAD_CAST"empalme")==0) {
452 } else if (xmlStrcmp(items->name, BAD_CAST"drenaje")==0) {
454 } else if (xmlStrcmp(items->name, BAD_CAST"and")==0) {
456 } else if (xmlStrcmp(items->name, BAD_CAST"or")==0) {
458 } else if (xmlStrcmp(items->name, BAD_CAST"not")==0) {
467 xmlFreeDoc(document);
469 // Ya cargado el XML, mando un msg para empezar a recibir los frames!
470 PlaQui::Server::Command c("transmission", "start");
471 c.add_arg("default");
472 c.add_arg(conexion->get_host());
477 void Principal::loadNot(xmlNodePtr nodo)
479 std::string name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
480 std::string id = (char *)xmlGetProp(nodo, BAD_CAST"id");
481 int orientacion=0, x, y;
485 nodo = nodo->children;
486 while (nodo != NULL) {
487 if (nodo->type == XML_ELEMENT_NODE) {
488 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
489 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
490 p = new ViewNot(name, orientacion);
491 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
492 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
493 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
494 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
495 } else if (xmlStrcmp(nodo->name, BAD_CAST"salida") == 0) {
496 linea.dst = (char *)XML_GET_CONTENT(nodo->children);
497 linea.is_tank = false;
498 p->out_lines.push_back(linea);
499 } else if (xmlStrcmp(nodo->name, BAD_CAST"entrada") == 0) {
500 linea.dst = (char *)XML_GET_CONTENT(nodo->children);
501 linea.is_tank = false;
502 if (dynamic_cast<ViewTank *>(find_item(linea.dst)) != NULL) {
503 linea.is_tank = true;
504 linea.is_tank_lower = false;
505 if (xmlStrcmp(xmlGetProp(nodo, BAD_CAST"id"), BAD_CAST"inferior")==0)
506 linea.is_tank_lower = true;
508 p->in_lines.push_back(linea);
514 p->signal_button_press_event().connect(SigC::bind( SigC::slot(*this, &Principal::on_item_clicked), p) );
515 p->set_position(x,y);
516 work_place->put(*p, x, y);
518 // los agrego al hash
522 void Principal::loadOr(xmlNodePtr nodo)
524 std::string name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
525 std::string id = (char *)xmlGetProp(nodo, BAD_CAST"id");
526 int orientacion=0, x, y;
531 nodo = nodo->children;
532 while (nodo != NULL) {
533 if (nodo->type == XML_ELEMENT_NODE) {
534 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
535 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
536 p = new ViewOr(name, orientacion);
537 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
538 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
539 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
540 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
541 } else if (xmlStrcmp(nodo->name, BAD_CAST"salida") == 0) {
542 linea.dst = (char *)XML_GET_CONTENT(nodo->children);
543 linea.is_tank = false;
544 p->out_lines.push_back(linea);
545 } else if (xmlStrcmp(nodo->name, BAD_CAST"entrada") == 0) {
546 linea.dst = (char *)XML_GET_CONTENT(nodo->children);
547 linea.is_tank = false;
548 if (dynamic_cast<ViewTank *>(find_item(linea.dst)) != NULL) {
549 linea.is_tank = true;
550 linea.is_tank_lower = false;
551 if (xmlStrcmp(xmlGetProp(nodo, BAD_CAST"id"), BAD_CAST"inferior")==0)
552 linea.is_tank_lower = true;
554 p->in_lines.push_back(linea);
560 p->signal_button_press_event().connect(SigC::bind( SigC::slot(*this, &Principal::on_item_clicked), p) );
561 p->set_position(x,y);
562 work_place->put(*p, x, y);
564 // los agrego al hash
568 void Principal::loadAnd(xmlNodePtr nodo)
570 std::string name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
571 std::string id = (char *)xmlGetProp(nodo, BAD_CAST"id");
572 int orientacion=0, x, y;
574 xmlNodePtr inicial = nodo;
578 nodo = nodo->children;
579 while (nodo != NULL) {
580 if (nodo->type == XML_ELEMENT_NODE) {
581 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
582 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
583 p = new ViewAnd(name, orientacion);
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) );
588 } else if (xmlStrcmp(nodo->name, BAD_CAST"salida") == 0) {
589 linea.dst = (char *)XML_GET_CONTENT(nodo->children);
590 p->out_lines.push_back(linea);
591 } else if (xmlStrcmp(nodo->name, BAD_CAST"entrada") == 0) {
592 linea.dst = (char *)XML_GET_CONTENT(nodo->children);
593 linea.is_tank = false;
594 if (dynamic_cast<ViewTank *>(find_item(linea.dst)) != NULL) {
595 linea.is_tank = true;
596 linea.is_tank_lower = false;
597 if (xmlStrcmp(xmlGetProp(nodo, BAD_CAST"id"), BAD_CAST"inferior")==0)
598 linea.is_tank_lower = true;
600 p->in_lines.push_back(linea);
606 p->signal_button_press_event().connect(SigC::bind( SigC::slot(*this, &Principal::on_item_clicked), p) );
607 p->set_position(x,y);
608 work_place->put(*p, x, y);
610 // los agrego al hash
614 void Principal::loadBomba(xmlNodePtr nodo)
616 Glib::ustring name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
617 int orientacion=0, x, y;
619 nodo = nodo->children;
620 while (nodo != NULL) {
621 if (nodo->type == XML_ELEMENT_NODE) {
622 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
623 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
624 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
625 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
626 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
627 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
633 // listo, ya recolecte todos los datos, ahora creo el objeto!
634 ViewPump *b = new ViewPump(name, orientacion);
635 b->signal_button_press_event().connect(SigC::bind( SigC::slot(*this, &Principal::on_item_clicked), b) );
636 b->set_position(x,y);
637 work_place->put(*b, x, y);
639 // los agrego al hash
643 void Principal::loadCodo(xmlNodePtr nodo)
645 std::string name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
646 int orientacion=0, x, y;
648 nodo = nodo->children;
649 while (nodo != NULL) {
650 if (nodo->type == XML_ELEMENT_NODE) {
651 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
652 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
653 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
654 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
655 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
656 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
662 // listo, ya recolecte todos los datos, ahora creo el objeto!
663 ViewItem *b = new ViewCodo(name, orientacion);
664 b->signal_button_press_event().connect(SigC::bind( SigC::slot(*this, &Principal::on_item_clicked), b) );
665 b->set_position(x,y);
666 work_place->put(*b, x, y);
668 // los agrego al hash
672 void Principal::loadConduct(xmlNodePtr nodo)
674 Glib::ustring name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
675 int orientacion=0, x, y;
677 nodo = nodo->children;
678 while (nodo != NULL) {
679 if (nodo->type == XML_ELEMENT_NODE) {
680 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
681 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
682 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
683 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
684 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
685 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
691 // listo, ya recolecte todos los datos, ahora creo el objeto!
692 ViewConduct *b = new ViewConduct(name, orientacion);
693 b->signal_button_press_event().connect(SigC::bind( SigC::slot(*this, &Principal::on_item_clicked), b) );
694 b->set_position(x,y);
695 work_place->put(*b, x, y);
697 // los agrego al hash
701 void Principal::loadExclusa(xmlNodePtr nodo)
703 Glib::ustring name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
704 int orientacion=0, x, y;
706 nodo = nodo->children;
707 while (nodo != NULL) {
708 if (nodo->type == XML_ELEMENT_NODE) {
709 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
710 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
711 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
712 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
713 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
714 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
720 // listo, ya recolecte todos los datos, ahora creo el objeto!
721 ViewExclusa *b = new ViewExclusa(name, orientacion);
722 b->signal_button_press_event().connect(SigC::bind( SigC::slot(*this, &Principal::on_item_clicked), b) );
723 b->set_position(x,y);
724 work_place->put(*b, x, y);
726 // los agrego al hash
730 void Principal::loadTank(xmlNodePtr nodo)
732 Glib::ustring name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
733 int orientacion=0, x, y;
735 nodo = nodo->children;
736 while (nodo != NULL) {
737 if (nodo->type == XML_ELEMENT_NODE) {
738 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
739 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
740 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
741 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
742 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
743 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
749 // listo, ya recolecte todos los datos, ahora creo el objeto!
750 ViewTank *b = new ViewTank(name, orientacion);
751 b->signal_button_press_event().connect(SigC::bind( SigC::slot(*this, &Principal::on_item_clicked), b) );
752 b->set_position(x,y);
753 work_place->put(*b, x, y);
755 // los agrego al hash
759 void Principal::loadUnion(xmlNodePtr nodo)
761 Glib::ustring name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
762 int orientacion=0, x, y;
764 nodo = nodo->children;
765 while (nodo != NULL) {
766 if (nodo->type == XML_ELEMENT_NODE) {
767 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
768 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
769 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
770 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
771 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
772 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
778 // listo, ya recolecte todos los datos, ahora creo el objeto!
779 ViewUnion *b = new ViewUnion(name, orientacion);
780 b->signal_button_release_event().connect(SigC::bind( SigC::slot(*this, &Principal::on_item_clicked), b) );
781 b->set_position(x,y);
782 work_place->put(*b, x, y);
784 // los agrego al hash
788 void Principal::loadDrain(xmlNodePtr nodo)
790 Glib::ustring name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
791 int orientacion=0, x, y;
793 nodo = nodo->children;
794 while (nodo != NULL) {
795 if (nodo->type == XML_ELEMENT_NODE) {
796 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
797 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
798 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
799 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
800 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
801 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
807 // listo, ya recolecte todos los datos, ahora creo el objeto!
808 ViewDrain *b = new ViewDrain(name, orientacion);
809 b->signal_button_release_event().connect(SigC::bind( SigC::slot(*this, &Principal::on_item_clicked), b) );
810 b->set_position(x,y);
811 work_place->put(*b, x, y);
813 // los agrego al hash
817 void Principal::read_status_xml(const std::string &_frame)
819 std::string item_name;
820 std::string frame = _frame;
823 // Cambio las , por . para evitar problemas de convercion
824 for(int i=0; i<frame.size(); i++) {
825 if (frame[i] == ',') {
829 document = xmlParseMemory(frame.c_str(),frame.size());
830 if (document == NULL) {
831 txt_view->get_buffer()->insert(txt_view->get_buffer()->begin(), "ERROR : No se pudo leer el último frame!\n");
835 xmlNodePtr nodo, items, props;
836 nodo = document->children;
840 if (strcmp((char *)nodo->name, "plantstatus") == 0) {
841 items = nodo->children;
842 while (items != NULL) {
843 if (items->type == XML_ELEMENT_NODE) {
846 if (xmlStrcmp(items->name, BAD_CAST"float")==0) {
847 tmp = get_float_from_xml(items->children);
848 item_name = (char *)xmlGetProp(items, BAD_CAST"name");
849 mapItems[item_name]->set_actual_flow(tmp);
850 } else if (xmlStrcmp(items->name, BAD_CAST"exclusa")==0) {
851 tmp_b = get_bool_from_xml(items->children);
852 item_name = (char *)xmlGetProp(items, BAD_CAST"name");
853 mapItems[item_name]->set_open(tmp_b);
854 } else if (xmlStrcmp(items->name, BAD_CAST"pump")==0) {
855 tmp_b = get_bool_from_xml(items->children);
856 item_name = (char *)xmlGetProp(items, BAD_CAST"name");
857 mapItems[item_name]->set_open(tmp_b);
858 } else if (xmlStrcmp(items->name, BAD_CAST"logic")==0) {
859 tmp_b = get_bool_from_xml(items->children);
860 item_name = (char *)xmlGetProp(items, BAD_CAST"name");
861 mapItems[item_name]->set_open(tmp_b);
862 } else if (xmlStrcmp(items->name, BAD_CAST"color")==0) {
863 item_name = (char *)xmlGetProp(items, BAD_CAST"name");
864 mapItems[item_name]->set_color( get_rgb_from_xml(items->children) );
865 } else if (xmlStrcmp(items->name, BAD_CAST"tank")==0) {
866 xmlNodePtr nodo_tmp = items->children;
870 while (nodo_tmp != NULL) {
871 if (nodo_tmp->type == XML_ELEMENT_NODE) {
872 if (xmlStrcmp(nodo_tmp->name, BAD_CAST"capacity")==0)
873 cap = atof( (char *)XML_GET_CONTENT(nodo_tmp->children) );
874 else if (xmlStrcmp(nodo_tmp->name, BAD_CAST"litros")==0)
875 lit= atof( (char *)XML_GET_CONTENT(nodo_tmp->children) );
876 else if (xmlStrcmp(nodo_tmp->name, BAD_CAST"salida")==0) {
877 if (xmlStrcmp(xmlGetProp(nodo_tmp, BAD_CAST"id"), BAD_CAST"inferior")==0) {
878 b_inf = get_bool_from_xml(nodo_tmp->children);
880 b_sup = get_bool_from_xml(nodo_tmp->children);
884 nodo_tmp = nodo_tmp->next;
886 item_name = (char *)xmlGetProp(items, BAD_CAST"name");
887 mapItems[item_name]->set_actual_flow(cap);
888 mapItems[item_name]->set_extra(lit);
889 dynamic_cast<ViewTank *>(mapItems[item_name])->set_out_sup(b_sup);
890 dynamic_cast<ViewTank *>(mapItems[item_name])->set_out_inf(b_inf);
896 xmlFreeDoc(document);
902 Gdk::Color Principal::get_rgb_from_xml(xmlNodePtr nodo)
905 while (nodo != NULL) {
906 if (nodo->type == XML_ELEMENT_NODE) {
907 if (xmlStrcmp(nodo->name, BAD_CAST"r")==0)
908 r = atoi( (char *)XML_GET_CONTENT(nodo->children) );
909 if (xmlStrcmp(nodo->name, BAD_CAST"g")==0)
910 g = atoi( (char *)XML_GET_CONTENT(nodo->children) );
911 if (xmlStrcmp(nodo->name, BAD_CAST"b")==0)
912 b = atoi( (char *)XML_GET_CONTENT(nodo->children) );
916 r = static_cast<gushort>(65535 * (r / 255.0f));
917 g = static_cast<gushort>(65535 * (g / 255.0f));
918 b = static_cast<gushort>(65535 * (b / 255.0f));
925 float Principal::get_float_from_xml(xmlNodePtr nodo)
929 while (nodo != NULL) {
930 if (nodo->type == XML_ELEMENT_NODE) {
931 if (xmlStrcmp(nodo->name, BAD_CAST"actual_flow")==0) {
932 s = (char *)XML_GET_CONTENT(nodo->children);
938 std::stringstream ss;
941 if (tmp == INFINITO) tmp = 0;
946 bool Principal::get_bool_from_xml(xmlNodePtr nodo)
949 while (nodo != NULL) {
950 if (nodo->type == XML_ELEMENT_NODE) {
951 if (xmlStrcmp(nodo->name, BAD_CAST"active")==0) {
952 tmp = (char *)XML_GET_CONTENT(nodo->children);
958 return tmp == "true";
961 void Principal::on_mnu_property()
963 dlg_property->show();
966 void Principal::on_dlg_property_ok()
969 PlaQui::Server::Command c("plant", "set_frequency");
970 c.add_arg("default");
971 c.add_arg( dlg_property->get_velocity() );
975 dlg_property->hide();
978 void Principal::on_btn_simulate_clicked()
980 if (conexion == NULL) return;
982 PlaQui::Server::Command c("plant", "start");
983 c.add_arg("default");
988 void Principal::on_btn_pause_clicked()
990 if (conexion == NULL) return;
992 PlaQui::Server::Command c("plant", "stop");
993 c.add_arg("default");