]> git.llucax.com Git - z.facultad/75.42/plaqui.git/commitdiff
* Ahora el modelo carga las compuertas logicas y crea las lineas necesarias
authorRicardo Markiewicz <gazer.arg@gmail.com>
Thu, 27 Nov 2003 22:47:10 +0000 (22:47 +0000)
committerRicardo Markiewicz <gazer.arg@gmail.com>
Thu, 27 Nov 2003 22:47:10 +0000 (22:47 +0000)
Constructor/include/and.h
Constructor/include/constructor.h
Constructor/include/not.h
Constructor/include/or.h
Constructor/include/workplace.h
Constructor/src/and.cpp
Constructor/src/constructor.cpp
Constructor/src/not.cpp
Constructor/src/or.cpp
Constructor/src/workplace.cpp

index 754a5343b34983df1539272cc3506f58c3ab781c..f523fd6248356064056c5bfd79e622834dbf6932 100644 (file)
@@ -5,7 +5,7 @@
 
 class And : public CItem {
        public:
-               And();
+               And(int orientacion=0);
                virtual ~And();
                virtual bool on_button_press_event(GdkEventButton *event);
                virtual void on_menu_popup_rotar();
index 702e79647158ace61f373fbf1f9d385db5a2862d..0746191f7218670b8afe5e44eff6bd1309a9d8a6 100644 (file)
@@ -103,6 +103,8 @@ class Constructor : public Gtk::Window {
        virtual void on_item_drop_drag_received(const Glib::RefPtr<Gdk::DragContext>& context, int x, int y, GtkSelectionData* selection_data, guint info, guint time);
 
        // Carga desde un XML
+       void create_lines(xmlNodePtr nodo);
+       void create_line(xmlNodePtr nodo, int logic_id);
        Pump *loadBomba(xmlNodePtr nodo);
        Conduct *loadConduct(xmlNodePtr nodo);
        Exclusa *loadExclusa(xmlNodePtr nodo);
@@ -110,5 +112,8 @@ class Constructor : public Gtk::Window {
        Union *loadUnion(xmlNodePtr nodo);
        Drain *loadDrain(xmlNodePtr nodo);
        Splitter *loadCodo(xmlNodePtr nodo);
+       And *loadAnd(xmlNodePtr nodo);
+       Not *loadNot(xmlNodePtr nodo);
+       Or *loadOr(xmlNodePtr nodo);
 };
 #endif
index 77c086e244156784d1d0092d33e98715ab6c9c68..9fdde6fcfb1e7550f0186f895402c93d84938349 100644 (file)
@@ -5,7 +5,7 @@
 
 class Not : public CItem {
        public:
-               Not();
+               Not(int orientacion=0);
                virtual ~Not();
                virtual bool on_button_press_event(GdkEventButton *event);
                virtual void on_menu_popup_rotar();
index d9506231e76a3964e2a9728f484c9d9a08d96162..9a22b3ec6927d48c5b99fdd912f688606457dd16 100644 (file)
@@ -5,7 +5,7 @@
 
 class Or : public CItem {
        public:
-               Or();
+               Or(int orientacion=0);
                virtual ~Or();
                virtual bool on_button_press_event(GdkEventButton *event);
                virtual void on_menu_popup_rotar();
index cb3156197c553a6d96e910c129d2ec7eefa2c352..960e04677ef4bb7acaf33a75e911193086710e76 100644 (file)
@@ -42,6 +42,9 @@ class WorkPlace:public Gtk::Fixed {
        
                ///Devuelve un puntero al item  de transporte _id.              
                CItem *get_item(int _id);
+
+               int get_item_id(const std::string &s);
+               int get_logic_id(const std::string &s);
        
                ///Actualiza las posiciones de los conectores logicos.
                void update_logic_position();
index 327e7c28e8d2d01ebb6701e197b640d094b92a60..0ef3bbd058f046236bf36b99a9894fd1861595a4 100644 (file)
@@ -1,19 +1,45 @@
 #include "and.h"
 
-And::And()
+And::And(int orientacion)
 {
+       is_logic = true;
        out_connected = false;
-       in_x = x;
-       in_y = y+16;
-       out_x = x+32;
-       out_y = y+16;
        imageN = Gdk::Pixbuf::create_from_file(PACKAGE_DATA_DIR"/plaqui-constructor/pixmaps/and_n.png");
        imageS = Gdk::Pixbuf::create_from_file(PACKAGE_DATA_DIR"/plaqui-constructor/pixmaps/and_s.png");
        imageE = Gdk::Pixbuf::create_from_file(PACKAGE_DATA_DIR"/plaqui-constructor/pixmaps/and_e.png");
        imageO = Gdk::Pixbuf::create_from_file(PACKAGE_DATA_DIR"/plaqui-constructor/pixmaps/and_o.png");
        null = Gdk::Pixbuf::create_from_file(PACKAGE_DATA_DIR"/plaqui-constructor/pixmaps/null.png");
-       imgActual = 0;
-       image = imageE;
+       imgActual = orientacion;
+       switch (imgActual) {
+               case 1:
+                       image = imageS;
+                       in_x = x +16;
+                       in_y = y;
+                       out_x = x+16;
+                       out_y = y+32;
+                       break;
+               case 2:
+                       image = imageO;
+                       in_x = x+32;
+                       in_y = y+16;
+                       out_x = x;
+                       out_y = y+16;
+                       break;
+               case 3:
+                       image = imageN;
+                       in_x = x+16;
+                       in_y = y+32;
+                       out_x = x+16;
+                       out_y = y;
+                       break;
+               default: 
+                       imgActual = 0;
+                       image = imageE;                 
+                       in_x = x;
+                       in_y = y+16;
+                       out_x = x+32;
+                       out_y = y+16;
+       }
        set_size_request(image->get_width(), image->get_height());
        name = "and";
        menulist.push_back( Gtk::Menu_Helpers::ImageMenuElem("Conectar", menu_image_linea,SigC::slot(*this, &CItem::on_menu_popup_conectar) ) ) ;
index a7e44aa6846217a34d88ae2a0fbdc02dd1bf339c..e8654c143bbdb63608de369c16b93449acbda45d 100644 (file)
@@ -272,11 +272,21 @@ void Constructor::on_load_from_xml()
                                        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->is_logic )
+                                               listaItems.push_back(current);
+                                       else {
+                                               lista_logic_Items.push_back(current);
+                                       }
                                        // 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
@@ -299,7 +309,11 @@ void Constructor::on_load_from_xml()
                        }
                        items = items->next;
                }
+
+               create_lines(document->children);
                xmlFreeDoc(document);
+               workplace->update_logic_position();
+               workplace->queue_draw();
        } else {
                // TODO : avisar que el XML no es valido!!
        }
@@ -609,6 +623,91 @@ bool Constructor::check_connection(Glib::ustring& name)
        return true;
 }      
 
+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");
@@ -838,3 +937,55 @@ Splitter *Constructor::loadCodo(xmlNodePtr nodo)
 
        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;
+       }
+}
+
+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);
+                               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);
+                       } 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;
+                       }
+               }
+               nodo = nodo->next;
+       }
+}
index 0d7e409a322b83355afb574e60c58bb92e02e5b1..2fc63e2ba60f4d9abb0446d6081e0cdbc5b8986f 100644 (file)
@@ -1,19 +1,45 @@
 #include "not.h"
 
