]> git.llucax.com Git - z.facultad/75.42/plaqui.git/blob - Constructor/src/constructor.cpp
corregi las imagenes del manual del usuario y agregue una mas
[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         saved = false;
7         set_title("Constructor");
8         
9         // Cargo todas las imagenes de los iconos de los botones
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");
20         
21         //Obtengo todos los widgets de la ventana principal.
22         refGlade->get_widget("btn_canio", btn_canio);
23         refGlade->get_widget("btn_codo", btn_codo);
24         refGlade->get_widget("btn_y", btn_y);
25         refGlade->get_widget("btn_tanque",btn_tanque);
26         refGlade->get_widget("btn_bomba", btn_bomba);
27         refGlade->get_widget("btn_exclusa", btn_exclusa);
28         refGlade->get_widget("btn_drain", btn_drain);
29         refGlade->get_widget("btn_and", btn_and);
30         refGlade->get_widget("btn_or", btn_or);
31         refGlade->get_widget("btn_not", btn_not);
32         refGlade->get_widget("main_menu_quit",main_menu_quit);
33         refGlade->get_widget("main_menu_new",main_menu_new);
34         refGlade->get_widget("main_menu_open",main_menu_open);
35         refGlade->get_widget("main_menu_save",main_menu_save);
36         refGlade->get_widget("edit_menu_del",edit_menu_del);
37         refGlade->get_widget("chk_btn_logica",chk_btn_logica);
38         refGlade->get_widget("file_open_selection",file_open_selection);
39         refGlade->get_widget("file_selection",file_selection);
40         refGlade->get_widget("combo_entry",combo_entry);
41         refGlade->get_widget("btn_check",btn_check);
42         refGlade->get_widget("dlg_connect", dlg_connect);
43         refGlade->get_widget("btn_dlg_close", btn_dlg_close);
44         refGlade->get_widget("dlg_label", dlg_label);
45         refGlade->get_widget("quick_btn_new", quick_btn_new);
46         refGlade->get_widget("quick_btn_save", quick_btn_save);
47         refGlade->get_widget("quick_btn_open", quick_btn_open);
48         refGlade->get_widget("edit_menu_delete_all", edit_menu_delete_all);
49         refGlade->get_widget("btn_find", btn_find);
50         refGlade->get_widget("status_bar", status_bar);
51         
52         //Obtengo el area de trabajo, la cual tiene definida su propia clase.
53         refGlade->get_widget_derived("workplace", workplace);  //fixed
54         
55         //Targets
56         listTargets.push_back( Gtk::TargetEntry("STRING") );
57         listTargets.push_back( Gtk::TargetEntry("text/plain") );
58         listTargets.push_back( Gtk::TargetEntry("POINTER") );
59         listTargets.push_back( Gtk::TargetEntry("application/pointer") );
60         
61         // Le indico cuales son los botones  desde los cuales se puede hacer un drag.
62         btn_canio->drag_source_set(listTargets);
63         btn_y->drag_source_set(listTargets);
64         btn_codo->drag_source_set(listTargets);
65         btn_tanque->drag_source_set(listTargets);
66         btn_bomba->drag_source_set(listTargets);
67         btn_drain->drag_source_set(listTargets);
68         btn_exclusa->drag_source_set(listTargets);
69         btn_and->drag_source_set(listTargets);
70         btn_or->drag_source_set(listTargets);
71         btn_not->drag_source_set(listTargets);
72         
73         //Conecto las señales de cada boton con su correspondiente metodo.
74         btn_canio->signal_drag_data_get().connect( SigC::slot(*this, &Constructor::on_btn_canio_drag_get));
75         btn_bomba->signal_drag_data_get().connect( SigC::slot(*this, &Constructor::on_btn_bomba_drag_get));
76         btn_exclusa->signal_drag_data_get().connect( SigC::slot(*this, &Constructor::on_btn_exclusa_drag_get));
77         btn_y->signal_drag_data_get().connect( SigC::slot(*this, &Constructor::on_btn_y_drag_get));
78         btn_codo->signal_drag_data_get().connect( SigC::slot(*this, &Constructor::on_btn_codo_drag_get));
79         btn_tanque->signal_drag_data_get().connect( SigC::slot(*this, &Constructor::on_btn_tanque_drag_get));
80         btn_drain->signal_drag_data_get().connect( SigC::slot(*this, &Constructor::on_btn_drain_drag_get));
81         btn_and->signal_drag_data_get().connect( SigC::slot(*this, &Constructor::on_btn_and_drag_get));
82         btn_or->signal_drag_data_get().connect( SigC::slot(*this, &Constructor::on_btn_or_drag_get));
83         btn_not->signal_drag_data_get().connect( SigC::slot(*this, &Constructor::on_btn_not_drag_get));
84         btn_check->signal_clicked().connect(SigC::slot(*this,&Constructor::on_btn_check_clicked));
85         btn_dlg_close->signal_clicked().connect(SigC::slot(*this,&Constructor::on_btn_dlg_connect_clicked));
86         btn_find->signal_clicked().connect(SigC::slot(*this,&Constructor::on_btn_find_clicked));        
87         chk_btn_logica->signal_clicked().connect(SigC::slot(*this, &Constructor::on_chk_btn_logica_clicked));
88         quick_btn_new->signal_clicked().connect(SigC::slot(*this, &Constructor::on_quick_btn_new_clicked));
89         quick_btn_save->signal_clicked().connect(SigC::slot(*this, &Constructor::on_quick_btn_save_clicked));
90         quick_btn_open->signal_clicked().connect(SigC::slot(*this, &Constructor::on_main_menu_open));
91         
92         main_menu_quit->signal_activate().connect(SigC::slot(*this, &Constructor::on_main_menu_quit));
93         main_menu_new->signal_activate().connect(SigC::slot(*this, &Constructor::on_quick_btn_new_clicked));
94         main_menu_open->signal_activate().connect(SigC::slot(*this, &Constructor::on_main_menu_open));
95         main_menu_save->signal_activate().connect(SigC::slot(*this, &Constructor::on_main_menu_save));
96         edit_menu_del->signal_activate().connect(SigC::slot(*this,&Constructor::on_edit_menu_del));
97         edit_menu_delete_all->signal_activate().connect(SigC::slot(*this,&Constructor::on_quick_btn_delete_all_clicked));
98         
99         //Obtengo y conecto los botones del dialogo de Salvar/Cargar un archivo.
100         btn_file_cancel = file_selection->get_cancel_button();
101         btn_file_ok = file_selection->get_ok_button();
102         btn_file_ok->signal_clicked().connect(SigC::slot(*this,&Constructor::on_btn_file_ok_clicked));
103         btn_file_cancel->signal_clicked().connect(SigC::slot(*this,&Constructor::on_btn_file_cancel_clicked));
104         btn_open_cancel = file_open_selection->get_cancel_button();
105         btn_open_ok = file_open_selection->get_ok_button();
106         btn_open_ok->signal_clicked().connect(SigC::slot(*this,&Constructor::on_load_from_xml));
107         btn_open_cancel->signal_clicked().connect(SigC::slot(*this,&Constructor::on_btn_open_cancel_clicked));
108
109         // Señales para cambiar el icono cuando empieza el drag.
110         btn_canio->signal_drag_begin().connect( SigC::slot(*this, &Constructor::on_canio_drag_begin));
111         btn_y->signal_drag_begin().connect( SigC::slot(*this, &Constructor::on_y_drag_begin));
112         btn_codo->signal_drag_begin().connect( SigC::slot(*this, &Constructor::on_codo_drag_begin));
113         btn_tanque->signal_drag_begin().connect( SigC::slot(*this, &Constructor::on_tanque_drag_begin));
114         btn_bomba->signal_drag_begin().connect( SigC::slot(*this, &Constructor::on_bomba_drag_begin));
115         btn_exclusa->signal_drag_begin().connect( SigC::slot(*this, &Constructor::on_exclusa_drag_begin));
116         btn_drain->signal_drag_begin().connect( SigC::slot(*this, &Constructor::on_drain_drag_begin));
117         btn_and->signal_drag_begin().connect( SigC::slot(*this, &Constructor::on_and_drag_begin));
118         btn_or->signal_drag_begin().connect( SigC::slot(*this, &Constructor::on_or_drag_begin));
119         btn_not->signal_drag_begin().connect( SigC::slot(*this, &Constructor::on_not_drag_begin));
120         workplace->drag_dest_set(listTargets);
121         workplace->signal_drag_data_received().connect( SigC::slot(*this, &Constructor::on_item_drop_drag_received) );  
122         // Apunto la lista del area de trabajo a la lista de items en el Constructor
123         workplace->listaItems = &listaItems;    
124         workplace->lista_logic_Items = &lista_logic_Items;      
125         workplace->logica = &logica;
126         logica = false;
127 }
128
129 Constructor::~Constructor()
130 {
131         // elimina todos los items 
132         Constructor::on_edit_menu_delete_all();
133 }
134
135 // Definicion de los metodos para obtener el icono al realizar un drag.
136 void Constructor::on_btn_canio_drag_get(const Glib::RefPtr<Gdk::DragContext>& context, GtkSelectionData* selection_data, guint info, guint time)
137 {
138         gtk_selection_data_set (selection_data, selection_data->target, 8, (const guchar*)"canio_n.png", 12);
139 }
140
141 void Constructor::on_btn_y_drag_get(const Glib::RefPtr<Gdk::DragContext>& context, GtkSelectionData* selection_data, guint info, guint time)
142 {
143         gtk_selection_data_set(selection_data, selection_data->target, 8,(const guchar*)"y_n.png",8);
144 }
145
146 void Constructor::on_btn_codo_drag_get(const Glib::RefPtr<Gdk::DragContext>& context, GtkSelectionData* selection_data, guint info, guint time)
147 {
148         gtk_selection_data_set(selection_data, selection_data->target, 8 ,(const guchar*)"codo_o.png",10);
149 }
150
151 void Constructor::on_btn_tanque_drag_get(const Glib::RefPtr<Gdk::DragContext>& context, GtkSelectionData* selection_data, guint info, guint time)
152 {
153         gtk_selection_data_set(selection_data, selection_data->target, 8,(const guchar*)"tanque_e.png",12);
154 }
155
156 void Constructor::on_btn_bomba_drag_get(const Glib::RefPtr<Gdk::DragContext>& context, GtkSelectionData* selection_data, guint info, guint time)
157 {
158         gtk_selection_data_set(selection_data, selection_data->target, 8,(const guchar*)"bomba_e.png",11);
159 }
160
161 void Constructor::on_btn_exclusa_drag_get(const Glib::RefPtr<Gdk::DragContext>& context, GtkSelectionData* selection_data, guint info, guint time)
162 {
163         gtk_selection_data_set(selection_data, selection_data->target, 8,(const guchar*)"exclusa_h.png",13);
164 }
165
166 void Constructor::on_btn_drain_drag_get(const Glib::RefPtr<Gdk::DragContext>& context, GtkSelectionData* selection_data, guint info, guint time)
167 {
168         gtk_selection_data_set(selection_data, selection_data->target, 8,(const guchar*)"drain_n.png",11);
169 }
170
171 void Constructor::on_btn_and_drag_get(const Glib::RefPtr<Gdk::DragContext>& context, GtkSelectionData* selection_data, guint info, guint time)
172 {
173         gtk_selection_data_set(selection_data, selection_data->target, 8,(const guchar*)"and_e.png",9);
174 }
175
176 void Constructor::on_btn_or_drag_get(const Glib::RefPtr<Gdk::DragContext>& context, GtkSelectionData* selection_data, guint info, guint time)
177 {
178         gtk_selection_data_set(selection_data, selection_data->target, 8,(const guchar*)"or_e.png",8);
179 }
180
181 void Constructor::on_btn_not_drag_get(const Glib::RefPtr<Gdk::DragContext>& context, GtkSelectionData* selection_data, guint info, guint time)
182 {
183         gtk_selection_data_set(selection_data, selection_data->target, 8,(const guchar*)"not_e.png",9);
184 }
185
186 //Sale del programa.
187 void Constructor::on_main_menu_quit()
188 {
189         delete this;
190         Gtk::Main::quit();
191         //hide();
192 }
193
194 // Carga de un archivo XML
195 void Constructor::on_main_menu_open()
196 {
197         // Conecto el boton OK para llamar al cargar del XML
198         file_open_selection->show();
199 }
200
201 // Salva un archivo XML
202 void Constructor::on_main_menu_save()
203 {
204         // Conecto el boton OK para llamar al salvar
205         Glib::ustring name;
206         if ( ! check_connection(name) ) {
207                 dlg_connect->set_title("Error");
208                 dlg_label->set_text("El elemento "+name+" no esta conectado\n\t\tcorrectamente");
209                 dlg_connect->show();
210         } else  
211                 file_selection->show();
212 }
213
214 // Elimina el item apuntado desde el menu principal
215 void Constructor::on_edit_menu_del()
216
217         workplace->delete_item(WorkPlace::pointed);
218 }
219
220 // Elimina todos lo items
221 void Constructor::on_edit_menu_delete_all()
222 {
223         std::list<CItem *>::iterator i = listaItems.begin();
224         while ( i != listaItems.end() ) {
225                 (*i)->workplace->delete_item((*i)->get_id());
226                 i = listaItems.begin();
227         }
228         i = lista_logic_Items.begin();
229         while ( i != lista_logic_Items.end() ) {
230                 (*i)->workplace->delete_item((*i)->get_id());
231                 i=lista_logic_Items.begin();
232         }
233         id = 0;
234         list_pointed.clear();
235         list_pointed.push_back(" ");
236         combo_entry->set_popdown_strings(list_pointed);
237         combo_entry->get_entry()->set_text("");
238 }
239
240 // Al presionarse el check button "logica"
241 void Constructor::on_chk_btn_logica_clicked()
242 {
243         logica = !logica;
244         CItem::logic_connect = !CItem::logic_connect;
245         workplace->queue_draw();
246 }
247
248 // Metodo que levanta el archivo XML y crea todos los items agregandolos a las listas correspondientes
249 void Constructor::on_load_from_xml()
250 {
251         on_edit_menu_delete_all();
252         file_name = file_open_selection->get_filename();
253
254         /* Parseo de ejemplo de un XML desde archivo */
255         xmlDocPtr document;
256         document = xmlParseFile(file_name.c_str());
257         if (document == NULL) {
258                 std::cout<<"NO SE PUDO CARGAR EL ARCHIVO"<<std::endl;
259                 // TODO : dar un aviso de que no se pudo abrir el archivo!!
260                 return;
261         }
262
263         /* bien, el archivo se parseo bien! */
264         xmlNodePtr nodo, items;
265         nodo = document->children;
266
267         // Recorro los items
268         CItem *current;
269         if (strcmp((char *)nodo->name, "planta") == 0) {
270                 items = nodo->children;
271                 while (items != NULL) {
272                         current = NULL;
273                         if (items->type == XML_ELEMENT_NODE) {
274                                 std::cout << "ITEM" << std::endl;
275                                 if (xmlStrcmp(items->name, BAD_CAST"bomba")==0) {
276                                         current = loadBomba(items);
277                                 } else if (xmlStrcmp(items->name, BAD_CAST"tubo")==0) {
278                                         current = loadConduct(items);
279                                 } else if (xmlStrcmp(items->name, BAD_CAST"codo")==0) {
280                                         current = loadCodo(items);
281                                 } else if (xmlStrcmp(items->name, BAD_CAST"exclusa")==0) {
282                                         current = loadExclusa(items);
283                                 } else if (xmlStrcmp(items->name, BAD_CAST"tanque")==0) {
284                                         current = loadTank(items);
285                                 } else if (xmlStrcmp(items->name, BAD_CAST"empalme")==0) {
286                                         current = loadUnion(items);
287                                 } else if (xmlStrcmp(items->name, BAD_CAST"drenaje")==0) {
288                                         current = loadDrain(items);
289                                 } else if (xmlStrcmp(items->name, BAD_CAST"and")==0) {
290                                         current = loadAnd(items);
291                                 } else if (xmlStrcmp(items->name, BAD_CAST"not")==0) {
292                                         current = loadNot(items);
293                                 } else if (xmlStrcmp(items->name, BAD_CAST"or")==0) {
294                                         current = loadOr(items);
295                                 }
296
297                                 if (current != NULL) {
298                                         if (! current->is_logic )
299                                                 listaItems.push_back(current);
300                                         else {
301                                                 lista_logic_Items.push_back(current);
302                                         }
303                                         // Agrego y conecto la bomba
304                                         current->drag_source_set(listTargets);
305                                         workplace->put(*current, current->get_position_x(), current->get_position_y());
306                                         //Apunto al workplace
307                                         current->workplace= workplace;
308                                         //Apunto a la lista.
309                                         current->combo_entry = combo_entry;
310                                         //Apunto a la lista de apuntados
311                                         current->list_pointed = &list_pointed;
312                                         //Apunto a la listaItems.
313                                         current->listaItems = &listaItems;
314                                         //Apunto a la lista de items logicos
315                                         current->lista_logic_Items = &lista_logic_Items;
316                                         //Apunto a la barra de estado
317                                         current->status_bar = status_bar;
318                                         // Conecto las señales
319                                         current->signal_drag_data_get().connect( SigC::slot(*this, &Constructor::on_item_drag_data_get));
320                                         current->signal_drag_begin().connect(SigC::bind( SigC::slot(*this, &Constructor::on_item_drag_begin), current));
321                                         current->show();        
322                                 }
323                         }
324                         items = items->next;
325                 }
326                 
327                 // Crea las lineas que conectan la parte logica.
328                 create_lines(document->children);
329                 xmlFreeDoc(document);
330                 workplace->update_logic_position();
331                 workplace->queue_draw();
332         } else {
333                 std::cout<< "EL XML NO ES VALIDO" << std::endl;
334                 // TODO : avisar que el XML no es valido!!
335         }
336         std::cout << "CARGA COMPLETA" << std::endl;
337         file_open_selection->hide();
338         
339         // Seteo el id en el maximo mas uno de todos los id cargados, para que quede bien cuando se agregan nuevos items en un proyecto 
340         // cargado desde un archivo.
341         int id_1 = -1 , id_2 = -1;
342         std::list<CItem *>::iterator i = listaItems.begin();
343         while ( i != listaItems.end() ){
344                 if ( (*i)->get_id() >= id_1 ) 
345                         id_1 = (*i)->get_id();
346         i++;
347         }
348         id_1++;
349         
350         i = lista_logic_Items.begin();
351         while ( i != lista_logic_Items.end() ){
352                 if ( (*i)->get_id() >= id_2 ) 
353                         id_2 = (*i)->get_id();
354         i++;
355         }
356         id_2++;
357         if ( id_1 < id_2 ) id = id_2;
358         else id = id_1;
359 }
360
361 // Recorre todo los items los cuales conocen la manera de salvarse en un archivo XML.
362 void Constructor::on_btn_file_ok_clicked()
363 {
364         std::list<CItem *>::iterator i = listaItems.begin();
365         file_name = file_selection->get_filename();
366         Glib::ustring name;
367         if ( (archivo = fopen( file_name.c_str(), "w+")) != NULL ){
368                 fprintf(archivo, "<?xml version=\"1.0\" encoding=\"iso-8859-1\" ?>\n");
369                 fprintf (archivo,"<planta>\n");
370                 while ( i != listaItems.end() ){
371                         (*i)->save(archivo);
372                         i++;
373                 }
374                 i = lista_logic_Items.begin();
375                 while ( i != lista_logic_Items.end() ) {
376                         (*i)->save(archivo);
377                         i++;
378                 }
379                 fprintf(archivo,"</planta>\n");
380                 saved = true;
381                 fclose(archivo);
382         } else 
383                 std::cout<<"NO SE ABRIO EL ARCHIVO"<<std::endl;
384         file_selection->hide();
385 }
386
387 // Salva el archivo, si no estaba salvado muestra el dialogo, si no sobreescribe el ultimo archivo salvado.
388 void Constructor::on_quick_btn_save_clicked()
389 {
390         if ( ! saved ) {
391                 on_main_menu_save();
392         } else {
393                 on_btn_file_ok_clicked();
394         }
395 }
396         
397 // Limpia la pantalla para comenzar un nuevo proyecto.
398 void Constructor::on_quick_btn_new_clicked()
399 {
400         on_quick_btn_delete_all_clicked();
401         saved = false;
402 }
403
404 // Borra todos los items pero desde otro boton.
405 void Constructor::on_quick_btn_delete_all_clicked()
406 {
407         on_edit_menu_delete_all();
408 }       
409
410 // busca en la lista el nombre del item que aparece en el cuadro de texto y si lo encuentra dibuja un recuadro para mostrarlo.
411 void Constructor::on_btn_find_clicked()
412 {
413         CItem * temp = NULL;
414         std::list<CItem *>::iterator i = listaItems.begin();
415         while ( i !=listaItems.end() ) {
416                 if ( (*i)->get_name()  == combo_entry->get_entry()->get_text() ) {
417                         temp = *i;
418                         break;
419                 }
420                 i++;
421         }
422         
423         i = lista_logic_Items.begin();
424         while ( i !=lista_logic_Items.end() ) {
425                 if ( (*i)->get_name()  == combo_entry->get_entry()->get_text() ) {
426                         temp = *i;
427                         break;
428                 }
429                 i++;
430         }
431         if ( temp != NULL )
432         workplace->get_window()->draw_rectangle(workplace->get_style()->get_black_gc(), false , temp->get_position_x()-5, temp->get_position_y()-5,
433                                                                                                                                                 temp->get_image()->get_width()+10, temp->get_image()->get_height()+10);
434 }
435
436 // Oculta el dialogo.
437 void Constructor::on_btn_file_cancel_clicked()
438 {
439         file_selection->hide();
440 }
441
442 //Muestra el dialogo para seleccionar archivo
443 void Constructor::on_btn_open_cancel_clicked()
444 {
445         file_open_selection->hide();
446 }
447
448 // Oculta el dialogo
449 void Constructor::on_btn_dlg_connect_clicked()
450 {
451         dlg_connect->hide();
452 }
453
454 //Metodos que permiten que el icono sea el del items durante el drag 
455 void Constructor::on_canio_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)
456 {
457         context->set_icon(ico_canio, 5, 5); 
458 }
459
460 void Constructor::on_y_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)
461 {
462         context->set_icon(ico_y, 5, 5); 
463 }
464
465 void Constructor::on_codo_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)
466 {
467         context->set_icon(ico_codo, 5, 5); 
468 }
469
470 void Constructor::on_tanque_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)
471 {
472         context->set_icon(ico_tanque, 5, 5); 
473 }
474
475 void Constructor::on_bomba_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)
476 {
477         context->set_icon(ico_bomba, 5, 5); 
478 }
479
480 void Constructor::on_exclusa_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)
481 {
482         context->set_icon(ico_exclusa, 5, 5); 
483 }
484
485 void Constructor::on_drain_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)
486 {
487         context->set_icon(ico_drain, 5, 5); 
488 }
489
490 void Constructor::on_and_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)
491 {
492         context->set_icon(ico_and, 5, 5); 
493 }
494
495 void Constructor::on_or_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)
496 {
497         context->set_icon(ico_or, 5, 5); 
498 }
499
500 void Constructor::on_not_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)
501 {
502         context->set_icon(ico_not, 5, 5); 
503 }
504
505 void Constructor::on_item_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context, CItem *item)
506 {
507         context->set_icon(item->get_image(), 5, 5);
508 }
509
510 void Constructor::on_item_drag_data_get(const Glib::RefPtr<Gdk::DragContext>& context, GtkSelectionData* selection_data, guint info, guint time)
511 {       
512         gtk_selection_data_set (selection_data, selection_data->target, 10, (const guchar*)"item_codo.png", 13);
513 }
514
515 // Si un item es movido encima de otro este metodo devueve falso. De esta manera no podran encimarse items.
516 bool Constructor::can_drop(CItem *item, int _x, int _y)
517 {
518         std::list<CItem*>::iterator  i = listaItems.begin();
519         while( i != listaItems.end() ) {
520                 CItem *temp = *i;
521                 if ( temp->get_id() != item->get_id()   ) {
522                         if (  (temp->is_occupied_area(_x, _y))  ||  
523                                 ( temp->is_occupied_area(_x+item->get_image()->get_width()-1, _y+item->get_image()->get_height()-1))  ||
524                                 ( temp->is_occupied_area(_x, _y+item->get_image()->get_height()-1)) ||
525                                 ( temp->is_occupied_area(_x+item->get_image()->get_width()-1, _y) ) ) 
526                                 return false;
527                         else i++;
528                 }
529                 else i++;
530         }
531         return true;
532 }
533
534 //Cada vez que se realiza un drag o un drop este metodo es invocado.
535 //Aca se validan las posiciones de los items y se crean si no estaban en el area de trabajo.
536 void Constructor::on_item_drop_drag_received(const Glib::RefPtr<Gdk::DragContext>& context, int x, int y, GtkSelectionData* selection_data, guint info, guint time)
537 {
538         workplace->update_logic_position();
539         workplace->queue_draw();
540         if ( !logica ) {
541                 /* Ajusto coordenada x e y para que caigan en un lugar de una cuadricula de 32x32 */
542                 int i,j;
543                 // el +1 es para evitar un bug cuando se selecciona muy cerce de la
544                 // separacion de 2 cuadritos
545                 i = (x+1)/32;
546                 j = (y+1)/32;
547                 // El drag es de un item
548                 if (selection_data->format == 10) {
549                         if (can_drop(((CItem*)drag_get_source_widget(context)),i*32, j*32)){
550                                 ((CItem*)drag_get_source_widget(context))->set_position(i*32, j*32);
551                                 workplace->move(*drag_get_source_widget(context), i*32, j*32);
552                         }
553                 }
554
555                 // El Drag es desde la barra de tareas
556                 if ((selection_data->length >= 0) && (selection_data->format == 8))     {
557                         CItem *a;
558                         if (strcmp((const char *)selection_data->data, "codo_o.png")==0) 
559                         a = new Splitter();
560                         else    if (strcmp((const char *)selection_data->data, "canio_n.png")==0) 
561                         a = new Conduct();
562                         else if (strcmp((const char *)selection_data->data, "y_n.png")==0) 
563                         a = new Union();
564                         else if (strcmp((const char *)selection_data->data, "tanque_e.png")==0) 
565                         a = new Cistern();
566                         else if (strcmp((const char *)selection_data->data, "bomba_e.png")==0) 
567                         a =new Pump();
568                         else if (strcmp((const char *)selection_data->data, "exclusa_h.png")==0) 
569                         a = new Exclusa();
570                         else if (strcmp((const char *)selection_data->data, "drain_n.png")==0) 
571                         a = new Drain();
572                         else if (strcmp((const char *)selection_data->data, "and_e.png")==0){ 
573                         a = new And(); a->is_logic = true;
574                         } else if (strcmp((const char *)selection_data->data, "or_e.png")==0) {
575                                 a = new Or(); a->is_logic = true;
576                                 } else if (strcmp((const char *)selection_data->data, "not_e.png")==0) {
577                                         a = new Not(); a->is_logic = true;
578                                         }
579                 
580                         char char_id[10];
581                         sprintf(char_id,"%d",id);
582                         a->set_id(id++);                
583                         a->set_name( a->get_name()+char_id );
584                         if ( can_drop(a, i*32, j*32) ) {
585                                 workplace->put(*a, i*32, j*32);
586                                 //Apunto al workplace
587                                 a->workplace = workplace;
588                                 //Apunto a la lista.
589                                 a->combo_entry = combo_entry;
590                                 //Apunto a la lista de apuntados
591                                 a->list_pointed = &list_pointed;
592                                 //Apunto a la listaItems.
593                                 a->listaItems = &listaItems;
594                                 //Apunto a la barra de estado
595                                 a->status_bar = status_bar;
596                                 //Apunto a la lista de items logicos
597                                 a->lista_logic_Items = &lista_logic_Items;
598                                 //Seteo la posicion del item
599                                 a->set_position(i*32,j*32);
600                                 // Seteo la lista de tipos de drags 
601                                 a->drag_source_set(listTargets);
602                                 // Conecto las señales
603                                 a->signal_drag_data_get().connect( SigC::slot(*this, &Constructor::on_item_drag_data_get));
604                                 // Utilizo el SigC::bind para que el callback on_drag_begin acepte un
605                                 // parametro extra, en este caso un CItem *. Esto se hace para
606                                 // que cuando el usuario quiera mover un item, saber que item es
607                                 // y pedirle su ícono para mostrar cono icono durante la operacion,
608                                 // Esto va a permitir, que si un widget tiene una imagen rotara o algo
609                                 // raro se vea el widget tal cual.
610                                 a->signal_drag_begin().connect(SigC::bind( SigC::slot(*this, &Constructor::on_item_drag_begin), a));
611                                 a->show();      
612                                 if (! a->is_logic )
613                                         listaItems.push_back(a);
614                                 else 
615                                         lista_logic_Items.push_back(a);
616                         } else {
617                                         id--;
618                                         delete a;
619                                 }
620                 }
621                 context->drag_finish(false, false, time);
622         }
623         workplace->update_logic_position();
624         workplace->queue_draw();
625 }
626
627 // Cuando se presiona el boton "Verificar Conexiones" esta funcion es invocada
628 //Muestra un dialogo de error en caso de que no esten bien conectados y un dialogo
629 //de exito si lo estan.
630 void Constructor::on_btn_check_clicked()
631 {
632         Glib::ustring name;
633         if ( ! check_connection(name) ) {
634                 dlg_connect->set_title("Error");
635                 dlg_label->set_text("El elemento "+name+" no esta conectado\n\t\tcorrectamente");
636                 dlg_connect->show();
637         } else {
638                 dlg_connect->set_title("Conexion");
639                 dlg_label->set_text("Los elementos estan conectados\n\t\tcorrectamente");
640                 dlg_connect->show();
641         }
642 }
643
644 //Verifica que todos los items esten correctamente conectados en sus extremos.
645 //Cada item verifica su conexion en forma independiente.
646 bool Constructor::check_connection(Glib::ustring& name)
647 {
648         std::list<CItem *>::iterator i = listaItems.begin();
649         while ( i != listaItems.end() ){
650                 (*i)->set_default_connector();
651                 (*i)->is_connected = false;
652                 i++;
653         }
654         i = listaItems.begin();
655         if ( !listaItems.empty() ) {
656                 while ( i != listaItems.end() ) {
657                         CItem *temp = *i;
658                         std::cout<< "item="<<temp->get_name()<<" "<<"check= "<<temp->check_connection()<<std::endl;
659                         if ( !temp->check_connection() ) {
660                                 name = temp->get_name();
661                                 return false;
662                         }       
663                 i++;
664                 }
665         }
666         std::cout<<"check_connection logic"<<std::endl;
667         std::list<CItem *>::iterator j = lista_logic_Items.begin();
668         while ( j != lista_logic_Items.end() ) {
669                 if ( !(*j)->check_connection() ) {
670                         name = (*j)->get_name();
671                         return false;
672                 }
673                 j++;
674         }
675         return true;
676 }       
677
678
679 //Los siguientes metodos son utilizados para levantar cada item desde el XML
680
681 Not *Constructor::loadNot(xmlNodePtr nodo)
682 {
683         std::string name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
684         std::string id = (char *)xmlGetProp(nodo, BAD_CAST"id");
685         int orientacion=0, x, y;
686
687         nodo = nodo->children;
688         while (nodo != NULL) {
689                 if (nodo->type == XML_ELEMENT_NODE) {
690                         if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
691                                 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
692                         } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
693                                 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
694                         } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
695                                 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
696                         }
697                 }
698                 nodo = nodo->next;
699         }
700
701         Not *p = new Not(orientacion);
702         p->set_position(x,y);
703         p->set_id( atoi(id.c_str()) );
704         p->set_name(name);
705
706         return p;
707 }
708
709 Or *Constructor::loadOr(xmlNodePtr nodo)
710 {
711         std::string name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
712         std::string id = (char *)xmlGetProp(nodo, BAD_CAST"id");
713         int orientacion=0, x, y;
714
715         nodo = nodo->children;
716         while (nodo != NULL) {
717                 if (nodo->type == XML_ELEMENT_NODE) {
718                         if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
719                                 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
720                         } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
721                                 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
722                         } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
723                                 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
724                         }
725                 }
726                 nodo = nodo->next;
727         }
728
729         Or *p = new Or(orientacion);
730         p->set_position(x,y);
731         p->set_id( atoi(id.c_str()) );
732         p->set_name(name);
733
734         return p;
735 }
736
737 And *Constructor::loadAnd(xmlNodePtr nodo)
738 {
739         std::string name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
740         std::string id = (char *)xmlGetProp(nodo, BAD_CAST"id");
741         int orientacion=0, x, y;
742         float flujo;
743         xmlNodePtr inicial = nodo;
744
745         nodo = nodo->children;
746         while (nodo != NULL) {
747                 if (nodo->type == XML_ELEMENT_NODE) {
748                         if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
749                                 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
750                         } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
751                                 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
752                         } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
753                                 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
754                         }
755                 }
756                 nodo = nodo->next;
757         }
758
759         And *p = new And(orientacion);
760         p->set_position(x,y);
761         p->set_id( atoi(id.c_str()) );
762         p->set_name(name);
763         return p;
764 }
765
766 Pump *Constructor::loadBomba(xmlNodePtr nodo)
767 {
768         std::string name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
769         std::string id = (char *)xmlGetProp(nodo, BAD_CAST"id");
770         int orientacion=0, x, y;
771         float flujo;
772         Gdk::Color color;
773
774         nodo = nodo->children;
775         while (nodo != NULL) {
776                 if (nodo->type == XML_ELEMENT_NODE) {
777                         if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
778                                 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
779                         } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
780                                 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
781                         } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
782                                 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
783                         } else if (xmlStrcmp(nodo->name, BAD_CAST"entrega") == 0) {
784                                 flujo = atof( (char *)XML_GET_CONTENT(nodo->children) );
785                         } else if (xmlStrcmp(nodo->name, BAD_CAST"color") == 0) {
786                                 color = loadColor(nodo->children);
787                         }
788                 }
789                 nodo = nodo->next;
790         }
791
792         Pump *p = new Pump(orientacion);
793         p->set_position(x,y);
794         p->set_entrega(flujo);
795         p->set_id( atoi(id.c_str()) );
796         p->set_name(name);
797         p->set_liquid_color(color);
798
799         return p;
800 }
801
802 Gdk::Color Constructor::loadColor(xmlNodePtr nodo)
803 {
804         gushort r,g,b;
805         while (nodo != NULL) {
806                 if (nodo->type == XML_ELEMENT_NODE) {
807                         if (xmlStrcmp(nodo->name, BAD_CAST"rojo")==0)
808                                 r = atoi( (char *)XML_GET_CONTENT(nodo->children) );
809                         if (xmlStrcmp(nodo->name, BAD_CAST"verde")==0)
810                                 g = atoi( (char *)XML_GET_CONTENT(nodo->children) );
811                         if (xmlStrcmp(nodo->name, BAD_CAST"azul")==0)
812                                 b = atoi( (char *)XML_GET_CONTENT(nodo->children) );
813                 }
814                 nodo = nodo->next;
815         }
816         Gdk::Color c;
817         c.set_rgb(r,g,b);
818         std::cout << r << "  " << g << " " << b << std::endl;
819         return c;
820 }
821
822 Conduct *Constructor::loadConduct(xmlNodePtr nodo)
823 {
824         std::string name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
825         std::string id = (char *)xmlGetProp(nodo, BAD_CAST"id");
826         int orientacion=0, x, y;
827         float flujo;
828
829         nodo = nodo->children;
830         while (nodo != NULL) {
831                 if (nodo->type == XML_ELEMENT_NODE) {
832                         if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
833                                 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
834                         } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
835                                 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
836                         } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
837                                 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
838                         } else if (xmlStrcmp(nodo->name, BAD_CAST"caudal") == 0) {
839                                 flujo = atof( (char *)XML_GET_CONTENT(nodo->children) );
840                         }
841                 }
842                 nodo = nodo->next;
843         }
844
845         Conduct *p = new Conduct(orientacion);
846         p->set_position(x,y);
847         p->set_caudal(flujo);
848         p->set_id( atoi(id.c_str()) );
849         p->set_name(name);
850
851         return p;
852 }
853
854 Exclusa *Constructor::loadExclusa(xmlNodePtr nodo)
855 {
856         std::string name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
857         std::string id = (char *)xmlGetProp(nodo, BAD_CAST"id");
858         std::string estado;
859         int orientacion=0, x, y;
860         float flujo;
861
862         nodo = nodo->children;
863         while (nodo != NULL) {
864                 if (nodo->type == XML_ELEMENT_NODE) {
865                         if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
866                                 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
867                         } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
868                                 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
869                         } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
870                                 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
871                         } else if (xmlStrcmp(nodo->name, BAD_CAST"estado") == 0) {
872                                 estado = (char *)XML_GET_CONTENT(nodo->children);
873                         }
874                 }
875                 nodo = nodo->next;
876         }
877
878         Exclusa *p = new Exclusa(orientacion);
879         p->set_position(x,y);
880         p->set_id( atoi(id.c_str()) );
881         p->set_name(name);
882         p->set_estado( estado == "1" );
883
884         return p;
885 }
886
887 Cistern *Constructor::loadTank(xmlNodePtr nodo)
888 {
889         std::string name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
890         std::string id = (char *)xmlGetProp(nodo, BAD_CAST"id");
891         int orientacion=0, x, y;
892         float liquido,capacidad;
893         Gdk::Color color;
894
895         nodo = nodo->children;
896         while (nodo != NULL) {
897                 if (nodo->type == XML_ELEMENT_NODE) {
898                         if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
899                                 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
900                         } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
901                                 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
902                         } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
903                                 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
904                         } else if (xmlStrcmp(nodo->name, BAD_CAST"capacidad") == 0) {
905                                 capacidad = atof ((char *)XML_GET_CONTENT(nodo->children) );
906                         } else if (xmlStrcmp(nodo->name, BAD_CAST"inicial") == 0) {
907                                 liquido = atof ((char *)XML_GET_CONTENT(nodo->children) );
908                         } else if (xmlStrcmp(nodo->name, BAD_CAST"color") == 0) {
909                                 color = loadColor(nodo->children);
910                         }
911                 }
912                 nodo = nodo->next;
913         }
914
915         Cistern *p = new Cistern(orientacion);
916         p->set_position(x,y);
917         p->set_id( atoi(id.c_str()) );
918         p->set_name(name);
919         p->set_capacidad(capacidad);
920         p->set_contenido_inicial(liquido);
921         p->set_liquid_color(color);
922         return p;
923 }
924
925 Union *Constructor::loadUnion(xmlNodePtr nodo)
926 {
927         std::string name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
928         std::string id = (char *)xmlGetProp(nodo, BAD_CAST"id");
929         std::string tipo;
930         int orientacion=0, x, y;
931         float caudal;
932
933         nodo = nodo->children;
934         while (nodo != NULL) {
935                 if (nodo->type == XML_ELEMENT_NODE) {
936                         if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
937                                 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
938                         } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
939                                 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
940                         } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
941                                 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
942                         } else if (xmlStrcmp(nodo->name, BAD_CAST"caudal") == 0) {
943                                 caudal = atof ((char *)XML_GET_CONTENT(nodo->children) );
944                         } else if (xmlStrcmp(nodo->name, BAD_CAST"tipo") == 0) {
945                                 tipo = (char *)XML_GET_CONTENT(nodo->children);
946                         }
947                 }
948                 nodo = nodo->next;
949         }
950
951         Union *p = new Union(orientacion);
952         p->set_position(x,y);
953         p->set_id( atoi(id.c_str()) );
954         p->set_name(name);
955         p->set_caudal(caudal);
956         p->is_union = (tipo == "union");
957
958         return p;
959 }
960
961 Drain *Constructor::loadDrain(xmlNodePtr nodo)
962 {
963         std::string name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
964         std::string id = (char *)xmlGetProp(nodo, BAD_CAST"id");
965         int orientacion=0, x, y;
966
967         nodo = nodo->children;
968         while (nodo != NULL) {
969                 if (nodo->type == XML_ELEMENT_NODE) {
970                         if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
971                                 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
972                         } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
973                                 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
974                         } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
975                                 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
976                         }
977                 }
978                 nodo = nodo->next;
979         }
980
981         Drain *p = new Drain(orientacion);
982         p->set_position(x,y);
983         p->set_id( atoi(id.c_str()) );
984         p->set_name(name);
985
986         return p;
987 }
988
989 Splitter *Constructor::loadCodo(xmlNodePtr nodo)
990 {
991         std::string name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
992         std::string id = (char *)xmlGetProp(nodo, BAD_CAST"id");
993         int orientacion=0, x, y;
994         float caudal;
995
996         nodo = nodo->children;
997         while (nodo != NULL) {
998                 if (nodo->type == XML_ELEMENT_NODE) {
999                         if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
1000                                 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
1001                         } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
1002                                 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
1003                         } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
1004                                 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
1005                         } else if (xmlStrcmp(nodo->name, BAD_CAST"caudal") == 0) {
1006                                 caudal = atof( (char *)XML_GET_CONTENT(nodo->children) );
1007                         }
1008                 }
1009                 nodo = nodo->next;
1010         }
1011
1012         Splitter *p = new Splitter(orientacion);
1013         p->set_position(x,y);
1014         p->set_id( atoi(id.c_str()) );
1015         p->set_name(name);
1016         p->set_caudal(caudal);
1017
1018         return p;
1019 }
1020
1021 void Constructor::create_lines(xmlNodePtr nodo)
1022 {
1023         std::string name;
1024         
1025         nodo = nodo->children;
1026         while (nodo != NULL) {
1027                 if (nodo->type == XML_ELEMENT_NODE) {
1028                         if (xmlStrcmp(nodo->name, BAD_CAST"and")==0) {
1029                                 name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
1030                                 std::cout << name << std::endl;
1031                                 create_line(nodo->children, workplace->get_logic_id(name));
1032                         } else if (xmlStrcmp(nodo->name, BAD_CAST"not")==0) {
1033                                 name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
1034                                 std::cout << name << std::endl;
1035                                 create_line(nodo->children, workplace->get_logic_id(name));
1036                         } else if (xmlStrcmp(nodo->name, BAD_CAST"or")==0) {
1037                                 name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
1038                                 std::cout << name << std::endl;
1039                                 create_line(nodo->children, workplace->get_logic_id(name));
1040                         }
1041                 }
1042                 nodo = nodo->next;
1043         }
1044 }
1045
1046 //Levanta las lineas desde el archvo XML 
1047 void Constructor::create_line(xmlNodePtr nodo, int logic_id)
1048 {
1049         std::string otro;
1050         std::cout << "Buscando lineas ..." << std::endl;
1051         while (nodo != NULL) {
1052                 if (nodo->type == XML_ELEMENT_NODE) {
1053                         if (xmlStrcmp(nodo->name, BAD_CAST"salida")==0) {
1054                                 otro = (char *)XML_GET_CONTENT(nodo->children);
1055                                 t_line tmp_line;
1056                                 tmp_line.logic_id = logic_id;
1057                                 //workplace->get_logic_item(logic_id)->set_out_connected(true);
1058                                 if (workplace->get_item_id(otro) != -1) {
1059                                         tmp_line.store_id = workplace->get_item_id(otro);
1060                                         std::cout << otro << " se conecta a una compuerta" << std::endl;
1061                                         workplace->lista_lineas_in.push_back(tmp_line);
1062                                 } else {
1063                                         /* Como no era un item, debe ser una compuerta */
1064                                         tmp_line.store_id = workplace->get_logic_id(otro);
1065                                         workplace->lista_lineas_logic.push_back(tmp_line);
1066                                 }
1067                         } else if (xmlStrcmp(nodo->name, BAD_CAST"entrada")==0) {
1068                                 otro = (char *)XML_GET_CONTENT(nodo->children);
1069                                 t_line tmp_line;
1070                                 tmp_line.logic_id = logic_id;
1071                                 if (workplace->get_item_id(otro) != -1) {
1072                                         tmp_line.store_id = workplace->get_item_id(otro);
1073                                         /* Tengo que ver si es un tanque, para setearlo correctamente */
1074                                         if (dynamic_cast<Cistern *>(workplace->get_item(workplace->get_item_id(otro)))) {
1075                                                 std::string donde = (char *)xmlGetProp(nodo, BAD_CAST"id");
1076                                                 tmp_line.cistern_out1 = true;
1077                                                 if (donde == "inferior") {
1078                                                         tmp_line.cistern_out1 = false;
1079                                                 }
1080                                         }
1081                                         workplace->lista_lineas_out.push_back(tmp_line);
1082                                         std::cout << otro << " se conecta a una compuerta" << std::endl;
1083                                 } else {
1084                                         /* Como no era un item, debe ser una compuerta */
1085                                         tmp_line.store_id = workplace->get_logic_id(otro);
1086                                         workplace->lista_lineas_logic.push_back(tmp_line);
1087                                 }
1088                         }
1089                 }
1090                 nodo = nodo->next;
1091         }
1092 }