* Se ponen un poco mas bonitas las lineas de las conexiones logicas
* Se arregla el modelo para prevenir colcagas cuando el circuito es
realimentado. Entraba en un loop infinito. Ahora simula bien, aunque
en algunos casos se actualiza mal. Voy a tratar de resolverlo pronto.
/// Destructor.
virtual ~WorkPlace();
/// Destructor.
virtual ~WorkPlace();
+
+ /// Funcion que se ejecuta cuando se crea la ventana
+ virtual void on_realize();
+
///Esta funcion es llamada cada vez que el area de trabajo se tenga que redibujar.
virtual bool on_expose_event(GdkEventExpose *event);
///Esta funcion es llamada cada vez que el area de trabajo se tenga que redibujar.
virtual bool on_expose_event(GdkEventExpose *event);
///Estado de diseño
bool *logica;
protected:
///Estado de diseño
bool *logica;
protected:
- void draw_line(int x1, int y1, int x2, int y2);
+ void draw_line(int x1, int y1, int x2, int y2, Gdk::Color &color);
+ Gdk::Color color_in, color_out, color_dot;
+ Glib::RefPtr<Gdk::GC> gc;
// XXX Esto no deberia ser necesario! en todo caso devolves false en
// vez de true para que siga llamando a los otros handlers :)
//Gtk::DrawingArea::on_expose_event(event);
// XXX Esto no deberia ser necesario! en todo caso devolves false en
// vez de true para que siga llamando a los otros handlers :)
//Gtk::DrawingArea::on_expose_event(event);
+ if (logic_connect && !is_logic) {
draw_connectors();
}
return true;
draw_connectors();
}
return true;
{
CItem * _item0, *_item1, *_item2;
ConnectorType temp0, temp1, temp2;
{
CItem * _item0, *_item1, *_item2;
ConnectorType temp0, temp1, temp2;
+ std::cout << get_img_actual() << std::endl;
switch (get_img_actual()) {
case 0:
temp0 = is_other_connection_area( get_position_x() - 5, get_position_y() +16, &_item0);
switch (get_img_actual()) {
case 0:
temp0 = is_other_connection_area( get_position_x() - 5, get_position_y() +16, &_item0);
break;
case 3:
temp1 = is_other_connection_area( get_position_x()+16, get_position_y()-5, &_item1);
break;
case 3:
temp1 = is_other_connection_area( get_position_x()+16, get_position_y()-5, &_item1);
- temp2 = is_other_connection_area( get_position_x()+get_image()->get_width()+5, get_position_y()+get_image()->get_height()/2,& _item0);
- temp0 = is_other_connection_area( get_position_x()+16, get_position_y()+get_image()->get_height()+5, &_item1);
+ temp2 = is_other_connection_area( get_position_x()+get_image()->get_width()+5, get_position_y()+get_image()->get_height()/2,& _item2);
+ temp0 = is_other_connection_area( get_position_x()+16, get_position_y()+get_image()->get_height()+5, &_item0);
}
if ( is_union ) {
if ( temp0 == OUT && temp1 == OUT && temp2 == IN ) {
}
if ( is_union ) {
if ( temp0 == OUT && temp1 == OUT && temp2 == IN ) {
int WorkPlace::pointed = -1;
int WorkPlace::pointed = -1;
-WorkPlace::WorkPlace( BaseObjectType* cobject, const Glib::RefPtr<Gnome::Glade::Xml> &refGlade):Gtk::Fixed(cobject)
+WorkPlace::WorkPlace(BaseObjectType* cobject, const Glib::RefPtr<Gnome::Glade::Xml> &refGlade):Gtk::Fixed(cobject)
+ gc = Gdk::GC::create(get_window());
+ std::cout << "Aca" << std::endl;
+ Glib::RefPtr<Gdk::Colormap> colormap = gc->get_colormap();
+ color_in = Gdk::Color("red");
+ color_out = Gdk::Color("blue");
+ color_dot = Gdk::Color("black");
+ colormap->alloc_color(color_in);
+ colormap->alloc_color(color_out);
+ colormap->alloc_color(color_dot);
}
WorkPlace::~WorkPlace()
{
}
}
WorkPlace::~WorkPlace()
{
}
+void WorkPlace::on_realize()
+{
+ Gtk::Fixed::on_realize();
+ gc = Gdk::GC::create(get_window());
+ std::cout << "Aca" << std::endl;
+ Glib::RefPtr<Gdk::Colormap> colormap = gc->get_colormap();
+ color_in = Gdk::Color("red");
+ color_out = Gdk::Color("blue");
+ colormap->alloc_color(color_in);
+ colormap->alloc_color(color_out);
+}
+
bool WorkPlace::on_expose_event(GdkEventExpose *event)
{
int x, y;
bool WorkPlace::on_expose_event(GdkEventExpose *event)
{
int x, y;
+ gc->set_foreground(color_dot);
for(x=0; x<get_width(); x+=32)
for (y=0; y<get_height();y+=32){
for(x=0; x<get_width(); x+=32)
for (y=0; y<get_height();y+=32){
- get_window()->draw_point (get_style()->get_black_gc(), x,y);
- get_window()->draw_point (get_style()->get_black_gc(), x,y+1);
- get_window()->draw_point (get_style()->get_black_gc(), x,y-1);
- get_window()->draw_point (get_style()->get_black_gc(), x+1,y);
- get_window()->draw_point (get_style()->get_black_gc(), x-1,y);
+ get_window()->draw_point (gc, x,y);
+ get_window()->draw_point (gc, x,y+1);
+ get_window()->draw_point (gc, x,y-1);
+ get_window()->draw_point (gc, x+1,y);
+ get_window()->draw_point (gc, x-1,y);
+ int a, b, w, z, x_offset, y_offset, img;
std::list<t_line>::iterator i = lista_lineas_in.begin();
while ( i != lista_lineas_in.end() ) {
t_line temp = *i;
if ( get_item(temp.store_id) != NULL && get_logic_item(temp.logic_id) != NULL ) {
std::list<t_line>::iterator i = lista_lineas_in.begin();
while ( i != lista_lineas_in.end() ) {
t_line temp = *i;
if ( get_item(temp.store_id) != NULL && get_logic_item(temp.logic_id) != NULL ) {
- get_item(temp.store_id)->get_in_logic_connect_position(w,z);
+ img = get_logic_item(temp.logic_id)->get_img_actual();
+ x_offset = y_offset = 0;
+ switch (img) {
+ case 0:
+ x_offset = 15;
+ break;
+ case 1:
+ y_offset = 15;
+ break;
+ case 2:
+ x_offset = -15;
+ break;
+ case 3:
+ y_offset = -15;
+ }
get_logic_item(temp.logic_id)->get_out_logic_connect_position(a, b);
get_logic_item(temp.logic_id)->get_out_logic_connect_position(a, b);
+ get_item(temp.store_id)->get_in_logic_connect_position(w,z);
+ draw_line(a+x_offset, b+y_offset, w,z, color_in);
+ get_window()->draw_line(gc, a, b, a+x_offset, b+y_offset);
while ( i != lista_lineas_out.end() ) {
t_line temp = *i;
if ( get_item(temp.store_id) != NULL && get_logic_item(temp.logic_id) != NULL ) {
while ( i != lista_lineas_out.end() ) {
t_line temp = *i;
if ( get_item(temp.store_id) != NULL && get_logic_item(temp.logic_id) != NULL ) {
+ img = get_logic_item(temp.logic_id)->get_img_actual();
+ x_offset = y_offset = 0;
+ switch (img) {
+ case 0:
+ x_offset = 15;
+ break;
+ case 1:
+ y_offset = 15;
+ break;
+ case 2:
+ x_offset = -15;
+ break;
+ case 3:
+ y_offset = -15;
+ }
get_item(temp.store_id)->get_out_logic_connect_position(w,z);
get_logic_item(temp.logic_id)->get_in_logic_connect_position(a, b);
get_item(temp.store_id)->get_out_logic_connect_position(w,z);
get_logic_item(temp.logic_id)->get_in_logic_connect_position(a, b);
+// draw_line(w, z, a, b, color_out);
+ draw_line(w, z, a+x_offset, b+y_offset,color_out);
+ get_window()->draw_line(gc, a, b, a+x_offset, b+y_offset);
-void WorkPlace::draw_line(int x1, int y1, int x2, int y2)
+void WorkPlace::draw_line(int x1, int y1, int x2, int y2, Gdk::Color &color)
- get_window()->draw_line (get_style()->get_black_gc(), x1, y1, x1, y2);
- get_window()->draw_line (get_style()->get_black_gc(), x1, y2, x2, y2);
+ gc->set_foreground(color);
+ gc->set_line_attributes(3, Gdk::LINE_SOLID, Gdk::CAP_NOT_LAST, Gdk::JOIN_MITER);
+ get_window()->draw_line (gc, x1, y1, x1, y2);
+ get_window()->draw_line (gc, x1, y2, x2, y2);
in_slots = 1;
out_slots = 1;
actual_flow = 99999;
in_slots = 1;
out_slots = 1;
actual_flow = 99999;
{
switch (msg) {
case MSG_QUERY_MAX_FLOW_OUT: {
{
switch (msg) {
case MSG_QUERY_MAX_FLOW_OUT: {
+ if (updated) {
+ who->recieve_msg(MSG_RESPONSE_MAX_FLOW, this, &actual_flow);
+ }
+
// Me preguntan por el flujo máximo.
// Primero me actualizo, y luego respondo
// Me preguntan por el flujo máximo.
// Primero me actualizo, y luego respondo
float tmp = *((float *)data);
actual_flow = (actual_flow>max_flow)?max_flow:actual_flow;
actual_flow = (actual_flow<tmp)?actual_flow:tmp;
send_msg(OUT, MSG_QUERY_MAX_FLOW_OUT, &actual_flow);
who->recieve_msg(MSG_RESPONSE_MAX_FLOW, this, &actual_flow);
float tmp = *((float *)data);
actual_flow = (actual_flow>max_flow)?max_flow:actual_flow;
actual_flow = (actual_flow<tmp)?actual_flow:tmp;
send_msg(OUT, MSG_QUERY_MAX_FLOW_OUT, &actual_flow);
who->recieve_msg(MSG_RESPONSE_MAX_FLOW, this, &actual_flow);
}
break;
case MSG_RESPONSE_MAX_FLOW: {
}
break;
case MSG_RESPONSE_MAX_FLOW: {
input = new ByPass();
output = new ByPass();
((ByPass *)output)->set_control(this);
input = new ByPass();
output = new ByPass();
((ByPass *)output)->set_control(this);
{
switch (msg) {
case MSG_QUERY_MAX_FLOW_OUT:
{
switch (msg) {
case MSG_QUERY_MAX_FLOW_OUT:
+ if (updated) {
+ who->recieve_msg(MSG_RESPONSE_MAX_FLOW, this, &temp);
+ }
temp = *((float *)data);
if (!is_open) temp = 0;
send_msg(OUT, MSG_QUERY_MAX_FLOW_OUT, &temp);
temp = *((float *)data);
if (!is_open) temp = 0;
send_msg(OUT, MSG_QUERY_MAX_FLOW_OUT, &temp);
using namespace PlaQui::Model;
IConector::IConector(unsigned in, unsigned out)
using namespace PlaQui::Model;
IConector::IConector(unsigned in, unsigned out)
(*it)->recieve_msg(msg, this, data);
break;
case OUT:
(*it)->recieve_msg(msg, this, data);
break;
case OUT:
- for(it=out_list.begin(); it!=out_list.end(); it++)
+ for(it=out_list.begin(); it!=out_list.end(); it++) {
(*it)->recieve_msg(msg, this, data);
(*it)->recieve_msg(msg, this, data);
document = xmlParseFile(filename.c_str());
if (document == NULL) {
is_load_ok = false;
document = xmlParseFile(filename.c_str());
if (document == NULL) {
is_load_ok = false;
+ std::cout << "Error cargando XML" << std::endl;
for(i1=pump_lst.begin(); i1!=pump_lst.end(); i1++)
(*i1)->update();
for(i1=pump_lst.begin(); i1!=pump_lst.end(); i1++)
(*i1)->update();
std::list<PlantItem *>::iterator i2;
std::list<PlantItem *>::iterator i2;
- for(i2=items.begin(); i2!=items.end(); i2++)
+ for(i2=items.begin(); i2!=items.end(); i2++)
(*i2)->simulate();
frame++;
(*i2)->simulate();
frame++;
continue;
}
// obtengo el items actual por su nombre
continue;
}
// obtengo el items actual por su nombre
+ std::string s = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
current_item = find((char *)xmlGetProp(nodo, BAD_CAST"nombre"));
props = nodo->children;
conector3 = conector2 = conector1 = NULL;
current_item = find((char *)xmlGetProp(nodo, BAD_CAST"nombre"));
props = nodo->children;
conector3 = conector2 = conector1 = NULL;
// bien, es a la entrada!, obtengo el item al cual lo tengo que conectar
to_connect = find((char *)XML_GET_CONTENT(conector1->children));
// y lo conecto
// bien, es a la entrada!, obtengo el item al cual lo tengo que conectar
to_connect = find((char *)XML_GET_CONTENT(conector1->children));
// y lo conecto
- current_item->connect(to_connect, IConector::IN);
+ if (!current_item->connect(to_connect, IConector::IN)) {
+ std::cout << s << " Error al conectar1 ENTRADA = " << (char *)XML_GET_CONTENT(conector1->children) << std::endl;
+ } else {
+ std::cout << s << " ENTRADA1 = " << (char *)XML_GET_CONTENT(conector1->children) << std::endl;
+ }
} else if (xmlStrcmp(conector1->name, BAD_CAST"salida") == 0) {
// Era a salida, es casi lo mismo que arriba
to_connect = find((char *)XML_GET_CONTENT(conector1->children));
} else if (xmlStrcmp(conector1->name, BAD_CAST"salida") == 0) {
// Era a salida, es casi lo mismo que arriba
to_connect = find((char *)XML_GET_CONTENT(conector1->children));
- current_item->connect(to_connect, IConector::OUT);
+ if (!current_item->connect(to_connect, IConector::OUT)) {
+ std::cout << s << " Error al conectar2 SALIDA" << std::endl;
+ } else {
+ std::cout << s << " SALIDA1 = " << (char *)XML_GET_CONTENT(conector1->children) << std::endl;
+ }
}
}
if (conector2 != NULL) {
}
}
if (conector2 != NULL) {
// bien, es a la entrada!, obtengo el item al cual lo tengo que conectar
to_connect = find((char *)XML_GET_CONTENT(conector2->children));
// y lo conecto
// bien, es a la entrada!, obtengo el item al cual lo tengo que conectar
to_connect = find((char *)XML_GET_CONTENT(conector2->children));
// y lo conecto
- current_item->connect(to_connect, IConector::IN);
+ if (!current_item->connect(to_connect, IConector::IN)) {
+ std::cout << s << " Error al conectar2 ENTRADA = " << (char *)XML_GET_CONTENT(conector2->children) << std::endl;
+ } else {
+ std::cout << s << " ENTRADA2 = " << (char *)XML_GET_CONTENT(conector2->children) << std::endl;
+ }
} else if (xmlStrcmp(conector2->name, BAD_CAST"salida") == 0) {
// Era a salida, es casi lo mismo que arriba
to_connect = find((char *)XML_GET_CONTENT(conector2->children));
} else if (xmlStrcmp(conector2->name, BAD_CAST"salida") == 0) {
// Era a salida, es casi lo mismo que arriba
to_connect = find((char *)XML_GET_CONTENT(conector2->children));
- current_item->connect(to_connect, IConector::OUT);
+ if (!current_item->connect(to_connect, IConector::OUT)) {
+ std::cout << s << " Error al conectar " << std::endl;
+ }
}
}
if (conector3 != NULL) {
}
}
if (conector3 != NULL) {
// bien, es a la entrada!, obtengo el item al cual lo tengo que conectar
to_connect = find((char *)XML_GET_CONTENT(conector3->children));
// y lo conecto
// bien, es a la entrada!, obtengo el item al cual lo tengo que conectar
to_connect = find((char *)XML_GET_CONTENT(conector3->children));
// y lo conecto
- current_item->connect(to_connect, IConector::IN);
+ if (!current_item->connect(to_connect, IConector::IN)) {
+ std::cout << s << " Error al conectar " << std::endl;
+ }
} else if (xmlStrcmp(conector3->name, BAD_CAST"salida") == 0) {
// Era a salida, es casi lo mismo que arriba
to_connect = find((char *)XML_GET_CONTENT(conector3->children));
} else if (xmlStrcmp(conector3->name, BAD_CAST"salida") == 0) {
// Era a salida, es casi lo mismo que arriba
to_connect = find((char *)XML_GET_CONTENT(conector3->children));
- current_item->connect(to_connect, IConector::OUT);
+ if (!current_item->connect(to_connect, IConector::OUT)) {
+ std::cout << s << " Error al conectar " << std::endl;
+ }
in_slots = 1;
out_slots = 2;
max_flow = actual_flow = 0.0f;
in_slots = 1;
out_slots = 2;
max_flow = actual_flow = 0.0f;
switch (msg) {
case MSG_QUERY_MAX_FLOW_OUT: {
switch (msg) {
case MSG_QUERY_MAX_FLOW_OUT: {
+ if (updated) {
+ who->recieve_msg(MSG_RESPONSE_MAX_FLOW, this, &actual_flow);
+ }
// Me preguntan por el flujo máximo.
// Primero me actualizo, y luego respondo
actual_flow = *((float *)data);
// Me preguntan por el flujo máximo.
// Primero me actualizo, y luego respondo
actual_flow = *((float *)data);
switch (msg) {
case MSG_QUERY_MAX_FLOW_OUT:
switch (msg) {
case MSG_QUERY_MAX_FLOW_OUT:
+ if (updated) {
+ who->recieve_msg(MSG_RESPONSE_MAX_FLOW, this, &actual_in_flow);
+ }
actual_in_flow = capacity - litros;
if (*((float *)data) < actual_in_flow)
actual_in_flow = *((float *)data);
actual_in_flow = capacity - litros;
if (*((float *)data) < actual_in_flow)
actual_in_flow = *((float *)data);
in_on_zero = 0;
in_ready = 0;
actual_flow = 999999;
in_on_zero = 0;
in_ready = 0;
actual_flow = 999999;
for(i=in_list.begin(); i!=in_list.end(); i++) {
if ((*i) == who) pos = IN;
}
for(i=in_list.begin(); i!=in_list.end(); i++) {
if ((*i) == who) pos = IN;
}
switch (msg) {
case MSG_QUERY_MAX_FLOW_OUT: {
// Me preguntan por el flujo máximo.
switch (msg) {
case MSG_QUERY_MAX_FLOW_OUT: {
// Me preguntan por el flujo máximo.
float m_data = *((float *)data)*2;
float tmp;
float m_data = *((float *)data)*2;
float tmp;
+ if (updated) {
+ who->recieve_msg(MSG_RESPONSE_MAX_FLOW, this, &actual_flow);
+ break;
+ }
+ updated = true;
if (m_data == 0) {
in_on_zero++;
tmp = 0.0f;
if (m_data == 0) {
in_on_zero++;
tmp = 0.0f;