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