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