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