2 #include "cisternptywnd.h"
5 Cistern::Cistern(int orientacion)
12 contenido_inicial = 0;
13 imageE = Gdk::Pixbuf::create_from_file(PACKAGE_DATA_DIR"/plaqui-constructor/pixmaps/tanque_e.png");
14 imageO = Gdk::Pixbuf::create_from_file(PACKAGE_DATA_DIR"/plaqui-constructor/pixmaps/tanque_o.png");
15 null = Gdk::Pixbuf::create_from_file(PACKAGE_DATA_DIR"/plaqui-constructor/pixmaps/tanque_null.png");
16 imgActual = orientacion;
25 set_size_request(image->get_width(), image->get_height());
27 Glib::RefPtr<Gnome::Glade::Xml> ref = Gnome::Glade::Xml::create(PACKAGE_DATA_DIR"/plaqui-constructor/dialogs/constructor.glade", "cistern_pty_wnd");
28 ref->get_widget_derived("cistern_pty_wnd",cistern_pty_wnd);
29 cistern_pty_wnd->cistern = this;
30 cistern_pty_wnd->set_title("Propiedades del Tanque");
36 connect_vec.push_back(temp); // entrada arriba
38 connect_vec.push_back(temp); // entrada abajo
45 bool Cistern::on_button_press_event(GdkEventButton *event)
49 if ((event->type == GDK_BUTTON_PRESS) && ( event->button == 1)) {
50 WorkPlace::pointed = ID;
51 list_pointed->push_back(name);
52 combo_entry->set_popdown_strings(*list_pointed);
53 combo_entry->get_entry()->set_text (name);
54 if (CItem::logic_connect && CItem::gate_id != -1) {
55 if ( detect_click_position((int)event->x, (int)event->y) == IN ){
56 tmp_line.logic_id = workplace->get_logic_item(CItem::gate_id)->get_id();
57 workplace->get_logic_item(CItem::gate_id)->set_out_connected(true);
58 tmp_line.store_id = ID;
59 workplace->lista_lineas_out.push_back(tmp_line);
60 workplace->queue_draw();
61 } else if (detect_click_position((int)event->x, (int)event->y) == OUT ) {
62 if (dynamic_cast<Not *>(workplace->get_logic_item(CItem::gate_id))) {
63 if ( !dynamic_cast<Not *>(workplace->get_logic_item(CItem::gate_id))->get_out_logic_connect()) {
64 workplace->get_logic_item(CItem::gate_id)->set_in_connected(true);
65 tmp_line.logic_id = CItem::gate_id;
66 tmp_line.store_id = ID;
67 workplace->lista_lineas_out.push_back(tmp_line);
68 workplace->queue_draw();
71 tmp_line.logic_id = CItem::gate_id;
72 tmp_line.store_id = ID;
73 workplace->lista_lineas_out.push_back(tmp_line);
74 workplace->queue_draw();
81 sprintf(f,"%.1f ",capacidad);
82 sprintf(g,"%.1f",contenido_inicial);
83 text = name+" Capacidad: ";
85 text += "Contenido Inicial: ";
87 status_bar->push ( text, 0);
90 if ((event->type == GDK_BUTTON_PRESS) && ( event->button ==2)){
92 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);
97 in_x = x + image->get_width()-5;
100 out_y = y + image->get_height();
107 out_x = x + image->get_width() -16;
108 out_y = y + image->get_height();
110 set_size_request(image->get_width(),image->get_height());
111 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);
114 if ((event->type == GDK_BUTTON_PRESS) && ( event->button == 3)){
115 menu_popup.popup(event->button, event->time);
116 return true; //It has been handled.
119 if ((event->type == GDK_2BUTTON_PRESS) && (event->button ==1)){
120 cistern_pty_wnd->spin_capacidad->set_value( capacidad );
121 cistern_pty_wnd->spin_inicial->set_value( contenido_inicial );
122 cistern_pty_wnd->txt_cistern_name->set_text( name );
123 cistern_pty_wnd->show();
125 workplace->queue_draw();
129 void Cistern::on_menu_popup_rotar()
131 GdkEventButton event;
132 event.type = GDK_BUTTON_PRESS;
134 Cistern::on_button_press_event(&event);
137 void Cistern::on_menu_popup_propiedades()
139 GdkEventButton event;
140 event.type = GDK_2BUTTON_PRESS;
142 Cistern::on_button_press_event(&event);
145 void Cistern::set_capacidad(double _cap)
150 void Cistern::set_liquid_color(Gdk::Color _color)
152 liquid_color = _color;
155 void Cistern::set_contenido_inicial(double _ini)
157 contenido_inicial = _ini;
160 double Cistern::get_capacidad()
165 double Cistern::get_contenido_inicial()
167 return contenido_inicial;
170 Gdk::Color Cistern::get_liquid_color()
175 void Cistern::save(FILE *archivo)
177 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];
178 Glib::ustring con0, con1;
179 con0 = "\t\t\t<entrada>"+get_other_name(connect_vec[0].id_dest)+"</entrada>\n";
180 con1 = "\t\t\t<salida>"+get_other_name(connect_vec[1].id_dest)+"</salida>\n";
181 sprintf(c_red,"\t\t\t<rojo>%d</rojo>\n",liquid_color.get_red());
182 sprintf(c_green,"\t\t\t<verde>%d</verde>\n",liquid_color.get_green());
183 sprintf(c_blue,"\t\t\t<azul>%d</azul>\n",liquid_color.get_blue());
184 sprintf(c_x,"\t\t<x>%d</x>\n",x);
185 sprintf(c_y,"\t\t<y>%d</y>\n",y);
186 sprintf(c_id,"%d",ID);
187 sprintf(c_cap,"\t\t<capacidad>%.2f</capacidad>\n", capacidad);
188 sprintf(c_ini,"\t\t<inicial>%.2f</inicial>\n", contenido_inicial);
189 sprintf(c_img,"\t\t<orientacion>%d</orientacion>\n",imgActual);
191 dato = "\t<tanque nombre=\""+name+"\" id=\"";
196 dato += "\t\t<color>\n";
200 dato += "\t\t</color>\n";
201 dato += "\t\t<conector>\n"+con0+con1+"\t\t</conector>\n";
205 dato += "\t</tanque>\n";
206 fprintf(archivo,dato.c_str());
209 bool Cistern::check_connection()
211 CItem * _item, *_item1;
212 ConnectorType temp0, temp1;
213 switch (get_img_actual()) {
215 temp0 = is_other_connection_area( get_position_x() + 16, get_position_y() - 5, &_item);//arriba - entrada
216 temp1 = is_other_connection_area( get_position_x()+get_image()->get_width() + 5 , get_position_y()+get_image()->get_height() -16, &_item1);//abajo - salida
219 temp0 = is_other_connection_area( get_position_x()+get_image()->get_width() - 16, get_position_y() - 5, &_item);//arriba - entrada
220 temp1 = is_other_connection_area( get_position_x() -5, get_position_y()+get_image()->get_height()-16, &_item1); //abajo - salida
222 if (temp0 == OUT && temp1 == IN) {
223 connect_vec[0].id_dest = _item->get_id();
224 connect_vec[1].id_dest = _item1->get_id();
225 return (is_connected = true);
230 ConnectorType Cistern::get_connector_type(int _a, int _b)
233 case 0: if ( (_a <= x+22)&&(_a>=x+10)&&(_b<=y+10)&&(_b > y) )//arriba
234 return connect_vec[0].type;
235 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
236 return connect_vec[1].type;
238 case 1: if ( (_a <= x+image->get_width()-10)&&(_a>=x+image->get_width()-22)&&(_b<=y+10)&&(_b > y) )//arriba
239 return connect_vec[0].type;
240 if ( (_a <= x +10)&&(_a > x)&&(_b<=y+image->get_height()-10)&&(_b >=y+image->get_height()-22) )//abajo
241 return connect_vec[1].type;
246 void Cistern::set_default_connector()
248 connect_vec[0].type = IN;
249 connect_vec[1].type = OUT;
252 void Cistern::get_in_logic_connect_position(int& _a, int& _b)
258 void Cistern::get_out_logic_connect_position(int& _a, int& _b)
264 ConnectorType Cistern::detect_click_position(int _a, int _b)
268 if ( (_a<=32) &&(_a>=0)&&(_b<=32)&&(_b>=0) )
270 if ( (_a<=image->get_width())&&(_a>=image->get_width()-32)&&(_b<=image->get_height())&&(_b>=image->get_height()-32) )
274 if ( (_a<=image->get_width()) &&(_a>=image->get_width()-32)&&(_b<=32)&&(_b>=0) )
276 if ( (_a<=32)&&(_a>=0)&&(_b<=image->get_height())&&(_b>=image->get_height()-32) )
282 void Cistern::update_logic_position()
286 in_x = x + image->get_width()-5;
289 out_y = y + image->get_height();
294 out_x = x + image->get_width() -16;
295 out_y = y + image->get_height();
299 void Cistern::draw_connectors()
302 Glib::RefPtr<Gdk::Window> window = get_window();
303 gc->set_foreground(blue);
304 window->draw_rectangle(gc, 1, in_x-5-x, in_y-y, 10, 10);
305 window->draw_rectangle(gc, 1, out_x-5-x, out_y-y-10, 10, 10);