]> git.llucax.com Git - z.facultad/75.42/plaqui.git/commitdiff
* Todos los items, menos el tanque, ya actualizan bien los colores
authorRicardo Markiewicz <gazer.arg@gmail.com>
Thu, 20 Nov 2003 07:47:32 +0000 (07:47 +0000)
committerRicardo Markiewicz <gazer.arg@gmail.com>
Thu, 20 Nov 2003 07:47:32 +0000 (07:47 +0000)
 * El cliente ya muestra bien todos los cambios de color (en el ejemplo
   solo se aprecia en la union, que suma rojo+negro)
 * Al desconectar se envian /connection/stop/get_host()/7522 pero recibo
   un error 404
 * Se agrega un poco de color al ejemplo

Faltaría ver si el server ya acepta abrir o cerrar bombas/exclusas de forma manual
para implementarlo en el cliente. Mañana miro el codigo, no toy para leer nada :-)

16 files changed:
Client/include/item.h
Client/include/principal.h
Client/src/client.glade
Client/src/item.cpp
Client/src/principal.cpp
Model/include/rgb.h
Model/include/simulator.h
Model/src/conduct.cpp
Model/src/drainage.cpp
Model/src/exclusa.cpp
Model/src/main.cpp
Model/src/plantitem.cpp
Model/src/simulator.cpp
Model/src/splitter.cpp
Model/src/union.cpp
Server/tests/prueba.xml

