From: Ricardo Markiewicz Date: Tue, 25 Nov 2003 17:48:48 +0000 (+0000) Subject: * Se arregla un bug en el constructor al verificar conexiones X-Git-Tag: svn_import~175 X-Git-Url: https://git.llucax.com/z.facultad/75.42/plaqui.git/commitdiff_plain/a4fcf877753b034b1df7fa73d41388849fbc9000 * Se arregla un bug en el constructor al verificar conexiones * Se ponen un poco mas bonitas las lineas de las conexiones logicas * Se arregla el modelo para prevenir colcagas cuando el circuito es realimentado. Entraba en un loop infinito. Ahora simula bien, aunque en algunos casos se actualiza mal. Voy a tratar de resolverlo pronto. --- diff --git a/Constructor/include/workplace.h b/Constructor/include/workplace.h index 004938b..fe82717 100644 --- a/Constructor/include/workplace.h +++ b/Constructor/include/workplace.h @@ -24,7 +24,10 @@ class WorkPlace:public Gtk::Fixed { /// Destructor. virtual ~WorkPlace(); - + + /// Funcion que se ejecuta cuando se crea la ventana + virtual void on_realize(); + ///Esta funcion es llamada cada vez que el area de trabajo se tenga que redibujar. virtual bool on_expose_event(GdkEventExpose *event); @@ -60,7 +63,9 @@ class WorkPlace:public Gtk::Fixed { ///Estado de diseño bool *logica; protected: - void draw_line(int x1, int y1, int x2, int y2); + void draw_line(int x1, int y1, int x2, int y2, Gdk::Color &color); + Gdk::Color color_in, color_out, color_dot; + Glib::RefPtr gc; }; #endif diff --git a/Constructor/src/item.cpp b/Constructor/src/item.cpp index d9e5035..f4604b0 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) { + if (logic_connect && !is_logic) { draw_connectors(); } return true; diff --git a/Constructor/src/union.cpp b/Constructor/src/union.cpp index 3e98e6d..dfbaa88 100644 --- a/Constructor/src/union.cpp +++ b/Constructor/src/union.cpp @@ -141,6 +141,7 @@ bool Union::check_connection() { CItem * _item0, *_item1, *_item2; ConnectorType temp0, temp1, temp2; + std::cout << get_img_actual() << std::endl; switch (get_img_actual()) { case 0: temp0 = is_other_connection_area( get_position_x() - 5, get_position_y() +16, &_item0); @@ -159,8 +160,8 @@ bool Union::check_connection() break; case 3: temp1 = is_other_connection_area( get_position_x()+16, get_position_y()-5, &_item1); - temp2 = is_other_connection_area( get_position_x()+get_image()->get_width()+5, get_position_y()+get_image()->get_height()/2,& _item0); - temp0 = is_other_connection_area( get_position_x()+16, get_position_y()+get_image()->get_height()+5, &_item1); + temp2 = is_other_connection_area( get_position_x()+get_image()->get_width()+5, get_position_y()+get_image()->get_height()/2,& _item2); + temp0 = is_other_connection_area( get_position_x()+16, get_position_y()+get_image()->get_height()+5, &_item0); } if ( is_union ) { if ( temp0 == OUT && temp1 == OUT && temp2 == IN ) { diff --git a/Constructor/src/workplace.cpp b/Constructor/src/workplace.cpp index 440306e..f889352 100644 --- a/Constructor/src/workplace.cpp +++ b/Constructor/src/workplace.cpp @@ -3,24 +3,46 @@ int WorkPlace::pointed = -1; -WorkPlace::WorkPlace( BaseObjectType* cobject, const Glib::RefPtr &refGlade):Gtk::Fixed(cobject) +WorkPlace::WorkPlace(BaseObjectType* cobject, const Glib::RefPtr &refGlade):Gtk::Fixed(cobject) { + gc = Gdk::GC::create(get_window()); + std::cout << "Aca" << std::endl; + Glib::RefPtr colormap = gc->get_colormap(); + color_in = Gdk::Color("red"); + color_out = Gdk::Color("blue"); + color_dot = Gdk::Color("black"); + colormap->alloc_color(color_in); + colormap->alloc_color(color_out); + colormap->alloc_color(color_dot); } WorkPlace::~WorkPlace() { } +void WorkPlace::on_realize() +{ + Gtk::Fixed::on_realize(); + gc = Gdk::GC::create(get_window()); + std::cout << "Aca" << std::endl; + Glib::RefPtr colormap = gc->get_colormap(); + color_in = Gdk::Color("red"); + color_out = Gdk::Color("blue"); + colormap->alloc_color(color_in); + colormap->alloc_color(color_out); +} + bool WorkPlace::on_expose_event(GdkEventExpose *event) { int x, y; + gc->set_foreground(color_dot); for(x=0; xdraw_point (get_style()->get_black_gc(), x,y); - get_window()->draw_point (get_style()->get_black_gc(), x,y+1); - get_window()->draw_point (get_style()->get_black_gc(), x,y-1); - get_window()->draw_point (get_style()->get_black_gc(), x+1,y); - get_window()->draw_point (get_style()->get_black_gc(), x-1,y); + get_window()->draw_point (gc, x,y); + get_window()->draw_point (gc, x,y+1); + get_window()->draw_point (gc, x,y-1); + get_window()->draw_point (gc, x+1,y); + get_window()->draw_point (gc, x-1,y); } if ( *logica ) { @@ -31,14 +53,30 @@ bool WorkPlace::on_expose_event(GdkEventExpose *event) } } - int a, b, w, z; + int a, b, w, z, x_offset, y_offset, img; std::list::iterator i = lista_lineas_in.begin(); while ( i != lista_lineas_in.end() ) { t_line temp = *i; 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); + img = get_logic_item(temp.logic_id)->get_img_actual(); + x_offset = y_offset = 0; + switch (img) { + case 0: + x_offset = 15; + break; + case 1: + y_offset = 15; + break; + case 2: + x_offset = -15; + break; + case 3: + y_offset = -15; + } get_logic_item(temp.logic_id)->get_out_logic_connect_position(a, b); - draw_line(a, b, w,z); + get_item(temp.store_id)->get_in_logic_connect_position(w,z); + draw_line(a+x_offset, b+y_offset, w,z, color_in); + get_window()->draw_line(gc, a, b, a+x_offset, b+y_offset); } i++; } @@ -46,9 +84,26 @@ bool WorkPlace::on_expose_event(GdkEventExpose *event) while ( i != lista_lineas_out.end() ) { t_line temp = *i; if ( get_item(temp.store_id) != NULL && get_logic_item(temp.logic_id) != NULL ) { + img = get_logic_item(temp.logic_id)->get_img_actual(); + x_offset = y_offset = 0; + switch (img) { + case 0: + x_offset = 15; + break; + case 1: + y_offset = 15; + break; + case 2: + x_offset = -15; + break; + case 3: + y_offset = -15; + } 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); - draw_line(w, z, a, b); +// draw_line(w, z, a, b, color_out); + draw_line(w, z, a+x_offset, b+y_offset,color_out); + get_window()->draw_line(gc, a, b, a+x_offset, b+y_offset); } i++; } @@ -162,8 +217,11 @@ void WorkPlace::update_logic_position() } } -void WorkPlace::draw_line(int x1, int y1, int x2, int y2) +void WorkPlace::draw_line(int x1, int y1, int x2, int y2, Gdk::Color &color) { - get_window()->draw_line (get_style()->get_black_gc(), x1, y1, x1, y2); - get_window()->draw_line (get_style()->get_black_gc(), x1, y2, x2, y2); + gc->set_foreground(color); + gc->set_line_attributes(3, Gdk::LINE_SOLID, Gdk::CAP_NOT_LAST, Gdk::JOIN_MITER); + get_window()->draw_line (gc, x1, y1, x1, y2); + get_window()->draw_line (gc, x1, y2, x2, y2); } + diff --git a/Model/src/conduct.cpp b/Model/src/conduct.cpp index b6eb6f2..3628ac6 100644 --- a/Model/src/conduct.cpp +++ b/Model/src/conduct.cpp @@ -11,6 +11,7 @@ Conduct::Conduct(const std::string &_name):Transport(_name) in_slots = 1; out_slots = 1; actual_flow = 99999; + updated = false; } Conduct::~Conduct() @@ -21,15 +22,19 @@ void Conduct::recieve_msg(int msg, IConector *who, void *data) { switch (msg) { case MSG_QUERY_MAX_FLOW_OUT: { + if (updated) { + who->recieve_msg(MSG_RESPONSE_MAX_FLOW, this, &actual_flow); + } + // Me preguntan por el flujo máximo. // Primero me actualizo, y luego respondo + updated = true; float tmp = *((float *)data); actual_flow = (actual_flow>max_flow)?max_flow:actual_flow; actual_flow = (actual_flowrecieve_msg(MSG_RESPONSE_MAX_FLOW, this, &actual_flow); - updated = true; } break; case MSG_RESPONSE_MAX_FLOW: { diff --git a/Model/src/exclusa.cpp b/Model/src/exclusa.cpp index 74ec906..cc61519 100644 --- a/Model/src/exclusa.cpp +++ b/Model/src/exclusa.cpp @@ -12,6 +12,7 @@ Exclusa::Exclusa(const std::string &_name):Control(_name) input = new ByPass(); output = new ByPass(); ((ByPass *)output)->set_control(this); + updated = false; } Exclusa::~Exclusa() @@ -47,6 +48,9 @@ void Exclusa::recieve_msg(int msg, IConector *who, void *data) { switch (msg) { case MSG_QUERY_MAX_FLOW_OUT: + if (updated) { + who->recieve_msg(MSG_RESPONSE_MAX_FLOW, this, &temp); + } temp = *((float *)data); if (!is_open) temp = 0; send_msg(OUT, MSG_QUERY_MAX_FLOW_OUT, &temp); diff --git a/Model/src/iconector.cpp b/Model/src/iconector.cpp index 7cbdd56..68d4024 100644 --- a/Model/src/iconector.cpp +++ b/Model/src/iconector.cpp @@ -1,7 +1,7 @@ #include "iconector.h" - +#include using namespace PlaQui::Model; IConector::IConector(unsigned in, unsigned out) @@ -28,8 +28,9 @@ void IConector::send_msg(int where, int msg, void *data) (*it)->recieve_msg(msg, this, data); break; case OUT: - for(it=out_list.begin(); it!=out_list.end(); it++) + for(it=out_list.begin(); it!=out_list.end(); it++) { (*it)->recieve_msg(msg, this, data); + } } } diff --git a/Model/src/simulator.cpp b/Model/src/simulator.cpp index 72c59ca..f910c85 100644 --- a/Model/src/simulator.cpp +++ b/Model/src/simulator.cpp @@ -11,6 +11,7 @@ Simulator::Simulator(const std::string &filename) document = xmlParseFile(filename.c_str()); if (document == NULL) { is_load_ok = false; + std::cout << "Error cargando XML" << std::endl; return; } @@ -149,9 +150,8 @@ void Simulator::simulate() for(i1=pump_lst.begin(); i1!=pump_lst.end(); i1++) (*i1)->update(); - // Simulo! std::list::iterator i2; - for(i2=items.begin(); i2!=items.end(); i2++) + for(i2=items.begin(); i2!=items.end(); i2++) (*i2)->simulate(); frame++; @@ -355,6 +355,7 @@ void Simulator::do_connections(xmlNodePtr nodo) continue; } // obtengo el items actual por su nombre + std::string s = (char *)xmlGetProp(nodo, BAD_CAST"nombre"); current_item = find((char *)xmlGetProp(nodo, BAD_CAST"nombre")); props = nodo->children; conector3 = conector2 = conector1 = NULL; @@ -397,11 +398,19 @@ void Simulator::do_connections(xmlNodePtr nodo) // bien, es a la entrada!, obtengo el item al cual lo tengo que conectar to_connect = find((char *)XML_GET_CONTENT(conector1->children)); // y lo conecto - current_item->connect(to_connect, IConector::IN); + if (!current_item->connect(to_connect, IConector::IN)) { + std::cout << s << " Error al conectar1 ENTRADA = " << (char *)XML_GET_CONTENT(conector1->children) << std::endl; + } else { + std::cout << s << " ENTRADA1 = " << (char *)XML_GET_CONTENT(conector1->children) << std::endl; + } } else if (xmlStrcmp(conector1->name, BAD_CAST"salida") == 0) { // Era a salida, es casi lo mismo que arriba to_connect = find((char *)XML_GET_CONTENT(conector1->children)); - current_item->connect(to_connect, IConector::OUT); + if (!current_item->connect(to_connect, IConector::OUT)) { + std::cout << s << " Error al conectar2 SALIDA" << std::endl; + } else { + std::cout << s << " SALIDA1 = " << (char *)XML_GET_CONTENT(conector1->children) << std::endl; + } } } if (conector2 != NULL) { @@ -410,11 +419,17 @@ void Simulator::do_connections(xmlNodePtr nodo) // bien, es a la entrada!, obtengo el item al cual lo tengo que conectar to_connect = find((char *)XML_GET_CONTENT(conector2->children)); // y lo conecto - current_item->connect(to_connect, IConector::IN); + if (!current_item->connect(to_connect, IConector::IN)) { + std::cout << s << " Error al conectar2 ENTRADA = " << (char *)XML_GET_CONTENT(conector2->children) << std::endl; + } else { + std::cout << s << " ENTRADA2 = " << (char *)XML_GET_CONTENT(conector2->children) << std::endl; + } } else if (xmlStrcmp(conector2->name, BAD_CAST"salida") == 0) { // Era a salida, es casi lo mismo que arriba to_connect = find((char *)XML_GET_CONTENT(conector2->children)); - current_item->connect(to_connect, IConector::OUT); + if (!current_item->connect(to_connect, IConector::OUT)) { + std::cout << s << " Error al conectar " << std::endl; + } } } if (conector3 != NULL) { @@ -423,11 +438,15 @@ void Simulator::do_connections(xmlNodePtr nodo) // bien, es a la entrada!, obtengo el item al cual lo tengo que conectar to_connect = find((char *)XML_GET_CONTENT(conector3->children)); // y lo conecto - current_item->connect(to_connect, IConector::IN); + if (!current_item->connect(to_connect, IConector::IN)) { + std::cout << s << " Error al conectar " << std::endl; + } } else if (xmlStrcmp(conector3->name, BAD_CAST"salida") == 0) { // Era a salida, es casi lo mismo que arriba to_connect = find((char *)XML_GET_CONTENT(conector3->children)); - current_item->connect(to_connect, IConector::OUT); + if (!current_item->connect(to_connect, IConector::OUT)) { + std::cout << s << " Error al conectar " << std::endl; + } } } nodo = nodo->next; diff --git a/Model/src/splitter.cpp b/Model/src/splitter.cpp index d973379..c3ce1b4 100644 --- a/Model/src/splitter.cpp +++ b/Model/src/splitter.cpp @@ -9,6 +9,7 @@ Splitter::Splitter(const std::string &_name):Transport(_name) in_slots = 1; out_slots = 2; max_flow = actual_flow = 0.0f; + updated = true; } Splitter::~Splitter() @@ -27,6 +28,9 @@ void Splitter::recieve_msg(int msg, IConector *who, void *data) switch (msg) { case MSG_QUERY_MAX_FLOW_OUT: { + if (updated) { + who->recieve_msg(MSG_RESPONSE_MAX_FLOW, this, &actual_flow); + } // Me preguntan por el flujo máximo. // Primero me actualizo, y luego respondo actual_flow = *((float *)data); diff --git a/Model/src/tank.cpp b/Model/src/tank.cpp index b3a940e..3f2fe43 100644 --- a/Model/src/tank.cpp +++ b/Model/src/tank.cpp @@ -71,6 +71,9 @@ void Tank::recieve_msg(int msg, IConector *who, void *data) switch (msg) { case MSG_QUERY_MAX_FLOW_OUT: + if (updated) { + who->recieve_msg(MSG_RESPONSE_MAX_FLOW, this, &actual_in_flow); + } actual_in_flow = capacity - litros; if (*((float *)data) < actual_in_flow) actual_in_flow = *((float *)data); diff --git a/Model/src/union.cpp b/Model/src/union.cpp index 26c404a..58bc8e1 100644 --- a/Model/src/union.cpp +++ b/Model/src/union.cpp @@ -12,6 +12,7 @@ Union::Union(const std::string &_name):Transport(_name) in_on_zero = 0; in_ready = 0; actual_flow = 999999; + updated = false; } Union::~Union() @@ -27,7 +28,6 @@ void Union::recieve_msg(int msg, IConector *who, void *data) for(i=in_list.begin(); i!=in_list.end(); i++) { if ((*i) == who) pos = IN; } - switch (msg) { case MSG_QUERY_MAX_FLOW_OUT: { // Me preguntan por el flujo máximo. @@ -35,6 +35,11 @@ void Union::recieve_msg(int msg, IConector *who, void *data) float m_data = *((float *)data)*2; float tmp; + if (updated) { + who->recieve_msg(MSG_RESPONSE_MAX_FLOW, this, &actual_flow); + break; + } + updated = true; if (m_data == 0) { in_on_zero++; tmp = 0.0f;