+ if (!paused) {
+ current_frame++;
+ if (current_frame > 7) {
+ current_frame = 0;
+ }
+ anim->set(anim_frames[current_frame]);
+ }
+
+ // Mando a redibujar a todos los items
+ std::map<const std::string, ViewItem *>::iterator i;
+ for(i=mapItems.begin(); i!=mapItems.end(); i++) {
+ i->second->queue_draw();
+ }
+ work_place->queue_draw();
+}
+
+void Principal::on_conexion_frame(const std::string &frame)
+{
+ if (conexion != NULL) {
+ read_status_xml(frame);
+ }
+}
+
+void Principal::on_conexion_finished()
+{
+ txt_view->get_buffer()->insert(txt_view->get_buffer()->begin(),"HANG UP\n");
+ ico_conected->set( Gtk::Stock::NO , Gtk::IconSize(Gtk::ICON_SIZE_LARGE_TOOLBAR));
+ conexion = NULL;
+ // Elimino la planta
+ std::map<const std::string, ViewItem *>::iterator i;
+ for(i=mapItems.begin(); i!=mapItems.end(); i++) {
+ delete i->second;
+ }
+ mapItems.clear();
+ is_xml_loaded = false;
+}
+
+void Principal::on_conexion_ok(const std::string &body)
+{
+ /* lo paso a la carga del XML */
+ /* verifico que body este completo */
+ if ((body.find("</planta>")>0) && (body.find("<planta>")>0)) {
+ xml_body = body;
+ load_xml_dispatch();
+ } else {
+ Glib::ustring s;
+ try {
+ s = "<IN>\n"+Glib::locale_to_utf8(body)+"\n</IN>\n";
+ }
+ catch (...) {
+ s = "NO SE PUDO CONVERTIR MENSAJE A UTF8";
+ }
+ txt_view->get_buffer()->insert(txt_view->get_buffer()->begin(),s);
+ }
+}
+
+void Principal::on_conexion_fatal_error(const PlaQui::Server::ControlClient::Error& code, const std::string& desc)
+{
+ std::stringstream a;
+ std::string s;
+ a << code;
+ a >> s;
+ Glib::ustring st;
+ st = "Error de red nro. "+s+": "+desc+"\n";
+ txt_view->get_buffer()->insert(txt_view->get_buffer()->begin(),st);
+}
+
+void Principal::on_conexion_error(unsigned code, const std::string& desc)
+{
+ std::stringstream a;
+ std::string s;
+ a << code;
+ a >> s;
+ Glib::ustring st;
+ st = "El server dice que hay error nro. "+s+": "+desc+"\n";
+ txt_view->get_buffer()->insert(txt_view->get_buffer()->begin(),st);
+}
+
+void Principal::loadXML()
+{
+ // ya lo cargue
+ if (is_xml_loaded) return;
+
+ /* Parseo de ejemplo de un XML desde archivo */
+ xmlDocPtr document;
+ document = xmlParseMemory(xml_body.c_str(),xml_body.size());
+ if (document == NULL) {
+ txt_view->get_buffer()->insert(txt_view->get_buffer()->begin(),"No se pudo cargar XML enviado por el servidor.");
+ is_xml_loaded = false;
+ return;
+ }
+ is_xml_loaded = true;
+ /* bien, el archivo se parseo bien! */
+ xmlNodePtr nodo, items;
+ nodo = document->children;
+
+ if (strcmp((char *)nodo->name, "planta") == 0) {
+ items = nodo->children;
+ while (items != NULL) {
+ if (items->type == XML_ELEMENT_NODE) {
+ if (xmlStrcmp(items->name, BAD_CAST"bomba")==0) {
+ loadBomba(items);
+ } else if (xmlStrcmp(items->name, BAD_CAST"codo")==0) {
+ loadCodo(items);
+ } else if (xmlStrcmp(items->name, BAD_CAST"tubo")==0) {
+ loadConduct(items);
+ } else if (xmlStrcmp(items->name, BAD_CAST"exclusa")==0) {
+ loadExclusa(items);
+ } else if (xmlStrcmp(items->name, BAD_CAST"tanque")==0) {
+ loadTank(items);
+ } else if (xmlStrcmp(items->name, BAD_CAST"empalme")==0) {
+ loadUnion(items);
+ } else if (xmlStrcmp(items->name, BAD_CAST"drenaje")==0) {
+ loadDrain(items);
+ } else if (xmlStrcmp(items->name, BAD_CAST"and")==0) {
+ loadAnd(items);
+ } else if (xmlStrcmp(items->name, BAD_CAST"or")==0) {
+ loadOr(items);
+ } else if (xmlStrcmp(items->name, BAD_CAST"not")==0) {
+ loadNot(items);
+ }
+
+ }
+ items = items->next;
+ }
+ }
+
+ xmlFreeDoc(document);
+
+ // Ya cargado el XML, mando un msg para empezar a recibir los frames!
+ PlaQui::Server::Command c("transmission", "start");
+ c.add_arg("default");
+ c.add_arg(conexion->get_host());
+ c.add_arg("7528");
+ conexion->send(c);
+}
+
+void Principal::loadNot(xmlNodePtr nodo)
+{
+ std::string name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
+ std::string id = (char *)xmlGetProp(nodo, BAD_CAST"id");
+ int orientacion=0, x, y;
+ t_Linea linea;
+
+ ViewNot *p;
+ nodo = nodo->children;
+ while (nodo != NULL) {
+ if (nodo->type == XML_ELEMENT_NODE) {
+ if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
+ orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
+ p = new ViewNot(name, orientacion);
+ } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
+ x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
+ } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
+ y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
+ } else if (xmlStrcmp(nodo->name, BAD_CAST"salida") == 0) {
+ linea.dst = (char *)XML_GET_CONTENT(nodo->children);
+ p->out_lines.push_back(linea);
+ } else if (xmlStrcmp(nodo->name, BAD_CAST"entrada") == 0) {
+ linea.dst = (char *)XML_GET_CONTENT(nodo->children);
+ linea.is_tank = false;
+ if (dynamic_cast<ViewTank *>(find_item(linea.dst)) != NULL) {
+ linea.is_tank = true;
+ linea.is_tank_lower = false;
+ if (xmlStrcmp(xmlGetProp(nodo, BAD_CAST"id"), BAD_CAST"inferior")==0)
+ linea.is_tank_lower = true;
+ }
+ p->in_lines.push_back(linea);
+ }
+ }
+ nodo = nodo->next;
+ }
+
+ p->signal_button_press_event().connect(SigC::bind( SigC::slot(*this, &Principal::on_item_clicked), p) );
+ p->set_position(x,y);
+ work_place->put(*p, x, y);
+ p->show();
+ // los agrego al hash
+ mapItems[name] = p;
+}
+
+void Principal::loadOr(xmlNodePtr nodo)
+{
+ std::string name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
+ std::string id = (char *)xmlGetProp(nodo, BAD_CAST"id");
+ int orientacion=0, x, y;
+ t_Linea linea;
+
+ ViewOr *p;
+
+ nodo = nodo->children;
+ while (nodo != NULL) {
+ if (nodo->type == XML_ELEMENT_NODE) {
+ if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
+ orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
+ p = new ViewOr(name, orientacion);
+ } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
+ x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
+ } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
+ y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
+ } else if (xmlStrcmp(nodo->name, BAD_CAST"salida") == 0) {
+ linea.dst = (char *)XML_GET_CONTENT(nodo->children);
+ p->out_lines.push_back(linea);
+ } else if (xmlStrcmp(nodo->name, BAD_CAST"entrada") == 0) {
+ linea.dst = (char *)XML_GET_CONTENT(nodo->children);
+ linea.is_tank = false;
+ if (dynamic_cast<ViewTank *>(find_item(linea.dst)) != NULL) {
+ linea.is_tank = true;
+ linea.is_tank_lower = false;
+ if (xmlStrcmp(xmlGetProp(nodo, BAD_CAST"id"), BAD_CAST"inferior")==0)
+ linea.is_tank_lower = true;
+ }
+ p->in_lines.push_back(linea);
+ }
+ }
+ nodo = nodo->next;
+ }
+
+ p->signal_button_press_event().connect(SigC::bind( SigC::slot(*this, &Principal::on_item_clicked), p) );
+ p->set_position(x,y);
+ work_place->put(*p, x, y);
+ p->show();
+ // los agrego al hash
+ mapItems[name] = p;
+}
+
+void Principal::loadAnd(xmlNodePtr nodo)
+{
+ std::string name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
+ std::string id = (char *)xmlGetProp(nodo, BAD_CAST"id");
+ int orientacion=0, x, y;
+ float flujo;
+ xmlNodePtr inicial = nodo;
+ t_Linea linea;
+ ViewAnd *p;
+
+ nodo = nodo->children;
+ while (nodo != NULL) {
+ if (nodo->type == XML_ELEMENT_NODE) {
+ if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
+ orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
+ p = new ViewAnd(name, orientacion);
+ } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
+ x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
+ } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
+ y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
+ } else if (xmlStrcmp(nodo->name, BAD_CAST"salida") == 0) {
+ linea.dst = (char *)XML_GET_CONTENT(nodo->children);
+ p->out_lines.push_back(linea);
+ } else if (xmlStrcmp(nodo->name, BAD_CAST"entrada") == 0) {
+ linea.dst = (char *)XML_GET_CONTENT(nodo->children);
+ linea.is_tank = false;
+ if (dynamic_cast<ViewTank *>(find_item(linea.dst)) != NULL) {
+ linea.is_tank = true;
+ linea.is_tank_lower = false;
+ if (xmlStrcmp(xmlGetProp(nodo, BAD_CAST"id"), BAD_CAST"inferior")==0)
+ linea.is_tank_lower = true;
+ }
+ p->in_lines.push_back(linea);
+ }
+ }
+ nodo = nodo->next;
+ }
+
+ p->signal_button_press_event().connect(SigC::bind( SigC::slot(*this, &Principal::on_item_clicked), p) );
+ p->set_position(x,y);
+ work_place->put(*p, x, y);
+ p->show();
+ // los agrego al hash
+ mapItems[name] = p;
+}
+
+void Principal::loadBomba(xmlNodePtr nodo)
+{
+ Glib::ustring name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
+ int orientacion=0, x, y;
+
+ nodo = nodo->children;
+ while (nodo != NULL) {
+ if (nodo->type == XML_ELEMENT_NODE) {
+ if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
+ orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
+ } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
+ x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
+ } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
+ y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
+ }
+ }
+ nodo = nodo->next;
+ }
+
+ // listo, ya recolecte todos los datos, ahora creo el objeto!
+ ViewPump *b = new ViewPump(name, orientacion);
+ b->signal_button_press_event().connect(SigC::bind( SigC::slot(*this, &Principal::on_item_clicked), b) );
+ b->set_position(x,y);
+ work_place->put(*b, x, y);
+ b->show();
+ // los agrego al hash
+ mapItems[name] = b;
+}
+
+void Principal::loadCodo(xmlNodePtr nodo)
+{
+ std::string name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
+ int orientacion=0, x, y;
+
+ nodo = nodo->children;
+ while (nodo != NULL) {
+ if (nodo->type == XML_ELEMENT_NODE) {
+ if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
+ orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
+ } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
+ x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
+ } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
+ y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
+ }
+ }
+ nodo = nodo->next;
+ }
+
+ // listo, ya recolecte todos los datos, ahora creo el objeto!
+ ViewItem *b = new ViewCodo(name, orientacion);
+ b->signal_button_press_event().connect(SigC::bind( SigC::slot(*this, &Principal::on_item_clicked), b) );
+ b->set_position(x,y);
+ work_place->put(*b, x, y);
+ b->show();
+ // los agrego al hash
+ mapItems[name] = b;
+}
+
+void Principal::loadConduct(xmlNodePtr nodo)
+{
+ Glib::ustring name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
+ int orientacion=0, x, y;
+
+ nodo = nodo->children;
+ while (nodo != NULL) {
+ if (nodo->type == XML_ELEMENT_NODE) {
+ if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
+ orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
+ } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
+ x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
+ } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
+ y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
+ }
+ }
+ nodo = nodo->next;
+ }
+
+ // listo, ya recolecte todos los datos, ahora creo el objeto!
+ ViewConduct *b = new ViewConduct(name, orientacion);
+ b->signal_button_press_event().connect(SigC::bind( SigC::slot(*this, &Principal::on_item_clicked), b) );
+ b->set_position(x,y);
+ work_place->put(*b, x, y);
+ b->show();
+ // los agrego al hash
+ mapItems[name] = b;
+}
+
+void Principal::loadExclusa(xmlNodePtr nodo)
+{
+ Glib::ustring name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
+ int orientacion=0, x, y;
+
+ nodo = nodo->children;
+ while (nodo != NULL) {
+ if (nodo->type == XML_ELEMENT_NODE) {
+ if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
+ orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
+ } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
+ x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
+ } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
+ y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
+ }
+ }
+ nodo = nodo->next;
+ }
+
+ // listo, ya recolecte todos los datos, ahora creo el objeto!
+ ViewExclusa *b = new ViewExclusa(name, orientacion);
+ b->signal_button_press_event().connect(SigC::bind( SigC::slot(*this, &Principal::on_item_clicked), b) );
+ b->set_position(x,y);
+ work_place->put(*b, x, y);
+ b->show();
+ // los agrego al hash
+ mapItems[name] = b;
+}
+
+void Principal::loadTank(xmlNodePtr nodo)
+{
+ Glib::ustring name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
+ int orientacion=0, x, y;
+
+ nodo = nodo->children;
+ while (nodo != NULL) {
+ if (nodo->type == XML_ELEMENT_NODE) {
+ if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
+ orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
+ } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
+ x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
+ } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
+ y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
+ }
+ }
+ nodo = nodo->next;
+ }
+
+ // listo, ya recolecte todos los datos, ahora creo el objeto!
+ ViewTank *b = new ViewTank(name, orientacion);
+ b->signal_button_press_event().connect(SigC::bind( SigC::slot(*this, &Principal::on_item_clicked), b) );
+ b->set_position(x,y);
+ work_place->put(*b, x, y);
+ b->show();
+ // los agrego al hash
+ mapItems[name] = b;
+}
+
+void Principal::loadUnion(xmlNodePtr nodo)
+{
+ Glib::ustring name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
+ int orientacion=0, x, y;
+
+ nodo = nodo->children;
+ while (nodo != NULL) {
+ if (nodo->type == XML_ELEMENT_NODE) {
+ if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
+ orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
+ } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
+ x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
+ } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
+ y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
+ }
+ }
+ nodo = nodo->next;