index fca3b79594c8478e0880584b78f9ef094cb3ee1e..e4c40c0734847f94b04414f2a160d0d88554d3f0 100644 (file)
@@ -12,14 +12,15 @@ class ViewItem:public Gtk::EventBox {
 public:
        ViewItem(Glib::ustring _name);
        virtual ~ViewItem();
-//     virtual bool on_expose_event(GdkEventExpose* event);
-       Glib::ustring get_name();
+       
+       inline Glib::ustring get_name() { return name; }
        void set_position(int _x, int _y);
        void set_name(Glib::ustring _name);
-       void set_actual_flow(float f) { actual_flow = f; }
-       void set_open(bool b) { open = b; }
-       void set_extra(float f) { extra = f; }
-
+       inline void set_actual_flow(float f) { actual_flow = f; }
+       inline void set_open(bool b) { open = b; }
+       inline void set_extra(float f) { extra = f; }
+       inline void set_color(const Gdk::Color &c) { color = c; }
+       inline Gdk::Color get_color() { return color; }
        
        std::string get_actual_flow();
        virtual std::string get_cap_flow() { return "Flujo Actual :"; }
@@ -28,6 +29,7 @@ public:
 protected:
        Glib::ustring name;
        Gtk::Image image;
+       Gdk::Color color;
        int x, y;
        float actual_flow, extra;
        bool open;
index 868f6f4bbf47235236f39ee2330de326f9fdea2c..5256b1d01d3864c83302079e003385ab8bc36952 100644 (file)
@@ -27,7 +27,8 @@ protected:
        void read_status_xml(const std::string &frame);
        float get_float_from_xml(xmlNodePtr nodo);
        bool get_bool_from_xml(xmlNodePtr nodo);
-       
+       Gdk::Color get_rgb_from_xml(xmlNodePtr nodo);
+
        // Funciones de carga del XML
        bool is_xml_loaded;
        void loadXML();
@@ -54,6 +55,7 @@ protected:
        Gtk::Fixed *work_place;
        Gtk::Label *lbl_nombre, *lbl_color, *lbl_flujo, *lbl_extra, *lbl_cap_flujo, *lbl_cap_extra;
        Gtk::Image *ico_conected;
+       Gtk::DrawingArea *color_preview;
 
        // Actualiza las propiedades en la ventana del item actual
        void update_items_prop();
index 05dcc588122bcf5789b67fcc50581f7ff94f771f..10d000f7035f32b11f86e8021490e8cfd37c0957 100644 (file)
                      </child>
 
                      <child>
-                       <widget class="GtkLabel" id="lbl_nombre">
+                       <widget class="GtkLabel" id="lbl_cap_extra">
                          <property name="visible">True</property>
-                         <property name="label" translatable="yes">...</property>
+                         <property name="label" translatable="yes">Extra : </property>
                          <property name="use_underline">False</property>
                          <property name="use_markup">False</property>
                          <property name="justify">GTK_JUSTIFY_LEFT</property>
                          <property name="ypad">0</property>
                        </widget>
                        <packing>
-                         <property name="left_attach">1</property>
-                         <property name="right_attach">2</property>
-                         <property name="top_attach">0</property>
-                         <property name="bottom_attach">1</property>
+                         <property name="left_attach">0</property>
+                         <property name="right_attach">1</property>
+                         <property name="top_attach">3</property>
+                         <property name="bottom_attach">4</property>
                          <property name="x_options">fill</property>
                          <property name="y_options"></property>
                        </packing>
                          <property name="right_attach">2</property>
                          <property name="top_attach">1</property>
                          <property name="bottom_attach">2</property>
-                         <property name="x_options">fill</property>
                          <property name="y_options"></property>
                        </packing>
                      </child>
 
                      <child>
-                       <widget class="GtkLabel" id="lbl_color">
+                       <widget class="GtkLabel" id="lbl_nombre">
                          <property name="visible">True</property>
                          <property name="label" translatable="yes">...</property>
                          <property name="use_underline">False</property>
                        <packing>
                          <property name="left_attach">1</property>
                          <property name="right_attach">2</property>
-                         <property name="top_attach">2</property>
-                         <property name="bottom_attach">3</property>
-                         <property name="x_options">fill</property>
+                         <property name="top_attach">0</property>
+                         <property name="bottom_attach">1</property>
                          <property name="y_options"></property>
                        </packing>
                      </child>
 
                      <child>
-                       <widget class="GtkLabel" id="lbl_cap_extra">
+                       <widget class="GtkLabel" id="lbl_extra">
                          <property name="visible">True</property>
-                         <property name="label" translatable="yes">Extra : </property>
+                         <property name="label" translatable="yes">...</property>
                          <property name="use_underline">False</property>
                          <property name="use_markup">False</property>
                          <property name="justify">GTK_JUSTIFY_LEFT</property>
                          <property name="ypad">0</property>
                        </widget>
                        <packing>
-                         <property name="left_attach">0</property>
-                         <property name="right_attach">1</property>
+                         <property name="left_attach">1</property>
+                         <property name="right_attach">2</property>
                          <property name="top_attach">3</property>
                          <property name="bottom_attach">4</property>
-                         <property name="x_options">fill</property>
                          <property name="y_options"></property>
                        </packing>
                      </child>
 
                      <child>
-                       <widget class="GtkLabel" id="lbl_extra">
+                       <widget class="GtkDrawingArea" id="color_preview">
                          <property name="visible">True</property>
-                         <property name="label" translatable="yes">...</property>
-                         <property name="use_underline">False</property>
-                         <property name="use_markup">False</property>
-                         <property name="justify">GTK_JUSTIFY_LEFT</property>
-                         <property name="wrap">False</property>
-                         <property name="selectable">False</property>
-                         <property name="xalign">0</property>
-                         <property name="yalign">0.5</property>
-                         <property name="xpad">0</property>
-                         <property name="ypad">0</property>
                        </widget>
                        <packing>
                          <property name="left_attach">1</property>
                          <property name="right_attach">2</property>
-                         <property name="top_attach">3</property>
-                         <property name="bottom_attach">4</property>
-                         <property name="x_options">fill</property>
-                         <property name="y_options"></property>
+                         <property name="top_attach">2</property>
+                         <property name="bottom_attach">3</property>
+                         <property name="y_options">fill</property>
                        </packing>
                      </child>
                    </widget>
index 4ce5846dfa7d2904b2b4745e49977e42b0d45b26..8fab941621dc4bdb251e67ef44cfc8c3c599a269 100644 (file)
@@ -1,3 +1,4 @@
+
 #include "item.h"
 #include <sstream>
 #include <string>
@@ -13,14 +14,7 @@ ViewItem::ViewItem(Glib::ustring _name):Gtk::EventBox(),image()
 ViewItem::~ViewItem()
 {
 }
-/*
-bool ViewItem::on_expose_event(GdkEventExpose* event)
-{
-       image->render_to_drawable ( get_window(),  get_style()->get_black_gc(), 0,  0,  0,  0,  image->get_width() ,image->get_height() , 
-                                                                                                                               Gdk::RGB_DITHER_NONE, 0, 0);
-       return true;
-}
-*/
+
 void ViewItem::set_position(int _x, int _y)
 {
        x = _x;
@@ -32,11 +26,6 @@ void ViewItem::set_name(Glib::ustring _name)
        name = _name;
 }
 
-Glib::ustring ViewItem::get_name()
-{
-       return name;
-}
-
 std::string ViewItem::get_actual_flow()
 {
        std::stringstream ss;
index 868e050b1efcdb9315fc978e520f11dd15c76148..1ccf645f883388c66c22caf80d8334abca92941a 100644 (file)
@@ -1,6 +1,4 @@
 
-
-
 #include "principal.h"
 #include <iostream>
 #include <sstream>
 
 Principal::Principal(BaseObjectType *co, const Glib::RefPtr<Gnome::Glade::Xml> &rg):Gtk::Window(co),refXml(rg)
 {
-       Gtk::MenuItem *conect=0, *exit=0, *about=0, *mnu_prop=0, *mnu_disconnect;
+       Gtk::MenuItem *conect=0, *exit=0, *about=0, *mnu_prop=0, *mnu_disconnect=0;
        Gtk::Button *btn_get=0, *bar_connect=0;
        txt_view = 0;
        txt_target = txt_command = txt_args = 0;
        work_place = 0;
        lbl_cap_flujo = lbl_cap_extra = lbl_extra = lbl_nombre = lbl_color = lbl_flujo = 0;
 
+       rg->get_widget("color_preview", color_preview);
        rg->get_widget("lbl_nombre", lbl_nombre);
        rg->get_widget("lbl_extra", lbl_extra);
        rg->get_widget("lbl_cap_extra", lbl_cap_extra);
@@ -102,11 +101,10 @@ void Principal::on_mnu_file_disconnect()
 {
        if (conexion == NULL) return;
 
-       PlaQui::Server::Command c("transmission", "stop");
+       PlaQui::Server::Command c("connection", "stop");
        c.add_arg(conexion->get_host());
-       c.add_arg("7528");
+       c.add_arg("7522");
        conexion->send(c);
-       conexion->finish();
 }
 
 void Principal::on_mnu_file_connect()
@@ -167,6 +165,11 @@ void Principal::update_items_prop()
 
        lbl_cap_flujo->set_text(last_selected->get_cap_flow());
        lbl_cap_extra->set_text(last_selected->get_cap_extra());
+
+       color_preview->modify_bg(Gtk::STATE_NORMAL, last_selected->get_color());
+       color_preview->queue_draw();
+
+       std::cout << last_selected->get_name() << " " << last_selected->get_color().get_red() << std::endl;
 }
 
 void Principal::on_conexion_connected()
@@ -528,6 +531,9 @@ void Principal::read_status_xml(const std::string &frame)
                                        tmp_b = get_bool_from_xml(items->children);
                                        item_name = (char *)xmlGetProp(items, BAD_CAST"name");
                                        mapItems[item_name]->set_open(tmp_b);
+                               }  else if (xmlStrcmp(items->name, BAD_CAST"color")==0) {
+                                       item_name = (char *)xmlGetProp(items, BAD_CAST"name");
+                                       mapItems[item_name]->set_color( get_rgb_from_xml(items->children) );
                                } else if (xmlStrcmp(items->name, BAD_CAST"tank")==0) {
                                        xmlNodePtr nodo_tmp = items->children;
                                        float cap, lit;
@@ -554,6 +560,28 @@ void Principal::read_status_xml(const std::string &frame)
        }
 }
 
