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