From: Nicolás Dimov Date: Sat, 29 Nov 2003 00:33:29 +0000 (+0000) Subject: Se arreglan las compuertas un poco mas. X-Git-Tag: svn_import~163 X-Git-Url: https://git.llucax.com/z.facultad/75.42/plaqui.git/commitdiff_plain/3314f9284024c7bb9e618f310ca467a93990922d Se arreglan las compuertas un poco mas. --- diff --git a/Constructor/include/and.h b/Constructor/include/and.h index f523fd6..56be2e9 100644 --- a/Constructor/include/and.h +++ b/Constructor/include/and.h @@ -16,6 +16,7 @@ class And : public CItem { virtual void get_in_logic_connect_position(int& _a, int& _b); virtual void get_out_logic_connect_position(int& _a, int& _b); virtual void set_out_connected(bool _o); + virtual void draw_connectors(); private: int in_x, in_y, out_x, out_y; bool out_connected; diff --git a/Constructor/include/cistern.h b/Constructor/include/cistern.h index 6ef50a3..b2a4baf 100644 --- a/Constructor/include/cistern.h +++ b/Constructor/include/cistern.h @@ -56,6 +56,9 @@ class Cistern : public CItem { /**Detecta si el click fue en el area de entrada o salida logica, devuelve UNDEF si no fue ninguna de las dos */ ConnectorType detect_click_position(int _a, int _b); + /**Dibuja los conectores logicos, que seran ambos azules pues son salidas. + */ + virtual void draw_connectors(); protected: /**Atributos que definen su comportamiento */ diff --git a/Constructor/include/item.h b/Constructor/include/item.h index 845bd64..140629b 100644 --- a/Constructor/include/item.h +++ b/Constructor/include/item.h @@ -126,7 +126,7 @@ public: virtual void set_out_connected(bool _o); virtual void set_in_connected(bool _o); - /**Dibuja los conectores logicos del Item, AZUL == ENTRADA, ROJO == SALIDA. + /**Dibuja los conectores logicos del Item, AZUL == SALIDA, ROJO == ENTRADA. */ virtual void draw_connectors(); diff --git a/Constructor/include/not.h b/Constructor/include/not.h index 9fdde6f..02b2bb4 100644 --- a/Constructor/include/not.h +++ b/Constructor/include/not.h @@ -17,6 +17,8 @@ class Not : public CItem { virtual void get_out_logic_connect_position(int& _a, int& _b); virtual void set_out_connected(bool _o); virtual void set_in_connected(bool _o); + virtual bool get_out_logic_connect(); + virtual void draw_connectors(); private: int in_x, in_y, out_x, out_y; bool in_connected, out_connected; diff --git a/Constructor/include/or.h b/Constructor/include/or.h index 9a22b3e..177f699 100644 --- a/Constructor/include/or.h +++ b/Constructor/include/or.h @@ -16,6 +16,7 @@ class Or : public CItem { virtual void get_in_logic_connect_position(int& _a, int& _b); virtual void get_out_logic_connect_position(int& _a, int& _b); virtual void set_out_connected(bool _o); + virtual void draw_connectors(); private: int in_x, in_y, out_x, out_y; bool out_connected; diff --git a/Constructor/include/workplace.h b/Constructor/include/workplace.h index 960e046..f226ee7 100644 --- a/Constructor/include/workplace.h +++ b/Constructor/include/workplace.h @@ -53,10 +53,13 @@ class WorkPlace:public Gtk::Fixed { 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 - lista_lineas_in = (salida) compuerta --> (entrada) item - lista_lineas_out= (entrada) compuerta --> (salida) item + * lista_lineas_in = (salida) compuerta --> (entrada) item + * lista_lineas_out= (entrada) compuerta --> (salida) item + * lista_lineas_logic = (salida) compuerta --> (entrada) compuerta. + * Esta ultima lista contiene las lineas que van desde la compuerta seleccionada que se guarda en gate_id hasta + * la compuerta clickeada en segundo termino. */ - std::list lista_lineas_in, lista_lineas_out; + std::list lista_lineas_in, lista_lineas_out, lista_lineas_logic; /**Variable global que identifica cual item logico fue apuntado para *conectarlo mediante una linea a un item de transporte diff --git a/Constructor/src/and.cpp b/Constructor/src/and.cpp index 0ef3bbd..3e52876 100644 --- a/Constructor/src/and.cpp +++ b/Constructor/src/and.cpp @@ -52,16 +52,26 @@ And::~And() bool And::on_button_press_event(GdkEventButton *event) { if ((event->type == GDK_BUTTON_PRESS) && ( event->button == 1)) { - if ( CItem::logic_connect ) { - if ( detect_click_position((int)event->x, (int)event->y ) == OUT && !out_connected) { + WorkPlace::pointed = ID; + t_line tmp_line; + std::cout << CItem::gate_id << std::endl; + if (CItem::logic_connect) { + if (CItem::gate_id != -1 ) { + if ( detect_click_position((int)event->x, (int)event->y ) == IN && CItem::gate_id != ID ) { + tmp_line.logic_id = CItem::gate_id; + workplace->get_logic_item(CItem::gate_id)->set_out_connected(true); + tmp_line.store_id = ID; + workplace->lista_lineas_logic.push_back(tmp_line); + workplace->queue_draw(); + CItem::gate_id = -1; + } + } else { CItem::gate_id = ID; - WorkPlace::pointed = ID; } - if ( detect_click_position((int)event->x, (int)event->y ) == IN ) { - CItem::gate_id = ID; - WorkPlace::pointed = ID; - } - } + } + if ( CItem::logic_connect && detect_click_position((int)event->x, (int)event->y ) == OUT && !out_connected) { + CItem::gate_id = ID; + } list_pointed->push_back(name); combo_entry->set_popdown_strings(*list_pointed); combo_entry->get_entry()->set_text (name); @@ -252,3 +262,41 @@ void And::set_out_connected(bool _o) { out_connected = _o; } + +void And::draw_connectors() +{ + Glib::RefPtr window = get_window(); + int a,b,c,d; + switch (imgActual) { + case 0: + a = in_x-x; + b = in_y-y-5; + c = out_x-x-10; + d = out_y-y-5; + break; + case 1: + a = in_x-x-5; + b = in_y-y; + c = out_x-x-5; + d = out_y-y-10; + break; + case 2: + a = in_x-x-10; + b = in_y-y-5; + c = out_x-x; + d = out_y-y-5; + break; + case 3: + a = in_x-x-5; + b = in_y-y-10; + c = out_x-x-5; + d = out_y-y; + } + gc->set_foreground(red); + gc->set_background(red); + window->draw_rectangle(gc, 1, a, b, 10, 10); + gc->set_foreground(blue); + gc->set_background(blue); + window->draw_rectangle(gc, 1, c, d, 10, 10); + queue_draw(); +} diff --git a/Constructor/src/cistern.cpp b/Constructor/src/cistern.cpp index e7e104d..628d69f 100644 --- a/Constructor/src/cistern.cpp +++ b/Constructor/src/cistern.cpp @@ -1,5 +1,6 @@ #include "cistern.h" #include "cisternptywnd.h" +#include "not.h" Cistern::Cistern(int orientacion) { @@ -34,7 +35,7 @@ Cistern::Cistern(int orientacion) temp.type = IN; connect_vec.push_back(temp); // entrada arriba temp.type = OUT; - connect_vec.push_back(temp); // salida abajo + connect_vec.push_back(temp); // entrada abajo } Cistern::~Cistern() @@ -46,24 +47,32 @@ bool Cistern::on_button_press_event(GdkEventButton *event) GdkEventExpose e; t_line tmp_line; if ((event->type == GDK_BUTTON_PRESS) && ( event->button == 1)) { + WorkPlace::pointed = ID; list_pointed->push_back(name); combo_entry->set_popdown_strings(*list_pointed); combo_entry->get_entry()->set_text (name); - WorkPlace::pointed = ID; if (CItem::logic_connect && CItem::gate_id != -1) { if ( detect_click_position((int)event->x, (int)event->y) == IN ){ tmp_line.logic_id = workplace->get_logic_item(CItem::gate_id)->get_id(); workplace->get_logic_item(CItem::gate_id)->set_out_connected(true); tmp_line.store_id = ID; - workplace->lista_lineas_in.push_back(tmp_line); - workplace->queue_draw(); - } else if (detect_click_position((int)event->x, (int)event->y) == OUT) { -// if (dynamic_cast(get_item(temp.logic_id))) - // get_logic_item(temp.logic_id)->set_in_connected(true); - 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(); + } else if (detect_click_position((int)event->x, (int)event->y) == OUT ) { + if (dynamic_cast(workplace->get_logic_item(CItem::gate_id))) { + if ( !dynamic_cast(workplace->get_logic_item(CItem::gate_id))->get_out_logic_connect()) { + workplace->get_logic_item(CItem::gate_id)->set_in_connected(true); + tmp_line.logic_id = CItem::gate_id; + tmp_line.store_id = ID; + workplace->lista_lineas_out.push_back(tmp_line); + workplace->queue_draw(); + } + } else { + tmp_line.logic_id = CItem::gate_id; + tmp_line.store_id = ID; + workplace->lista_lineas_out.push_back(tmp_line); + workplace->queue_draw(); + } } CItem::gate_id = -1; } @@ -254,7 +263,6 @@ void Cistern::get_out_logic_connect_position(int& _a, int& _b) ConnectorType Cistern::detect_click_position(int _a, int _b) { - //VER DONDE CAEN LOS CLICKS!!!!!!!!!!!!!! SI ES CON RESPECTO AL WORKPLACE O AL ITEM!!! switch(imgActual) { case 0: if ( (_a<=32) &&(_a>=0)&&(_b<=32)&&(_b>=0) ) @@ -287,3 +295,14 @@ void Cistern::update_logic_position() out_y = y + image->get_height(); } } + +void Cistern::draw_connectors() +{ + if ( in_x != -1 ) { + Glib::RefPtr window = get_window(); + gc->set_foreground(blue); + window->draw_rectangle(gc, 1, in_x-5-x, in_y-y, 10, 10); + window->draw_rectangle(gc, 1, out_x-5-x, out_y-y-10, 10, 10); + queue_draw(); + } +} diff --git a/Constructor/src/constructor.cpp b/Constructor/src/constructor.cpp index e8654c1..4ab81de 100644 --- a/Constructor/src/constructor.cpp +++ b/Constructor/src/constructor.cpp @@ -319,7 +319,7 @@ void Constructor::on_load_from_xml() } std::cout << "CARGA COMPLETA" << std::endl; file_open_selection->hide(); - id = listaItems.size()+lista_logic_Items.size()+1; + id = listaItems.size()+lista_logic_Items.size()+2; } void Constructor::on_btn_file_ok_clicked() diff --git a/Constructor/src/exclusa.cpp b/Constructor/src/exclusa.cpp index a7c4583..048dd6c 100644 --- a/Constructor/src/exclusa.cpp +++ b/Constructor/src/exclusa.cpp @@ -1,5 +1,6 @@ #include "exclusa.h" #include "exclusaptywnd.h" +#include "not.h" Exclusa::Exclusa(int orientacion) { @@ -41,10 +42,10 @@ bool Exclusa::on_button_press_event(GdkEventButton *event) { t_line tmp_line; if ((event->type == GDK_BUTTON_PRESS) && ( event->button == 1)) { + WorkPlace::pointed = ID; list_pointed->push_back(name); combo_entry->set_popdown_strings(*list_pointed); combo_entry->get_entry()->set_text (name); - WorkPlace::pointed = ID; if (CItem::logic_connect && CItem::gate_id != -1) { if ( detect_click_position((int)event->x, (int)event->y) == IN) { tmp_line.logic_id = workplace->get_logic_item(CItem::gate_id)->get_id(); @@ -52,11 +53,21 @@ bool Exclusa::on_button_press_event(GdkEventButton *event) tmp_line.store_id = ID; workplace->lista_lineas_in.push_back(tmp_line); workplace->queue_draw(); - } else if (detect_click_position((int)event->x, (int)event->y) == OUT) { - 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(); + } else if (detect_click_position((int)event->x, (int)event->y) == OUT ) { + if (dynamic_cast(workplace->get_logic_item(CItem::gate_id))) { + if (!dynamic_cast(workplace->get_logic_item(CItem::gate_id))->get_out_logic_connect()) { + workplace->get_logic_item(CItem::gate_id)->set_in_connected(true); + tmp_line.logic_id = CItem::gate_id; + tmp_line.store_id = ID; + workplace->lista_lineas_out.push_back(tmp_line); + workplace->queue_draw(); + } + } else { + tmp_line.logic_id = CItem::gate_id; + tmp_line.store_id = ID; + workplace->lista_lineas_out.push_back(tmp_line); + workplace->queue_draw(); + } } CItem::gate_id = -1; } diff --git a/Constructor/src/item.cpp b/Constructor/src/item.cpp index d3624db..e5027e0 100644 --- a/Constructor/src/item.cpp +++ b/Constructor/src/item.cpp @@ -61,7 +61,7 @@ bool CItem::on_expose_event(GdkEventExpose* event) // XXX Esto no deberia ser necesario! en todo caso devolves false en // vez de true para que siga llamando a los otros handlers :) //Gtk::DrawingArea::on_expose_event(event); - if (logic_connect && !is_logic) { + if (CItem::logic_connect) { draw_connectors(); } return true; diff --git a/Constructor/src/not.cpp b/Constructor/src/not.cpp index 2fc63e2..8a33e1c 100644 --- a/Constructor/src/not.cpp +++ b/Constructor/src/not.cpp @@ -53,14 +53,28 @@ bool Not::on_button_press_event(GdkEventButton *event) { if ((event->type == GDK_BUTTON_PRESS) && ( event->button == 1)) { + WorkPlace::pointed = ID; + t_line tmp_line; + if (CItem::logic_connect) { + if (CItem::gate_id != -1) { + if ( detect_click_position((int)event->x, (int)event->y) == IN && !in_connected) { + tmp_line.logic_id = CItem::gate_id; + workplace->get_logic_item(CItem::gate_id)->set_out_connected(true); + set_in_connected(true); + tmp_line.store_id = ID; + workplace->lista_lineas_logic.push_back(tmp_line); + workplace->queue_draw(); + CItem::gate_id = -1; + } + } else + CItem::gate_id = ID; + } if ( CItem::logic_connect ) { if ( detect_click_position((int)event->x, (int)event->y ) == OUT && !out_connected ) { CItem::gate_id = ID; - WorkPlace::pointed = ID; } if ( detect_click_position((int)event->x, (int)event->y ) == IN && !in_connected) { CItem::gate_id = ID; - WorkPlace::pointed = ID; } } list_pointed->push_back(name); @@ -258,3 +272,46 @@ void Not::set_in_connected(bool _o) { in_connected = _o; } + +bool Not::get_out_logic_connect() +{ + return out_connected; +} + +void Not::draw_connectors() +{ + Glib::RefPtr window = get_window(); + int a,b,c,d; + switch (imgActual) { + case 0: + a = in_x-x; + b = in_y-y-5; + c = out_x-x-10; + d = out_y-y-5; + break; + case 1: + a = in_x-x-5; + b = in_y-y; + c = out_x-x-5; + d = out_y-y-10; + break; + case 2: + a = in_x-x-10; + b = in_y-y-5; + c = out_x-x; + d = out_y-y-5; + break; + case 3: + a = in_x-x-5; + b = in_y-y-10; + c = out_x-x-5; + d = out_y-y; + } + gc->set_foreground(red); + gc->set_background(red); + window->draw_rectangle(gc, 1, a, b, 10, 10); + gc->set_foreground(blue); + gc->set_background(blue); + window->draw_rectangle(gc, 1, c, d, 10, 10); + queue_draw(); +} diff --git a/Constructor/src/or.cpp b/Constructor/src/or.cpp index 4cbd535..50ad73f 100644 --- a/Constructor/src/or.cpp +++ b/Constructor/src/or.cpp @@ -52,15 +52,24 @@ Or::~Or() bool Or::on_button_press_event(GdkEventButton *event) { if ((event->type == GDK_BUTTON_PRESS) && ( event->button == 1)) { + WorkPlace::pointed = ID; + t_line tmp_line; + if (CItem::logic_connect) { + if (CItem::gate_id != -1) { + if ( detect_click_position((int)event->x, (int)event->y) == IN) { + tmp_line.logic_id = CItem::gate_id; + workplace->get_logic_item(CItem::gate_id)->set_out_connected(true); + tmp_line.store_id = ID; + workplace->lista_lineas_logic.push_back(tmp_line); + workplace->queue_draw(); + } + } else + CItem::gate_id = ID; + } if ( CItem::logic_connect ) { if ( detect_click_position((int)event->x, (int)event->y ) == OUT && !out_connected) { CItem::gate_id = ID; - WorkPlace::pointed = ID; } - if ( detect_click_position((int)event->x, (int)event->y ) == IN ) { - CItem::gate_id = ID; - WorkPlace::pointed = ID; - } } list_pointed->push_back(name); combo_entry->set_popdown_strings(*list_pointed); @@ -254,3 +263,41 @@ void Or::set_out_connected(bool _o) { out_connected = _o; } + +void Or::draw_connectors() +{ + Glib::RefPtr window = get_window(); + int a,b,c,d; + switch (imgActual) { + case 0: + a = in_x-x; + b = in_y-y-5; + c = out_x-x-10; + d = out_y-y-5; + break; + case 1: + a = in_x-x-5; + b = in_y-y; + c = out_x-x-5; + d = out_y-y-10; + break; + case 2: + a = in_x-x-10; + b = in_y-y-5; + c = out_x-x; + d = out_y-y-5; + break; + case 3: + a = in_x-x-5; + b = in_y-y-10; + c = out_x-x-5; + d = out_y-y; + } + gc->set_foreground(red); + gc->set_background(red); + window->draw_rectangle(gc, 1, a, b, 10, 10); + gc->set_foreground(blue); + gc->set_background(blue); + window->draw_rectangle(gc, 1, c, d, 10, 10); + queue_draw(); +} diff --git a/Constructor/src/pump.cpp b/Constructor/src/pump.cpp index 897ca50..47cf1b9 100644 --- a/Constructor/src/pump.cpp +++ b/Constructor/src/pump.cpp @@ -1,5 +1,6 @@ #include "pump.h" #include "pumpptywnd.h" +#include "not.h" Pump::Pump(int orientacion) { @@ -46,18 +47,29 @@ bool Pump::on_button_press_event(GdkEventButton *event) combo_entry->set_popdown_strings(*list_pointed); combo_entry->get_entry()->set_text (name); WorkPlace::pointed = ID; + std::cout<< "CItem::gate_id = "<x, (int)event->y) == IN) { - tmp_line.logic_id = workplace->get_logic_item(CItem::gate_id)->get_id(); + tmp_line.logic_id = CItem::gate_id; workplace->get_logic_item(CItem::gate_id)->set_out_connected(true); tmp_line.store_id = ID; workplace->lista_lineas_in.push_back(tmp_line); workplace->queue_draw(); - } else if (detect_click_position((int)event->x, (int)event->y) == OUT) { - 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(); + } else if (detect_click_position((int)event->x, (int)event->y) == OUT ) { + if (dynamic_cast(workplace->get_logic_item(CItem::gate_id))) { + if ( !dynamic_cast(workplace->get_logic_item(CItem::gate_id))->get_out_logic_connect()) { + workplace->get_logic_item(CItem::gate_id)->set_in_connected(true); + tmp_line.logic_id = CItem::gate_id; + tmp_line.store_id = ID; + workplace->lista_lineas_out.push_back(tmp_line); + workplace->queue_draw(); + } + } else { + tmp_line.logic_id = CItem::gate_id; + tmp_line.store_id = ID; + workplace->lista_lineas_out.push_back(tmp_line); + workplace->queue_draw(); + } } CItem::gate_id = -1; } diff --git a/Constructor/src/workplace.cpp b/Constructor/src/workplace.cpp index 847aa17..206bca3 100644 --- a/Constructor/src/workplace.cpp +++ b/Constructor/src/workplace.cpp @@ -86,7 +86,6 @@ bool WorkPlace::on_expose_event(GdkEventExpose *event) y_offset = -15; } get_logic_item(temp.logic_id)->get_out_logic_connect_position(a, b); - get_logic_item(temp.logic_id)->set_out_connected(true); get_item(temp.store_id)->get_in_logic_connect_position(w,z); draw_line(a+x_offset, b+y_offset, w+item_x_offset, z+item_y_offset, color_in); get_window()->draw_line(gc, a, b, a+x_offset, b+y_offset); @@ -115,14 +114,23 @@ bool WorkPlace::on_expose_event(GdkEventExpose *event) y_offset = 15; } get_item(temp.store_id)->get_out_logic_connect_position(w,z); - if (dynamic_cast(get_logic_item(temp.logic_id))) - get_logic_item(temp.logic_id)->set_in_connected(true); get_logic_item(temp.logic_id)->get_in_logic_connect_position(a, b); draw_line(w+item_y_offset, z+item_y_offset, a+x_offset, b+y_offset,color_out); get_window()->draw_line(gc, a, b, a+x_offset, b+y_offset); } i++; } + + i = lista_lineas_logic.begin(); + while ( i != lista_lineas_logic.end() ) { + t_line temp = *i; + if ( get_logic_item(temp.store_id) != NULL && get_logic_item(temp.logic_id) != NULL ) { + get_logic_item(temp.logic_id)->get_out_logic_connect_position(w,z); + get_logic_item(temp.store_id)->get_in_logic_connect_position(a, b); + get_window()->draw_line(gc, a, b, w,z); + } + i++; + } return true; }