4 Or::Or(int orientacion)
8 imageN = Gdk::Pixbuf::create_from_file(PACKAGE_DATA_DIR"/plaqui-constructor/pixmaps/or_n.png");
9 imageS = Gdk::Pixbuf::create_from_file(PACKAGE_DATA_DIR"/plaqui-constructor/pixmaps/or_s.png");
10 imageE = Gdk::Pixbuf::create_from_file(PACKAGE_DATA_DIR"/plaqui-constructor/pixmaps/or_e.png");
11 imageO = Gdk::Pixbuf::create_from_file(PACKAGE_DATA_DIR"/plaqui-constructor/pixmaps/or_o.png");
12 null = Gdk::Pixbuf::create_from_file(PACKAGE_DATA_DIR"/plaqui-constructor/pixmaps/null.png");
13 imgActual = orientacion;
44 set_size_request(image->get_width(), image->get_height());
52 bool Or::on_button_press_event(GdkEventButton *event)
54 if ((event->type == GDK_BUTTON_PRESS) && ( event->button == 1)) {
55 WorkPlace::pointed = ID;
57 if (CItem::logic_connect) {
58 if (CItem::gate_id != -1) {
59 if ( detect_click_position((int)event->x, (int)event->y) == IN && !workplace->get_logic_item(CItem::gate_id)->get_out_logic_connect()) {
60 tmp_line.logic_id = CItem::gate_id;
61 workplace->get_logic_item(CItem::gate_id)->set_out_connected(true);
62 tmp_line.store_id = ID;
63 workplace->lista_lineas_logic.push_back(tmp_line);
64 workplace->queue_draw();
69 if ( CItem::logic_connect ) {
70 if ( detect_click_position((int)event->x, (int)event->y ) == OUT && !out_connected) {
74 list_pointed->push_back(name);
75 combo_entry->set_popdown_strings(*list_pointed);
76 combo_entry->get_entry()->set_text (name);
79 sprintf(f," Conector OUT = %d",out_connected);
81 status_bar->push ( text, 0);
84 if ((event->type == GDK_BUTTON_PRESS) && ( event->button == 2)){
86 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);
118 set_size_request(image->get_width(),image->get_height());
119 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);
121 if ((event->type == GDK_BUTTON_PRESS) && ( event->button == 3)){
122 menu_popup.popup(event->button, event->time);
123 return true; //It has been handled.
125 workplace->queue_draw();
129 void Or::on_menu_popup_rotar()
131 GdkEventButton event;
132 event.type = GDK_BUTTON_PRESS;
134 Or::on_button_press_event(&event);
137 void Or::save(FILE *archivo)
139 vec_connector.clear();
142 char c_img[50], c_x[50], c_y[50], c_id[50];
143 sprintf(c_id,"%d",ID);
144 sprintf(c_img,"\t\t<orientacion>%d</orientacion>\n",imgActual);
145 sprintf(c_x,"\t\t<x>%d</x>\n",x);
146 sprintf(c_y,"\t\t<y>%d</y>\n",y);
147 dato = "\t<or nombre=\""+name+"\" id=\"";
153 for ( int i=0; i<=vec_connector.size()-1&&!vec_connector.empty(); i++) {
154 if ( vec_connector[i].type == IN ) {
155 if ( vec_connector[i].cistern_connector == 1 ) {
156 dato += "\t\t<entrada id = \"superior\">";
157 dato += vec_connector[i].name_dest + "</entrada>\n";
159 if ( vec_connector[i].cistern_connector == 0 ) {
160 dato += "\t\t<entrada id = \"inferior\">";
161 dato += vec_connector[i].name_dest + "</entrada>\n";
163 if ( vec_connector[i].cistern_connector == -1 ) {
164 dato += "\t\t<entrada>";
165 dato += vec_connector[i].name_dest + "</entrada>\n";
168 dato += "\t\t<salida>";
169 dato += vec_connector[i].name_dest + "</salida>\n";
173 fprintf(archivo, dato.c_str() );
176 //<entrada><tanque id="superior">tanque1</tanque></entrada>
178 bool Or::check_connection()
180 int cant_in = 0, cant_out =0;
181 t_logic_connector temp;
182 std::list<t_line>::iterator i = workplace->lista_lineas_in.begin();
183 while ( i != workplace->lista_lineas_in.end() ) {
184 if ( (*i).logic_id== ID ) {
186 temp.name_dest = workplace->get_item((*i).store_id)->get_name();
187 temp.cistern_connector = -1;
188 vec_connector.push_back(temp);
194 i = workplace->lista_lineas_out.begin();
195 while ( i != workplace->lista_lineas_out.end() ) {
196 if ( (*i).logic_id== ID ) {
198 temp.name_dest = workplace->get_item((*i).store_id)->get_name();
199 if ( dynamic_cast<Cistern *>(workplace->get_item((*i).store_id)) ) {
200 if ( (*i).cistern_out1 )
201 temp.cistern_connector = 1; //arriba
203 temp.cistern_connector = 0; //abajo
205 temp.cistern_connector = -1; //si no es tanque.
206 std::cout<<"cistern_connector = "<<temp.cistern_connector<<std::endl;
207 vec_connector.push_back(temp);
213 i = workplace->lista_lineas_logic.begin();
214 while ( i != workplace->lista_lineas_logic.end() ) {
215 if ( (*i).logic_id == ID ) {
217 temp.name_dest = workplace->get_logic_item((*i).store_id)->get_name();
218 vec_connector.push_back(temp);
224 i = workplace->lista_lineas_logic.begin();
225 while ( i != workplace->lista_lineas_logic.end() ) {
226 if ( (*i).store_id == ID ) {
228 temp.name_dest = workplace->get_logic_item((*i).logic_id)->get_name();
229 temp.cistern_connector = -1;
230 vec_connector.push_back(temp);
238 ConnectorType Or::detect_click_position(int _a, int _b)
242 if ( (_a<=32 )&&(_a>=22)&&(_b<=20)&&(_b>=10) )
244 if ( (_a<=10)&&(_a>=0)&&(_b<=20)&&(_b>=10) )
248 if ( (_a<=20 )&&(_a>=10)&&(_b<=32)&&(_b>=22) )
250 if ( (_a<=20)&&(_a>=10)&&(_b<=10)&&(_b>=0) )
254 if ( (_a<=10 )&&(_a>=0)&&(_b<=20)&&(_b>=10) )
256 if ( (_a<=32)&&(_a>=22)&&(_b<=20)&&(_b>=10) )
260 if ( (_a<=20 )&&(_a>=10)&&(_b<=10)&&(_b>=0) )
262 if ( (_a<=20)&&(_a>=10)&&(_b<=32)&&(_b>=22) )
268 void Or::update_logic_position()
297 void Or::get_in_logic_connect_position(int& _a, int& _b)
303 void Or::get_out_logic_connect_position(int& _a, int& _b)
309 void Or::set_out_connected(bool _o)
314 bool Or::get_out_logic_connect()
316 return out_connected;
319 void Or::draw_connectors()
321 Glib::RefPtr<Gdk::Window> window = get_window();
348 gc->set_foreground(red);
349 gc->set_background(red);
350 window->draw_rectangle(gc, 1, a, b, 10, 10);
351 gc->set_foreground(blue);
352 gc->set_background(blue);
353 window->draw_rectangle(gc, 1, c, d, 10, 10);