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 resto lo que entrego
38 litros -= actual_out_flow;
40 // calculo el nuevo color
42 float l = litros+actual_in_flow;
44 r = (int)(fluid_color.r()*litros/l + in_color.r()*actual_in_flow/l);
45 g = (int)(fluid_color.g()*litros/l + in_color.g()*actual_in_flow/l);
46 b = (int)(fluid_color.b()*litros/l + in_color.b()*actual_in_flow/l);
48 fluid_color = RGB(r,g,b);
50 // le sumo lo que recibo
53 std::cout << name << "Capacidad: " << capacity;
54 std::cout << " Litros : " << litros << std::endl;
58 void Tank::recieve_msg(int msg, IConector *who, void *data)
62 // Verifico si esta conectado a mi entrada
63 std::list<IConector *>::iterator i;
64 for(i=in_list.begin(); i!=in_list.end(); i++) {
65 if ((*i) == who) pos = IN;
69 case MSG_QUERY_MAX_FLOW_OUT:
70 actual_in_flow = capacity - litros;
71 if (*((float *)data) < actual_in_flow)
72 actual_in_flow = *((float *)data);
73 actual_out_flow = litros;
74 send_msg(OUT, MSG_QUERY_MAX_FLOW_OUT, &actual_out_flow);
76 who->recieve_msg(MSG_RESPONSE_MAX_FLOW, this, &actual_in_flow);
79 case MSG_RESPONSE_MAX_FLOW:
81 if (*((float *)data) < actual_out_flow)
82 actual_out_flow = *((float *)data);
87 void Tank::get_state_as_xml(std::stringstream &out)
89 PlantItem::get_state_as_xml(out);
91 out << "\t<tank name=\"" << name << "\">" << std::endl;
92 out << "\t\t<capacity>" << capacity << "</capacity>" << std::endl;
93 out << "\t\t<litros>" << litros << "</litros>" << std::endl;
94 out << "\t</tank>" << std::endl;