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