3 Splitter::Splitter(int orientacion)
6 imageN = Gdk::Pixbuf::create_from_file(PACKAGE_DATA_DIR"/plaqui-constructor/pixmaps/codo_n.png");
7 imageS = Gdk::Pixbuf::create_from_file(PACKAGE_DATA_DIR"/plaqui-constructor/pixmaps/codo_s.png");
8 imageE = Gdk::Pixbuf::create_from_file(PACKAGE_DATA_DIR"/plaqui-constructor/pixmaps/codo_e.png");
9 imageO = Gdk::Pixbuf::create_from_file(PACKAGE_DATA_DIR"/plaqui-constructor/pixmaps/codo_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 Codo");
32 connect_vec.push_back(temp);
33 connect_vec.push_back(temp);
40 bool Splitter::on_button_press_event(GdkEventButton *event)
42 if ((event->type == GDK_BUTTON_PRESS) && ( event->button == 1)) {
43 combo_entry->set_text(name);
44 WorkPlace::pointed = ID;
47 if ((event->type == GDK_BUTTON_PRESS) && ( event->button == 2)){
49 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);
65 set_size_request(image->get_width(),image->get_height());
66 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);
68 if ((event->type == GDK_BUTTON_PRESS) && ( event->button == 3)){
69 menu_popup.popup(event->button, event->time);
70 return true; //It has been handled.
73 if ((event->type == GDK_2BUTTON_PRESS) && ( event->button == 1)){
74 property_wnd->spin_caudal->set_value( caudal_max );
75 property_wnd->txt_item_name->set_text( name );
80 void Splitter::on_menu_popup_rotar()
83 event.type = GDK_BUTTON_PRESS;
85 Splitter::on_button_press_event(&event);
88 void Splitter::on_menu_popup_propiedades()
91 event.type = GDK_2BUTTON_PRESS;
93 Splitter::on_button_press_event(&event);
96 void Splitter::save(FILE *archivo)
98 char c_id[50], c_caudal[50], c_x[50], c_y[50], c_img[50];
99 Glib::ustring con0, con1;
100 if (connect_vec[0].type == IN)
101 con0 = "\t\t\t<entrada>"+get_other_name(connect_vec[0].id_dest)+"</entrada>\n";
103 con0 = "\t\t\t<salida>"+get_other_name(connect_vec[0].id_dest)+"</salida>\n";
104 if (connect_vec[1].type == IN)
105 con1 = "\t\t\t<entrada>"+get_other_name(connect_vec[1].id_dest)+"</entrada>\n";
107 con1 = "\t\t\t<salida>"+get_other_name(connect_vec[1].id_dest)+"</salida>\n";
108 sprintf(c_x,"\t\t<x>%d</x>\n",x);
109 sprintf(c_y,"\t\t<y>%d</y>\n",y);
110 sprintf(c_id,"%d",ID);
111 sprintf(c_caudal,"\t\t<caudal>%.2f</caudal>\n", caudal_max);
112 sprintf(c_img,"\t\t<orientacion>%d</orientacion>\n",imgActual);
114 dato = "\t<codo nombre=\""+name+"\" id=\"";
118 dato += "\t\t<conector>\n"+con0 + con1+"\t\t</conector>\n";
122 dato += "\t</codo>\n";
123 fprintf(archivo,dato.c_str());
126 bool Splitter::check_connection()
129 CItem *_item0, *_item1;
130 switch (get_img_actual()) {
132 connect_vec[0].type = is_other_connection_area( get_position_x()-5, get_position_y()+16, &_item0); //arriba-izquierda h
133 connect_vec[1].type = is_other_connection_area( get_position_x()+get_image()->get_width()-16, +get_position_y()+get_image()->get_height() + 5, &_item1);//abajo-derecha v
136 connect_vec[0].type = is_other_connection_area( get_position_x()+get_image()->get_width() - 16, get_position_y() -5,& _item0);//arriba-derecha v
137 connect_vec[1].type = is_other_connection_area( get_position_x()-5, get_position_y()+get_image()->get_height()-16, &_item1);//abajo-izquierda h
140 connect_vec[1].type = is_other_connection_area( get_position_x() + 16, get_position_y() - 5, &_item1);//arriba-izquierda v
141 connect_vec[0].type = is_other_connection_area( get_position_x()+get_image()->get_width()+5, get_position_y()+get_image()->get_height() - 16, &_item0); //abajo-derecha h
144 connect_vec[1].type = is_other_connection_area( get_position_x()+get_image()->get_width()+5, get_position_y() +16,& _item1);//arriba-derecha h
145 connect_vec[0].type = is_other_connection_area( get_position_x() + 16, get_position_y()+get_image()->get_height() + 5, &_item0); //abajo-izquierda v
147 if (connect_vec[0].type != UNDEF && connect_vec[1].type != UNDEF) {
148 aux = connect_vec[0].type;
149 connect_vec[0].type = connect_vec[1].type;
150 connect_vec[1].type = aux;
151 connect_vec[0].id_dest = _item0->get_id();
152 connect_vec[1].id_dest = _item1->get_id();
153 return ( is_connected = (connect_vec[0].type != connect_vec[1].type) );
155 else return is_connected;
158 ConnectorType Splitter::get_connector_type(int _a, int _b)
161 if ( ! is_connected ) {
164 if ( (_a <= x+10)&&(_a > x) && (_b <=y+22)&&(_b>=y+10) ) // arriba - izquierda h
165 return is_other_connection_area (get_position_x()+get_image()->get_width()-16, +get_position_y()+get_image()->get_height() + 5, &_item);
166 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) )//abajo-derecha v
167 return is_other_connection_area( get_position_x()-5, get_position_y()+16,& _item);
170 if ( (_a <= x+image->get_width()-10)&&(_a >= x+image->get_width()-22) && (_b <=y+10)&&(_b > y) ) //arriba-derecha v
171 return is_other_connection_area( get_position_x()-5, get_position_y()+get_image()->get_height()-16, &_item);
172 if ( (_a <= x+10)&&(_a > x)&&(_b<=y+image->get_height()-10)&&(_b>=y+image->get_height()-22) ) // abajo-izquierda h
173 return is_other_connection_area( get_position_x()+get_image()->get_width() - 16, get_position_y() -5, &_item);
176 if ( (_a <= x+22)&&(_a >= x+10) && (_b <=y+10)&&(_b > y) ) //arriba-izquierda v
177 return is_other_connection_area( get_position_x()+get_image()->get_width()+5, get_position_y()+get_image()->get_height() - 16, &_item);
178 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) ) // abajo-derecha h
179 return is_other_connection_area( get_position_x() + 16, get_position_y() - 5,& _item);
182 if ( (_a <= x+image->get_width()-1)&&(_a >= x+image->get_width()-10) && (_b <=y+22)&&(_b>=y+10) ) //arriba-derecha h
183 return is_other_connection_area( get_position_x() + 16, get_position_y()+get_image()->get_height() + 5, &_item);
184 if ( (_a <= x+22)&&(_a>=x+10)&&(_b<=y+image->get_height()-1)&&(_b>=y+image->get_height()-10) ) // abajo-izquierda v
185 return is_other_connection_area( get_position_x()+get_image()->get_width()+5, get_position_y() +16,& _item);
190 if ( (_a <= x+10)&&(_a > x) && (_b <=y+22)&&(_b>=y+10) ) // arriba - izquierda h
191 return connect_vec[0].type;
192 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) )//abajo-derecha v
193 return connect_vec[1].type;
196 if ( (_a <= x+image->get_width()-10)&&(_a >= x+image->get_width()-22) && (_b <=y+10)&&(_b > y) ) //arriba-derecha v
197 return connect_vec[0].type;
198 if ( (_a <= x+10)&&(_a > x)&&(_b<=y+image->get_height()-10)&&(_b>=y+image->get_height()-22) ) // abajo-izquierda h
199 return connect_vec[1].type;
202 if ( (_a <= x+22)&&(_a >= x+10) && (_b <=y+10)&&(_b > y) ) //arriba-izquierda v
203 return connect_vec[1].type;
204 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) ) // abajo-derecha h
205 return connect_vec[0].type;
208 if ( (_a <= x+image->get_width()-1)&&(_a >= x+image->get_width()-10) && (_b <=y+22)&&(_b>=y+10) ) //arriba-derecha h
209 return connect_vec[1].type;
210 if ( (_a <= x+22)&&(_a>=x+10)&&(_b<=y+image->get_height()-1)&&(_b>=y+image->get_height()-10) ) // abajo-izquierda v
211 return connect_vec[0].type;
217 void Splitter::set_default_connector()
219 connect_vec[0].type = UNDEF;
220 connect_vec[1].type = UNDEF;