2 #include "pumpptywnd.h"
4 Pump::Pump(int orientacion)
11 imageE = Gdk::Pixbuf::create_from_file(PACKAGE_DATA_DIR"/plaqui-constructor/pixmaps/bomba_e.png");
12 imageO = Gdk::Pixbuf::create_from_file(PACKAGE_DATA_DIR"/plaqui-constructor/pixmaps/bomba_o.png");
13 null = Gdk::Pixbuf::create_from_file(PACKAGE_DATA_DIR"/plaqui-constructor/pixmaps/bomba_null.png");
14 imgActual = orientacion;
23 set_size_request(image->get_width(), image->get_height());
25 Glib::RefPtr<Gnome::Glade::Xml> ref = Gnome::Glade::Xml::create(PACKAGE_DATA_DIR"/plaqui-constructor/dialogs/constructor.glade", "pump_pty_wnd");
26 ref->get_widget_derived("pump_pty_wnd",pump_pty_wnd);
27 pump_pty_wnd->pump = this;
33 connect_vec.push_back(temp);
41 bool Pump::on_button_press_event(GdkEventButton *event)
44 if ((event->type == GDK_BUTTON_PRESS) && ( event->button == 1)) {
45 list_pointed->push_back(name);
46 combo_entry->set_popdown_strings(*list_pointed);
47 combo_entry->get_entry()->set_text (name);
48 WorkPlace::pointed = ID;
49 if (CItem::logic_connect && CItem::gate_id != -1) {
50 if ( detect_click_position((int)event->x, (int)event->y) == IN) {
51 tmp_line.logic_id = workplace->get_logic_item(CItem::gate_id)->get_id();
52 workplace->get_logic_item(CItem::gate_id)->set_out_connected(true);
53 tmp_line.store_id = ID;
54 workplace->lista_lineas_in.push_back(tmp_line);
55 workplace->queue_draw();
56 } else if (detect_click_position((int)event->x, (int)event->y) == OUT) {
57 tmp_line.logic_id = workplace->get_logic_item(CItem::gate_id)->get_id();
58 tmp_line.store_id = ID;
59 workplace->lista_lineas_out.push_back(tmp_line);
60 workplace->queue_draw();
66 if ((event->type == GDK_BUTTON_PRESS) && ( event->button ==2)){
68 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);
81 in_x = x + image->get_width()-16;
86 set_size_request(image->get_width(),image->get_height());
87 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);
90 if ((event->type == GDK_BUTTON_PRESS) && ( event->button == 3)){
91 menu_popup.popup(event->button, event->time);
92 return true; //It has been handled.
95 if ((event->type == GDK_2BUTTON_PRESS) && (event->button ==1)){
96 pump_pty_wnd->spin_fluid->set_value( entrega );
97 pump_pty_wnd->txt_pump_name->set_text( name );
100 workplace->queue_draw();
104 void Pump::on_menu_popup_rotar()
106 GdkEventButton event;
107 event.type = GDK_BUTTON_PRESS;
109 Pump::on_button_press_event(&event);
112 void Pump::on_menu_popup_propiedades()
114 GdkEventButton event;
115 event.type = GDK_2BUTTON_PRESS;
117 Pump::on_button_press_event(&event);
120 void Pump::set_entrega(double _ent)
125 void Pump::set_liquid_color(Gdk::Color _color)
127 liquid_color = _color;
130 double Pump::get_entrega()
135 Gdk::Color Pump::get_liquid_color()
140 void Pump::save(FILE *archivo)
142 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];
145 con0 = "\t\t\t<salida>"+get_other_name(connect_vec[0].id_dest)+"</salida>\n";
146 sprintf(c_red,"\t\t\t<rojo>%d</rojo>\n",liquid_color.get_red());
147 sprintf(c_green,"\t\t\t<verde>%d</verde>\n",liquid_color.get_green());
148 sprintf(c_blue,"\t\t\t<azul>%d</azul>\n",liquid_color.get_blue());
149 sprintf(c_x,"\t\t<x>%d</x>\n",x);
150 sprintf(c_y,"\t\t<y>%d</y>\n",y);
151 sprintf(c_id,"%d",ID);
152 sprintf(c_entrega,"\t\t<entrega>%.2f</entrega>\n", entrega);
153 sprintf(c_img,"\t\t<orientacion>%d</orientacion>\n",imgActual);
155 dato = "\t<bomba nombre=\""+name+"\" id=\"";
159 dato += "\t\t<color>\n";
163 dato += "\t\t</color>\n";
164 dato += "\t\t<conector>\n"+con0+"\t\t</conector>\n";
168 dato += "\t</bomba>\n";
169 fprintf(archivo,dato.c_str());
172 bool Pump::check_connection()
176 switch (get_img_actual()) {
178 temp = is_other_connection_area( get_position_x()+get_image()->get_width()+5 , get_position_y() +16,& _item);
181 temp = is_other_connection_area( get_position_x() -5, get_position_y() +16, &_item);
183 if (is_connected = ( temp == IN) ) {
184 connect_vec[0].id_dest = _item->get_id();
190 ConnectorType Pump::get_connector_type(int _a, int _b)
194 if ( (_a <= x+image->get_width()-1)&&(_a>=x+image->get_width()-10)&&(_b<=y+22)&&(_b > y) ) //derecha.
195 return connect_vec[0].type;
198 if ( (_a <= x+10)&&(_a > x)&&(_b<=y+22)&&(_b > y) ) //izquierda
199 return connect_vec[0].type;
204 void Pump::set_default_connector()
206 connect_vec[0].type = OUT;
209 void Pump::get_in_logic_connect_position(int& _a, int& _b)
215 void Pump::get_out_logic_connect_position(int& _a, int& _b)
221 ConnectorType Pump::detect_click_position(int _a, int _b)
225 if ( (_a <=image->get_width())&&(_a>=image->get_width()-32)&&(_b<=16)&&(_b >= 0) )
227 if ( (_a <= image->get_width())&&(_a>=image->get_width()-32)&&(_b<=32)&&(_b > 16) )
231 if ( (_a <= 32)&&(_a>=0)&&(_b<=16)&&(_b >= 0) )
233 if ( (_a <= 32)&&(_a>=0)&&(_b<=32)&&(_b > 16) )
239 void Pump::update_logic_position()
249 in_x = x + image->get_width()-16;