actual.
- El ejemplo es completamente funcional y si se cambia algun valor los flujos
siguen dando bien actualizados :-)
- Se pone al dia el diagrama de clases
void Constructor::on_item_drag_data_get(const Glib::RefPtr<Gdk::DragContext>& context, GtkSelectionData* selection_data, guint info, guint time)
{
- if ( strcmp((const char *)selection_data->data,"item_codo.png")==0)
- gtk_selection_data_set (selection_data, selection_data->target, 10, (const guchar*)"item_codo.png", 13);
- if ( strcmp((const char *)selection_data->data,"item_canio.png")==0)
- gtk_selection_data_set (selection_data, selection_data->target, 10, (const guchar*)"item_canio.png", 14);
- if ( strcmp((const char *)selection_data->data,"item_y.png")==0)
- gtk_selection_data_set (selection_data, selection_data->target, 10, (const guchar*)"item_y.png", 10);
+ gtk_selection_data_set (selection_data, selection_data->target, 10, (const guchar*)"item_codo.png", 13);
}
void Constructor::on_item_drop_drag_received(const Glib::RefPtr<Gdk::DragContext>& context, int x, int y, GtkSelectionData* selection_data, guint info, guint time)
virtual bool get_output();
virtual void simulate();
+ float get_actual_flow() { return actual_flow; }
+ float get_max_flow() { return max_flow; }
+ void set_max_flow(float _f) { max_flow = _f; }
protected:
float max_flow;
+ float actual_flow;
private:
Source(const Source &):Control("null") {}
Source &operator = (const Source &) { return *this; }
out_slots = 1;
active = true;
open = true;
- max_flow = 1;
+ max_flow = actual_flow = 0.0f;
}
Bomb::~Bomb()
void Bomb::update()
{
if (updated) return;
+ actual_flow = 99999;
updated = true;
send_msg(OUT, MSG_QUERY_MAX_FLOW);
}
void Bomb::simulate()
{
- std::cout << name << "::Flujo entregado = " << (active && open)?max_flow:0;
+ std::cout << name << "::Flujo actual = " << ((active && open)?actual_flow:0) \
+ << " de " << max_flow;
std::cout << ((active && open)?" (funcionando)":" (apagada)") << std::endl;
}
// Me preguntan por el flujo máximo.
// Primero me actualizo, y luego respondo
update();
- float tmp = (active && open)?max_flow:0;
+ float tmp;
+ if (active && open) {
+ tmp = (actual_flow<max_flow)?actual_flow:max_flow;
+ } else {
+ tmp = 0.0f;
+ }
who->recieve_msg(MSG_RESPONSE_MAX_FLOW, this, &tmp);
}
break;
case MSG_RESPONSE_MAX_FLOW: {
- max_flow = *((float *)data);
+ float tmp = *((float *)data);
+ if (tmp < actual_flow) actual_flow = tmp;
}
break;
default:
Conduct *canio2;
bomba = new Bomb("bomba");
+ bomba->set_max_flow(3);
canio1 = new Conduct("cond_1");
canio1->set_max_flow(10);
canio2 = new Conduct("cond_2");