2 #include "pumpptywnd.h"
5 Pump::Pump(int orientacion)
12 imageE = Gdk::Pixbuf::create_from_file(PACKAGE_DATA_DIR"/plaqui-constructor/pixmaps/bomba_e.png");
13 imageO = Gdk::Pixbuf::create_from_file(PACKAGE_DATA_DIR"/plaqui-constructor/pixmaps/bomba_o.png");
14 null = Gdk::Pixbuf::create_from_file(PACKAGE_DATA_DIR"/plaqui-constructor/pixmaps/bomba_null.png");
15 imgActual = orientacion;
24 set_size_request(image->get_width(), image->get_height());
26 Glib::RefPtr<Gnome::Glade::Xml> ref = Gnome::Glade::Xml::create(PACKAGE_DATA_DIR"/plaqui-constructor/dialogs/constructor.glade", "pump_pty_wnd");
27 ref->get_widget_derived("pump_pty_wnd",pump_pty_wnd);
28 pump_pty_wnd->pump = this;
34 connect_vec.push_back(temp);
42 bool Pump::on_button_press_event(GdkEventButton *event)
45 if ((event->type == GDK_BUTTON_PRESS) && ( event->button == 1)) {
46 list_pointed->push_back(name);
47 combo_entry->set_popdown_strings(*list_pointed);
48 combo_entry->get_entry()->set_text (name);
49 WorkPlace::pointed = ID;
50 std::cout<< "CItem::gate_id = "<<CItem::gate_id<<std::endl;
51 if (CItem::logic_connect && CItem::gate_id != -1) {
52 if ( detect_click_position((int)event->x, (int)event->y) == IN && !workplace->get_logic_item(CItem::gate_id)->get_out_logic_connect()) {
53 tmp_line.logic_id = CItem::gate_id;
54 workplace->get_logic_item(CItem::gate_id)->set_out_connected(true);
55 tmp_line.store_id = ID;
56 workplace->lista_lineas_in.push_back(tmp_line);
57 workplace->queue_draw();
58 } else if (detect_click_position((int)event->x, (int)event->y) == OUT ) {
59 if (dynamic_cast<Not *>(workplace->get_logic_item(CItem::gate_id))) {
60 if ( !dynamic_cast<Not *>(workplace->get_logic_item(CItem::gate_id))->get_in_logic_connect()) {
61 workplace->get_logic_item(CItem::gate_id)->set_in_connected(true);
62 tmp_line.logic_id = CItem::gate_id;
63 tmp_line.store_id = ID;
64 workplace->lista_lineas_out.push_back(tmp_line);
65 workplace->queue_draw();
68 tmp_line.logic_id = CItem::gate_id;
69 tmp_line.store_id = ID;
70 workplace->lista_lineas_out.push_back(tmp_line);
71 workplace->queue_draw();
78 sprintf(f," Entrega:%.1f",entrega);
80 status_bar->push ( text, 0);
83 if ((event->type == GDK_BUTTON_PRESS) && ( event->button ==2)){
85 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);
98 in_x = x + image->get_width()-16;
103 set_size_request(image->get_width(),image->get_height());
104 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);
107 if ((event->type == GDK_BUTTON_PRESS) && ( event->button == 3)){
108 menu_popup.popup(event->button, event->time);
109 return true; //It has been handled.
112 if ((event->type == GDK_2BUTTON_PRESS) && (event->button ==1)){
113 pump_pty_wnd->spin_fluid->set_value( entrega );
114 pump_pty_wnd->txt_pump_name->set_text( name );
115 pump_pty_wnd->show();
117 workplace->queue_draw();
121 void Pump::on_menu_popup_rotar()
123 GdkEventButton event;
124 event.type = GDK_BUTTON_PRESS;
126 Pump::on_button_press_event(&event);
129 void Pump::on_menu_popup_propiedades()
131 GdkEventButton event;
132 event.type = GDK_2BUTTON_PRESS;
134 Pump::on_button_press_event(&event);
137 void Pump::set_entrega(double _ent)
142 void Pump::set_liquid_color(Gdk::Color _color)
144 liquid_color = _color;
147 double Pump::get_entrega()
152 Gdk::Color Pump::get_liquid_color()
157 void Pump::save(FILE *archivo)
159 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];
162 con0 = "\t\t\t<salida>"+get_other_name(connect_vec[0].id_dest)+"</salida>\n";
163 sprintf(c_red,"\t\t\t<rojo>%d</rojo>\n",liquid_color.get_red());
164 sprintf(c_green,"\t\t\t<verde>%d</verde>\n",liquid_color.get_green());
165 sprintf(c_blue,"\t\t\t<azul>%d</azul>\n",liquid_color.get_blue());
166 sprintf(c_x,"\t\t<x>%d</x>\n",x);
167 sprintf(c_y,"\t\t<y>%d</y>\n",y);
168 sprintf(c_id,"%d",ID);
169 sprintf(c_entrega,"\t\t<entrega>%.2f</entrega>\n", entrega);
170 sprintf(c_img,"\t\t<orientacion>%d</orientacion>\n",imgActual);
172 dato = "\t<bomba nombre=\""+name+"\" id=\"";
176 dato += "\t\t<color>\n";
180 dato += "\t\t</color>\n";
181 dato += "\t\t<conector>\n"+con0+"\t\t</conector>\n";
185 dato += "\t</bomba>\n";
186 fprintf(archivo,dato.c_str());
189 bool Pump::check_connection()
193 switch (get_img_actual()) {
195 temp = is_other_connection_area( get_position_x()+get_image()->get_width()+5 , get_position_y() +16,& _item);
198 temp = is_other_connection_area( get_position_x() -5, get_position_y() +16, &_item);
200 if (is_connected = ( temp == IN) ) {
201 std::cout << "PUMP " << _item->get_id() << std::endl;
202 connect_vec[0].id_dest = _item->get_id();
208 ConnectorType Pump::get_connector_type(int _a, int _b)
212 if ( (_a <= x+image->get_width()-1)&&(_a>=x+image->get_width()-10)&&(_b<=y+22)&&(_b > y) ) //derecha.
213 return connect_vec[0].type;
216 if ( (_a <= x+10)&&(_a > x)&&(_b<=y+22)&&(_b > y) ) //izquierda
217 return connect_vec[0].type;
222 void Pump::set_default_connector()
224 connect_vec[0].type = OUT;
227 void Pump::get_in_logic_connect_position(int& _a, int& _b)
233 void Pump::get_out_logic_connect_position(int& _a, int& _b)
239 ConnectorType Pump::detect_click_position(int _a, int _b)
243 if ( (_a <=image->get_width())&&(_a>=image->get_width()-32)&&(_b<=16)&&(_b >= 0) )
245 if ( (_a <= image->get_width())&&(_a>=image->get_width()-32)&&(_b<=32)&&(_b > 16) )
249 if ( (_a <= 32)&&(_a>=0)&&(_b<=16)&&(_b >= 0) )
251 if ( (_a <= 32)&&(_a>=0)&&(_b<=32)&&(_b > 16) )
257 void Pump::update_logic_position()
267 in_x = x + image->get_width()-16;