]> git.llucax.com Git - z.facultad/75.42/plaqui.git/blob - Constructor/src/constructor.cpp
* Se agrega carga de una planta desde un XML (Archivo->Abrir)
[z.facultad/75.42/plaqui.git] / Constructor / src / constructor.cpp
1 #include "constructor.h"
2
3 Constructor::Constructor(BaseObjectType* cobject, const Glib::RefPtr<Gnome::Glade::Xml>& refGlade):Gtk::Window(cobject)
4 {
5         id = 0;
6         set_title("Constructor");
7         
8         
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");
19         
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);
42         
43         refGlade->get_widget_derived("workplace", workplace);  //fixed
44         
45         //Targets
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") );
50         
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);
61         
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));
75         
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));
80                         
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));
85         
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));
90
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;      
106         logica = false;
107 }
108
109 Constructor::~Constructor()
110 {
111         std::list<CItem *>::iterator i = listaItems.begin();
112         while ( i != listaItems.end() ){
113                 CItem *temp = *i;
114                 listaItems.erase(i);
115                 delete temp;
116                 i = listaItems.begin();
117         }
118 }
119
120 void Constructor::on_btn_canio_drag_get(const Glib::RefPtr<Gdk::DragContext>& context, GtkSelectionData* selection_data, guint info, guint time)
121 {
122         gtk_selection_data_set (selection_data, selection_data->target, 8, (const guchar*)"canio_n.png", 12);
123 }
124
125 void Constructor::on_btn_y_drag_get(const Glib::RefPtr<Gdk::DragContext>& context, GtkSelectionData* selection_data, guint info, guint time)
126 {
127         gtk_selection_data_set(selection_data, selection_data->target, 8,(const guchar*)"y_n.png",8);
128 }
129
130 void Constructor::on_btn_codo_drag_get(const Glib::RefPtr<Gdk::DragContext>& context, GtkSelectionData* selection_data, guint info, guint time)
131 {
132         gtk_selection_data_set(selection_data, selection_data->target, 8 ,(const guchar*)"codo_o.png",10);
133 }
134
135 void Constructor::on_btn_tanque_drag_get(const Glib::RefPtr<Gdk::DragContext>& context, GtkSelectionData* selection_data, guint info, guint time)
136 {
137         gtk_selection_data_set(selection_data, selection_data->target, 8,(const guchar*)"tanque_e.png",12);
138 }
139
140 void Constructor::on_btn_bomba_drag_get(const Glib::RefPtr<Gdk::DragContext>& context, GtkSelectionData* selection_data, guint info, guint time)
141 {
142         gtk_selection_data_set(selection_data, selection_data->target, 8,(const guchar*)"bomba_e.png",11);
143 }
144
145 void Constructor::on_btn_exclusa_drag_get(const Glib::RefPtr<Gdk::DragContext>& context, GtkSelectionData* selection_data, guint info, guint time)
146 {
147         gtk_selection_data_set(selection_data, selection_data->target, 8,(const guchar*)"exclusa_h.png",13);
148 }
149
150 void Constructor::on_btn_drain_drag_get(const Glib::RefPtr<Gdk::DragContext>& context, GtkSelectionData* selection_data, guint info, guint time)
151 {
152         gtk_selection_data_set(selection_data, selection_data->target, 8,(const guchar*)"drain_n.png",11);
153 }
154
155 void Constructor::on_btn_and_drag_get(const Glib::RefPtr<Gdk::DragContext>& context, GtkSelectionData* selection_data, guint info, guint time)
156 {
157         gtk_selection_data_set(selection_data, selection_data->target, 8,(const guchar*)"and_e.png",9);
158 }
159
160 void Constructor::on_btn_or_drag_get(const Glib::RefPtr<Gdk::DragContext>& context, GtkSelectionData* selection_data, guint info, guint time)
161 {
162         gtk_selection_data_set(selection_data, selection_data->target, 8,(const guchar*)"or_e.png",8);
163 }
164
165 void Constructor::on_btn_not_drag_get(const Glib::RefPtr<Gdk::DragContext>& context, GtkSelectionData* selection_data, guint info, guint time)
166 {
167         gtk_selection_data_set(selection_data, selection_data->target, 8,(const guchar*)"not_e.png",9);
168 }
169
170
171 void Constructor::on_main_menu_quit()
172 {
173         delete this;
174         Gtk::Main::quit();
175         //hide();
176 }
177
178 void Constructor::on_main_menu_open()
179 {
180         // Conecto el boton OK para llamar al cargar del XML
181         file_open_selection->show();
182 }
183
184 void Constructor::on_main_menu_save()
185 {
186         // Conecto el boton OK para llamar al salvar
187         file_selection->show();
188 }
189
190 void Constructor::on_edit_menu_del()
191 {  // OJO que borra al primero que encuentra con el mismo nombre!!!
192         std::list<CItem *>::iterator i = listaItems.begin();
193         Glib::ustring pointed = combo_entry->get_text();
194         while ( i != listaItems.end() ){
195                 CItem *temp = *i;
196                 if ( temp->get_name() == pointed ){ 
197                         workplace->delete_item(temp->get_id());
198                         break;
199                 }
200         i++;
201         }
202 }
203
204 void Constructor::on_chk_btn_clicked()
205 {
206         logica = !logica;
207 }
208
209 void Constructor::on_load_from_xml()
210 {
211         std::string file_name = file_open_selection->get_filename();
212
213         /* Parseo de ejemplo de un XML desde archivo */
214         xmlDocPtr document;
215         document = xmlParseFile(file_name.c_str());
216         if (document == NULL) {
217                 // TODO : dar un aviso de que no se pudo abrir el archivo!!
218                 return;
219         }
220
221         /* bien, el archivo se parseo bien! */
222         xmlNodePtr nodo, items;
223         nodo = document->children;
224
225         // Recorro los items
226         CItem *current;
227         if (strcmp((char *)nodo->name, "planta") == 0) {
228                 items = nodo->children;
229                 while (items != NULL) {
230                         current = 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);
247                                 }
248
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;
256                                         //Apunto a la lista.
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));
265                                         current->show();        
266                                 }
267                         }
268                         items = items->next;
269                 }
270         } else {
271                 // TODO : avisar que el XML no es valido!!
272         }
273         std::cout << "CARGA COMPLETA" << std::endl;
274         file_open_selection->hide();
275 }
276 void Constructor::on_btn_file_ok_clicked()
277 {
278         std::list<CItem *>::iterator i = listaItems.begin();
279         std::string file_name = file_selection->get_filename();
280         if ( (archivo = fopen( file_name.c_str(), "w+")) != NULL ){
281                 fprintf(archivo, "<?xml version=\"1.0\" encoding=\"iso-8859-1\" ?>\n");
282                 fprintf (archivo,"<planta>\n");
283                 while ( i != listaItems.end() ){
284                         CItem *temp = *i;
285                         temp->save(archivo);
286                         i++;
287                 }
288                 fprintf(archivo,"</planta>\n");
289         } else 
290                 std::cout<<"NO SE ABRIO EL ARCHIVO"<<std::endl;
291         fclose(archivo);
292         file_selection->hide();
293 }
294
295 void Constructor::on_btn_file_cancel_clicked()
296 {
297         file_selection->hide();
298 }
299
300 void Constructor::on_btn_open_cancel_clicked()
301 {
302         file_open_selection->hide();
303 }
304
305 void Constructor::on_btn_dlg_connect_clicked()
306 {
307         dlg_connect->hide();
308 }
309
310 void Constructor::on_canio_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)
311 {
312         context->set_icon(ico_canio, 5, 5); 
313 }
314
315 void Constructor::on_y_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)
316 {
317         context->set_icon(ico_y, 5, 5); 
318 }
319
320 void Constructor::on_codo_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)
321 {
322         context->set_icon(ico_codo, 5, 5); 
323 }
324
325 void Constructor::on_tanque_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)
326 {
327         context->set_icon(ico_tanque, 5, 5); 
328 }
329
330 void Constructor::on_bomba_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)
331 {
332         context->set_icon(ico_bomba, 5, 5); 
333 }
334
335 void Constructor::on_exclusa_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)
336 {
337         context->set_icon(ico_exclusa, 5, 5); 
338 }
339
340 void Constructor::on_drain_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)
341 {
342         context->set_icon(ico_drain, 5, 5); 
343 }
344
345 void Constructor::on_and_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)
346 {
347         context->set_icon(ico_and, 5, 5); 
348 }
349
350 void Constructor::on_or_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)
351 {
352         context->set_icon(ico_or, 5, 5); 
353 }
354
355 void Constructor::on_not_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)
356 {
357         context->set_icon(ico_not, 5, 5); 
358 }
359
360 void Constructor::on_item_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context, CItem *item)
361 {
362         GdkEventExpose e;
363         context->set_icon(item->get_image(), 5, 5);
364         workplace->on_expose_event(&e);
365 }
366
367 void Constructor::on_item_drag_data_get(const Glib::RefPtr<Gdk::DragContext>& context, GtkSelectionData* selection_data, guint info, guint time)
368 {       
369                 gtk_selection_data_set (selection_data, selection_data->target, 10, (const guchar*)"item_codo.png", 13);
370 }
371
372 bool Constructor::can_drop(CItem *item, int _x, int _y)
373 {
374         std::list<CItem*>::iterator  i = listaItems.begin();
375         while( i != listaItems.end() ) {
376                 CItem *temp = *i;
377                 if ( temp->get_id() != item->get_id()   ) {
378                         if (  (temp->is_occupied_area(_x, _y))  ||  
379                                 ( temp->is_occupied_area(_x+item->get_image()->get_width()-1, _y+item->get_image()->get_height()-1))  ||
380                                 ( temp->is_occupied_area(_x, _y+item->get_image()->get_height()-1)) ||
381                                 ( temp->is_occupied_area(_x+item->get_image()->get_width()-1, _y) ) ) 
382                                 return false;
383                         else i++;
384                 }
385                 else i++;
386         }
387         return true;
388 }
389
390 void Constructor::on_item_drop_drag_received(const Glib::RefPtr<Gdk::DragContext>& context, int x, int y, GtkSelectionData* selection_data, guint info, guint time)
391 {
392         if ( !logica ) {
393                 /* Ajusto coordenada x e y para que caigan en un lugar de una cuadricula de 32x32 */
394                 int i,j;
395                 // el +1 es para evitar un bug cuando se selecciona muy cerce de la
396                 // separacion de 2 cuadritos
397                 i = (x+1)/32;
398                 j = (y+1)/32;
399                 // El drag es de un item
400                 if (selection_data->format == 10) {
401                         if (can_drop(((CItem*)drag_get_source_widget(context)),i*32, j*32)){
402                                 ((CItem*)drag_get_source_widget(context))->set_position(i*32, j*32);
403                                 workplace->move(*drag_get_source_widget(context), i*32, j*32);
404                         }
405                 }
406
407                 // El Drag es desde la barra de tareas
408                 if ((selection_data->length >= 0) && (selection_data->format == 8))     {
409                         CItem *a;
410                         if (strcmp((const char *)selection_data->data, "codo_o.png")==0) 
411                         a = new Splitter();
412                         else    if (strcmp((const char *)selection_data->data, "canio_n.png")==0) 
413                         a = new Conduct();
414                         else if (strcmp((const char *)selection_data->data, "y_n.png")==0) 
415                         a = new Union();
416                         else if (strcmp((const char *)selection_data->data, "tanque_e.png")==0) 
417                         a = new Cistern();
418                         else if (strcmp((const char *)selection_data->data, "bomba_e.png")==0) 
419                         a =new Pump();
420                         else if (strcmp((const char *)selection_data->data, "exclusa_h.png")==0) 
421                         a = new Exclusa();
422                         else if (strcmp((const char *)selection_data->data, "drain_n.png")==0) 
423                         a = new Drain();
424                         else if (strcmp((const char *)selection_data->data, "and_e.png")==0){ 
425                         a = new And(); a->is_logic = true;
426                         } else if (strcmp((const char *)selection_data->data, "or_e.png")==0) {
427                                 a = new Or(); a->is_logic = true;
428                                 } else if (strcmp((const char *)selection_data->data, "not_e.png")==0) {
429                                         a = new Not();  a->is_logic = true;
430                                         }
431                 
432                         char char_id[10];
433                         sprintf(char_id,"%d",id);
434                         a->set_id(id++);                
435                         a->set_name( a->get_name()+char_id );
436                         if ( can_drop(a, i*32, j*32) ) {
437                                 workplace->put(*a, i*32, j*32);
438                                 //Apunto al workplace
439                                 a->workplace= workplace;
440                                 //Apunto a la lista.
441                                 a->combo_entry = combo_entry;
442                                 //Apunto a la listaItems.
443                                 a->listaItems = &listaItems;
444                                 //Apunto a la lista de items logicos
445                                 a->lista_logic_Items = &lista_logic_Items;
446                                 //Seteo la posicion del item
447                                 a->set_position(i*32,j*32);
448                                 // Seteo la lista de tipos de drags 
449                                 a->drag_source_set(listTargets);
450                                 // Conecto las señales
451                                 a->signal_drag_data_get().connect( SigC::slot(*this, &Constructor::on_item_drag_data_get));
452                                 // Utilizo el SigC::bind para que el callback on_drag_begin acepte un
453                                 // parametro extra, en este caso un CItem *. Esto se hace para
454                                 // que cuando el usuario quiera mover un item, saber que item es
455                                 // y pedirle su ícono para mostrar cono icono durante la operacion,
456                                 // Esto va a permitir, que si un widget tiene una imagen rotara o algo
457                                 // raro se vea el widget tal cual.
458                                 a->signal_drag_begin().connect(SigC::bind( SigC::slot(*this, &Constructor::on_item_drag_begin), a));
459                                 a->show();      
460                                 if (! a->is_logic )
461                                         listaItems.push_back(a);
462                                 else 
463                                         lista_logic_Items.push_back(a);
464                         } else {
465                                         id--;
466                                         delete a;
467                                 }
468                 }
469                 context->drag_finish(false, false, time);
470         }
471 }
472
473 void Constructor::on_btn_check_clicked()
474 {
475         std::list<CItem *>::iterator i = listaItems.begin();
476         while ( i != listaItems.end() ){
477                 (*i)->set_default_connector();
478                 (*i)->is_connected = false;
479                 i++;
480         }
481         
482         i = listaItems.begin();
483         if ( !listaItems.empty() ) {
484                 while ( i != listaItems.end() ) {
485                         CItem *temp = *i;
486                         std::cout<< "item="<<temp->get_name()<<" "<<"check= "<<temp->check_connection()<<std::endl;
487                         if ( !temp->check_connection() ) {
488                                 dlg_connect->set_title("Error");
489                                 dlg_label->set_text("Los elementos no estan conectados\n\t\tcorrectamente");
490                                 dlg_connect->show();
491                                 return;
492                         }       
493                 i++;
494                 }
495                 dlg_connect->set_title("Conexion");
496                 dlg_label->set_text("Los elementos estan conectados\n\t\tcorrectamente");
497                 dlg_connect->show();    
498         }
499 }
500
501 Pump *Constructor::loadBomba(xmlNodePtr nodo)
502 {
503         std::string name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
504         std::string id = (char *)xmlGetProp(nodo, BAD_CAST"id");
505         int orientacion=0, x, y;
506         float flujo;
507
508         nodo = nodo->children;
509         while (nodo != NULL) {
510                 if (nodo->type == XML_ELEMENT_NODE) {
511                         if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
512                                 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
513                         } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
514                                 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
515                         } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
516                                 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
517                         } else if (xmlStrcmp(nodo->name, BAD_CAST"entrega") == 0) {
518                                 flujo = atof( (char *)XML_GET_CONTENT(nodo->children) );
519                         } else if (xmlStrcmp(nodo->name, BAD_CAST"color") == 0) {
520                                 // FIXME !
521                         }
522                 }
523                 nodo = nodo->next;
524         }
525
526         Pump *p = new Pump(orientacion);
527         p->set_position(x,y);
528         p->set_entrega(flujo);
529         p->set_id( atoi(id.c_str()) );
530         p->set_name(name);
531
532         return p;
533 }
534
535 Conduct *Constructor::loadConduct(xmlNodePtr nodo)
536 {
537         std::string name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
538         std::string id = (char *)xmlGetProp(nodo, BAD_CAST"id");
539         int orientacion=0, x, y;
540         float flujo;
541
542         nodo = nodo->children;
543         while (nodo != NULL) {
544                 if (nodo->type == XML_ELEMENT_NODE) {
545                         if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
546                                 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
547                         } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
548                                 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
549                         } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
550                                 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
551                         } else if (xmlStrcmp(nodo->name, BAD_CAST"caudal") == 0) {
552                                 flujo = atof( (char *)XML_GET_CONTENT(nodo->children) );
553                         }
554                 }
555                 nodo = nodo->next;
556         }
557
558         Conduct *p = new Conduct(orientacion);
559         p->set_position(x,y);
560         p->set_caudal(flujo);
561         p->set_id( atoi(id.c_str()) );
562         p->set_name(name);
563
564         return p;
565 }
566
567 Exclusa *Constructor::loadExclusa(xmlNodePtr nodo)
568 {
569         std::string name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
570         std::string id = (char *)xmlGetProp(nodo, BAD_CAST"id");
571         std::string estado;
572         int orientacion=0, x, y;
573         float flujo;
574
575         nodo = nodo->children;
576         while (nodo != NULL) {
577                 if (nodo->type == XML_ELEMENT_NODE) {
578                         if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
579                                 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
580                         } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
581                                 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
582                         } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
583                                 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
584                         } else if (xmlStrcmp(nodo->name, BAD_CAST"estado") == 0) {
585                                 estado = (char *)XML_GET_CONTENT(nodo->children);
586                         }
587                 }
588                 nodo = nodo->next;
589         }
590
591         Exclusa *p = new Exclusa(orientacion);
592         p->set_position(x,y);
593         p->set_id( atoi(id.c_str()) );
594         p->set_name(name);
595         p->set_estado( estado == "1" );
596
597         return p;
598 }
599
600 Cistern *Constructor::loadTank(xmlNodePtr nodo)
601 {
602         std::string name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
603         std::string id = (char *)xmlGetProp(nodo, BAD_CAST"id");
604         int orientacion=0, x, y;
605         float liquido,capacidad;
606
607         nodo = nodo->children;
608         while (nodo != NULL) {
609                 if (nodo->type == XML_ELEMENT_NODE) {
610                         if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
611                                 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
612                         } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
613                                 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
614                         } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
615                                 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
616                         } else if (xmlStrcmp(nodo->name, BAD_CAST"capacidad") == 0) {
617                                 capacidad = atof ((char *)XML_GET_CONTENT(nodo->children) );
618                         } else if (xmlStrcmp(nodo->name, BAD_CAST"inicial") == 0) {
619                                 liquido = atof ((char *)XML_GET_CONTENT(nodo->children) );
620                         }
621                 }
622                 nodo = nodo->next;
623         }
624
625         Cistern *p = new Cistern(orientacion);
626         p->set_position(x,y);
627         p->set_id( atoi(id.c_str()) );
628         p->set_name(name);
629         p->set_capacidad(capacidad);
630         p->set_contenido_inicial(liquido);
631
632         return p;
633 }
634
635 Union *Constructor::loadUnion(xmlNodePtr nodo)
636 {
637         std::string name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
638         std::string id = (char *)xmlGetProp(nodo, BAD_CAST"id");
639         std::string tipo;
640         int orientacion=0, x, y;
641         float caudal;
642
643         nodo = nodo->children;
644         while (nodo != NULL) {
645                 if (nodo->type == XML_ELEMENT_NODE) {
646                         if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
647                                 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
648                         } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
649                                 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
650                         } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
651                                 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
652                         } else if (xmlStrcmp(nodo->name, BAD_CAST"caudal") == 0) {
653                                 caudal = atof ((char *)XML_GET_CONTENT(nodo->children) );
654                         } else if (xmlStrcmp(nodo->name, BAD_CAST"tipo") == 0) {
655                                 tipo = (char *)XML_GET_CONTENT(nodo->children);
656                         }
657                 }
658                 nodo = nodo->next;
659         }
660
661         Union *p = new Union(orientacion);
662         p->set_position(x,y);
663         p->set_id( atoi(id.c_str()) );
664         p->set_name(name);
665         p->set_caudal(caudal);
666         p->is_union = (tipo == "union");
667
668         return p;
669 }
670
671 Drain *Constructor::loadDrain(xmlNodePtr nodo)
672 {
673         std::string name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
674         std::string id = (char *)xmlGetProp(nodo, BAD_CAST"id");
675         int orientacion=0, x, y;
676
677         nodo = nodo->children;
678         while (nodo != NULL) {
679                 if (nodo->type == XML_ELEMENT_NODE) {
680                         if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
681                                 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
682                         } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
683                                 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
684                         } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
685                                 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
686                         }
687                 }
688                 nodo = nodo->next;
689         }
690
691         Drain *p = new Drain(orientacion);
692         p->set_position(x,y);
693         p->set_id( atoi(id.c_str()) );
694         p->set_name(name);
695
696         return p;
697 }
698
699 Splitter *Constructor::loadCodo(xmlNodePtr nodo)
700 {
701         std::string name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
702         std::string id = (char *)xmlGetProp(nodo, BAD_CAST"id");
703         int orientacion=0, x, y;
704         float caudal;
705
706         nodo = nodo->children;
707         while (nodo != NULL) {
708                 if (nodo->type == XML_ELEMENT_NODE) {
709                         if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
710                                 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
711                         } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
712                                 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
713                         } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
714                                 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
715                         } else if (xmlStrcmp(nodo->name, BAD_CAST"caudal") == 0) {
716                                 caudal = atof( (char *)XML_GET_CONTENT(nodo->children) );
717                         }
718                 }
719                 nodo = nodo->next;
720         }
721
722         Splitter *p = new Splitter(orientacion);
723         p->set_position(x,y);
724         p->set_id( atoi(id.c_str()) );
725         p->set_name(name);
726         p->set_caudal(caudal);
727
728         return p;
729 }
730