]> git.llucax.com Git - z.facultad/75.42/plaqui.git/blob - Constructor/pump.cpp
- Se agrega el método HTTPRequest::method_str() para obtener el método como un
[z.facultad/75.42/plaqui.git] / Constructor / pump.cpp
1 #include "pump.h"
2 #include "pumpptywnd.h"
3
4 Pump::Pump()
5 {
6         imageE = Gdk::Pixbuf::create_from_file("bomba_e.png");
7         imageO = Gdk::Pixbuf::create_from_file("bomba_o.png");
8         null = Gdk::Pixbuf::create_from_file("bomba_null.png");
9         imgActual = 0;
10         image = imageE;
11         set_size_request(image->get_width(), image->get_height());
12
13         Glib::RefPtr<Gnome::Glade::Xml> ref = Gnome::Glade::Xml::create("constructor.glade", "item_pty_wnd");
14         ref->get_widget_derived("item_pty_wnd",pump_pty_wnd);
15         pump_pty_wnd->pump = this;
16         pump_pty_wnd->set_title("Propiedades de la Bomba");     
17         name = "bomba";
18 }
19
20 Pump::~Pump()
21 {
22 }
23
24 bool Pump::on_button_press_event(GdkEventButton *event)
25 {
26         if ((event->type == GDK_BUTTON_PRESS) && ( event->button == 1))
27                 combo_entry->set_text(name);
28         
29         if ((event->type == GDK_BUTTON_PRESS) && ( event->button ==2)){
30                 image = null; 
31                 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);
32                 imgActual++;
33                 switch (imgActual) {
34                         case 1:
35                                 image = imageO;
36                                 break;
37                         default: 
38                                 imgActual = 0;
39                                 image = imageE;                 
40                 }
41                 set_size_request(image->get_width(),image->get_height());
42                 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);
43         }
44         
45         if ((event->type == GDK_BUTTON_PRESS) && ( event->button == 3)){
46                 menu_popup.popup(event->button, event->time);
47                  return true; //It has been handled.
48         }
49         
50         if ((event->type == GDK_2BUTTON_PRESS) && (event->button ==1)){
51                 pump_pty_wnd->spin_caudal->set_value( entrega );
52                 pump_pty_wnd->txt_item_name->set_text( name );
53                 pump_pty_wnd->show();
54         }               
55         return true;
56 }
57
58 void Pump::on_menu_popup_rotar()
59 {
60         GdkEventButton event; 
61                 event.type = GDK_BUTTON_PRESS;
62                 event.button = 2;
63         Pump::on_button_press_event(&event);
64 }
65
66 void Pump::on_menu_popup_propiedades()
67 {
68         GdkEventButton event; 
69                 event.type = GDK_2BUTTON_PRESS;
70                 event.button = 1;
71         Pump::on_button_press_event(&event);
72 }
73
74 void Pump::set_entrega(double _ent)
75 {
76         entrega = _ent;
77 }
78
79 double Pump::get_entrega()
80 {
81         return entrega;
82 }
83
84 void Pump::save(FILE *archivo)
85 {
86         char c_id[50], c_entrega[50], c_x[50], c_y[50], c_img[50];
87         sprintf(c_x,"\t\t<x>%d</x>\n",x);
88         sprintf(c_y,"\t\t<y>%d</y>\n",y);
89         sprintf(c_id,"%d",ID);
90         sprintf(c_entrega,"\t\t<entrega>%.2f</entrega>\n", entrega);
91         sprintf(c_img,"\t\t<orientacion>%d</orientacion>\n",imgActual);
92         Glib::ustring dato;
93         dato = "\t<bomba nombre=\""+name+"\" id=\"";
94         dato += c_id;
95         dato += "\">\n";
96         dato += c_entrega;
97         dato += c_img;
98         dato += c_x; 
99         dato += c_y;
100         dato += "\t</bomba>\n";
101         fprintf(archivo,dato.c_str());  
102 }
103
104 bool Pump::check_connection()
105 {
106         switch (get_img_actual()) {
107                 case 0:
108                         if ( is_other_connection_area( get_position_x()+get_image()->get_width()+5 , get_position_y() +16) )
109                                 return true;                            
110                         break;
111                 case 1:
112                         if ( is_other_connection_area( get_position_x() -5, get_position_y() +16) )
113                                 return true;
114         }
115         return false;
116 }
117
118 bool Pump::is_connection_area(int _a, int _b)
119 {
120         switch (imgActual) {
121                 case 0: if ( (_a <= x+image->get_width()-1)&&(_a>=x+image->get_width()-10)&&(_b<=y+22)&&(_b > y) ) 
122                                                 return true;
123                 case 1: if ( (_a <= x+10)&&(_a > x)&&(_b<=y+22)&&(_b > y) ) 
124                                                 return true;
125         }
126         return false;
127 }