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 connect_vec[0].type = aux2;
192 connect_vec[1].type = aux1;
194 connect_vec[0].id_dest = _item0->get_id();
195 connect_vec[1].id_dest = _item1->get_id();
196 return ( is_connected = (connect_vec[0].type != connect_vec[1].type) );
198 return is_connected = false;
201 ConnectorType Exclusa::get_connector_type(int _a, int _b)
206 if ( (_a <= x+image->get_width()-10 )&&(_a >= x + 10) && (_b <= y+10) &&(_b > y ) ){ //arriba
207 if ( is_connected ) return connect_vec[0].type;
208 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
209 switch ( connect_vec[1].type ) {
211 connect_vec[1].type = OUT;
212 connect_vec[0].type = IN;
215 connect_vec[1].type = IN;
216 connect_vec[0].type = OUT;
222 return connect_vec[0].type;
225 if ((_a <= x+22 )&&(_a >= x + 10) && (_b <= y+image->get_height()-1) &&(_b >= y+image->get_height()-10 )) {//abajo
226 if ( is_connected ) return connect_vec[1].type;
227 connect_vec[0].type = is_other_connection_area( get_position_x()+16, get_position_y()-5,& _item);//pregunto que hay arriba.
228 switch ( connect_vec[0].type ) {
230 connect_vec[0].type = OUT;
231 connect_vec[1].type = IN;
234 connect_vec[0].type = IN;
235 connect_vec[1].type = OUT;
241 return connect_vec[1].type;
245 if ((_a <= x+10 )&&(_a > x) && (_b <= y+image->get_height()-10) &&(_b >= y+10 )){ //izquierda
246 if ( is_connected ) return connect_vec[0].type;
247 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
248 switch ( connect_vec[1].type ) {
250 connect_vec[1].type = OUT;
251 connect_vec[0].type = IN;
254 connect_vec[1].type = IN;
255 connect_vec[0].type = OUT;
261 return connect_vec[0].type;
263 if ((_a <= x+image->get_width()-1)&&(_a >= x+image->get_width()-10) && (_b <= y+image->get_height()-10) &&(_b >= y +10 )) {//derecha
264 if ( is_connected ) return connect_vec[1].type;
265 connect_vec[0].type = is_other_connection_area(get_position_x()-5, get_position_y()+16, &_item); //pregunto por la izquierda.
266 switch ( connect_vec[0].type ) {
268 connect_vec[0].type = OUT;
269 connect_vec[1].type = IN;
272 connect_vec[0].type = IN;
273 connect_vec[1].type = OUT;
279 return connect_vec[1].type;
285 void Exclusa::set_default_connector()
287 connect_vec[0].type = UNDEF;
288 connect_vec[1].type = UNDEF;
291 void Exclusa::get_in_logic_connect_position(int& _a, int& _b)
297 void Exclusa::get_out_logic_connect_position(int& _a, int& _b)
303 ConnectorType Exclusa::detect_click_position(int _a, int _b)
307 if ( (_a <= image->get_width()/2+10)&&(_a>=image->get_width()/2-10)&&(_b<=16)&&(_b >= 0) )
309 if ( (_a <= image->get_width()/2+10)&&(_a>=image->get_width()/2-10)&&(_b<=32)&&(_b > 16) )
313 if ( (_a <=32)&&(_a> 16)&&(_b<=image->get_height()/2+10)&&(_b >= image->get_height()/2-10) )
315 if ( (_a <= 16)&&(_a>=0)&&(_b<=image->get_height()/2+10)&&(_b >= image->get_height()/2-10) )
321 void Exclusa::update_logic_position()
325 in_x = x + image->get_width()-5;
326 in_y = y + image->get_height()/2-5;
331 in_x = x + image->get_width()/2;
334 out_y = y +image->get_height();