2 #include "exclusaptywnd.h"
4 Exclusa::Exclusa(int orientacion)
10 imageN = Gdk::Pixbuf::create_from_file(PACKAGE_DATA_DIR"/plaqui-constructor/pixmaps/exclusa_h.png");
11 imageS = Gdk::Pixbuf::create_from_file(PACKAGE_DATA_DIR"/plaqui-constructor/pixmaps/exclusa_s.png");
12 null = Gdk::Pixbuf::create_from_file(PACKAGE_DATA_DIR"/plaqui-constructor/pixmaps/null.png");
13 imgActual = orientacion;
22 set_size_request(image->get_width(), image->get_height());
24 Glib::RefPtr<Gnome::Glade::Xml> ref = Gnome::Glade::Xml::create(PACKAGE_DATA_DIR"/plaqui-constructor/dialogs/constructor.glade", "exclusa_pty_wnd");
25 ref->get_widget_derived("exclusa_pty_wnd",exclusa_pty_wnd);
26 exclusa_pty_wnd->exclusa = this;
32 connect_vec.push_back(temp);
33 connect_vec.push_back(temp);
40 bool Exclusa::on_button_press_event(GdkEventButton *event)
43 if ((event->type == GDK_BUTTON_PRESS) && ( event->button == 1)) {
44 list_pointed->push_back(name);
45 combo_entry->set_popdown_strings(*list_pointed);
46 combo_entry->get_entry()->set_text (name);
47 WorkPlace::pointed = ID;
48 if (CItem::logic_connect && CItem::gate_id != -1) {
49 if ( detect_click_position((int)event->x, (int)event->y) == IN) {
50 tmp_line.logic_id = workplace->get_logic_item(CItem::gate_id)->get_id();
51 tmp_line.store_id = ID;
52 workplace->lista_lineas_in.push_back(tmp_line);
53 workplace->queue_draw();
54 } else if (detect_click_position((int)event->x, (int)event->y) == OUT) {
55 tmp_line.logic_id = workplace->get_logic_item(CItem::gate_id)->get_id();
56 tmp_line.store_id = ID;
57 workplace->lista_lineas_out.push_back(tmp_line);
58 workplace->queue_draw();
63 if ((event->type == GDK_BUTTON_PRESS) && ( event->button ==2)){
65 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);
70 in_x = x + image->get_width()-5;
71 in_y = y + image->get_height()/2-5;
78 in_x = x + image->get_width()/2;
81 out_y = y +image->get_height();
83 set_size_request(image->get_width(),image->get_height());
84 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);
86 if ((event->type == GDK_BUTTON_PRESS) && ( event->button == 3)){
87 menu_popup.popup(event->button, event->time);
88 return true; //It has been handled.
91 if ((event->type == GDK_2BUTTON_PRESS) && (event->button ==1)){
92 exclusa_pty_wnd->txt_exclusa_name->set_text( name);
93 if (estado) exclusa_pty_wnd->rd_btn_open->set_active(true);
94 exclusa_pty_wnd->show();
96 workplace->queue_draw();
100 void Exclusa::set_estado(bool _state)
105 bool Exclusa::get_estado()
110 void Exclusa::on_menu_popup_rotar()
112 GdkEventButton event;
113 event.type = GDK_BUTTON_PRESS;
115 Exclusa::on_button_press_event(&event);
118 void Exclusa::on_menu_popup_propiedades()
120 GdkEventButton event;
121 event.type = GDK_2BUTTON_PRESS;
123 Exclusa::on_button_press_event(&event);
126 void Exclusa::save(FILE *archivo)
128 char c_id[50], c_est[50], c_x[50], c_y[50], c_img[50];
130 Glib::ustring con0, con1;
131 if (connect_vec[0].type == IN)
132 con0 = "\t\t\t<entrada>"+get_other_name(connect_vec[0].id_dest)+"</entrada>\n";
134 con0 = "\t\t\t<salida>"+get_other_name(connect_vec[0].id_dest)+"</salida>\n";
135 if (connect_vec[1].type == IN)
136 con1 = "\t\t\t<entrada>"+get_other_name(connect_vec[1].id_dest)+"</entrada>\n";
138 con1 = "\t\t\t<salida>"+get_other_name(connect_vec[1].id_dest)+"</salida>\n";
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);
144 sprintf(c_est,"\t\t<estado>%d</estado>\n", est);
145 sprintf(c_img,"\t\t<orientacion>%d</orientacion>\n",imgActual);
147 dato = "\t<exclusa nombre=\""+name+"\" id=\"";
150 dato += "\t\t<conector>\n"+con0 + con1+"\t\t</conector>\n";
155 dato += "\t</exclusa>\n";
156 fprintf(archivo,dato.c_str());
159 bool Exclusa::check_connection()
162 CItem *_item0, *_item1;
163 switch (get_img_actual()) {
165 connect_vec[0].type = is_other_connection_area( get_position_x()-5, get_position_y()+16, &_item0); //izquierda
166 connect_vec[1].type = is_other_connection_area( get_position_x()+get_image()->get_width()+5, get_position_y()+16,& _item1); //derecha
169 connect_vec[0].type = is_other_connection_area( get_position_x()+16, get_position_y()-5, &_item0); // arriba
170 connect_vec[1].type = is_other_connection_area( get_position_x()+16, get_position_y()+get_image()->get_height() +5, &_item1); //abajo
172 if ( connect_vec[0].type != UNDEF && connect_vec[1].type != UNDEF ) {
173 aux = connect_vec[0].type;
174 connect_vec[0].type = connect_vec[1].type;
175 connect_vec[1].type = aux;
176 connect_vec[0].id_dest = _item0->get_id();
177 connect_vec[1].id_dest = _item1->get_id();
178 return ( is_connected = (connect_vec[0].type != connect_vec[1].type) );
180 else return is_connected;
183 ConnectorType Exclusa::get_connector_type(int _a, int _b)
188 if ( (_a <= x+image->get_width()-10 )&&(_a >= x + 10) && (_b <= y+10) &&(_b > 0 ) ){ //arriba
189 if ( is_connected ) return connect_vec[0].type;
190 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
191 switch ( connect_vec[1].type ) {
193 connect_vec[1] = OUT;
198 connect_vec[0] = OUT;
203 return connect_vec[0].type;
206 if ((_a <= x+22 )&&(_a >= x + 10) && (_b <= y+image->get_height()-1) &&(_b >= y+image->get_height()-10 )) {//abajo
207 if ( is_connected ) return connect_vec[1].type;
208 connect_vec[0].type = is_other_connection_area( get_position_x()+16, get_position_y()-5,& _item);//pregunto que hay arriba.
209 switch ( connect_vec[0].type ) {
211 connect_vec[0] = OUT;
216 connect_vec[1] = OUT;
221 return connect_vec[1].type;
225 if ((_a <= x+10 )&&(_a > 0) && (_b <= y+image->get_height()-10) &&(_b >= y+10 )){ //izquierda
226 if ( is_connected ) return connect_vec[0].type;
227 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
228 switch ( connect_vec[1].type ) {
230 connect_vec[1] = OUT;
235 connect_vec[0] = OUT;
241 return connect_vec[0].type;
243 if ((_a <= x+image->get_width()-1)&&(_a >= x+image->get_width()-10) && (_b <= y+image->get_height()-10) &&(_b >= y +10 )) {//derecha
244 if ( is_connected ) return connect_vec[1].type;
245 connect_vec[0].type = is_other_connection_area(get_position_x()-5, get_position_y()+16, &_item); //pregunto por la izquierda.
246 switch ( connect_vec[0].type ) {
248 connect_vec[0] = OUT;
253 connect_vec[1] = OUT;
259 return connect_vec[1].type;
265 void Exclusa::set_default_connector()
267 connect_vec[0].type = UNDEF;
268 connect_vec[1].type = UNDEF;
271 void Exclusa::get_in_logic_connect_position(int& _a, int& _b)
277 void Exclusa::get_out_logic_connect_position(int& _a, int& _b)
283 ConnectorType Exclusa::detect_click_position(int _a, int _b)
287 if ( (_a <= image->get_width()/2+10)&&(_a>=image->get_width()/2-10)&&(_b<=16)&&(_b >= 0) )
289 if ( (_a <= image->get_width()/2+10)&&(_a>=image->get_width()/2-10)&&(_b<=32)&&(_b > 16) )
293 if ( (_a <=32)&&(_a> 16)&&(_b<=image->get_height()/2+10)&&(_b >= image->get_height()/2-10) )
295 if ( (_a <= 16)&&(_a>=0)&&(_b<=image->get_height()/2+10)&&(_b >= image->get_height()/2-10) )
301 void Exclusa::update_logic_position()
305 in_x = x + image->get_width()-5;
306 in_y = y + image->get_height()/2-5;
311 in_x = x + image->get_width()/2;
314 out_y = y +image->get_height();