]> git.llucax.com Git - z.facultad/75.42/plaqui.git/blobdiff - 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
index 2318a4405d57b71b14ba1bc07c98163ecdc68945..acf5bc1f2ca8f743d408aac8c1c1419638e15b17 100644 (file)
@@ -6,7 +6,7 @@ Constructor::Constructor(BaseObjectType* cobject, const Glib::RefPtr<Gnome::Glad
        saved = false;
        set_title("Constructor");
        
        saved = false;
        set_title("Constructor");
        
-       
+       // Cargo todas las imagenes de los iconos de los botones
        ico_canio = Gdk::Pixbuf::create_from_file(PACKAGE_DATA_DIR"/plaqui-constructor/pixmaps/canio_n.png");
        ico_y     = Gdk::Pixbuf::create_from_file(PACKAGE_DATA_DIR"/plaqui-constructor/pixmaps/y_n.png");
        ico_codo  = Gdk::Pixbuf::create_from_file(PACKAGE_DATA_DIR"/plaqui-constructor/pixmaps/codo_o.png");
        ico_canio = Gdk::Pixbuf::create_from_file(PACKAGE_DATA_DIR"/plaqui-constructor/pixmaps/canio_n.png");
        ico_y     = Gdk::Pixbuf::create_from_file(PACKAGE_DATA_DIR"/plaqui-constructor/pixmaps/y_n.png");
        ico_codo  = Gdk::Pixbuf::create_from_file(PACKAGE_DATA_DIR"/plaqui-constructor/pixmaps/codo_o.png");
@@ -18,6 +18,7 @@ Constructor::Constructor(BaseObjectType* cobject, const Glib::RefPtr<Gnome::Glad
        ico_or = Gdk::Pixbuf::create_from_file(PACKAGE_DATA_DIR"/plaqui-constructor/pixmaps/or_e.png");
        ico_not = Gdk::Pixbuf::create_from_file(PACKAGE_DATA_DIR"/plaqui-constructor/pixmaps/not_e.png");
        
        ico_or = Gdk::Pixbuf::create_from_file(PACKAGE_DATA_DIR"/plaqui-constructor/pixmaps/or_e.png");
        ico_not = Gdk::Pixbuf::create_from_file(PACKAGE_DATA_DIR"/plaqui-constructor/pixmaps/not_e.png");
        
+       //Obtengo todos los widgets de la ventana principal.
        refGlade->get_widget("btn_canio", btn_canio);
        refGlade->get_widget("btn_codo", btn_codo);
        refGlade->get_widget("btn_y", btn_y);
        refGlade->get_widget("btn_canio", btn_canio);
        refGlade->get_widget("btn_codo", btn_codo);
        refGlade->get_widget("btn_y", btn_y);
@@ -45,7 +46,10 @@ Constructor::Constructor(BaseObjectType* cobject, const Glib::RefPtr<Gnome::Glad
        refGlade->get_widget("quick_btn_save", quick_btn_save);
        refGlade->get_widget("quick_btn_open", quick_btn_open);
        refGlade->get_widget("edit_menu_delete_all", edit_menu_delete_all);
        refGlade->get_widget("quick_btn_save", quick_btn_save);
        refGlade->get_widget("quick_btn_open", quick_btn_open);
        refGlade->get_widget("edit_menu_delete_all", edit_menu_delete_all);
+       refGlade->get_widget("btn_find", btn_find);
+       refGlade->get_widget("status_bar", status_bar);
        
        
+       //Obtengo el area de trabajo, la cual tiene definida su propia clase.
        refGlade->get_widget_derived("workplace", workplace);  //fixed
        
        //Targets
        refGlade->get_widget_derived("workplace", workplace);  //fixed
        
        //Targets
@@ -54,6 +58,7 @@ Constructor::Constructor(BaseObjectType* cobject, const Glib::RefPtr<Gnome::Glad
        listTargets.push_back( Gtk::TargetEntry("POINTER") );
        listTargets.push_back( Gtk::TargetEntry("application/pointer") );
        
        listTargets.push_back( Gtk::TargetEntry("POINTER") );
        listTargets.push_back( Gtk::TargetEntry("application/pointer") );
        
+       // Le indico cuales son los botones  desde los cuales se puede hacer un drag.
        btn_canio->drag_source_set(listTargets);
        btn_y->drag_source_set(listTargets);
        btn_codo->drag_source_set(listTargets);
        btn_canio->drag_source_set(listTargets);
        btn_y->drag_source_set(listTargets);
        btn_codo->drag_source_set(listTargets);
@@ -65,6 +70,7 @@ Constructor::Constructor(BaseObjectType* cobject, const Glib::RefPtr<Gnome::Glad
        btn_or->drag_source_set(listTargets);
        btn_not->drag_source_set(listTargets);
        
        btn_or->drag_source_set(listTargets);
        btn_not->drag_source_set(listTargets);
        
+       //Conecto las señales de cada boton con su correspondiente metodo.
        btn_canio->signal_drag_data_get().connect( SigC::slot(*this, &Constructor::on_btn_canio_drag_get));
        btn_bomba->signal_drag_data_get().connect( SigC::slot(*this, &Constructor::on_btn_bomba_drag_get));
        btn_exclusa->signal_drag_data_get().connect( SigC::slot(*this, &Constructor::on_btn_exclusa_drag_get));
        btn_canio->signal_drag_data_get().connect( SigC::slot(*this, &Constructor::on_btn_canio_drag_get));
        btn_bomba->signal_drag_data_get().connect( SigC::slot(*this, &Constructor::on_btn_bomba_drag_get));
        btn_exclusa->signal_drag_data_get().connect( SigC::slot(*this, &Constructor::on_btn_exclusa_drag_get));
@@ -77,7 +83,8 @@ Constructor::Constructor(BaseObjectType* cobject, const Glib::RefPtr<Gnome::Glad
        btn_not->signal_drag_data_get().connect( SigC::slot(*this, &Constructor::on_btn_not_drag_get));
        btn_check->signal_clicked().connect(SigC::slot(*this,&Constructor::on_btn_check_clicked));
        btn_dlg_close->signal_clicked().connect(SigC::slot(*this,&Constructor::on_btn_dlg_connect_clicked));
        btn_not->signal_drag_data_get().connect( SigC::slot(*this, &Constructor::on_btn_not_drag_get));
        btn_check->signal_clicked().connect(SigC::slot(*this,&Constructor::on_btn_check_clicked));
        btn_dlg_close->signal_clicked().connect(SigC::slot(*this,&Constructor::on_btn_dlg_connect_clicked));
-       chk_btn_logica->signal_clicked().connect(SigC::slot(*this, &Constructor::on_chk_btn_clicked));
+       btn_find->signal_clicked().connect(SigC::slot(*this,&Constructor::on_btn_find_clicked));        
+       chk_btn_logica->signal_clicked().connect(SigC::slot(*this, &Constructor::on_chk_btn_logica_clicked));
        quick_btn_new->signal_clicked().connect(SigC::slot(*this, &Constructor::on_quick_btn_new_clicked));
        quick_btn_save->signal_clicked().connect(SigC::slot(*this, &Constructor::on_quick_btn_save_clicked));
        quick_btn_open->signal_clicked().connect(SigC::slot(*this, &Constructor::on_main_menu_open));
        quick_btn_new->signal_clicked().connect(SigC::slot(*this, &Constructor::on_quick_btn_new_clicked));
        quick_btn_save->signal_clicked().connect(SigC::slot(*this, &Constructor::on_quick_btn_save_clicked));
        quick_btn_open->signal_clicked().connect(SigC::slot(*this, &Constructor::on_main_menu_open));
@@ -89,11 +96,11 @@ Constructor::Constructor(BaseObjectType* cobject, const Glib::RefPtr<Gnome::Glad
        edit_menu_del->signal_activate().connect(SigC::slot(*this,&Constructor::on_edit_menu_del));
        edit_menu_delete_all->signal_activate().connect(SigC::slot(*this,&Constructor::on_quick_btn_delete_all_clicked));
        
        edit_menu_del->signal_activate().connect(SigC::slot(*this,&Constructor::on_edit_menu_del));
        edit_menu_delete_all->signal_activate().connect(SigC::slot(*this,&Constructor::on_quick_btn_delete_all_clicked));
        
+       //Obtengo y conecto los botones del dialogo de Salvar/Cargar un archivo.
        btn_file_cancel = file_selection->get_cancel_button();
        btn_file_ok = file_selection->get_ok_button();
        btn_file_ok->signal_clicked().connect(SigC::slot(*this,&Constructor::on_btn_file_ok_clicked));
        btn_file_cancel->signal_clicked().connect(SigC::slot(*this,&Constructor::on_btn_file_cancel_clicked));
        btn_file_cancel = file_selection->get_cancel_button();
        btn_file_ok = file_selection->get_ok_button();
        btn_file_ok->signal_clicked().connect(SigC::slot(*this,&Constructor::on_btn_file_ok_clicked));
        btn_file_cancel->signal_clicked().connect(SigC::slot(*this,&Constructor::on_btn_file_cancel_clicked));
-       
        btn_open_cancel = file_open_selection->get_cancel_button();
        btn_open_ok = file_open_selection->get_ok_button();
        btn_open_ok->signal_clicked().connect(SigC::slot(*this,&Constructor::on_load_from_xml));
        btn_open_cancel = file_open_selection->get_cancel_button();
        btn_open_ok = file_open_selection->get_ok_button();
        btn_open_ok->signal_clicked().connect(SigC::slot(*this,&Constructor::on_load_from_xml));
@@ -112,16 +119,20 @@ Constructor::Constructor(BaseObjectType* cobject, const Glib::RefPtr<Gnome::Glad
        btn_not->signal_drag_begin().connect( SigC::slot(*this, &Constructor::on_not_drag_begin));
        workplace->drag_dest_set(listTargets);
        workplace->signal_drag_data_received().connect( SigC::slot(*this, &Constructor::on_item_drop_drag_received) );  
        btn_not->signal_drag_begin().connect( SigC::slot(*this, &Constructor::on_not_drag_begin));
        workplace->drag_dest_set(listTargets);
        workplace->signal_drag_data_received().connect( SigC::slot(*this, &Constructor::on_item_drop_drag_received) );  
+       // Apunto la lista del area de trabajo a la lista de items en el Constructor
        workplace->listaItems = &listaItems;    
        workplace->lista_logic_Items = &lista_logic_Items;      
        workplace->listaItems = &listaItems;    
        workplace->lista_logic_Items = &lista_logic_Items;      
+       workplace->logica = &logica;
        logica = false;
 }
 
 Constructor::~Constructor()
 {
        logica = false;
 }
 
 Constructor::~Constructor()
 {
+       // elimina todos los items 
        Constructor::on_edit_menu_delete_all();
 }
 
        Constructor::on_edit_menu_delete_all();
 }
 
+// Definicion de los metodos para obtener el icono al realizar un drag.
 void Constructor::on_btn_canio_drag_get(const Glib::RefPtr<Gdk::DragContext>& context, GtkSelectionData* selection_data, guint info, guint time)
 {
        gtk_selection_data_set (selection_data, selection_data->target, 8, (const guchar*)"canio_n.png", 12);
 void Constructor::on_btn_canio_drag_get(const Glib::RefPtr<Gdk::DragContext>& context, GtkSelectionData* selection_data, guint info, guint time)
 {
        gtk_selection_data_set (selection_data, selection_data->target, 8, (const guchar*)"canio_n.png", 12);
@@ -172,7 +183,7 @@ void Constructor::on_btn_not_drag_get(const Glib::RefPtr<Gdk::DragContext>& cont
        gtk_selection_data_set(selection_data, selection_data->target, 8,(const guchar*)"not_e.png",9);
 }
 
        gtk_selection_data_set(selection_data, selection_data->target, 8,(const guchar*)"not_e.png",9);
 }
 
-
+//Sale del programa.
 void Constructor::on_main_menu_quit()
 {
        delete this;
 void Constructor::on_main_menu_quit()
 {
        delete this;
@@ -180,12 +191,14 @@ void Constructor::on_main_menu_quit()
        //hide();
 }
 
        //hide();
 }
 
+// Carga de un archivo XML
 void Constructor::on_main_menu_open()
 {
        // Conecto el boton OK para llamar al cargar del XML
        file_open_selection->show();
 }
 
 void Constructor::on_main_menu_open()
 {
        // Conecto el boton OK para llamar al cargar del XML
        file_open_selection->show();
 }
 
+// Salva un archivo XML
 void Constructor::on_main_menu_save()
 {
        // Conecto el boton OK para llamar al salvar
 void Constructor::on_main_menu_save()
 {
        // Conecto el boton OK para llamar al salvar
@@ -198,11 +211,13 @@ void Constructor::on_main_menu_save()
                file_selection->show();
 }
 
                file_selection->show();
 }
 
+// Elimina el item apuntado desde el menu principal
 void Constructor::on_edit_menu_del()
 { 
        workplace->delete_item(WorkPlace::pointed);
 }
 
 void Constructor::on_edit_menu_del()
 { 
        workplace->delete_item(WorkPlace::pointed);
 }
 
+// Elimina todos lo items
 void Constructor::on_edit_menu_delete_all()
 {
        std::list<CItem *>::iterator i = listaItems.begin();
 void Constructor::on_edit_menu_delete_all()
 {
        std::list<CItem *>::iterator i = listaItems.begin();
@@ -216,14 +231,21 @@ void Constructor::on_edit_menu_delete_all()
                i=lista_logic_Items.begin();
        }
        id = 0;
                i=lista_logic_Items.begin();
        }
        id = 0;
+       list_pointed.clear();
+       list_pointed.push_back(" ");
+       combo_entry->set_popdown_strings(list_pointed);
+       combo_entry->get_entry()->set_text("");
 }
 
 }
 
-void Constructor::on_chk_btn_clicked()
+// Al presionarse el check button "logica"
+void Constructor::on_chk_btn_logica_clicked()
 {
        logica = !logica;
        CItem::logic_connect = !CItem::logic_connect;
 {
        logica = !logica;
        CItem::logic_connect = !CItem::logic_connect;
+       workplace->queue_draw();
 }
 
 }
 
+// Metodo que levanta el archivo XML y crea todos los items agregandolos a las listas correspondientes
 void Constructor::on_load_from_xml()
 {
        on_edit_menu_delete_all();
 void Constructor::on_load_from_xml()
 {
        on_edit_menu_delete_all();
@@ -233,6 +255,7 @@ void Constructor::on_load_from_xml()
        xmlDocPtr document;
        document = xmlParseFile(file_name.c_str());
        if (document == NULL) {
        xmlDocPtr document;
        document = xmlParseFile(file_name.c_str());
        if (document == NULL) {
+               std::cout<<"NO SE PUDO CARGAR EL ARCHIVO"<<std::endl;
                // TODO : dar un aviso de que no se pudo abrir el archivo!!
                return;
        }
                // TODO : dar un aviso de que no se pudo abrir el archivo!!
                return;
        }
@@ -263,21 +286,35 @@ void Constructor::on_load_from_xml()
                                        current = loadUnion(items);
                                } else if (xmlStrcmp(items->name, BAD_CAST"drenaje")==0) {
                                        current = loadDrain(items);
                                        current = loadUnion(items);
                                } else if (xmlStrcmp(items->name, BAD_CAST"drenaje")==0) {
                                        current = loadDrain(items);
+                               } else if (xmlStrcmp(items->name, BAD_CAST"and")==0) {
+                                       current = loadAnd(items);
+                               } else if (xmlStrcmp(items->name, BAD_CAST"not")==0) {
+                                       current = loadNot(items);
+                               } else if (xmlStrcmp(items->name, BAD_CAST"or")==0) {
+                                       current = loadOr(items);
                                }
 
                                if (current != NULL) {
                                }
 
                                if (current != NULL) {
+                                       if (! current->is_logic )
+                                               listaItems.push_back(current);
+                                       else {
+                                               lista_logic_Items.push_back(current);
+                                       }
                                        // Agrego y conecto la bomba
                                        // Agrego y conecto la bomba
-                                       listaItems.push_back(current);
                                        current->drag_source_set(listTargets);
                                        workplace->put(*current, current->get_position_x(), current->get_position_y());
                                        //Apunto al workplace
                                        current->workplace= workplace;
                                        //Apunto a la lista.
                                        current->combo_entry = combo_entry;
                                        current->drag_source_set(listTargets);
                                        workplace->put(*current, current->get_position_x(), current->get_position_y());
                                        //Apunto al workplace
                                        current->workplace= workplace;
                                        //Apunto a la lista.
                                        current->combo_entry = combo_entry;
+                                       //Apunto a la lista de apuntados
+                                       current->list_pointed = &list_pointed;
                                        //Apunto a la listaItems.
                                        current->listaItems = &listaItems;
                                        //Apunto a la lista de items logicos
                                        current->lista_logic_Items = &lista_logic_Items;
                                        //Apunto a la listaItems.
                                        current->listaItems = &listaItems;
                                        //Apunto a la lista de items logicos
                                        current->lista_logic_Items = &lista_logic_Items;
+                                       //Apunto a la barra de estado
+                                       current->status_bar = status_bar;
                                        // Conecto las señales
                                        current->signal_drag_data_get().connect( SigC::slot(*this, &Constructor::on_item_drag_data_get));
                                        current->signal_drag_begin().connect(SigC::bind( SigC::slot(*this, &Constructor::on_item_drag_begin), current));
                                        // Conecto las señales
                                        current->signal_drag_data_get().connect( SigC::slot(*this, &Constructor::on_item_drag_data_get));
                                        current->signal_drag_begin().connect(SigC::bind( SigC::slot(*this, &Constructor::on_item_drag_begin), current));
@@ -286,14 +323,42 @@ void Constructor::on_load_from_xml()
                        }
                        items = items->next;
                }
                        }
                        items = items->next;
                }
+               
+               // Crea las lineas que conectan la parte logica.
+               create_lines(document->children);
+               xmlFreeDoc(document);
+               workplace->update_logic_position();
+               workplace->queue_draw();
        } else {
        } else {
+               std::cout<< "EL XML NO ES VALIDO" << std::endl;
                // TODO : avisar que el XML no es valido!!
        }
        std::cout << "CARGA COMPLETA" << std::endl;
        file_open_selection->hide();
                // TODO : avisar que el XML no es valido!!
        }
        std::cout << "CARGA COMPLETA" << std::endl;
        file_open_selection->hide();
-       id = listaItems.size()+lista_logic_Items.size()+1;
+       
+       // 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 
+       // cargado desde un archivo.
+       int id_1 = -1 , id_2 = -1;
+       std::list<CItem *>::iterator i = listaItems.begin();
+       while ( i != listaItems.end() ){
+               if ( (*i)->get_id() >= id_1 ) 
+                       id_1 = (*i)->get_id();
+       i++;
+       }
+       id_1++;
+       
+       i = lista_logic_Items.begin();
+       while ( i != lista_logic_Items.end() ){
+               if ( (*i)->get_id() >= id_2 ) 
+                       id_2 = (*i)->get_id();
+       i++;
+       }
+       id_2++;
+       if ( id_1 < id_2 ) id = id_2;
+       else id = id_1;
 }
 
 }
 
