6 using namespace PlaQui::Model;
8 Tank::Tank(const std::string &_name):Source(_name),Drain(_name),Control(_name)
12 /* Utilizo en input como el flotante de arriba y el output como el de abajo */
13 input = new Condition(Condition::GT, 0.9, this);
14 output = new Condition(Condition::LT, 0.1, this);
23 bool Tank::get_output()
28 void Tank::update(int dir)
37 // le sumo lo que recibo
38 litros += actual_in_flow;
39 // calculo el nuevo color
41 // le resto lo que entrego
42 litros -= actual_out_flow;
45 std::cout << name << "Capacidad: " << capacity;
46 std::cout << " Litros : " << litros << std::endl;
49 color_updated = false;
52 void Tank::recieve_msg(int msg, IConector *who, void *data)
56 // Verifico si esta conectado a mi entrada
57 std::list<IConector *>::iterator i;
58 for(i=in_list.begin(); i!=in_list.end(); i++) {
59 if ((*i) == who) pos = IN;
63 case MSG_QUERY_MAX_FLOW_OUT:
65 who->recieve_msg(MSG_RESPONSE_MAX_FLOW, this, &actual_in_flow);
67 actual_in_flow = capacity - litros;
68 if (*((float *)data) < actual_in_flow)
69 actual_in_flow = *((float *)data);
70 actual_flow = actual_out_flow = litros;
72 send_msg(OUT, MSG_QUERY_MAX_FLOW_OUT, &actual_out_flow);
74 who->recieve_msg(MSG_RESPONSE_MAX_FLOW, this, &actual_in_flow);
76 case MSG_RESPONSE_MAX_FLOW:
78 if (*((float *)data) < actual_out_flow)
79 actual_flow = actual_out_flow = *((float *)data);
82 case MSG_RESPONSE_COLOR:
84 RGB c = *((RGB *)data);
85 PlantItem *ic = static_cast<PlantItem *>(*(in_list.begin()));
87 float total = litros + ic->get_actual_flow();
89 r = (int)(get_color().r()*litros/total + c.r()*ic->get_actual_flow()/total);
90 g = (int)(get_color().g()*litros/total + c.g()*ic->get_actual_flow()/total);
91 b = (int)(get_color().b()*litros/total + c.b()*ic->get_actual_flow()/total);
95 set_color(RGB(r,g,b));
100 Control::recieve_msg(msg, who, data);
104 void Tank::get_state_as_xml(std::stringstream &out)
106 PlantItem::get_state_as_xml(out);
108 out << "\t<tank name=\"" << name << "\">" << std::endl;
109 out << "\t\t<capacity>" << capacity << "</capacity>" << std::endl;
110 out << "\t\t<litros>" << litros << "</litros>" << std::endl;
111 out << "\t\t<salida id=\"inferior\"><active>" << (output->get_output()?"true":"false") << "</active></salida>" << std::endl;
112 out << "\t\t<salida id=\"superior\"><active>" << (input->get_output()?"true":"false") << "</active></salida>" << std::endl;
113 out << "\t</tank>" << std::endl;