]> git.llucax.com Git - z.facultad/75.42/plaqui.git/blob - Constructor/exclusa.cpp
0ffb1a6afebfcd6a4c852d58a2fc65000fe2d973
[z.facultad/75.42/plaqui.git] / Constructor / exclusa.cpp
1 #include "exclusa.h"
2 #include "exclusaptywnd.h"
3
4 Exclusa::Exclusa()
5 {
6         imageN = Gdk::Pixbuf::create_from_file("exclusa_h.png");
7         imageS = Gdk::Pixbuf::create_from_file("exclusa_s.png");
8         null = Gdk::Pixbuf::create_from_file("null.png");
9         imgActual = 0;
10         image = imageN;
11         set_size_request(image->get_width(), image->get_height());
12         
13         Glib::RefPtr<Gnome::Glade::Xml> ref = Gnome::Glade::Xml::create("constructor.glade", "exclusa_pty_wnd");
14         ref->get_widget_derived("exclusa_pty_wnd",exclusa_pty_wnd);
15         exclusa_pty_wnd->exclusa = this;
16         name = "exclusa";
17         
18         Connector temp;
19         temp.id_dest = -1;
20         temp.type = UNDEF;
21         connect_vec.push_back(temp);
22         connect_vec.push_back(temp);
23 }
24
25 Exclusa::~Exclusa()
26 {
27 }
28
29 bool Exclusa::on_button_press_event(GdkEventButton *event)
30 {
31         GdkEventExpose e;
32         t_line tmp_line;
33         if ((event->type == GDK_BUTTON_PRESS) && ( event->button == 1)) {
34                 combo_entry->set_text(name);
35                 if (CItem::logic_connect) {
36                         tmp_line.logic =  workplace->get_logic_item(CItem::quien);
37                         tmp_line.store = this;
38                         workplace->lista_lineas.push_back(tmp_line);
39                         workplace->on_expose_event(&e);
40                 }
41                 CItem::logic_connect = false;   
42         }
43         
44         if ((event->type == GDK_BUTTON_PRESS) && ( event->button ==2)){
45                 image = null; 
46                 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);
47                 imgActual++;
48                 switch (imgActual) {
49                         case 1:
50                                 image = imageS;
51                                 break;
52                         default: 
53                                 imgActual = 0;
54                                 image = imageN;                 
55                 }
56                 set_size_request(image->get_width(),image->get_height());               
57                 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);
58         }
59         if ((event->type == GDK_BUTTON_PRESS) && ( event->button == 3)){
60                 menu_popup.popup(event->button, event->time);
61                  return true; //It has been handled.
62         }
63         
64         if ((event->type == GDK_2BUTTON_PRESS) && (event->button ==1)){
65                 exclusa_pty_wnd->txt_exclusa_name->set_text( name);
66                 if (estado) exclusa_pty_wnd->rd_btn_open->set_active(true);
67                 exclusa_pty_wnd->show();
68         }
69         return true;
70 }
71
72 void Exclusa::set_estado(bool _state)
73 {
74         estado = _state;
75 }
76
77 bool Exclusa::get_estado()
78 {
79         return estado;
80 }
81
82 void Exclusa::on_menu_popup_rotar()
83 {
84         GdkEventButton event; 
85                 event.type = GDK_BUTTON_PRESS;
86                 event.button = 2;
87         Exclusa::on_button_press_event(&event);
88 }
89
90 void Exclusa::on_menu_popup_propiedades()
91 {
92         GdkEventButton event;
93         event.type = GDK_2BUTTON_PRESS;
94         event.button = 1;
95         Exclusa::on_button_press_event(&event);
96 }
97
98 void Exclusa::save(FILE *archivo)
99 {
100         char c_id[50], c_est[50], c_x[50], c_y[50], c_img[50];
101         int est;
102         Glib::ustring  con0, con1;
103         if (connect_vec[0].type == IN)
104                 con0 = "\t\t\t<entrada>"+get_other_name(connect_vec[0].id_dest)+"</entrada>\n";
105         else
106                 con0 = "\t\t\t<salida>"+get_other_name(connect_vec[0].id_dest)+"</salida>\n";
107         if (connect_vec[1].type == IN) 
108                 con1 = "\t\t\t<entrada>"+get_other_name(connect_vec[1].id_dest)+"</entrada>\n";
109         else
110                 con1 = "\t\t\t<salida>"+get_other_name(connect_vec[1].id_dest)+"</salida>\n";
111         sprintf(c_x,"\t\t<x>%d</x>\n",x);
112         sprintf(c_y,"\t\t<y>%d</y>\n",y);
113         sprintf(c_id,"%d",ID);
114         if (estado) est = 1;
115         else est = 0;
116         sprintf(c_est,"\t\t<estado>%d</estado>\n", est);
117         sprintf(c_img,"\t\t<orientacion>%d</orientacion>\n",imgActual);
118         Glib::ustring dato;
119         dato = "\t<exclusa nombre=\""+name+"\" id=\"";
120         dato += c_id;
121         dato += "\">\n";
122         dato += "\t\t<conector>\n"+con0 + con1+"\t\t</conector>\n";
123         dato += c_img;
124         dato += c_est;
125         dato += c_x; 
126         dato += c_y;
127         dato += "\t</exclusa>\n";
128         fprintf(archivo,dato.c_str());  
129 }
130
131 bool Exclusa::check_connection()
132 {
133         ConnectorType aux;
134         CItem *_item0, *_item1;
135         switch (get_img_actual()) {
136                         case 0:
137                                 connect_vec[0].type = is_other_connection_area( get_position_x()-5, get_position_y()+16, &_item0); //izquierda
138                                 connect_vec[1].type = is_other_connection_area( get_position_x()+get_image()->get_width()+5, get_position_y()+16,& _item1); //derecha
139                         break;          
140                         case 1:
141                                 connect_vec[0].type =  is_other_connection_area( get_position_x()+16, get_position_y()-5, &_item0); // arriba
142                                 connect_vec[1].type = is_other_connection_area( get_position_x()+16, get_position_y()+get_image()->get_height() +5, &_item1); //abajo
143         }
144         if ( connect_vec[0].type != UNDEF && connect_vec[1].type != UNDEF ) {
145                 aux = connect_vec[0].type; 
146                 connect_vec[0].type = connect_vec[1].type;
147                 connect_vec[1].type = aux;
148                 connect_vec[0].id_dest = _item0->get_id();
149                 connect_vec[1].id_dest = _item1->get_id();
150                 return ( is_connected = (connect_vec[0].type != connect_vec[1].type) );
151         }
152         else return is_connected;
153 }
154
155 ConnectorType Exclusa::get_connector_type(int _a, int _b)
156 {
157         CItem * _item;
158         if ( ! is_connected ) {
159                 switch (imgActual) {
160                         case 0:
161                                 if ((_a <= x+10 )&&(_a > 0) && (_b <= y+image->get_height()-10) &&(_b >= y+10 )) //izquierda
162                                         return is_other_connection_area(get_position_x()+get_image()->get_width()+5, get_position_y()+16, &_item);//pregunto por la derecha
163                                 if ((_a <= x+image->get_width()-1)&&(_a >= x+image->get_width()-10) && (_b <= y+image->get_height()-10) &&(_b >= y +10 )) //derecha
164                                         return is_other_connection_area(get_position_x()-5, get_position_y()+16, &_item); //pregunto por la izquierda.
165                                 break;
166                         case 1: 
167                                 if ( (_a <= x+image->get_width()-10 )&&(_a >= x + 10) && (_b <= y+10) &&(_b > 0 ) )  //arriba
168                                         return is_other_connection_area(get_position_x()+16, get_position_y()+get_image()->get_height() +5, &_item); //pregunto que hay abajo
169                                 if ((_a <= x+22 )&&(_a >= x + 10) && (_b <= y+image->get_height()-1) &&(_b >= y+image->get_height()-10 ))//abajo
170                                         return is_other_connection_area( get_position_x()+16, get_position_y()-5, &_item);//pregunto que hay arriba.
171                 }
172         } else {
173                 switch (imgActual) {
174                         case 0: 
175                                 if ((_a <= x+10 )&&(_a > 0) && (_b <= y+image->get_height()-10) &&(_b >= y+10 )) //izquierda
176                                         return connect_vec[0].type;
177                                 if ((_a <= x+image->get_width()-1)&&(_a >= x+image->get_width()-10) && (_b <= y+image->get_height()-10) &&(_b >= y +10 )) //derecha
178                                         return connect_vec[1].type;
179                                 break;
180                         case 1:
181                                 if ( (_a <= x+image->get_width()-10 )&&(_a >= x + 10) && (_b <= y+10) &&(_b > 0 ) ) //arriba
182                                         return connect_vec[0].type;
183                                 if ((_a <= x+22 )&&(_a >= x + 10) && (_b <= y+image->get_height()-1) &&(_b >= y+image->get_height()-10 )) //abajo
184                                         return connect_vec[1].type;
185                 }
186         }
187         return UNDEF;
188 }
189
190 void Exclusa::set_default_connector()
191 {
192         connect_vec[0].type = UNDEF;
193         connect_vec[1].type = UNDEF;
194 }