]> git.llucax.com Git - z.facultad/75.42/plaqui.git/blob - Constructor/pump.cpp
* Cliente carga todos los widgets (falta exclusa!)
[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", "pump_pty_wnd");
14         ref->get_widget_derived("pump_pty_wnd",pump_pty_wnd);
15         pump_pty_wnd->pump = this;
16         name = "bomba";
17 }
18
19 Pump::~Pump()
20 {
21 }
22
23 bool Pump::on_button_press_event(GdkEventButton *event)
24 {
25         if ((event->type == GDK_BUTTON_PRESS) && ( event->button == 1))
26                 combo_entry->set_text(name);
27         
28         if ((event->type == GDK_BUTTON_PRESS) && ( event->button ==2)){
29                 image = null; 
30                 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);
31                 imgActual++;
32                 switch (imgActual) {
33                         case 1:
34                                 image = imageO;
35                                 break;
36                         default: 
37                                 imgActual = 0;
38                                 image = imageE;                 
39                 }
40                 set_size_request(image->get_width(),image->get_height());
41                 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);
42         }
43         
44         if ((event->type == GDK_BUTTON_PRESS) && ( event->button == 3)){
45                 menu_popup.popup(event->button, event->time);
46                  return true; //It has been handled.
47         }
48         
49         if ((event->type == GDK_2BUTTON_PRESS) && (event->button ==1)){
50                 pump_pty_wnd->spin_fluid->set_value( entrega );
51                 pump_pty_wnd->txt_pump_name->set_text( name );
52                 pump_pty_wnd->show();
53         }               
54         return true;
55 }
56
57 void Pump::on_menu_popup_rotar()
58 {
59         GdkEventButton event; 
60                 event.type = GDK_BUTTON_PRESS;
61                 event.button = 2;
62         Pump::on_button_press_event(&event);
63 }
64
65 void Pump::on_menu_popup_propiedades()
66 {
67         GdkEventButton event; 
68                 event.type = GDK_2BUTTON_PRESS;
69                 event.button = 1;
70         Pump::on_button_press_event(&event);
71 }
72
73 void Pump::set_entrega(double _ent)
74 {
75         entrega = _ent;
76 }
77
78 void Pump::set_liquid_color(Gdk::Color _color)
79 {
80         liquid_color = _color;
81 }
82
83 double Pump::get_entrega()
84 {
85         return entrega;
86 }
87
88 Gdk::Color Pump::get_liquid_color()
89 {
90         return liquid_color;
91 }
92
93 void Pump::save(FILE *archivo)
94 {
95         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];
96         sprintf(c_red,"\t\t\t<rojo>%d</rojo>\n",liquid_color.get_red());
97         sprintf(c_green,"\t\t\t<verde>%d</verde>\n",liquid_color.get_green());
98         sprintf(c_blue,"\t\t\t<azul>%d</azul>\n",liquid_color.get_blue());
99         sprintf(c_x,"\t\t<x>%d</x>\n",x);
100         sprintf(c_y,"\t\t<y>%d</y>\n",y);
101         sprintf(c_id,"%d",ID);
102         sprintf(c_entrega,"\t\t<entrega>%.2f</entrega>\n", entrega);
103         sprintf(c_img,"\t\t<orientacion>%d</orientacion>\n",imgActual);
104         Glib::ustring dato;
105         dato = "\t<bomba nombre=\""+name+"\" id=\"";
106         dato += c_id;
107         dato += "\">\n";
108         dato += c_entrega;
109         dato += "\t<color>\n";
110         dato += c_red;
111         dato += c_green;
112         dato += c_blue;
113         dato += "\t</color>\n";
114         dato += c_img;
115         dato += c_x; 
116         dato += c_y;
117         dato += "\t</bomba>\n";
118         fprintf(archivo,dato.c_str());  
119 }
120
121 bool Pump::check_connection()
122 {
123         switch (get_img_actual()) {
124                 case 0:
125                         if ( is_other_connection_area( get_position_x()+get_image()->get_width()+5 , get_position_y() +16) )
126                                 return true;                            
127                         break;
128                 case 1:
129                         if ( is_other_connection_area( get_position_x() -5, get_position_y() +16) )
130                                 return true;
131         }
132         return false;
133 }
134
135 bool Pump::is_connection_area(int _a, int _b)
136 {
137         switch (imgActual) {
138                 case 0: if ( (_a <= x+image->get_width()-1)&&(_a>=x+image->get_width()-10)&&(_b<=y+22)&&(_b > y) ) 
139                                                 return true;
140                 case 1: if ( (_a <= x+10)&&(_a > x)&&(_b<=y+22)&&(_b > y) ) 
141                                                 return true;
142         }
143         return false;
144 }