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_new",main_menu_new);
33 refGlade->get_widget("main_menu_open",main_menu_open);
34 refGlade->get_widget("main_menu_save",main_menu_save);
35 refGlade->get_widget("edit_menu_del",edit_menu_del);
36 refGlade->get_widget("chk_btn_logica",chk_btn_logica);
37 refGlade->get_widget("file_open_selection",file_open_selection);
38 refGlade->get_widget("file_selection",file_selection);
39 refGlade->get_widget("combo_entry",combo_entry);
40 refGlade->get_widget("btn_check",btn_check);
41 refGlade->get_widget("dlg_connect", dlg_connect);
42 refGlade->get_widget("btn_dlg_close", btn_dlg_close);
43 refGlade->get_widget("dlg_label", dlg_label);
44 refGlade->get_widget("quick_btn_new", quick_btn_new);
45 refGlade->get_widget("quick_btn_save", quick_btn_save);
46 refGlade->get_widget("quick_btn_open", quick_btn_open);
47 refGlade->get_widget("edit_menu_delete_all", edit_menu_delete_all);
49 refGlade->get_widget_derived("workplace", workplace); //fixed
52 listTargets.push_back( Gtk::TargetEntry("STRING") );
53 listTargets.push_back( Gtk::TargetEntry("text/plain") );
54 listTargets.push_back( Gtk::TargetEntry("POINTER") );
55 listTargets.push_back( Gtk::TargetEntry("application/pointer") );
57 btn_canio->drag_source_set(listTargets);
58 btn_y->drag_source_set(listTargets);
59 btn_codo->drag_source_set(listTargets);
60 btn_tanque->drag_source_set(listTargets);
61 btn_bomba->drag_source_set(listTargets);
62 btn_drain->drag_source_set(listTargets);
63 btn_exclusa->drag_source_set(listTargets);
64 btn_and->drag_source_set(listTargets);
65 btn_or->drag_source_set(listTargets);
66 btn_not->drag_source_set(listTargets);
68 btn_canio->signal_drag_data_get().connect( SigC::slot(*this, &Constructor::on_btn_canio_drag_get));
69 btn_bomba->signal_drag_data_get().connect( SigC::slot(*this, &Constructor::on_btn_bomba_drag_get));
70 btn_exclusa->signal_drag_data_get().connect( SigC::slot(*this, &Constructor::on_btn_exclusa_drag_get));
71 btn_y->signal_drag_data_get().connect( SigC::slot(*this, &Constructor::on_btn_y_drag_get));
72 btn_codo->signal_drag_data_get().connect( SigC::slot(*this, &Constructor::on_btn_codo_drag_get));
73 btn_tanque->signal_drag_data_get().connect( SigC::slot(*this, &Constructor::on_btn_tanque_drag_get));
74 btn_drain->signal_drag_data_get().connect( SigC::slot(*this, &Constructor::on_btn_drain_drag_get));
75 btn_and->signal_drag_data_get().connect( SigC::slot(*this, &Constructor::on_btn_and_drag_get));
76 btn_or->signal_drag_data_get().connect( SigC::slot(*this, &Constructor::on_btn_or_drag_get));
77 btn_not->signal_drag_data_get().connect( SigC::slot(*this, &Constructor::on_btn_not_drag_get));
78 btn_check->signal_clicked().connect(SigC::slot(*this,&Constructor::on_btn_check_clicked));
79 btn_dlg_close->signal_clicked().connect(SigC::slot(*this,&Constructor::on_btn_dlg_connect_clicked));
80 chk_btn_logica->signal_clicked().connect(SigC::slot(*this, &Constructor::on_chk_btn_clicked));
81 quick_btn_new->signal_clicked().connect(SigC::slot(*this, &Constructor::on_quick_btn_new_clicked));
82 quick_btn_save->signal_clicked().connect(SigC::slot(*this, &Constructor::on_quick_btn_save_clicked));
83 quick_btn_open->signal_clicked().connect(SigC::slot(*this, &Constructor::on_main_menu_open));
85 main_menu_quit->signal_activate().connect(SigC::slot(*this, &Constructor::on_main_menu_quit));
86 main_menu_new->signal_activate().connect(SigC::slot(*this, &Constructor::on_quick_btn_new_clicked));
87 main_menu_open->signal_activate().connect(SigC::slot(*this, &Constructor::on_main_menu_open));
88 main_menu_save->signal_activate().connect(SigC::slot(*this, &Constructor::on_main_menu_save));
89 edit_menu_del->signal_activate().connect(SigC::slot(*this,&Constructor::on_edit_menu_del));
90 edit_menu_delete_all->signal_activate().connect(SigC::slot(*this,&Constructor::on_quick_btn_delete_all_clicked));
92 btn_file_cancel = file_selection->get_cancel_button();
93 btn_file_ok = file_selection->get_ok_button();
94 btn_file_ok->signal_clicked().connect(SigC::slot(*this,&Constructor::on_btn_file_ok_clicked));
95 btn_file_cancel->signal_clicked().connect(SigC::slot(*this,&Constructor::on_btn_file_cancel_clicked));
97 btn_open_cancel = file_open_selection->get_cancel_button();
98 btn_open_ok = file_open_selection->get_ok_button();
99 btn_open_ok->signal_clicked().connect(SigC::slot(*this,&Constructor::on_load_from_xml));
100 btn_open_cancel->signal_clicked().connect(SigC::slot(*this,&Constructor::on_btn_open_cancel_clicked));
102 // Señales para cambiar el icono cuando empieza el drag.
103 btn_canio->signal_drag_begin().connect( SigC::slot(*this, &Constructor::on_canio_drag_begin));
104 btn_y->signal_drag_begin().connect( SigC::slot(*this, &Constructor::on_y_drag_begin));
105 btn_codo->signal_drag_begin().connect( SigC::slot(*this, &Constructor::on_codo_drag_begin));
106 btn_tanque->signal_drag_begin().connect( SigC::slot(*this, &Constructor::on_tanque_drag_begin));
107 btn_bomba->signal_drag_begin().connect( SigC::slot(*this, &Constructor::on_bomba_drag_begin));
108 btn_exclusa->signal_drag_begin().connect( SigC::slot(*this, &Constructor::on_exclusa_drag_begin));
109 btn_drain->signal_drag_begin().connect( SigC::slot(*this, &Constructor::on_drain_drag_begin));
110 btn_and->signal_drag_begin().connect( SigC::slot(*this, &Constructor::on_and_drag_begin));
111 btn_or->signal_drag_begin().connect( SigC::slot(*this, &Constructor::on_or_drag_begin));
112 btn_not->signal_drag_begin().connect( SigC::slot(*this, &Constructor::on_not_drag_begin));
113 workplace->drag_dest_set(listTargets);
114 workplace->signal_drag_data_received().connect( SigC::slot(*this, &Constructor::on_item_drop_drag_received) );
115 workplace->listaItems = &listaItems;
116 workplace->lista_logic_Items = &lista_logic_Items;
120 Constructor::~Constructor()
122 Constructor::on_edit_menu_delete_all();
125 void Constructor::on_btn_canio_drag_get(const Glib::RefPtr<Gdk::DragContext>& context, GtkSelectionData* selection_data, guint info, guint time)
127 gtk_selection_data_set (selection_data, selection_data->target, 8, (const guchar*)"canio_n.png", 12);
130 void Constructor::on_btn_y_drag_get(const Glib::RefPtr<Gdk::DragContext>& context, GtkSelectionData* selection_data, guint info, guint time)
132 gtk_selection_data_set(selection_data, selection_data->target, 8,(const guchar*)"y_n.png",8);
135 void Constructor::on_btn_codo_drag_get(const Glib::RefPtr<Gdk::DragContext>& context, GtkSelectionData* selection_data, guint info, guint time)
137 gtk_selection_data_set(selection_data, selection_data->target, 8 ,(const guchar*)"codo_o.png",10);
140 void Constructor::on_btn_tanque_drag_get(const Glib::RefPtr<Gdk::DragContext>& context, GtkSelectionData* selection_data, guint info, guint time)
142 gtk_selection_data_set(selection_data, selection_data->target, 8,(const guchar*)"tanque_e.png",12);
145 void Constructor::on_btn_bomba_drag_get(const Glib::RefPtr<Gdk::DragContext>& context, GtkSelectionData* selection_data, guint info, guint time)
147 gtk_selection_data_set(selection_data, selection_data->target, 8,(const guchar*)"bomba_e.png",11);
150 void Constructor::on_btn_exclusa_drag_get(const Glib::RefPtr<Gdk::DragContext>& context, GtkSelectionData* selection_data, guint info, guint time)
152 gtk_selection_data_set(selection_data, selection_data->target, 8,(const guchar*)"exclusa_h.png",13);
155 void Constructor::on_btn_drain_drag_get(const Glib::RefPtr<Gdk::DragContext>& context, GtkSelectionData* selection_data, guint info, guint time)
157 gtk_selection_data_set(selection_data, selection_data->target, 8,(const guchar*)"drain_n.png",11);
160 void Constructor::on_btn_and_drag_get(const Glib::RefPtr<Gdk::DragContext>& context, GtkSelectionData* selection_data, guint info, guint time)
162 gtk_selection_data_set(selection_data, selection_data->target, 8,(const guchar*)"and_e.png",9);
165 void Constructor::on_btn_or_drag_get(const Glib::RefPtr<Gdk::DragContext>& context, GtkSelectionData* selection_data, guint info, guint time)
167 gtk_selection_data_set(selection_data, selection_data->target, 8,(const guchar*)"or_e.png",8);
170 void Constructor::on_btn_not_drag_get(const Glib::RefPtr<Gdk::DragContext>& context, GtkSelectionData* selection_data, guint info, guint time)
172 gtk_selection_data_set(selection_data, selection_data->target, 8,(const guchar*)"not_e.png",9);
176 void Constructor::on_main_menu_quit()
183 void Constructor::on_main_menu_open()
185 // Conecto el boton OK para llamar al cargar del XML
186 file_open_selection->show();
189 void Constructor::on_main_menu_save()
191 // Conecto el boton OK para llamar al salvar
193 if ( ! check_connection(name) ) {
194 dlg_connect->set_title("Error");
195 dlg_label->set_text("El elemento "+name+" no esta conectado\n\t\tcorrectamente");
198 file_selection->show();
201 void Constructor::on_edit_menu_del()
203 workplace->delete_item(WorkPlace::pointed);
206 void Constructor::on_edit_menu_delete_all()
208 std::list<CItem *>::iterator i = listaItems.begin();
209 while ( i != listaItems.end() ) {
210 (*i)->workplace->delete_item((*i)->get_id());
211 i = listaItems.begin();
213 i = lista_logic_Items.begin();
214 while ( i != lista_logic_Items.end() ) {
215 (*i)->workplace->delete_item((*i)->get_id());
216 i=lista_logic_Items.begin();
221 void Constructor::on_chk_btn_clicked()
224 CItem::logic_connect = !CItem::logic_connect;
227 void Constructor::on_load_from_xml()
229 on_edit_menu_delete_all();
230 file_name = file_open_selection->get_filename();
232 /* Parseo de ejemplo de un XML desde archivo */
234 document = xmlParseFile(file_name.c_str());
235 if (document == NULL) {
236 // TODO : dar un aviso de que no se pudo abrir el archivo!!
240 /* bien, el archivo se parseo bien! */
241 xmlNodePtr nodo, items;
242 nodo = document->children;
246 if (strcmp((char *)nodo->name, "planta") == 0) {
247 items = nodo->children;
248 while (items != NULL) {
250 if (items->type == XML_ELEMENT_NODE) {
251 std::cout << "ITEM" << std::endl;
252 if (xmlStrcmp(items->name, BAD_CAST"bomba")==0) {
253 current = loadBomba(items);
254 } else if (xmlStrcmp(items->name, BAD_CAST"tubo")==0) {
255 current = loadConduct(items);
256 } else if (xmlStrcmp(items->name, BAD_CAST"codo")==0) {
257 current = loadCodo(items);
258 } else if (xmlStrcmp(items->name, BAD_CAST"exclusa")==0) {
259 current = loadExclusa(items);
260 } else if (xmlStrcmp(items->name, BAD_CAST"tanque")==0) {
261 current = loadTank(items);
262 } else if (xmlStrcmp(items->name, BAD_CAST"empalme")==0) {
263 current = loadUnion(items);
264 } else if (xmlStrcmp(items->name, BAD_CAST"drenaje")==0) {
265 current = loadDrain(items);
268 if (current != NULL) {
269 // Agrego y conecto la bomba
270 listaItems.push_back(current);
271 current->drag_source_set(listTargets);
272 workplace->put(*current, current->get_position_x(), current->get_position_y());
273 //Apunto al workplace
274 current->workplace= workplace;
276 current->combo_entry = combo_entry;
277 //Apunto a la listaItems.
278 current->listaItems = &listaItems;
279 //Apunto a la lista de items logicos
280 current->lista_logic_Items = &lista_logic_Items;
281 // Conecto las señales
282 current->signal_drag_data_get().connect( SigC::slot(*this, &Constructor::on_item_drag_data_get));
283 current->signal_drag_begin().connect(SigC::bind( SigC::slot(*this, &Constructor::on_item_drag_begin), current));
290 // TODO : avisar que el XML no es valido!!
292 std::cout << "CARGA COMPLETA" << std::endl;
293 file_open_selection->hide();
294 id = listaItems.size()+lista_logic_Items.size()+1;
297 void Constructor::on_btn_file_ok_clicked()
299 std::list<CItem *>::iterator i = listaItems.begin();
300 file_name = file_selection->get_filename();
302 if ( (archivo = fopen( file_name.c_str(), "w+")) != NULL ){
303 fprintf(archivo, "<?xml version=\"1.0\" encoding=\"iso-8859-1\" ?>\n");
304 fprintf (archivo,"<planta>\n");
305 while ( i != listaItems.end() ){
309 i = lista_logic_Items.begin();
310 while ( i != lista_logic_Items.end() ) {
314 fprintf(archivo,"</planta>\n");
318 std::cout<<"NO SE ABRIO EL ARCHIVO"<<std::endl;
319 file_selection->hide();
322 void Constructor::on_quick_btn_save_clicked()
327 on_btn_file_ok_clicked();
331 void Constructor::on_quick_btn_new_clicked()
333 on_quick_btn_delete_all_clicked();
337 void Constructor::on_quick_btn_delete_all_clicked()
339 std::list<CItem *>::iterator i = listaItems.begin();
340 while ( i != listaItems.end() ){
344 i = listaItems.begin();
346 i = lista_logic_Items.begin();
347 while ( i != lista_logic_Items.end() ){
349 lista_logic_Items.erase(i);
351 i = lista_logic_Items.begin();
356 void Constructor::on_btn_file_cancel_clicked()
358 file_selection->hide();
361 void Constructor::on_btn_open_cancel_clicked()
363 file_open_selection->hide();
366 void Constructor::on_btn_dlg_connect_clicked()
371 void Constructor::on_canio_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)
373 context->set_icon(ico_canio, 5, 5);
376 void Constructor::on_y_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)
378 context->set_icon(ico_y, 5, 5);
381 void Constructor::on_codo_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)
383 context->set_icon(ico_codo, 5, 5);
386 void Constructor::on_tanque_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)
388 context->set_icon(ico_tanque, 5, 5);
391 void Constructor::on_bomba_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)
393 context->set_icon(ico_bomba, 5, 5);
396 void Constructor::on_exclusa_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)
398 context->set_icon(ico_exclusa, 5, 5);
401 void Constructor::on_drain_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)
403 context->set_icon(ico_drain, 5, 5);
406 void Constructor::on_and_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)
408 context->set_icon(ico_and, 5, 5);
411 void Constructor::on_or_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)
413 context->set_icon(ico_or, 5, 5);
416 void Constructor::on_not_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)
418 context->set_icon(ico_not, 5, 5);
421 void Constructor::on_item_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context, CItem *item)
423 context->set_icon(item->get_image(), 5, 5);
426 void Constructor::on_item_drag_data_get(const Glib::RefPtr<Gdk::DragContext>& context, GtkSelectionData* selection_data, guint info, guint time)
428 gtk_selection_data_set (selection_data, selection_data->target, 10, (const guchar*)"item_codo.png", 13);
431 bool Constructor::can_drop(CItem *item, int _x, int _y)
433 std::list<CItem*>::iterator i = listaItems.begin();
434 while( i != listaItems.end() ) {
436 if ( temp->get_id() != item->get_id() ) {
437 if ( (temp->is_occupied_area(_x, _y)) ||
438 ( temp->is_occupied_area(_x+item->get_image()->get_width()-1, _y+item->get_image()->get_height()-1)) ||
439 ( temp->is_occupied_area(_x, _y+item->get_image()->get_height()-1)) ||
440 ( temp->is_occupied_area(_x+item->get_image()->get_width()-1, _y) ) )
449 void Constructor::on_item_drop_drag_received(const Glib::RefPtr<Gdk::DragContext>& context, int x, int y, GtkSelectionData* selection_data, guint info, guint time)
451 workplace->update_logic_position();
452 workplace->queue_draw();
454 /* Ajusto coordenada x e y para que caigan en un lugar de una cuadricula de 32x32 */
456 // el +1 es para evitar un bug cuando se selecciona muy cerce de la
457 // separacion de 2 cuadritos
460 // El drag es de un item
461 if (selection_data->format == 10) {
462 if (can_drop(((CItem*)drag_get_source_widget(context)),i*32, j*32)){
463 ((CItem*)drag_get_source_widget(context))->set_position(i*32, j*32);
464 workplace->move(*drag_get_source_widget(context), i*32, j*32);
468 // El Drag es desde la barra de tareas
469 if ((selection_data->length >= 0) && (selection_data->format == 8)) {
471 if (strcmp((const char *)selection_data->data, "codo_o.png")==0)
473 else if (strcmp((const char *)selection_data->data, "canio_n.png")==0)
475 else if (strcmp((const char *)selection_data->data, "y_n.png")==0)
477 else if (strcmp((const char *)selection_data->data, "tanque_e.png")==0)
479 else if (strcmp((const char *)selection_data->data, "bomba_e.png")==0)
481 else if (strcmp((const char *)selection_data->data, "exclusa_h.png")==0)
483 else if (strcmp((const char *)selection_data->data, "drain_n.png")==0)
485 else if (strcmp((const char *)selection_data->data, "and_e.png")==0){
486 a = new And(); a->is_logic = true;
487 } else if (strcmp((const char *)selection_data->data, "or_e.png")==0) {
488 a = new Or(); a->is_logic = true;
489 } else if (strcmp((const char *)selection_data->data, "not_e.png")==0) {
490 a = new Not(); a->is_logic = true;
494 sprintf(char_id,"%d",id);
496 a->set_name( a->get_name()+char_id );
497 if ( can_drop(a, i*32, j*32) ) {
498 workplace->put(*a, i*32, j*32);
499 //Apunto al workplace
500 a->workplace= workplace;
502 a->combo_entry = combo_entry;
503 //Apunto a la listaItems.
504 a->listaItems = &listaItems;
505 //Apunto a la lista de items logicos
506 a->lista_logic_Items = &lista_logic_Items;
507 //Seteo la posicion del item
508 a->set_position(i*32,j*32);
509 // Seteo la lista de tipos de drags
510 a->drag_source_set(listTargets);
511 // Conecto las señales
512 a->signal_drag_data_get().connect( SigC::slot(*this, &Constructor::on_item_drag_data_get));
513 // Utilizo el SigC::bind para que el callback on_drag_begin acepte un
514 // parametro extra, en este caso un CItem *. Esto se hace para
515 // que cuando el usuario quiera mover un item, saber que item es
516 // y pedirle su ícono para mostrar cono icono durante la operacion,
517 // Esto va a permitir, que si un widget tiene una imagen rotara o algo
518 // raro se vea el widget tal cual.
519 a->signal_drag_begin().connect(SigC::bind( SigC::slot(*this, &Constructor::on_item_drag_begin), a));
522 listaItems.push_back(a);
524 lista_logic_Items.push_back(a);
530 context->drag_finish(false, false, time);
532 workplace->update_logic_position();
533 workplace->queue_draw();
536 void Constructor::on_btn_check_clicked()
539 if ( ! check_connection(name) ) {
540 dlg_connect->set_title("Error");
541 dlg_label->set_text("El elemento "+name+" no esta conectado\n\t\tcorrectamente");
544 dlg_connect->set_title("Conexion");
545 dlg_label->set_text("Los elementos estan conectados\n\t\tcorrectamente");
551 bool Constructor::check_connection(Glib::ustring& name)
553 std::list<CItem *>::iterator i = listaItems.begin();
554 while ( i != listaItems.end() ){
555 (*i)->set_default_connector();
556 (*i)->is_connected = false;
559 i = listaItems.begin();
560 if ( !listaItems.empty() ) {
561 while ( i != listaItems.end() ) {
563 std::cout<< "item="<<temp->get_name()<<" "<<"check= "<<temp->check_connection()<<std::endl;
564 if ( !temp->check_connection() ) {
565 name = temp->get_name();
571 std::cout<<"check_connection logic"<<std::endl;
572 std::list<CItem *>::iterator j = lista_logic_Items.begin();
573 while ( j != lista_logic_Items.end() ) {
574 if ( !(*j)->check_connection() ) {
575 name = (*j)->get_name();
583 Pump *Constructor::loadBomba(xmlNodePtr nodo)
585 std::string name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
586 std::string id = (char *)xmlGetProp(nodo, BAD_CAST"id");
587 int orientacion=0, x, y;
590 nodo = nodo->children;
591 while (nodo != NULL) {
592 if (nodo->type == XML_ELEMENT_NODE) {
593 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
594 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
595 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
596 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
597 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
598 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
599 } else if (xmlStrcmp(nodo->name, BAD_CAST"entrega") == 0) {
600 flujo = atof( (char *)XML_GET_CONTENT(nodo->children) );
601 } else if (xmlStrcmp(nodo->name, BAD_CAST"color") == 0) {
608 Pump *p = new Pump(orientacion);
609 p->set_position(x,y);
610 p->set_entrega(flujo);
611 p->set_id( atoi(id.c_str()) );
617 Conduct *Constructor::loadConduct(xmlNodePtr nodo)
619 std::string name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
620 std::string id = (char *)xmlGetProp(nodo, BAD_CAST"id");
621 int orientacion=0, x, y;
624 nodo = nodo->children;
625 while (nodo != NULL) {
626 if (nodo->type == XML_ELEMENT_NODE) {
627 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
628 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
629 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
630 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
631 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
632 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
633 } else if (xmlStrcmp(nodo->name, BAD_CAST"caudal") == 0) {
634 flujo = atof( (char *)XML_GET_CONTENT(nodo->children) );
640 Conduct *p = new Conduct(orientacion);
641 p->set_position(x,y);
642 p->set_caudal(flujo);
643 p->set_id( atoi(id.c_str()) );
649 Exclusa *Constructor::loadExclusa(xmlNodePtr nodo)
651 std::string name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
652 std::string id = (char *)xmlGetProp(nodo, BAD_CAST"id");
654 int orientacion=0, x, y;
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"estado") == 0) {
667 estado = (char *)XML_GET_CONTENT(nodo->children);
673 Exclusa *p = new Exclusa(orientacion);
674 p->set_position(x,y);
675 p->set_id( atoi(id.c_str()) );
677 p->set_estado( estado == "1" );
682 Cistern *Constructor::loadTank(xmlNodePtr nodo)
684 std::string name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
685 std::string id = (char *)xmlGetProp(nodo, BAD_CAST"id");
686 int orientacion=0, x, y;
687 float liquido,capacidad;
689 nodo = nodo->children;
690 while (nodo != NULL) {
691 if (nodo->type == XML_ELEMENT_NODE) {
692 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
693 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
694 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
695 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
696 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
697 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
698 } else if (xmlStrcmp(nodo->name, BAD_CAST"capacidad") == 0) {
699 capacidad = atof ((char *)XML_GET_CONTENT(nodo->children) );
700 } else if (xmlStrcmp(nodo->name, BAD_CAST"inicial") == 0) {
701 liquido = atof ((char *)XML_GET_CONTENT(nodo->children) );
707 Cistern *p = new Cistern(orientacion);
708 p->set_position(x,y);
709 p->set_id( atoi(id.c_str()) );
711 p->set_capacidad(capacidad);
712 p->set_contenido_inicial(liquido);
717 Union *Constructor::loadUnion(xmlNodePtr nodo)
719 std::string name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
720 std::string id = (char *)xmlGetProp(nodo, BAD_CAST"id");
722 int orientacion=0, x, y;
725 nodo = nodo->children;
726 while (nodo != NULL) {
727 if (nodo->type == XML_ELEMENT_NODE) {
728 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
729 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
730 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
731 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
732 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
733 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
734 } else if (xmlStrcmp(nodo->name, BAD_CAST"caudal") == 0) {
735 caudal = atof ((char *)XML_GET_CONTENT(nodo->children) );
736 } else if (xmlStrcmp(nodo->name, BAD_CAST"tipo") == 0) {
737 tipo = (char *)XML_GET_CONTENT(nodo->children);
743 Union *p = new Union(orientacion);
744 p->set_position(x,y);
745 p->set_id( atoi(id.c_str()) );
747 p->set_caudal(caudal);
748 p->is_union = (tipo == "union");
753 Drain *Constructor::loadDrain(xmlNodePtr nodo)
755 std::string name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
756 std::string id = (char *)xmlGetProp(nodo, BAD_CAST"id");
757 int orientacion=0, x, y;
759 nodo = nodo->children;
760 while (nodo != NULL) {
761 if (nodo->type == XML_ELEMENT_NODE) {
762 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
763 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
764 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
765 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
766 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
767 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
773 Drain *p = new Drain(orientacion);
774 p->set_position(x,y);
775 p->set_id( atoi(id.c_str()) );
781 Splitter *Constructor::loadCodo(xmlNodePtr nodo)
783 std::string name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
784 std::string id = (char *)xmlGetProp(nodo, BAD_CAST"id");
785 int orientacion=0, x, y;
788 nodo = nodo->children;
789 while (nodo != NULL) {
790 if (nodo->type == XML_ELEMENT_NODE) {
791 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
792 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
793 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
794 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
795 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
796 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
797 } else if (xmlStrcmp(nodo->name, BAD_CAST"caudal") == 0) {
798 caudal = atof( (char *)XML_GET_CONTENT(nodo->children) );
804 Splitter *p = new Splitter(orientacion);
805 p->set_position(x,y);
806 p->set_id( atoi(id.c_str()) );
808 p->set_caudal(caudal);