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());
46 menulist.push_back( Gtk::Menu_Helpers::ImageMenuElem("Conectar", menu_image_linea,SigC::slot(*this, &CItem::on_menu_popup_conectar) ) ) ;
53 bool Or::on_button_press_event(GdkEventButton *event)
55 if ((event->type == GDK_BUTTON_PRESS) && ( event->button == 1)) {
56 WorkPlace::pointed = ID;
58 if (CItem::logic_connect) {
59 if (CItem::gate_id != -1) {
60 if ( detect_click_position((int)event->x, (int)event->y) == IN && !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();
70 if ( CItem::logic_connect ) {
71 if ( 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);
80 sprintf(f," Conector OUT = %d",out_connected);
82 status_bar->push ( text, 0);
85 if ((event->type == GDK_BUTTON_PRESS) && ( event->button == 2)){
87 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);
119 set_size_request(image->get_width(),image->get_height());
120 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);
122 if ((event->type == GDK_BUTTON_PRESS) && ( event->button == 3)){
123 menu_popup.popup(event->button, event->time);
124 return true; //It has been handled.
126 workplace->queue_draw();
130 void Or::on_menu_popup_rotar()
132 GdkEventButton event;
133 event.type = GDK_BUTTON_PRESS;
135 Or::on_button_press_event(&event);
138 void Or::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<or 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 id = \"superior\">";
158 dato += vec_connector[i].name_dest + "</entrada>\n";
160 if ( vec_connector[i].cistern_connector == 0 ) {
161 dato += "\t\t<entrada id = \"inferior\">";
162 dato += vec_connector[i].name_dest + "</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";
174 fprintf(archivo, dato.c_str() );
177 //<entrada><tanque id="superior">tanque1</tanque></entrada>
179 bool Or::check_connection()
181 int cant_in = 0, cant_out =0;
182 t_logic_connector temp;
183 std::list<t_line>::iterator i = workplace->lista_lineas_in.begin();
184 while ( i != workplace->lista_lineas_in.end() ) {
185 if ( (*i).logic_id== ID ) {
187 temp.name_dest = workplace->get_item((*i).store_id)->get_name();
188 temp.cistern_connector = -1;
189 vec_connector.push_back(temp);
195 i = workplace->lista_lineas_out.begin();
196 while ( i != workplace->lista_lineas_out.end() ) {
197 if ( (*i).logic_id== ID ) {
199 temp.name_dest = workplace->get_item((*i).store_id)->get_name();
200 if ( dynamic_cast<Cistern *>(workplace->get_item((*i).store_id)) ) {
201 if ( (*i).cistern_out1 )
202 temp.cistern_connector = 1; //arriba
204 temp.cistern_connector = 0; //abajo
206 temp.cistern_connector = -1; //si no es tanque.
207 std::cout<<"cistern_connector = "<<temp.cistern_connector<<std::endl;
208 vec_connector.push_back(temp);
214 i = workplace->lista_lineas_logic.begin();
215 while ( i != workplace->lista_lineas_logic.end() ) {
216 if ( (*i).logic_id == ID ) {
218 temp.name_dest = workplace->get_logic_item((*i).store_id)->get_name();
219 vec_connector.push_back(temp);
225 i = workplace->lista_lineas_logic.begin();
226 while ( i != workplace->lista_lineas_logic.end() ) {
227 if ( (*i).store_id == ID ) {
229 temp.name_dest = workplace->get_logic_item((*i).logic_id)->get_name();
230 temp.cistern_connector = -1;
231 vec_connector.push_back(temp);
239 ConnectorType Or::detect_click_position(int _a, int _b)
243 if ( (_a<=32 )&&(_a>=22)&&(_b<=20)&&(_b>=10) )
245 if ( (_a<=10)&&(_a>=0)&&(_b<=20)&&(_b>=10) )
249 if ( (_a<=20 )&&(_a>=10)&&(_b<=32)&&(_b>=22) )
251 if ( (_a<=20)&&(_a>=10)&&(_b<=10)&&(_b>=0) )
255 if ( (_a<=10 )&&(_a>=0)&&(_b<=20)&&(_b>=10) )
257 if ( (_a<=32)&&(_a>=22)&&(_b<=20)&&(_b>=10) )
261 if ( (_a<=20 )&&(_a>=10)&&(_b<=10)&&(_b>=0) )
263 if ( (_a<=20)&&(_a>=10)&&(_b<=32)&&(_b>=22) )
269 void Or::update_logic_position()
298 void Or::get_in_logic_connect_position(int& _a, int& _b)
304 void Or::get_out_logic_connect_position(int& _a, int& _b)
310 void Or::set_out_connected(bool _o)
315 bool Or::get_out_logic_connect()
317 return out_connected;
320 void Or::draw_connectors()
322 Glib::RefPtr<Gdk::Window> window = get_window();
349 gc->set_foreground(red);
350 gc->set_background(red);
351 window->draw_rectangle(gc, 1, a, b, 10, 10);
352 gc->set_foreground(blue);
353 gc->set_background(blue);
354 window->draw_rectangle(gc, 1, c, d, 10, 10);