3 And::And(int orientacion)
7 imageN = Gdk::Pixbuf::create_from_file(PACKAGE_DATA_DIR"/plaqui-constructor/pixmaps/and_n.png");
8 imageS = Gdk::Pixbuf::create_from_file(PACKAGE_DATA_DIR"/plaqui-constructor/pixmaps/and_s.png");
9 imageE = Gdk::Pixbuf::create_from_file(PACKAGE_DATA_DIR"/plaqui-constructor/pixmaps/and_e.png");
10 imageO = Gdk::Pixbuf::create_from_file(PACKAGE_DATA_DIR"/plaqui-constructor/pixmaps/and_o.png");
11 null = Gdk::Pixbuf::create_from_file(PACKAGE_DATA_DIR"/plaqui-constructor/pixmaps/null.png");
12 imgActual = orientacion;
43 set_size_request(image->get_width(), image->get_height());
45 menulist.push_back( Gtk::Menu_Helpers::ImageMenuElem("Conectar", menu_image_linea,SigC::slot(*this, &CItem::on_menu_popup_conectar) ) ) ;
52 bool And::on_button_press_event(GdkEventButton *event)
54 if ((event->type == GDK_BUTTON_PRESS) && ( event->button == 1)) {
55 WorkPlace::pointed = ID;
57 std::cout << CItem::gate_id << std::endl;
58 if (CItem::logic_connect) {
59 if (CItem::gate_id != -1 ) {
60 if ( detect_click_position((int)event->x, (int)event->y ) == IN && CItem::gate_id != ID && !workplace->get_logic_item(CItem::gate_id)->get_out_logic_connect()) {
61 tmp_line.logic_id = CItem::gate_id;
62 workplace->get_logic_item(CItem::gate_id)->set_out_connected(true);
63 tmp_line.store_id = ID;
64 workplace->lista_lineas_logic.push_back(tmp_line);
65 workplace->queue_draw();
72 if ( CItem::logic_connect && detect_click_position((int)event->x, (int)event->y ) == OUT && !out_connected) {
75 list_pointed->push_back(name);
76 combo_entry->set_popdown_strings(*list_pointed);
77 combo_entry->get_entry()->set_text (name);
78 workplace->queue_draw();
81 sprintf(f," Conector OUT = %d",out_connected);
83 status_bar->push ( text, 0);
86 if ((event->type == GDK_BUTTON_PRESS) && ( event->button == 2)){
88 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);
120 set_size_request(image->get_width(),image->get_height());
121 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);
123 if ((event->type == GDK_BUTTON_PRESS) && ( event->button == 3)){
124 menu_popup.popup(event->button, event->time);
125 return true; //It has been handled.
127 workplace->queue_draw();
130 void And::on_menu_popup_rotar()
132 GdkEventButton event;
133 event.type = GDK_BUTTON_PRESS;
135 And::on_button_press_event(&event);
138 void And::save(FILE *archivo)
140 vec_connector.clear();
143 char c_img[50], c_x[50], c_y[50], c_id[50];
144 sprintf(c_id,"%d",ID);
145 sprintf(c_img,"\t\t<orientacion>%d</orientacion>\n",imgActual);
146 sprintf(c_x,"\t\t<x>%d</x>\n",x);
147 sprintf(c_y,"\t\t<y>%d</y>\n",y);
148 dato = "\t<and nombre=\""+name+"\" id=\"";
154 for ( int i=0; i<=vec_connector.size()-1&&!vec_connector.empty(); i++) {
155 if ( vec_connector[i].type == IN ) {
156 if ( vec_connector[i].cistern_connector == 1 ) {
157 dato += "\t\t<entrada><tanque id = \"superior\">";
158 dato += vec_connector[i].name_dest + "</tanque></entrada>\n";
160 if ( vec_connector[i].cistern_connector == 0 ) {
161 dato += "\t\t<entrada><tanque id = \"inferior\">";
162 dato += vec_connector[i].name_dest + "</tanque></entrada>\n";
164 if ( vec_connector[i].cistern_connector == -1 ) {
165 dato += "\t\t<entrada>";
166 dato += vec_connector[i].name_dest + "</entrada>\n";
169 dato += "\t\t<salida>";
170 dato += vec_connector[i].name_dest + "</salida>\n";
173 dato += "\t</and>\n";
174 fprintf(archivo, dato.c_str() );
177 bool And::check_connection()
179 t_logic_connector temp;
180 std::list<t_line>::iterator i = workplace->lista_lineas_in.begin();
181 while ( i != workplace->lista_lineas_in.end() ) {
182 if ( (*i).logic_id== ID ) {
184 temp.name_dest = workplace->get_item((*i).store_id)->get_name();
185 vec_connector.push_back(temp);
190 i = workplace->lista_lineas_out.begin();
191 while ( i != workplace->lista_lineas_out.end() ) {
192 if ( (*i).logic_id== ID ) {
194 temp.name_dest = workplace->get_item((*i).store_id)->get_name();
195 if ( dynamic_cast<Cistern *>(workplace->get_item((*i).store_id)) ) {
196 if ( (*i).cistern_out1 )
197 temp.cistern_connector = 1; //arriba
199 temp.cistern_connector = 0; //abajo
201 temp.cistern_connector = -1; //si no es tanque.
202 vec_connector.push_back(temp);
207 i = workplace->lista_lineas_logic.begin();
208 while ( i != workplace->lista_lineas_logic.end() ) {
209 if ( (*i).logic_id == ID ) {
211 temp.name_dest = workplace->get_logic_item((*i).store_id)->get_name();
212 vec_connector.push_back(temp);
217 i = workplace->lista_lineas_logic.begin();
218 while ( i != workplace->lista_lineas_logic.end() ) {
219 if ( (*i).store_id == ID ) {
221 temp.name_dest = workplace->get_logic_item((*i).logic_id)->get_name();
222 vec_connector.push_back(temp);
227 return true; //out_connected;
230 ConnectorType And::detect_click_position(int _a, int _b)
234 if ( (_a<=32 )&&(_a>=22)&&(_b<=20)&&(_b>=10) )
236 if ( (_a<=10)&&(_a>=0)&&(_b<=20)&&(_b>=10) )
240 if ( (_a<=20 )&&(_a>=10)&&(_b<=32)&&(_b>=22) )
242 if ( (_a<=20)&&(_a>=10)&&(_b<=10)&&(_b>=0) )
246 if ( (_a<=10 )&&(_a>=0)&&(_b<=20)&&(_b>=10) )
248 if ( (_a<=32)&&(_a>=22)&&(_b<=20)&&(_b>=10) )
252 if ( (_a<=20 )&&(_a>=10)&&(_b<=10)&&(_b>=0) )
254 if ( (_a<=20)&&(_a>=10)&&(_b<=32)&&(_b>=22) )
260 void And::update_logic_position()
289 void And::get_in_logic_connect_position(int& _a, int& _b)
295 void And::get_out_logic_connect_position(int& _a, int& _b)
301 void And::set_out_connected(bool _o)
306 bool And::get_out_logic_connect()
308 return out_connected;
311 void And::draw_connectors()
313 Glib::RefPtr<Gdk::Window> window = get_window();
340 gc->set_foreground(red);
341 gc->set_background(red);
342 window->draw_rectangle(gc, 1, a, b, 10, 10);
343 gc->set_foreground(blue);
344 gc->set_background(blue);
345 window->draw_rectangle(gc, 1, c, d, 10, 10);