public:
ViewItem(Glib::ustring _name);
virtual ~ViewItem();
-// virtual bool on_expose_event(GdkEventExpose* event);
- Glib::ustring get_name();
+
+ inline Glib::ustring get_name() { return name; }
void set_position(int _x, int _y);
void set_name(Glib::ustring _name);
- void set_actual_flow(float f) { actual_flow = f; }
- void set_open(bool b) { open = b; }
- void set_extra(float f) { extra = f; }
-
+ inline void set_actual_flow(float f) { actual_flow = f; }
+ inline void set_open(bool b) { open = b; }
+ inline void set_extra(float f) { extra = f; }
+ inline void set_color(const Gdk::Color &c) { color = c; }
+ inline Gdk::Color get_color() { return color; }
std::string get_actual_flow();
virtual std::string get_cap_flow() { return "Flujo Actual :"; }
protected:
Glib::ustring name;
Gtk::Image image;
+ Gdk::Color color;
int x, y;
float actual_flow, extra;
bool open;
void read_status_xml(const std::string &frame);
float get_float_from_xml(xmlNodePtr nodo);
bool get_bool_from_xml(xmlNodePtr nodo);
-
+ Gdk::Color get_rgb_from_xml(xmlNodePtr nodo);
+
// Funciones de carga del XML
bool is_xml_loaded;
void loadXML();
Gtk::Fixed *work_place;
Gtk::Label *lbl_nombre, *lbl_color, *lbl_flujo, *lbl_extra, *lbl_cap_flujo, *lbl_cap_extra;
Gtk::Image *ico_conected;
+ Gtk::DrawingArea *color_preview;
// Actualiza las propiedades en la ventana del item actual
void update_items_prop();
</child>
<child>
- <widget class="GtkLabel" id="lbl_nombre">
+ <widget class="GtkLabel" id="lbl_cap_extra">
<property name="visible">True</property>
- <property name="label" translatable="yes">...</property>
+ <property name="label" translatable="yes">Extra : </property>
<property name="use_underline">False</property>
<property name="use_markup">False</property>
<property name="justify">GTK_JUSTIFY_LEFT</property>
<property name="ypad">0</property>
</widget>
<packing>
- <property name="left_attach">1</property>
- <property name="right_attach">2</property>
- <property name="top_attach">0</property>
- <property name="bottom_attach">1</property>
+ <property name="left_attach">0</property>
+ <property name="right_attach">1</property>
+ <property name="top_attach">3</property>
+ <property name="bottom_attach">4</property>
<property name="x_options">fill</property>
<property name="y_options"></property>
</packing>
<property name="right_attach">2</property>
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
- <property name="x_options">fill</property>
<property name="y_options"></property>
</packing>
</child>
<child>
- <widget class="GtkLabel" id="lbl_color">
+ <widget class="GtkLabel" id="lbl_nombre">
<property name="visible">True</property>
<property name="label" translatable="yes">...</property>
<property name="use_underline">False</property>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
- <property name="top_attach">2</property>
- <property name="bottom_attach">3</property>
- <property name="x_options">fill</property>
+ <property name="top_attach">0</property>
+ <property name="bottom_attach">1</property>
<property name="y_options"></property>
</packing>
</child>
<child>
- <widget class="GtkLabel" id="lbl_cap_extra">
+ <widget class="GtkLabel" id="lbl_extra">
<property name="visible">True</property>
- <property name="label" translatable="yes">Extra : </property>
+ <property name="label" translatable="yes">...</property>
<property name="use_underline">False</property>
<property name="use_markup">False</property>
<property name="justify">GTK_JUSTIFY_LEFT</property>
<property name="ypad">0</property>
</widget>
<packing>
- <property name="left_attach">0</property>
- <property name="right_attach">1</property>
+ <property name="left_attach">1</property>
+ <property name="right_attach">2</property>
<property name="top_attach">3</property>
<property name="bottom_attach">4</property>
- <property name="x_options">fill</property>
<property name="y_options"></property>
</packing>
</child>
<child>
- <widget class="GtkLabel" id="lbl_extra">
+ <widget class="GtkDrawingArea" id="color_preview">
<property name="visible">True</property>
- <property name="label" translatable="yes">...</property>
- <property name="use_underline">False</property>
- <property name="use_markup">False</property>
- <property name="justify">GTK_JUSTIFY_LEFT</property>
- <property name="wrap">False</property>
- <property name="selectable">False</property>
- <property name="xalign">0</property>
- <property name="yalign">0.5</property>
- <property name="xpad">0</property>
- <property name="ypad">0</property>
</widget>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
- <property name="top_attach">3</property>
- <property name="bottom_attach">4</property>
- <property name="x_options">fill</property>
- <property name="y_options"></property>
+ <property name="top_attach">2</property>
+ <property name="bottom_attach">3</property>
+ <property name="y_options">fill</property>
</packing>
</child>
</widget>
+
#include "item.h"
#include <sstream>
#include <string>
ViewItem::~ViewItem()
{
}
-/*
-bool ViewItem::on_expose_event(GdkEventExpose* event)
-{
- image->render_to_drawable ( get_window(), get_style()->get_black_gc(), 0, 0, 0, 0, image->get_width() ,image->get_height() ,
- Gdk::RGB_DITHER_NONE, 0, 0);
- return true;
-}
-*/
+
void ViewItem::set_position(int _x, int _y)
{
x = _x;
name = _name;
}
-Glib::ustring ViewItem::get_name()
-{
- return name;
-}
-
std::string ViewItem::get_actual_flow()
{
std::stringstream ss;
-
-
#include "principal.h"
#include <iostream>
#include <sstream>
Principal::Principal(BaseObjectType *co, const Glib::RefPtr<Gnome::Glade::Xml> &rg):Gtk::Window(co),refXml(rg)
{
- Gtk::MenuItem *conect=0, *exit=0, *about=0, *mnu_prop=0, *mnu_disconnect;
+ Gtk::MenuItem *conect=0, *exit=0, *about=0, *mnu_prop=0, *mnu_disconnect=0;
Gtk::Button *btn_get=0, *bar_connect=0;
txt_view = 0;
txt_target = txt_command = txt_args = 0;
work_place = 0;
lbl_cap_flujo = lbl_cap_extra = lbl_extra = lbl_nombre = lbl_color = lbl_flujo = 0;
+ rg->get_widget("color_preview", color_preview);
rg->get_widget("lbl_nombre", lbl_nombre);
rg->get_widget("lbl_extra", lbl_extra);
rg->get_widget("lbl_cap_extra", lbl_cap_extra);
{
if (conexion == NULL) return;
- PlaQui::Server::Command c("transmission", "stop");
+ PlaQui::Server::Command c("connection", "stop");
c.add_arg(conexion->get_host());
- c.add_arg("7528");
+ c.add_arg("7522");
conexion->send(c);
- conexion->finish();
}
void Principal::on_mnu_file_connect()
lbl_cap_flujo->set_text(last_selected->get_cap_flow());
lbl_cap_extra->set_text(last_selected->get_cap_extra());
+
+ color_preview->modify_bg(Gtk::STATE_NORMAL, last_selected->get_color());
+ color_preview->queue_draw();
+
+ std::cout << last_selected->get_name() << " " << last_selected->get_color().get_red() << std::endl;
}
void Principal::on_conexion_connected()
tmp_b = get_bool_from_xml(items->children);
item_name = (char *)xmlGetProp(items, BAD_CAST"name");
mapItems[item_name]->set_open(tmp_b);
+ } else if (xmlStrcmp(items->name, BAD_CAST"color")==0) {
+ item_name = (char *)xmlGetProp(items, BAD_CAST"name");
+ mapItems[item_name]->set_color( get_rgb_from_xml(items->children) );
} else if (xmlStrcmp(items->name, BAD_CAST"tank")==0) {
xmlNodePtr nodo_tmp = items->children;
float cap, lit;
}
}
+Gdk::Color Principal::get_rgb_from_xml(xmlNodePtr nodo)
+{
+ unsigned r,g,b;
+ while (nodo != NULL) {
+ if (nodo->type == XML_ELEMENT_NODE) {
+ if (xmlStrcmp(nodo->name, BAD_CAST"r")==0)
+ r = atoi( (char *)XML_GET_CONTENT(nodo->children) );
+ if (xmlStrcmp(nodo->name, BAD_CAST"g")==0)
+ g = atoi( (char *)XML_GET_CONTENT(nodo->children) );
+ if (xmlStrcmp(nodo->name, BAD_CAST"b")==0)
+ b = atoi( (char *)XML_GET_CONTENT(nodo->children) );
+ }
+ nodo = nodo->next;
+ }
+ r = 65535 * r / 255;
+ g = 65535 * g / 255;
+ b = 65535 * b / 255;
+ Gdk::Color c;
+ c.set_rgb(r,g,b);
+
+ return c;
+}
float Principal::get_float_from_xml(xmlNodePtr nodo)
{
float tmp = -1;
#ifndef _RGB_H_
#define _RGB_H_
-typedef unsigned char color;
+typedef unsigned int color;
/** Representación de un color en codificación RGB */
class RGB {
void loadUnion(xmlNodePtr nodo);
void loadDrain(xmlNodePtr nodo);
+ RGB loadRGB(xmlNodePtr nodo);
+
// Frame. Define el orden para los cuadros del XML
unsigned long int frame;
};
return;
}
+ std::list<IConector *>::iterator i = in_list.begin();
+ if (i != in_list.end()) {
+ PlantItem *o = (PlantItem *)(*i);
+ set_color( o->get_color() );
+ }
std::cout << name << "::Flujo actual = " << actual_flow << " de " << max_flow << std::endl;
updated = false;
}
void Drainage::simulate()
{
+ std::list<IConector *>::iterator i = in_list.begin();
+ if (i != in_list.end()) {
+ PlantItem *o = (PlantItem *)(*i);
+ set_color( o->get_color() );
+ }
std::cout << name << "::Flujo recibido = " << actual_flow << std::endl;
updated = false;
actual_flow = 0;
void Exclusa::simulate()
{
+ std::list<IConector *>::iterator i = in_list.begin();
+ if (i != in_list.end()) {
+ PlantItem *o = (PlantItem *)(*i);
+ set_color( o->get_color() );
+ }
std::cout << name << ": " << ((is_open)?"Abierta":"Cerrada") << std::endl;
}
while (i<2) {
sim->simulate();
-// std::cout << sim->get_state_as_xml() << std::endl << std::endl;
+ std::cout << sim->get_state_as_xml() << std::endl << std::endl;
i++;
}
{
name = _name;
updated = false;
+ fluid_color = RGB(255,255,255);
}
PlantItem::PlantItem(unsigned ins, unsigned outs):IConector(ins, outs)
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;
} else if (xmlStrcmp(nodo->name, BAD_CAST"entrega") == 0) {
flujo = atof( (char *)XML_GET_CONTENT(nodo->children) );
} else if (xmlStrcmp(nodo->name, BAD_CAST"color") == 0) {
- // FIXME !
- color = RGB();
+ color = loadRGB(nodo->children);
}
}
nodo = nodo->next;
std::string name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
int orientacion=0, x, y;
float capacidad, inicial;
- RGB color; // TODO
+ RGB color;
nodo = nodo->children;
while (nodo != NULL) {
capacidad = atoi( (char *)XML_GET_CONTENT(nodo->children) );
} else if (xmlStrcmp(nodo->name, BAD_CAST"inicial") == 0) {
inicial = atof( (char *)XML_GET_CONTENT(nodo->children) );
+ } else if (xmlStrcmp(nodo->name, BAD_CAST"") == 0) {
+ color = loadRGB(nodo->children);
}
}
nodo = nodo->next;
return out.str();;
}
+RGB Simulator::loadRGB(xmlNodePtr nodo)
+{
+ unsigned r,g,b;
+ while (nodo != NULL) {
+ if (nodo->type == XML_ELEMENT_NODE) {
+ if (xmlStrcmp(nodo->name, BAD_CAST"rojo")==0)
+ r = atoi( (char *)XML_GET_CONTENT(nodo->children) );
+ if (xmlStrcmp(nodo->name, BAD_CAST"verde")==0)
+ g = atoi( (char *)XML_GET_CONTENT(nodo->children) );
+ if (xmlStrcmp(nodo->name, BAD_CAST"azul")==0)
+ b = atoi( (char *)XML_GET_CONTENT(nodo->children) );
+ }
+ nodo = nodo->next;
+ }
+ return RGB(r,g,b);
+}
+
return;
}
+ std::list<IConector *>::iterator i = in_list.begin();
+ if (i != in_list.end()) {
+ PlantItem *o = (PlantItem *)(*i);
+ set_color( o->get_color() );
+ }
std::cout << name << "::Flujo actual = " << actual_flow << std::endl;
updated = false;
}
void Union::simulate()
{
+ RGB c_in1, c_in2;
+ unsigned r,g,b;
+
if (!updated) {
return;
}
+ std::list<IConector *>::iterator i = in_list.begin();
+ if (i != in_list.end()) {
+ PlantItem *o = (PlantItem *)(*i);
+ c_in1 = o->get_color();
+ i++;
+ o = (PlantItem *)(*i);
+ c_in2 = o->get_color();
+ }
+ r = ((c_in1.r()+c_in2.r())/2)%256;
+ g = ((c_in1.g()+c_in2.g())/2)%256;
+ b = ((c_in1.b()+c_in2.b())/2)%256;
+ set_color(RGB(r,g,b));
std::cout << name << "::Flujo actual = " << actual_flow << std::endl;
updated = false;
in_on_zero = 0;
<bomba nombre="bomba0" id="0">
<entrega>50,00</entrega>
<color>
- <rojo>0</rojo>
+ <rojo>255</rojo>
<verde>0</verde>
<azul>0</azul>
</color>