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);
40 bool Pump::on_button_press_event(GdkEventButton *event)
43 if ((event->type == GDK_BUTTON_PRESS) && ( event->button == 1)) {
44 list_pointed->push_back(name);
45 combo_entry->set_popdown_strings(*list_pointed);
46 combo_entry->get_entry()->set_text (name);
47 WorkPlace::pointed = ID;
48 if (CItem::logic_connect && CItem::gate_id != -1) {
49 if ( detect_click_position((int)event->x, (int)event->y) == IN) {
50 tmp_line.logic_id = workplace->get_logic_item(CItem::gate_id)->get_id();
51 tmp_line.store_id = ID;
52 workplace->lista_lineas_in.push_back(tmp_line);
53 workplace->queue_draw();
54 } else if (detect_click_position((int)event->x, (int)event->y) == OUT) {
55 tmp_line.logic_id = workplace->get_logic_item(CItem::gate_id)->get_id();
56 tmp_line.store_id = ID;
57 workplace->lista_lineas_out.push_back(tmp_line);
58 workplace->queue_draw();
63 if ((event->type == GDK_BUTTON_PRESS) && ( event->button ==2)){
65 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);
78 in_x = x + image->get_width()-16;
83 set_size_request(image->get_width(),image->get_height());
84 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);
87 if ((event->type == GDK_BUTTON_PRESS) && ( event->button == 3)){
88 menu_popup.popup(event->button, event->time);
89 return true; //It has been handled.
92 if ((event->type == GDK_2BUTTON_PRESS) && (event->button ==1)){
93 pump_pty_wnd->spin_fluid->set_value( entrega );
94 pump_pty_wnd->txt_pump_name->set_text( name );
97 workplace->queue_draw();
101 void Pump::on_menu_popup_rotar()
103 GdkEventButton event;
104 event.type = GDK_BUTTON_PRESS;
106 Pump::on_button_press_event(&event);
109 void Pump::on_menu_popup_propiedades()
111 GdkEventButton event;
112 event.type = GDK_2BUTTON_PRESS;
114 Pump::on_button_press_event(&event);
117 void Pump::set_entrega(double _ent)
122 void Pump::set_liquid_color(Gdk::Color _color)
124 liquid_color = _color;
127 double Pump::get_entrega()
132 Gdk::Color Pump::get_liquid_color()
137 void Pump::save(FILE *archivo)
139 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];
142 con0 = "\t\t\t<salida>"+get_other_name(connect_vec[0].id_dest)+"</salida>\n";
143 sprintf(c_red,"\t\t\t<rojo>%d</rojo>\n",liquid_color.get_red());
144 sprintf(c_green,"\t\t\t<verde>%d</verde>\n",liquid_color.get_green());
145 sprintf(c_blue,"\t\t\t<azul>%d</azul>\n",liquid_color.get_blue());
146 sprintf(c_x,"\t\t<x>%d</x>\n",x);
147 sprintf(c_y,"\t\t<y>%d</y>\n",y);
148 sprintf(c_id,"%d",ID);
149 sprintf(c_entrega,"\t\t<entrega>%.2f</entrega>\n", entrega);
150 sprintf(c_img,"\t\t<orientacion>%d</orientacion>\n",imgActual);
152 dato = "\t<bomba nombre=\""+name+"\" id=\"";
156 dato += "\t\t<color>\n";
160 dato += "\t\t</color>\n";
161 dato += "\t\t<conector>\n"+con0+"\t\t</conector>\n";
165 dato += "\t</bomba>\n";
166 fprintf(archivo,dato.c_str());
169 bool Pump::check_connection()
173 switch (get_img_actual()) {
175 temp = is_other_connection_area( get_position_x()+get_image()->get_width()+5 , get_position_y() +16,& _item);
178 temp = is_other_connection_area( get_position_x() -5, get_position_y() +16, &_item);
180 if (is_connected = ( temp == IN) ) {
181 connect_vec[0].id_dest = _item->get_id();
187 ConnectorType Pump::get_connector_type(int _a, int _b)
191 if ( (_a <= x+image->get_width()-1)&&(_a>=x+image->get_width()-10)&&(_b<=y+22)&&(_b > y) ) //derecha.
192 return connect_vec[0].type;
195 if ( (_a <= x+10)&&(_a > x)&&(_b<=y+22)&&(_b > y) ) //izquierda
196 return connect_vec[0].type;
201 void Pump::set_default_connector()
203 connect_vec[0].type = OUT;
206 void Pump::get_in_logic_connect_position(int& _a, int& _b)
212 void Pump::get_out_logic_connect_position(int& _a, int& _b)
218 ConnectorType Pump::detect_click_position(int _a, int _b)
222 if ( (_a <=image->get_width())&&(_a>=image->get_width()-32)&&(_b<=16)&&(_b >= 0) )
224 if ( (_a <= image->get_width())&&(_a>=image->get_width()-32)&&(_b<=32)&&(_b > 16) )
228 if ( (_a <= 32)&&(_a>=0)&&(_b<=16)&&(_b >= 0) )
230 if ( (_a <= 32)&&(_a>=0)&&(_b<=32)&&(_b > 16) )
236 void Pump::update_logic_position()
246 in_x = x + image->get_width()-16;