]> git.llucax.com Git - z.facultad/75.42/plaqui.git/commitdiff
* Se agrega el tanque la suma de color (no me gusta como esta, vere si la puedo hacer...
authorRicardo Markiewicz <gazer.arg@gmail.com>
Thu, 20 Nov 2003 16:58:42 +0000 (16:58 +0000)
committerRicardo Markiewicz <gazer.arg@gmail.com>
Thu, 20 Nov 2003 16:58:42 +0000 (16:58 +0000)
* El cliente ahra tiene un boton On/Off que apaga o enciende un elemento
  dependiendo de su estado actual. Anda para cualquier objeto, despues
voy a filtrar para que solo se pueda usar en exclusa y bomba.

Es muy lindo apagar la bomba de arriba a la derecha y ver como se vacia
el tanque, y cuando se vuelve a encender se llena :-)

Client/include/item.h
Client/include/item_pump.h
Client/include/principal.h
Client/src/client.glade
Client/src/principal.cpp
Model/src/tank.cpp

index e4c40c0734847f94b04414f2a160d0d88554d3f0..5a374dd7de63681b354ec2974aa4f3ec8b370794 100644 (file)
@@ -16,6 +16,7 @@ public:
        inline Glib::ustring get_name() { return name; }
        void set_position(int _x, int _y);
        void set_name(Glib::ustring _name);
        inline Glib::ustring get_name() { return name; }
        void set_position(int _x, int _y);
        void set_name(Glib::ustring _name);
+       inline bool get_open() { return open; }
        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_actual_flow(float f) { actual_flow = f; }
        inline void set_open(bool b) { open = b; }
        inline void set_extra(float f) { extra = f; }
index 8fd486444f61639903a4d0b3885095a1573c6877..f426f2773abe6abfd6643c7236bfaee3427357a3 100644 (file)
@@ -8,6 +8,8 @@ class ViewPump:public ViewItem {
 public:
        ViewPump(Glib::ustring _name, int orientacion);
        virtual ~ViewPump();
 public:
        ViewPump(Glib::ustring _name, int orientacion);
        virtual ~ViewPump();
+       virtual std::string get_cap_extra() { return "Estado"; }
+       virtual std::string get_extra() { return (open)?"Encendida":"Apagada"; }
 };
 
 #endif
 };
 
 #endif
index 5256b1d01d3864c83302079e003385ab8bc36952..f166cf3f5e797a548f28b5880c2c4a9d7cb0f664 100644 (file)
@@ -55,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::Fixed *work_place;
        Gtk::Label *lbl_nombre, *lbl_color, *lbl_flujo, *lbl_extra, *lbl_cap_flujo, *lbl_cap_extra;
        Gtk::Image *ico_conected;
+       Gtk::Button *btn_activar;
        Gtk::DrawingArea *color_preview;
 
        // Actualiza las propiedades en la ventana del item actual
        Gtk::DrawingArea *color_preview;
 
        // Actualiza las propiedades en la ventana del item actual
@@ -67,6 +68,7 @@ protected:
        virtual void on_mnu_help_about();
        virtual void on_dlg_connect_ok();
        virtual void on_get_clicked();
        virtual void on_mnu_help_about();
        virtual void on_dlg_connect_ok();
        virtual void on_get_clicked();
+       virtual void on_btn_activar_clicked();
 
        virtual bool on_item_clicked(GdkEventButton *, ViewItem *);
        
 
        virtual bool on_item_clicked(GdkEventButton *, ViewItem *);
        
index 10d000f7035f32b11f86e8021490e8cfd37c0957..1ca5be1062f47f07ced4d548792a3373fcf5bcc8 100644 (file)
                  <child>
                    <widget class="GtkTable" id="table3">
                      <property name="visible">True</property>
                  <child>
                    <widget class="GtkTable" id="table3">
                      <property name="visible">True</property>
-                     <property name="n_rows">4</property>
+                     <property name="n_rows">5</property>
                      <property name="n_columns">2</property>
                      <property name="homogeneous">False</property>
                      <property name="row_spacing">0</property>
                      <property name="n_columns">2</property>
                      <property name="homogeneous">False</property>
                      <property name="row_spacing">0</property>
                      </child>
 
                      <child>
                      </child>
 
                      <child>
-                       <widget class="GtkLabel" id="lbl_cap_color">
+                       <widget class="GtkLabel" id="lbl_flujo">
                          <property name="visible">True</property>
                          <property name="visible">True</property>
-                         <property name="label" translatable="yes">Color : </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="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="ypad">0</property>
                        </widget>
                        <packing>
