]> git.llucax.com Git - z.facultad/75.42/plaqui.git/blob - Constructor/src/pump.cpp
Se agrega el doc del cliente REVISAR Y CORREGIR A GUSTO!
[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 && !workplace->get_logic_item(CItem::gate_id)->get_out_logic_connect()) {
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_in_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[20];
77                 Glib::ustring text;
78                 sprintf(f,"  Entrega:%.1f",entrega);
79                 text = name+f;
80                 status_bar->push ( text, 0);
81         }
82         
83         if ((event->type == GDK_BUTTON_PRESS) && ( event->button ==2)){
84                 image = null; 
85                 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);
86                 imgActual++;
87                 switch (imgActual) {
88                         case 1:
89                                 image = imageO;
90                                 in_x = x + 16;
91                                 in_y = y;                       
92                                 out_x = in_x;
93                                 out_y = y + 32;
94                                 break;
95                         default: 
96                                 imgActual = 0;
97                                 image = imageE;                 
98                                 in_x = x + image->get_width()-16;
99                                 in_y = y;
100                                 out_x = in_x;
101                                 out_y = y + 32;
102                 }
103                 set_size_request(image->get_width(),image->get_height());
104                 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);
105         }
106         
107         if ((event->type == GDK_BUTTON_PRESS) && ( event->button == 3)){
108                 menu_popup.popup(event->button, event->time);
109                  return true; //It has been handled.
110         }
111         
112         if ((event->type == GDK_2BUTTON_PRESS) && (event->button ==1)){
113                 pump_pty_wnd->spin_fluid->set_value( entrega );
114                 pump_pty_wnd->txt_pump_name->set_text( name );
115                 pump_pty_wnd->show();
116         }               
117         workplace->queue_draw();
118         return true;
119 }
120
121 void Pump::on_menu_popup_rotar()
122 {
123         GdkEventButton event; 
124                 event.type = GDK_BUTTON_PRESS;
125                 event.button = 2;
126         Pump::on_button_press_event(&event);
127 }
128
129 void Pump::on_menu_popup_propiedades()
130 {
131         GdkEventButton event; 
132                 event.type = GDK_2BUTTON_PRESS;
133                 event.button = 1;
134         Pump::on_button_press_event(&event);
135 }
136
137 void Pump::set_entrega(double _ent)
138 {
139         entrega = _ent;
140 }
141
142 void Pump::set_liquid_color(Gdk::Color _color)
143 {
144         liquid_color = _color;
145 }
146
147 double Pump::get_entrega()
148 {
149         return entrega;
150 }
151
152 Gdk::Color Pump::get_liquid_color()
153 {
154         return liquid_color;
155 }
156
157 void Pump::save(FILE *archivo)
158 {
159         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];
160         Glib::ustring con0;
161         
162         con0 = "\t\t\t<salida>"+get_other_name(connect_vec[0].id_dest)+"</salida>\n";
163         sprintf(c_red,"\t\t\t<rojo>%d</rojo>\n",liquid_color.get_red());
164         sprintf(c_green,"\t\t\t<verde>%d</verde>\n",liquid_color.get_green());
165         sprintf(c_blue,"\t\t\t<azul>%d</azul>\n",liquid_color.get_blue());
166         sprintf(c_x,"\t\t<x>%d</x>\n",x);
167         sprintf(c_y,"\t\t<y>%d</y>\n",y);
168         sprintf(c_id,"%d",ID);
169         sprintf(c_entrega,"\t\t<entrega>%.2f</entrega>\n", entrega);
170         sprintf(c_img,"\t\t<orientacion>%d</orientacion>\n",imgActual);
171         Glib::ustring dato;
172         dato = "\t<bomba nombre=\""+name+"\" id=\"";
173         dato += c_id;
174         dato += "\">\n";
175         dato += c_entrega;
176         dato += "\t\t<color>\n";
177         dato += c_red;
178         dato += c_green;
179         dato += c_blue;
180         dato += "\t\t</color>\n";
181         dato += "\t\t<conector>\n"+con0+"\t\t</conector>\n";
182         dato += c_img;
183         dato += c_x; 
184         dato += c_y;
185         dato += "\t</bomba>\n";
186         fprintf(archivo,dato.c_str());  
187 }
188
189 bool Pump::check_connection()
190 {
191         CItem * _item;
192         ConnectorType temp;
193         switch (get_img_actual()) {
194                 case 0:
195                         temp = is_other_connection_area( get_position_x()+get_image()->get_width()+5 , get_position_y() +16,& _item);
196                         break;
197                 case 1:
198                         temp =  is_other_connection_area( get_position_x() -5, get_position_y() +16, &_item);
199         }
200          if (is_connected = ( temp == IN) ) {
201                         std::cout << "PUMP " << _item->get_id() << std::endl;
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 }