3 Splitter::Splitter(int orientacion)
5 imageN = Gdk::Pixbuf::create_from_file(PACKAGE_DATA_DIR"/plaqui-constructor/pixmaps/codo_n.png");
6 imageS = Gdk::Pixbuf::create_from_file(PACKAGE_DATA_DIR"/plaqui-constructor/pixmaps/codo_s.png");
7 imageE = Gdk::Pixbuf::create_from_file(PACKAGE_DATA_DIR"/plaqui-constructor/pixmaps/codo_e.png");
8 imageO = Gdk::Pixbuf::create_from_file(PACKAGE_DATA_DIR"/plaqui-constructor/pixmaps/codo_o.png");
9 null = Gdk::Pixbuf::create_from_file(PACKAGE_DATA_DIR"/plaqui-constructor/pixmaps/null.png");
10 imgActual = orientacion;
25 set_size_request(image->get_width(), image->get_height());
26 property_wnd->set_title("Propiedades del Codo");
31 connect_vec.push_back(temp);
32 connect_vec.push_back(temp);
39 bool Splitter::on_button_press_event(GdkEventButton *event)
41 if ((event->type == GDK_BUTTON_PRESS) && ( event->button == 1))
42 combo_entry->set_text(name);
44 if ((event->type == GDK_BUTTON_PRESS) && ( event->button == 2)){
46 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);
62 set_size_request(image->get_width(),image->get_height());
63 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 if ((event->type == GDK_BUTTON_PRESS) && ( event->button == 3)){
66 menu_popup.popup(event->button, event->time);
67 return true; //It has been handled.
70 if ((event->type == GDK_2BUTTON_PRESS) && ( event->button == 1)){
71 property_wnd->spin_caudal->set_value( caudal_max );
72 property_wnd->txt_item_name->set_text( name );
77 void Splitter::on_menu_popup_rotar()
80 event.type = GDK_BUTTON_PRESS;
82 Splitter::on_button_press_event(&event);
85 void Splitter::on_menu_popup_propiedades()
88 event.type = GDK_2BUTTON_PRESS;
90 Splitter::on_button_press_event(&event);
93 void Splitter::save(FILE *archivo)
95 char c_id[50], c_caudal[50], c_x[50], c_y[50], c_img[50];
96 Glib::ustring con0, con1;
97 if (connect_vec[0].type == IN)
98 con0 = "\t\t\t<entrada>"+get_other_name(connect_vec[0].id_dest)+"</entrada>\n";
100 con0 = "\t\t\t<salida>"+get_other_name(connect_vec[0].id_dest)+"</salida>\n";
101 if (connect_vec[1].type == IN)
102 con1 = "\t\t\t<entrada>"+get_other_name(connect_vec[1].id_dest)+"</entrada>\n";
104 con1 = "\t\t\t<salida>"+get_other_name(connect_vec[1].id_dest)+"</salida>\n";
105 sprintf(c_x,"\t\t<x>%d</x>\n",x);
106 sprintf(c_y,"\t\t<y>%d</y>\n",y);
107 sprintf(c_id,"%d",ID);
108 sprintf(c_caudal,"\t\t<caudal>%.2f</caudal>\n", caudal_max);
109 sprintf(c_img,"\t\t<orientacion>%d</orientacion>\n",imgActual);
111 dato = "\t<codo nombre=\""+name+"\" id=\"";
115 dato += "\t\t<conector>\n"+con0 + con1+"\t\t</conector>\n";
119 dato += "\t</codo>\n";
120 fprintf(archivo,dato.c_str());
123 bool Splitter::check_connection()
126 CItem *_item0, *_item1;
127 switch (get_img_actual()) {
129 connect_vec[0].type = is_other_connection_area( get_position_x()-5, get_position_y()+16, &_item0); //arriba-izquierda h
130 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
133 connect_vec[0].type = is_other_connection_area( get_position_x()+get_image()->get_width() - 16, get_position_y() -5,& _item0);//arriba-derecha v
134 connect_vec[1].type = is_other_connection_area( get_position_x()-5, get_position_y()+get_image()->get_height()-16, &_item1);//abajo-izquierda h
137 connect_vec[1].type = is_other_connection_area( get_position_x() + 16, get_position_y() - 5, &_item1);//arriba-izquierda v
138 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
141 connect_vec[1].type = is_other_connection_area( get_position_x()+get_image()->get_width()+5, get_position_y() +16,& _item1);//arriba-derecha h
142 connect_vec[0].type = is_other_connection_area( get_position_x() + 16, get_position_y()+get_image()->get_height() + 5, &_item0); //abajo-izquierda v
144 if (connect_vec[0].type != UNDEF && connect_vec[1].type != UNDEF) {
145 aux = connect_vec[0].type;
146 connect_vec[0].type = connect_vec[1].type;
147 connect_vec[1].type = aux;
148 connect_vec[0].id_dest = _item0->get_id();
149 connect_vec[1].id_dest = _item1->get_id();
150 return ( is_connected = (connect_vec[0].type != connect_vec[1].type) );
152 else return is_connected;
155 ConnectorType Splitter::get_connector_type(int _a, int _b)
158 if ( ! is_connected ) {
161 if ( (_a <= x+10)&&(_a > x) && (_b <=y+22)&&(_b>=y+10) ) // arriba - izquierda h
162 return is_other_connection_area (get_position_x()+get_image()->get_width()-16, +get_position_y()+get_image()->get_height() + 5, &_item);
163 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
164 return is_other_connection_area( get_position_x()-5, get_position_y()+16,& _item);
167 if ( (_a <= x+image->get_width()-10)&&(_a >= x+image->get_width()-22) && (_b <=y+10)&&(_b > y) ) //arriba-derecha v
168 return is_other_connection_area( get_position_x()-5, get_position_y()+get_image()->get_height()-16, &_item);
169 if ( (_a <= x+10)&&(_a > x)&&(_b<=y+image->get_height()-10)&&(_b>=y+image->get_height()-22) ) // abajo-izquierda h
170 return is_other_connection_area( get_position_x()+get_image()->get_width() - 16, get_position_y() -5, &_item);
173 if ( (_a <= x+22)&&(_a >= x+10) && (_b <=y+10)&&(_b > y) ) //arriba-izquierda v
174 return is_other_connection_area( get_position_x()+get_image()->get_width()+5, get_position_y()+get_image()->get_height() - 16, &_item);
175 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
176 return is_other_connection_area( get_position_x() + 16, get_position_y() - 5,& _item);
179 if ( (_a <= x+image->get_width()-1)&&(_a >= x+image->get_width()-10) && (_b <=y+22)&&(_b>=y+10) ) //arriba-derecha h
180 return is_other_connection_area( get_position_x() + 16, get_position_y()+get_image()->get_height() + 5, &_item);
181 if ( (_a <= x+22)&&(_a>=x+10)&&(_b<=y+image->get_height()-1)&&(_b>=y+image->get_height()-10) ) // abajo-izquierda v
182 return is_other_connection_area( get_position_x()+get_image()->get_width()+5, get_position_y() +16,& _item);
187 if ( (_a <= x+10)&&(_a > x) && (_b <=y+22)&&(_b>=y+10) ) // arriba - izquierda h
188 return connect_vec[0].type;
189 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
190 return connect_vec[1].type;
193 if ( (_a <= x+image->get_width()-10)&&(_a >= x+image->get_width()-22) && (_b <=y+10)&&(_b > y) ) //arriba-derecha v
194 return connect_vec[0].type;
195 if ( (_a <= x+10)&&(_a > x)&&(_b<=y+image->get_height()-10)&&(_b>=y+image->get_height()-22) ) // abajo-izquierda h
196 return connect_vec[1].type;
199 if ( (_a <= x+22)&&(_a >= x+10) && (_b <=y+10)&&(_b > y) ) //arriba-izquierda v
200 return connect_vec[1].type;
201 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
202 return connect_vec[0].type;
205 if ( (_a <= x+image->get_width()-1)&&(_a >= x+image->get_width()-10) && (_b <=y+22)&&(_b>=y+10) ) //arriba-derecha h
206 return connect_vec[1].type;
207 if ( (_a <= x+22)&&(_a>=x+10)&&(_b<=y+image->get_height()-1)&&(_b>=y+image->get_height()-10) ) // abajo-izquierda v
208 return connect_vec[0].type;
214 void Splitter::set_default_connector()
216 connect_vec[0].type = UNDEF;
217 connect_vec[1].type = UNDEF;