1 #include "constructor.h"
3 Constructor::Constructor(BaseObjectType* cobject, const Glib::RefPtr<Gnome::Glade::Xml>& refGlade):Gtk::Window(cobject)
6 set_title("Constructor");
9 ico_canio = Gdk::Pixbuf::create_from_file(PACKAGE_DATA_DIR"/plaqui-constructor/pixmaps/canio_n.png");
10 ico_y = Gdk::Pixbuf::create_from_file(PACKAGE_DATA_DIR"/plaqui-constructor/pixmaps/y_n.png");
11 ico_codo = Gdk::Pixbuf::create_from_file(PACKAGE_DATA_DIR"/plaqui-constructor/pixmaps/codo_o.png");
12 ico_tanque = Gdk::Pixbuf::create_from_file(PACKAGE_DATA_DIR"/plaqui-constructor/pixmaps/tanque_e.png");
13 ico_exclusa = Gdk::Pixbuf::create_from_file(PACKAGE_DATA_DIR"/plaqui-constructor/pixmaps/exclusa_h.png");
14 ico_drain = Gdk::Pixbuf::create_from_file(PACKAGE_DATA_DIR"/plaqui-constructor/pixmaps/drain_n.png");
15 ico_bomba = Gdk::Pixbuf::create_from_file(PACKAGE_DATA_DIR"/plaqui-constructor/pixmaps/bomba_e.png");
16 ico_and = Gdk::Pixbuf::create_from_file(PACKAGE_DATA_DIR"/plaqui-constructor/pixmaps/and_e.png");
17 ico_or = Gdk::Pixbuf::create_from_file(PACKAGE_DATA_DIR"/plaqui-constructor/pixmaps/or_e.png");
18 ico_not = Gdk::Pixbuf::create_from_file(PACKAGE_DATA_DIR"/plaqui-constructor/pixmaps/not_e.png");
20 refGlade->get_widget("btn_canio", btn_canio);
21 refGlade->get_widget("btn_codo", btn_codo);
22 refGlade->get_widget("btn_y", btn_y);
23 refGlade->get_widget("btn_tanque",btn_tanque);
24 refGlade->get_widget("btn_bomba", btn_bomba);
25 refGlade->get_widget("btn_exclusa", btn_exclusa);
26 refGlade->get_widget("btn_drain", btn_drain);
27 refGlade->get_widget("btn_and", btn_and);
28 refGlade->get_widget("btn_or", btn_or);
29 refGlade->get_widget("btn_not", btn_not);
30 refGlade->get_widget("main_menu_quit",main_menu_quit);
31 refGlade->get_widget("main_menu_open",main_menu_open);
32 refGlade->get_widget("main_menu_save",main_menu_save);
33 refGlade->get_widget("edit_menu_del",edit_menu_del);
34 refGlade->get_widget("chk_btn_logica",chk_btn_logica);
35 refGlade->get_widget("file_open_selection",file_open_selection);
36 refGlade->get_widget("file_selection",file_selection);
37 refGlade->get_widget("combo_entry",combo_entry);
38 refGlade->get_widget("btn_check",btn_check);
39 refGlade->get_widget("dlg_connect", dlg_connect);
40 refGlade->get_widget("btn_dlg_close", btn_dlg_close);
41 refGlade->get_widget("dlg_label", dlg_label);
43 refGlade->get_widget_derived("workplace", workplace); //fixed
46 listTargets.push_back( Gtk::TargetEntry("STRING") );
47 listTargets.push_back( Gtk::TargetEntry("text/plain") );
48 listTargets.push_back( Gtk::TargetEntry("POINTER") );
49 listTargets.push_back( Gtk::TargetEntry("application/pointer") );
51 btn_canio->drag_source_set(listTargets);
52 btn_y->drag_source_set(listTargets);
53 btn_codo->drag_source_set(listTargets);
54 btn_tanque->drag_source_set(listTargets);
55 btn_bomba->drag_source_set(listTargets);
56 btn_drain->drag_source_set(listTargets);
57 btn_exclusa->drag_source_set(listTargets);
58 btn_and->drag_source_set(listTargets);
59 btn_or->drag_source_set(listTargets);
60 btn_not->drag_source_set(listTargets);
62 btn_canio->signal_drag_data_get().connect( SigC::slot(*this, &Constructor::on_btn_canio_drag_get));
63 btn_bomba->signal_drag_data_get().connect( SigC::slot(*this, &Constructor::on_btn_bomba_drag_get));
64 btn_exclusa->signal_drag_data_get().connect( SigC::slot(*this, &Constructor::on_btn_exclusa_drag_get));
65 btn_y->signal_drag_data_get().connect( SigC::slot(*this, &Constructor::on_btn_y_drag_get));
66 btn_codo->signal_drag_data_get().connect( SigC::slot(*this, &Constructor::on_btn_codo_drag_get));
67 btn_tanque->signal_drag_data_get().connect( SigC::slot(*this, &Constructor::on_btn_tanque_drag_get));
68 btn_drain->signal_drag_data_get().connect( SigC::slot(*this, &Constructor::on_btn_drain_drag_get));
69 btn_and->signal_drag_data_get().connect( SigC::slot(*this, &Constructor::on_btn_and_drag_get));
70 btn_or->signal_drag_data_get().connect( SigC::slot(*this, &Constructor::on_btn_or_drag_get));
71 btn_not->signal_drag_data_get().connect( SigC::slot(*this, &Constructor::on_btn_not_drag_get));
72 btn_check->signal_clicked().connect(SigC::slot(*this,&Constructor::on_btn_check_clicked));
73 btn_dlg_close->signal_clicked().connect(SigC::slot(*this,&Constructor::on_btn_dlg_connect_clicked));
74 chk_btn_logica->signal_clicked().connect(SigC::slot(*this, &Constructor::on_chk_btn_clicked));
76 main_menu_quit->signal_activate().connect(SigC::slot(*this, &Constructor::on_main_menu_quit));
77 main_menu_open->signal_activate().connect(SigC::slot(*this, &Constructor::on_main_menu_open));
78 main_menu_save->signal_activate().connect(SigC::slot(*this, &Constructor::on_main_menu_save));
79 edit_menu_del->signal_activate().connect(SigC::slot(*this,&Constructor::on_edit_menu_del));
81 btn_file_cancel = file_selection->get_cancel_button();
82 btn_file_ok = file_selection->get_ok_button();
83 btn_file_ok->signal_clicked().connect(SigC::slot(*this,&Constructor::on_btn_file_ok_clicked));
84 btn_file_cancel->signal_clicked().connect(SigC::slot(*this,&Constructor::on_btn_file_cancel_clicked));
86 btn_open_cancel = file_open_selection->get_cancel_button();
87 btn_open_ok = file_open_selection->get_ok_button();
88 btn_open_ok->signal_clicked().connect(SigC::slot(*this,&Constructor::on_load_from_xml));
89 btn_open_cancel->signal_clicked().connect(SigC::slot(*this,&Constructor::on_btn_open_cancel_clicked));
91 // Señales para cambiar el icono cuando empieza el drag.
92 btn_canio->signal_drag_begin().connect( SigC::slot(*this, &Constructor::on_canio_drag_begin));
93 btn_y->signal_drag_begin().connect( SigC::slot(*this, &Constructor::on_y_drag_begin));
94 btn_codo->signal_drag_begin().connect( SigC::slot(*this, &Constructor::on_codo_drag_begin));
95 btn_tanque->signal_drag_begin().connect( SigC::slot(*this, &Constructor::on_tanque_drag_begin));
96 btn_bomba->signal_drag_begin().connect( SigC::slot(*this, &Constructor::on_bomba_drag_begin));
97 btn_exclusa->signal_drag_begin().connect( SigC::slot(*this, &Constructor::on_exclusa_drag_begin));
98 btn_drain->signal_drag_begin().connect( SigC::slot(*this, &Constructor::on_drain_drag_begin));
99 btn_and->signal_drag_begin().connect( SigC::slot(*this, &Constructor::on_and_drag_begin));
100 btn_or->signal_drag_begin().connect( SigC::slot(*this, &Constructor::on_or_drag_begin));
101 btn_not->signal_drag_begin().connect( SigC::slot(*this, &Constructor::on_not_drag_begin));
102 workplace->drag_dest_set(listTargets);
103 workplace->signal_drag_data_received().connect( SigC::slot(*this, &Constructor::on_item_drop_drag_received) );
104 workplace->listaItems = &listaItems;
105 workplace->lista_logic_Items = &lista_logic_Items;
109 Constructor::~Constructor()
111 Constructor::on_edit_menu_delete_all();
114 void Constructor::on_btn_canio_drag_get(const Glib::RefPtr<Gdk::DragContext>& context, GtkSelectionData* selection_data, guint info, guint time)
116 gtk_selection_data_set (selection_data, selection_data->target, 8, (const guchar*)"canio_n.png", 12);
119 void Constructor::on_btn_y_drag_get(const Glib::RefPtr<Gdk::DragContext>& context, GtkSelectionData* selection_data, guint info, guint time)
121 gtk_selection_data_set(selection_data, selection_data->target, 8,(const guchar*)"y_n.png",8);
124 void Constructor::on_btn_codo_drag_get(const Glib::RefPtr<Gdk::DragContext>& context, GtkSelectionData* selection_data, guint info, guint time)
126 gtk_selection_data_set(selection_data, selection_data->target, 8 ,(const guchar*)"codo_o.png",10);
129 void Constructor::on_btn_tanque_drag_get(const Glib::RefPtr<Gdk::DragContext>& context, GtkSelectionData* selection_data, guint info, guint time)
131 gtk_selection_data_set(selection_data, selection_data->target, 8,(const guchar*)"tanque_e.png",12);
134 void Constructor::on_btn_bomba_drag_get(const Glib::RefPtr<Gdk::DragContext>& context, GtkSelectionData* selection_data, guint info, guint time)
136 gtk_selection_data_set(selection_data, selection_data->target, 8,(const guchar*)"bomba_e.png",11);
139 void Constructor::on_btn_exclusa_drag_get(const Glib::RefPtr<Gdk::DragContext>& context, GtkSelectionData* selection_data, guint info, guint time)
141 gtk_selection_data_set(selection_data, selection_data->target, 8,(const guchar*)"exclusa_h.png",13);
144 void Constructor::on_btn_drain_drag_get(const Glib::RefPtr<Gdk::DragContext>& context, GtkSelectionData* selection_data, guint info, guint time)
146 gtk_selection_data_set(selection_data, selection_data->target, 8,(const guchar*)"drain_n.png",11);
149 void Constructor::on_btn_and_drag_get(const Glib::RefPtr<Gdk::DragContext>& context, GtkSelectionData* selection_data, guint info, guint time)
151 gtk_selection_data_set(selection_data, selection_data->target, 8,(const guchar*)"and_e.png",9);
154 void Constructor::on_btn_or_drag_get(const Glib::RefPtr<Gdk::DragContext>& context, GtkSelectionData* selection_data, guint info, guint time)
156 gtk_selection_data_set(selection_data, selection_data->target, 8,(const guchar*)"or_e.png",8);
159 void Constructor::on_btn_not_drag_get(const Glib::RefPtr<Gdk::DragContext>& context, GtkSelectionData* selection_data, guint info, guint time)
161 gtk_selection_data_set(selection_data, selection_data->target, 8,(const guchar*)"not_e.png",9);
165 void Constructor::on_main_menu_quit()
172 void Constructor::on_main_menu_open()
174 // Conecto el boton OK para llamar al cargar del XML
175 file_open_selection->show();
178 void Constructor::on_main_menu_save()
180 // Conecto el boton OK para llamar al salvar
181 file_selection->show();
184 void Constructor::on_edit_menu_del()
186 workplace->delete_item(WorkPlace::pointed);
189 void Constructor::on_edit_menu_delete_all()
191 std::list<CItem *>::iterator i = listaItems.begin();
192 while ( i != listaItems.end() ) {
193 (*i)->workplace->delete_item((*i)->get_id());
194 i = listaItems.begin();
196 i = lista_logic_Items.begin();
197 while ( i != lista_logic_Items.end() ) {
198 (*i)->workplace->delete_item((*i)->get_id());
199 i=lista_logic_Items.begin();
203 void Constructor::on_chk_btn_clicked()
206 CItem::logic_connect = !CItem::logic_connect;
209 void Constructor::on_load_from_xml()
211 std::string file_name = file_open_selection->get_filename();
213 /* Parseo de ejemplo de un XML desde archivo */
215 document = xmlParseFile(file_name.c_str());
216 if (document == NULL) {
217 // TODO : dar un aviso de que no se pudo abrir el archivo!!
221 /* bien, el archivo se parseo bien! */
222 xmlNodePtr nodo, items;
223 nodo = document->children;
227 if (strcmp((char *)nodo->name, "planta") == 0) {
228 items = nodo->children;
229 while (items != NULL) {
231 if (items->type == XML_ELEMENT_NODE) {
232 std::cout << "ITEM" << std::endl;
233 if (xmlStrcmp(items->name, BAD_CAST"bomba")==0) {
234 current = loadBomba(items);
235 } else if (xmlStrcmp(items->name, BAD_CAST"tubo")==0) {
236 current = loadConduct(items);
237 } else if (xmlStrcmp(items->name, BAD_CAST"codo")==0) {
238 current = loadCodo(items);
239 } else if (xmlStrcmp(items->name, BAD_CAST"exclusa")==0) {
240 current = loadExclusa(items);
241 } else if (xmlStrcmp(items->name, BAD_CAST"tanque")==0) {
242 current = loadTank(items);
243 } else if (xmlStrcmp(items->name, BAD_CAST"empalme")==0) {
244 current = loadUnion(items);
245 } else if (xmlStrcmp(items->name, BAD_CAST"drenaje")==0) {
246 current = loadDrain(items);
249 if (current != NULL) {
250 // Agrego y conecto la bomba
251 listaItems.push_back(current);
252 current->drag_source_set(listTargets);
253 workplace->put(*current, current->get_position_x(), current->get_position_y());
254 //Apunto al workplace
255 current->workplace= workplace;
257 current->combo_entry = combo_entry;
258 //Apunto a la listaItems.
259 current->listaItems = &listaItems;
260 //Apunto a la lista de items logicos
261 current->lista_logic_Items = &lista_logic_Items;
262 // Conecto las señales
263 current->signal_drag_data_get().connect( SigC::slot(*this, &Constructor::on_item_drag_data_get));
264 current->signal_drag_begin().connect(SigC::bind( SigC::slot(*this, &Constructor::on_item_drag_begin), current));
271 // TODO : avisar que el XML no es valido!!
273 std::cout << "CARGA COMPLETA" << std::endl;
274 file_open_selection->hide();
275 id = listaItems.size()+lista_logic_Items.size()+1;
277 void Constructor::on_btn_file_ok_clicked()
279 std::list<CItem *>::iterator i = listaItems.begin();
280 std::string file_name = file_selection->get_filename();
281 if ( (archivo = fopen( file_name.c_str(), "w+")) != NULL ){
282 fprintf(archivo, "<?xml version=\"1.0\" encoding=\"iso-8859-1\" ?>\n");
283 fprintf (archivo,"<planta>\n");
284 while ( i != listaItems.end() ){
289 fprintf(archivo,"</planta>\n");
291 std::cout<<"NO SE ABRIO EL ARCHIVO"<<std::endl;
293 file_selection->hide();
296 void Constructor::on_btn_file_cancel_clicked()
298 file_selection->hide();
301 void Constructor::on_btn_open_cancel_clicked()
303 file_open_selection->hide();
306 void Constructor::on_btn_dlg_connect_clicked()
311 void Constructor::on_canio_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)
313 context->set_icon(ico_canio, 5, 5);
316 void Constructor::on_y_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)
318 context->set_icon(ico_y, 5, 5);
321 void Constructor::on_codo_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)
323 context->set_icon(ico_codo, 5, 5);
326 void Constructor::on_tanque_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)
328 context->set_icon(ico_tanque, 5, 5);
331 void Constructor::on_bomba_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)
333 context->set_icon(ico_bomba, 5, 5);
336 void Constructor::on_exclusa_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)
338 context->set_icon(ico_exclusa, 5, 5);
341 void Constructor::on_drain_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)
343 context->set_icon(ico_drain, 5, 5);
346 void Constructor::on_and_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)
348 context->set_icon(ico_and, 5, 5);
351 void Constructor::on_or_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)
353 context->set_icon(ico_or, 5, 5);
356 void Constructor::on_not_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)
358 context->set_icon(ico_not, 5, 5);
361 void Constructor::on_item_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context, CItem *item)
364 context->set_icon(item->get_image(), 5, 5);
365 workplace->update_logic_position();
366 workplace->queue_draw();
369 void Constructor::on_item_drag_data_get(const Glib::RefPtr<Gdk::DragContext>& context, GtkSelectionData* selection_data, guint info, guint time)
371 gtk_selection_data_set (selection_data, selection_data->target, 10, (const guchar*)"item_codo.png", 13);
374 bool Constructor::can_drop(CItem *item, int _x, int _y)
376 std::list<CItem*>::iterator i = listaItems.begin();
377 while( i != listaItems.end() ) {
379 if ( temp->get_id() != item->get_id() ) {
380 if ( (temp->is_occupied_area(_x, _y)) ||
381 ( temp->is_occupied_area(_x+item->get_image()->get_width()-1, _y+item->get_image()->get_height()-1)) ||
382 ( temp->is_occupied_area(_x, _y+item->get_image()->get_height()-1)) ||
383 ( temp->is_occupied_area(_x+item->get_image()->get_width()-1, _y) ) )
392 void Constructor::on_item_drop_drag_received(const Glib::RefPtr<Gdk::DragContext>& context, int x, int y, GtkSelectionData* selection_data, guint info, guint time)
395 /* Ajusto coordenada x e y para que caigan en un lugar de una cuadricula de 32x32 */
397 // el +1 es para evitar un bug cuando se selecciona muy cerce de la
398 // separacion de 2 cuadritos
401 // El drag es de un item
402 if (selection_data->format == 10) {
403 if (can_drop(((CItem*)drag_get_source_widget(context)),i*32, j*32)){
404 ((CItem*)drag_get_source_widget(context))->set_position(i*32, j*32);
405 workplace->move(*drag_get_source_widget(context), i*32, j*32);
409 // El Drag es desde la barra de tareas
410 if ((selection_data->length >= 0) && (selection_data->format == 8)) {
412 if (strcmp((const char *)selection_data->data, "codo_o.png")==0)
414 else if (strcmp((const char *)selection_data->data, "canio_n.png")==0)
416 else if (strcmp((const char *)selection_data->data, "y_n.png")==0)
418 else if (strcmp((const char *)selection_data->data, "tanque_e.png")==0)
420 else if (strcmp((const char *)selection_data->data, "bomba_e.png")==0)
422 else if (strcmp((const char *)selection_data->data, "exclusa_h.png")==0)
424 else if (strcmp((const char *)selection_data->data, "drain_n.png")==0)
426 else if (strcmp((const char *)selection_data->data, "and_e.png")==0){
427 a = new And(); a->is_logic = true;
428 } else if (strcmp((const char *)selection_data->data, "or_e.png")==0) {
429 a = new Or(); a->is_logic = true;
430 } else if (strcmp((const char *)selection_data->data, "not_e.png")==0) {
431 a = new Not(); a->is_logic = true;
435 sprintf(char_id,"%d",id);
437 a->set_name( a->get_name()+char_id );
438 if ( can_drop(a, i*32, j*32) ) {
439 workplace->put(*a, i*32, j*32);
440 //Apunto al workplace
441 a->workplace= workplace;
443 a->combo_entry = combo_entry;
444 //Apunto a la listaItems.
445 a->listaItems = &listaItems;
446 //Apunto a la lista de items logicos
447 a->lista_logic_Items = &lista_logic_Items;
448 //Seteo la posicion del item
449 a->set_position(i*32,j*32);
450 // Seteo la lista de tipos de drags
451 a->drag_source_set(listTargets);
452 // Conecto las señales
453 a->signal_drag_data_get().connect( SigC::slot(*this, &Constructor::on_item_drag_data_get));
454 // Utilizo el SigC::bind para que el callback on_drag_begin acepte un
455 // parametro extra, en este caso un CItem *. Esto se hace para
456 // que cuando el usuario quiera mover un item, saber que item es
457 // y pedirle su ícono para mostrar cono icono durante la operacion,
458 // Esto va a permitir, que si un widget tiene una imagen rotara o algo
459 // raro se vea el widget tal cual.
460 a->signal_drag_begin().connect(SigC::bind( SigC::slot(*this, &Constructor::on_item_drag_begin), a));
463 listaItems.push_back(a);
465 lista_logic_Items.push_back(a);
471 context->drag_finish(false, false, time);
475 void Constructor::on_btn_check_clicked()
477 std::list<CItem *>::iterator i = listaItems.begin();
478 while ( i != listaItems.end() ){
479 (*i)->set_default_connector();
480 (*i)->is_connected = false;
484 i = listaItems.begin();
485 if ( !listaItems.empty() ) {
486 while ( i != listaItems.end() ) {
488 std::cout<< "item="<<temp->get_name()<<" "<<"check= "<<temp->check_connection()<<std::endl;
489 if ( !temp->check_connection() ) {
490 dlg_connect->set_title("Error");
491 dlg_label->set_text("Los elementos no estan conectados\n\t\tcorrectamente");
497 dlg_connect->set_title("Conexion");
498 dlg_label->set_text("Los elementos estan conectados\n\t\tcorrectamente");
503 Pump *Constructor::loadBomba(xmlNodePtr nodo)
505 std::string name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
506 std::string id = (char *)xmlGetProp(nodo, BAD_CAST"id");
507 int orientacion=0, x, y;
510 nodo = nodo->children;
511 while (nodo != NULL) {
512 if (nodo->type == XML_ELEMENT_NODE) {
513 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
514 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
515 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
516 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
517 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
518 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
519 } else if (xmlStrcmp(nodo->name, BAD_CAST"entrega") == 0) {
520 flujo = atof( (char *)XML_GET_CONTENT(nodo->children) );
521 } else if (xmlStrcmp(nodo->name, BAD_CAST"color") == 0) {
528 Pump *p = new Pump(orientacion);
529 p->set_position(x,y);
530 p->set_entrega(flujo);
531 p->set_id( atoi(id.c_str()) );
537 Conduct *Constructor::loadConduct(xmlNodePtr nodo)
539 std::string name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
540 std::string id = (char *)xmlGetProp(nodo, BAD_CAST"id");
541 int orientacion=0, x, y;
544 nodo = nodo->children;
545 while (nodo != NULL) {
546 if (nodo->type == XML_ELEMENT_NODE) {
547 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
548 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
549 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
550 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
551 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
552 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
553 } else if (xmlStrcmp(nodo->name, BAD_CAST"caudal") == 0) {
554 flujo = atof( (char *)XML_GET_CONTENT(nodo->children) );
560 Conduct *p = new Conduct(orientacion);
561 p->set_position(x,y);
562 p->set_caudal(flujo);
563 p->set_id( atoi(id.c_str()) );
569 Exclusa *Constructor::loadExclusa(xmlNodePtr nodo)
571 std::string name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
572 std::string id = (char *)xmlGetProp(nodo, BAD_CAST"id");
574 int orientacion=0, x, y;
577 nodo = nodo->children;
578 while (nodo != NULL) {
579 if (nodo->type == XML_ELEMENT_NODE) {
580 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
581 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
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"estado") == 0) {
587 estado = (char *)XML_GET_CONTENT(nodo->children);
593 Exclusa *p = new Exclusa(orientacion);
594 p->set_position(x,y);
595 p->set_id( atoi(id.c_str()) );
597 p->set_estado( estado == "1" );
602 Cistern *Constructor::loadTank(xmlNodePtr nodo)
604 std::string name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
605 std::string id = (char *)xmlGetProp(nodo, BAD_CAST"id");
606 int orientacion=0, x, y;
607 float liquido,capacidad;
609 nodo = nodo->children;
610 while (nodo != NULL) {
611 if (nodo->type == XML_ELEMENT_NODE) {
612 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
613 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
614 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
615 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
616 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
617 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
618 } else if (xmlStrcmp(nodo->name, BAD_CAST"capacidad") == 0) {
619 capacidad = atof ((char *)XML_GET_CONTENT(nodo->children) );
620 } else if (xmlStrcmp(nodo->name, BAD_CAST"inicial") == 0) {
621 liquido = atof ((char *)XML_GET_CONTENT(nodo->children) );
627 Cistern *p = new Cistern(orientacion);
628 p->set_position(x,y);
629 p->set_id( atoi(id.c_str()) );
631 p->set_capacidad(capacidad);
632 p->set_contenido_inicial(liquido);
637 Union *Constructor::loadUnion(xmlNodePtr nodo)
639 std::string name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
640 std::string id = (char *)xmlGetProp(nodo, BAD_CAST"id");
642 int orientacion=0, x, y;
645 nodo = nodo->children;
646 while (nodo != NULL) {
647 if (nodo->type == XML_ELEMENT_NODE) {
648 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
649 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
650 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
651 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
652 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
653 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
654 } else if (xmlStrcmp(nodo->name, BAD_CAST"caudal") == 0) {
655 caudal = atof ((char *)XML_GET_CONTENT(nodo->children) );
656 } else if (xmlStrcmp(nodo->name, BAD_CAST"tipo") == 0) {
657 tipo = (char *)XML_GET_CONTENT(nodo->children);
663 Union *p = new Union(orientacion);
664 p->set_position(x,y);
665 p->set_id( atoi(id.c_str()) );
667 p->set_caudal(caudal);
668 p->is_union = (tipo == "union");
673 Drain *Constructor::loadDrain(xmlNodePtr nodo)
675 std::string name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
676 std::string id = (char *)xmlGetProp(nodo, BAD_CAST"id");
677 int orientacion=0, x, y;
679 nodo = nodo->children;
680 while (nodo != NULL) {
681 if (nodo->type == XML_ELEMENT_NODE) {
682 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
683 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
684 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
685 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
686 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
687 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
693 Drain *p = new Drain(orientacion);
694 p->set_position(x,y);
695 p->set_id( atoi(id.c_str()) );
701 Splitter *Constructor::loadCodo(xmlNodePtr nodo)
703 std::string name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
704 std::string id = (char *)xmlGetProp(nodo, BAD_CAST"id");
705 int orientacion=0, x, y;
708 nodo = nodo->children;
709 while (nodo != NULL) {
710 if (nodo->type == XML_ELEMENT_NODE) {
711 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
712 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
713 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
714 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
715 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
716 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
717 } else if (xmlStrcmp(nodo->name, BAD_CAST"caudal") == 0) {
718 caudal = atof( (char *)XML_GET_CONTENT(nodo->children) );
724 Splitter *p = new Splitter(orientacion);
725 p->set_position(x,y);
726 p->set_id( atoi(id.c_str()) );
728 p->set_caudal(caudal);