-                         <property name="left_attach">0</property>
-                         <property name="right_attach">1</property>
-                         <property name="top_attach">2</property>
-                         <property name="bottom_attach">3</property>
-                         <property name="x_options">fill</property>
+                         <property name="left_attach">1</property>
+                         <property name="right_attach">2</property>
+                         <property name="top_attach">1</property>
+                         <property name="bottom_attach">2</property>
                          <property name="y_options"></property>
                        </packing>
                      </child>
 
                      <child>
                          <property name="y_options"></property>
                        </packing>
                      </child>
 
                      <child>
-                       <widget class="GtkLabel" id="lbl_cap_extra">
+                       <widget class="GtkLabel" id="lbl_nombre">
                          <property name="visible">True</property>
                          <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="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="ypad">0</property>
                        </widget>
                        <packing>
-                         <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="left_attach">1</property>
+                         <property name="right_attach">2</property>
+                         <property name="top_attach">0</property>
+                         <property name="bottom_attach">1</property>
                          <property name="y_options"></property>
                        </packing>
                      </child>
 
                      <child>
                          <property name="y_options"></property>
                        </packing>
                      </child>
 
                      <child>
-                       <widget class="GtkLabel" id="lbl_flujo">
+                       <widget class="GtkLabel" id="lbl_cap_color">
                          <property name="visible">True</property>
                          <property name="visible">True</property>
-                         <property name="label" translatable="yes">...</property>
+                         <property name="label" translatable="yes">Color : </property>
                          <property name="use_underline">False</property>
                          <property name="use_markup">False</property>
                          <property name="justify">GTK_JUSTIFY_LEFT</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="ypad">0</property>
                        </widget>
                        <packing>
-                         <property name="left_attach">1</property>
-                         <property name="right_attach">2</property>
-                         <property name="top_attach">1</property>
-                         <property name="bottom_attach">2</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>
                      </child>
 
                      <child>
                          <property name="y_options"></property>
                        </packing>
                      </child>
 
                      <child>
-                       <widget class="GtkLabel" id="lbl_nombre">
+                       <widget class="GtkLabel" id="lbl_cap_extra">
                          <property name="visible">True</property>
                          <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="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="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">2</property>
+                         <property name="bottom_attach">3</property>
+                         <property name="x_options">fill</property>
                          <property name="y_options"></property>
                        </packing>
                      </child>
                          <property name="y_options"></property>
                        </packing>
                      </child>
                        <packing>
                          <property name="left_attach">1</property>
                          <property name="right_attach">2</property>
                        <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="top_attach">2</property>
+                         <property name="bottom_attach">3</property>
                          <property name="y_options"></property>
                        </packing>
                      </child>
                          <property name="y_options"></property>
                        </packing>
                      </child>
                        <packing>
                          <property name="left_attach">1</property>
                          <property name="right_attach">2</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="top_attach">3</property>
+                         <property name="bottom_attach">4</property>
                          <property name="y_options">fill</property>
                        </packing>
                      </child>
                          <property name="y_options">fill</property>
                        </packing>
                      </child>
+
+                     <child>
+                       <widget class="GtkButton" id="btn_activar">
+                         <property name="visible">True</property>
+                         <property name="can_focus">True</property>
+                         <property name="label" translatable="yes">On/Off</property>
+                         <property name="use_underline">True</property>
+                         <property name="relief">GTK_RELIEF_NORMAL</property>
+                       </widget>
+                       <packing>
+                         <property name="left_attach">0</property>
+                         <property name="right_attach">2</property>
+                         <property name="top_attach">4</property>
+                         <property name="bottom_attach">5</property>
+                         <property name="x_options">fill</property>
+                         <property name="y_options"></property>
+                       </packing>
+                     </child>
                    </widget>
                  </child>
 
                    </widget>
                  </child>
 