-Not::Not()
+Not::Not(int orientacion)
 {
+       is_logic = true;
        in_connected = out_connected = false;
-       in_x = x;
-       in_y = y+16;
-       out_x = x+32;
-       out_y = y+16;
        imageN = Gdk::Pixbuf::create_from_file(PACKAGE_DATA_DIR"/plaqui-constructor/pixmaps/not_n.png");
        imageS = Gdk::Pixbuf::create_from_file(PACKAGE_DATA_DIR"/plaqui-constructor/pixmaps/not_s.png");
        imageE = Gdk::Pixbuf::create_from_file(PACKAGE_DATA_DIR"/plaqui-constructor/pixmaps/not_e.png");
        imageO = Gdk::Pixbuf::create_from_file(PACKAGE_DATA_DIR"/plaqui-constructor/pixmaps/not_o.png");
        null = Gdk::Pixbuf::create_from_file(PACKAGE_DATA_DIR"/plaqui-constructor/pixmaps/null.png");
-       imgActual = 0;
-       image = imageE;
+       imgActual = orientacion;
+       switch (imgActual) {
+               case 1:
+                       image = imageS;
+                       in_x = x +16;
+                       in_y = y;
+                       out_x = x+16;
+                       out_y = y+32;
+                       break;
+               case 2:
+                       image = imageO;
+                       in_x = x+32;
+                       in_y = y+16;
+                       out_x = x;
+                       out_y = y+16;
+                       break;
+               case 3:
+                       image = imageN;
+                       in_x = x+16;
+                       in_y = y+32;
+                       out_x = x+16;
+                       out_y = y;
+                       break;
+               default: 
+                       imgActual = 0;
+                       image = imageE;                 
+                       in_x = x;
+                       in_y = y+16;
+                       out_x = x+32;
+                       out_y = y+16;
+       }
        set_size_request(image->get_width(), image->get_height());
        name = "not";
        menulist.push_back( Gtk::Menu_Helpers::ImageMenuElem("Conectar", menu_image_linea,SigC::slot(*this, &CItem::on_menu_popup_conectar) ) ) ;
index 4fdf2f2ae9636ae09ab0ca269f2c840263b9842e..4cbd5352a6d6ebd6c4192974bf0883e6add1accd 100644 (file)
@@ -1,19 +1,45 @@
 #include "or.h"
 
-Or::Or()
+Or::Or(int orientacion)
 {
+       is_logic = true;
        out_connected = false;
-       in_x = x;
-       in_y = y+16;
-       out_x = x+32;
-       out_y = y+16;
        imageN = Gdk::Pixbuf::create_from_file(PACKAGE_DATA_DIR"/plaqui-constructor/pixmaps/or_n.png");
        imageS = Gdk::Pixbuf::create_from_file(PACKAGE_DATA_DIR"/plaqui-constructor/pixmaps/or_s.png");
        imageE = Gdk::Pixbuf::create_from_file(PACKAGE_DATA_DIR"/plaqui-constructor/pixmaps/or_e.png");
        imageO = Gdk::Pixbuf::create_from_file(PACKAGE_DATA_DIR"/plaqui-constructor/pixmaps/or_o.png");
        null = Gdk::Pixbuf::create_from_file(PACKAGE_DATA_DIR"/plaqui-constructor/pixmaps/null.png");
-       imgActual = 0;
-       image = imageE;
+       imgActual = orientacion;
+       switch (imgActual) {
+               case 1:
+                       image = imageS;
+                       in_x = x +16;
+                       in_y = y;
+                       out_x = x+16;
+                       out_y = y+32;
+                       break;
+               case 2:
+                       image = imageO;
+                       in_x = x+32;
+                       in_y = y+16;
+                       out_x = x;
+                       out_y = y+16;
+                       break;
+               case 3:
+                       image = imageN;
+                       in_x = x+16;
+                       in_y = y+32;
+                       out_x = x+16;
+                       out_y = y;
+                       break;
+               default: 
+                       imgActual = 0;
+                       image = imageE;                 
+                       in_x = x;
+                       in_y = y+16;
+                       out_x = x+32;
+                       out_y = y+16;
+       }
        set_size_request(image->get_width(), image->get_height());
        name = "or";
        menulist.push_back( Gtk::Menu_Helpers::ImageMenuElem("Conectar", menu_image_linea,SigC::slot(*this, &CItem::on_menu_popup_conectar) ) ) ;
index 2b04130487e1e58665709e74b767cb5b044b93b0..847aa17930769248e8480b28a7bf0c272d93bf06 100644 (file)
@@ -174,6 +174,27 @@ CItem *WorkPlace::get_item(int _id)
        return NULL;
 }
 
+int WorkPlace::get_logic_id(const std::string &_s)
+{
+       std::list<CItem *>::iterator i = lista_logic_Items->begin();
+       while ( i != lista_logic_Items->end() ){
+               if ( (*i)->get_name() == _s ) 
+                       return (*i)->get_id();
+               i++;
+       }
+       return -1;
+}
+
+int WorkPlace::get_item_id(const std::string &_s)
+{
+       std::list<CItem *>::iterator i = listaItems->begin();
+       while ( i != listaItems->end() ){
+               if ( (*i)->get_name() == _s ) 
+                       return (*i)->get_id();
+               i++;
+       }
+       return -1;
+}
        
 void WorkPlace::delete_line(int _id)
 {