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