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