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;
55 std::cout << name << "Capacidad: " << capacity;
56 std::cout << " Litros : " << litros << std::endl;
60 void Tank::recieve_msg(int msg, IConector *who, void *data)
64 // Verifico si esta conectado a mi entrada
65 std::list<IConector *>::iterator i;
66 for(i=in_list.begin(); i!=in_list.end(); i++) {
67 if ((*i) == who) pos = IN;
71 case MSG_QUERY_MAX_FLOW_OUT:
72 actual_in_flow = capacity - litros;
73 if (*((float *)data) < actual_in_flow)
74 actual_in_flow = *((float *)data);
75 actual_out_flow = litros;
76 send_msg(OUT, MSG_QUERY_MAX_FLOW_OUT, &actual_out_flow);
78 who->recieve_msg(MSG_RESPONSE_MAX_FLOW, this, &actual_in_flow);
81 case MSG_RESPONSE_MAX_FLOW:
83 if (*((float *)data) < actual_out_flow)
84 actual_out_flow = *((float *)data);
89 void Tank::get_state_as_xml(std::stringstream &out)
91 PlantItem::get_state_as_xml(out);
93 out << "\t<tank name=\"" << name << "\">" << std::endl;
94 out << "\t\t<capacity>" << capacity << "</capacity>" << std::endl;
95 out << "\t\t<litros>" << litros << "</litros>" << std::endl;
96 out << "\t</tank>" << std::endl;