2 #include "exclusaptywnd.h"
5 Exclusa::Exclusa(int orientacion)
11 imageN = Gdk::Pixbuf::create_from_file(PACKAGE_DATA_DIR"/plaqui-constructor/pixmaps/exclusa_h.png");
12 imageS = Gdk::Pixbuf::create_from_file(PACKAGE_DATA_DIR"/plaqui-constructor/pixmaps/exclusa_s.png");
13 null = Gdk::Pixbuf::create_from_file(PACKAGE_DATA_DIR"/plaqui-constructor/pixmaps/null.png");
14 imgActual = orientacion;
23 set_size_request(image->get_width(), image->get_height());
25 Glib::RefPtr<Gnome::Glade::Xml> ref = Gnome::Glade::Xml::create(PACKAGE_DATA_DIR"/plaqui-constructor/dialogs/constructor.glade", "exclusa_pty_wnd");
26 ref->get_widget_derived("exclusa_pty_wnd",exclusa_pty_wnd);
27 exclusa_pty_wnd->exclusa = this;
33 connect_vec.push_back(temp);
34 connect_vec.push_back(temp);
41 bool Exclusa::on_button_press_event(GdkEventButton *event)
44 if ((event->type == GDK_BUTTON_PRESS) && ( event->button == 1)) {
45 WorkPlace::pointed = ID;
46 list_pointed->push_back(name);
47 combo_entry->set_popdown_strings(*list_pointed);
48 combo_entry->get_entry()->set_text (name);
49 if (CItem::logic_connect && CItem::gate_id != -1) {
50 if ( detect_click_position((int)event->x, (int)event->y) == IN && !workplace->get_logic_item(CItem::gate_id)->get_out_logic_connect()) {
51 tmp_line.logic_id = CItem::gate_id;
52 workplace->get_logic_item(CItem::gate_id)->set_out_connected(true);
53 tmp_line.store_id = ID;
54 workplace->lista_lineas_in.push_back(tmp_line);
55 workplace->queue_draw();
56 } else if (detect_click_position((int)event->x, (int)event->y) == OUT ) {
57 if (dynamic_cast<Not *>(workplace->get_logic_item(CItem::gate_id))) {
58 if (!dynamic_cast<Not *>(workplace->get_logic_item(CItem::gate_id))->get_in_logic_connect()) {
59 workplace->get_logic_item(CItem::gate_id)->set_in_connected(true);
60 tmp_line.logic_id = CItem::gate_id;
61 tmp_line.store_id = ID;
62 workplace->lista_lineas_out.push_back(tmp_line);
63 workplace->queue_draw();
66 tmp_line.logic_id = CItem::gate_id;
67 tmp_line.store_id = ID;
68 workplace->lista_lineas_out.push_back(tmp_line);
69 workplace->queue_draw();
75 if(estado) text = name+" Estado: ABIERTO";
76 else text = name+" Estado: CERRADO";
77 status_bar->push ( text, 0);
80 if ((event->type == GDK_BUTTON_PRESS) && ( event->button ==2)){
82 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);
87 in_x = x + image->get_width()-5;
88 in_y = y + image->get_height()/2-5;
95 in_x = x + image->get_width()/2;
98 out_y = y +image->get_height();
100 set_size_request(image->get_width(),image->get_height());
101 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);
103 if ((event->type == GDK_BUTTON_PRESS) && ( event->button == 3)){
104 menu_popup.popup(event->button, event->time);
105 return true; //It has been handled.
108 if ((event->type == GDK_2BUTTON_PRESS) && (event->button ==1)){
109 exclusa_pty_wnd->txt_exclusa_name->set_text( name);
110 if (estado) exclusa_pty_wnd->rd_btn_open->set_active(true);
111 exclusa_pty_wnd->show();
113 workplace->queue_draw();
117 void Exclusa::set_estado(bool _state)
122 bool Exclusa::get_estado()
127 void Exclusa::on_menu_popup_rotar()
129 GdkEventButton event;
130 event.type = GDK_BUTTON_PRESS;
132 Exclusa::on_button_press_event(&event);
135 void Exclusa::on_menu_popup_propiedades()
137 GdkEventButton event;
138 event.type = GDK_2BUTTON_PRESS;
140 Exclusa::on_button_press_event(&event);
143 void Exclusa::save(FILE *archivo)
145 char c_id[50], c_est[50], c_x[50], c_y[50], c_img[50];
147 Glib::ustring con0, con1;
148 if (connect_vec[0].type == IN)
149 con0 = "\t\t\t<entrada>"+get_other_name(connect_vec[0].id_dest)+"</entrada>\n";
151 con0 = "\t\t\t<salida>"+get_other_name(connect_vec[0].id_dest)+"</salida>\n";
152 if (connect_vec[1].type == IN)
153 con1 = "\t\t\t<entrada>"+get_other_name(connect_vec[1].id_dest)+"</entrada>\n";
155 con1 = "\t\t\t<salida>"+get_other_name(connect_vec[1].id_dest)+"</salida>\n";
156 sprintf(c_x,"\t\t<x>%d</x>\n",x);
157 sprintf(c_y,"\t\t<y>%d</y>\n",y);
158 sprintf(c_id,"%d",ID);
161 sprintf(c_est,"\t\t<estado>%d</estado>\n", est);
162 sprintf(c_img,"\t\t<orientacion>%d</orientacion>\n",imgActual);
164 dato = "\t<exclusa nombre=\""+name+"\" id=\"";
167 dato += "\t\t<conector>\n"+con0 + con1+"\t\t</conector>\n";
172 dato += "\t</exclusa>\n";
173 fprintf(archivo,dato.c_str());
176 bool Exclusa::check_connection()
178 ConnectorType aux, aux1, aux2;
179 CItem *_item0, *_item1;
180 switch (get_img_actual()) {
182 aux1 = is_other_connection_area( get_position_x()-5, get_position_y()+16, &_item0); //izquierda
183 aux2 = is_other_connection_area( get_position_x()+get_image()->get_width()+5, get_position_y()+16,& _item1); //derecha
186 aux1 = is_other_connection_area( get_position_x()+16, get_position_y()-5, &_item0); // arriba
187 aux2 = is_other_connection_area( get_position_x()+16, get_position_y()+get_image()->get_height() +5, &_item1); //abajo
189 if ( aux1 != UNDEF && aux2 != UNDEF ) {
191 //aux = connect_vec[0].type;
192 // Aca van invertidos los tipos de entrada/salida
193 connect_vec[0].type = aux2; //connect_vec[1].type;
194 connect_vec[1].type = aux1;
196 connect_vec[0].id_dest = _item0->get_id();
197 connect_vec[1].id_dest = _item1->get_id();
198 return ( is_connected = (connect_vec[0].type != connect_vec[1].type) );
200 return is_connected = false;
203 ConnectorType Exclusa::get_connector_type(int _a, int _b)
208 if ( (_a <= x+image->get_width()-10 )&&(_a >= x + 10) && (_b <= y+10) &&(_b > y ) ){ //arriba
209 if ( is_connected ) return connect_vec[0].type;
210 connect_vec[1].type = is_other_connection_area(get_position_x()+16, get_position_y()+get_image()->get_height() +5, &_item); //pregunto que hay abajo
211 switch ( connect_vec[1].type ) {
213 connect_vec[1].type = OUT;
214 connect_vec[0].type = IN;
217 connect_vec[1].type = IN;
218 connect_vec[0].type = OUT;
224 return connect_vec[0].type;
227 if ((_a <= x+22 )&&(_a >= x + 10) && (_b <= y+image->get_height()-1) &&(_b >= y+image->get_height()-10 )) {//abajo
228 if ( is_connected ) return connect_vec[1].type;
229 connect_vec[0].type = is_other_connection_area( get_position_x()+16, get_position_y()-5,& _item);//pregunto que hay arriba.
230 switch ( connect_vec[0].type ) {
232 connect_vec[0].type = OUT;
233 connect_vec[1].type = IN;
236 connect_vec[0].type = IN;
237 connect_vec[1].type = OUT;
243 return connect_vec[1].type;
247 if ((_a <= x+10 )&&(_a > x) && (_b <= y+image->get_height()-10) &&(_b >= y+10 )){ //izquierda
248 if ( is_connected ) return connect_vec[0].type;
249 connect_vec[1].type = is_other_connection_area(get_position_x()+get_image()->get_width()+5, get_position_y()+16, &_item);//pregunto por la derecha
250 switch ( connect_vec[1].type ) {
252 connect_vec[1].type = OUT;
253 connect_vec[0].type = IN;
256 connect_vec[1].type = IN;
257 connect_vec[0].type = OUT;
263 return connect_vec[0].type;
265 if ((_a <= x+image->get_width()-1)&&(_a >= x+image->get_width()-10) && (_b <= y+image->get_height()-10) &&(_b >= y +10 )) {//derecha
266 if ( is_connected ) return connect_vec[1].type;
267 connect_vec[0].type = is_other_connection_area(get_position_x()-5, get_position_y()+16, &_item); //pregunto por la izquierda.
268 switch ( connect_vec[0].type ) {
270 connect_vec[0].type = OUT;
271 connect_vec[1].type = IN;
274 connect_vec[0].type = IN;
275 connect_vec[1].type = OUT;
281 return connect_vec[1].type;
287 void Exclusa::set_default_connector()
289 connect_vec[0].type = UNDEF;
290 connect_vec[1].type = UNDEF;
293 void Exclusa::get_in_logic_connect_position(int& _a, int& _b)
299 void Exclusa::get_out_logic_connect_position(int& _a, int& _b)
305 ConnectorType Exclusa::detect_click_position(int _a, int _b)
309 if ( (_a <= image->get_width()/2+10)&&(_a>=image->get_width()/2-10)&&(_b<=16)&&(_b >= 0) )
311 if ( (_a <= image->get_width()/2+10)&&(_a>=image->get_width()/2-10)&&(_b<=32)&&(_b > 16) )
315 if ( (_a <=32)&&(_a> 16)&&(_b<=image->get_height()/2+10)&&(_b >= image->get_height()/2-10) )
317 if ( (_a <= 16)&&(_a>=0)&&(_b<=image->get_height()/2+10)&&(_b >= image->get_height()/2-10) )
323 void Exclusa::update_logic_position()
327 in_x = x + image->get_width()-5;
328 in_y = y + image->get_height()/2-5;
333 in_x = x + image->get_width()/2;
336 out_y = y +image->get_height();