+// Recorre todo los items los cuales conocen la manera de salvarse en un archivo XML.
 void Constructor::on_btn_file_ok_clicked()
 {
        std::list<CItem *>::iterator i = listaItems.begin();
 void Constructor::on_btn_file_ok_clicked()
 {
        std::list<CItem *>::iterator i = listaItems.begin();
@@ -319,6 +384,7 @@ void Constructor::on_btn_file_ok_clicked()
        file_selection->hide();
 }
 
        file_selection->hide();
 }
 
+// Salva el archivo, si no estaba salvado muestra el dialogo, si no sobreescribe el ultimo archivo salvado.
 void Constructor::on_quick_btn_save_clicked()
 {
        if ( ! saved ) {
 void Constructor::on_quick_btn_save_clicked()
 {
        if ( ! saved ) {
@@ -328,46 +394,64 @@ void Constructor::on_quick_btn_save_clicked()
        }
 }
        
        }
 }
        
+// Limpia la pantalla para comenzar un nuevo proyecto.
 void Constructor::on_quick_btn_new_clicked()
 {
        on_quick_btn_delete_all_clicked();
        saved = false;
 }
 
 void Constructor::on_quick_btn_new_clicked()
 {
        on_quick_btn_delete_all_clicked();
        saved = false;
 }
 
