From: Ricardo Markiewicz Date: Thu, 27 Nov 2003 22:47:10 +0000 (+0000) Subject: * Ahora el modelo carga las compuertas logicas y crea las lineas necesarias X-Git-Tag: svn_import~168 X-Git-Url: https://git.llucax.com/z.facultad/75.42/plaqui.git/commitdiff_plain/f1f01b21410b676a9c35c93251d5739bb65c711d * Ahora el modelo carga las compuertas logicas y crea las lineas necesarias --- diff --git a/Constructor/include/and.h b/Constructor/include/and.h index 754a534..f523fd6 100644 --- a/Constructor/include/and.h +++ b/Constructor/include/and.h @@ -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(); diff --git a/Constructor/include/constructor.h b/Constructor/include/constructor.h index 702e796..0746191 100644 --- a/Constructor/include/constructor.h +++ b/Constructor/include/constructor.h @@ -103,6 +103,8 @@ class Constructor : public Gtk::Window { virtual void on_item_drop_drag_received(const Glib::RefPtr& 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 diff --git a/Constructor/include/not.h b/Constructor/include/not.h index 77c086e..9fdde6f 100644 --- a/Constructor/include/not.h +++ b/Constructor/include/not.h @@ -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(); diff --git a/Constructor/include/or.h b/Constructor/include/or.h index d950623..9a22b3e 100644 --- a/Constructor/include/or.h +++ b/Constructor/include/or.h @@ -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(); diff --git a/Constructor/include/workplace.h b/Constructor/include/workplace.h index cb31561..960e046 100644 --- a/Constructor/include/workplace.h +++ b/Constructor/include/workplace.h @@ -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(); diff --git a/Constructor/src/and.cpp b/Constructor/src/and.cpp index 327e7c2..0ef3bbd 100644 --- a/Constructor/src/and.cpp +++ b/Constructor/src/and.cpp @@ -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) ) ) ; diff --git a/Constructor/src/constructor.cpp b/Constructor/src/constructor.cpp index a7e44aa..e8654c1 100644 --- a/Constructor/src/constructor.cpp +++ b/Constructor/src/constructor.cpp @@ -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; + } +} diff --git a/Constructor/src/not.cpp b/Constructor/src/not.cpp index 0d7e409..2fc63e2 100644 --- a/Constructor/src/not.cpp +++ b/Constructor/src/not.cpp @@ -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) ) ) ; diff --git a/Constructor/src/or.cpp b/Constructor/src/or.cpp index 4fdf2f2..4cbd535 100644 --- a/Constructor/src/or.cpp +++ b/Constructor/src/or.cpp @@ -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) ) ) ; diff --git a/Constructor/src/workplace.cpp b/Constructor/src/workplace.cpp index 2b04130..847aa17 100644 --- a/Constructor/src/workplace.cpp +++ b/Constructor/src/workplace.cpp @@ -174,6 +174,27 @@ CItem *WorkPlace::get_item(int _id) return NULL; } +int WorkPlace::get_logic_id(const std::string &_s) +{ + std::list::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::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) {