From: Nicolás Dimov Date: Mon, 17 Nov 2003 00:04:14 +0000 (+0000) Subject: cambios drasticos producen cuelgues obvios, etapa de revision, pueden mirarlo libremente X-Git-Tag: svn_import~290 X-Git-Url: https://git.llucax.com/z.facultad/75.42/plaqui.git/commitdiff_plain/31b3e321726d5c3fe720dd216687d3138523714f?ds=sidebyside cambios drasticos producen cuelgues obvios, etapa de revision, pueden mirarlo libremente --- diff --git a/Constructor/and.cpp b/Constructor/and.cpp index debe5f5..768390a 100644 --- a/Constructor/and.cpp +++ b/Constructor/and.cpp @@ -66,30 +66,29 @@ void And::save(FILE *archivo) // CAMBIAR TODO ESTO!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! bool And::check_connection() { - switch (get_img_actual()) { + /*switch (get_img_actual()) { case 0: if ( is_other_connection_area( get_position_x()-5, get_position_y()+16) && is_other_connection_area( get_position_x()+get_image()->get_width()-16, +get_position_y()+get_image()->get_height() + 5) ) return true; - break; case 1: if ( is_other_connection_area( get_position_x()+get_image()->get_width() - 16, get_position_y() -5) && is_other_connection_area( get_position_x()-5, get_position_y()+get_image()->get_height()-16) ) return true; - break; case 2: if ( is_other_connection_area( get_position_x() + 16, get_position_y() -5) && is_other_connection_area( get_position_x()+get_image()->get_width()+5, get_position_y()+get_image()->get_height()-16) ) return true; - break; case 3: if ( is_other_connection_area( get_position_x()+get_image()->get_width()+5, get_position_y() +16) && is_other_connection_area( get_position_x() + 16, get_position_y()+get_image()->get_height() + 5) ) return true; } - return false; + return false;*/ + return true; } +/* bool And::is_connection_area(int _a, int _b) { switch (imgActual) { @@ -108,3 +107,4 @@ bool And::is_connection_area(int _a, int _b) } return false; } +*/ diff --git a/Constructor/and.h b/Constructor/and.h index cca48a1..2895668 100644 --- a/Constructor/and.h +++ b/Constructor/and.h @@ -11,7 +11,7 @@ class And : public CItem { virtual void on_menu_popup_rotar(); virtual void save(FILE *archivo); virtual bool check_connection(); - virtual bool is_connection_area(int _a, int _b); +// virtual bool is_connection_area(int _a, int _b); private: Glib::RefPtr imageN; // 0 Glib::RefPtr imageS; // 1 diff --git a/Constructor/cistern.cpp b/Constructor/cistern.cpp index 88eae2d..b42f690 100644 --- a/Constructor/cistern.cpp +++ b/Constructor/cistern.cpp @@ -15,6 +15,13 @@ Cistern::Cistern() cistern_pty_wnd->cistern = this; cistern_pty_wnd->set_title("Propiedades del Tanque"); name = "tanque"; + + Connector temp; + temp.id_dest = -1; + temp.type = IN; + connect_vec.push_back(temp); // entrada arriba + temp.type = OUT; + connect_vec.push_back(temp); // salida abajo } Cistern::~Cistern() @@ -134,28 +141,54 @@ void Cistern::save(FILE *archivo) bool Cistern::check_connection() { + ConnectorType temp0, temp1; switch (get_img_actual()) { case 0: - if ( is_other_connection_area( get_position_x()+get_image()->get_width() + 5 , get_position_y()+get_image()->get_height() -16) && - is_other_connection_area( get_position_x() + 16, get_position_y() - 5) ) - return true; + 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); + break; case 1: - if ( is_other_connection_area( get_position_x() -5, get_position_y()+get_image()->get_height()-16) && - is_other_connection_area( get_position_x()+get_image()->get_width() - 16, get_position_y() - 5) ) - return true; + 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); } - return false; + if (temp0 == OUT && temp1 == IN) + return (is_connected = true); + return is_connected; } -bool Cistern::is_connection_area(int _a, int _b) +ConnectorType Cistern::get_connector_type(int _a, int _b) +{ + switch (imgActual) { + case 0: if ( (_a <= x+22)&&(_a>=x+10)&&(_b<=y+10)&&(_b > y) ) + return connect_vec[0].type; + 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) ) + return connect_vec[1].type; + break; + case 1: if ( (_a <= x+image->get_width()-10)&&(_a>=x+image->get_width()-22)&&(_b<=y+10)&&(_b > y) ) + return connect_vec[0].type; + if ( (_a <= x +10)&&(_a > x)&&(_b<=y+image->get_height()-10)&&(_b >=y+image->get_height()-22) ) + return connect_vec[1].type; + } + return UNDEF; +} + +/* +ConnectorType Cistern::is_connection_area(int _a, int _b) { switch (imgActual) { - case 0: if ( ( (_a <= x+22)&&(_a>=x+10)&&(_b<=y+10)&&(_b > y) ) || - ( (_a <= x+image->get_width()-1)&&(_a >=x+image->get_width()-10)&&(_b<=y+image->get_height()-10)&&(_b >=y+image->get_height()-22) ) ) - return true; - case 1: if ( ( (_a <= x+image->get_width()-10)&&(_a>=x+image->get_width()-22)&&(_b<=y+10)&&(_b > y) ) || - ( (_a <= x +10)&&(_a > x)&&(_b<=y+image->get_height()-10)&&(_b >=y+image->get_height()-22) ) ) - return true; + case 0: + if ( (_a <= x+22)&&(_a>=x+10)&&(_b<=y+10)&&(_b > y) ) + return connect_vec[0].type; + 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) ) + return connect_vec[1].type; + break; + case 1: + if ( (_a <= x+image->get_width()-10)&&(_a>=x+image->get_width()-22)&&(_b<=y+10)&&(_b > y) ) + return connect_vec[0].type; + if ( (_a <= x +10)&&(_a > x)&&(_b<=y+image->get_height()-10)&&(_b >=y+image->get_height()-22) ) + return connect_vec[1].type; + break; } - return false; + return UNDEF; } +*/ diff --git a/Constructor/cistern.h b/Constructor/cistern.h index 0065554..67184c2 100644 --- a/Constructor/cistern.h +++ b/Constructor/cistern.h @@ -21,7 +21,8 @@ class Cistern : public CItem { Gdk::Color get_liquid_color(); virtual void save(FILE *archivo); virtual bool check_connection(); - virtual bool is_connection_area(int _a, int _b); +// virtual ConnectorType is_connection_area(int _a, int _b); + virtual ConnectorType get_connector_type(int _a, int _b); protected: double capacidad, contenido_inicial; Glib::RefPtr imageE; // 0 diff --git a/Constructor/cisternptywnd.cpp b/Constructor/cisternptywnd.cpp index e5ca32d..12617e2 100644 --- a/Constructor/cisternptywnd.cpp +++ b/Constructor/cisternptywnd.cpp @@ -7,6 +7,8 @@ CisternPtyWnd::CisternPtyWnd(BaseObjectType* cobject, const Glib::RefPtrget_widget("spin_inicial", spin_inicial); refGlade->get_widget("txt_cistern_name", txt_cistern_name); refGlade->get_widget("btn_select_color", btn_select_color); + refGlade->get_widget("color_preview",color_preview); + Glib::RefPtr ref = Gnome::Glade::Xml::create("constructor.glade", "color_select_dlg"); ref->get_widget("color_select_dlg",color_select_dlg); ref->get_widget("dlg_select_color_cancel",dlg_select_color_cancel); @@ -49,5 +51,6 @@ void CisternPtyWnd::on_dlg_select_color_cancel_clicked() void CisternPtyWnd::on_dlg_select_color_ok_clicked() { cistern->set_liquid_color( color_select_dlg->get_colorsel()->get_current_color() ); + color_preview->modify_bg( Gtk::STATE_NORMAL , cistern->get_liquid_color() ); color_select_dlg->hide(); } diff --git a/Constructor/cisternptywnd.h b/Constructor/cisternptywnd.h index 81af75c..276e889 100644 --- a/Constructor/cisternptywnd.h +++ b/Constructor/cisternptywnd.h @@ -14,6 +14,7 @@ class CisternPtyWnd : public PropertyWnd { Gtk::Button *btn_select_color, *dlg_select_color_ok, *dlg_select_color_cancel; Gtk::Entry *txt_cistern_name; Gtk::ColorSelectionDialog *color_select_dlg; + Gtk::DrawingArea *color_preview; virtual void on_btn_accept_clicked(); virtual void on_btn_apply_clicked(); virtual void on_btn_select_color_clicked(); diff --git a/Constructor/conduct.cpp b/Constructor/conduct.cpp index 9b2e31f..c2ca140 100644 --- a/Constructor/conduct.cpp +++ b/Constructor/conduct.cpp @@ -10,6 +10,11 @@ Conduct::Conduct() set_size_request(image->get_width(), image->get_height()); property_wnd->set_title("Propiedades del Tubo"); name="tubo"; + Connector temp; + temp.id_dest = -1; + temp.type = UNDEF; + connect_vec.push_back(temp); + connect_vec.push_back(temp); } Conduct::~Conduct() @@ -91,17 +96,55 @@ bool Conduct::check_connection() { switch (get_img_actual()) { case 0: - if ( is_other_connection_area( get_position_x()+16, get_position_y()-5) && - is_other_connection_area( get_position_x()+16, get_position_y()+get_image()->get_height() +5) ) - return true; + 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); + break; case 1: - if ( is_other_connection_area( get_position_x()-5, get_position_y()+16) && - is_other_connection_area( get_position_x()+get_image()->get_width()+5, get_position_y()+16) ) - return true; + 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); } - return false; + if ( connect_vec[0].type != UNDEF && connect_vec[1].type != UNDEF ) + return ( is_connected = (connect_vec[0].type != connect_vec[1].type) ); + else return false; } +ConnectorType Conduct::get_connector_type(int _a, int _b) +{ + 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 + 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. + 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 + 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. + } + } else { + switch (imgActual) { + case 0: + if ( (_a <= x+image->get_width()-10 )&&(_a >= x + 10) && (_b <= y+10) &&(_b > 0 ) ) //arriba + return connect_vec[0].type; + if ((_a <= x+22 )&&(_a >= x + 10) && (_b <= y+image->get_height()-1) &&(_b >= y+image->get_height()-10 )) //abajo + return connect_vec[1].type; + break; + case 1: + if ((_a <= x+10 )&&(_a > 0) && (_b <= y+image->get_height()-10) &&(_b >= y+10 )) //izquierda + return connect_vec[0].type; + if ((_a <= x+image->get_width()-1)&&(_a >= x+image->get_width()-10) && (_b <= y+image->get_height()-10) &&(_b >= y +10 )) //derecha + return connect_vec[1].type; + } + } + return UNDEF; +} +/*si no estoy conectado pregunto por el del otro lado, y ahi puedo setear los dos + *si ya estoy devuelvo. +*/ +/* bool Conduct::is_connection_area(int _a, int _b) { switch (imgActual){ @@ -116,3 +159,4 @@ bool Conduct::is_connection_area(int _a, int _b) } return false; } +*/ diff --git a/Constructor/conduct.h b/Constructor/conduct.h index bb22740..21773ed 100644 --- a/Constructor/conduct.h +++ b/Constructor/conduct.h @@ -12,7 +12,8 @@ class Conduct : public CItem { virtual void on_menu_popup_propiedades(); virtual void save(FILE *archivo); virtual bool check_connection(); - virtual bool is_connection_area(int _a, int _b); +// virtual bool is_connection_area(int _a, int _b); + virtual ConnectorType get_connector_type(int _a, int _b); private: Glib::RefPtr imageN; // 0 Glib::RefPtr imageS; // 1 diff --git a/Constructor/constructor.cpp b/Constructor/constructor.cpp index deb918d..8aa6655 100644 --- a/Constructor/constructor.cpp +++ b/Constructor/constructor.cpp @@ -11,6 +11,7 @@ Constructor::Constructor(BaseObjectType* cobject, const Glib::RefPtrget_widget("btn_tanque",btn_tanque); refGlade->get_widget("btn_bomba", btn_bomba); refGlade->get_widget("btn_exclusa", btn_exclusa); + refGlade->get_widget("btn_drain", btn_drain); refGlade->get_widget("btn_and", btn_and); refGlade->get_widget("btn_or", btn_or); refGlade->get_widget("btn_not", btn_not); @@ -49,6 +51,7 @@ Constructor::Constructor(BaseObjectType* cobject, const Glib::RefPtrdrag_source_set(listTargets); btn_tanque->drag_source_set(listTargets); btn_bomba->drag_source_set(listTargets); + btn_drain->drag_source_set(listTargets); btn_exclusa->drag_source_set(listTargets); btn_and->drag_source_set(listTargets); btn_or->drag_source_set(listTargets); @@ -60,6 +63,7 @@ Constructor::Constructor(BaseObjectType* cobject, const Glib::RefPtrsignal_drag_data_get().connect( SigC::slot(*this, &Constructor::on_btn_y_drag_get)); btn_codo->signal_drag_data_get().connect( SigC::slot(*this, &Constructor::on_btn_codo_drag_get)); btn_tanque->signal_drag_data_get().connect( SigC::slot(*this, &Constructor::on_btn_tanque_drag_get)); + btn_drain->signal_drag_data_get().connect( SigC::slot(*this, &Constructor::on_btn_drain_drag_get)); btn_and->signal_drag_data_get().connect( SigC::slot(*this, &Constructor::on_btn_and_drag_get)); btn_or->signal_drag_data_get().connect( SigC::slot(*this, &Constructor::on_btn_or_drag_get)); btn_not->signal_drag_data_get().connect( SigC::slot(*this, &Constructor::on_btn_not_drag_get)); @@ -83,6 +87,7 @@ Constructor::Constructor(BaseObjectType* cobject, const Glib::RefPtrsignal_drag_begin().connect( SigC::slot(*this, &Constructor::on_tanque_drag_begin)); btn_bomba->signal_drag_begin().connect( SigC::slot(*this, &Constructor::on_bomba_drag_begin)); btn_exclusa->signal_drag_begin().connect( SigC::slot(*this, &Constructor::on_exclusa_drag_begin)); + btn_drain->signal_drag_begin().connect( SigC::slot(*this, &Constructor::on_drain_drag_begin)); btn_and->signal_drag_begin().connect( SigC::slot(*this, &Constructor::on_and_drag_begin)); btn_or->signal_drag_begin().connect( SigC::slot(*this, &Constructor::on_or_drag_begin)); btn_not->signal_drag_begin().connect( SigC::slot(*this, &Constructor::on_not_drag_begin)); @@ -133,6 +138,11 @@ void Constructor::on_btn_exclusa_drag_get(const Glib::RefPtr& gtk_selection_data_set(selection_data, selection_data->target, 8,(const guchar*)"exclusa_h.png",15); } +void Constructor::on_btn_drain_drag_get(const Glib::RefPtr& context, GtkSelectionData* selection_data, guint info, guint time) +{ + gtk_selection_data_set(selection_data, selection_data->target, 8,(const guchar*)"drain_n.png",11); +} + void Constructor::on_btn_and_drag_get(const Glib::RefPtr& context, GtkSelectionData* selection_data, guint info, guint time) { gtk_selection_data_set(selection_data, selection_data->target, 8,(const guchar*)"and_e.png",9); @@ -185,6 +195,7 @@ void Constructor::on_btn_file_ok_clicked() std::list::iterator i = listaItems.begin(); std::string file_name = file_selection->get_filename(); if ( (archivo = fopen( file_name.c_str(), "w+")) != NULL ){ + fprintf(archivo, "\n"); fprintf (archivo,"\n"); while ( i != listaItems.end() ){ CItem *temp = *i; @@ -238,6 +249,11 @@ void Constructor::on_exclusa_drag_begin(const Glib::RefPtr& co context->set_icon(ico_exclusa, 5, 5); } +void Constructor::on_drain_drag_begin(const Glib::RefPtr& context) +{ + context->set_icon(ico_drain, 5, 5); +} + void Constructor::on_and_drag_begin(const Glib::RefPtr& context) { context->set_icon(ico_and, 5, 5); @@ -313,15 +329,17 @@ void Constructor::on_item_drop_drag_received(const Glib::RefPtrdata, "exclusa_h.png")==0) a = new Exclusa(); - else if (strcmp((const char *)selection_data->data, "and_e.png")==0) - a = new And(); - else if (strcmp((const char *)selection_data->data, "or_e.png")==0) - a = new Or(); - else if (strcmp((const char *)selection_data->data, "not_e.png")==0) - a = new Not(); + else if (strcmp((const char *)selection_data->data, "drain_n.png")==0) + a = new Drain(); + else if (strcmp((const char *)selection_data->data, "and_e.png")==0) + a = new And(); + else if (strcmp((const char *)selection_data->data, "or_e.png")==0) + a = new Or(); + else if (strcmp((const char *)selection_data->data, "not_e.png")==0) + a = new Not(); char char_id[10]; - sprintf(char_id," %d",id); + sprintf(char_id,"%d",id); a->set_id(++id); a->set_name( a->get_name()+char_id ); if ( can_drop(a, i*32, j*32) ) { diff --git a/Constructor/constructor.glade b/Constructor/constructor.glade index cf1bea9..5deafe9 100644 --- a/Constructor/constructor.glade +++ b/Constructor/constructor.glade @@ -4,8 +4,8 @@ - 640 - 573 + 738 + 689 True Constuctor GTK_WINDOW_TOPLEVEL @@ -458,6 +458,49 @@ + + + + True + True + True + GTK_RELIEF_NORMAL + + + + True + 0.5 + 0.5 + 0 + 0 + + + + True + False + 2 + + + + True + drain_n.png + 0.5 + 0.5 + 0 + 0 + + + 0 + False + False + + + + + + + + 0 @@ -659,7 +702,7 @@ - 272 + 304 182 Propiedades del Tanque GTK_WINDOW_TOPLEVEL @@ -884,6 +927,20 @@ + + + + True + + + 1 + 2 + 3 + 4 + fill + fill + + 0 @@ -1038,7 +1095,7 @@ - + True Flujo Máximo False @@ -1677,6 +1734,20 @@ + + + + True + + + 1 + 2 + 2 + 3 + fill + fill + + 10 diff --git a/Constructor/constructor.h b/Constructor/constructor.h index b9297fb..aa15f54 100644 --- a/Constructor/constructor.h +++ b/Constructor/constructor.h @@ -21,6 +21,7 @@ #include "cistern.h" #include "exclusa.h" #include "pump.h" +#include "drain.h" #include "and.h" #include "or.h" #include "not.h" @@ -34,7 +35,7 @@ class Constructor : public Gtk::Window { protected: int id; // / defino los elementos de la ventana. - Gtk::Button *btn_canio, *btn_codo, *btn_y, *btn_tanque, *btn_bomba, *btn_exclusa, *btn_file_ok, *btn_file_cancel, *btn_check, *btn_dlg_close, + Gtk::Button *btn_canio, *btn_codo, *btn_y, *btn_tanque, *btn_bomba, *btn_exclusa, *btn_drain, *btn_file_ok, *btn_file_cancel, *btn_check, *btn_dlg_close, *btn_and, *btn_or, *btn_not; Gtk::ImageMenuItem *main_menu_quit, *edit_menu_del, *main_menu_save; Gtk::CheckButton *chk_btn_logica; @@ -42,7 +43,7 @@ class Constructor : public Gtk::Window { Gtk::Entry *combo_entry; Gtk::Dialog *dlg_connect; Gtk::Label *dlg_label; - Glib::RefPtr ico_canio, ico_y, ico_codo, ico_tanque, ico_bomba, ico_exclusa, ico_and, ico_or, ico_not; + Glib::RefPtr ico_canio, ico_y, ico_codo, ico_tanque, ico_bomba, ico_exclusa, ico_drain, ico_and, ico_or, ico_not; Glib::RefPtr ico_last; std::list listTargets; std::list listaItems; @@ -57,6 +58,7 @@ class Constructor : public Gtk::Window { virtual void on_btn_tanque_drag_get(const Glib::RefPtr& context, GtkSelectionData* selection_data, guint info, guint time); virtual void on_btn_bomba_drag_get(const Glib::RefPtr& context, GtkSelectionData* selection_data, guint info, guint time); virtual void on_btn_exclusa_drag_get(const Glib::RefPtr& context, GtkSelectionData* selection_data, guint info, guint time); + virtual void on_btn_drain_drag_get(const Glib::RefPtr& context, GtkSelectionData* selection_data, guint info, guint time); virtual void on_btn_and_drag_get(const Glib::RefPtr& context, GtkSelectionData* selection_data, guint info, guint time); virtual void on_btn_or_drag_get(const Glib::RefPtr& context, GtkSelectionData* selection_data, guint info, guint time); virtual void on_btn_not_drag_get(const Glib::RefPtr& context, GtkSelectionData* selection_data, guint info, guint time); @@ -76,6 +78,7 @@ class Constructor : public Gtk::Window { virtual void on_tanque_drag_begin(const Glib::RefPtr& context); virtual void on_bomba_drag_begin(const Glib::RefPtr& context); virtual void on_exclusa_drag_begin(const Glib::RefPtr& context); + virtual void on_drain_drag_begin(const Glib::RefPtr& context); virtual void on_and_drag_begin(const Glib::RefPtr& context); virtual void on_or_drag_begin(const Glib::RefPtr& context); virtual void on_not_drag_begin(const Glib::RefPtr& context); diff --git a/Constructor/drain.cpp b/Constructor/drain.cpp new file mode 100644 index 0000000..e1f0792 --- /dev/null +++ b/Constructor/drain.cpp @@ -0,0 +1,140 @@ +#include "drain.h" + +Drain::Drain() +{ + imageE = Gdk::Pixbuf::create_from_file("drain_e.png"); + imageO = Gdk::Pixbuf::create_from_file("drain_o.png"); + imageN = Gdk::Pixbuf::create_from_file("drain_n.png"); + imageS = Gdk::Pixbuf::create_from_file("drain_s.png"); + null = Gdk::Pixbuf::create_from_file("null.png"); + imgActual = 0; + image = imageN; + set_size_request(image->get_width(), image->get_height()); + property_wnd->item = this; + property_wnd->lb_max_fluid->property_visible() = false; + property_wnd->spin_caudal->property_visible() = false; + property_wnd->set_title("Propiedades del Drenaje"); + name = "drenaje"; + Connector temp; + temp.id_dest = -1; + temp.type = IN; + connect_vec.push_back(temp); +} + +Drain::~Drain() +{ +} + +bool Drain::on_button_press_event(GdkEventButton *event) +{ + if ((event->type == GDK_BUTTON_PRESS) && ( event->button == 1)) + combo_entry->set_text(name); + + if ((event->type == GDK_BUTTON_PRESS) && ( event->button ==2)){ + image = null; + 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); + imgActual++; + switch (imgActual) { + case 1: + image = imageE; + break; + case 2: + image = imageS; + break; + case 3: + image = imageO; + break; + default: + imgActual = 0; + image = imageN; + } + set_size_request(image->get_width(),image->get_height()); + 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); + } + + if ((event->type == GDK_BUTTON_PRESS) && ( event->button == 3)){ + menu_popup.popup(event->button, event->time); + return true; //It has been handled. + } + + if ((event->type == GDK_2BUTTON_PRESS) && (event->button ==1)){ + property_wnd->txt_item_name->set_text( name ); + property_wnd->show(); + } + return true; +} + +void Drain::on_menu_popup_rotar() +{ + GdkEventButton event; + event.type = GDK_BUTTON_PRESS; + event.button = 2; + Drain::on_button_press_event(&event); +} + +void Drain::on_menu_popup_propiedades() +{ + GdkEventButton event; + event.type = GDK_2BUTTON_PRESS; + event.button = 1; + Drain::on_button_press_event(&event); +} + +void Drain::save(FILE *archivo) +{ + char c_id[50], c_x[50], c_y[50], c_img[50]; + sprintf(c_x,"\t\t%d\n",x); + sprintf(c_y,"\t\t%d\n",y); + sprintf(c_id,"%d",ID); + sprintf(c_img,"\t\t%d\n",imgActual); + Glib::ustring dato; + dato = "\t\n"; + dato += c_img; + dato += c_x; + dato += c_y; + dato += "\t\n"; + fprintf(archivo,dato.c_str()); +} + +bool Drain::check_connection() +{ + ConnectorType temp; + switch (get_img_actual()) { + case 0: + temp = is_other_connection_area( get_position_x()+16 , get_position_y() -5); + break; + case 1: + temp = is_other_connection_area( get_position_x()+image->get_width() + 5, get_position_y()+16); + break; + case 2: + temp = is_other_connection_area( get_position_x()+16, get_position_y()+image->get_height()+5); + break; + case 3: + temp = is_other_connection_area( get_position_x()-5, get_position_y()+16); + } + return ( is_connected = (temp == OUT) ); +} + +ConnectorType Drain::get_connector_type(int _a, int _b) +{ + switch (imgActual) { + case 0: + if ( (_a <= x+22)&&(_a>=x+10)&&(_b<=y+10)&&(_b > y) ) + return connect_vec[0].type; + break; + case 1: + if ( (_a <= x+image->get_width() -1)&&(_a>=x+image->get_width()-10)&&(_b<=y+22)&&(_b >= y+10) ) + return connect_vec[0].type; + break; + case 2: + if ( (_a <= x +22)&&(_a >= x+10)&&(_b<=y+image->get_height() -1)&&(_b >=y+image->get_height()-10) ) + return connect_vec[0].type; + break; + case 3: + if ( (_a <= x+10)&&(_a >x)&&(_b<=y+22)&&(_b >=y+10) ) + return connect_vec[0].type; + } + return UNDEF; +} diff --git a/Constructor/drain.h b/Constructor/drain.h new file mode 100644 index 0000000..2c6ab7b --- /dev/null +++ b/Constructor/drain.h @@ -0,0 +1,28 @@ +#ifndef _DRAIN_H_ +#define _DRAIN_H_ + +#include +#include "item.h" + + +class Drain : public CItem { + public: + Drain(); + virtual ~Drain(); + virtual bool on_button_press_event(GdkEventButton *event); + virtual void on_menu_popup_rotar(); + virtual void on_menu_popup_propiedades(); + double get_contenido_inicial(); + double get_capacidad(); + virtual void save(FILE *archivo); + virtual bool check_connection(); + //virtual ConnectorType is_connection_area(int _a, int _b); + virtual ConnectorType get_connector_type(int _a, int _b); + protected: + Glib::RefPtr imageE; // 0 + Glib::RefPtr imageO; // 1 + Glib::RefPtr imageN; // 1 + Glib::RefPtr imageS; // 1 + Glib::RefPtr null; +}; +#endif diff --git a/Constructor/drain_e.png b/Constructor/drain_e.png new file mode 100644 index 0000000..bc3d60b Binary files /dev/null and b/Constructor/drain_e.png differ diff --git a/Constructor/drain_n.png b/Constructor/drain_n.png new file mode 100644 index 0000000..2f11c9b Binary files /dev/null and b/Constructor/drain_n.png differ diff --git a/Constructor/drain_o.png b/Constructor/drain_o.png new file mode 100644 index 0000000..9138db7 Binary files /dev/null and b/Constructor/drain_o.png differ diff --git a/Constructor/drain_s.png b/Constructor/drain_s.png new file mode 100644 index 0000000..8e8b9b5 Binary files /dev/null and b/Constructor/drain_s.png differ diff --git a/Constructor/exclusa.cpp b/Constructor/exclusa.cpp index e8547d6..6a386d1 100644 --- a/Constructor/exclusa.cpp +++ b/Constructor/exclusa.cpp @@ -108,19 +108,55 @@ bool Exclusa::check_connection() { switch (get_img_actual()) { case 0: - if ( is_other_connection_area( get_position_x()+get_image()->get_width()+5, get_position_y()+16) && - is_other_connection_area( get_position_x()-5, get_position_y() + 16) ) - return true; - break; + 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); + break; case 1: - if ( is_other_connection_area( get_position_x()+16, get_position_y()-5 ) && - is_other_connection_area( get_position_x()+16, get_position_y()+get_image()->get_height()+5) ) - return true; + 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); } - return false; + if ( connect_vec[0].type != UNDEF && connect_vec[1].type != UNDEF ) + return ( is_connected = (connect_vec[0].type != connect_vec[1].type) ); + else return false; } -bool Exclusa::is_connection_area(int _a, int _b) +ConnectorType Exclusa::get_connector_type(int _a, int _b) +{ + 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 + 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. + 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 + 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. + } + } else { + switch (imgActual) { + case 0: + if ( (_a <= x+image->get_width()-10 )&&(_a >= x + 10) && (_b <= y+10) &&(_b > 0 ) ) //arriba + return connect_vec[0].type; + if ((_a <= x+22 )&&(_a >= x + 10) && (_b <= y+image->get_height()-1) &&(_b >= y+image->get_height()-10 )) //abajo + return connect_vec[1].type; + break; + case 1: + if ((_a <= x+10 )&&(_a > 0) && (_b <= y+image->get_height()-10) &&(_b >= y+10 )) //izquierda + return connect_vec[0].type; + if ((_a <= x+image->get_width()-1)&&(_a >= x+image->get_width()-10) && (_b <= y+image->get_height()-10) &&(_b >= y +10 )) //derecha + return connect_vec[1].type; + } + } + return UNDEF; +} +/*si no estoy conectado pregunto por el del otro lado, y ahi puedo setear los dos + *si ya estoy devuelvo. +*/ +/*bool Exclusa::is_connection_area(int _a, int _b) { switch (imgActual){ case 0: @@ -134,3 +170,4 @@ bool Exclusa::is_connection_area(int _a, int _b) } return false; } +*/ diff --git a/Constructor/exclusa.h b/Constructor/exclusa.h index 86a5c1c..b65e616 100644 --- a/Constructor/exclusa.h +++ b/Constructor/exclusa.h @@ -14,7 +14,8 @@ class Exclusa : public CItem { virtual void on_menu_popup_propiedades(); virtual void save(FILE *archivo); virtual bool check_connection(); - virtual bool is_connection_area(int _a, int _b); +// virtual ConnectorType is_connection_area(int _a, int _b); + virtual ConnectorType get_connector_type(int _a, int _b); void set_estado(bool _state); bool get_estado(); private: diff --git a/Constructor/item.cpp b/Constructor/item.cpp index c08f894..72f6393 100644 --- a/Constructor/item.cpp +++ b/Constructor/item.cpp @@ -14,6 +14,7 @@ CItem::CItem() ref->get_widget_derived("item_pty_wnd",property_wnd); caudal_max = 0.0; is_union = true; + is_connected = false; property_wnd->item = this; menu_image_propiedades.set(Gtk::Stock::PREFERENCES, Gtk::ICON_SIZE_MENU); menu_image_delete.set(Gtk::Stock::CANCEL, Gtk::ICON_SIZE_MENU); @@ -60,37 +61,6 @@ void CItem::on_menu_popup_conectar() { } -void CItem::set_position(int _x, int _y) -{ - this->x = _x; - this->y = _y; -} - -void CItem::set_id(int _id) -{ - ID = _id; -} - -void CItem::set_caudal(double _caudal) -{ - caudal_max = _caudal; -} - -void CItem::set_name(Glib::ustring _name) -{ - name = _name; -} - -void CItem::set_conector_in(int _in) -{ - conector_in = _in; -} - -void CItem::set_conector_out(int _out) -{ - conector_out = _out; -} - int CItem::get_position_x() { return x; @@ -117,19 +87,30 @@ Glib::ustring CItem::get_name() return name; } -int CItem::get_conector_in() +int CItem::get_img_actual() { - return conector_in; + return imgActual; } -int CItem::get_conector_out() +void CItem::set_position(int _x, int _y) { - return conector_out; + this->x = _x; + this->y = _y; } -int CItem::get_img_actual() +void CItem::set_id(int _id) { - return imgActual; + ID = _id; +} + +void CItem::set_caudal(double _caudal) +{ + caudal_max = _caudal; +} + +void CItem::set_name(Glib::ustring _name) +{ + name = _name; } bool CItem::is_occupied_area(int _a, int _b) @@ -139,14 +120,21 @@ bool CItem::is_occupied_area(int _a, int _b) else return false; } -bool CItem::is_other_connection_area(int _a, int _b) +ConnectorType CItem::is_other_connection_area(int _a, int _b) { + ConnectorType temp2; std::list::iterator i = listaItems->begin(); - while ( i != listaItems->end() ){ + while ( i != listaItems->end() ) { CItem *temp = *i; - if ( temp->is_connection_area(_a,_b) ) - return true; - i++; + if (temp != this) { + if ( (temp2 = temp->get_connector_type(_a,_b)) != UNDEF ) + return temp2; + i++; + } } - return false; + return UNDEF; +} +ConnectorType CItem::get_connector_type( int _a, int _b ) +{ + return UNDEF; } diff --git a/Constructor/item.h b/Constructor/item.h index 7c1e771..1654bf3 100644 --- a/Constructor/item.h +++ b/Constructor/item.h @@ -11,6 +11,20 @@ #include #include "itemptywnd.h" +typedef enum { NONE, RIGHT, LEFT, MIDDLE } ConnectorSide; +typedef enum { UNDEF, IN, OUT } ConnectorType; + +class Connector { + public: + int id_dest; + ConnectorType type; + Connector& operator= (Connector & c) { + id_dest = c.id_dest; + type = c.type; + return *this; + } +}; + class WorkPlace; class CItem:public Gtk::DrawingArea { @@ -27,8 +41,6 @@ public: int get_position_x(); int get_position_y(); int get_id(); - int get_conector_in(); - int get_conector_out(); int get_img_actual(); Glib::ustring get_name(); double get_caudal(); @@ -36,20 +48,23 @@ public: void set_id(int _id); void set_caudal(double _caudal); void set_name(Glib::ustring _name); - void set_conector_in(int _in); - void set_conector_out(int _out); bool is_occupied_area(int _a, int _b); - bool is_other_connection_area(int _a, int _b); + ConnectorType is_other_connection_area(int _a, int _b); virtual void save(FILE *archivo) = 0; virtual bool check_connection()=0; - virtual bool is_connection_area(int _a, int _b)=0; +// virtual ConnectorType is_connection_area(int _a, int _b)=0; + virtual ConnectorType get_connector_type( int _a, int _b ); WorkPlace *workplace; Gtk::Entry *combo_entry; std::list *listaItems; bool is_union; + bool is_connected; + // Hay que ocultarlo --- problemas con el get y el set!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + // 0 = izquierda/arriba , 1 = derecha/abajo , 2 = medio. tomando como referencia la imagen inicial de cada item cuando corresponda + std::vector connect_vec; protected: int imgActual; - int ID, conector_in, conector_out; + int ID; Glib::ustring name; double caudal_max; Gtk::Menu menu_popup; diff --git a/Constructor/itemptywnd.cpp b/Constructor/itemptywnd.cpp index 44d7392..7810e7c 100644 --- a/Constructor/itemptywnd.cpp +++ b/Constructor/itemptywnd.cpp @@ -8,7 +8,7 @@ ItemPtyWnd::ItemPtyWnd(BaseObjectType* cobject, const Glib::RefPtrget_widget("rd_btn_division", rd_btn_division); refGlade->get_widget("rd_btn_union", rd_btn_union); refGlade->get_widget("lb_type", lb_type); - + refGlade->get_widget("lb_max_fluid", lb_max_fluid); rd_btn_division->signal_clicked().connect(SigC::slot(*this,&ItemPtyWnd::on_rd_btn_division_clicked)); rd_btn_union->signal_clicked().connect(SigC::slot(*this,&ItemPtyWnd::on_rd_btn_union_clicked)); } @@ -37,10 +37,16 @@ void ItemPtyWnd::on_btn_cancel_clicked() void ItemPtyWnd::on_rd_btn_union_clicked() { + item->connect_vec[0].type = IN; + item->connect_vec[1].type = IN; + item->connect_vec[2].type = OUT; item->is_union = true; } void ItemPtyWnd::on_rd_btn_division_clicked() { + item->connect_vec[0].type = OUT; + item->connect_vec[1].type = OUT; + item->connect_vec[2].type = IN; item->is_union = false; } diff --git a/Constructor/itemptywnd.h b/Constructor/itemptywnd.h index 6f82c22..c8f4dd1 100644 --- a/Constructor/itemptywnd.h +++ b/Constructor/itemptywnd.h @@ -9,7 +9,7 @@ class ItemPtyWnd : public PropertyWnd { virtual ~ItemPtyWnd(); Gtk::SpinButton *spin_caudal; Gtk::RadioButton *rd_btn_union, *rd_btn_division; - Gtk::Label *lb_type; + Gtk::Label *lb_type, *lb_max_fluid; Gtk::Entry *txt_item_name; protected: virtual void on_btn_cancel_clicked(); diff --git a/Constructor/not.cpp b/Constructor/not.cpp index 1107030..ca112fe 100644 --- a/Constructor/not.cpp +++ b/Constructor/not.cpp @@ -66,7 +66,7 @@ void Not::save(FILE *archivo) // CAMBIAR TODO ESTO!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! bool Not::check_connection() { - switch (get_img_actual()) { +/* switch (get_img_actual()) { case 0: if ( is_other_connection_area( get_position_x()-5, get_position_y()+16) && is_other_connection_area( get_position_x()+get_image()->get_width()-16, +get_position_y()+get_image()->get_height() + 5) ) @@ -87,12 +87,14 @@ bool Not::check_connection() is_other_connection_area( get_position_x() + 16, get_position_y()+get_image()->get_height() + 5) ) return true; } - return false; + return false;*/ + return true; } +/* bool Not::is_connection_area(int _a, int _b) { - switch (imgActual) { + /*switch (imgActual) { case 0: if ( ( (_a <= x+10)&&(_a > x) && (_b <=y+22)&&(_b>=y+10) ) || ( (_a <= x+image->get_width()-10)&&(_a>=x+image->get_width()-22)&&(_b<=y+image->get_height()-1)&&(_b>=y+image->get_height()-10) ) ) return true; @@ -107,4 +109,6 @@ bool Not::is_connection_area(int _a, int _b) return true; } return false; + return true; } +*/ diff --git a/Constructor/not.h b/Constructor/not.h index dd572fe..4e0480c 100644 --- a/Constructor/not.h +++ b/Constructor/not.h @@ -11,7 +11,7 @@ class Not : public CItem { virtual void on_menu_popup_rotar(); virtual void save(FILE *archivo); virtual bool check_connection(); - virtual bool is_connection_area(int _a, int _b); + //virtual bool is_connection_area(int _a, int _b); private: Glib::RefPtr imageN; // 0 Glib::RefPtr imageS; // 1 diff --git a/Constructor/or.cpp b/Constructor/or.cpp index d68dc6d..c162ecb 100644 --- a/Constructor/or.cpp +++ b/Constructor/or.cpp @@ -66,7 +66,7 @@ void Or::save(FILE *archivo) // CAMBIAR TODO ESTO!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! bool Or::check_connection() { - switch (get_img_actual()) { + /*switch (get_img_actual()) { case 0: if ( is_other_connection_area( get_position_x()-5, get_position_y()+16) && is_other_connection_area( get_position_x()+get_image()->get_width()-16, +get_position_y()+get_image()->get_height() + 5) ) @@ -87,12 +87,14 @@ bool Or::check_connection() is_other_connection_area( get_position_x() + 16, get_position_y()+get_image()->get_height() + 5) ) return true; } - return false; + return false;*/ + return true; } +/* bool Or::is_connection_area(int _a, int _b) { - switch (imgActual) { + /*switch (imgActual) { case 0: if ( ( (_a <= x+10)&&(_a > x) && (_b <=y+22)&&(_b>=y+10) ) || ( (_a <= x+image->get_width()-10)&&(_a>=x+image->get_width()-22)&&(_b<=y+image->get_height()-1)&&(_b>=y+image->get_height()-10) ) ) return true; @@ -108,3 +110,4 @@ bool Or::is_connection_area(int _a, int _b) } return false; } +*/ diff --git a/Constructor/or.h b/Constructor/or.h index b0de3da..617ab1b 100644 --- a/Constructor/or.h +++ b/Constructor/or.h @@ -11,7 +11,7 @@ class Or : public CItem { virtual void on_menu_popup_rotar(); virtual void save(FILE *archivo); virtual bool check_connection(); - virtual bool is_connection_area(int _a, int _b); + //virtual ConnectorType is_connection_area(int _a, int _b); private: Glib::RefPtr imageN; // 0 Glib::RefPtr imageS; // 1 diff --git a/Constructor/propertywnd.h b/Constructor/propertywnd.h index 383552b..b510a21 100644 --- a/Constructor/propertywnd.h +++ b/Constructor/propertywnd.h @@ -6,6 +6,7 @@ #include #include #include +#include #include #include diff --git a/Constructor/pump.cpp b/Constructor/pump.cpp index c2f2edb..fbc0937 100644 --- a/Constructor/pump.cpp +++ b/Constructor/pump.cpp @@ -14,6 +14,11 @@ Pump::Pump() ref->get_widget_derived("pump_pty_wnd",pump_pty_wnd); pump_pty_wnd->pump = this; name = "bomba"; + + Connector temp; + temp.id_dest = -1; + temp.type = OUT; + connect_vec.push_back(temp); } Pump::~Pump() @@ -120,18 +125,31 @@ void Pump::save(FILE *archivo) bool Pump::check_connection() { + ConnectorType temp; switch (get_img_actual()) { case 0: - if ( is_other_connection_area( get_position_x()+get_image()->get_width()+5 , get_position_y() +16) ) - return true; + temp = is_other_connection_area( get_position_x()+get_image()->get_width()+5 , get_position_y() +16); break; case 1: - if ( is_other_connection_area( get_position_x() -5, get_position_y() +16) ) - return true; + temp = is_other_connection_area( get_position_x() -5, get_position_y() +16); } - return false; + return (is_connected = ( temp == IN) ); } +ConnectorType Pump::get_connector_type(int _a, int _b) +{ + switch (imgActual) { + case 0: + if ( (_a <= x+image->get_width()-1)&&(_a>=x+image->get_width()-10)&&(_b<=y+22)&&(_b > y) ) //derecha. + return connect_vec[0].type; + break; + case 1: + if ( (_a <= x+10)&&(_a > x)&&(_b<=y+22)&&(_b > y) ) //izquierda + return connect_vec[0].type; + } + return UNDEF; +} +/* bool Pump::is_connection_area(int _a, int _b) { switch (imgActual) { @@ -142,3 +160,4 @@ bool Pump::is_connection_area(int _a, int _b) } return false; } +*/ diff --git a/Constructor/pump.h b/Constructor/pump.h index 0fd2d07..201475f 100644 --- a/Constructor/pump.h +++ b/Constructor/pump.h @@ -19,7 +19,7 @@ class Pump : public CItem { Gdk::Color get_liquid_color(); virtual void save(FILE *archivo); virtual bool check_connection(); - virtual bool is_connection_area(int _a, int _b); + virtual ConnectorType get_connector_type(int _a, int _b); protected: double entrega; Glib::RefPtr imageE; // 0 diff --git a/Constructor/pumpptywnd.cpp b/Constructor/pumpptywnd.cpp index d4510f3..cc5adba 100644 --- a/Constructor/pumpptywnd.cpp +++ b/Constructor/pumpptywnd.cpp @@ -6,6 +6,7 @@ PumpPtyWnd::PumpPtyWnd(BaseObjectType* cobject, const Glib::RefPtrget_widget("btn_select_color",btn_select_color); refGlade->get_widget("spin_fluid",spin_fluid); refGlade->get_widget("txt_pump_name",txt_pump_name); + refGlade->get_widget("color_preview",color_preview); Glib::RefPtr ref = Gnome::Glade::Xml::create("constructor.glade", "color_select_dlg"); ref->get_widget("color_select_dlg",color_select_dlg); @@ -47,7 +48,8 @@ void PumpPtyWnd::on_dlg_select_color_cancel_clicked() } void PumpPtyWnd::on_dlg_select_color_ok_clicked() -{ +{ pump->set_liquid_color( color_select_dlg->get_colorsel()->get_current_color() ); + color_preview->modify_bg( Gtk::STATE_NORMAL , pump->get_liquid_color() ); color_select_dlg->hide(); } diff --git a/Constructor/pumpptywnd.h b/Constructor/pumpptywnd.h index 5ad59ab..296cddd 100644 --- a/Constructor/pumpptywnd.h +++ b/Constructor/pumpptywnd.h @@ -14,6 +14,7 @@ class PumpPtyWnd : public PropertyWnd{ Gtk::Entry *txt_pump_name; Gtk::Button *btn_select_color, *dlg_select_color_cancel, *dlg_select_color_ok; Gtk::ColorSelectionDialog *color_select_dlg; + Gtk::DrawingArea *color_preview; virtual void on_btn_accept_clicked(); virtual void on_btn_apply_clicked(); virtual void on_btn_select_color_clicked(); diff --git a/Constructor/splitter.cpp b/Constructor/splitter.cpp index c7ca0e6..2e11992 100644 --- a/Constructor/splitter.cpp +++ b/Constructor/splitter.cpp @@ -12,6 +12,11 @@ Splitter::Splitter() set_size_request(image->get_width(), image->get_height()); property_wnd->set_title("Propiedades del Codo"); name = "codo"; + Connector temp; + temp.id_dest = -1; + temp.type = UNDEF; + connect_vec.push_back(temp); + connect_vec.push_back(temp); } Splitter::~Splitter() @@ -96,28 +101,85 @@ bool Splitter::check_connection() { switch (get_img_actual()) { case 0: - if ( is_other_connection_area( get_position_x()-5, get_position_y()+16) && - is_other_connection_area( get_position_x()+get_image()->get_width()-16, +get_position_y()+get_image()->get_height() + 5) ) - return true; + 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 break; case 1: - if ( is_other_connection_area( get_position_x()+get_image()->get_width() - 16, get_position_y() -5) && - is_other_connection_area( get_position_x()-5, get_position_y()+get_image()->get_height()-16) ) - return true; + 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 break; case 2: - if ( is_other_connection_area( get_position_x() + 16, get_position_y() -5) && - is_other_connection_area( get_position_x()+get_image()->get_width()+5, get_position_y()+get_image()->get_height()-16) ) - return true; + 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 break; case 3: - if ( is_other_connection_area( get_position_x()+get_image()->get_width()+5, get_position_y() +16) && - is_other_connection_area( get_position_x() + 16, get_position_y()+get_image()->get_height() + 5) ) - return true; + 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 } - return false; + if (connect_vec[0].type != UNDEF && connect_vec[1].type != UNDEF) + return ( is_connected = (connect_vec[0].type == connect_vec[1].type) ); + else return false; } +ConnectorType Splitter::get_connector_type(int _a, int _b) +{ + 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); + 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); + 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); + 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); + 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); + 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); + 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); + 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); + } + } else { + switch (imgActual) { + case 0: + if ( (_a <= x+10)&&(_a > x) && (_b <=y+22)&&(_b>=y+10) ) // arriba - izquierda h + return connect_vec[0].type; + 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 connect_vec[1].type; + 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 connect_vec[0].type; + if ( (_a <= x+10)&&(_a > x)&&(_b<=y+image->get_height()-10)&&(_b>=y+image->get_height()-22) ) // abajo-izquierda h + return connect_vec[1].type; + break; + case 2: + if ( (_a <= x+22)&&(_a >= x+10) && (_b <=y+10)&&(_b > y) ) //arriba-izquierda v + return connect_vec[1].type; + 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 connect_vec[0].type; + 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 connect_vec[1].type; + if ( (_a <= x+22)&&(_a>=x+10)&&(_b<=y+image->get_height()-1)&&(_b>=y+image->get_height()-10) ) // abajo-izquierda v + return connect_vec[0].type; + } + } + return UNDEF; +} + +/* bool Splitter::is_connection_area(int _a, int _b) { switch (imgActual) { @@ -136,3 +198,4 @@ bool Splitter::is_connection_area(int _a, int _b) } return false; } +*/ diff --git a/Constructor/splitter.h b/Constructor/splitter.h index a3942a6..bcd13e4 100644 --- a/Constructor/splitter.h +++ b/Constructor/splitter.h @@ -12,7 +12,8 @@ class Splitter : public CItem { virtual void on_menu_popup_propiedades(); virtual void save(FILE *archivo); virtual bool check_connection(); - virtual bool is_connection_area(int _a, int _b); +// virtual ConnectorType is_connection_area(int _a, int _b); + virtual ConnectorType get_connector_type(int _a, int _b); private: Glib::RefPtr imageN; // 0 Glib::RefPtr imageS; // 1 diff --git a/Constructor/union.cpp b/Constructor/union.cpp index d0955bb..b7b97bd 100644 --- a/Constructor/union.cpp +++ b/Constructor/union.cpp @@ -15,6 +15,13 @@ Union::Union() property_wnd->rd_btn_union->property_visible() = true; property_wnd->lb_type->property_visible() = true; name = "union"; + Connector temp; + temp.id_dest = -1; + temp.type = IN; + connect_vec.push_back(temp); //izquierda + connect_vec.push_back(temp); //derecha + temp.type = OUT; + connect_vec.push_back(temp); //medio } Union::~Union() @@ -103,38 +110,78 @@ void Union::save(FILE *archivo) bool Union::check_connection() { + ConnectorType temp0, temp1, temp2; switch (get_img_actual()) { case 0: - if ( is_other_connection_area( get_position_x() - 5, get_position_y() +16) && - is_other_connection_area( get_position_x()+get_image()->get_width()+5, get_position_y()+16) && - is_other_connection_area( get_position_x()+get_image()->get_width()/2, get_position_y()+get_image()->get_height()+5) ) - return true; + 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); break; case 1: - if ( is_other_connection_area( get_position_x()-5, get_position_y()+get_image()->get_height()/2) && - is_other_connection_area( get_position_x()+get_image()->get_width()-16, get_position_y()-5) && - is_other_connection_area( get_position_x()+get_image()->get_width()-16, get_position_y()+get_image()->get_height()+5) ) - return true; + 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); break; case 2: - if ( is_other_connection_area( get_position_x()-5, get_position_y()+get_image()->get_height()-16) && - is_other_connection_area( get_position_x()+get_image()->get_width()/2, get_position_y()-5) && - is_other_connection_area( get_position_x()+get_image()->get_width()+5, get_position_y()+get_image()->get_height()-16) ) - return true; + 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); break; case 3: - if ( is_other_connection_area( get_position_x()+16, get_position_y()-5) && - is_other_connection_area( get_position_x()+get_image()->get_width()+5, get_position_y()+get_image()->get_height()/2) && - is_other_connection_area( get_position_x()+16, get_position_y()+get_image()->get_height()+5) ) - return true; + 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); } - return false; + if ( is_union ) { + if ( temp0 == OUT && temp1 == OUT && temp2 == IN ) + return (is_connected = true); + } else { + if ( temp0 == IN && temp1 == IN && temp2 == OUT ) + return (is_connected = true); + } + return false; +} + +ConnectorType Union::get_connector_type(int _a, int _b) +{ + switch ( imgActual) { + case 0: if ((_a <= x+10) && (_a > x+1) && (_b<= y + 22) && (_b >= y+10)) + return connect_vec[0].type; + if ((_a <= x+image->get_width()-1) && (_a >= x+image->get_width()-10)&&(_b <= y+22) && (_b >= y+10)) + return connect_vec[1].type; + if ((_a <= x+image->get_width()/2 + 5)&&( _a>= x+image->get_width()/2 - 5) && (_b<=y+image->get_height()-1)&&(_b >= y+image->get_height()-10)) + return connect_vec[2].type; + break; + case 1: if ((_a <= x+image->get_width()-10) && (_a >= x+image->get_width() -22) && (_b<= y + 10) && (_b > y )) + return connect_vec[0].type; + if ((_a <= x +10) && (_a > x )&&(_b <= y+image->get_height()/2+5 ) && (_b >= y+image->get_height()/2-5)) + return connect_vec[2].type; + 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)) + return connect_vec[1].type; + break; + case 2: if ((_a <= x+10) && (_a > x) && (_b<= y+image->get_height()-10) && (_b >= y+image->get_height()-22)) + return connect_vec[1].type; + 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)) + return connect_vec[0].type; + if ((_a <= x+image->get_width()/2 + 5)&&( _a>= x+image->get_width()/2 - 5) && (_b<=y+10)&&(_b > y)) + return connect_vec[2].type; + break; + case 3: if ((_a <= x+22) && (_a >= x+10) && (_b<= y + 10) && (_b > y )) + return connect_vec[1].type; + if ((_a <= x+22) && (_a >= x+10 )&&(_b <= y+image->get_height()-1 ) && (_b >= y+image->get_height()-10)) + return connect_vec[0].type; + if ((_a <= x+image->get_width() -1)&&( _a>= x+image->get_width()-10) && (_b<=y+image->get_height()/2+5)&&(_b >= y+image->get_height()/2-5)) + return connect_vec[2].type; + } + return UNDEF; } -bool Union::is_connection_area(int _a, int _b) +/* +ConnectorType Union::is_connection_area(int _a, int _b) { switch ( imgActual) { - case 0: if ( ((_a <= x+10) && (_a > x+1) && (_b<= y + 22) && (_b >= y+10)) || + case 0: if ( ((_a <= x+10) && (_a > x+1) && (_b<= y + 22) && (_b >= y+10)) + retur ((_a <= x+image->get_width()-1) && (_a >= x+image->get_width()-10)&&(_b <= y+22) && (_b >= y+10)) || ((_a <= x+image->get_width()/2 + 5)&&( _a>= x+image->get_width()/2 - 5) && (_b<=y+image->get_height()-1)&&(_b >= y+image->get_height()-10)) ) return true; @@ -152,4 +199,4 @@ bool Union::is_connection_area(int _a, int _b) return true; } return false; -} +}*/ diff --git a/Constructor/union.h b/Constructor/union.h index 12c3566..18aba4f 100644 --- a/Constructor/union.h +++ b/Constructor/union.h @@ -13,7 +13,8 @@ class Union : public CItem { virtual void on_menu_popup_propiedades(); virtual void save(FILE *archivo); virtual bool check_connection(); - virtual bool is_connection_area(int _a, int _b); + //virtual ConnectorType is_connection_area(int _a, int _b); + virtual ConnectorType get_connector_type(int _a, int _b); private: Glib::RefPtr imageN; // 0 Glib::RefPtr imageS; // 1