]> git.llucax.com Git - z.facultad/75.42/plaqui.git/blob - Constructor/src/and.cpp
Se arregla el cliente para que compile de nuevo (NOT TESTED!)
[z.facultad/75.42/plaqui.git] / Constructor / src / and.cpp
1 #include "and.h"
2
3 And::And()
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/and_n.png");
10         imageS = Gdk::Pixbuf::create_from_file(PACKAGE_DATA_DIR"/plaqui-constructor/pixmaps/and_s.png");
11         imageE = Gdk::Pixbuf::create_from_file(PACKAGE_DATA_DIR"/plaqui-constructor/pixmaps/and_e.png");
12         imageO = Gdk::Pixbuf::create_from_file(PACKAGE_DATA_DIR"/plaqui-constructor/pixmaps/and_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 = "and";
18         menulist.push_back( Gtk::Menu_Helpers::ImageMenuElem("Conectar", menu_image_linea,SigC::slot(*this, &CItem::on_menu_popup_conectar) ) ) ;
19 }
20
21 And::~And()
22 {
23 }
24
25 bool And::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                 }
32                 list_pointed->push_back(name);
33                 combo_entry->set_popdown_strings(*list_pointed);
34                 combo_entry->get_entry()->set_text (name);
35                 workplace->queue_draw();
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 void And::on_menu_popup_rotar()
83 {
84         GdkEventButton event; 
85         event.type = GDK_BUTTON_PRESS;
86         event.button = 2;
87         And::on_button_press_event(&event);
88 }
89
90 void And::save(FILE *archivo)
91 {
92         vec_connector.clear();
93         check_connection();
94         Glib::ustring dato;
95         char c_img[50], c_x[50], c_y[50], c_id[50];
96         sprintf(c_id,"%d",ID);
97         sprintf(c_img,"\t\t<orientacion>%d</orientacion>\n",imgActual);
98         sprintf(c_x,"\t\t<x>%d</x>\n",x);
99         sprintf(c_y,"\t\t<y>%d</y>\n",y);
100         dato = "\t<and nombre=\""+name+"\" id=\"";
101         dato += c_id;
102         dato += "\">\n";
103         dato += c_img;
104         dato += c_x;
105         dato += c_y;
106         for ( int i=0; i<=vec_connector.size()-1&&!vec_connector.empty(); i++) {
107                 if ( vec_connector[i].type == IN ) {
108                         dato += "\t\t<entrada>";
109                         dato += vec_connector[i].name_dest + "</entrada>\n";
110                 } else {
111                         dato += "\t\t<salida>";
112                         dato += vec_connector[i].name_dest + "</salida>\n";
113                 }       
114         }       
115         dato += "\t</and>\n";
116         fprintf(archivo, dato.c_str() );
117 }
118
119 bool And::check_connection()
120 {
121         int cant_in = 0, cant_out =0;
122         t_logic_connector temp;
123         std::list<t_line>::iterator i = workplace->lista_lineas_in.begin();
124         while ( i != workplace->lista_lineas_in.end() ) {
125                 if ( workplace->get_logic_item((*i).logic_id)->get_id() == ID ) {
126                         temp.type = OUT;
127                         temp.name_dest = workplace->get_item((*i).store_id)->get_name();
128                         vec_connector.push_back(temp);
129                         cant_out++;
130                 }
131                 i++;
132         }
133
134         i = workplace->lista_lineas_out.begin();
135         while ( i != workplace->lista_lineas_out.end() ) {
136                 if ( workplace->get_logic_item((*i).logic_id)->get_id() == ID ) {
137                         temp.type = IN;
138                         temp.name_dest = workplace->get_item((*i).store_id)->get_name();
139                         vec_connector.push_back(temp);
140                         cant_in++;
141                 }
142                 i++;
143         }
144         //FIXME   la and tiene n entradas  y una salida!!!!!!!!!!!!!!!
145         return true;// (cant_in == cant_out );
146 }
147
148 ConnectorType And::detect_click_position(int _a, int _b)
149 {
150         switch (imgActual) {
151                 case 0: 
152                         if ( (_a<=32 )&&(_a>=22)&&(_b<=20)&&(_b>=10) )
153                                 return OUT;
154                         if ( (_a<=10)&&(_a>=0)&&(_b<=20)&&(_b>=10) )
155                                 return IN;
156                         break;  
157                 case 1: 
158                         if ( (_a<=20 )&&(_a>=10)&&(_b<=32)&&(_b>=22) )
159                                 return OUT;
160                         if ( (_a<=20)&&(_a>=10)&&(_b<=10)&&(_b>=0) )
161                                 return IN;
162                         break;
163                 case 2: 
164                         if ( (_a<=10 )&&(_a>=0)&&(_b<=20)&&(_b>=10) )
165                                 return OUT;
166                         if ( (_a<=32)&&(_a>=22)&&(_b<=20)&&(_b>=10) )
167                                 return IN;
168                         break;
169                 case 3: 
170                         if ( (_a<=20 )&&(_a>=10)&&(_b<=10)&&(_b>=0) )
171                                 return OUT;
172                         if ( (_a<=20)&&(_a>=10)&&(_b<=32)&&(_b>=22) )
173                                 return IN;
174         }
175         return UNDEF;
176 }
177
178 void And::update_logic_position() 
179 {
180         switch (imgActual) {
181                 case 0: 
182                         in_x = x;
183                         in_y = y+16;
184                         out_x = x+32;
185                         out_y = y+16;
186                         break;
187                 case 1:
188                         in_x = x+16;
189                         in_y = y;
190                         out_x = x+16;
191                         out_y = y+32;
192                         break;
193                 case 2:
194                         in_x = x+32;
195                         in_y = y+16;
196                         out_x = x;
197                         out_y = y+16;
198                         break;
199                 case 3:
200                         in_x = x+16;
201                         in_y = y+32;
202                         out_x = x+16;
203                         out_y = y;
204         }
205 }
206
207 void And::get_in_logic_connect_position(int& _a, int& _b)
208 {
209         _a = in_x;
210         _b = in_y;
211 }
212
213 void And::get_out_logic_connect_position(int& _a, int& _b)
214 {
215         _a =out_x;
216         _b =out_y;
217 }