]> git.llucax.com Git - z.facultad/75.42/plaqui.git/blob - Constructor/src/cistern.cpp
- Se agrega el metodo Model::Simulator::set_open() para abrir y cerrar bombas y
[z.facultad/75.42/plaqui.git] / Constructor / src / cistern.cpp
1 #include "cistern.h"
2 #include "cisternptywnd.h"
3
4 Cistern::Cistern(int orientacion)
5 {
6         imageE = Gdk::Pixbuf::create_from_file(PACKAGE_DATA_DIR"/plaqui-constructor/pixmaps/tanque_e.png");
7         imageO = Gdk::Pixbuf::create_from_file(PACKAGE_DATA_DIR"/plaqui-constructor/pixmaps/tanque_o.png");
8         null = Gdk::Pixbuf::create_from_file(PACKAGE_DATA_DIR"/plaqui-constructor/pixmaps/tanque_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", "cistern_pty_wnd");
21         ref->get_widget_derived("cistern_pty_wnd",cistern_pty_wnd);
22         cistern_pty_wnd->cistern = this;
23         cistern_pty_wnd->set_title("Propiedades del Tanque");   
24         name = "tanque";
25         
26         Connector temp;
27         temp.id_dest = -1;
28         temp.type = IN;
29         connect_vec.push_back(temp); // entrada arriba
30         temp.type = OUT;
31         connect_vec.push_back(temp); // salida abajo
32 }
33
34 Cistern::~Cistern()
35 {
36 }
37
38 bool Cistern::on_button_press_event(GdkEventButton *event)
39 {
40         GdkEventExpose e;
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) {
46                         tmp_line.logic =  workplace->get_logic_item(CItem::quien);
47                         tmp_line.store = this;
48                         workplace->lista_lineas.push_back(tmp_line);
49                         workplace->on_expose_event(&e);
50                 }
51         }
52         
53         if ((event->type == GDK_BUTTON_PRESS) && ( event->button ==2)){
54                 image = null; 
55                 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);
56                 imgActual++;
57                 switch (imgActual) {
58                         case 1:
59                                 image = imageO;
60                                 break;
61                         default: 
62                                 imgActual = 0;
63                                 image = imageE;                 
64                 }
65                 set_size_request(image->get_width(),image->get_height());
66                 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);
67         }
68         
69         if ((event->type == GDK_BUTTON_PRESS) && ( event->button == 3)){
70                 menu_popup.popup(event->button, event->time);
71                  return true; //It has been handled.
72         }
73         
74         if ((event->type == GDK_2BUTTON_PRESS) && (event->button ==1)){
75                 cistern_pty_wnd->spin_capacidad->set_value( capacidad );
76                 cistern_pty_wnd->spin_inicial->set_value( contenido_inicial );
77                 cistern_pty_wnd->txt_cistern_name->set_text( name );
78                 cistern_pty_wnd->show();
79         }               
80         workplace->on_expose_event(&e);
81         return true;
82 }
83
84 void Cistern::on_menu_popup_rotar()
85 {
86         GdkEventButton event; 
87                 event.type = GDK_BUTTON_PRESS;
88                 event.button = 2;
89         Cistern::on_button_press_event(&event);
90 }
91
92 void Cistern::on_menu_popup_propiedades()
93 {
94         GdkEventButton event; 
95                 event.type = GDK_2BUTTON_PRESS;
96                 event.button = 1;
97         Cistern::on_button_press_event(&event);
98 }
99
100 void Cistern::set_capacidad(double _cap)
101 {
102         capacidad = _cap;
103 }
104
105 void Cistern::set_liquid_color(Gdk::Color _color)
106 {
107         liquid_color = _color;
108 }
109
110 void Cistern::set_contenido_inicial(double _ini)
111 {
112         contenido_inicial = _ini;
113 }
114
115 double Cistern::get_capacidad()
116 {
117         return capacidad;
118 }
119
120 double Cistern::get_contenido_inicial()
121 {
122         return contenido_inicial;
123 }
124
125 Gdk::Color Cistern::get_liquid_color()
126 {
127         return liquid_color;
128 }
129
130 void Cistern::save(FILE *archivo)
131 {
132         char c_id[50], c_cap[50], c_x[50], c_y[50], c_img[50], c_ini[50], c_red[50], c_green[50], c_blue[50];
133         Glib::ustring  con0, con1;
134         con0 = "\t\t\t<entrada>"+get_other_name(connect_vec[0].id_dest)+"</entrada>\n";
135         con1 = "\t\t\t<salida>"+get_other_name(connect_vec[1].id_dest)+"</salida>\n";
136         sprintf(c_red,"\t\t\t<rojo>%d</rojo>\n",liquid_color.get_red());
137         sprintf(c_green,"\t\t\t<verde>%d</verde>\n",liquid_color.get_green());
138         sprintf(c_blue,"\t\t\t<azul>%d</azul>\n",liquid_color.get_blue());
139         sprintf(c_x,"\t\t<x>%d</x>\n",x);
140         sprintf(c_y,"\t\t<y>%d</y>\n",y);
141         sprintf(c_id,"%d",ID);
142         sprintf(c_cap,"\t\t<capacidad>%.2f</capacidad>\n", capacidad);
143         sprintf(c_ini,"\t\t<inicial>%.2f</inicial>\n", contenido_inicial);
144         sprintf(c_img,"\t\t<orientacion>%d</orientacion>\n",imgActual);
145         Glib::ustring dato;
146         dato = "\t<tanque nombre=\""+name+"\" id=\"";
147         dato += c_id;
148         dato += "\">\n";
149         dato += c_cap;
150         dato += c_ini;
151         dato += "\t\t<color>\n";
152         dato += c_red;
153         dato += c_green;
154         dato += c_blue;
155         dato += "\t\t</color>\n";
156         dato += "\t\t<conector>\n"+con0+con1+"\t\t</conector>\n";
157         dato += c_img;
158         dato += c_x; 
159         dato += c_y;
160         dato += "\t</tanque>\n";
161         fprintf(archivo,dato.c_str());  
162 }
163
164 bool Cistern::check_connection()
165 {
166         CItem * _item, *_item1;
167         ConnectorType temp0, temp1;
168         switch (get_img_actual()) {
169                 case 0:
170                         temp0 = is_other_connection_area( get_position_x() + 16, get_position_y() - 5, &_item);//arriba - entrada
171                         temp1 = is_other_connection_area( get_position_x()+get_image()->get_width() + 5 , get_position_y()+get_image()->get_height() -16, &_item1);//abajo - salida             
172                         break;
173                 case 1:
174                         temp0 = is_other_connection_area( get_position_x()+get_image()->get_width() - 16, get_position_y() - 5, &_item);//arriba - entrada
175                         temp1 = is_other_connection_area( get_position_x() -5, get_position_y()+get_image()->get_height()-16, &_item1); //abajo - salida
176         }
177         if (temp0 == OUT && temp1 == IN) { 
178                 connect_vec[0].id_dest = _item->get_id();
179                 connect_vec[1].id_dest = _item1->get_id();
180                 return (is_connected = true);
181         }
182         return is_connected;
183 }
184
185 ConnectorType Cistern::get_connector_type(int _a, int _b)
186 {
187         switch (imgActual) {
188                 case 0: if ( (_a <= x+22)&&(_a>=x+10)&&(_b<=y+10)&&(_b > y) )//arriba
189                                                 return connect_vec[0].type;
190                                         if ( (_a <= x+image->get_width()-1)&&(_a >=x+image->get_width()-10)&&(_b<=y+image->get_height()-10)&&(_b >=y+image->get_height()-22) )//abajo
191                                                 return connect_vec[1].type;
192                                         break;
193                 case 1: if ( (_a <= x+image->get_width()-10)&&(_a>=x+image->get_width()-22)&&(_b<=y+10)&&(_b > y) )//arriba
194                                                 return connect_vec[0].type;
195                                         if ( (_a <= x +10)&&(_a > x)&&(_b<=y+image->get_height()-10)&&(_b >=y+image->get_height()-22) )//abajo
196                                                 return connect_vec[1].type;
197         }
198         return UNDEF;
199 }
200
201 void Cistern::set_default_connector()
202 {
203         connect_vec[0].type = IN;
204         connect_vec[1].type = OUT;
205 }
206
207 void Cistern::get_logic_connect_position(int& _a, int& _b)
208 {
209         switch(imgActual) {
210                 case 0: 
211                         _a = x;
212                         _b = y + 10;
213                         break;
214                 case 1: 
215                         _a = x +image->get_width();
216                         _b = y + 10;
217         }
218 }