1 #include "constructor.h"
3 Constructor::Constructor(BaseObjectType* cobject, const Glib::RefPtr<Gnome::Glade::Xml>& refGlade):Gtk::Window(cobject)
7 set_title("Constructor");
10 ico_canio = Gdk::Pixbuf::create_from_file(PACKAGE_DATA_DIR"/plaqui-constructor/pixmaps/canio_n.png");
11 ico_y = Gdk::Pixbuf::create_from_file(PACKAGE_DATA_DIR"/plaqui-constructor/pixmaps/y_n.png");
12 ico_codo = Gdk::Pixbuf::create_from_file(PACKAGE_DATA_DIR"/plaqui-constructor/pixmaps/codo_o.png");
13 ico_tanque = Gdk::Pixbuf::create_from_file(PACKAGE_DATA_DIR"/plaqui-constructor/pixmaps/tanque_e.png");
14 ico_exclusa = Gdk::Pixbuf::create_from_file(PACKAGE_DATA_DIR"/plaqui-constructor/pixmaps/exclusa_h.png");
15 ico_drain = Gdk::Pixbuf::create_from_file(PACKAGE_DATA_DIR"/plaqui-constructor/pixmaps/drain_n.png");
16 ico_bomba = Gdk::Pixbuf::create_from_file(PACKAGE_DATA_DIR"/plaqui-constructor/pixmaps/bomba_e.png");
17 ico_and = Gdk::Pixbuf::create_from_file(PACKAGE_DATA_DIR"/plaqui-constructor/pixmaps/and_e.png");
18 ico_or = Gdk::Pixbuf::create_from_file(PACKAGE_DATA_DIR"/plaqui-constructor/pixmaps/or_e.png");
19 ico_not = Gdk::Pixbuf::create_from_file(PACKAGE_DATA_DIR"/plaqui-constructor/pixmaps/not_e.png");
21 refGlade->get_widget("btn_canio", btn_canio);
22 refGlade->get_widget("btn_codo", btn_codo);
23 refGlade->get_widget("btn_y", btn_y);
24 refGlade->get_widget("btn_tanque",btn_tanque);
25 refGlade->get_widget("btn_bomba", btn_bomba);
26 refGlade->get_widget("btn_exclusa", btn_exclusa);
27 refGlade->get_widget("btn_drain", btn_drain);
28 refGlade->get_widget("btn_and", btn_and);
29 refGlade->get_widget("btn_or", btn_or);
30 refGlade->get_widget("btn_not", btn_not);
31 refGlade->get_widget("main_menu_quit",main_menu_quit);
32 refGlade->get_widget("main_menu_open",main_menu_open);
33 refGlade->get_widget("main_menu_save",main_menu_save);
34 refGlade->get_widget("edit_menu_del",edit_menu_del);
35 refGlade->get_widget("chk_btn_logica",chk_btn_logica);
36 refGlade->get_widget("file_open_selection",file_open_selection);
37 refGlade->get_widget("file_selection",file_selection);
38 refGlade->get_widget("combo_entry",combo_entry);
39 refGlade->get_widget("btn_check",btn_check);
40 refGlade->get_widget("dlg_connect", dlg_connect);
41 refGlade->get_widget("btn_dlg_close", btn_dlg_close);
42 refGlade->get_widget("dlg_label", dlg_label);
43 refGlade->get_widget("quick_btn_clear", quick_btn_clear);
44 refGlade->get_widget("quick_btn_save", quick_btn_save);
46 refGlade->get_widget_derived("workplace", workplace); //fixed
49 listTargets.push_back( Gtk::TargetEntry("STRING") );
50 listTargets.push_back( Gtk::TargetEntry("text/plain") );
51 listTargets.push_back( Gtk::TargetEntry("POINTER") );
52 listTargets.push_back( Gtk::TargetEntry("application/pointer") );
54 btn_canio->drag_source_set(listTargets);
55 btn_y->drag_source_set(listTargets);
56 btn_codo->drag_source_set(listTargets);
57 btn_tanque->drag_source_set(listTargets);
58 btn_bomba->drag_source_set(listTargets);
59 btn_drain->drag_source_set(listTargets);
60 btn_exclusa->drag_source_set(listTargets);
61 btn_and->drag_source_set(listTargets);
62 btn_or->drag_source_set(listTargets);
63 btn_not->drag_source_set(listTargets);
65 btn_canio->signal_drag_data_get().connect( SigC::slot(*this, &Constructor::on_btn_canio_drag_get));
66 btn_bomba->signal_drag_data_get().connect( SigC::slot(*this, &Constructor::on_btn_bomba_drag_get));
67 btn_exclusa->signal_drag_data_get().connect( SigC::slot(*this, &Constructor::on_btn_exclusa_drag_get));
68 btn_y->signal_drag_data_get().connect( SigC::slot(*this, &Constructor::on_btn_y_drag_get));
69 btn_codo->signal_drag_data_get().connect( SigC::slot(*this, &Constructor::on_btn_codo_drag_get));
70 btn_tanque->signal_drag_data_get().connect( SigC::slot(*this, &Constructor::on_btn_tanque_drag_get));
71 btn_drain->signal_drag_data_get().connect( SigC::slot(*this, &Constructor::on_btn_drain_drag_get));
72 btn_and->signal_drag_data_get().connect( SigC::slot(*this, &Constructor::on_btn_and_drag_get));
73 btn_or->signal_drag_data_get().connect( SigC::slot(*this, &Constructor::on_btn_or_drag_get));
74 btn_not->signal_drag_data_get().connect( SigC::slot(*this, &Constructor::on_btn_not_drag_get));
75 btn_check->signal_clicked().connect(SigC::slot(*this,&Constructor::on_btn_check_clicked));
76 btn_dlg_close->signal_clicked().connect(SigC::slot(*this,&Constructor::on_btn_dlg_connect_clicked));
77 chk_btn_logica->signal_clicked().connect(SigC::slot(*this, &Constructor::on_chk_btn_clicked));
78 quick_btn_clear->signal_clicked().connect(SigC::slot(*this, &Constructor::on_quick_btn_clear_clicked));
79 quick_btn_save->signal_clicked().connect(SigC::slot(*this, &Constructor::on_quick_btn_save_clicked));
81 main_menu_quit->signal_activate().connect(SigC::slot(*this, &Constructor::on_main_menu_quit));
82 main_menu_open->signal_activate().connect(SigC::slot(*this, &Constructor::on_main_menu_open));
83 main_menu_save->signal_activate().connect(SigC::slot(*this, &Constructor::on_main_menu_save));
84 edit_menu_del->signal_activate().connect(SigC::slot(*this,&Constructor::on_edit_menu_del));
86 btn_file_cancel = file_selection->get_cancel_button();
87 btn_file_ok = file_selection->get_ok_button();
88 btn_file_ok->signal_clicked().connect(SigC::slot(*this,&Constructor::on_btn_file_ok_clicked));
89 btn_file_cancel->signal_clicked().connect(SigC::slot(*this,&Constructor::on_btn_file_cancel_clicked));
91 btn_open_cancel = file_open_selection->get_cancel_button();
92 btn_open_ok = file_open_selection->get_ok_button();
93 btn_open_ok->signal_clicked().connect(SigC::slot(*this,&Constructor::on_load_from_xml));
94 btn_open_cancel->signal_clicked().connect(SigC::slot(*this,&Constructor::on_btn_open_cancel_clicked));
96 // Señales para cambiar el icono cuando empieza el drag.
97 btn_canio->signal_drag_begin().connect( SigC::slot(*this, &Constructor::on_canio_drag_begin));
98 btn_y->signal_drag_begin().connect( SigC::slot(*this, &Constructor::on_y_drag_begin));
99 btn_codo->signal_drag_begin().connect( SigC::slot(*this, &Constructor::on_codo_drag_begin));
100 btn_tanque->signal_drag_begin().connect( SigC::slot(*this, &Constructor::on_tanque_drag_begin));
101 btn_bomba->signal_drag_begin().connect( SigC::slot(*this, &Constructor::on_bomba_drag_begin));
102 btn_exclusa->signal_drag_begin().connect( SigC::slot(*this, &Constructor::on_exclusa_drag_begin));
103 btn_drain->signal_drag_begin().connect( SigC::slot(*this, &Constructor::on_drain_drag_begin));
104 btn_and->signal_drag_begin().connect( SigC::slot(*this, &Constructor::on_and_drag_begin));
105 btn_or->signal_drag_begin().connect( SigC::slot(*this, &Constructor::on_or_drag_begin));
106 btn_not->signal_drag_begin().connect( SigC::slot(*this, &Constructor::on_not_drag_begin));
107 workplace->drag_dest_set(listTargets);
108 workplace->signal_drag_data_received().connect( SigC::slot(*this, &Constructor::on_item_drop_drag_received) );
109 workplace->listaItems = &listaItems;
110 workplace->lista_logic_Items = &lista_logic_Items;
114 Constructor::~Constructor()
116 Constructor::on_edit_menu_delete_all();
119 void Constructor::on_btn_canio_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*)"canio_n.png", 12);
124 void Constructor::on_btn_y_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*)"y_n.png",8);
129 void Constructor::on_btn_codo_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*)"codo_o.png",10);
134 void Constructor::on_btn_tanque_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*)"tanque_e.png",12);
139 void Constructor::on_btn_bomba_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*)"bomba_e.png",11);
144 void Constructor::on_btn_exclusa_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*)"exclusa_h.png",13);
149 void Constructor::on_btn_drain_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*)"drain_n.png",11);
154 void Constructor::on_btn_and_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*)"and_e.png",9);
159 void Constructor::on_btn_or_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*)"or_e.png",8);
164 void Constructor::on_btn_not_drag_get(const Glib::RefPtr<Gdk::DragContext>& context, GtkSelectionData* selection_data, guint info, guint time)
166 gtk_selection_data_set(selection_data, selection_data->target, 8,(const guchar*)"not_e.png",9);
170 void Constructor::on_main_menu_quit()
177 void Constructor::on_main_menu_open()
179 // Conecto el boton OK para llamar al cargar del XML
180 file_open_selection->show();
183 void Constructor::on_main_menu_save()
185 // Conecto el boton OK para llamar al salvar
186 file_selection->show();
189 void Constructor::on_edit_menu_del()
191 workplace->delete_item(WorkPlace::pointed);
194 void Constructor::on_edit_menu_delete_all()
196 std::list<CItem *>::iterator i = listaItems.begin();
197 while ( i != listaItems.end() ) {
198 (*i)->workplace->delete_item((*i)->get_id());
199 i = listaItems.begin();
201 i = lista_logic_Items.begin();
202 while ( i != lista_logic_Items.end() ) {
203 (*i)->workplace->delete_item((*i)->get_id());
204 i=lista_logic_Items.begin();
208 void Constructor::on_chk_btn_clicked()
211 CItem::logic_connect = !CItem::logic_connect;
214 void Constructor::on_load_from_xml()
216 file_name = file_open_selection->get_filename();
218 /* Parseo de ejemplo de un XML desde archivo */
220 document = xmlParseFile(file_name.c_str());
221 if (document == NULL) {
222 // TODO : dar un aviso de que no se pudo abrir el archivo!!
226 /* bien, el archivo se parseo bien! */
227 xmlNodePtr nodo, items;
228 nodo = document->children;
232 if (strcmp((char *)nodo->name, "planta") == 0) {
233 items = nodo->children;
234 while (items != NULL) {
236 if (items->type == XML_ELEMENT_NODE) {
237 std::cout << "ITEM" << std::endl;
238 if (xmlStrcmp(items->name, BAD_CAST"bomba")==0) {
239 current = loadBomba(items);
240 } else if (xmlStrcmp(items->name, BAD_CAST"tubo")==0) {
241 current = loadConduct(items);
242 } else if (xmlStrcmp(items->name, BAD_CAST"codo")==0) {
243 current = loadCodo(items);
244 } else if (xmlStrcmp(items->name, BAD_CAST"exclusa")==0) {
245 current = loadExclusa(items);
246 } else if (xmlStrcmp(items->name, BAD_CAST"tanque")==0) {
247 current = loadTank(items);
248 } else if (xmlStrcmp(items->name, BAD_CAST"empalme")==0) {
249 current = loadUnion(items);
250 } else if (xmlStrcmp(items->name, BAD_CAST"drenaje")==0) {
251 current = loadDrain(items);
254 if (current != NULL) {
255 // Agrego y conecto la bomba
256 listaItems.push_back(current);
257 current->drag_source_set(listTargets);
258 workplace->put(*current, current->get_position_x(), current->get_position_y());
259 //Apunto al workplace
260 current->workplace= workplace;
262 current->combo_entry = combo_entry;
263 //Apunto a la listaItems.
264 current->listaItems = &listaItems;
265 //Apunto a la lista de items logicos
266 current->lista_logic_Items = &lista_logic_Items;
267 // Conecto las señales
268 current->signal_drag_data_get().connect( SigC::slot(*this, &Constructor::on_item_drag_data_get));
269 current->signal_drag_begin().connect(SigC::bind( SigC::slot(*this, &Constructor::on_item_drag_begin), current));
276 // TODO : avisar que el XML no es valido!!
278 std::cout << "CARGA COMPLETA" << std::endl;
279 file_open_selection->hide();
280 id = listaItems.size()+lista_logic_Items.size()+1;
283 void Constructor::on_btn_file_ok_clicked()
285 std::list<CItem *>::iterator i = listaItems.begin();
286 file_name = file_selection->get_filename();
287 if ( (archivo = fopen( file_name.c_str(), "w+")) != NULL ){
288 fprintf(archivo, "<?xml version=\"1.0\" encoding=\"iso-8859-1\" ?>\n");
289 fprintf (archivo,"<planta>\n");
290 while ( i != listaItems.end() ){
294 i = lista_logic_Items.begin();
295 while ( i != lista_logic_Items.end() ) {
299 fprintf(archivo,"</planta>\n");
302 std::cout<<"NO SE ABRIO EL ARCHIVO"<<std::endl;
304 file_selection->hide();
307 void Constructor::on_quick_btn_save_clicked()
312 on_btn_file_ok_clicked();
317 void Constructor::on_quick_btn_clear_clicked()
319 std::list<CItem *>::iterator i = listaItems.begin();
320 while ( i != listaItems.end() ){
324 i = listaItems.begin();
326 i = lista_logic_Items.begin();
327 while ( i != lista_logic_Items.end() ){
329 lista_logic_Items.erase(i);
331 i = lista_logic_Items.begin();
335 void Constructor::on_btn_file_cancel_clicked()
337 file_selection->hide();
340 void Constructor::on_btn_open_cancel_clicked()
342 file_open_selection->hide();
345 void Constructor::on_btn_dlg_connect_clicked()
350 void Constructor::on_canio_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)
352 context->set_icon(ico_canio, 5, 5);
355 void Constructor::on_y_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)
357 context->set_icon(ico_y, 5, 5);
360 void Constructor::on_codo_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)
362 context->set_icon(ico_codo, 5, 5);
365 void Constructor::on_tanque_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)
367 context->set_icon(ico_tanque, 5, 5);
370 void Constructor::on_bomba_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)
372 context->set_icon(ico_bomba, 5, 5);
375 void Constructor::on_exclusa_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)
377 context->set_icon(ico_exclusa, 5, 5);
380 void Constructor::on_drain_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)
382 context->set_icon(ico_drain, 5, 5);
385 void Constructor::on_and_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)
387 context->set_icon(ico_and, 5, 5);
390 void Constructor::on_or_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)
392 context->set_icon(ico_or, 5, 5);
395 void Constructor::on_not_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)
397 context->set_icon(ico_not, 5, 5);
400 void Constructor::on_item_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context, CItem *item)
402 context->set_icon(item->get_image(), 5, 5);
405 void Constructor::on_item_drag_data_get(const Glib::RefPtr<Gdk::DragContext>& context, GtkSelectionData* selection_data, guint info, guint time)
407 gtk_selection_data_set (selection_data, selection_data->target, 10, (const guchar*)"item_codo.png", 13);
410 bool Constructor::can_drop(CItem *item, int _x, int _y)
412 std::list<CItem*>::iterator i = listaItems.begin();
413 while( i != listaItems.end() ) {
415 if ( temp->get_id() != item->get_id() ) {
416 if ( (temp->is_occupied_area(_x, _y)) ||
417 ( temp->is_occupied_area(_x+item->get_image()->get_width()-1, _y+item->get_image()->get_height()-1)) ||
418 ( temp->is_occupied_area(_x, _y+item->get_image()->get_height()-1)) ||
419 ( temp->is_occupied_area(_x+item->get_image()->get_width()-1, _y) ) )
428 void Constructor::on_item_drop_drag_received(const Glib::RefPtr<Gdk::DragContext>& context, int x, int y, GtkSelectionData* selection_data, guint info, guint time)
430 workplace->update_logic_position();
431 workplace->queue_draw();
433 /* Ajusto coordenada x e y para que caigan en un lugar de una cuadricula de 32x32 */
435 // el +1 es para evitar un bug cuando se selecciona muy cerce de la
436 // separacion de 2 cuadritos
439 // El drag es de un item
440 if (selection_data->format == 10) {
441 if (can_drop(((CItem*)drag_get_source_widget(context)),i*32, j*32)){
442 ((CItem*)drag_get_source_widget(context))->set_position(i*32, j*32);
443 workplace->move(*drag_get_source_widget(context), i*32, j*32);
447 // El Drag es desde la barra de tareas
448 if ((selection_data->length >= 0) && (selection_data->format == 8)) {
450 if (strcmp((const char *)selection_data->data, "codo_o.png")==0)
452 else if (strcmp((const char *)selection_data->data, "canio_n.png")==0)
454 else if (strcmp((const char *)selection_data->data, "y_n.png")==0)
456 else if (strcmp((const char *)selection_data->data, "tanque_e.png")==0)
458 else if (strcmp((const char *)selection_data->data, "bomba_e.png")==0)
460 else if (strcmp((const char *)selection_data->data, "exclusa_h.png")==0)
462 else if (strcmp((const char *)selection_data->data, "drain_n.png")==0)
464 else if (strcmp((const char *)selection_data->data, "and_e.png")==0){
465 a = new And(); a->is_logic = true;
466 } else if (strcmp((const char *)selection_data->data, "or_e.png")==0) {
467 a = new Or(); a->is_logic = true;
468 } else if (strcmp((const char *)selection_data->data, "not_e.png")==0) {
469 a = new Not(); a->is_logic = true;
473 sprintf(char_id,"%d",id);
475 a->set_name( a->get_name()+char_id );
476 if ( can_drop(a, i*32, j*32) ) {
477 workplace->put(*a, i*32, j*32);
478 //Apunto al workplace
479 a->workplace= workplace;
481 a->combo_entry = combo_entry;
482 //Apunto a la listaItems.
483 a->listaItems = &listaItems;
484 //Apunto a la lista de items logicos
485 a->lista_logic_Items = &lista_logic_Items;
486 //Seteo la posicion del item
487 a->set_position(i*32,j*32);
488 // Seteo la lista de tipos de drags
489 a->drag_source_set(listTargets);
490 // Conecto las señales
491 a->signal_drag_data_get().connect( SigC::slot(*this, &Constructor::on_item_drag_data_get));
492 // Utilizo el SigC::bind para que el callback on_drag_begin acepte un
493 // parametro extra, en este caso un CItem *. Esto se hace para
494 // que cuando el usuario quiera mover un item, saber que item es
495 // y pedirle su ícono para mostrar cono icono durante la operacion,
496 // Esto va a permitir, que si un widget tiene una imagen rotara o algo
497 // raro se vea el widget tal cual.
498 a->signal_drag_begin().connect(SigC::bind( SigC::slot(*this, &Constructor::on_item_drag_begin), a));
501 listaItems.push_back(a);
503 lista_logic_Items.push_back(a);
509 context->drag_finish(false, false, time);
511 workplace->update_logic_position();
512 workplace->queue_draw();
515 void Constructor::on_btn_check_clicked()
517 std::list<CItem *>::iterator i = listaItems.begin();
518 while ( i != listaItems.end() ){
519 (*i)->set_default_connector();
520 (*i)->is_connected = false;
524 i = listaItems.begin();
525 if ( !listaItems.empty() ) {
526 while ( i != listaItems.end() ) {
528 std::cout<< "item="<<temp->get_name()<<" "<<"check= "<<temp->check_connection()<<std::endl;
529 if ( !temp->check_connection() ) {
530 dlg_connect->set_title("Error");
531 dlg_label->set_text("Los elementos no estan conectados\n\t\tcorrectamente");
537 dlg_connect->set_title("Conexion");
538 dlg_label->set_text("Los elementos estan conectados\n\t\tcorrectamente");
541 std::cout<<"check_connection logic"<<std::endl;
542 std::list<CItem *>::iterator j = lista_logic_Items.begin();
543 while ( j != lista_logic_Items.end() ) {
544 (*j)->check_connection();
551 Pump *Constructor::loadBomba(xmlNodePtr nodo)
553 std::string name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
554 std::string id = (char *)xmlGetProp(nodo, BAD_CAST"id");
555 int orientacion=0, x, y;
558 nodo = nodo->children;
559 while (nodo != NULL) {
560 if (nodo->type == XML_ELEMENT_NODE) {
561 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
562 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
563 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
564 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
565 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
566 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
567 } else if (xmlStrcmp(nodo->name, BAD_CAST"entrega") == 0) {
568 flujo = atof( (char *)XML_GET_CONTENT(nodo->children) );
569 } else if (xmlStrcmp(nodo->name, BAD_CAST"color") == 0) {
576 Pump *p = new Pump(orientacion);
577 p->set_position(x,y);
578 p->set_entrega(flujo);
579 p->set_id( atoi(id.c_str()) );
585 Conduct *Constructor::loadConduct(xmlNodePtr nodo)
587 std::string name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
588 std::string id = (char *)xmlGetProp(nodo, BAD_CAST"id");
589 int orientacion=0, x, y;
592 nodo = nodo->children;
593 while (nodo != NULL) {
594 if (nodo->type == XML_ELEMENT_NODE) {
595 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
596 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
597 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
598 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
599 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
600 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
601 } else if (xmlStrcmp(nodo->name, BAD_CAST"caudal") == 0) {
602 flujo = atof( (char *)XML_GET_CONTENT(nodo->children) );
608 Conduct *p = new Conduct(orientacion);
609 p->set_position(x,y);
610 p->set_caudal(flujo);
611 p->set_id( atoi(id.c_str()) );
617 Exclusa *Constructor::loadExclusa(xmlNodePtr nodo)
619 std::string name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
620 std::string id = (char *)xmlGetProp(nodo, BAD_CAST"id");
622 int orientacion=0, x, y;
625 nodo = nodo->children;
626 while (nodo != NULL) {
627 if (nodo->type == XML_ELEMENT_NODE) {
628 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
629 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
630 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
631 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
632 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
633 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
634 } else if (xmlStrcmp(nodo->name, BAD_CAST"estado") == 0) {
635 estado = (char *)XML_GET_CONTENT(nodo->children);
641 Exclusa *p = new Exclusa(orientacion);
642 p->set_position(x,y);
643 p->set_id( atoi(id.c_str()) );
645 p->set_estado( estado == "1" );
650 Cistern *Constructor::loadTank(xmlNodePtr nodo)
652 std::string name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
653 std::string id = (char *)xmlGetProp(nodo, BAD_CAST"id");
654 int orientacion=0, x, y;
655 float liquido,capacidad;
657 nodo = nodo->children;
658 while (nodo != NULL) {
659 if (nodo->type == XML_ELEMENT_NODE) {
660 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
661 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
662 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
663 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
664 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
665 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
666 } else if (xmlStrcmp(nodo->name, BAD_CAST"capacidad") == 0) {
667 capacidad = atof ((char *)XML_GET_CONTENT(nodo->children) );
668 } else if (xmlStrcmp(nodo->name, BAD_CAST"inicial") == 0) {
669 liquido = atof ((char *)XML_GET_CONTENT(nodo->children) );
675 Cistern *p = new Cistern(orientacion);
676 p->set_position(x,y);
677 p->set_id( atoi(id.c_str()) );
679 p->set_capacidad(capacidad);
680 p->set_contenido_inicial(liquido);
685 Union *Constructor::loadUnion(xmlNodePtr nodo)
687 std::string name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
688 std::string id = (char *)xmlGetProp(nodo, BAD_CAST"id");
690 int orientacion=0, x, y;
693 nodo = nodo->children;
694 while (nodo != NULL) {
695 if (nodo->type == XML_ELEMENT_NODE) {
696 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
697 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
698 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
699 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
700 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
701 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
702 } else if (xmlStrcmp(nodo->name, BAD_CAST"caudal") == 0) {
703 caudal = atof ((char *)XML_GET_CONTENT(nodo->children) );
704 } else if (xmlStrcmp(nodo->name, BAD_CAST"tipo") == 0) {
705 tipo = (char *)XML_GET_CONTENT(nodo->children);
711 Union *p = new Union(orientacion);
712 p->set_position(x,y);
713 p->set_id( atoi(id.c_str()) );
715 p->set_caudal(caudal);
716 p->is_union = (tipo == "union");
721 Drain *Constructor::loadDrain(xmlNodePtr nodo)
723 std::string name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
724 std::string id = (char *)xmlGetProp(nodo, BAD_CAST"id");
725 int orientacion=0, x, y;
727 nodo = nodo->children;
728 while (nodo != NULL) {
729 if (nodo->type == XML_ELEMENT_NODE) {
730 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
731 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
732 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
733 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
734 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
735 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
741 Drain *p = new Drain(orientacion);
742 p->set_position(x,y);
743 p->set_id( atoi(id.c_str()) );
749 Splitter *Constructor::loadCodo(xmlNodePtr nodo)
751 std::string name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
752 std::string id = (char *)xmlGetProp(nodo, BAD_CAST"id");
753 int orientacion=0, x, y;
756 nodo = nodo->children;
757 while (nodo != NULL) {
758 if (nodo->type == XML_ELEMENT_NODE) {
759 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
760 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
761 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
762 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
763 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
764 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
765 } else if (xmlStrcmp(nodo->name, BAD_CAST"caudal") == 0) {
766 caudal = atof( (char *)XML_GET_CONTENT(nodo->children) );
772 Splitter *p = new Splitter(orientacion);
773 p->set_position(x,y);
774 p->set_id( atoi(id.c_str()) );
776 p->set_caudal(caudal);