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 combo_entry->set_text(name);
45 WorkPlace::pointed = ID;
46 if (CItem::logic_connect && CItem::gate_id != -1) {
47 if ( detect_click_position(event->x, event->y) == IN) {
48 tmp_line.logic_id = workplace->get_logic_item(CItem::gate_id)->get_id();
49 tmp_line.store_id = ID;
50 workplace->lista_lineas_in.push_back(tmp_line);
51 workplace->queue_draw();
52 } else if (detect_click_position(event->x, event->y) == OUT) {
53 tmp_line.logic_id = workplace->get_logic_item(CItem::gate_id)->get_id();
54 tmp_line.store_id = ID;
55 workplace->lista_lineas_out.push_back(tmp_line);
56 workplace->queue_draw();
61 if ((event->type == GDK_BUTTON_PRESS) && ( event->button ==2)){
63 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);
68 in_x = x + image->get_width();
69 in_y = y + image->get_height()/2;
76 in_x = x + image->get_width()/2;
79 out_y = y +image->get_height();
81 set_size_request(image->get_width(),image->get_height());
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);
84 if ((event->type == GDK_BUTTON_PRESS) && ( event->button == 3)){
85 menu_popup.popup(event->button, event->time);
86 return true; //It has been handled.
89 if ((event->type == GDK_2BUTTON_PRESS) && (event->button ==1)){
90 exclusa_pty_wnd->txt_exclusa_name->set_text( name);
91 if (estado) exclusa_pty_wnd->rd_btn_open->set_active(true);
92 exclusa_pty_wnd->show();
94 workplace->queue_draw();
98 void Exclusa::set_estado(bool _state)
103 bool Exclusa::get_estado()
108 void Exclusa::on_menu_popup_rotar()
110 GdkEventButton event;
111 event.type = GDK_BUTTON_PRESS;
113 Exclusa::on_button_press_event(&event);
116 void Exclusa::on_menu_popup_propiedades()
118 GdkEventButton event;
119 event.type = GDK_2BUTTON_PRESS;
121 Exclusa::on_button_press_event(&event);
124 void Exclusa::save(FILE *archivo)
126 char c_id[50], c_est[50], c_x[50], c_y[50], c_img[50];
128 Glib::ustring con0, con1;
129 if (connect_vec[0].type == IN)
130 con0 = "\t\t\t<entrada>"+get_other_name(connect_vec[0].id_dest)+"</entrada>\n";
132 con0 = "\t\t\t<salida>"+get_other_name(connect_vec[0].id_dest)+"</salida>\n";
133 if (connect_vec[1].type == IN)
134 con1 = "\t\t\t<entrada>"+get_other_name(connect_vec[1].id_dest)+"</entrada>\n";
136 con1 = "\t\t\t<salida>"+get_other_name(connect_vec[1].id_dest)+"</salida>\n";
137 sprintf(c_x,"\t\t<x>%d</x>\n",x);
138 sprintf(c_y,"\t\t<y>%d</y>\n",y);
139 sprintf(c_id,"%d",ID);
142 sprintf(c_est,"\t\t<estado>%d</estado>\n", est);
143 sprintf(c_img,"\t\t<orientacion>%d</orientacion>\n",imgActual);
145 dato = "\t<exclusa nombre=\""+name+"\" id=\"";
148 dato += "\t\t<conector>\n"+con0 + con1+"\t\t</conector>\n";
153 dato += "\t</exclusa>\n";
154 fprintf(archivo,dato.c_str());
157 bool Exclusa::check_connection()
160 CItem *_item0, *_item1;
161 switch (get_img_actual()) {
163 connect_vec[0].type = is_other_connection_area( get_position_x()-5, get_position_y()+16, &_item0); //izquierda
164 connect_vec[1].type = is_other_connection_area( get_position_x()+get_image()->get_width()+5, get_position_y()+16,& _item1); //derecha
167 connect_vec[0].type = is_other_connection_area( get_position_x()+16, get_position_y()-5, &_item0); // arriba
168 connect_vec[1].type = is_other_connection_area( get_position_x()+16, get_position_y()+get_image()->get_height() +5, &_item1); //abajo
170 if ( connect_vec[0].type != UNDEF && connect_vec[1].type != UNDEF ) {
171 aux = connect_vec[0].type;
172 connect_vec[0].type = connect_vec[1].type;
173 connect_vec[1].type = aux;
174 connect_vec[0].id_dest = _item0->get_id();
175 connect_vec[1].id_dest = _item1->get_id();
176 return ( is_connected = (connect_vec[0].type != connect_vec[1].type) );
178 else return is_connected;
181 ConnectorType Exclusa::get_connector_type(int _a, int _b)
184 if ( ! is_connected ) {
187 if ((_a <= x+10 )&&(_a > 0) && (_b <= y+image->get_height()-10) &&(_b >= y+10 )) //izquierda
188 return is_other_connection_area(get_position_x()+get_image()->get_width()+5, get_position_y()+16, &_item);//pregunto por la derecha
189 if ((_a <= x+image->get_width()-1)&&(_a >= x+image->get_width()-10) && (_b <= y+image->get_height()-10) &&(_b >= y +10 )) //derecha
190 return is_other_connection_area(get_position_x()-5, get_position_y()+16, &_item); //pregunto por la izquierda.
193 if ( (_a <= x+image->get_width()-10 )&&(_a >= x + 10) && (_b <= y+10) &&(_b > 0 ) ) //arriba
194 return is_other_connection_area(get_position_x()+16, get_position_y()+get_image()->get_height() +5, &_item); //pregunto que hay abajo
195 if ((_a <= x+22 )&&(_a >= x + 10) && (_b <= y+image->get_height()-1) &&(_b >= y+image->get_height()-10 ))//abajo
196 return is_other_connection_area( get_position_x()+16, get_position_y()-5, &_item);//pregunto que hay arriba.
201 if ((_a <= x+10 )&&(_a > 0) && (_b <= y+image->get_height()-10) &&(_b >= y+10 )) //izquierda
202 return connect_vec[0].type;
203 if ((_a <= x+image->get_width()-1)&&(_a >= x+image->get_width()-10) && (_b <= y+image->get_height()-10) &&(_b >= y +10 )) //derecha
204 return connect_vec[1].type;
207 if ( (_a <= x+image->get_width()-10 )&&(_a >= x + 10) && (_b <= y+10) &&(_b > 0 ) ) //arriba
208 return connect_vec[0].type;
209 if ((_a <= x+22 )&&(_a >= x + 10) && (_b <= y+image->get_height()-1) &&(_b >= y+image->get_height()-10 )) //abajo
210 return connect_vec[1].type;
216 void Exclusa::set_default_connector()
218 connect_vec[0].type = UNDEF;
219 connect_vec[1].type = UNDEF;
222 void Exclusa::get_in_logic_connect_position(int& _a, int& _b)
228 void Exclusa::get_out_logic_connect_position(int& _a, int& _b)
234 ConnectorType Exclusa::detect_click_position(int _a, int _b)
238 if ( (_a <= image->get_width()/2+10)&&(_a>=image->get_width()/2-10)&&(_b<=16)&&(_b >= 0) )
240 if ( (_a <= image->get_width()/2+10)&&(_a>=image->get_width()/2-10)&&(_b<=32)&&(_b > 16) )
244 if ( (_a <=32)&&(_a> 16)&&(_b<=image->get_height()/2+10)&&(_b >= image->get_height()/2-10) )
246 if ( (_a <= 16)&&(_a>=0)&&(_b<=image->get_height()/2+10)&&(_b >= image->get_height()/2-10) )
252 void Exclusa::update_logic_position()
256 in_x = x + image->get_width();
257 in_y = y + image->get_height()/2;
262 in_x = x + image->get_width()/2;
265 out_y = y +image->get_height();