+// Borra todos los items pero desde otro boton.
 void Constructor::on_quick_btn_delete_all_clicked()
 {
 void Constructor::on_quick_btn_delete_all_clicked()
 {
+       on_edit_menu_delete_all();
+}      
+
+// busca en la lista el nombre del item que aparece en el cuadro de texto y si lo encuentra dibuja un recuadro para mostrarlo.
+void Constructor::on_btn_find_clicked()
+{
+       CItem * temp = NULL;
        std::list<CItem *>::iterator i = listaItems.begin();
        std::list<CItem *>::iterator i = listaItems.begin();
-       while ( i != listaItems.end() ){
-               CItem *temp = *i;
-               listaItems.erase(i);
-               delete temp;
-               i = listaItems.begin();
+       while ( i !=listaItems.end() ) {
+               if ( (*i)->get_name()  == combo_entry->get_entry()->get_text() ) {
+                       temp = *i;
+                       break;
+               }
+               i++;
        }
        }
+       
        i = lista_logic_Items.begin();
        i = lista_logic_Items.begin();
-       while ( i != lista_logic_Items.end() ){
-               CItem *temp2 = *i;
-               lista_logic_Items.erase(i);
-               delete temp2;
-               i = lista_logic_Items.begin();
+       while ( i !=lista_logic_Items.end() ) {
+               if ( (*i)->get_name()  == combo_entry->get_entry()->get_text() ) {
+                       temp = *i;
+                       break;
+               }
+               i++;
        }
        }
-       id = 0;
-}      
+       if ( temp != NULL )
+       workplace->get_window()->draw_rectangle(workplace->get_style()->get_black_gc(), false , temp->get_position_x()-5, temp->get_position_y()-5,
+                                                                                                                                               temp->get_image()->get_width()+10, temp->get_image()->get_height()+10);
+}
 
 
+// Oculta el dialogo.
 void Constructor::on_btn_file_cancel_clicked()
 {
        file_selection->hide();
 }
 
 void Constructor::on_btn_file_cancel_clicked()
 {
        file_selection->hide();
 }
 
