]> git.llucax.com Git - z.facultad/75.42/plaqui.git/blobdiff - Constructor/src/constructor.cpp
Se corrige el XML a mano para probarlo.
[z.facultad/75.42/plaqui.git] / Constructor / src / constructor.cpp
index 8a368099443ee3690758de92cafacb6863601208..86e88421a031bb6f546695417759a0cedfaab6bf 100644 (file)
@@ -1,10 +1,41 @@
 #include "constructor.h"
 #include "constructor.h"
+#include <iostream>
 
 Constructor::Constructor(BaseObjectType* cobject, const Glib::RefPtr<Gnome::Glade::Xml>& refGlade):Gtk::Window(cobject)
 {
        id = 0;
        saved = false;
        set_title("Constructor");
 
 Constructor::Constructor(BaseObjectType* cobject, const Glib::RefPtr<Gnome::Glade::Xml>& refGlade):Gtk::Window(cobject)
 {
        id = 0;
        saved = false;
        set_title("Constructor");
+       Gtk::Label *lbl_plaqui_version;
+       Gtk::Image *plaqui_logo;
+       Gtk::MenuItem *mnu_about;
+       Gtk::Button *close_about;
+       
+       plaqui_logo = 0;
+       lbl_plaqui_version = 0;
+       refGlade->get_widget("lbl_plaqui_version", lbl_plaqui_version);
+       refGlade->get_widget("plaqui_logo", plaqui_logo);
+       plaqui_logo->set(PACKAGE_DATA_DIR"/plaqui-constructor/pixmaps/logo.png");
+
+       refGlade->get_widget("plaqui_logo", plaqui_logo);
+       // Calculo número de revisión.
+       std::string rev = "$Rev$";
+       rev = rev.substr(6, rev.length() - 8);
+       std::string s = "PlaQui Constructor versión " VERSION " (revisión ";
+       s += rev + ")"; 
+       try {
+               lbl_plaqui_version->set_text(Glib::locale_to_utf8(s));
+       }
+       catch (Glib::ConvertError e) {
+               lbl_plaqui_version->set_text("PlaQui Constructor");
+       }
+       catch (...) {
+               lbl_plaqui_version->set_text("PlaQui Constructor");
+       }
+       
+       refGlade->get_widget("dlgAbout", dlg_about);
+       refGlade->get_widget("close_about", close_about);
+       refGlade->get_widget("mnu_about", mnu_about);
        
        // 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");
        
        // 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");
@@ -48,6 +79,9 @@ Constructor::Constructor(BaseObjectType* cobject, const Glib::RefPtr<Gnome::Glad
        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);
        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);
+       refGlade->get_widget("dlg_quit", dlg_quit);
+       refGlade->get_widget("btn_dlg_quit_ok", btn_dlg_quit_ok);
+       refGlade->get_widget("btn_dlg_quit_cancel", btn_dlg_quit_cancel);
        
        //Obtengo el area de trabajo, la cual tiene definida su propia clase.
        refGlade->get_widget_derived("workplace", workplace);  //fixed
        
        //Obtengo el area de trabajo, la cual tiene definida su propia clase.
        refGlade->get_widget_derived("workplace", workplace);  //fixed
@@ -59,6 +93,8 @@ Constructor::Constructor(BaseObjectType* cobject, const Glib::RefPtr<Gnome::Glad
        listTargets.push_back( Gtk::TargetEntry("application/pointer") );
        
        // Le indico cuales son los botones  desde los cuales se puede hacer un drag.
        listTargets.push_back( Gtk::TargetEntry("application/pointer") );
        
        // Le indico cuales son los botones  desde los cuales se puede hacer un drag.
+       mnu_about->signal_activate().connect( SigC::slot(*dlg_about, &Gtk::Widget::show) );
+       close_about->signal_clicked().connect( SigC::slot(*dlg_about, &Gtk::Widget::hide) );
        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);
@@ -88,6 +124,8 @@ Constructor::Constructor(BaseObjectType* cobject, const Glib::RefPtr<Gnome::Glad
        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));
+       btn_dlg_quit_ok->signal_clicked().connect(SigC::slot(*this, &Constructor::on_btn_dlg_quit_ok_clicked));
+       btn_dlg_quit_cancel->signal_clicked().connect(SigC::slot(*this, &Constructor::on_btn_dlg_quit_cancel_clicked));
        
        main_menu_quit->signal_activate().connect(SigC::slot(*this, &Constructor::on_main_menu_quit));
        main_menu_new->signal_activate().connect(SigC::slot(*this, &Constructor::on_quick_btn_new_clicked));
        
        main_menu_quit->signal_activate().connect(SigC::slot(*this, &Constructor::on_main_menu_quit));
        main_menu_new->signal_activate().connect(SigC::slot(*this, &Constructor::on_quick_btn_new_clicked));
@@ -183,14 +221,35 @@ 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.
+//Sale del programa. Pregunta si desea salvar antes de salir.
 void Constructor::on_main_menu_quit()
 {
 void Constructor::on_main_menu_quit()
 {
-       delete this;
+       if ( !saved ) 
+               dlg_quit->show();
+       else 
+               Gtk::Main::quit();
+}
+bool Constructor::on_delete_event(GdkEventAny *e)
+{
+       std::cout<<"terminando constructor"<<std::endl;
+       on_main_menu_quit();
+       return true;
+}
+//Sale del programa guardando el archivo.
+void Constructor::on_btn_dlg_quit_ok_clicked()
+{
+       dlg_quit->hide();
+       on_quick_btn_save_clicked();
+}
+
+//Sale del programa sin guardar el archivo.
+void Constructor::on_btn_dlg_quit_cancel_clicked()
+{
+       dlg_quit->hide();
        Gtk::Main::quit();
        Gtk::Main::quit();
-       //hide();
 }
 
 }
 
+
 // Carga de un archivo XML
 void Constructor::on_main_menu_open()
 {
 // Carga de un archivo XML
 void Constructor::on_main_menu_open()
 {
@@ -769,6 +828,7 @@ Pump *Constructor::loadBomba(xmlNodePtr nodo)
        std::string id = (char *)xmlGetProp(nodo, BAD_CAST"id");
        int orientacion=0, x, y;
        float flujo;
        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) {
@@ -782,7 +842,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;
@@ -793,10 +853,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");
@@ -868,6 +949,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) {
@@ -882,6 +964,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;
@@ -893,7 +977,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;
 }
 
@@ -1030,16 +1114,36 @@ void Constructor::create_line(xmlNodePtr nodo, int logic_id)
                                t_line tmp_line;
                                tmp_line.logic_id = logic_id;
                                //workplace->get_logic_item(logic_id)->set_out_connected(true);
                                t_line tmp_line;
                                tmp_line.logic_id = logic_id;
                                //workplace->get_logic_item(logic_id)->set_out_connected(true);
-                               tmp_line.store_id = workplace->get_item_id(otro);
-                               std::cout << otro << " " << tmp_line.logic_id << " " << tmp_line.store_id << std::endl;
-                               workplace->lista_lineas_in.push_back(tmp_line);
+                               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;
                        } 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;
-                               tmp_line.store_id = workplace->get_item_id(otro);
-                               workplace->lista_lineas_out.push_back(tmp_line);
-                               std::cout << otro << " " << tmp_line.logic_id << " " << tmp_line.store_id << std::endl;
+                               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;
                        }
                }
                nodo = nodo->next;