+Gdk::Color Principal::get_rgb_from_xml(xmlNodePtr nodo)
+{
+       unsigned r,g,b;
+       while (nodo != NULL) {
+               if (nodo->type == XML_ELEMENT_NODE) {
+                       if (xmlStrcmp(nodo->name, BAD_CAST"r")==0)
+                               r = atoi( (char *)XML_GET_CONTENT(nodo->children) );
+                       if (xmlStrcmp(nodo->name, BAD_CAST"g")==0)
+                               g = atoi( (char *)XML_GET_CONTENT(nodo->children) );
+                       if (xmlStrcmp(nodo->name, BAD_CAST"b")==0)
+                               b = atoi( (char *)XML_GET_CONTENT(nodo->children) );
+               }
+               nodo = nodo->next;
+       }
+       r = 65535 * r / 255;
+       g = 65535 * g / 255;
+       b = 65535 * b / 255;
+       Gdk::Color c;
+       c.set_rgb(r,g,b);
+
+       return c;
+}
 float Principal::get_float_from_xml(xmlNodePtr nodo)
 {
        float tmp = -1;
index 4a851e05c773c4b192cdc85fefb0255b73059e64..0feedc26e74ba09f822e66dac5318680a0105aeb 100644 (file)
@@ -3,7 +3,7 @@
 #ifndef _RGB_H_
 #define _RGB_H_
 
-typedef unsigned char color;
+typedef unsigned int color;
 
 /** Representación de un color en codificación RGB */
 class RGB {
index 3713776245b620f7018e4e5a5758881aab7c39cf..e19a038b4c589b6ba85a6638473bb0fce1148764 100644 (file)
@@ -79,6 +79,8 @@ protected:
        void loadUnion(xmlNodePtr nodo);
        void loadDrain(xmlNodePtr nodo);
 
+       RGB loadRGB(xmlNodePtr nodo);
+
        // Frame. Define el orden para los cuadros del XML
        unsigned long int frame;
 };
index f278904ed7dc1156db9e0196da86bec0e94ca343..bc0e3f352a2a341644967fd104a0969457b30601 100644 (file)
@@ -63,6 +63,11 @@ void Conduct::simulate()
                return;
        }
 