+//Muestra el dialogo para seleccionar archivo
 void Constructor::on_btn_open_cancel_clicked()
 {
        file_open_selection->hide();
 }
 
 void Constructor::on_btn_open_cancel_clicked()
 {
        file_open_selection->hide();
 }
 
+// Oculta el dialogo
 void Constructor::on_btn_dlg_connect_clicked()
 {
        dlg_connect->hide();
 }
 
 void Constructor::on_btn_dlg_connect_clicked()
 {
        dlg_connect->hide();
 }
 
+//Metodos que permiten que el icono sea el del items durante el drag 
 void Constructor::on_canio_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)
 {
        context->set_icon(ico_canio, 5, 5); 
 void Constructor::on_canio_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)
 {
        context->set_icon(ico_canio, 5, 5); 
@@ -428,6 +512,7 @@ void Constructor::on_item_drag_data_get(const Glib::RefPtr<Gdk::DragContext>& co
        gtk_selection_data_set (selection_data, selection_data->target, 10, (const guchar*)"item_codo.png", 13);
 }
 
        gtk_selection_data_set (selection_data, selection_data->target, 10, (const guchar*)"item_codo.png", 13);
 }
 
+// Si un item es movido encima de otro este metodo devueve falso. De esta manera no podran encimarse items.
 bool Constructor::can_drop(CItem *item, int _x, int _y)
 {
        std::list<CItem*>::iterator  i = listaItems.begin();
 bool Constructor::can_drop(CItem *item, int _x, int _y)
 {
        std::list<CItem*>::iterator  i = listaItems.begin();
@@ -446,6 +531,8 @@ bool Constructor::can_drop(CItem *item, int _x, int _y)
        return true;
 }
 
        return true;
 }
 
