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