class CItem;
typedef struct {
- CItem *logic, *store;
+ int logic_id, store_id;
}t_line;
class WorkPlace:public Gtk::Fixed {
void delete_item(int _id);
void delete_line(int _id);
CItem *get_logic_item(int _id);
+ CItem *get_item(int _id);
void update_logic_position();
std::list<CItem *> *listaItems, *lista_logic_Items;
/** Listas de lineas que van de una compuerta a la entrada de un item y de la salida de un item a una compuerta
bool And::on_button_press_event(GdkEventButton *event)
{
if ((event->type == GDK_BUTTON_PRESS) && ( event->button == 1)) {
- CItem::logic_connect = true;
- CItem::gate_id = ID;
+ if ( CItem::logic_connect ) {
+ CItem::gate_id = ID;
+ WorkPlace::pointed = ID;
+ }
combo_entry->set_text(name);
- WorkPlace::pointed = ID;
+
}
if ((event->type == GDK_BUTTON_PRESS) && ( event->button == 2)){
dato += c_img;
dato += c_x;
dato += c_y;
- for ( int i=0; i<=vec_connector.size()-1; i++) {
+ for ( int i=0; i<=vec_connector.size()-1&&!vec_connector.empty(); i++) {
if ( vec_connector[i].type == IN ) {
dato += "\t\t<entrada>";
dato += vec_connector[i].name_dest + "</entrada>\n";
t_logic_connector temp;
std::list<t_line>::iterator i = workplace->lista_lineas_in.begin();
while ( i != workplace->lista_lineas_in.end() ) {
- if ( (*i).logic->get_id() == ID ) {
+ if ( workplace->get_logic_item((*i).logic_id)->get_id() == ID ) {
temp.type = OUT;
- temp.name_dest = (*i).store->get_name();
+ temp.name_dest = workplace->get_item((*i).store_id)->get_name();
vec_connector.push_back(temp);
cant_out++;
}
i = workplace->lista_lineas_out.begin();
while ( i != workplace->lista_lineas_out.end() ) {
- if ( (*i).logic->get_id() == ID ) {
+ if ( workplace->get_logic_item((*i).logic_id)->get_id() == ID ) {
temp.type = IN;
- temp.name_dest = (*i).store->get_name();
+ temp.name_dest = workplace->get_item((*i).store_id)->get_name();
vec_connector.push_back(temp);
cant_in++;
}
if ((event->type == GDK_BUTTON_PRESS) && ( event->button == 1)) {
combo_entry->set_text(name);
WorkPlace::pointed = ID;
- if (CItem::logic_connect) {
+ if (CItem::logic_connect && CItem::gate_id != -1) {
if ( detect_click_position(event->x, event->y) == IN ){
- tmp_line.logic = workplace->get_logic_item(CItem::gate_id);
- tmp_line.store = this;
+ tmp_line.logic_id = workplace->get_logic_item(CItem::gate_id)->get_id();
+ tmp_line.store_id = ID;
workplace->lista_lineas_in.push_back(tmp_line);
workplace->queue_draw();
} else if (detect_click_position(event->x, event->y) == OUT) {
- tmp_line.logic = workplace->get_logic_item(CItem::gate_id);
- tmp_line.store = this;
+ tmp_line.logic_id = workplace->get_logic_item(CItem::gate_id)->get_id();
+ tmp_line.store_id = ID;
workplace->lista_lineas_out.push_back(tmp_line);
workplace->queue_draw();
}
cistern_pty_wnd->txt_cistern_name->set_text( name );
cistern_pty_wnd->show();
}
- CItem::logic_connect =false;
workplace->queue_draw();
return true;
}
if ((event->type == GDK_BUTTON_PRESS) && ( event->button == 1)) {
combo_entry->set_text(name);
WorkPlace::pointed = ID;
- if (CItem::logic_connect) {
+ if (CItem::logic_connect && CItem::gate_id != -1) {
if ( detect_click_position(event->x, event->y) == IN) {
- tmp_line.logic = workplace->get_logic_item(CItem::gate_id);
- tmp_line.store = this;
+ tmp_line.logic_id = workplace->get_logic_item(CItem::gate_id)->get_id();
+ tmp_line.store_id = ID;
workplace->lista_lineas_in.push_back(tmp_line);
workplace->queue_draw();
} else if (detect_click_position(event->x, event->y) == OUT) {
- tmp_line.logic = workplace->get_logic_item(CItem::gate_id);
- tmp_line.store = this;
+ tmp_line.logic_id = workplace->get_logic_item(CItem::gate_id)->get_id();
+ tmp_line.store_id = ID;
workplace->lista_lineas_out.push_back(tmp_line);
workplace->queue_draw();
}
if (estado) exclusa_pty_wnd->rd_btn_open->set_active(true);
exclusa_pty_wnd->show();
}
- CItem::logic_connect =false;
workplace->queue_draw();
return true;
}
{
if ((event->type == GDK_BUTTON_PRESS) && ( event->button == 1)) {
- CItem::logic_connect = true;
- CItem::gate_id = ID;
+ if ( CItem::logic_connect ) {
+ CItem::gate_id = ID;
+ WorkPlace::pointed = ID;
+ }
combo_entry->set_text(name);
- WorkPlace::pointed = ID;
}
if ((event->type == GDK_BUTTON_PRESS) && ( event->button == 2)){
dato += c_img;
dato += c_x;
dato += c_y;
- for ( int i=0; i<=vec_connector.size()-1; i++) {
+ for ( int i=0; i<=vec_connector.size()-1&&!vec_connector.empty(); i++) {
if ( vec_connector[i].type == IN ) {
dato += "\t\t<entrada>";
dato += vec_connector[i].name_dest + "</entrada>\n";
t_logic_connector temp;
std::list<t_line>::iterator i = workplace->lista_lineas_in.begin();
while ( i != workplace->lista_lineas_in.end() ) {
- if ( (*i).logic->get_id() == ID ) {
+ if ( workplace->get_logic_item((*i).logic_id)->get_id() == ID ) {
temp.type = OUT;
- temp.name_dest = (*i).store->get_name();
+ temp.name_dest = workplace->get_item((*i).store_id)->get_name();
vec_connector.push_back(temp);
cant_out++;
}
i = workplace->lista_lineas_out.begin();
while ( i != workplace->lista_lineas_out.end() ) {
- if ( (*i).logic->get_id() == ID ) {
+ if (workplace->get_logic_item((*i).logic_id)->get_id() == ID ) {
temp.type = IN;
- temp.name_dest = (*i).store->get_name();
+ temp.name_dest = workplace->get_item((*i).store_id)->get_name();
vec_connector.push_back(temp);
cant_in++;
}
bool Or::on_button_press_event(GdkEventButton *event)
{
if ((event->type == GDK_BUTTON_PRESS) && ( event->button == 1)) {
- CItem::logic_connect = true;
- CItem::gate_id = ID;
+ if ( CItem::logic_connect ) {
+ CItem::gate_id = ID;
+ WorkPlace::pointed = ID;
+ }
combo_entry->set_text(name);
- WorkPlace::pointed = ID;
}
if ((event->type == GDK_BUTTON_PRESS) && ( event->button == 2)){
dato += c_img;
dato += c_x;
dato += c_y;
- for ( int i=0; i<=vec_connector.size()-1; i++) {
+ for ( int i=0; i<=vec_connector.size()-1&&!vec_connector.empty(); i++) {
if ( vec_connector[i].type == IN ) {
dato += "\t\t<entrada>";
dato += vec_connector[i].name_dest + "</entrada>\n";
t_logic_connector temp;
std::list<t_line>::iterator i = workplace->lista_lineas_in.begin();
while ( i != workplace->lista_lineas_in.end() ) {
- if ( (*i).logic->get_id() == ID ) {
+ if ( workplace->get_logic_item((*i).logic_id)->get_id() == ID ) {
temp.type = OUT;
- temp.name_dest = (*i).store->get_name();
+ temp.name_dest = workplace->get_item((*i).store_id)->get_name();
vec_connector.push_back(temp);
cant_out++;
}
i = workplace->lista_lineas_out.begin();
while ( i != workplace->lista_lineas_out.end() ) {
- if ( (*i).logic->get_id() == ID ) {
+ if ( workplace->get_logic_item((*i).logic_id)->get_id() == ID ) {
temp.type = IN;
- temp.name_dest = (*i).store->get_name();
+ temp.name_dest = workplace->get_item((*i).store_id)->get_name();
vec_connector.push_back(temp);
cant_in++;
}
if ((event->type == GDK_BUTTON_PRESS) && ( event->button == 1)) {
combo_entry->set_text(name);
WorkPlace::pointed = ID;
- if (CItem::logic_connect) {
+ if (CItem::logic_connect && CItem::gate_id != -1) {
if ( detect_click_position(event->x, event->y) == IN) {
- tmp_line.logic = workplace->get_logic_item(CItem::gate_id);
- tmp_line.store = this;
+ tmp_line.logic_id = workplace->get_logic_item(CItem::gate_id)->get_id();
+ tmp_line.store_id = ID;
workplace->lista_lineas_in.push_back(tmp_line);
workplace->queue_draw();
} else if (detect_click_position(event->x, event->y) == OUT) {
- tmp_line.logic = workplace->get_logic_item(CItem::gate_id);
- tmp_line.store = this;
+ tmp_line.logic_id = workplace->get_logic_item(CItem::gate_id)->get_id();
+ tmp_line.store_id = ID;
workplace->lista_lineas_out.push_back(tmp_line);
workplace->queue_draw();
}
pump_pty_wnd->txt_pump_name->set_text( name );
pump_pty_wnd->show();
}
- CItem::logic_connect =false;
workplace->queue_draw();
return true;
}
get_window()->draw_point (get_style()->get_black_gc(), x-1,y);
}
-
Glib::RefPtr<Gdk::GC> gc = get_style()->get_black_gc();
Gdk::Color color;
color.set_rgb(255,0,0);
std::list<t_line>::iterator i = lista_lineas_in.begin();
while ( i != lista_lineas_in.end() ) {
t_line temp = *i;
- temp.store->get_in_logic_connect_position(w,z);
- temp.logic->get_out_logic_connect_position(a, b);
- get_window()->draw_line (get_style()->get_black_gc(), a, b, w,z);
+ 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);
+ get_logic_item(temp.logic_id)->get_out_logic_connect_position(a, b);
+ get_window()->draw_line (get_style()->get_black_gc(), a, b, w,z);
+ }
i++;
}
i = lista_lineas_out.begin();
while ( i != lista_lineas_out.end() ) {
t_line temp = *i;
- temp.store->get_out_logic_connect_position(w,z);
- temp.logic->get_in_logic_connect_position(a, b);
- get_window()->draw_line (get_style()->get_black_gc(), a, b, w, z);
+ if ( get_item(temp.store_id) != NULL && get_logic_item(temp.logic_id) != NULL ) {
+ 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_window()->draw_line (get_style()->get_black_gc(), a, b, w, z);
+ }
i++;
}
-
return true;
}
void WorkPlace::delete_item(int _id)
{
+ delete_line(_id);
CItem::logic_connect = false;
std::list<CItem*>::iterator i = listaItems->begin();
while ( i != listaItems->end() ){
CItem *temp = *i;
if ( temp->get_id() == _id ){
- delete_line(_id);
+// delete_line(_id);
listaItems->erase(i);
delete temp;
break;
while ( i != lista_logic_Items->end() ){
CItem *temp = *i;
if ( temp->get_id() == _id ){
- delete_line(_id);
+// delete_line(_id);
lista_logic_Items->erase(i);
delete temp;
break;
}
i++;
}
-
+ CItem::gate_id = -1;
}
CItem* WorkPlace::get_logic_item(int _id)
{
std::list<CItem *>::iterator i = lista_logic_Items->begin();
while ( i != lista_logic_Items->end() ){
- CItem *temp = *i;
- if ( temp->get_id() == _id )
- return temp;
+ if ( (*i)->get_id() == _id )
+ return *i;
+ i++;
+ }
+ return NULL;
+}
+
+CItem *WorkPlace::get_item(int _id)
+{
+ std::list<CItem *>::iterator i = listaItems->begin();
+ while ( i != listaItems->end() ){
+ if ( (*i)->get_id() == _id )
+ return *i;
i++;
}
return NULL;
}
+
void WorkPlace::delete_line(int _id)
{
std::list<t_line>::iterator i = lista_lineas_in.begin();
while ( i != lista_lineas_in.end() ){
- if ( (*i).store->get_id() == _id ) {
- lista_lineas_in.erase(i);
- i = lista_lineas_in.begin();
- }
+ if (get_item( (*i).store_id ) != NULL)
+ if ( get_item( (*i).store_id )->get_id() == _id ) {
+ lista_lineas_in.erase(i);
+ i = lista_lineas_in.begin();
+ }
i++;
}
i = lista_lineas_in.begin();
while ( i != lista_lineas_in.end() ){
- if ( (*i).logic->get_id() == _id ) {
- lista_lineas_in.erase(i);
- i = lista_lineas_in.begin();
- }
+ if ( get_logic_item((*i).logic_id) != NULL)
+ if ( get_logic_item((*i).logic_id)->get_id() == _id) {
+ lista_lineas_in.erase(i);
+ i = lista_lineas_in.begin();
+ }
i++;
}
- i = lista_lineas_out.begin();
- while ( i != lista_lineas_out.end() ){
- if ( (*i).store->get_id() == _id ) {
- lista_lineas_out.erase(i);
- i = lista_lineas_out.begin();
- }
- i++;
- }
- i = lista_lineas_out.begin();
- while ( i != lista_lineas_out.end() ){
- if ( (*i).logic->get_id() == _id ) {
- lista_lineas_out.erase(i);
- i = lista_lineas_out.begin();
- }
- i++;
+ std::list<t_line>::iterator j = lista_lineas_out.begin();
+ while ( j != lista_lineas_out.end() ){
+ if ( get_item((*j).store_id) != NULL )
+ if ( get_item((*j).store_id)->get_id() == _id ) {
+ lista_lineas_out.erase(j);
+ j = lista_lineas_out.begin();
+ }
+ j++;
}
+ j = lista_lineas_out.begin();
+ while ( j != lista_lineas_out.end() ){
+ if ( get_logic_item((*j).logic_id) != NULL )
+ if ( get_logic_item((*j).logic_id)->get_id() == _id ) {
+ lista_lineas_out.erase(j);
+ j = lista_lineas_out.begin();
+ }
+ j++;
+ }
}
void WorkPlace::update_logic_position()