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();
51 } else if (detect_click_position(event->x, event->y) == OUT) {
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 CItem::logic_connect =false;
95 workplace->queue_draw();
99 void Pump::on_menu_popup_rotar()
101 GdkEventButton event;
102 event.type = GDK_BUTTON_PRESS;
104 Pump::on_button_press_event(&event);
107 void Pump::on_menu_popup_propiedades()
109 GdkEventButton event;
110 event.type = GDK_2BUTTON_PRESS;
112 Pump::on_button_press_event(&event);
115 void Pump::set_entrega(double _ent)
120 void Pump::set_liquid_color(Gdk::Color _color)
122 liquid_color = _color;
125 double Pump::get_entrega()
130 Gdk::Color Pump::get_liquid_color()
135 void Pump::save(FILE *archivo)
137 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];
140 con0 = "\t\t\t<salida>"+get_other_name(connect_vec[0].id_dest)+"</salida>\n";
141 sprintf(c_red,"\t\t\t<rojo>%d</rojo>\n",liquid_color.get_red());
142 sprintf(c_green,"\t\t\t<verde>%d</verde>\n",liquid_color.get_green());
143 sprintf(c_blue,"\t\t\t<azul>%d</azul>\n",liquid_color.get_blue());
144 sprintf(c_x,"\t\t<x>%d</x>\n",x);
145 sprintf(c_y,"\t\t<y>%d</y>\n",y);
146 sprintf(c_id,"%d",ID);
147 sprintf(c_entrega,"\t\t<entrega>%.2f</entrega>\n", entrega);
148 sprintf(c_img,"\t\t<orientacion>%d</orientacion>\n",imgActual);
150 dato = "\t<bomba nombre=\""+name+"\" id=\"";
154 dato += "\t\t<color>\n";
158 dato += "\t\t</color>\n";
159 dato += "\t\t<conector>\n"+con0+"\t\t</conector>\n";
163 dato += "\t</bomba>\n";
164 fprintf(archivo,dato.c_str());
167 bool Pump::check_connection()
171 switch (get_img_actual()) {
173 temp = is_other_connection_area( get_position_x()+get_image()->get_width()+5 , get_position_y() +16,& _item);
176 temp = is_other_connection_area( get_position_x() -5, get_position_y() +16, &_item);
178 if (is_connected = ( temp == IN) ) {
179 connect_vec[0].id_dest = _item->get_id();
185 ConnectorType Pump::get_connector_type(int _a, int _b)
189 if ( (_a <= x+image->get_width()-1)&&(_a>=x+image->get_width()-10)&&(_b<=y+22)&&(_b > y) ) //derecha.
190 return connect_vec[0].type;
193 if ( (_a <= x+10)&&(_a > x)&&(_b<=y+22)&&(_b > y) ) //izquierda
194 return connect_vec[0].type;
199 void Pump::set_default_connector()
201 connect_vec[0].type = OUT;
204 void Pump::get_in_logic_connect_position(int& _a, int& _b)
210 void Pump::get_out_logic_connect_position(int& _a, int& _b)
216 ConnectorType Pump::detect_click_position(int _a, int _b)
220 if ( (_a <=image->get_width())&&(_a>=image->get_width()-32)&&(_b<=16)&&(_b >= 0) )
222 if ( (_a <= image->get_width())&&(_a>=image->get_width()-32)&&(_b<=32)&&(_b > 16) )
226 if ( (_a <= 32)&&(_a>=0)&&(_b<=16)&&(_b >= 0) )
228 if ( (_a <= 32)&&(_a>=0)&&(_b<=32)&&(_b > 16) )
234 void Pump::update_logic_position()
244 in_x = x + image->get_width()-16;