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