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