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 p->out_lines.push_back(linea);
498 } else if (xmlStrcmp(nodo->name, BAD_CAST"entrada") == 0) {
499 linea.dst = (char *)XML_GET_CONTENT(nodo->children);
500 linea.is_tank = false;
501 if (dynamic_cast<ViewTank *>(find_item(linea.dst)) != NULL) {
502 linea.is_tank = true;
503 linea.is_tank_lower = false;
504 if (xmlStrcmp(xmlGetProp(nodo, BAD_CAST"id"), BAD_CAST"inferior")==0)
505 linea.is_tank_lower = true;
507 p->in_lines.push_back(linea);
513 p->signal_button_press_event().connect(SigC::bind( SigC::slot(*this, &Principal::on_item_clicked), p) );
514 p->set_position(x,y);
515 work_place->put(*p, x, y);
517 // los agrego al hash
521 void Principal::loadOr(xmlNodePtr nodo)
523 std::string name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
524 std::string id = (char *)xmlGetProp(nodo, BAD_CAST"id");
525 int orientacion=0, x, y;
530 nodo = nodo->children;
531 while (nodo != NULL) {
532 if (nodo->type == XML_ELEMENT_NODE) {
533 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
534 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
535 p = new ViewOr(name, orientacion);
536 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
537 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
538 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
539 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
540 } else if (xmlStrcmp(nodo->name, BAD_CAST"salida") == 0) {
541 linea.dst = (char *)XML_GET_CONTENT(nodo->children);
542 p->out_lines.push_back(linea);
543 } else if (xmlStrcmp(nodo->name, BAD_CAST"entrada") == 0) {
544 linea.dst = (char *)XML_GET_CONTENT(nodo->children);
545 linea.is_tank = false;
546 if (dynamic_cast<ViewTank *>(find_item(linea.dst)) != NULL) {
547 linea.is_tank = true;
548 linea.is_tank_lower = false;
549 if (xmlStrcmp(xmlGetProp(nodo, BAD_CAST"id"), BAD_CAST"inferior")==0)
550 linea.is_tank_lower = true;
552 p->in_lines.push_back(linea);
558 p->signal_button_press_event().connect(SigC::bind( SigC::slot(*this, &Principal::on_item_clicked), p) );
559 p->set_position(x,y);
560 work_place->put(*p, x, y);
562 // los agrego al hash
566 void Principal::loadAnd(xmlNodePtr nodo)
568 std::string name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
569 std::string id = (char *)xmlGetProp(nodo, BAD_CAST"id");
570 int orientacion=0, x, y;
572 xmlNodePtr inicial = nodo;
576 nodo = nodo->children;
577 while (nodo != NULL) {
578 if (nodo->type == XML_ELEMENT_NODE) {
579 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
580 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
581 p = new ViewAnd(name, orientacion);
582 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
583 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
584 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
585 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
586 } else if (xmlStrcmp(nodo->name, BAD_CAST"salida") == 0) {
587 linea.dst = (char *)XML_GET_CONTENT(nodo->children);
588 p->out_lines.push_back(linea);
589 } else if (xmlStrcmp(nodo->name, BAD_CAST"entrada") == 0) {
590 linea.dst = (char *)XML_GET_CONTENT(nodo->children);
591 linea.is_tank = false;
592 if (dynamic_cast<ViewTank *>(find_item(linea.dst)) != NULL) {
593 linea.is_tank = true;
594 linea.is_tank_lower = false;
595 if (xmlStrcmp(xmlGetProp(nodo, BAD_CAST"id"), BAD_CAST"inferior")==0)
596 linea.is_tank_lower = true;
598 p->in_lines.push_back(linea);
604 p->signal_button_press_event().connect(SigC::bind( SigC::slot(*this, &Principal::on_item_clicked), p) );
605 p->set_position(x,y);
606 work_place->put(*p, x, y);
608 // los agrego al hash
612 void Principal::loadBomba(xmlNodePtr nodo)
614 Glib::ustring name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
615 int orientacion=0, x, y;
617 nodo = nodo->children;
618 while (nodo != NULL) {
619 if (nodo->type == XML_ELEMENT_NODE) {
620 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
621 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
622 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
623 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
624 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
625 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
631 // listo, ya recolecte todos los datos, ahora creo el objeto!
632 ViewPump *b = new ViewPump(name, orientacion);
633 b->signal_button_press_event().connect(SigC::bind( SigC::slot(*this, &Principal::on_item_clicked), b) );
634 b->set_position(x,y);
635 work_place->put(*b, x, y);
637 // los agrego al hash
641 void Principal::loadCodo(xmlNodePtr nodo)
643 std::string name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
644 int orientacion=0, x, y;
646 nodo = nodo->children;
647 while (nodo != NULL) {
648 if (nodo->type == XML_ELEMENT_NODE) {
649 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
650 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
651 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
652 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
653 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
654 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
660 // listo, ya recolecte todos los datos, ahora creo el objeto!
661 ViewItem *b = new ViewCodo(name, orientacion);
662 b->signal_button_press_event().connect(SigC::bind( SigC::slot(*this, &Principal::on_item_clicked), b) );
663 b->set_position(x,y);
664 work_place->put(*b, x, y);
666 // los agrego al hash
670 void Principal::loadConduct(xmlNodePtr nodo)
672 Glib::ustring name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
673 int orientacion=0, x, y;
675 nodo = nodo->children;
676 while (nodo != NULL) {
677 if (nodo->type == XML_ELEMENT_NODE) {
678 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
679 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
680 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
681 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
682 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
683 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
689 // listo, ya recolecte todos los datos, ahora creo el objeto!
690 ViewConduct *b = new ViewConduct(name, orientacion);
691 b->signal_button_press_event().connect(SigC::bind( SigC::slot(*this, &Principal::on_item_clicked), b) );
692 b->set_position(x,y);
693 work_place->put(*b, x, y);
695 // los agrego al hash
699 void Principal::loadExclusa(xmlNodePtr nodo)
701 Glib::ustring name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
702 int orientacion=0, x, y;
704 nodo = nodo->children;
705 while (nodo != NULL) {
706 if (nodo->type == XML_ELEMENT_NODE) {
707 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
708 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
709 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
710 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
711 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
712 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
718 // listo, ya recolecte todos los datos, ahora creo el objeto!
719 ViewExclusa *b = new ViewExclusa(name, orientacion);
720 b->signal_button_press_event().connect(SigC::bind( SigC::slot(*this, &Principal::on_item_clicked), b) );
721 b->set_position(x,y);
722 work_place->put(*b, x, y);
724 // los agrego al hash
728 void Principal::loadTank(xmlNodePtr nodo)
730 Glib::ustring name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
731 int orientacion=0, x, y;
733 nodo = nodo->children;
734 while (nodo != NULL) {
735 if (nodo->type == XML_ELEMENT_NODE) {
736 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
737 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
738 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
739 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
740 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
741 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
747 // listo, ya recolecte todos los datos, ahora creo el objeto!
748 ViewTank *b = new ViewTank(name, orientacion);
749 b->signal_button_press_event().connect(SigC::bind( SigC::slot(*this, &Principal::on_item_clicked), b) );
750 b->set_position(x,y);
751 work_place->put(*b, x, y);
753 // los agrego al hash
757 void Principal::loadUnion(xmlNodePtr nodo)
759 Glib::ustring name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
760 int orientacion=0, x, y;
762 nodo = nodo->children;
763 while (nodo != NULL) {
764 if (nodo->type == XML_ELEMENT_NODE) {
765 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
766 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
767 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
768 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
769 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
770 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
776 // listo, ya recolecte todos los datos, ahora creo el objeto!
777 ViewUnion *b = new ViewUnion(name, orientacion);
778 b->signal_button_release_event().connect(SigC::bind( SigC::slot(*this, &Principal::on_item_clicked), b) );
779 b->set_position(x,y);
780 work_place->put(*b, x, y);
782 // los agrego al hash
786 void Principal::loadDrain(xmlNodePtr nodo)
788 Glib::ustring name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
789 int orientacion=0, x, y;
791 nodo = nodo->children;
792 while (nodo != NULL) {
793 if (nodo->type == XML_ELEMENT_NODE) {
794 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
795 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
796 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
797 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
798 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
799 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
805 // listo, ya recolecte todos los datos, ahora creo el objeto!
806 ViewDrain *b = new ViewDrain(name, orientacion);
807 b->signal_button_release_event().connect(SigC::bind( SigC::slot(*this, &Principal::on_item_clicked), b) );
808 b->set_position(x,y);
809 work_place->put(*b, x, y);
811 // los agrego al hash
815 void Principal::read_status_xml(const std::string &_frame)
817 std::string item_name;
818 std::string frame = _frame;
821 // Cambio las , por . para evitar problemas de convercion
822 for(int i=0; i<frame.size(); i++) {
823 if (frame[i] == ',') {
827 document = xmlParseMemory(frame.c_str(),frame.size());
828 if (document == NULL) {
829 txt_view->get_buffer()->insert(txt_view->get_buffer()->begin(), "ERROR : No se pudo leer el último frame!\n");
833 xmlNodePtr nodo, items, props;
834 nodo = document->children;
838 if (strcmp((char *)nodo->name, "plantstatus") == 0) {
839 items = nodo->children;
840 while (items != NULL) {
841 if (items->type == XML_ELEMENT_NODE) {
844 if (xmlStrcmp(items->name, BAD_CAST"float")==0) {
845 tmp = get_float_from_xml(items->children);
846 item_name = (char *)xmlGetProp(items, BAD_CAST"name");
847 std::cout << item_name << " " << tmp << std::endl;
848 mapItems[item_name]->set_actual_flow(tmp);
849 } else if (xmlStrcmp(items->name, BAD_CAST"exclusa")==0) {
850 tmp_b = get_bool_from_xml(items->children);
851 item_name = (char *)xmlGetProp(items, BAD_CAST"name");
852 mapItems[item_name]->set_open(tmp_b);
853 } else if (xmlStrcmp(items->name, BAD_CAST"pump")==0) {
854 tmp_b = get_bool_from_xml(items->children);
855 item_name = (char *)xmlGetProp(items, BAD_CAST"name");
856 mapItems[item_name]->set_open(tmp_b);
857 } else if (xmlStrcmp(items->name, BAD_CAST"logic")==0) {
858 tmp_b = get_bool_from_xml(items->children);
859 item_name = (char *)xmlGetProp(items, BAD_CAST"name");
860 mapItems[item_name]->set_open(tmp_b);
861 } else if (xmlStrcmp(items->name, BAD_CAST"color")==0) {
862 item_name = (char *)xmlGetProp(items, BAD_CAST"name");
863 mapItems[item_name]->set_color( get_rgb_from_xml(items->children) );
864 } else if (xmlStrcmp(items->name, BAD_CAST"tank")==0) {
865 xmlNodePtr nodo_tmp = items->children;
869 while (nodo_tmp != NULL) {
870 if (nodo_tmp->type == XML_ELEMENT_NODE) {
871 if (xmlStrcmp(nodo_tmp->name, BAD_CAST"capacity")==0)
872 cap = atof( (char *)XML_GET_CONTENT(nodo_tmp->children) );
873 else if (xmlStrcmp(nodo_tmp->name, BAD_CAST"litros")==0)
874 lit= atof( (char *)XML_GET_CONTENT(nodo_tmp->children) );
875 else if (xmlStrcmp(nodo_tmp->name, BAD_CAST"salida")==0) {
876 if (xmlStrcmp(xmlGetProp(items, BAD_CAST"id"), BAD_CAST"inferior")==0) {
877 b_inf = get_bool_from_xml(nodo_tmp->children);
879 b_sup = get_bool_from_xml(nodo_tmp->children);
883 nodo_tmp = nodo_tmp->next;
885 item_name = (char *)xmlGetProp(items, BAD_CAST"name");
886 mapItems[item_name]->set_actual_flow(cap);
887 mapItems[item_name]->set_extra(lit);
888 dynamic_cast<ViewTank *>(mapItems[item_name])->set_out_sup(b_sup);
889 dynamic_cast<ViewTank *>(mapItems[item_name])->set_out_inf(b_inf);
895 xmlFreeDoc(document);
901 Gdk::Color Principal::get_rgb_from_xml(xmlNodePtr nodo)
904 while (nodo != NULL) {
905 if (nodo->type == XML_ELEMENT_NODE) {
906 if (xmlStrcmp(nodo->name, BAD_CAST"r")==0)
907 r = atoi( (char *)XML_GET_CONTENT(nodo->children) );
908 if (xmlStrcmp(nodo->name, BAD_CAST"g")==0)
909 g = atoi( (char *)XML_GET_CONTENT(nodo->children) );
910 if (xmlStrcmp(nodo->name, BAD_CAST"b")==0)
911 b = atoi( (char *)XML_GET_CONTENT(nodo->children) );
915 r = static_cast<gushort>(65535 * (r / 255.0f));
916 g = static_cast<gushort>(65535 * (g / 255.0f));
917 b = static_cast<gushort>(65535 * (b / 255.0f));
924 float Principal::get_float_from_xml(xmlNodePtr nodo)
928 while (nodo != NULL) {
929 if (nodo->type == XML_ELEMENT_NODE) {
930 if (xmlStrcmp(nodo->name, BAD_CAST"actual_flow")==0) {
931 s = (char *)XML_GET_CONTENT(nodo->children);
937 std::stringstream ss;
940 if (tmp == INFINITO) tmp = 0;
945 bool Principal::get_bool_from_xml(xmlNodePtr nodo)
948 while (nodo != NULL) {
949 if (nodo->type == XML_ELEMENT_NODE) {
950 if (xmlStrcmp(nodo->name, BAD_CAST"active")==0) {
951 tmp = (char *)XML_GET_CONTENT(nodo->children);
957 return tmp == "true";
960 void Principal::on_mnu_property()
962 dlg_property->show();
965 void Principal::on_dlg_property_ok()
968 PlaQui::Server::Command c("plant", "set_frequency");
969 c.add_arg("default");
970 c.add_arg( dlg_property->get_velocity() );
974 dlg_property->hide();
977 void Principal::on_btn_simulate_clicked()
979 if (conexion == NULL) return;
981 PlaQui::Server::Command c("plant", "start");
982 c.add_arg("default");
987 void Principal::on_btn_pause_clicked()
989 if (conexion == NULL) return;
991 PlaQui::Server::Command c("plant", "stop");
992 c.add_arg("default");