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);
15 input->set_name(name+" superior");
16 output->set_name(name+" inferior");
25 bool Tank::get_output()
27 std::cout << "TODO MAL" << std::endl;
31 void Tank::update(int dir)
40 // le sumo lo que recibo
41 litros += actual_in_flow;
42 // calculo el nuevo color
44 // le resto lo que entrego
45 litros -= actual_out_flow;
48 std::cout << name << "Capacidad: " << capacity;
49 std::cout << " Litros : " << litros << std::endl;
52 color_updated = false;
55 void Tank::recieve_msg(int msg, IConector *who, void *data)
59 // Verifico si esta conectado a mi entrada
60 std::list<IConector *>::iterator i;
61 for(i=in_list.begin(); i!=in_list.end(); i++) {
62 if ((*i) == who) pos = IN;
66 case MSG_QUERY_MAX_FLOW_OUT:
68 who->recieve_msg(MSG_RESPONSE_MAX_FLOW, this, &actual_in_flow);
70 actual_in_flow = capacity - litros;
71 if (*((float *)data) < actual_in_flow)
72 actual_in_flow = *((float *)data);
73 actual_flow = actual_out_flow = litros;
75 send_msg(OUT, MSG_QUERY_MAX_FLOW_OUT, &actual_out_flow);
77 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_flow = actual_out_flow = *((float *)data);
85 case MSG_RESPONSE_COLOR:
87 RGB c = *((RGB *)data);
88 PlantItem *ic = static_cast<PlantItem *>(*(in_list.begin()));
90 float total = litros + ic->get_actual_flow();
92 r = (int)(get_color().r()*litros/total + c.r()*ic->get_actual_flow()/total);
93 g = (int)(get_color().g()*litros/total + c.g()*ic->get_actual_flow()/total);
94 b = (int)(get_color().b()*litros/total + c.b()*ic->get_actual_flow()/total);
98 set_color(RGB(r,g,b));
103 Control::recieve_msg(msg, who, data);
107 void Tank::get_state_as_xml(std::stringstream &out)
109 PlantItem::get_state_as_xml(out);
111 out << "\t<tank name=\"" << name << "\">" << std::endl;
112 out << "\t\t<capacity>" << capacity << "</capacity>" << std::endl;
113 out << "\t\t<litros>" << litros << "</litros>" << std::endl;
114 out << "\t\t<salida id=\"inferior\"><active>" << (output->get_output()?"true":"false") << "</active></salida>" << std::endl;
115 out << "\t\t<salida id=\"superior\"><active>" << (input->get_output()?"true":"false") << "</active></salida>" << std::endl;
116 out << "\t</tank>" << std::endl;