From 65e0e3da6246674b0014c3a7c10aeecb61499725 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Nicol=C3=A1s=20Dimov?= Date: Thu, 20 Nov 2003 06:44:16 +0000 Subject: [PATCH] arreglo miles de bugs que me hicieron cambiar muchas cosas que no eran necesarias porque el bug estaba en otro lado --- Constructor/include/workplace.h | 3 +- Constructor/src/and.cpp | 18 ++++--- Constructor/src/cistern.cpp | 11 ++-- Constructor/src/exclusa.cpp | 11 ++-- Constructor/src/not.cpp | 17 +++--- Constructor/src/or.cpp | 17 +++--- Constructor/src/pump.cpp | 11 ++-- Constructor/src/workplace.cpp | 92 ++++++++++++++++++++------------- 8 files changed, 100 insertions(+), 80 deletions(-) diff --git a/Constructor/include/workplace.h b/Constructor/include/workplace.h index db4b3ce..c4dfc94 100644 --- a/Constructor/include/workplace.h +++ b/Constructor/include/workplace.h @@ -9,7 +9,7 @@ class CItem; typedef struct { - CItem *logic, *store; + int logic_id, store_id; }t_line; class WorkPlace:public Gtk::Fixed { @@ -20,6 +20,7 @@ class WorkPlace:public Gtk::Fixed { void delete_item(int _id); void delete_line(int _id); CItem *get_logic_item(int _id); + CItem *get_item(int _id); void update_logic_position(); std::list *listaItems, *lista_logic_Items; /** Listas de lineas que van de una compuerta a la entrada de un item y de la salida de un item a una compuerta diff --git a/Constructor/src/and.cpp b/Constructor/src/and.cpp index fbee412..4e0534e 100644 --- a/Constructor/src/and.cpp +++ b/Constructor/src/and.cpp @@ -25,10 +25,12 @@ And::~And() bool And::on_button_press_event(GdkEventButton *event) { if ((event->type == GDK_BUTTON_PRESS) && ( event->button == 1)) { - CItem::logic_connect = true; - CItem::gate_id = ID; + if ( CItem::logic_connect ) { + CItem::gate_id = ID; + WorkPlace::pointed = ID; + } combo_entry->set_text(name); - WorkPlace::pointed = ID; + } if ((event->type == GDK_BUTTON_PRESS) && ( event->button == 2)){ @@ -99,7 +101,7 @@ void And::save(FILE *archivo) dato += c_img; dato += c_x; dato += c_y; - for ( int i=0; i<=vec_connector.size()-1; i++) { + for ( int i=0; i<=vec_connector.size()-1&&!vec_connector.empty(); i++) { if ( vec_connector[i].type == IN ) { dato += "\t\t"; dato += vec_connector[i].name_dest + "\n"; @@ -118,9 +120,9 @@ bool And::check_connection() t_logic_connector temp; std::list::iterator i = workplace->lista_lineas_in.begin(); while ( i != workplace->lista_lineas_in.end() ) { - if ( (*i).logic->get_id() == ID ) { + if ( workplace->get_logic_item((*i).logic_id)->get_id() == ID ) { temp.type = OUT; - temp.name_dest = (*i).store->get_name(); + temp.name_dest = workplace->get_item((*i).store_id)->get_name(); vec_connector.push_back(temp); cant_out++; } @@ -129,9 +131,9 @@ bool And::check_connection() i = workplace->lista_lineas_out.begin(); while ( i != workplace->lista_lineas_out.end() ) { - if ( (*i).logic->get_id() == ID ) { + if ( workplace->get_logic_item((*i).logic_id)->get_id() == ID ) { temp.type = IN; - temp.name_dest = (*i).store->get_name(); + temp.name_dest = workplace->get_item((*i).store_id)->get_name(); vec_connector.push_back(temp); cant_in++; } diff --git a/Constructor/src/cistern.cpp b/Constructor/src/cistern.cpp index 5ad6ecb..2f7a02c 100644 --- a/Constructor/src/cistern.cpp +++ b/Constructor/src/cistern.cpp @@ -46,15 +46,15 @@ bool Cistern::on_button_press_event(GdkEventButton *event) if ((event->type == GDK_BUTTON_PRESS) && ( event->button == 1)) { combo_entry->set_text(name); WorkPlace::pointed = ID; - if (CItem::logic_connect) { + if (CItem::logic_connect && CItem::gate_id != -1) { if ( detect_click_position(event->x, event->y) == IN ){ - tmp_line.logic = workplace->get_logic_item(CItem::gate_id); - tmp_line.store = this; + tmp_line.logic_id = workplace->get_logic_item(CItem::gate_id)->get_id(); + tmp_line.store_id = ID; workplace->lista_lineas_in.push_back(tmp_line); workplace->queue_draw(); } else if (detect_click_position(event->x, event->y) == OUT) { - tmp_line.logic = workplace->get_logic_item(CItem::gate_id); - tmp_line.store = this; + tmp_line.logic_id = workplace->get_logic_item(CItem::gate_id)->get_id(); + tmp_line.store_id = ID; workplace->lista_lineas_out.push_back(tmp_line); workplace->queue_draw(); } @@ -96,7 +96,6 @@ bool Cistern::on_button_press_event(GdkEventButton *event) cistern_pty_wnd->txt_cistern_name->set_text( name ); cistern_pty_wnd->show(); } - CItem::logic_connect =false; workplace->queue_draw(); return true; } diff --git a/Constructor/src/exclusa.cpp b/Constructor/src/exclusa.cpp index 365b6e4..ee75ed5 100644 --- a/Constructor/src/exclusa.cpp +++ b/Constructor/src/exclusa.cpp @@ -43,15 +43,15 @@ bool Exclusa::on_button_press_event(GdkEventButton *event) if ((event->type == GDK_BUTTON_PRESS) && ( event->button == 1)) { combo_entry->set_text(name); WorkPlace::pointed = ID; - if (CItem::logic_connect) { + if (CItem::logic_connect && CItem::gate_id != -1) { if ( detect_click_position(event->x, event->y) == IN) { - tmp_line.logic = workplace->get_logic_item(CItem::gate_id); - tmp_line.store = this; + tmp_line.logic_id = workplace->get_logic_item(CItem::gate_id)->get_id(); + tmp_line.store_id = ID; workplace->lista_lineas_in.push_back(tmp_line); workplace->queue_draw(); } else if (detect_click_position(event->x, event->y) == OUT) { - tmp_line.logic = workplace->get_logic_item(CItem::gate_id); - tmp_line.store = this; + tmp_line.logic_id = workplace->get_logic_item(CItem::gate_id)->get_id(); + tmp_line.store_id = ID; workplace->lista_lineas_out.push_back(tmp_line); workplace->queue_draw(); } @@ -91,7 +91,6 @@ bool Exclusa::on_button_press_event(GdkEventButton *event) if (estado) exclusa_pty_wnd->rd_btn_open->set_active(true); exclusa_pty_wnd->show(); } - CItem::logic_connect =false; workplace->queue_draw(); return true; } diff --git a/Constructor/src/not.cpp b/Constructor/src/not.cpp index 668bed8..463a91a 100644 --- a/Constructor/src/not.cpp +++ b/Constructor/src/not.cpp @@ -26,10 +26,11 @@ bool Not::on_button_press_event(GdkEventButton *event) { if ((event->type == GDK_BUTTON_PRESS) && ( event->button == 1)) { - CItem::logic_connect = true; - CItem::gate_id = ID; + if ( CItem::logic_connect ) { + CItem::gate_id = ID; + WorkPlace::pointed = ID; + } combo_entry->set_text(name); - WorkPlace::pointed = ID; } if ((event->type == GDK_BUTTON_PRESS) && ( event->button == 2)){ @@ -100,7 +101,7 @@ void Not::save(FILE *archivo) dato += c_img; dato += c_x; dato += c_y; - for ( int i=0; i<=vec_connector.size()-1; i++) { + for ( int i=0; i<=vec_connector.size()-1&&!vec_connector.empty(); i++) { if ( vec_connector[i].type == IN ) { dato += "\t\t"; dato += vec_connector[i].name_dest + "\n"; @@ -119,9 +120,9 @@ bool Not::check_connection() t_logic_connector temp; std::list::iterator i = workplace->lista_lineas_in.begin(); while ( i != workplace->lista_lineas_in.end() ) { - if ( (*i).logic->get_id() == ID ) { + if ( workplace->get_logic_item((*i).logic_id)->get_id() == ID ) { temp.type = OUT; - temp.name_dest = (*i).store->get_name(); + temp.name_dest = workplace->get_item((*i).store_id)->get_name(); vec_connector.push_back(temp); cant_out++; } @@ -130,9 +131,9 @@ bool Not::check_connection() i = workplace->lista_lineas_out.begin(); while ( i != workplace->lista_lineas_out.end() ) { - if ( (*i).logic->get_id() == ID ) { + if (workplace->get_logic_item((*i).logic_id)->get_id() == ID ) { temp.type = IN; - temp.name_dest = (*i).store->get_name(); + temp.name_dest = workplace->get_item((*i).store_id)->get_name(); vec_connector.push_back(temp); cant_in++; } diff --git a/Constructor/src/or.cpp b/Constructor/src/or.cpp index 9668cac..fbd2152 100644 --- a/Constructor/src/or.cpp +++ b/Constructor/src/or.cpp @@ -25,10 +25,11 @@ Or::~Or() bool Or::on_button_press_event(GdkEventButton *event) { if ((event->type == GDK_BUTTON_PRESS) && ( event->button == 1)) { - CItem::logic_connect = true; - CItem::gate_id = ID; + if ( CItem::logic_connect ) { + CItem::gate_id = ID; + WorkPlace::pointed = ID; + } combo_entry->set_text(name); - WorkPlace::pointed = ID; } if ((event->type == GDK_BUTTON_PRESS) && ( event->button == 2)){ @@ -100,7 +101,7 @@ void Or::save(FILE *archivo) dato += c_img; dato += c_x; dato += c_y; - for ( int i=0; i<=vec_connector.size()-1; i++) { + for ( int i=0; i<=vec_connector.size()-1&&!vec_connector.empty(); i++) { if ( vec_connector[i].type == IN ) { dato += "\t\t"; dato += vec_connector[i].name_dest + "\n"; @@ -119,9 +120,9 @@ bool Or::check_connection() t_logic_connector temp; std::list::iterator i = workplace->lista_lineas_in.begin(); while ( i != workplace->lista_lineas_in.end() ) { - if ( (*i).logic->get_id() == ID ) { + if ( workplace->get_logic_item((*i).logic_id)->get_id() == ID ) { temp.type = OUT; - temp.name_dest = (*i).store->get_name(); + temp.name_dest = workplace->get_item((*i).store_id)->get_name(); vec_connector.push_back(temp); cant_out++; } @@ -130,9 +131,9 @@ bool Or::check_connection() i = workplace->lista_lineas_out.begin(); while ( i != workplace->lista_lineas_out.end() ) { - if ( (*i).logic->get_id() == ID ) { + if ( workplace->get_logic_item((*i).logic_id)->get_id() == ID ) { temp.type = IN; - temp.name_dest = (*i).store->get_name(); + temp.name_dest = workplace->get_item((*i).store_id)->get_name(); vec_connector.push_back(temp); cant_in++; } diff --git a/Constructor/src/pump.cpp b/Constructor/src/pump.cpp index 9d2a95a..8fd4e05 100644 --- a/Constructor/src/pump.cpp +++ b/Constructor/src/pump.cpp @@ -42,15 +42,15 @@ bool Pump::on_button_press_event(GdkEventButton *event) if ((event->type == GDK_BUTTON_PRESS) && ( event->button == 1)) { combo_entry->set_text(name); WorkPlace::pointed = ID; - if (CItem::logic_connect) { + if (CItem::logic_connect && CItem::gate_id != -1) { if ( detect_click_position(event->x, event->y) == IN) { - tmp_line.logic = workplace->get_logic_item(CItem::gate_id); - tmp_line.store = this; + tmp_line.logic_id = workplace->get_logic_item(CItem::gate_id)->get_id(); + tmp_line.store_id = ID; workplace->lista_lineas_in.push_back(tmp_line); workplace->queue_draw(); } else if (detect_click_position(event->x, event->y) == OUT) { - tmp_line.logic = workplace->get_logic_item(CItem::gate_id); - tmp_line.store = this; + tmp_line.logic_id = workplace->get_logic_item(CItem::gate_id)->get_id(); + tmp_line.store_id = ID; workplace->lista_lineas_out.push_back(tmp_line); workplace->queue_draw(); } @@ -91,7 +91,6 @@ bool Pump::on_button_press_event(GdkEventButton *event) pump_pty_wnd->txt_pump_name->set_text( name ); pump_pty_wnd->show(); } - CItem::logic_connect =false; workplace->queue_draw(); return true; } diff --git a/Constructor/src/workplace.cpp b/Constructor/src/workplace.cpp index 64ad9f5..1d93082 100644 --- a/Constructor/src/workplace.cpp +++ b/Constructor/src/workplace.cpp @@ -23,7 +23,6 @@ bool WorkPlace::on_expose_event(GdkEventExpose *event) get_window()->draw_point (get_style()->get_black_gc(), x-1,y); } - Glib::RefPtr gc = get_style()->get_black_gc(); Gdk::Color color; color.set_rgb(255,0,0); @@ -33,31 +32,35 @@ bool WorkPlace::on_expose_event(GdkEventExpose *event) std::list::iterator i = lista_lineas_in.begin(); while ( i != lista_lineas_in.end() ) { t_line temp = *i; - temp.store->get_in_logic_connect_position(w,z); - temp.logic->get_out_logic_connect_position(a, b); - get_window()->draw_line (get_style()->get_black_gc(), a, b, w,z); + if ( get_item(temp.store_id) != NULL && get_logic_item(temp.logic_id) != NULL ) { + get_item(temp.store_id)->get_in_logic_connect_position(w,z); + get_logic_item(temp.logic_id)->get_out_logic_connect_position(a, b); + get_window()->draw_line (get_style()->get_black_gc(), a, b, w,z); + } i++; } i = lista_lineas_out.begin(); while ( i != lista_lineas_out.end() ) { t_line temp = *i; - temp.store->get_out_logic_connect_position(w,z); - temp.logic->get_in_logic_connect_position(a, b); - get_window()->draw_line (get_style()->get_black_gc(), a, b, w, z); + if ( get_item(temp.store_id) != NULL && get_logic_item(temp.logic_id) != NULL ) { + get_item(temp.store_id)->get_out_logic_connect_position(w,z); + get_logic_item(temp.logic_id)->get_in_logic_connect_position(a, b); + get_window()->draw_line (get_style()->get_black_gc(), a, b, w, z); + } i++; } - return true; } void WorkPlace::delete_item(int _id) { + delete_line(_id); CItem::logic_connect = false; std::list::iterator i = listaItems->begin(); while ( i != listaItems->end() ){ CItem *temp = *i; if ( temp->get_id() == _id ){ - delete_line(_id); +// delete_line(_id); listaItems->erase(i); delete temp; break; @@ -68,65 +71,80 @@ void WorkPlace::delete_item(int _id) while ( i != lista_logic_Items->end() ){ CItem *temp = *i; if ( temp->get_id() == _id ){ - delete_line(_id); +// delete_line(_id); lista_logic_Items->erase(i); delete temp; break; } i++; } - + CItem::gate_id = -1; } CItem* WorkPlace::get_logic_item(int _id) { std::list::iterator i = lista_logic_Items->begin(); while ( i != lista_logic_Items->end() ){ - CItem *temp = *i; - if ( temp->get_id() == _id ) - return temp; + if ( (*i)->get_id() == _id ) + return *i; + i++; + } + return NULL; +} + +CItem *WorkPlace::get_item(int _id) +{ + std::list::iterator i = listaItems->begin(); + while ( i != listaItems->end() ){ + if ( (*i)->get_id() == _id ) + return *i; i++; } return NULL; } + void WorkPlace::delete_line(int _id) { std::list::iterator i = lista_lineas_in.begin(); while ( i != lista_lineas_in.end() ){ - if ( (*i).store->get_id() == _id ) { - lista_lineas_in.erase(i); - i = lista_lineas_in.begin(); - } + if (get_item( (*i).store_id ) != NULL) + if ( get_item( (*i).store_id )->get_id() == _id ) { + lista_lineas_in.erase(i); + i = lista_lineas_in.begin(); + } i++; } i = lista_lineas_in.begin(); while ( i != lista_lineas_in.end() ){ - if ( (*i).logic->get_id() == _id ) { - lista_lineas_in.erase(i); - i = lista_lineas_in.begin(); - } + if ( get_logic_item((*i).logic_id) != NULL) + if ( get_logic_item((*i).logic_id)->get_id() == _id) { + lista_lineas_in.erase(i); + i = lista_lineas_in.begin(); + } i++; } - i = lista_lineas_out.begin(); - while ( i != lista_lineas_out.end() ){ - if ( (*i).store->get_id() == _id ) { - lista_lineas_out.erase(i); - i = lista_lineas_out.begin(); - } - i++; - } - i = lista_lineas_out.begin(); - while ( i != lista_lineas_out.end() ){ - if ( (*i).logic->get_id() == _id ) { - lista_lineas_out.erase(i); - i = lista_lineas_out.begin(); - } - i++; + std::list::iterator j = lista_lineas_out.begin(); + while ( j != lista_lineas_out.end() ){ + if ( get_item((*j).store_id) != NULL ) + if ( get_item((*j).store_id)->get_id() == _id ) { + lista_lineas_out.erase(j); + j = lista_lineas_out.begin(); + } + j++; } + j = lista_lineas_out.begin(); + while ( j != lista_lineas_out.end() ){ + if ( get_logic_item((*j).logic_id) != NULL ) + if ( get_logic_item((*j).logic_id)->get_id() == _id ) { + lista_lineas_out.erase(j); + j = lista_lineas_out.begin(); + } + j++; + } } void WorkPlace::update_logic_position() -- 2.43.0