+       std::list<IConector *>::iterator i = in_list.begin();
+       if (i != in_list.end()) {
+               PlantItem *o = (PlantItem *)(*i);
+               set_color( o->get_color() );
+       }
        std::cout << name << "::Flujo actual = " << actual_flow << " de " << max_flow << std::endl;
        updated = false;
 }
index 80dc0101ec1a4a170f2d9dbd11df44e145430a71..09fd79d133cd5f6e1bab6ab8e6b51ff788460844 100644 (file)
@@ -27,6 +27,11 @@ void Drainage::update(int dir)
 
 void Drainage::simulate()
 {
+       std::list<IConector *>::iterator i = in_list.begin();
+       if (i != in_list.end()) {
+               PlantItem *o = (PlantItem *)(*i);
+               set_color( o->get_color() );
+       }
        std::cout << name << "::Flujo recibido = " << actual_flow << std::endl;
        updated = false;
        actual_flow = 0;
index 8e64bc3be8130297ae1d4f749f7ac3521fd40bdb..6e76c66a13e674337c5f1f7900250dca2899055a 100644 (file)
@@ -31,6 +31,11 @@ void Exclusa::update(int dir)
 
 void Exclusa::simulate()
 {
+       std::list<IConector *>::iterator i = in_list.begin();
+       if (i != in_list.end()) {
+               PlantItem *o = (PlantItem *)(*i);
+               set_color( o->get_color() );
+       }
        std::cout << name << ": " << ((is_open)?"Abierta":"Cerrada") << std::endl;
 }
 
index 4470fc4afa62392d5725ebb264a67cea5528fb67..e6e52b555e14a7ddc4d26f27fe0e5dc158287c5b 100644 (file)
@@ -22,7 +22,7 @@ int main(int argc, char *argv[])
        while (i<2) {
                sim->simulate();
 
-//             std::cout << sim->get_state_as_xml() << std::endl << std::endl;
+               std::cout << sim->get_state_as_xml() << std::endl << std::endl;
                i++;
        }
 
index ea3b85ee4d0f97e50ab73a6b28ab99eed4a92578..9405a945455e2191f23b9df591bcd5fd32e69482 100644 (file)
@@ -8,6 +8,7 @@ PlantItem::PlantItem(const std::string &_name):IConector(0, 0)
 {
        name = _name;
        updated = false;
+       fluid_color = RGB(255,255,255);
 }
 
 PlantItem::PlantItem(unsigned ins, unsigned outs):IConector(ins, outs)
@@ -36,6 +37,11 @@ void PlantItem::get_state_as_xml(std::stringstream &out)
        out << "\t<float name=\"" << name << "\">" << std::endl;
        out << "\t\t<actual_flow>" << actual_flow << "</actual_flow>" << std::endl;
        out << "\t</float>" << std::endl;
+       out << "\t<color name=\"" << name << "\">" << std::endl;
+       out << "\t\t<r>" << fluid_color.r() << "</r>" << std::endl;
+       out << "\t\t<g>" << fluid_color.g() << "</g>" << std::endl;
+       out << "\t\t<b>" << fluid_color.b() << "</b>" << std::endl;
+       out << "\t</color>" << std::endl;
 
        // Para que quede bonito
        actual_flow = 99999;
index 106f6e39ef69fc2f51508fb7f6c08745a738575d..2fe6f6ecb586672da5cb106ce0eecb7b7e634d6e 100644 (file)
@@ -201,8 +201,7 @@ void Simulator::loadBomba(xmlNodePtr nodo)
                        } else if (xmlStrcmp(nodo->name, BAD_CAST"entrega") == 0) {
                                flujo = atof( (char *)XML_GET_CONTENT(nodo->children) );
                        } else if (xmlStrcmp(nodo->name, BAD_CAST"color") == 0) {
-                               // FIXME !
-                               color = RGB();
+                               color = loadRGB(nodo->children);
                        }
                }
                nodo = nodo->next;
