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()
25 std::cout << "TODO MAL" << std::endl;
29 void Tank::update(int dir)
38 // le sumo lo que recibo
39 litros += actual_in_flow;
40 // calculo el nuevo color
42 // le resto lo que entrego
43 litros -= actual_out_flow;
46 std::cout << name << "Capacidad: " << capacity;
47 std::cout << " Litros : " << litros << std::endl;
50 color_updated = false;
53 void Tank::recieve_msg(int msg, IConector *who, void *data)
57 // Verifico si esta conectado a mi entrada
58 std::list<IConector *>::iterator i;
59 for(i=in_list.begin(); i!=in_list.end(); i++) {
60 if ((*i) == who) pos = IN;
64 case MSG_QUERY_MAX_FLOW_OUT:
66 who->recieve_msg(MSG_RESPONSE_MAX_FLOW, this, &actual_in_flow);
68 actual_in_flow = capacity - litros;
69 if (*((float *)data) < actual_in_flow)
70 actual_in_flow = *((float *)data);
71 actual_flow = actual_out_flow = litros;
73 send_msg(OUT, MSG_QUERY_MAX_FLOW_OUT, &actual_out_flow);
75 who->recieve_msg(MSG_RESPONSE_MAX_FLOW, this, &actual_in_flow);
77 case MSG_RESPONSE_MAX_FLOW:
79 if (*((float *)data) < actual_out_flow)
80 actual_flow = actual_out_flow = *((float *)data);
83 case MSG_RESPONSE_COLOR:
85 RGB c = *((RGB *)data);
86 PlantItem *ic = static_cast<PlantItem *>(*(in_list.begin()));
88 float total = litros + ic->get_actual_flow();
90 r = (int)(get_color().r()*litros/total + c.r()*ic->get_actual_flow()/total);
91 g = (int)(get_color().g()*litros/total + c.g()*ic->get_actual_flow()/total);
92 b = (int)(get_color().b()*litros/total + c.b()*ic->get_actual_flow()/total);
96 set_color(RGB(r,g,b));
101 Control::recieve_msg(msg, who, data);
105 void Tank::get_state_as_xml(std::stringstream &out)
107 PlantItem::get_state_as_xml(out);
109 out << "\t<tank name=\"" << name << "\">" << std::endl;
110 out << "\t\t<capacity>" << capacity << "</capacity>" << std::endl;
111 out << "\t\t<litros>" << litros << "</litros>" << std::endl;
112 out << "\t\t<salida id=\"inferior\"><active>" << (output->get_output()?"true":"false") << "</active></salida>" << std::endl;
113 out << "\t\t<salida id=\"superior\"><active>" << (input->get_output()?"true":"false") << "</active></salida>" << std::endl;
114 out << "\t</tank>" << std::endl;