From: Nicolás Dimov Date: Mon, 17 Nov 2003 16:39:49 +0000 (+0000) Subject: - Se actualiza la funcion save() de todos los item X-Git-Tag: svn_import~277 X-Git-Url: https://git.llucax.com/z.facultad/75.42/plaqui.git/commitdiff_plain/789188ab0bf658fdf35c99e7bd2cfabab41091f2?ds=sidebyside - Se actualiza la funcion save() de todos los item - 2 bombas, una union y un drenaje se conectan bien --- diff --git a/Constructor/cistern.cpp b/Constructor/cistern.cpp index fd49a6e..198d940 100644 --- a/Constructor/cistern.cpp +++ b/Constructor/cistern.cpp @@ -112,6 +112,16 @@ Gdk::Color Cistern::get_liquid_color() void Cistern::save(FILE *archivo) { char c_id[50], c_cap[50], c_x[50], c_y[50], c_img[50], c_ini[50], c_red[50], c_green[50], c_blue[50]; + Glib::ustring con0, con1; + if (connect_vec[0].type == IN) + con0 = "\t\t\t"+get_other_name(connect_vec[0].id_dest)+"\n"; + else + con0 = "\t\t\t"+get_other_name(connect_vec[0].id_dest)+"\n"; + if (connect_vec[1].type == IN) + con1 = "\t\t\t"+get_other_name(connect_vec[1].id_dest)+"\n"; + else + con1 = "\t\t\t"+get_other_name(connect_vec[1].id_dest)+"\n"; + sprintf(c_red,"\t\t\t%d\n",liquid_color.get_red()); sprintf(c_green,"\t\t\t%d\n",liquid_color.get_green()); sprintf(c_blue,"\t\t\t%d\n",liquid_color.get_blue()); @@ -127,11 +137,12 @@ void Cistern::save(FILE *archivo) dato += "\">\n"; dato += c_cap; dato += c_ini; - dato += "\t\n"; + dato += "\t\t\n"; dato += c_red; dato += c_green; dato += c_blue; - dato += "\t\n"; + dato += "\t\t\n"; + dato += "\t\t\n"+con0+con1+"\t\t\n"; dato += c_img; dato += c_x; dato += c_y; @@ -141,18 +152,22 @@ void Cistern::save(FILE *archivo) bool Cistern::check_connection() { + CItem * _item, *_item1; ConnectorType temp0, temp1; switch (get_img_actual()) { case 0: - temp0 = is_other_connection_area( get_position_x()+get_image()->get_width() + 5 , get_position_y()+get_image()->get_height() -16); - temp1 = is_other_connection_area( get_position_x() + 16, get_position_y() - 5); + temp0 = is_other_connection_area( get_position_x()+get_image()->get_width() + 5 , get_position_y()+get_image()->get_height() -16, &_item); + temp1 = is_other_connection_area( get_position_x() + 16, get_position_y() - 5, &_item1); break; case 1: - temp0 = is_other_connection_area( get_position_x() -5, get_position_y()+get_image()->get_height()-16); - temp1 = is_other_connection_area( get_position_x()+get_image()->get_width() - 16, get_position_y() - 5); + temp0 = is_other_connection_area( get_position_x() -5, get_position_y()+get_image()->get_height()-16, &_item); + temp1 = is_other_connection_area( get_position_x()+get_image()->get_width() - 16, get_position_y() - 5, &_item1); } - if (temp0 == OUT && temp1 == IN) + if (temp0 == OUT && temp1 == IN) { + connect_vec[0].id_dest = _item->get_id(); + connect_vec[1].id_dest = _item1->get_id(); return (is_connected = true); + } return is_connected; } diff --git a/Constructor/conduct.cpp b/Constructor/conduct.cpp index 1e5bde3..b286e68 100644 --- a/Constructor/conduct.cpp +++ b/Constructor/conduct.cpp @@ -75,6 +75,15 @@ void Conduct::on_menu_popup_propiedades() void Conduct::save(FILE *archivo) { char c_id[50], c_caudal[50], c_x[50], c_y[50], c_img[50]; + Glib::ustring con0, con1; + if (connect_vec[0].type == IN) + con0 = "\t\t\t"+get_other_name(connect_vec[0].id_dest)+"\n"; + else + con0 = "\t\t\t"+get_other_name(connect_vec[0].id_dest)+"\n"; + if (connect_vec[1].type == IN) + con1 = "\t\t\t"+get_other_name(connect_vec[1].id_dest)+"\n"; + else + con1 = "\t\t\t"+get_other_name(connect_vec[1].id_dest)+"\n"; sprintf(c_x,"\t\t%d\n",x); sprintf(c_y,"\t\t%d\n",y); sprintf(c_id,"%d",ID); @@ -85,6 +94,7 @@ void Conduct::save(FILE *archivo) dato += c_id; dato += "\">\n"; dato += c_caudal; + dato += "\t\t\n"+con0 + con1+"\t\t\n"; dato += c_img; dato += c_x; dato += c_y; @@ -94,35 +104,40 @@ void Conduct::save(FILE *archivo) bool Conduct::check_connection() { + CItem *_item0, *_item1; switch (get_img_actual()) { case 0: - connect_vec[0].type = is_other_connection_area( get_position_x()+16, get_position_y()-5); - connect_vec[1].type = is_other_connection_area( get_position_x()+16, get_position_y()+get_image()->get_height() +5); + connect_vec[0].type = is_other_connection_area( get_position_x()+16, get_position_y()-5, &_item0); + connect_vec[1].type = is_other_connection_area( get_position_x()+16, get_position_y()+get_image()->get_height() +5,& _item1); break; case 1: - connect_vec[0].type = is_other_connection_area( get_position_x()-5, get_position_y()+16); - connect_vec[1].type = is_other_connection_area( get_position_x()+get_image()->get_width()+5, get_position_y()+16); + connect_vec[0].type = is_other_connection_area( get_position_x()-5, get_position_y()+16, &_item0); + connect_vec[1].type = is_other_connection_area( get_position_x()+get_image()->get_width()+5, get_position_y()+16, &_item1); } - if ( connect_vec[0].type != UNDEF && connect_vec[1].type != UNDEF ) + if ( connect_vec[0].type != UNDEF && connect_vec[1].type != UNDEF ) { + connect_vec[0].id_dest = _item0->get_id(); + connect_vec[1].id_dest = _item1->get_id(); return ( is_connected = (connect_vec[0].type != connect_vec[1].type) ); - else return false; + } + else return is_connected; } ConnectorType Conduct::get_connector_type(int _a, int _b) -{ +{ + CItem *_item; if ( ! is_connected ) { switch (imgActual) { case 0: if ( (_a <= x+image->get_width()-10 )&&(_a >= x + 10) && (_b <= y+10) &&(_b > 0 ) ) //arriba - return is_other_connection_area(get_position_x()+16, get_position_y()+get_image()->get_height() +5); //pregunto que hay abajo + return is_other_connection_area(get_position_x()+16, get_position_y()+get_image()->get_height() +5, &_item); //pregunto que hay abajo if ((_a <= x+22 )&&(_a >= x + 10) && (_b <= y+image->get_height()-1) &&(_b >= y+image->get_height()-10 ))//abajo - return is_other_connection_area( get_position_x()+16, get_position_y()-5);//pregunto que hay arriba. + return is_other_connection_area( get_position_x()+16, get_position_y()-5,& _item);//pregunto que hay arriba. break; case 1: if ((_a <= x+10 )&&(_a > 0) && (_b <= y+image->get_height()-10) &&(_b >= y+10 )) //izquierda - return is_other_connection_area(get_position_x()+get_image()->get_width()+5, get_position_y()+16);//pregunto por la derecha + return is_other_connection_area(get_position_x()+get_image()->get_width()+5, get_position_y()+16, &_item);//pregunto por la derecha if ((_a <= x+image->get_width()-1)&&(_a >= x+image->get_width()-10) && (_b <= y+image->get_height()-10) &&(_b >= y +10 )) //derecha - return is_other_connection_area(get_position_x()-5, get_position_y()+16); //pregunto por la izquierda. + return is_other_connection_area(get_position_x()-5, get_position_y()+16, &_item); //pregunto por la izquierda. } } else { switch (imgActual) { diff --git a/Constructor/constructor.cpp b/Constructor/constructor.cpp index aa162e9..4b26ee4 100644 --- a/Constructor/constructor.cpp +++ b/Constructor/constructor.cpp @@ -272,11 +272,6 @@ void Constructor::on_not_drag_begin(const Glib::RefPtr& contex void Constructor::on_item_drag_begin(const Glib::RefPtr& context, CItem *item) { context->set_icon(item->get_image(), 5, 5); - std::list::iterator i = listaItems.begin(); - while ( i != listaItems.end() ){ - (*i)->set_default_connector(); - i++; - } } void Constructor::on_item_drag_data_get(const Glib::RefPtr& context, GtkSelectionData* selection_data, guint info, guint time) @@ -382,6 +377,13 @@ void Constructor::on_item_drop_drag_received(const Glib::RefPtr::iterator i = listaItems.begin(); + while ( i != listaItems.end() ){ + (*i)->set_default_connector(); + (*i)->is_connected = false; + i++; + } + + i = listaItems.begin(); if ( !listaItems.empty() ) { while ( i != listaItems.end() ) { CItem *temp = *i; diff --git a/Constructor/drain.cpp b/Constructor/drain.cpp index cd4ee57..76f15a2 100644 --- a/Constructor/drain.cpp +++ b/Constructor/drain.cpp @@ -83,6 +83,8 @@ void Drain::on_menu_popup_propiedades() void Drain::save(FILE *archivo) { char c_id[50], c_x[50], c_y[50], c_img[50]; + Glib::ustring con0; + con0 = "\t\t\t"+get_other_name(connect_vec[0].id_dest)+"\n"; sprintf(c_x,"\t\t%d\n",x); sprintf(c_y,"\t\t%d\n",y); sprintf(c_id,"%d",ID); @@ -91,6 +93,7 @@ void Drain::save(FILE *archivo) dato = "\t\n"; + dato += "\t\t\n"+con0+"\t\t\n"; dato += c_img; dato += c_x; dato += c_y; @@ -100,21 +103,26 @@ void Drain::save(FILE *archivo) bool Drain::check_connection() { + CItem *_item0; ConnectorType temp; switch (get_img_actual()) { case 0: - temp = is_other_connection_area( get_position_x()+16 , get_position_y() -5); + temp = is_other_connection_area( get_position_x()+16 , get_position_y() -5,& _item0); break; case 1: - temp = is_other_connection_area( get_position_x()+image->get_width() + 5, get_position_y()+16); + temp = is_other_connection_area( get_position_x()+image->get_width() + 5, get_position_y()+16,& _item0); break; case 2: - temp = is_other_connection_area( get_position_x()+16, get_position_y()+image->get_height()+5); + temp = is_other_connection_area( get_position_x()+16, get_position_y()+image->get_height()+5, &_item0); break; case 3: - temp = is_other_connection_area( get_position_x()-5, get_position_y()+16); + temp = is_other_connection_area( get_position_x()-5, get_position_y()+16,& _item0); } - return ( is_connected = (temp == OUT) ); + if ( is_connected = (temp == OUT) ) { + connect_vec[0].id_dest = _item0->get_id(); + return is_connected; + } + return is_connected; } ConnectorType Drain::get_connector_type(int _a, int _b) diff --git a/Constructor/exclusa.cpp b/Constructor/exclusa.cpp index b759ea7..4035ad7 100644 --- a/Constructor/exclusa.cpp +++ b/Constructor/exclusa.cpp @@ -91,6 +91,15 @@ void Exclusa::save(FILE *archivo) { char c_id[50], c_est[50], c_x[50], c_y[50], c_img[50]; int est; + Glib::ustring con0, con1; + if (connect_vec[0].type == IN) + con0 = "\t\t\t"+get_other_name(connect_vec[0].id_dest)+"\n"; + else + con0 = "\t\t\t"+get_other_name(connect_vec[0].id_dest)+"\n"; + if (connect_vec[1].type == IN) + con1 = "\t\t\t"+get_other_name(connect_vec[1].id_dest)+"\n"; + else + con1 = "\t\t\t"+get_other_name(connect_vec[1].id_dest)+"\n"; sprintf(c_x,"\t\t%d\n",x); sprintf(c_y,"\t\t%d\n",y); sprintf(c_id,"%d",ID); @@ -102,6 +111,7 @@ void Exclusa::save(FILE *archivo) dato = "\t\n"; + dato += "\t\t\n"+con0 + con1+"\t\t\n"; dato += c_img; dato += c_est; dato += c_x; @@ -112,35 +122,40 @@ void Exclusa::save(FILE *archivo) bool Exclusa::check_connection() { + CItem *_item0, *_item1; switch (get_img_actual()) { case 0: - connect_vec[0].type = is_other_connection_area( get_position_x()+16, get_position_y()-5); - connect_vec[1].type = is_other_connection_area( get_position_x()+16, get_position_y()+get_image()->get_height() +5); + connect_vec[0].type = is_other_connection_area( get_position_x()+16, get_position_y()-5, &_item0); + connect_vec[1].type = is_other_connection_area( get_position_x()+16, get_position_y()+get_image()->get_height() +5, &_item1); break; case 1: - connect_vec[0].type = is_other_connection_area( get_position_x()-5, get_position_y()+16); - connect_vec[1].type = is_other_connection_area( get_position_x()+get_image()->get_width()+5, get_position_y()+16); + connect_vec[0].type = is_other_connection_area( get_position_x()-5, get_position_y()+16, &_item0); + connect_vec[1].type = is_other_connection_area( get_position_x()+get_image()->get_width()+5, get_position_y()+16,& _item1); } - if ( connect_vec[0].type != UNDEF && connect_vec[1].type != UNDEF ) + if ( connect_vec[0].type != UNDEF && connect_vec[1].type != UNDEF ) { + connect_vec[0].id_dest = _item0->get_id(); + connect_vec[1].id_dest = _item1->get_id(); return ( is_connected = (connect_vec[0].type != connect_vec[1].type) ); - else return false; + } + else return is_connected; } ConnectorType Exclusa::get_connector_type(int _a, int _b) { + CItem * _item; if ( ! is_connected ) { switch (imgActual) { case 0: if ( (_a <= x+image->get_width()-10 )&&(_a >= x + 10) && (_b <= y+10) &&(_b > 0 ) ) //arriba - return is_other_connection_area(get_position_x()+16, get_position_y()+get_image()->get_height() +5); //pregunto que hay abajo + return is_other_connection_area(get_position_x()+16, get_position_y()+get_image()->get_height() +5, &_item); //pregunto que hay abajo if ((_a <= x+22 )&&(_a >= x + 10) && (_b <= y+image->get_height()-1) &&(_b >= y+image->get_height()-10 ))//abajo - return is_other_connection_area( get_position_x()+16, get_position_y()-5);//pregunto que hay arriba. + return is_other_connection_area( get_position_x()+16, get_position_y()-5, &_item);//pregunto que hay arriba. break; case 1: if ((_a <= x+10 )&&(_a > 0) && (_b <= y+image->get_height()-10) &&(_b >= y+10 )) //izquierda - return is_other_connection_area(get_position_x()+get_image()->get_width()+5, get_position_y()+16);//pregunto por la derecha + return is_other_connection_area(get_position_x()+get_image()->get_width()+5, get_position_y()+16, &_item);//pregunto por la derecha if ((_a <= x+image->get_width()-1)&&(_a >= x+image->get_width()-10) && (_b <= y+image->get_height()-10) &&(_b >= y +10 )) //derecha - return is_other_connection_area(get_position_x()-5, get_position_y()+16); //pregunto por la izquierda. + return is_other_connection_area(get_position_x()-5, get_position_y()+16, &_item); //pregunto por la izquierda. } } else { switch (imgActual) { diff --git a/Constructor/item.cpp b/Constructor/item.cpp index de9c4cd..4bec05d 100644 --- a/Constructor/item.cpp +++ b/Constructor/item.cpp @@ -87,6 +87,17 @@ Glib::ustring CItem::get_name() return name; } +Glib::ustring CItem::get_other_name(int _id) +{ + std::list::iterator i = listaItems->begin(); + while ( i != listaItems->end() ) { + if ( (*i)->get_id() == _id ) + return (*i)->get_name(); + i++; + } + return name; +} + int CItem::get_img_actual() { return imgActual; @@ -120,15 +131,17 @@ bool CItem::is_occupied_area(int _a, int _b) else return false; } -ConnectorType CItem::is_other_connection_area(int _a, int _b) +ConnectorType CItem::is_other_connection_area(int _a, int _b, CItem **_item) { ConnectorType temp2; std::list::iterator i = listaItems->begin(); while ( i != listaItems->end() ) { CItem *temp = *i; if (temp != this) - if ( (temp2 = temp->get_connector_type(_a,_b)) != UNDEF ) + if ( (temp2 = temp->get_connector_type(_a,_b)) != UNDEF ) { + *_item = temp; return temp2; + } i++; } return UNDEF; diff --git a/Constructor/item.h b/Constructor/item.h index 10070b8..64c5049 100644 --- a/Constructor/item.h +++ b/Constructor/item.h @@ -42,14 +42,15 @@ public: int get_position_y(); int get_id(); int get_img_actual(); - Glib::ustring get_name(); double get_caudal(); + Glib::ustring get_name(); + Glib::ustring get_other_name(int _id); void set_position(int _x, int _y); void set_id(int _id); void set_caudal(double _caudal); void set_name(Glib::ustring _name); bool is_occupied_area(int _a, int _b); - ConnectorType is_other_connection_area(int _a, int _b); + ConnectorType is_other_connection_area(int _a, int _b, CItem ** _item); virtual void save(FILE *archivo) = 0; virtual bool check_connection()=0; virtual void set_default_connector(); diff --git a/Constructor/itemptywnd.cpp b/Constructor/itemptywnd.cpp index 7810e7c..b550ba5 100644 --- a/Constructor/itemptywnd.cpp +++ b/Constructor/itemptywnd.cpp @@ -37,16 +37,30 @@ void ItemPtyWnd::on_btn_cancel_clicked() void ItemPtyWnd::on_rd_btn_union_clicked() { + Glib::ustring name; + char char_id[10]; + sprintf(char_id,"%d",item->get_id()); + name = "union"; + name += char_id; item->connect_vec[0].type = IN; item->connect_vec[1].type = IN; item->connect_vec[2].type = OUT; + item->set_name(name); + txt_item_name->set_text( item->get_name() ); item->is_union = true; } void ItemPtyWnd::on_rd_btn_division_clicked() { + Glib::ustring name; + char char_id[10]; + sprintf(char_id,"%d",item->get_id()); + name = "division"; + name += char_id; item->connect_vec[0].type = OUT; item->connect_vec[1].type = OUT; item->connect_vec[2].type = IN; + item->set_name(name); + txt_item_name->set_text( item->get_name() ); item->is_union = false; } diff --git a/Constructor/pump.cpp b/Constructor/pump.cpp index 515dc90..b26cda1 100644 --- a/Constructor/pump.cpp +++ b/Constructor/pump.cpp @@ -98,6 +98,9 @@ Gdk::Color Pump::get_liquid_color() void Pump::save(FILE *archivo) { char c_id[50], c_entrega[50], c_x[50], c_y[50], c_img[50], c_red[50], c_green[50], c_blue[50]; + Glib::ustring con0; + + con0 = "\t\t\t"+get_other_name(connect_vec[0].id_dest)+"\n"; sprintf(c_red,"\t\t\t%d\n",liquid_color.get_red()); sprintf(c_green,"\t\t\t%d\n",liquid_color.get_green()); sprintf(c_blue,"\t\t\t%d\n",liquid_color.get_blue()); @@ -111,11 +114,12 @@ void Pump::save(FILE *archivo) dato += c_id; dato += "\">\n"; dato += c_entrega; - dato += "\t\n"; + dato += "\t\t\n"; dato += c_red; dato += c_green; dato += c_blue; - dato += "\t\n"; + dato += "\t\t\n"; + dato += "\t\t\n"+con0+"\t\t\n"; dato += c_img; dato += c_x; dato += c_y; @@ -125,15 +129,20 @@ void Pump::save(FILE *archivo) bool Pump::check_connection() { + CItem * _item; ConnectorType temp; switch (get_img_actual()) { case 0: - temp = is_other_connection_area( get_position_x()+get_image()->get_width()+5 , get_position_y() +16); + temp = is_other_connection_area( get_position_x()+get_image()->get_width()+5 , get_position_y() +16,& _item); break; case 1: - temp = is_other_connection_area( get_position_x() -5, get_position_y() +16); + temp = is_other_connection_area( get_position_x() -5, get_position_y() +16, &_item); } - return (is_connected = ( temp == IN) ); + if (is_connected = ( temp == IN) ) { + connect_vec[0].id_dest = _item->get_id(); + return is_connected; + } + return is_connected; } ConnectorType Pump::get_connector_type(int _a, int _b) diff --git a/Constructor/splitter.cpp b/Constructor/splitter.cpp index 4804849..32b3280 100644 --- a/Constructor/splitter.cpp +++ b/Constructor/splitter.cpp @@ -80,6 +80,15 @@ void Splitter::on_menu_popup_propiedades() void Splitter::save(FILE *archivo) { char c_id[50], c_caudal[50], c_x[50], c_y[50], c_img[50]; + Glib::ustring con0, con1; + if (connect_vec[0].type == IN) + con0 = "\t\t\t"+get_other_name(connect_vec[0].id_dest)+"\n"; + else + con0 = "\t\t\t"+get_other_name(connect_vec[0].id_dest)+"\n"; + if (connect_vec[1].type == IN) + con1 = "\t\t\t"+get_other_name(connect_vec[1].id_dest)+"\n"; + else + con1 = "\t\t\t"+get_other_name(connect_vec[1].id_dest)+"\n"; sprintf(c_x,"\t\t%d\n",x); sprintf(c_y,"\t\t%d\n",y); sprintf(c_id,"%d",ID); @@ -90,6 +99,7 @@ void Splitter::save(FILE *archivo) dato += c_id; dato += "\">\n"; dato += c_caudal; + dato += "\t\t\n"+con0 + con1+"\t\t\n"; dato += c_img; dato += c_x; dato += c_y; @@ -99,55 +109,60 @@ void Splitter::save(FILE *archivo) bool Splitter::check_connection() { + CItem *_item0, *_item1; switch (get_img_actual()) { case 0: - connect_vec[0].type = is_other_connection_area( get_position_x()-5, get_position_y()+16); //arriba-izquierda h - connect_vec[1].type = is_other_connection_area( get_position_x()+get_image()->get_width()-16, +get_position_y()+get_image()->get_height() + 5);//abajo-derecha v + connect_vec[0].type = is_other_connection_area( get_position_x()-5, get_position_y()+16, &_item0); //arriba-izquierda h + connect_vec[1].type = is_other_connection_area( get_position_x()+get_image()->get_width()-16, +get_position_y()+get_image()->get_height() + 5, &_item1);//abajo-derecha v break; case 1: - connect_vec[0].type = is_other_connection_area( get_position_x()+get_image()->get_width() - 16, get_position_y() -5);//arriba-derecha v - connect_vec[1].type = is_other_connection_area( get_position_x()-5, get_position_y()+get_image()->get_height()-16);//abajo-izquierda h + connect_vec[0].type = is_other_connection_area( get_position_x()+get_image()->get_width() - 16, get_position_y() -5,& _item0);//arriba-derecha v + connect_vec[1].type = is_other_connection_area( get_position_x()-5, get_position_y()+get_image()->get_height()-16, &_item1);//abajo-izquierda h break; case 2: - connect_vec[1].type = is_other_connection_area( get_position_x() + 16, get_position_y() - 5);//arriba-izquierda v - connect_vec[0].type = is_other_connection_area( get_position_x()+get_image()->get_width()+5, get_position_y()+get_image()->get_height() - 16); //abajo-derecha h + connect_vec[1].type = is_other_connection_area( get_position_x() + 16, get_position_y() - 5, &_item1);//arriba-izquierda v + connect_vec[0].type = is_other_connection_area( get_position_x()+get_image()->get_width()+5, get_position_y()+get_image()->get_height() - 16, &_item0); //abajo-derecha h break; case 3: - connect_vec[1].type = is_other_connection_area( get_position_x()+get_image()->get_width()+5, get_position_y() +16);//arriba-derecha h - connect_vec[0].type = is_other_connection_area( get_position_x() + 16, get_position_y()+get_image()->get_height() + 5); //abajo-izquierda v + connect_vec[1].type = is_other_connection_area( get_position_x()+get_image()->get_width()+5, get_position_y() +16,& _item1);//arriba-derecha h + connect_vec[0].type = is_other_connection_area( get_position_x() + 16, get_position_y()+get_image()->get_height() + 5, &_item0); //abajo-izquierda v } - if (connect_vec[0].type != UNDEF && connect_vec[1].type != UNDEF) + if (connect_vec[0].type != UNDEF && connect_vec[1].type != UNDEF) { + connect_vec[0].id_dest = _item0->get_id(); + connect_vec[1].id_dest = _item1->get_id(); return ( is_connected = (connect_vec[0].type == connect_vec[1].type) ); - else return false; + } + else return is_connected; } ConnectorType Splitter::get_connector_type(int _a, int _b) { + CItem *_item; if ( ! is_connected ) { switch (imgActual) { case 0: if ( (_a <= x+10)&&(_a > x) && (_b <=y+22)&&(_b>=y+10) ) // arriba - izquierda h - return is_other_connection_area (get_position_x()+get_image()->get_width()-16, +get_position_y()+get_image()->get_height() + 5); + return is_other_connection_area (get_position_x()+get_image()->get_width()-16, +get_position_y()+get_image()->get_height() + 5, &_item); if ( (_a <= x+image->get_width()-10)&&(_a>=x+image->get_width()-22)&&(_b<=y+image->get_height()-1)&&(_b>=y+image->get_height()-10) )//abajo-derecha v - return is_other_connection_area( get_position_x()-5, get_position_y()+16); + return is_other_connection_area( get_position_x()-5, get_position_y()+16,& _item); break; case 1: if ( (_a <= x+image->get_width()-10)&&(_a >= x+image->get_width()-22) && (_b <=y+10)&&(_b > y) ) //arriba-derecha v - return is_other_connection_area( get_position_x()-5, get_position_y()+get_image()->get_height()-16); + return is_other_connection_area( get_position_x()-5, get_position_y()+get_image()->get_height()-16, &_item); if ( (_a <= x+10)&&(_a > x)&&(_b<=y+image->get_height()-10)&&(_b>=y+image->get_height()-22) ) // abajo-izquierda h - return is_other_connection_area( get_position_x()+get_image()->get_width() - 16, get_position_y() -5); + return is_other_connection_area( get_position_x()+get_image()->get_width() - 16, get_position_y() -5, &_item); break; case 2: if ( (_a <= x+22)&&(_a >= x+10) && (_b <=y+10)&&(_b > y) ) //arriba-izquierda v - return is_other_connection_area( get_position_x()+get_image()->get_width()+5, get_position_y()+get_image()->get_height() - 16); + return is_other_connection_area( get_position_x()+get_image()->get_width()+5, get_position_y()+get_image()->get_height() - 16, &_item); if ( (_a <= x+image->get_width()-1)&&(_a>=x+image->get_width()-10)&&(_b<=y+image->get_height()-10)&&(_b>=y+image->get_height()-22) ) // abajo-derecha h - return is_other_connection_area( get_position_x() + 16, get_position_y() - 5); + return is_other_connection_area( get_position_x() + 16, get_position_y() - 5,& _item); break; case 3: if ( (_a <= x+image->get_width()-1)&&(_a >= x+image->get_width()-10) && (_b <=y+22)&&(_b>=y+10) ) //arriba-derecha h - return is_other_connection_area( get_position_x() + 16, get_position_y()+get_image()->get_height() + 5); + return is_other_connection_area( get_position_x() + 16, get_position_y()+get_image()->get_height() + 5, &_item); if ( (_a <= x+22)&&(_a>=x+10)&&(_b<=y+image->get_height()-1)&&(_b>=y+image->get_height()-10) ) // abajo-izquierda v - return is_other_connection_area( get_position_x()+get_image()->get_width()+5, get_position_y() +16); + return is_other_connection_area( get_position_x()+get_image()->get_width()+5, get_position_y() +16,& _item); } } else { switch (imgActual) { diff --git a/Constructor/union.cpp b/Constructor/union.cpp index 1311bd5..4508b89 100644 --- a/Constructor/union.cpp +++ b/Constructor/union.cpp @@ -87,9 +87,18 @@ void Union::on_menu_popup_propiedades() void Union::save(FILE *archivo) { char c_id[50], c_caudal[50], c_x[50], c_y[50], c_img[50]; - Glib::ustring c_type; - if ( is_union ) c_type = "\t\tunion\n"; - else c_type = "\t\tdivision\n"; + Glib::ustring con0, con1, con2, c_type; + if (is_union){ + con0 = "\t\t\t"+get_other_name(connect_vec[0].id_dest)+"\n"; + con1 = "\t\t\t"+get_other_name(connect_vec[1].id_dest)+"\n"; + con2 = "\t\t\t"+get_other_name(connect_vec[2].id_dest)+"\n"; + c_type = "\t\tunion\n"; + } else { + con0 = "\t\t\t"+get_other_name(connect_vec[0].id_dest)+"\n"; + con1 = "\t\t\t"+get_other_name(connect_vec[1].id_dest)+"\n"; + con2 = "\t\t\t"+get_other_name(connect_vec[2].id_dest)+"\n"; + c_type = "\t\tdivision\n"; + } sprintf(c_x,"\t\t%d\n",x); sprintf(c_y,"\t\t%d\n",y); sprintf(c_id,"%d",ID); @@ -100,6 +109,7 @@ void Union::save(FILE *archivo) dato += c_id; dato += "\">\n"; dato += c_type; + dato += "\t\t\n"+con0+con1+con2+"\t\t\n"; dato += c_caudal; dato += c_img; dato += c_x; @@ -110,36 +120,41 @@ void Union::save(FILE *archivo) bool Union::check_connection() { + CItem * _item0, *_item1, *_item2; ConnectorType temp0, temp1, temp2; switch (get_img_actual()) { case 0: - temp0 = is_other_connection_area( get_position_x() - 5, get_position_y() +16); - temp1 = is_other_connection_area( get_position_x()+get_image()->get_width()+5, get_position_y()+16); - temp2 = is_other_connection_area( get_position_x()+get_image()->get_width()/2, get_position_y()+get_image()->get_height()+5); + temp0 = is_other_connection_area( get_position_x() - 5, get_position_y() +16, &_item0); + temp1 = is_other_connection_area( get_position_x()+get_image()->get_width()+5, get_position_y()+16, &_item1); + temp2 = is_other_connection_area( get_position_x()+get_image()->get_width()/2, get_position_y()+get_image()->get_height()+5, &_item2); break; case 1: - temp2 = is_other_connection_area( get_position_x()-5, get_position_y()+get_image()->get_height()/2); - temp0 = is_other_connection_area( get_position_x()+get_image()->get_width()-16, get_position_y()-5); - temp1 = is_other_connection_area( get_position_x()+get_image()->get_width()-16, get_position_y()+get_image()->get_height()+5); + temp2 = is_other_connection_area( get_position_x()-5, get_position_y()+get_image()->get_height()/2, &_item2); + temp0 = is_other_connection_area( get_position_x()+get_image()->get_width()-16, get_position_y()-5, &_item0); + temp1 = is_other_connection_area( get_position_x()+get_image()->get_width()-16, get_position_y()+get_image()->get_height()+5,& _item1); break; case 2: - temp1 = is_other_connection_area( get_position_x()-5, get_position_y()+get_image()->get_height()-16); - temp2 = is_other_connection_area( get_position_x()+get_image()->get_width()/2, get_position_y()-5); - temp0 = is_other_connection_area( get_position_x()+get_image()->get_width()+5, get_position_y()+get_image()->get_height()-16); + temp1 = is_other_connection_area( get_position_x()-5, get_position_y()+get_image()->get_height()-16,& _item1); + temp2 = is_other_connection_area( get_position_x()+get_image()->get_width()/2, get_position_y()-5, &_item2); + temp0 = is_other_connection_area( get_position_x()+get_image()->get_width()+5, get_position_y()+get_image()->get_height()-16, &_item0); break; case 3: - temp1 = is_other_connection_area( get_position_x()+16, get_position_y()-5); - temp2 = is_other_connection_area( get_position_x()+get_image()->get_width()+5, get_position_y()+get_image()->get_height()/2); - temp0 = is_other_connection_area( get_position_x()+16, get_position_y()+get_image()->get_height()+5); + 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); } if ( is_union ) { - if ( temp0 == OUT && temp1 == OUT && temp2 == IN ) + if ( temp0 == OUT && temp1 == OUT && temp2 == IN ) { + connect_vec[0].id_dest = _item0->get_id(); + connect_vec[1].id_dest = _item1->get_id(); + connect_vec[2].id_dest = _item2->get_id(); return (is_connected = true); + } } else { if ( temp0 == IN && temp1 == IN && temp2 == OUT ) return (is_connected = true); } - return false; + return is_connected; } ConnectorType Union::get_connector_type(int _a, int _b)