+//Cada vez que se realiza un drag o un drop este metodo es invocado.
+//Aca se validan las posiciones de los items y se crean si no estaban en el area de trabajo.
 void Constructor::on_item_drop_drag_received(const Glib::RefPtr<Gdk::DragContext>& context, int x, int y, GtkSelectionData* selection_data, guint info, guint time)
 {
        workplace->update_logic_position();
 void Constructor::on_item_drop_drag_received(const Glib::RefPtr<Gdk::DragContext>& context, int x, int y, GtkSelectionData* selection_data, guint info, guint time)
 {
        workplace->update_logic_position();
@@ -497,11 +584,15 @@ void Constructor::on_item_drop_drag_received(const Glib::RefPtr<Gdk::DragContext
                        if ( can_drop(a, i*32, j*32) ) {
                                workplace->put(*a, i*32, j*32);
                                //Apunto al workplace
                        if ( can_drop(a, i*32, j*32) ) {
                                workplace->put(*a, i*32, j*32);
                                //Apunto al workplace
-                               a->workplace= workplace;
+                               a->workplace = workplace;
                                //Apunto a la lista.
                                a->combo_entry = combo_entry;
                                //Apunto a la lista.
                                a->combo_entry = combo_entry;
+                               //Apunto a la lista de apuntados
+                               a->list_pointed = &list_pointed;
                                //Apunto a la listaItems.
                                a->listaItems = &listaItems;
                                //Apunto a la listaItems.
                                a->listaItems = &listaItems;
+                               //Apunto a la barra de estado
+                               a->status_bar = status_bar;
                                //Apunto a la lista de items logicos
                                a->lista_logic_Items = &lista_logic_Items;
                                //Seteo la posicion del item
                                //Apunto a la lista de items logicos
                                a->lista_logic_Items = &lista_logic_Items;
                                //Seteo la posicion del item
@@ -533,6 +624,9 @@ void Constructor::on_item_drop_drag_received(const Glib::RefPtr<Gdk::DragContext
        workplace->queue_draw();
 }
 
        workplace->queue_draw();
 }
 
+// Cuando se presiona el boton "Verificar Conexiones" esta funcion es invocada
+//Muestra un dialogo de error en caso de que no esten bien conectados y un dialogo
+//de exito si lo estan.
 void Constructor::on_btn_check_clicked()
 {
        Glib::ustring name;
 void Constructor::on_btn_check_clicked()
 {
        Glib::ustring name;
@@ -547,7 +641,8 @@ void Constructor::on_btn_check_clicked()
        }
 }
 
        }
 }
 
-
+//Verifica que todos los items esten correctamente conectados en sus extremos.
+//Cada item verifica su conexion en forma independiente.
 bool Constructor::check_connection(Glib::ustring& name)
 {
        std::list<CItem *>::iterator i = listaItems.begin();
 bool Constructor::check_connection(Glib::ustring& name)
 {
        std::list<CItem *>::iterator i = listaItems.begin();
@@ -580,12 +675,101 @@ bool Constructor::check_connection(Glib::ustring& name)
        return true;
 }      
 
        return true;
 }      
 
+
+//Los siguientes metodos son utilizados para levantar cada item desde el XML
+
+Not *Constructor::loadNot(xmlNodePtr nodo)
+{
+       std::string name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
+       std::string id = (char *)xmlGetProp(nodo, BAD_CAST"id");
+       int orientacion=0, x, y;
+
+       nodo = nodo->children;
+       while (nodo != NULL) {
+               if (nodo->type == XML_ELEMENT_NODE) {
+                       if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
+                               orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
+                       } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
+                               x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
+                       } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
+                               y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
+                       }
+               }
+               nodo = nodo->next;
+       }
+
+       Not *p = new Not(orientacion);
+       p->set_position(x,y);
+       p->set_id( atoi(id.c_str()) );
+       p->set_name(name);
+
+       return p;
+}
+
+Or *Constructor::loadOr(xmlNodePtr nodo)
+{
+       std::string name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
+       std::string id = (char *)xmlGetProp(nodo, BAD_CAST"id");
+       int orientacion=0, x, y;
+
+       nodo = nodo->children;
+       while (nodo != NULL) {
+               if (nodo->type == XML_ELEMENT_NODE) {
+                       if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
+                               orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
+                       } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
+                               x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
+                       } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
+                               y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
+                       }
+               }
+               nodo = nodo->next;
+       }
+
+       Or *p = new Or(orientacion);
+       p->set_position(x,y);
+       p->set_id( atoi(id.c_str()) );
+       p->set_name(name);
+
+       return p;
+}
+
+And *Constructor::loadAnd(xmlNodePtr nodo)
+{
+       std::string name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
+       std::string id = (char *)xmlGetProp(nodo, BAD_CAST"id");
+       int orientacion=0, x, y;
+       float flujo;
+       xmlNodePtr inicial = nodo;
+
+       nodo = nodo->children;
+       while (nodo != NULL) {
+               if (nodo->type == XML_ELEMENT_NODE) {
+                       if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
+                               orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
+                       } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
+                               x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
+                       } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
+                               y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
+                       }
+               }
+               nodo = nodo->next;
+       }
+
+       And *p = new And(orientacion);
+       p->set_position(x,y);
+       p->set_id( atoi(id.c_str()) );
+       p->set_name(name);
+       return p;
+}
+
 Pump *Constructor::loadBomba(xmlNodePtr nodo)
 {
        std::string name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
        std::string id = (char *)xmlGetProp(nodo, BAD_CAST"id");
        int orientacion=0, x, y;
        float flujo;
 Pump *Constructor::loadBomba(xmlNodePtr nodo)
 {
        std::string name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
        std::string id = (char *)xmlGetProp(nodo, BAD_CAST"id");
        int orientacion=0, x, y;
        float flujo;
+       Gdk::Color color;
 
        nodo = nodo->children;
        while (nodo != NULL) {
 
        nodo = nodo->children;
        while (nodo != NULL) {
@@ -599,7 +783,7 @@ Pump *Constructor::loadBomba(xmlNodePtr nodo)
                        } else if (xmlStrcmp(nodo->name, BAD_CAST"entrega") == 0) {
                                flujo = atof( (char *)XML_GET_CONTENT(nodo->children) );
                        } else if (xmlStrcmp(nodo->name, BAD_CAST"color") == 0) {
                        } else if (xmlStrcmp(nodo->name, BAD_CAST"entrega") == 0) {
                                flujo = atof( (char *)XML_GET_CONTENT(nodo->children) );
                        } else if (xmlStrcmp(nodo->name, BAD_CAST"color") == 0) {
-                               // FIXME !
+                               color = loadColor(nodo->children);
                        }
                }
                nodo = nodo->next;
                        }
                }
                nodo = nodo->next;
