]> git.llucax.com Git - z.facultad/75.42/plaqui.git/blob - Constructor/src/or.cpp
-Se carga la lista de items al ir haciendo click sobre ellos
[z.facultad/75.42/plaqui.git] / Constructor / src / or.cpp
1 #include "or.h"
2
3 Or::Or()
4 {
5         in_x = x;
6         in_y = y+16;
7         out_x = x+32;
8         out_y = y+16;
9         imageN = Gdk::Pixbuf::create_from_file(PACKAGE_DATA_DIR"/plaqui-constructor/pixmaps/or_n.png");
10         imageS = Gdk::Pixbuf::create_from_file(PACKAGE_DATA_DIR"/plaqui-constructor/pixmaps/or_s.png");
11         imageE = Gdk::Pixbuf::create_from_file(PACKAGE_DATA_DIR"/plaqui-constructor/pixmaps/or_e.png");
12         imageO = Gdk::Pixbuf::create_from_file(PACKAGE_DATA_DIR"/plaqui-constructor/pixmaps/or_o.png");
13         null = Gdk::Pixbuf::create_from_file(PACKAGE_DATA_DIR"/plaqui-constructor/pixmaps/null.png");
14         imgActual = 0;
15         image = imageE;
16         set_size_request(image->get_width(), image->get_height());
17         name = "or";
18         menulist.push_back( Gtk::Menu_Helpers::ImageMenuElem("Conectar", menu_image_linea,SigC::slot(*this, &CItem::on_menu_popup_conectar) ) ) ;
19 }
20
21 Or::~Or()
22 {
23 }
24
25 bool Or::on_button_press_event(GdkEventButton *event)
26 {
27         if ((event->type == GDK_BUTTON_PRESS) && ( event->button == 1)) {
28                 if ( CItem::logic_connect ) {
29                         CItem::gate_id = ID;
30                         WorkPlace::pointed = ID;
31                         workplace->queue_draw();
32                 }
33                 list_pointed->push_back(name);
34                 combo_entry->set_popdown_strings(*list_pointed);
35                 combo_entry->get_entry()->set_text (name);
36         }
37         
38         if ((event->type == GDK_BUTTON_PRESS) && ( event->button == 2)){
39                 image = null;   
40                 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);
41                 imgActual++;
42                 switch (imgActual) {
43                         case 1:
44                                 image = imageS;
45                                 in_x = x +16;
46                                 in_y = y;
47                                 out_x = x+16;
48                                 out_y = y+32;
49                                 break;
50                         case 2:
51                                 image = imageO;
52                                 in_x = x+32;
53                                 in_y = y+16;
54                                 out_x = x;
55                                 out_y = y+16;
56                                 break;
57                         case 3:
58                                 image = imageN;
59                                 in_x = x+16;
60                                 in_y = y+32;
61                                 out_x = x+16;
62                                 out_y = y;
63                                 break;
64                         default: 
65                                 imgActual = 0;
66                                 image = imageE;                 
67                                 in_x = x;
68                                 in_y = y+16;
69                                 out_x = x+32;
70                                 out_y = y+16;
71                 }
72                 set_size_request(image->get_width(),image->get_height());
73                 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);
74         }
75         if ((event->type == GDK_BUTTON_PRESS) && ( event->button == 3)){
76                 menu_popup.popup(event->button, event->time);
77                  return true; //It has been handled.
78         }
79         workplace->queue_draw();
80         return true;
81 }
82
83 void Or::on_menu_popup_rotar()
84 {
85         GdkEventButton event; 
86         event.type = GDK_BUTTON_PRESS;
87         event.button = 2;
88         Or::on_button_press_event(&event);
89 }
90
91 void Or::save(FILE *archivo)
92 {
93         vec_connector.clear();
94         check_connection();
95         Glib::ustring dato;
96         char c_img[50], c_x[50], c_y[50], c_id[50];
97         sprintf(c_id,"%d",ID);
98         sprintf(c_img,"\t\t<orientacion>%d</orientacion>\n",imgActual);
99         sprintf(c_x,"\t\t<x>%d</x>\n",x);
100         sprintf(c_y,"\t\t<y>%d</y>\n",y);
101         dato = "\t<or nombre=\""+name+"\" id=\"";
102         dato += c_id;
103         dato += "\">\n";
104         dato += c_img;
105         dato += c_x;
106         dato += c_y;
107         for ( int i=0; i<=vec_connector.size()-1&&!vec_connector.empty(); i++) {
108                 if ( vec_connector[i].type == IN ) {
109                         dato += "\t\t<entrada>";
110                         dato += vec_connector[i].name_dest + "</entrada>\n";
111                 } else {
112                         dato += "\t\t<salida>";
113                         dato += vec_connector[i].name_dest + "</salida>\n";
114                 }       
115         }       
116         dato += "\t</or>\n";
117         fprintf(archivo, dato.c_str() );
118 }
119
120 bool Or::check_connection()
121 {
122         int cant_in = 0, cant_out =0;
123         t_logic_connector temp;
124         std::list<t_line>::iterator i = workplace->lista_lineas_in.begin();
125         while ( i != workplace->lista_lineas_in.end() ) {
126                 if ( workplace->get_logic_item((*i).logic_id)->get_id() == ID ) {
127                         temp.type = OUT;
128                         temp.name_dest = workplace->get_item((*i).store_id)->get_name();
129                         vec_connector.push_back(temp);
130                         cant_out++;
131                 }
132                 i++;
133         }
134
135         i = workplace->lista_lineas_out.begin();
136         while ( i != workplace->lista_lineas_out.end() ) {
137                 if ( workplace->get_logic_item((*i).logic_id)->get_id() == ID ) {
138                         temp.type = IN;
139                         temp.name_dest = workplace->get_item((*i).store_id)->get_name();
140                         vec_connector.push_back(temp);
141                         cant_in++;
142                 }
143                 i++;
144         }
145
146         //FIXME   la or tiene n entradas y una salida!!!!!!!!!!!!!!!!!!
147         return true;// (cant_in == cant_out );
148 }
149
150 ConnectorType Or::detect_click_position(int _a, int _b)
151 {
152         switch (imgActual) {
153                 case 0: 
154                         if ( (_a<=32 )&&(_a>=22)&&(_b<=20)&&(_b>=10) )
155                                 return OUT;
156                         if ( (_a<=10)&&(_a>=0)&&(_b<=20)&&(_b>=10) )
157                                 return IN;
158                         break;  
159                 case 1: 
160                         if ( (_a<=20 )&&(_a>=10)&&(_b<=32)&&(_b>=22) )
161                                 return OUT;
162                         if ( (_a<=20)&&(_a>=10)&&(_b<=10)&&(_b>=0) )
163                                 return IN;
164                         break;
165                 case 2: 
166                         if ( (_a<=10 )&&(_a>=0)&&(_b<=20)&&(_b>=10) )
167                                 return OUT;
168                         if ( (_a<=32)&&(_a>=22)&&(_b<=20)&&(_b>=10) )
169                                 return IN;
170                         break;
171                 case 3: 
172                         if ( (_a<=20 )&&(_a>=10)&&(_b<=10)&&(_b>=0) )
173                                 return OUT;
174                         if ( (_a<=20)&&(_a>=10)&&(_b<=32)&&(_b>=22) )
175                                 return IN;
176         }
177         return UNDEF;
178 }
179         
180 void Or::update_logic_position() 
181 {
182         switch (imgActual) {
183                 case 0: 
184                         in_x = x;
185                         in_y = y+16;
186                         out_x = x+32;
187                         out_y = y+16;
188                         break;
189                 case 1:
190                         in_x = x+16;
191                         in_y = y;
192                         out_x = x+16;
193                         out_y = y+32;
194                         break;
195                 case 2:
196                         in_x = x+32;
197                         in_y = y+16;
198                         out_x = x;
199                         out_y = y+16;
200                         break;
201                 case 3:
202                         in_x = x+16;
203                         in_y = y+32;
204                         out_x = x+16;
205                         out_y = y;
206         }
207 }
208
209 void Or::get_in_logic_connect_position(int& _a, int& _b)
210 {
211         _a = in_x;
212         _b = in_y;
213 }
214
215 void Or::get_out_logic_connect_position(int& _a, int& _b)
216 {
217         _a =out_x;
218         _b =out_y;
219 }