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