-
#include "plantitem.h"
+#include <iostream>
using namespace PlaQui::Model;
{
name = _name;
updated = false;
+ fluid_color = RGB(255,255,255);
+ color_updated = false;
}
PlantItem::PlantItem(unsigned ins, unsigned outs):IConector(ins, outs)
// TODO
return;
break;
+ case MSG_QUERY_COLOR:
+ if (color_updated) {
+ who->recieve_msg(MSG_RESPONSE_COLOR, this, &fluid_color);
+ return;
+ }
+ update_color();
+ who->recieve_msg(MSG_RESPONSE_COLOR, this, &fluid_color);
+ break;
+ case MSG_RESPONSE_COLOR:
+ {
+ RGB *c = ((RGB *)data);
+ set_color(*c);
+ }
+ break;
default:
IConector::recieve_msg(msg, who, data);
}
}
+void PlantItem::update_color()
+{
+ if (color_updated) return;
+
+ color_updated = true;
+ send_msg(IConector::IN, MSG_QUERY_COLOR);
+}
+
void PlantItem::get_state_as_xml(std::stringstream &out)
{
out << "\t<float name=\"" << name << "\">" << std::endl;
out << "\t\t<actual_flow>" << actual_flow << "</actual_flow>" << std::endl;
out << "\t</float>" << std::endl;
+ out << "\t<color name=\"" << name << "\">" << std::endl;
+ out << "\t\t<r>" << fluid_color.r() << "</r>" << std::endl;
+ out << "\t\t<g>" << fluid_color.g() << "</g>" << std::endl;
+ out << "\t\t<b>" << fluid_color.b() << "</b>" << std::endl;
+ out << "\t</color>" << std::endl;
// Para que quede bonito
actual_flow = 99999;