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