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 ";
56 lbl_plaqui_version->set_text(Glib::locale_to_utf8(s));
58 rg->get_widget("anim_frames", anim);
59 anim->set(anim_frames[current_frame]);
61 rg->get_widget("close_about", close_about);
62 rg->get_widget("dlgAbout", dlg_about);
63 rg->get_widget("mnu_pausar", mnu_pausar);
64 rg->get_widget("btn_pausa", btn_pause);
65 rg->get_widget("mnu_simular", mnu_simular);
66 rg->get_widget("btn_simular", btn_simulate);
67 rg->get_widget("btn_activar", btn_activar);
68 rg->get_widget("color_preview", color_preview);
69 rg->get_widget("lbl_nombre", lbl_nombre);
70 rg->get_widget("lbl_extra", lbl_extra);
71 rg->get_widget("lbl_cap_extra", lbl_cap_extra);
72 rg->get_widget("lbl_cap_flujo", lbl_cap_flujo);
73 rg->get_widget("lbl_flujo", lbl_flujo);
74 rg->get_widget("mnu_file_connect", conect);
75 rg->get_widget("mnu_file_disconnect", mnu_disconnect);
76 rg->get_widget("mnu_file_exit", exit);
77 rg->get_widget("mnu_help_about", about);
78 rg->get_widget("mnu_server_stop", server_stop);
79 rg->get_widget("mnu_prop", mnu_prop);
80 rg->get_widget_derived("dlg_property", dlg_property);
81 rg->get_widget_derived("dlgConectar", dlg_conectar);
82 rg->get_widget("txt_view", txt_view);
83 rg->get_widget("bar_connect", bar_connect);
84 rg->get_widget("work_place", work_place);
85 rg->get_widget("ico_conected", ico_conected);
87 work_place->signal_expose_event().connect( SigC::slot(*this, &Principal::on_workplace_expose_event) );
88 dlg_property->get_ok_button()->signal_clicked().connect( SigC::slot(*this, &Principal::on_dlg_property_ok) );
89 dlg_conectar->get_ok_button()->signal_clicked().connect( SigC::slot(*this, &Principal::on_dlg_connect_ok) );
90 mnu_prop->signal_activate().connect( SigC::slot(*this, &Principal::on_mnu_property));
91 mnu_disconnect->signal_activate().connect( SigC::slot(*this, &Principal::on_mnu_file_disconnect));
92 server_stop->signal_activate().connect( SigC::slot(*this, &Principal::on_mnu_server_stop_activate));
93 conect->signal_activate().connect( SigC::slot(*this, &Principal::on_mnu_file_connect));
94 bar_connect->signal_clicked().connect( SigC::slot(*this, &Principal::on_mnu_file_connect));
95 exit->signal_activate().connect( SigC::slot(*this, &Principal::on_mnu_file_exit));
96 about->signal_activate().connect( SigC::slot(*this, &Principal::on_mnu_help_about));
97 btn_activar->signal_clicked().connect( SigC::slot(*this, &Principal::on_btn_activar_clicked) );
98 mnu_simular->signal_activate().connect( SigC::slot(*this, &Principal::on_btn_simulate_clicked) );
99 btn_simulate->signal_clicked().connect( SigC::slot(*this, &Principal::on_btn_simulate_clicked) );
100 mnu_pausar->signal_activate().connect( SigC::slot(*this, &Principal::on_btn_pause_clicked) );
101 btn_pause->signal_clicked().connect( SigC::slot(*this, &Principal::on_btn_pause_clicked) );
102 close_about->signal_clicked().connect( SigC::slot(*dlg_about, &Gtk::Widget::hide) );
105 is_xml_loaded = false;
106 last_selected = NULL;
108 update_ui.connect( SigC::slot(*this, &Principal::update_items_prop ) );
109 load_xml_dispatch.connect( SigC::slot(*this, &Principal::loadXML ) );
110 gc = Gdk::GC::create(get_window());
111 color_low = Gdk::Color("blue");
112 color_high = Gdk::Color("red");
113 Gtk::Widget::get_default_colormap()->alloc_color(color_low);
114 Gtk::Widget::get_default_colormap()->alloc_color(color_high);
115 txt_view->set_editable(false);
118 Principal::~Principal()
122 void Principal::on_realize()
124 Gtk::Window::on_realize();
127 bool Principal::on_workplace_expose_event(GdkEventExpose *e)
129 Glib::RefPtr<Gdk::Window> window = work_place->get_window();
133 std::map<const std::string, ViewItem *>::iterator i;
134 for(i=mapItems.begin(); i!=mapItems.end(); i++) {
135 if (dynamic_cast<ViewAnd *>(i->second) || dynamic_cast<ViewOr *>(i->second) || dynamic_cast<ViewNot *>(i->second)) {
136 x1 = i->second->x + i->second->in_x;
137 y1 = i->second->y + i->second->in_y;
138 std::list<t_Linea>::iterator linea;
139 for(linea=i->second->in_lines.begin(); linea!=i->second->in_lines.end(); linea++) {
140 ViewItem *tmp = find_item(linea->dst);
141 /* Si este item es un tanque */
142 if (linea->is_tank) {
143 if (linea->is_tank_lower) {
144 x2 = tmp->x + tmp->out_x;
145 y2 = tmp->y + tmp->out_y;
146 if (dynamic_cast<ViewTank *>(tmp)->get_out_inf()) {
147 gc->set_foreground(color_high);
149 gc->set_foreground(color_low);
152 x2 = tmp->x + tmp->in_x;
153 y2 = tmp->y + tmp->in_y;
154 if (dynamic_cast<ViewTank *>(tmp)->get_out_sup()) {
155 gc->set_foreground(color_high);
157 gc->set_foreground(color_low);
161 x2 = tmp->x + tmp->out_x;
162 y2 = tmp->y + tmp->out_y;
163 if (tmp->get_open()) {
164 gc->set_foreground(color_high);
166 gc->set_foreground(color_low);
169 gc->set_line_attributes(3, Gdk::LINE_SOLID, Gdk::CAP_NOT_LAST, Gdk::JOIN_MITER);
170 window->draw_line(gc, x2+tmp->item_offset_x, y2+tmp->item_offset_y, x2+tmp->item_offset_x, y1+i->second->offset_y);
171 window->draw_line(gc, x2+tmp->item_offset_x, y1+i->second->offset_y, x1+i->second->offset_x, y1+i->second->offset_y);
172 window->draw_line(gc, x1, y1, x1+i->second->offset_x, y1+i->second->offset_y);
173 window->draw_line(gc, x2, y2, x2+tmp->item_offset_x, y2+tmp->item_offset_y);
175 x1 = i->second->x + i->second->out_x;
176 y1 = i->second->y + i->second->out_y;
177 for(linea=i->second->out_lines.begin(); linea!=i->second->out_lines.end(); linea++) {
178 ViewItem *tmp = find_item(linea->dst);
179 x2 = tmp->x + tmp->in_x;
180 y2 = tmp->y + tmp->in_y;
181 if (i->second->get_open()) {
182 gc->set_foreground(color_high);
184 gc->set_foreground(color_low);
186 gc->set_line_attributes(3, Gdk::LINE_SOLID, Gdk::CAP_NOT_LAST, Gdk::JOIN_MITER);
187 window->draw_line(gc, x1+i->second->offset_x, y1+i->second->offset_y, x1+i->second->offset_x, y2+tmp->item_offset_y);
188 window->draw_line(gc, x1+i->second->offset_x, y2+tmp->item_offset_y, x2+tmp->item_offset_x, y2+tmp->item_offset_y);
189 window->draw_line(gc, x1, y1, x1+i->second->offset_x, y1+i->second->offset_y);
190 window->draw_line(gc, x2, y2, x2+tmp->item_offset_x, y2+tmp->item_offset_y);
196 ViewItem *Principal::find_item(std::string &_name)
198 std::map<const std::string, ViewItem *>::iterator i;
199 for(i=mapItems.begin(); i!=mapItems.end(); i++) {
200 if (i->second->get_name() == _name) {
207 void Principal::on_dlg_connect_ok()
209 if (conexion == NULL) {
212 conexion = new PlaQui::Server::ControlClient(dlg_conectar->get_server_name(), dlg_conectar->get_server_port());
215 txt_view->get_buffer()->insert(txt_view->get_buffer()->begin(), "NO SE PUDO CONECTAR\n");
216 //delete conexion; XXX Si no me equivoco, si falla el
217 //constructor, no se reserva la memoria (el delete no va).
220 dlg_conectar->hide();
224 // Conecto las señales
225 conexion->signal_ok_received().connect( SigC::slot(*this, &Principal::on_conexion_ok) );
226 conexion->signal_error().connect( SigC::slot(*this, &Principal::on_conexion_fatal_error) );
227 conexion->signal_error_received().connect( SigC::slot(*this, &Principal::on_conexion_error) );
228 conexion->signal_finished().connect( SigC::slot(*this, &Principal::on_conexion_finished) );
229 conexion->signal_frame_received().connect(SigC::slot(*this, &Principal::on_conexion_frame));
230 // Lanzo la conexion!
232 txt_view->get_buffer()->insert(txt_view->get_buffer()->begin(),"CONNECTED\n");
233 ico_conected->set( Gtk::Stock::YES , Gtk::IconSize(Gtk::ICON_SIZE_LARGE_TOOLBAR));
235 // Pido la planta por defecto
236 PlaQui::Server::Command c("plant", "get");
237 c.add_arg("default");
240 dlg_conectar->hide();
243 void Principal::on_mnu_file_exit()
245 on_mnu_file_disconnect();
249 // Espera a que termine realmente.
251 Glib::usleep(100000); // 0,1 segundo
256 bool Principal::on_delete_event(GdkEventAny *e)
262 void Principal::on_mnu_server_stop_activate()
264 if (conexion == NULL) return;
266 PlaQui::Server::Command c("server", "stop");
270 void Principal::on_btn_activar_clicked()
272 if ((conexion == NULL) || (last_selected == NULL)) return;
274 PlaQui::Server::Command c("plant", "set");
275 c.add_arg("default");
276 c.add_arg(last_selected->get_name());
279 if (last_selected->get_open())
287 void Principal::on_mnu_file_disconnect()
289 if (conexion == NULL) return;
291 PlaQui::Server::Command c("transmission", "stop");
292 c.add_arg(conexion->get_host());
295 PlaQui::Server::Command c2("connection", "stop");
296 c2.add_arg(conexion->get_host());
297 c2.add_arg(conexion->get_port());
301 void Principal::on_mnu_file_connect()
303 dlg_conectar->show();
306 void Principal::on_mnu_help_about()
311 bool Principal::on_item_clicked(GdkEventButton *e, ViewItem *i)
314 s = "Selecciono "+i->get_name()+"\n";
315 txt_view->get_buffer()->insert(txt_view->get_buffer()->begin(), s);
321 void Principal::update_items_prop()
323 if (last_selected != NULL) {
324 lbl_nombre->set_text(last_selected->get_name());
325 lbl_flujo->set_text(last_selected->get_actual_flow());
326 lbl_extra->set_text(last_selected->get_extra());
328 lbl_cap_flujo->set_text(last_selected->get_cap_flow());
329 lbl_cap_extra->set_text(last_selected->get_cap_extra());
331 color_preview->modify_bg(Gtk::STATE_NORMAL, last_selected->get_color());
332 color_preview->queue_draw();
337 if (current_frame > 7) {
340 anim->set(anim_frames[current_frame]);
343 // Mando a redibujar a todos los items
344 std::map<const std::string, ViewItem *>::iterator i;
345 for(i=mapItems.begin(); i!=mapItems.end(); i++) {
346 i->second->queue_draw();
348 work_place->queue_draw();
351 void Principal::on_conexion_frame(const std::string &frame)
353 if (conexion != NULL) {
354 read_status_xml(frame);
358 void Principal::on_conexion_finished()
360 txt_view->get_buffer()->insert(txt_view->get_buffer()->begin(),"HANG UP\n");
361 ico_conected->set( Gtk::Stock::NO , Gtk::IconSize(Gtk::ICON_SIZE_LARGE_TOOLBAR));
364 std::map<const std::string, ViewItem *>::iterator i;
365 for(i=mapItems.begin(); i!=mapItems.end(); i++) {
369 is_xml_loaded = false;
372 void Principal::on_conexion_ok(const std::string &body)
374 /* lo paso a la carga del XML */
375 /* verifico que body este completo */
376 if ((body.find("</planta>")>0) && (body.find("<planta>")>0)) {
381 s = "<IN>\n"+Glib::locale_to_utf8(body)+"\n</IN>\n";
382 txt_view->get_buffer()->insert(txt_view->get_buffer()->begin(),s);
386 void Principal::on_conexion_fatal_error(const PlaQui::Server::ControlClient::Error& code, const std::string& desc)
393 st = "Error de red nro. "+s+": "+desc+"\n";
394 txt_view->get_buffer()->insert(txt_view->get_buffer()->begin(),st);
397 void Principal::on_conexion_error(unsigned code, const std::string& desc)
404 st = "El server dice que hay error nro. "+s+": "+desc+"\n";
405 txt_view->get_buffer()->insert(txt_view->get_buffer()->begin(),st);
408 void Principal::loadXML()
411 if (is_xml_loaded) return;
413 /* Parseo de ejemplo de un XML desde archivo */
415 document = xmlParseMemory(xml_body.c_str(),xml_body.size());
416 if (document == NULL) {
417 txt_view->get_buffer()->insert(txt_view->get_buffer()->begin(),"No se pudo cargar XML enviado por el servidor.");
418 is_xml_loaded = false;
421 is_xml_loaded = true;
422 /* bien, el archivo se parseo bien! */
423 xmlNodePtr nodo, items;
424 nodo = document->children;
426 if (strcmp((char *)nodo->name, "planta") == 0) {
427 items = nodo->children;
428 while (items != NULL) {
429 if (items->type == XML_ELEMENT_NODE) {
430 if (xmlStrcmp(items->name, BAD_CAST"bomba")==0) {
432 } else if (xmlStrcmp(items->name, BAD_CAST"codo")==0) {
434 } else if (xmlStrcmp(items->name, BAD_CAST"tubo")==0) {
436 } else if (xmlStrcmp(items->name, BAD_CAST"exclusa")==0) {
438 } else if (xmlStrcmp(items->name, BAD_CAST"tanque")==0) {
440 } else if (xmlStrcmp(items->name, BAD_CAST"empalme")==0) {
442 } else if (xmlStrcmp(items->name, BAD_CAST"drenaje")==0) {
444 } else if (xmlStrcmp(items->name, BAD_CAST"and")==0) {
446 } else if (xmlStrcmp(items->name, BAD_CAST"or")==0) {
448 } else if (xmlStrcmp(items->name, BAD_CAST"not")==0) {
457 xmlFreeDoc(document);
459 // Ya cargado el XML, mando un msg para empezar a recibir los frames!
460 PlaQui::Server::Command c("transmission", "start");
461 c.add_arg("default");
462 c.add_arg(conexion->get_host());
467 void Principal::loadNot(xmlNodePtr nodo)
469 std::string name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
470 std::string id = (char *)xmlGetProp(nodo, BAD_CAST"id");
471 int orientacion=0, x, y;
475 nodo = nodo->children;
476 while (nodo != NULL) {
477 if (nodo->type == XML_ELEMENT_NODE) {
478 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
479 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
480 p = new ViewNot(name, orientacion);
481 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
482 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
483 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
484 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
485 } else if (xmlStrcmp(nodo->name, BAD_CAST"salida") == 0) {
486 linea.dst = (char *)XML_GET_CONTENT(nodo->children);
487 p->out_lines.push_back(linea);
488 } else if (xmlStrcmp(nodo->name, BAD_CAST"entrada") == 0) {
489 linea.dst = (char *)XML_GET_CONTENT(nodo->children);
490 linea.is_tank = false;
491 if (dynamic_cast<ViewTank *>(find_item(linea.dst)) != NULL) {
492 linea.is_tank = true;
493 linea.is_tank_lower = false;
494 if (xmlStrcmp(xmlGetProp(nodo, BAD_CAST"id"), BAD_CAST"inferior")==0)
495 linea.is_tank_lower = true;
497 p->in_lines.push_back(linea);
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::loadOr(xmlNodePtr nodo)
513 std::string name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
514 std::string id = (char *)xmlGetProp(nodo, BAD_CAST"id");
515 int orientacion=0, x, y;
520 nodo = nodo->children;
521 while (nodo != NULL) {
522 if (nodo->type == XML_ELEMENT_NODE) {
523 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
524 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
525 p = new ViewOr(name, orientacion);
526 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
527 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
528 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
529 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
530 } else if (xmlStrcmp(nodo->name, BAD_CAST"salida") == 0) {
531 linea.dst = (char *)XML_GET_CONTENT(nodo->children);
532 p->out_lines.push_back(linea);
533 } else if (xmlStrcmp(nodo->name, BAD_CAST"entrada") == 0) {
534 linea.dst = (char *)XML_GET_CONTENT(nodo->children);
535 linea.is_tank = false;
536 if (dynamic_cast<ViewTank *>(find_item(linea.dst)) != NULL) {
537 linea.is_tank = true;
538 linea.is_tank_lower = false;
539 if (xmlStrcmp(xmlGetProp(nodo, BAD_CAST"id"), BAD_CAST"inferior")==0)
540 linea.is_tank_lower = true;
542 p->in_lines.push_back(linea);
548 p->signal_button_press_event().connect(SigC::bind( SigC::slot(*this, &Principal::on_item_clicked), p) );
549 p->set_position(x,y);
550 work_place->put(*p, x, y);
552 // los agrego al hash
556 void Principal::loadAnd(xmlNodePtr nodo)
558 std::string name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
559 std::string id = (char *)xmlGetProp(nodo, BAD_CAST"id");
560 int orientacion=0, x, y;
562 xmlNodePtr inicial = nodo;
566 nodo = nodo->children;
567 while (nodo != NULL) {
568 if (nodo->type == XML_ELEMENT_NODE) {
569 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
570 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
571 p = new ViewAnd(name, orientacion);
572 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
573 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
574 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
575 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
576 } else if (xmlStrcmp(nodo->name, BAD_CAST"salida") == 0) {
577 linea.dst = (char *)XML_GET_CONTENT(nodo->children);
578 p->out_lines.push_back(linea);
579 } else if (xmlStrcmp(nodo->name, BAD_CAST"entrada") == 0) {
580 linea.dst = (char *)XML_GET_CONTENT(nodo->children);
581 linea.is_tank = false;
582 if (dynamic_cast<ViewTank *>(find_item(linea.dst)) != NULL) {
583 linea.is_tank = true;
584 linea.is_tank_lower = false;
585 if (xmlStrcmp(xmlGetProp(nodo, BAD_CAST"id"), BAD_CAST"inferior")==0)
586 linea.is_tank_lower = true;
588 p->in_lines.push_back(linea);
594 p->signal_button_press_event().connect(SigC::bind( SigC::slot(*this, &Principal::on_item_clicked), p) );
595 p->set_position(x,y);
596 work_place->put(*p, x, y);
598 // los agrego al hash
602 void Principal::loadBomba(xmlNodePtr nodo)
604 Glib::ustring name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
605 int orientacion=0, x, y;
607 nodo = nodo->children;
608 while (nodo != NULL) {
609 if (nodo->type == XML_ELEMENT_NODE) {
610 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
611 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
612 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
613 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
614 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
615 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
621 // listo, ya recolecte todos los datos, ahora creo el objeto!
622 ViewPump *b = new ViewPump(name, orientacion);
623 b->signal_button_press_event().connect(SigC::bind( SigC::slot(*this, &Principal::on_item_clicked), b) );
624 b->set_position(x,y);
625 work_place->put(*b, x, y);
627 // los agrego al hash
631 void Principal::loadCodo(xmlNodePtr nodo)
633 std::string name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
634 int orientacion=0, x, y;
636 nodo = nodo->children;
637 while (nodo != NULL) {
638 if (nodo->type == XML_ELEMENT_NODE) {
639 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
640 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
641 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
642 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
643 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
644 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
650 // listo, ya recolecte todos los datos, ahora creo el objeto!
651 ViewItem *b = new ViewCodo(name, orientacion);
652 b->signal_button_press_event().connect(SigC::bind( SigC::slot(*this, &Principal::on_item_clicked), b) );
653 b->set_position(x,y);
654 work_place->put(*b, x, y);
656 // los agrego al hash
660 void Principal::loadConduct(xmlNodePtr nodo)
662 Glib::ustring name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
663 int orientacion=0, x, y;
665 nodo = nodo->children;
666 while (nodo != NULL) {
667 if (nodo->type == XML_ELEMENT_NODE) {
668 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
669 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
670 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
671 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
672 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
673 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
679 // listo, ya recolecte todos los datos, ahora creo el objeto!
680 ViewConduct *b = new ViewConduct(name, orientacion);
681 b->signal_button_press_event().connect(SigC::bind( SigC::slot(*this, &Principal::on_item_clicked), b) );
682 b->set_position(x,y);
683 work_place->put(*b, x, y);
685 // los agrego al hash
689 void Principal::loadExclusa(xmlNodePtr nodo)
691 Glib::ustring name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
692 int orientacion=0, x, y;
694 nodo = nodo->children;
695 while (nodo != NULL) {
696 if (nodo->type == XML_ELEMENT_NODE) {
697 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
698 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
699 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
700 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
701 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
702 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
708 // listo, ya recolecte todos los datos, ahora creo el objeto!
709 ViewExclusa *b = new ViewExclusa(name, orientacion);
710 b->signal_button_press_event().connect(SigC::bind( SigC::slot(*this, &Principal::on_item_clicked), b) );
711 b->set_position(x,y);
712 work_place->put(*b, x, y);
714 // los agrego al hash
718 void Principal::loadTank(xmlNodePtr nodo)
720 Glib::ustring name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
721 int orientacion=0, x, y;
723 nodo = nodo->children;
724 while (nodo != NULL) {
725 if (nodo->type == XML_ELEMENT_NODE) {
726 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
727 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
728 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
729 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
730 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
731 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
737 // listo, ya recolecte todos los datos, ahora creo el objeto!
738 ViewTank *b = new ViewTank(name, orientacion);
739 b->signal_button_press_event().connect(SigC::bind( SigC::slot(*this, &Principal::on_item_clicked), b) );
740 b->set_position(x,y);
741 work_place->put(*b, x, y);
743 // los agrego al hash
747 void Principal::loadUnion(xmlNodePtr nodo)
749 Glib::ustring name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
750 int orientacion=0, x, y;
752 nodo = nodo->children;
753 while (nodo != NULL) {
754 if (nodo->type == XML_ELEMENT_NODE) {
755 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
756 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
757 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
758 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
759 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
760 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
766 // listo, ya recolecte todos los datos, ahora creo el objeto!
767 ViewUnion *b = new ViewUnion(name, orientacion);
768 b->signal_button_release_event().connect(SigC::bind( SigC::slot(*this, &Principal::on_item_clicked), b) );
769 b->set_position(x,y);
770 work_place->put(*b, x, y);
772 // los agrego al hash
776 void Principal::loadDrain(xmlNodePtr nodo)
778 Glib::ustring name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
779 int orientacion=0, x, y;
781 nodo = nodo->children;
782 while (nodo != NULL) {
783 if (nodo->type == XML_ELEMENT_NODE) {
784 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
785 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
786 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
787 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
788 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
789 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
795 // listo, ya recolecte todos los datos, ahora creo el objeto!
796 ViewDrain *b = new ViewDrain(name, orientacion);
797 b->signal_button_release_event().connect(SigC::bind( SigC::slot(*this, &Principal::on_item_clicked), b) );
798 b->set_position(x,y);
799 work_place->put(*b, x, y);
801 // los agrego al hash
805 void Principal::read_status_xml(const std::string &frame)
807 std::string item_name;
809 document = xmlParseMemory(frame.c_str(),frame.size());
810 if (document == NULL) {
811 txt_view->get_buffer()->insert(txt_view->get_buffer()->begin(), "ERROR : No se pudo leer el último frame!\n");
815 xmlNodePtr nodo, items, props;
816 nodo = document->children;
820 if (strcmp((char *)nodo->name, "plantstatus") == 0) {
821 items = nodo->children;
822 while (items != NULL) {
823 if (items->type == XML_ELEMENT_NODE) {
826 if (xmlStrcmp(items->name, BAD_CAST"float")==0) {
827 tmp = get_float_from_xml(items->children);
828 item_name = (char *)xmlGetProp(items, BAD_CAST"name");
829 mapItems[item_name]->set_actual_flow(tmp);
830 } else if (xmlStrcmp(items->name, BAD_CAST"exclusa")==0) {
831 tmp_b = get_bool_from_xml(items->children);
832 item_name = (char *)xmlGetProp(items, BAD_CAST"name");
833 mapItems[item_name]->set_open(tmp_b);
834 } else if (xmlStrcmp(items->name, BAD_CAST"pump")==0) {
835 tmp_b = get_bool_from_xml(items->children);
836 item_name = (char *)xmlGetProp(items, BAD_CAST"name");
837 mapItems[item_name]->set_open(tmp_b);
838 } else if (xmlStrcmp(items->name, BAD_CAST"logic")==0) {
839 tmp_b = get_bool_from_xml(items->children);
840 item_name = (char *)xmlGetProp(items, BAD_CAST"name");
841 mapItems[item_name]->set_open(tmp_b);
842 } else if (xmlStrcmp(items->name, BAD_CAST"color")==0) {
843 item_name = (char *)xmlGetProp(items, BAD_CAST"name");
844 mapItems[item_name]->set_color( get_rgb_from_xml(items->children) );
845 } else if (xmlStrcmp(items->name, BAD_CAST"tank")==0) {
846 xmlNodePtr nodo_tmp = items->children;
850 while (nodo_tmp != NULL) {
851 if (nodo_tmp->type == XML_ELEMENT_NODE) {
852 if (xmlStrcmp(nodo_tmp->name, BAD_CAST"capacity")==0)
853 cap = atof( (char *)XML_GET_CONTENT(nodo_tmp->children) );
854 else if (xmlStrcmp(nodo_tmp->name, BAD_CAST"litros")==0)
855 lit= atof( (char *)XML_GET_CONTENT(nodo_tmp->children) );
856 else if (xmlStrcmp(nodo_tmp->name, BAD_CAST"salida")==0) {
857 if (xmlStrcmp(xmlGetProp(items, BAD_CAST"id"), BAD_CAST"inferior")==0) {
858 b_inf = get_bool_from_xml(nodo_tmp->children);
860 b_sup = get_bool_from_xml(nodo_tmp->children);
864 nodo_tmp = nodo_tmp->next;
866 item_name = (char *)xmlGetProp(items, BAD_CAST"name");
867 mapItems[item_name]->set_actual_flow(cap);
868 mapItems[item_name]->set_extra(lit);
869 dynamic_cast<ViewTank *>(mapItems[item_name])->set_out_sup(b_sup);
870 dynamic_cast<ViewTank *>(mapItems[item_name])->set_out_inf(b_inf);
876 xmlFreeDoc(document);
882 Gdk::Color Principal::get_rgb_from_xml(xmlNodePtr nodo)
885 while (nodo != NULL) {
886 if (nodo->type == XML_ELEMENT_NODE) {
887 if (xmlStrcmp(nodo->name, BAD_CAST"r")==0)
888 r = atoi( (char *)XML_GET_CONTENT(nodo->children) );
889 if (xmlStrcmp(nodo->name, BAD_CAST"g")==0)
890 g = atoi( (char *)XML_GET_CONTENT(nodo->children) );
891 if (xmlStrcmp(nodo->name, BAD_CAST"b")==0)
892 b = atoi( (char *)XML_GET_CONTENT(nodo->children) );
896 r = static_cast<gushort>(65535 * (r / 255.0f));
897 g = static_cast<gushort>(65535 * (g / 255.0f));
898 b = static_cast<gushort>(65535 * (b / 255.0f));
905 float Principal::get_float_from_xml(xmlNodePtr nodo)
908 while (nodo != NULL) {
909 if (nodo->type == XML_ELEMENT_NODE) {
910 if (xmlStrcmp(nodo->name, BAD_CAST"actual_flow")==0) {
911 tmp = atof( (char *)XML_GET_CONTENT(nodo->children) );
917 if (tmp == INFINITO) tmp = 0;
921 bool Principal::get_bool_from_xml(xmlNodePtr nodo)
924 while (nodo != NULL) {
925 if (nodo->type == XML_ELEMENT_NODE) {
926 if (xmlStrcmp(nodo->name, BAD_CAST"active")==0) {
927 tmp = (char *)XML_GET_CONTENT(nodo->children);
933 return tmp == "true";
936 void Principal::on_mnu_property()
938 dlg_property->show();
941 void Principal::on_dlg_property_ok()
944 PlaQui::Server::Command c("plant", "set_frequency");
945 c.add_arg("default");
946 c.add_arg( dlg_property->get_velocity() );
950 dlg_property->hide();
953 void Principal::on_btn_simulate_clicked()
955 if (conexion == NULL) return;
957 PlaQui::Server::Command c("plant", "start");
958 c.add_arg("default");
963 void Principal::on_btn_pause_clicked()
965 if (conexion == NULL) return;
967 PlaQui::Server::Command c("plant", "stop");
968 c.add_arg("default");