2 #include "cisternptywnd.h"
6 imageE = Gdk::Pixbuf::create_from_file("tanque_e.png");
7 imageO = Gdk::Pixbuf::create_from_file("tanque_o.png");
8 null = Gdk::Pixbuf::create_from_file("tanque_null.png");
11 set_size_request(image->get_width(), image->get_height());
13 Glib::RefPtr<Gnome::Glade::Xml> ref = Gnome::Glade::Xml::create("constructor.glade", "cistern_pty_wnd");
14 ref->get_widget_derived("cistern_pty_wnd",cistern_pty_wnd);
15 cistern_pty_wnd->cistern = this;
16 cistern_pty_wnd->set_title("Propiedades del Tanque");
22 connect_vec.push_back(temp); // entrada arriba
24 connect_vec.push_back(temp); // salida abajo
31 bool Cistern::on_button_press_event(GdkEventButton *event)
36 if ((event->type == GDK_BUTTON_PRESS) && ( event->button == 1)) {
37 combo_entry->set_text(name);
38 if (CItem::logic_connect) {
39 std::cout<<workplace<<std::endl;
40 tmp_line.logic = workplace->get_logic_item(CItem::quien);
41 tmp_line.store = this;
42 workplace->lista_lineas.push_back(tmp_line);
43 workplace->on_expose_event(&e);
46 CItem::logic_connect = false;
49 if ((event->type == GDK_BUTTON_PRESS) && ( event->button ==2)){
51 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);
61 set_size_request(image->get_width(),image->get_height());
62 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);
65 if ((event->type == GDK_BUTTON_PRESS) && ( event->button == 3)){
66 menu_popup.popup(event->button, event->time);
67 return true; //It has been handled.
70 if ((event->type == GDK_2BUTTON_PRESS) && (event->button ==1)){
71 cistern_pty_wnd->spin_capacidad->set_value( capacidad );
72 cistern_pty_wnd->spin_inicial->set_value( contenido_inicial );
73 cistern_pty_wnd->txt_cistern_name->set_text( name );
74 cistern_pty_wnd->show();
79 void Cistern::on_menu_popup_rotar()
82 event.type = GDK_BUTTON_PRESS;
84 Cistern::on_button_press_event(&event);
87 void Cistern::on_menu_popup_propiedades()
90 event.type = GDK_2BUTTON_PRESS;
92 Cistern::on_button_press_event(&event);
95 void Cistern::set_capacidad(double _cap)
100 void Cistern::set_liquid_color(Gdk::Color _color)
102 liquid_color = _color;
105 void Cistern::set_contenido_inicial(double _ini)
107 contenido_inicial = _ini;
110 double Cistern::get_capacidad()
115 double Cistern::get_contenido_inicial()
117 return contenido_inicial;
120 Gdk::Color Cistern::get_liquid_color()
125 void Cistern::save(FILE *archivo)
127 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];
128 Glib::ustring con0, con1;
129 con0 = "\t\t\t<entrada>"+get_other_name(connect_vec[0].id_dest)+"</entrada>\n";
130 con1 = "\t\t\t<salida>"+get_other_name(connect_vec[1].id_dest)+"</salida>\n";
131 sprintf(c_red,"\t\t\t<rojo>%d</rojo>\n",liquid_color.get_red());
132 sprintf(c_green,"\t\t\t<verde>%d</verde>\n",liquid_color.get_green());
133 sprintf(c_blue,"\t\t\t<azul>%d</azul>\n",liquid_color.get_blue());
134 sprintf(c_x,"\t\t<x>%d</x>\n",x);
135 sprintf(c_y,"\t\t<y>%d</y>\n",y);
136 sprintf(c_id,"%d",ID);
137 sprintf(c_cap,"\t\t<capacidad>%.2f</capacidad>\n", capacidad);
138 sprintf(c_ini,"\t\t<inicial>%.2f</inicial>\n", contenido_inicial);
139 sprintf(c_img,"\t\t<orientacion>%d</orientacion>\n",imgActual);
141 dato = "\t<tanque nombre=\""+name+"\" id=\"";
146 dato += "\t\t<color>\n";
150 dato += "\t\t</color>\n";
151 dato += "\t\t<conector>\n"+con0+con1+"\t\t</conector>\n";
155 dato += "\t</tanque>\n";
156 fprintf(archivo,dato.c_str());
159 bool Cistern::check_connection()
161 CItem * _item, *_item1;
162 ConnectorType temp0, temp1;
163 switch (get_img_actual()) {
165 temp0 = is_other_connection_area( get_position_x() + 16, get_position_y() - 5, &_item);//arriba - entrada
166 temp1 = is_other_connection_area( get_position_x()+get_image()->get_width() + 5 , get_position_y()+get_image()->get_height() -16, &_item1);//abajo - salida
169 temp0 = is_other_connection_area( get_position_x()+get_image()->get_width() - 16, get_position_y() - 5, &_item);//arriba - entrada
170 temp1 = is_other_connection_area( get_position_x() -5, get_position_y()+get_image()->get_height()-16, &_item1); //abajo - salida
172 if (temp0 == OUT && temp1 == IN) {
173 connect_vec[0].id_dest = _item->get_id();
174 connect_vec[1].id_dest = _item1->get_id();
175 return (is_connected = true);
180 ConnectorType Cistern::get_connector_type(int _a, int _b)
183 case 0: if ( (_a <= x+22)&&(_a>=x+10)&&(_b<=y+10)&&(_b > y) )//arriba
184 return connect_vec[0].type;
185 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
186 return connect_vec[1].type;
188 case 1: if ( (_a <= x+image->get_width()-10)&&(_a>=x+image->get_width()-22)&&(_b<=y+10)&&(_b > y) )//arriba
189 return connect_vec[0].type;
190 if ( (_a <= x +10)&&(_a > x)&&(_b<=y+image->get_height()-10)&&(_b >=y+image->get_height()-22) )//abajo
191 return connect_vec[1].type;
196 void Cistern::set_default_connector()
198 connect_vec[0].type = IN;
199 connect_vec[1].type = OUT;