@@ -610,10 +794,31 @@ Pump *Constructor::loadBomba(xmlNodePtr nodo)
        p->set_entrega(flujo);
        p->set_id( atoi(id.c_str()) );
        p->set_name(name);
        p->set_entrega(flujo);
        p->set_id( atoi(id.c_str()) );
        p->set_name(name);
+       p->set_liquid_color(color);
 
        return p;
 }
 
 
        return p;
 }
 
+Gdk::Color Constructor::loadColor(xmlNodePtr nodo)
+{
+       gushort r,g,b;
+       while (nodo != NULL) {
+               if (nodo->type == XML_ELEMENT_NODE) {
+                       if (xmlStrcmp(nodo->name, BAD_CAST"rojo")==0)
+                               r = atoi( (char *)XML_GET_CONTENT(nodo->children) );
+                       if (xmlStrcmp(nodo->name, BAD_CAST"verde")==0)
+                               g = atoi( (char *)XML_GET_CONTENT(nodo->children) );
+                       if (xmlStrcmp(nodo->name, BAD_CAST"azul")==0)
+                               b = atoi( (char *)XML_GET_CONTENT(nodo->children) );
+               }
+               nodo = nodo->next;
+       }
+       Gdk::Color c;
+       c.set_rgb(r,g,b);
+       std::cout << r << "  " << g << " " << b << std::endl;
+       return c;
+}
+
 Conduct *Constructor::loadConduct(xmlNodePtr nodo)
 {
        std::string name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
 Conduct *Constructor::loadConduct(xmlNodePtr nodo)
 {
        std::string name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
@@ -685,6 +890,7 @@ Cistern *Constructor::loadTank(xmlNodePtr nodo)
        std::string id = (char *)xmlGetProp(nodo, BAD_CAST"id");
        int orientacion=0, x, y;
        float liquido,capacidad;
        std::string id = (char *)xmlGetProp(nodo, BAD_CAST"id");
        int orientacion=0, x, y;
        float liquido,capacidad;
+       Gdk::Color color;
 
        nodo = nodo->children;
        while (nodo != NULL) {
 
        nodo = nodo->children;
        while (nodo != NULL) {
@@ -699,6 +905,8 @@ Cistern *Constructor::loadTank(xmlNodePtr nodo)
                                capacidad = atof ((char *)XML_GET_CONTENT(nodo->children) );
                        } else if (xmlStrcmp(nodo->name, BAD_CAST"inicial") == 0) {
                                liquido = atof ((char *)XML_GET_CONTENT(nodo->children) );
                                capacidad = atof ((char *)XML_GET_CONTENT(nodo->children) );
                        } else if (xmlStrcmp(nodo->name, BAD_CAST"inicial") == 0) {
                                liquido = atof ((char *)XML_GET_CONTENT(nodo->children) );
+                       } else if (xmlStrcmp(nodo->name, BAD_CAST"color") == 0) {
+                               color = loadColor(nodo->children);
                        }
                }
                nodo = nodo->next;
                        }
                }
                nodo = nodo->next;
