3 Union::Union(int orientacion)
6 imageN = Gdk::Pixbuf::create_from_file(PACKAGE_DATA_DIR"/plaqui-constructor/pixmaps/y_n.png");
7 imageS = Gdk::Pixbuf::create_from_file(PACKAGE_DATA_DIR"/plaqui-constructor/pixmaps/y_s.png");
8 imageE = Gdk::Pixbuf::create_from_file(PACKAGE_DATA_DIR"/plaqui-constructor/pixmaps/y_e.png");
9 imageO = Gdk::Pixbuf::create_from_file(PACKAGE_DATA_DIR"/plaqui-constructor/pixmaps/y_o.png");
10 null = Gdk::Pixbuf::create_from_file(PACKAGE_DATA_DIR"/plaqui-constructor/pixmaps/null.png");
11 imgActual = orientacion;
26 set_size_request(image->get_width(), image->get_height());
27 property_wnd->set_title("Propiedades del Empalme");
28 property_wnd->rd_btn_division->property_visible() = true;
29 property_wnd->rd_btn_union->property_visible() = true;
30 property_wnd->lb_type->property_visible() = true;
35 connect_vec.push_back(temp); //izquierda
36 connect_vec.push_back(temp); //derecha
38 connect_vec.push_back(temp); //medio
45 bool Union::on_button_press_event(GdkEventButton *event)
47 if ((event->type == GDK_BUTTON_PRESS) && ( event->button == 1)) {
48 list_pointed->push_back(name);
49 combo_entry->set_popdown_strings(*list_pointed);
50 combo_entry->get_entry()->set_text (name);
51 workplace->queue_draw();
52 WorkPlace::pointed = ID;
55 if ((event->type == GDK_BUTTON_PRESS) && (event->button == 2 )){
57 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);
73 set_size_request(image->get_width(), image->get_height());
74 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);
76 if ((event->type == GDK_BUTTON_PRESS) && ( event->button == 3)){
77 menu_popup.popup(event->button, event->time);
78 return true; //It has been handled.
81 if ((event->type == GDK_2BUTTON_PRESS) && ( event->button == 1)){
82 property_wnd->spin_caudal->set_value( caudal_max );
83 property_wnd->txt_item_name->set_text( name );
84 if (is_union) property_wnd->rd_btn_union->set_active(true);
90 void Union::on_menu_popup_rotar()
93 event.type = GDK_BUTTON_PRESS;
95 Union::on_button_press_event(&event);
98 void Union::on_menu_popup_propiedades()
100 GdkEventButton event;
101 event.type = GDK_2BUTTON_PRESS;
103 Union::on_button_press_event(&event);
106 void Union::save(FILE *archivo)
108 char c_id[50], c_caudal[50], c_x[50], c_y[50], c_img[50];
109 Glib::ustring con0, con1, con2, c_type;
111 con0 = "\t\t\t<entrada>"+get_other_name(connect_vec[0].id_dest)+"</entrada>\n";
112 con1 = "\t\t\t<entrada>"+get_other_name(connect_vec[1].id_dest)+"</entrada>\n";
113 con2 = "\t\t\t<salida>"+get_other_name(connect_vec[2].id_dest)+"</salida>\n";
114 c_type = "\t\t<tipo>union</tipo>\n";
116 con0 = "\t\t\t<salida>"+get_other_name(connect_vec[0].id_dest)+"</salida>\n";
117 con1 = "\t\t\t<salida>"+get_other_name(connect_vec[1].id_dest)+"</salida>\n";
118 con2 = "\t\t\t<entrada>"+get_other_name(connect_vec[2].id_dest)+"</entrada>\n";
119 c_type = "\t\t<tipo>division</tipo>\n";
121 sprintf(c_x,"\t\t<x>%d</x>\n",x);
122 sprintf(c_y,"\t\t<y>%d</y>\n",y);
123 sprintf(c_id,"%d",ID);
124 sprintf(c_caudal,"\t\t<caudal>%.2f</caudal>\n", caudal_max);
125 sprintf(c_img,"\t\t<orientacion>%d</orientacion>\n",imgActual);
127 dato = "\t<empalme nombre=\""+name+"\" id=\"";
131 dato += "\t\t<conector>\n"+con0+con1+con2+"\t\t</conector>\n";
136 dato += "\t</empalme>\n";
137 fprintf(archivo,dato.c_str());
140 bool Union::check_connection()
142 CItem * _item0, *_item1, *_item2;
143 ConnectorType temp0, temp1, temp2;
144 switch (get_img_actual()) {
146 temp0 = is_other_connection_area( get_position_x() - 5, get_position_y() +16, &_item0);
147 temp1 = is_other_connection_area( get_position_x()+get_image()->get_width()+5, get_position_y()+16, &_item1);
148 temp2 = is_other_connection_area( get_position_x()+get_image()->get_width()/2, get_position_y()+get_image()->get_height()+5, &_item2);
151 temp2 = is_other_connection_area( get_position_x()-5, get_position_y()+get_image()->get_height()/2, &_item2);
152 temp0 = is_other_connection_area( get_position_x()+get_image()->get_width()-16, get_position_y()-5, &_item0);
153 temp1 = is_other_connection_area( get_position_x()+get_image()->get_width()-16, get_position_y()+get_image()->get_height()+5,& _item1);
156 temp1 = is_other_connection_area( get_position_x()-5, get_position_y()+get_image()->get_height()-16,& _item1);
157 temp2 = is_other_connection_area( get_position_x()+get_image()->get_width()/2, get_position_y()-5, &_item2);
158 temp0 = is_other_connection_area( get_position_x()+get_image()->get_width()+5, get_position_y()+get_image()->get_height()-16, &_item0);
161 temp1 = is_other_connection_area( get_position_x()+16, get_position_y()-5, &_item1);
162 temp2 = is_other_connection_area( get_position_x()+get_image()->get_width()+5, get_position_y()+get_image()->get_height()/2,& _item0);
163 temp0 = is_other_connection_area( get_position_x()+16, get_position_y()+get_image()->get_height()+5, &_item1);
166 if ( temp0 == OUT && temp1 == OUT && temp2 == IN ) {
167 connect_vec[0].id_dest = _item0->get_id();
168 connect_vec[1].id_dest = _item1->get_id();
169 connect_vec[2].id_dest = _item2->get_id();
170 return (is_connected = true);
173 if ( temp0 == IN && temp1 == IN && temp2 == OUT ) {
174 connect_vec[0].id_dest = _item0->get_id();
175 connect_vec[1].id_dest = _item1->get_id();
176 connect_vec[2].id_dest = _item2->get_id();
177 return (is_connected = true);
183 ConnectorType Union::get_connector_type(int _a, int _b)
185 switch ( imgActual) {
186 case 0: if ((_a <= x+10) && (_a > x+1) && (_b<= y + 22) && (_b >= y+10))
187 return connect_vec[0].type;
188 if ((_a <= x+image->get_width()-1) && (_a >= x+image->get_width()-10)&&(_b <= y+22) && (_b >= y+10))
189 return connect_vec[1].type;
190 if ((_a <= x+image->get_width()/2 + 5)&&( _a>= x+image->get_width()/2 - 5) && (_b<=y+image->get_height()-1)&&(_b >= y+image->get_height()-10))
191 return connect_vec[2].type;
193 case 1: if ((_a <= x+image->get_width()-10) && (_a >= x+image->get_width() -22) && (_b<= y + 10) && (_b > y ))
194 return connect_vec[0].type;
195 if ((_a <= x +10) && (_a > x )&&(_b <= y+image->get_height()/2+5 ) && (_b >= y+image->get_height()/2-5))
196 return connect_vec[2].type;
197 if ((_a <= x+image->get_width() - 10)&&( _a>= x+image->get_width()-22) && (_b<=y+image->get_height()-1)&&(_b >= y+image->get_height()-10))
198 return connect_vec[1].type;
200 case 2: if ((_a <= x+10) && (_a > x) && (_b<= y+image->get_height()-10) && (_b >= y+image->get_height()-22))
201 return connect_vec[1].type;
202 if ((_a <= x+image->get_width()-1) && (_a >= x+image->get_width()-10)&&(_b <= y+image->get_height()-10) && (_b >= y+image->get_height()-22))
203 return connect_vec[0].type;
204 if ((_a <= x+image->get_width()/2 + 5)&&( _a>= x+image->get_width()/2 - 5) && (_b<=y+10)&&(_b > y))
205 return connect_vec[2].type;
207 case 3: if ((_a <= x+22) && (_a >= x+10) && (_b<= y + 10) && (_b > y ))
208 return connect_vec[1].type;
209 if ((_a <= x+22) && (_a >= x+10 )&&(_b <= y+image->get_height()-1 ) && (_b >= y+image->get_height()-10))
210 return connect_vec[0].type;
211 if ((_a <= x+image->get_width() -1)&&( _a>= x+image->get_width()-10) && (_b<=y+image->get_height()/2+5)&&(_b >= y+image->get_height()/2-5))
212 return connect_vec[2].type;
217 void Union::set_default_connector()
220 connect_vec[0].type = IN;
221 connect_vec[1].type = IN;
222 connect_vec[2].type = OUT;
224 connect_vec[0].type = OUT;
225 connect_vec[1].type = OUT;
226 connect_vec[2].type = IN;