+#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<x>%d</x>\n",x);
+ sprintf(c_y,"\t\t<y>%d</y>\n",y);
+ sprintf(c_id,"%d",ID);
+ sprintf(c_img,"\t\t<orientacion>%d</orientacion>\n",imgActual);
+ Glib::ustring dato;
+ dato = "\t<drenaje nombre=\""+name+"\" id=\"";
+ dato += c_id;
+ dato += "\">\n";
+ dato += c_img;
+ dato += c_x;
+ dato += c_y;
+ dato += "\t</drenaje>\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;
+}