@@ -710,7 +918,7 @@ Cistern *Constructor::loadTank(xmlNodePtr nodo)
        p->set_name(name);
        p->set_capacidad(capacidad);
        p->set_contenido_inicial(liquido);
        p->set_name(name);
        p->set_capacidad(capacidad);
        p->set_contenido_inicial(liquido);
-
+       p->set_liquid_color(color);
        return p;
 }
 
        return p;
 }
 
@@ -809,3 +1017,76 @@ Splitter *Constructor::loadCodo(xmlNodePtr nodo)
 
        return p;
 }
 
        return p;
 }
+
+void Constructor::create_lines(xmlNodePtr nodo)
+{
+       std::string name;
+       
+       nodo = nodo->children;
+       while (nodo != NULL) {
+               if (nodo->type == XML_ELEMENT_NODE) {
+                       if (xmlStrcmp(nodo->name, BAD_CAST"and")==0) {
+                               name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
+                               std::cout << name << std::endl;
+                               create_line(nodo->children, workplace->get_logic_id(name));
+                       } else if (xmlStrcmp(nodo->name, BAD_CAST"not")==0) {
+                               name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
+                               std::cout << name << std::endl;
+                               create_line(nodo->children, workplace->get_logic_id(name));
+                       } else if (xmlStrcmp(nodo->name, BAD_CAST"or")==0) {
+                               name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
+                               std::cout << name << std::endl;
+                               create_line(nodo->children, workplace->get_logic_id(name));
+                       }
+               }
+               nodo = nodo->next;
+       }
+}
+
+//Levanta las lineas desde el archvo XML 
+void Constructor::create_line(xmlNodePtr nodo, int logic_id)
+{
+       std::string otro;
+       std::cout << "Buscando lineas ..." << std::endl;
+       while (nodo != NULL) {
+               if (nodo->type == XML_ELEMENT_NODE) {
+                       if (xmlStrcmp(nodo->name, BAD_CAST"salida")==0) {
+                               otro = (char *)XML_GET_CONTENT(nodo->children);
+                               t_line tmp_line;
+                               tmp_line.logic_id = logic_id;
+                               //workplace->get_logic_item(logic_id)->set_out_connected(true);
+                               if (workplace->get_item_id(otro) != -1) {
+                                       tmp_line.store_id = workplace->get_item_id(otro);
+                                       std::cout << otro << " se conecta a una compuerta" << std::endl;
+                                       workplace->lista_lineas_in.push_back(tmp_line);
+                               } else {
+                                       /* Como no era un item, debe ser una compuerta */
+                                       tmp_line.store_id = workplace->get_logic_id(otro);
+                                       workplace->lista_lineas_logic.push_back(tmp_line);
+                               }
+                       } else if (xmlStrcmp(nodo->name, BAD_CAST"entrada")==0) {
+                               otro = (char *)XML_GET_CONTENT(nodo->children);
+                               t_line tmp_line;
+                               tmp_line.logic_id = logic_id;
+                               if (workplace->get_item_id(otro) != -1) {
+                                       tmp_line.store_id = workplace->get_item_id(otro);
+                                       /* Tengo que ver si es un tanque, para setearlo correctamente */
+                                       if (dynamic_cast<Cistern *>(workplace->get_item(workplace->get_item_id(otro)))) {
+                                               std::string donde = (char *)xmlGetProp(nodo, BAD_CAST"id");
+                                               tmp_line.cistern_out1 = true;
+                                               if (donde == "inferior") {
+                                                       tmp_line.cistern_out1 = false;
+                                               }
+                                       }
+                                       workplace->lista_lineas_out.push_back(tmp_line);
+                                       std::cout << otro << " se conecta a una compuerta" << std::endl;
+                               } else {
+                                       /* Como no era un item, debe ser una compuerta */
+                                       tmp_line.store_id = workplace->get_logic_id(otro);
+                                       workplace->lista_lineas_logic.push_back(tmp_line);
+                               }
+                       }
+               }
+               nodo = nodo->next;
+       }
+}