index 1ccf645f883388c66c22caf80d8334abca92941a..0b59c0b8040470fa36ec54d6cd17b0ef14e9112d 100644 (file)
@@ -22,6 +22,7 @@ Principal::Principal(BaseObjectType *co, const Glib::RefPtr<Gnome::Glade::Xml> &
        work_place = 0;
        lbl_cap_flujo = lbl_cap_extra = lbl_extra = lbl_nombre = lbl_color = lbl_flujo = 0;
 
        work_place = 0;
        lbl_cap_flujo = lbl_cap_extra = lbl_extra = lbl_nombre = lbl_color = lbl_flujo = 0;
 
+       rg->get_widget("btn_activar", btn_activar);
        rg->get_widget("color_preview", color_preview);
        rg->get_widget("lbl_nombre", lbl_nombre);
        rg->get_widget("lbl_extra", lbl_extra);
        rg->get_widget("color_preview", color_preview);
        rg->get_widget("lbl_nombre", lbl_nombre);
        rg->get_widget("lbl_extra", lbl_extra);
@@ -50,6 +51,7 @@ Principal::Principal(BaseObjectType *co, const Glib::RefPtr<Gnome::Glade::Xml> &
        exit->signal_activate().connect( SigC::slot(*this, &Principal::on_mnu_file_exit));
        about->signal_activate().connect( SigC::slot(*this, &Principal::on_mnu_help_about));
        btn_get->signal_clicked().connect( SigC::slot(*this, &Principal::on_get_clicked) );
        exit->signal_activate().connect( SigC::slot(*this, &Principal::on_mnu_file_exit));
        about->signal_activate().connect( SigC::slot(*this, &Principal::on_mnu_help_about));
        btn_get->signal_clicked().connect( SigC::slot(*this, &Principal::on_get_clicked) );
+       btn_activar->signal_clicked().connect( SigC::slot(*this, &Principal::on_btn_activar_clicked) );
 
        conexion = NULL;
        is_xml_loaded = false;
 
        conexion = NULL;
        is_xml_loaded = false;
@@ -97,6 +99,23 @@ void Principal::on_mnu_file_exit()
        Gtk::Main::quit();
 }
 
        Gtk::Main::quit();
 }
 
+void Principal::on_btn_activar_clicked()
+{
+       if ((conexion == NULL) || (last_selected == NULL)) return;
+
+       PlaQui::Server::Command c("plant", "set");
+       c.add_arg("default");
+       c.add_arg(last_selected->get_name());
+       c.add_arg("open");
+       
+       if (last_selected->get_open())
+               c.add_arg("false");
+       else
+               c.add_arg("true");
+
+       conexion->send(c);
+}
+
 void Principal::on_mnu_file_disconnect()
 {
        if (conexion == NULL) return;
 void Principal::on_mnu_file_disconnect()
 {
        if (conexion == NULL) return;
@@ -168,8 +187,6 @@ void Principal::update_items_prop()
 
        color_preview->modify_bg(Gtk::STATE_NORMAL, last_selected->get_color());
        color_preview->queue_draw();
 
        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()
 }
 
 void Principal::on_conexion_connected()
index e951254a92de82d3ceeb553a899ab3b74d48b914..895b5eff04a010748319af99761d95db68442346 100644 (file)
@@ -26,11 +26,29 @@ void Tank::update(int dir)
 void Tank::simulate()
 {
        if (!updated) return;
 void Tank::simulate()
 {
        if (!updated) return;
+       RGB in_color;
+
+       std::list<IConector *>::iterator i = in_list.begin();
+       if (i != in_list.end()) {
+               PlantItem *o = (PlantItem *)(*i);
+               in_color = o->get_color();
+       }
 
        // le resto lo que entrego
        litros -= actual_out_flow;
 
        // le resto lo que entrego
        litros -= actual_out_flow;
+
+       // calculo el nuevo color
+       int r, g, b;
+       float l = litros+actual_in_flow;
+
+       r = (int)(fluid_color.r()*litros/l + in_color.r()*actual_in_flow/l);
+       g = (int)(fluid_color.g()*litros/l + in_color.g()*actual_in_flow/l);
+       b = (int)(fluid_color.b()*litros/l + in_color.b()*actual_in_flow/l);
+       
+       fluid_color = RGB(r,g,b);
+
        // le sumo lo que recibo
        // le sumo lo que recibo
-       litros += actual_in_flow;
+       litros = l;
 
        std::cout << name << "Capacidad: " << capacity;
        std::cout << "  Litros : " << litros << std::endl;
 
        std::cout << name << "Capacidad: " << capacity;
        std::cout << "  Litros : " << litros << std::endl;
@@ -68,7 +86,8 @@ void Tank::recieve_msg(int msg, IConector *who, void *data)
 
 void Tank::get_state_as_xml(std::stringstream &out)
 {
 
 void Tank::get_state_as_xml(std::stringstream &out)
 {
-       // El tanque no emite flujo actual!
+       PlantItem::get_state_as_xml(out);
+                               
        out << "\t<tank name=\"" << name << "\">" << std::endl;
        out << "\t\t<capacity>" << capacity << "</capacity>" << std::endl;
        out << "\t\t<litros>" << litros << "</litros>" << std::endl;
        out << "\t<tank name=\"" << name << "\">" << std::endl;
        out << "\t\t<capacity>" << capacity << "</capacity>" << std::endl;
        out << "\t\t<litros>" << litros << "</litros>" << std::endl;