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