]> git.llucax.com Git - z.facultad/75.42/plaqui.git/blob - Constructor/src/pump.cpp
Se arregla el cliente para que compile de nuevo (NOT TESTED!)
[z.facultad/75.42/plaqui.git] / Constructor / src / pump.cpp
1 #include "pump.h"
2 #include "pumpptywnd.h"
3
4 Pump::Pump(int orientacion)
5 {
6         in_x = x + 48;
7         in_y = y;
8         out_x = in_x;
9         out_y = y + 32;
10         imageE = Gdk::Pixbuf::create_from_file(PACKAGE_DATA_DIR"/plaqui-constructor/pixmaps/bomba_e.png");
11         imageO = Gdk::Pixbuf::create_from_file(PACKAGE_DATA_DIR"/plaqui-constructor/pixmaps/bomba_o.png");
12         null = Gdk::Pixbuf::create_from_file(PACKAGE_DATA_DIR"/plaqui-constructor/pixmaps/bomba_null.png");
13         imgActual = orientacion;
14         switch (imgActual) {
15                 case 1:
16                         image = imageO;
17                         break;
18                 default: 
19                         imgActual = 0;
20                         image = imageE;                 
21         }
22         set_size_request(image->get_width(), image->get_height());
23
24         Glib::RefPtr<Gnome::Glade::Xml> ref = Gnome::Glade::Xml::create(PACKAGE_DATA_DIR"/plaqui-constructor/dialogs/constructor.glade", "pump_pty_wnd");
25         ref->get_widget_derived("pump_pty_wnd",pump_pty_wnd);
26         pump_pty_wnd->pump = this;
27         name = "bomba";
28         
29         Connector temp;
30         temp.id_dest = -1;
31         temp.type = OUT;
32         connect_vec.push_back(temp);
33 }
34
35
36 Pump::~Pump()
37 {
38 }
39
40 bool Pump::on_button_press_event(GdkEventButton *event)
41 {
42         t_line tmp_line;
43         if ((event->type == GDK_BUTTON_PRESS) && ( event->button == 1)) {
44                 list_pointed->push_back(name);
45                 combo_entry->set_popdown_strings(*list_pointed);
46                 combo_entry->get_entry()->set_text (name);
47                 WorkPlace::pointed = ID;
48                 if (CItem::logic_connect && CItem::gate_id != -1) {
49                         if ( detect_click_position((int)event->x, (int)event->y) == IN) {
50                                 tmp_line.logic_id =  workplace->get_logic_item(CItem::gate_id)->get_id();
51                                 tmp_line.store_id = ID;
52                                 workplace->lista_lineas_in.push_back(tmp_line);
53                                 workplace->queue_draw();
54                         } else if (detect_click_position((int)event->x, (int)event->y) == OUT) {
55                                 tmp_line.logic_id =  workplace->get_logic_item(CItem::gate_id)->get_id();
56                                 tmp_line.store_id = ID;
57                                 workplace->lista_lineas_out.push_back(tmp_line);
58                                 workplace->queue_draw();
59                         }
60                 }
61         }
62         
63         if ((event->type == GDK_BUTTON_PRESS) && ( event->button ==2)){
64                 image = null; 
65                 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);
66                 imgActual++;
67                 switch (imgActual) {
68                         case 1:
69                                 image = imageO;
70                                 in_x = x + 16;
71                                 in_y = y;                       
72                                 out_x = in_x;
73                                 out_y = y + 32;
74                                 break;
75                         default: 
76                                 imgActual = 0;
77                                 image = imageE;                 
78                                 in_x = x + image->get_width()-16;
79                                 in_y = y;
80                                 out_x = in_x;
81                                 out_y = y + 32;
82                 }
83                 set_size_request(image->get_width(),image->get_height());
84                 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);
85         }
86         
87         if ((event->type == GDK_BUTTON_PRESS) && ( event->button == 3)){
88                 menu_popup.popup(event->button, event->time);
89                  return true; //It has been handled.
90         }
91         
92         if ((event->type == GDK_2BUTTON_PRESS) && (event->button ==1)){
93                 pump_pty_wnd->spin_fluid->set_value( entrega );
94                 pump_pty_wnd->txt_pump_name->set_text( name );
95                 pump_pty_wnd->show();
96         }               
97         workplace->queue_draw();
98         return true;
99 }
100
101 void Pump::on_menu_popup_rotar()
102 {
103         GdkEventButton event; 
104                 event.type = GDK_BUTTON_PRESS;
105                 event.button = 2;
106         Pump::on_button_press_event(&event);
107 }
108
109 void Pump::on_menu_popup_propiedades()
110 {
111         GdkEventButton event; 
112                 event.type = GDK_2BUTTON_PRESS;
113                 event.button = 1;
114         Pump::on_button_press_event(&event);
115 }
116
117 void Pump::set_entrega(double _ent)
118 {
119         entrega = _ent;
120 }
121
122 void Pump::set_liquid_color(Gdk::Color _color)
123 {
124         liquid_color = _color;
125 }
126
127 double Pump::get_entrega()
128 {
129         return entrega;
130 }
131
132 Gdk::Color Pump::get_liquid_color()
133 {
134         return liquid_color;
135 }
136
137 void Pump::save(FILE *archivo)
138 {
139         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];
140         Glib::ustring con0;
141         
142         con0 = "\t\t\t<salida>"+get_other_name(connect_vec[0].id_dest)+"</salida>\n";
143         sprintf(c_red,"\t\t\t<rojo>%d</rojo>\n",liquid_color.get_red());
144         sprintf(c_green,"\t\t\t<verde>%d</verde>\n",liquid_color.get_green());
145         sprintf(c_blue,"\t\t\t<azul>%d</azul>\n",liquid_color.get_blue());
146         sprintf(c_x,"\t\t<x>%d</x>\n",x);
147         sprintf(c_y,"\t\t<y>%d</y>\n",y);
148         sprintf(c_id,"%d",ID);
149         sprintf(c_entrega,"\t\t<entrega>%.2f</entrega>\n", entrega);
150         sprintf(c_img,"\t\t<orientacion>%d</orientacion>\n",imgActual);
151         Glib::ustring dato;
152         dato = "\t<bomba nombre=\""+name+"\" id=\"";
153         dato += c_id;
154         dato += "\">\n";
155         dato += c_entrega;
156         dato += "\t\t<color>\n";
157         dato += c_red;
158         dato += c_green;
159         dato += c_blue;
160         dato += "\t\t</color>\n";
161         dato += "\t\t<conector>\n"+con0+"\t\t</conector>\n";
162         dato += c_img;
163         dato += c_x; 
164         dato += c_y;
165         dato += "\t</bomba>\n";
166         fprintf(archivo,dato.c_str());  
167 }
168
169 bool Pump::check_connection()
170 {
171         CItem * _item;
172         ConnectorType temp;
173         switch (get_img_actual()) {
174                 case 0:
175                         temp = is_other_connection_area( get_position_x()+get_image()->get_width()+5 , get_position_y() +16,& _item);
176                         break;
177                 case 1:
178                         temp =  is_other_connection_area( get_position_x() -5, get_position_y() +16, &_item);
179         }
180          if (is_connected = ( temp == IN) ) {
181                  connect_vec[0].id_dest = _item->get_id();
182                  return is_connected;
183          }
184          return is_connected;
185 }
186
187 ConnectorType Pump::get_connector_type(int _a, int _b)
188 {
189         switch (imgActual) {
190                 case 0: 
191                         if ( (_a <= x+image->get_width()-1)&&(_a>=x+image->get_width()-10)&&(_b<=y+22)&&(_b > y) )  //derecha.
192                                 return connect_vec[0].type;
193                         break;
194                 case 1: 
195                         if ( (_a <= x+10)&&(_a > x)&&(_b<=y+22)&&(_b > y) ) //izquierda
196                                 return connect_vec[0].type;
197         }
198         return UNDEF;
199 }
200
201 void Pump::set_default_connector()
202 {
203         connect_vec[0].type = OUT;
204 }
205
206 void Pump::get_in_logic_connect_position(int& _a, int& _b)
207 {
208         _a = in_x;
209         _b = in_y;
210 }
211
212 void Pump::get_out_logic_connect_position(int& _a, int& _b)
213 {
214         _a = out_x;
215         _b = out_y;
216 }
217         
218 ConnectorType Pump::detect_click_position(int _a, int _b)
219 {
220         switch (imgActual) {
221                 case 0:
222                         if ( (_a <=image->get_width())&&(_a>=image->get_width()-32)&&(_b<=16)&&(_b >= 0) )
223                                 return IN;
224                         if ( (_a <= image->get_width())&&(_a>=image->get_width()-32)&&(_b<=32)&&(_b > 16) )
225                                 return OUT;
226                         break;
227                 case 1:
228                         if ( (_a <= 32)&&(_a>=0)&&(_b<=16)&&(_b >= 0) )
229                                 return IN;
230                         if ( (_a <= 32)&&(_a>=0)&&(_b<=32)&&(_b > 16) )
231                                 return OUT;
232                 }
233                 return UNDEF;
234 }
235
236 void Pump::update_logic_position()
237 {
238         switch (imgActual) {
239                 case 1:
240                         in_x = x + 16;
241                         in_y = y;                       
242                         out_x = in_x;
243                         out_y = y + 32;
244                         break;
245                 case 0: 
246                         in_x = x + image->get_width()-16;
247                         in_y = y;
248                         out_x = in_x;
249                         out_y = y + 32;
250         }
251 }