@@ -270,7 +269,7 @@ void Simulator::loadTank(xmlNodePtr nodo)
        std::string name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
        int orientacion=0, x, y;
        float capacidad, inicial;
-       RGB color; // TODO
+       RGB color;
 
        nodo = nodo->children;
        while (nodo != NULL) {
@@ -285,6 +284,8 @@ void Simulator::loadTank(xmlNodePtr nodo)
                                capacidad = atoi( (char *)XML_GET_CONTENT(nodo->children) );
                        } else if (xmlStrcmp(nodo->name, BAD_CAST"inicial") == 0) {
                                inicial = atof( (char *)XML_GET_CONTENT(nodo->children) );
+                       } else if (xmlStrcmp(nodo->name, BAD_CAST"") == 0) {
+                               color = loadRGB(nodo->children);
                        }
                }
                nodo = nodo->next;
@@ -443,3 +444,20 @@ std::string Simulator::get_state_as_xml()
        return out.str();;
 }
 
+RGB Simulator::loadRGB(xmlNodePtr nodo)
+{
+       unsigned r,g,b;
+       while (nodo != NULL) {
+               if (nodo->type == XML_ELEMENT_NODE) {
+                       if (xmlStrcmp(nodo->name, BAD_CAST"rojo")==0)
+                               r = atoi( (char *)XML_GET_CONTENT(nodo->children) );
+                       if (xmlStrcmp(nodo->name, BAD_CAST"verde")==0)
+                               g = atoi( (char *)XML_GET_CONTENT(nodo->children) );
+                       if (xmlStrcmp(nodo->name, BAD_CAST"azul")==0)
+                               b = atoi( (char *)XML_GET_CONTENT(nodo->children) );
+               }
+               nodo = nodo->next;
+       }
+       return RGB(r,g,b);
+}
+
index 4d4497ef1d55a6858c702a8733dd870c92e681b6..7afa150e9ea85328a2528c6b9c147ed6126f073b 100644 (file)
@@ -83,6 +83,11 @@ void Splitter::simulate()
                return;
        }
 
+       std::list<IConector *>::iterator i = in_list.begin();
+       if (i != in_list.end()) {
+               PlantItem *o = (PlantItem *)(*i);
+               set_color( o->get_color() );
+       }
        std::cout << name << "::Flujo actual = " << actual_flow << std::endl;
        updated = false;
 }
index baf3cc3a4f2593efede6827a4f95bc45a31813c0..5f22ef59d7c726b9f508de17329d4e0d25c7d170 100644 (file)
@@ -105,10 +105,25 @@ void Union::update(int dir)
 
 void Union::simulate()
 {
+       RGB c_in1, c_in2;
+       unsigned r,g,b;
+
        if (!updated) {
                return;
        }
+       std::list<IConector *>::iterator i = in_list.begin();
+       if (i != in_list.end()) {
+               PlantItem *o = (PlantItem *)(*i);
+               c_in1 = o->get_color();
+               i++;
+               o = (PlantItem *)(*i);
+               c_in2 = o->get_color();
+       }
 
+       r = ((c_in1.r()+c_in2.r())/2)%256;
+       g = ((c_in1.g()+c_in2.g())/2)%256;
+       b = ((c_in1.b()+c_in2.b())/2)%256;
+       set_color(RGB(r,g,b));
        std::cout << name << "::Flujo actual = " << actual_flow << std::endl;
        updated = false;
        in_on_zero = 0;
index 00880ec5a5953539811edf40ca0f1c8d51917b1d..48fe609cf955cf21bf75520e1ea50ec0e52e9b74 100644 (file)
@@ -3,7 +3,7 @@
        <bomba nombre="bomba0" id="0">
                <entrega>50,00</entrega>
                <color>
-                       <rojo>0</rojo>
+                       <rojo>255</rojo>
                        <verde>0</verde>
                        <azul>0</azul>
                </color>