5 using namespace PlaQui::Model;
7 Tank::Tank(const std::string &_name):Source(_name),Drain(_name),Control(_name)
16 bool Tank::get_output()
21 void Tank::update(int dir)
31 std::list<IConector *>::iterator i = in_list.begin();
32 if (i != in_list.end()) {
33 PlantItem *o = (PlantItem *)(*i);
34 in_color = o->get_color();
37 // le sumo lo que recibo
38 litros += actual_in_flow;
39 // calculo el nuevo color
43 r = (int)(fluid_color.r()*litros/l + in_color.r()*actual_in_flow/l);
44 g = (int)(fluid_color.g()*litros/l + in_color.g()*actual_in_flow/l);
45 b = (int)(fluid_color.b()*litros/l + in_color.b()*actual_in_flow/l);
50 fluid_color = RGB(r,g,b);
52 // le resto lo que entrego
53 litros -= actual_out_flow;
56 std::cout << name << "Capacidad: " << capacity;
57 std::cout << " Litros : " << litros << std::endl;
62 void Tank::recieve_msg(int msg, IConector *who, void *data)
66 // Verifico si esta conectado a mi entrada
67 std::list<IConector *>::iterator i;
68 for(i=in_list.begin(); i!=in_list.end(); i++) {
69 if ((*i) == who) pos = IN;
73 case MSG_QUERY_MAX_FLOW_OUT:
74 actual_in_flow = capacity - litros;
75 if (*((float *)data) < actual_in_flow)
76 actual_in_flow = *((float *)data);
77 actual_out_flow = litros;
78 send_msg(OUT, MSG_QUERY_MAX_FLOW_OUT, &actual_out_flow);
80 who->recieve_msg(MSG_RESPONSE_MAX_FLOW, this, &actual_in_flow);
83 case MSG_RESPONSE_MAX_FLOW:
85 if (*((float *)data) < actual_out_flow)
86 actual_out_flow = *((float *)data);
91 void Tank::get_state_as_xml(std::stringstream &out)
93 PlantItem::get_state_as_xml(out);
95 out << "\t<tank name=\"" << name << "\">" << std::endl;
96 out << "\t\t<capacity>" << capacity << "</capacity>" << std::endl;
97 out << "\t\t<litros>" << litros << "</litros>" << std::endl;
98 out << "\t</tank>" << std::endl;