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