2 #include "pumpptywnd.h"
4 Pump::Pump(int orientacion)
10 imageE = Gdk::Pixbuf::create_from_file(PACKAGE_DATA_DIR"/plaqui-constructor/pixmaps/bomba_e.png");
11 imageO = Gdk::Pixbuf::create_from_file(PACKAGE_DATA_DIR"/plaqui-constructor/pixmaps/bomba_o.png");
12 null = Gdk::Pixbuf::create_from_file(PACKAGE_DATA_DIR"/plaqui-constructor/pixmaps/bomba_null.png");
13 imgActual = orientacion;
22 set_size_request(image->get_width(), image->get_height());
24 Glib::RefPtr<Gnome::Glade::Xml> ref = Gnome::Glade::Xml::create(PACKAGE_DATA_DIR"/plaqui-constructor/dialogs/constructor.glade", "pump_pty_wnd");
25 ref->get_widget_derived("pump_pty_wnd",pump_pty_wnd);
26 pump_pty_wnd->pump = this;
32 connect_vec.push_back(temp);
39 bool Pump::on_button_press_event(GdkEventButton *event)
42 if ((event->type == GDK_BUTTON_PRESS) && ( event->button == 1)) {
43 combo_entry->set_text(name);
44 WorkPlace::pointed = ID;
45 if (CItem::logic_connect) {
46 if ( detect_click_position(event->x, event->y) == IN) {
47 tmp_line.logic = workplace->get_logic_item(CItem::gate_id);
48 tmp_line.store = this;
49 workplace->lista_lineas_in.push_back(tmp_line);
50 workplace->queue_draw();
52 tmp_line.logic = workplace->get_logic_item(CItem::gate_id);
53 tmp_line.store = this;
54 workplace->lista_lineas_out.push_back(tmp_line);
55 workplace->queue_draw();
60 if ((event->type == GDK_BUTTON_PRESS) && ( event->button ==2)){
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);
75 in_x = x + image->get_width()-16;
80 set_size_request(image->get_width(),image->get_height());
81 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);
84 if ((event->type == GDK_BUTTON_PRESS) && ( event->button == 3)){
85 menu_popup.popup(event->button, event->time);
86 return true; //It has been handled.
89 if ((event->type == GDK_2BUTTON_PRESS) && (event->button ==1)){
90 pump_pty_wnd->spin_fluid->set_value( entrega );
91 pump_pty_wnd->txt_pump_name->set_text( name );
94 workplace->queue_draw();
98 void Pump::on_menu_popup_rotar()
100 GdkEventButton event;
101 event.type = GDK_BUTTON_PRESS;
103 Pump::on_button_press_event(&event);
106 void Pump::on_menu_popup_propiedades()
108 GdkEventButton event;
109 event.type = GDK_2BUTTON_PRESS;
111 Pump::on_button_press_event(&event);
114 void Pump::set_entrega(double _ent)
119 void Pump::set_liquid_color(Gdk::Color _color)
121 liquid_color = _color;
124 double Pump::get_entrega()
129 Gdk::Color Pump::get_liquid_color()
134 void Pump::save(FILE *archivo)
136 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];
139 con0 = "\t\t\t<salida>"+get_other_name(connect_vec[0].id_dest)+"</salida>\n";
140 sprintf(c_red,"\t\t\t<rojo>%d</rojo>\n",liquid_color.get_red());
141 sprintf(c_green,"\t\t\t<verde>%d</verde>\n",liquid_color.get_green());
142 sprintf(c_blue,"\t\t\t<azul>%d</azul>\n",liquid_color.get_blue());
143 sprintf(c_x,"\t\t<x>%d</x>\n",x);
144 sprintf(c_y,"\t\t<y>%d</y>\n",y);
145 sprintf(c_id,"%d",ID);
146 sprintf(c_entrega,"\t\t<entrega>%.2f</entrega>\n", entrega);
147 sprintf(c_img,"\t\t<orientacion>%d</orientacion>\n",imgActual);
149 dato = "\t<bomba nombre=\""+name+"\" id=\"";
153 dato += "\t\t<color>\n";
157 dato += "\t\t</color>\n";
158 dato += "\t\t<conector>\n"+con0+"\t\t</conector>\n";
162 dato += "\t</bomba>\n";
163 fprintf(archivo,dato.c_str());
166 bool Pump::check_connection()
170 switch (get_img_actual()) {
172 temp = is_other_connection_area( get_position_x()+get_image()->get_width()+5 , get_position_y() +16,& _item);
175 temp = is_other_connection_area( get_position_x() -5, get_position_y() +16, &_item);
177 if (is_connected = ( temp == IN) ) {
178 connect_vec[0].id_dest = _item->get_id();
184 ConnectorType Pump::get_connector_type(int _a, int _b)
188 if ( (_a <= x+image->get_width()-1)&&(_a>=x+image->get_width()-10)&&(_b<=y+22)&&(_b > y) ) //derecha.
189 return connect_vec[0].type;
192 if ( (_a <= x+10)&&(_a > x)&&(_b<=y+22)&&(_b > y) ) //izquierda
193 return connect_vec[0].type;
198 void Pump::set_default_connector()
200 connect_vec[0].type = OUT;
203 void Pump::get_in_logic_connect_position(int& _a, int& _b)
209 void Pump::get_out_logic_connect_position(int& _a, int& _b)
215 ConnectorType Pump::detect_click_position(int _a, int _b)
219 if ( (_a <=image->get_width())&&(_a>=image->get_width()-32)&&(_b<=16)&&(_b >= 0) )
221 if ( (_a <= image->get_width())&&(_a>=image->get_width()-32)&&(_b<=32)&&(_b > 16) )
225 if ( (_a <= 32)&&(_a>=0)&&(_b<=16)&&(_b >= 0) )
227 if ( (_a <= 32)&&(_a>=0)&&(_b<=32)&&(_b > 16) )
233 void Pump::update_logic_position()
243 in_x = x + image->get_width()-16;