]> git.llucax.com Git - z.facultad/75.42/plaqui.git/blob - Constructor/src/not.cpp
0d7e409a322b83355afb574e60c58bb92e02e5b1
[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         return true;// (in_connected    == out_connected ) ==true;
153 }
154
155 ConnectorType Not::detect_click_position(int _a, int _b)
156 {
157         switch (imgActual) {
158                 case 0: 
159                         if ( (_a<=32 )&&(_a>=22)&&(_b<=20)&&(_b>=10) )
160                                 return OUT;
161                         if ( (_a<=10)&&(_a>=0)&&(_b<=20)&&(_b>=10) )
162                                 return IN;
163                         break;  
164                 case 1: 
165                         if ( (_a<=20 )&&(_a>=10)&&(_b<=32)&&(_b>=22) )
166                                 return OUT;
167                         if ( (_a<=20)&&(_a>=10)&&(_b<=10)&&(_b>=0) )
168                                 return IN;
169                         break;
170                 case 2: 
171                         if ( (_a<=10 )&&(_a>=0)&&(_b<=20)&&(_b>=10) )
172                                 return OUT;
173                         if ( (_a<=32)&&(_a>=22)&&(_b<=20)&&(_b>=10) )
174                                 return IN;
175                         break;
176                 case 3: 
177                         if ( (_a<=20 )&&(_a>=10)&&(_b<=10)&&(_b>=0) )
178                                 return OUT;
179                         if ( (_a<=20)&&(_a>=10)&&(_b<=32)&&(_b>=22) )
180                                 return IN;
181         }
182         return UNDEF;
183 }
184
185 void Not::update_logic_position() 
186 {
187         switch (imgActual) {
188                 case 0: 
189                         in_x = x;
190                         in_y = y+16;
191                         out_x = x+32;
192                         out_y = y+16;
193                         break;
194                 case 1:
195                         in_x = x+16;
196                         in_y = y;
197                         out_x = x+16;
198                         out_y = y+32;
199                         break;
200                 case 2:
201                         in_x = x+32;
202                         in_y = y+16;
203                         out_x = x;
204                         out_y = y+16;
205                         break;
206                 case 3:
207                         in_x = x+16;
208                         in_y = y+32;
209                         out_x = x+16;
210                         out_y = y;
211         }
212 }
213
214 void Not::get_in_logic_connect_position(int& _a, int& _b)
215 {
216         _a = in_x;
217         _b = in_y;
218 }
219
220 void Not::get_out_logic_connect_position(int& _a, int& _b)
221 {
222         _a =out_x;
223         _b =out_y;
224 }
225
226 void Not::set_out_connected(bool _o)
227 {
228         out_connected = _o;
229 }
230
231 void Not::set_in_connected(bool _o)
232 {
233         in_connected = _o;
234 }