]> git.llucax.com Git - z.facultad/75.42/plaqui.git/commitdiff
* Se arregla un bug en el constructor al verificar conexiones
authorRicardo Markiewicz <gazer.arg@gmail.com>
Tue, 25 Nov 2003 17:48:48 +0000 (17:48 +0000)
committerRicardo Markiewicz <gazer.arg@gmail.com>
Tue, 25 Nov 2003 17:48:48 +0000 (17:48 +0000)
 * 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.

Constructor/include/workplace.h
Constructor/src/item.cpp
Constructor/src/union.cpp
Constructor/src/workplace.cpp
Model/src/conduct.cpp
Model/src/exclusa.cpp
Model/src/iconector.cpp
Model/src/simulator.cpp
Model/src/splitter.cpp
Model/src/tank.cpp
Model/src/union.cpp

index 004938b7df983472dc2ad566cdfcdbb24196881e..fe827174459313d65e8addc4ee954e049a96981e 100644 (file)
@@ -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<Gdk::GC> gc;
 };
 
 #endif
index d9e5035fdab57253846c1cc338e710154d24ac35..f4604b009f0e3cf24badb5d6fd4145943c5ee54c 100644 (file)
@@ -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;
index 3e98e6d0258c7c14a2897ee39a721c8f297eb0d5..dfbaa8874c77a9fdab6f43db8782566f1904ac5d 100644 (file)
@@ -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 ) {
index 440306ebb9899241951b585dc9da8ccdf801bfcd..f8893521a43bb0db96b2a93be34e0fa3eb91c350 100644 (file)
@@ -3,24 +3,46 @@
 
 int WorkPlace::pointed = -1;
 
-WorkPlace::WorkPlace( BaseObjectType* cobject, const Glib::RefPtr<Gnome::Glade::Xml> &refGlade):Gtk::Fixed(cobject)
+WorkPlace::WorkPlace(BaseObjectType* cobject, const Glib::RefPtr<Gnome::Glade::Xml> &refGlade):Gtk::Fixed(cobject)
 {
+       gc = Gdk::GC::create(get_window());
+       std::cout << "Aca" << std::endl;
+       Glib::RefPtr<Gdk::Colormap> 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<Gdk::Colormap> 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; x<get_width(); x+=32) 
                for (y=0; y<get_height();y+=32){
-                       get_window()->draw_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<t_line>::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);
 }
+
index b6eb6f2672f49149cbfdd8170333d41bde38f511..3628ac6282abfb7622389f93219d3b2689fb119d 100644 (file)
@@ -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_flow<tmp)?actual_flow:tmp;
 
                        send_msg(OUT, MSG_QUERY_MAX_FLOW_OUT, &actual_flow);
                        who->recieve_msg(MSG_RESPONSE_MAX_FLOW, this, &actual_flow);
-                       updated = true;
                }
                break;
                case MSG_RESPONSE_MAX_FLOW: {
index 74ec90625e2209c6c49cf5cee5e119b79a320d40..cc61519a7823f20890ab06173787edab60c6ced2 100644 (file)
@@ -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);
index 7cbdd5670720b38622cd605abf8ec9abf1e95543..68d40247e1da654db633122eaa9c845ed9ba2ddf 100644 (file)
@@ -1,7 +1,7 @@
 
 
 #include "iconector.h"
-
+#include <iostream>
 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);
+                       }
        }
 }
 
index 72c59ca61561f2888b6413d106613f680339e0a9..f910c85b8f36328559bea907d3cfb9247d84ed16 100644 (file)
@@ -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<PlantItem *>::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;
index d9733794166ad84b1a88bcd369cb6c295bbb7d68..c3ce1b4dc9664772f82f3522d6ef21bff28950c8 100644 (file)
@@ -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);
index b3a940e79688e48624749cb428eca0b42a488c98..3f2fe43b73d7a903c091b478928619ca8e80d3db 100644 (file)
@@ -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);
index 26c404a5697db4afb24442262eca5ae289941fbd..58bc8e1a06570df69e2bef416f4b19ef16ca80a8 100644 (file)
@@ -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;