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 list_pointed->push_back(name);
44 combo_entry->set_popdown_strings(*list_pointed);
45 combo_entry->get_entry()->set_text (name);
46 workplace->queue_draw();
47 WorkPlace::pointed = ID;
50 sprintf(f,"%.1f",caudal_max);
51 text = name+" Caudal Maximo: ";
53 status_bar->push ( text, 0);
56 if ((event->type == GDK_BUTTON_PRESS) && ( event->button == 2)){
58 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);
74 set_size_request(image->get_width(),image->get_height());
75 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);
77 if ((event->type == GDK_BUTTON_PRESS) && ( event->button == 3)){
78 menu_popup.popup(event->button, event->time);
79 return true; //It has been handled.
82 if ((event->type == GDK_2BUTTON_PRESS) && ( event->button == 1)){
83 property_wnd->spin_caudal->set_value( caudal_max );
84 property_wnd->txt_item_name->set_text( name );
89 void Splitter::on_menu_popup_rotar()
92 event.type = GDK_BUTTON_PRESS;
94 Splitter::on_button_press_event(&event);
97 void Splitter::on_menu_popup_propiedades()
100 event.type = GDK_2BUTTON_PRESS;
102 Splitter::on_button_press_event(&event);
105 void Splitter::save(FILE *archivo)
107 char c_id[50], c_caudal[50], c_x[50], c_y[50], c_img[50];
108 Glib::ustring con0, con1;
109 if (connect_vec[0].type == IN)
110 con0 = "\t\t\t<entrada>"+get_other_name(connect_vec[0].id_dest)+"</entrada>\n";
112 con0 = "\t\t\t<salida>"+get_other_name(connect_vec[0].id_dest)+"</salida>\n";
113 if (connect_vec[1].type == IN)
114 con1 = "\t\t\t<entrada>"+get_other_name(connect_vec[1].id_dest)+"</entrada>\n";
116 con1 = "\t\t\t<salida>"+get_other_name(connect_vec[1].id_dest)+"</salida>\n";
117 sprintf(c_x,"\t\t<x>%d</x>\n",x);
118 sprintf(c_y,"\t\t<y>%d</y>\n",y);
119 sprintf(c_id,"%d",ID);
120 sprintf(c_caudal,"\t\t<caudal>%.2f</caudal>\n", caudal_max);
121 sprintf(c_img,"\t\t<orientacion>%d</orientacion>\n",imgActual);
123 dato = "\t<codo nombre=\""+name+"\" id=\"";
127 dato += "\t\t<conector>\n"+con0 + con1+"\t\t</conector>\n";
131 dato += "\t</codo>\n";
132 fprintf(archivo,dato.c_str());
135 bool Splitter::check_connection()
137 ConnectorType aux, aux1, aux2;
138 CItem *_item0, *_item1;
139 switch (get_img_actual()) {
141 aux1 = is_other_connection_area( get_position_x()-5, get_position_y()+16, &_item0); //arriba-izquierda h
142 aux2 = is_other_connection_area( get_position_x()+get_image()->get_width()-16, +get_position_y()+get_image()->get_height() + 5, &_item1);//abajo-derecha v
145 aux1 = is_other_connection_area( get_position_x()+get_image()->get_width() - 16, get_position_y() -5,& _item0);//arriba-derecha v
146 aux2 = is_other_connection_area( get_position_x()-5, get_position_y()+get_image()->get_height()-16, &_item1);//abajo-izquierda h
149 aux2 = is_other_connection_area( get_position_x() + 16, get_position_y() - 5, &_item1);//arriba-izquierda v
150 aux1 = is_other_connection_area( get_position_x()+get_image()->get_width()+5, get_position_y()+get_image()->get_height() - 16, &_item0); //abajo-derecha h
153 aux2 = is_other_connection_area( get_position_x()+get_image()->get_width()+5, get_position_y() +16,& _item1);//arriba-derecha h
154 aux1 = is_other_connection_area( get_position_x() + 16, get_position_y()+get_image()->get_height() + 5, &_item0); //abajo-izquierda v
156 if ((aux2 != UNDEF) && (aux1 != UNDEF)) {
158 connect_vec[0].type = aux2;
159 connect_vec[1].type = aux1;
161 connect_vec[0].id_dest = _item0->get_id();
162 connect_vec[1].id_dest = _item1->get_id();
163 return ( is_connected = (connect_vec[0].type != connect_vec[1].type) );
165 return is_connected = false;
168 ConnectorType Splitter::get_connector_type(int _a, int _b)
173 if ( (_a <= x+10)&&(_a > x) && (_b <=y+22)&&(_b>=y+10) ) {// arriba - izquierda h
174 if ( is_connected ) return connect_vec[0].type;
175 connect_vec[1].type = is_other_connection_area (get_position_x()+get_image()->get_width()-16, +get_position_y()+get_image()->get_height() + 5, &_item);
176 switch ( connect_vec[1].type ) {
178 connect_vec[0].type = IN;
179 connect_vec[1].type = OUT;
182 connect_vec[0].type = OUT;
183 connect_vec[1].type = IN;
189 return connect_vec[0].type;
191 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
192 if ( is_connected ) return connect_vec[1].type;
193 connect_vec[0].type = is_other_connection_area( get_position_x()-5, get_position_y()+16,& _item);
194 switch ( connect_vec[0].type ) {
196 connect_vec[0].type = OUT;
197 connect_vec[1].type = IN;
200 connect_vec[0].type = IN;
201 connect_vec[1].type = OUT;
207 return connect_vec[1].type;
211 if ( (_a <= x+image->get_width()-10)&&(_a >= x+image->get_width()-22) && (_b <=y+10)&&(_b > y) ) {//arriba-derecha v
212 if (is_connected) return connect_vec[0].type;
213 connect_vec[1].type = is_other_connection_area( get_position_x()-5, get_position_y()+get_image()->get_height()-16, &_item);
214 switch ( connect_vec[1].type ) {
216 connect_vec[0].type = IN;
217 connect_vec[1].type = OUT;
220 connect_vec[0].type = OUT;
221 connect_vec[1].type = IN;
227 return connect_vec[0].type;
230 if ( (_a <= x+10)&&(_a > x)&&(_b<=y+image->get_height()-10)&&(_b>=y+image->get_height()-22) ) {// abajo-izquierda h
231 if ( is_connected ) return connect_vec[1].type;
232 connect_vec[0].type = is_other_connection_area( get_position_x()+get_image()->get_width() - 16, get_position_y() -5, &_item);
233 switch ( connect_vec[0].type ) {
235 connect_vec[0].type = OUT;
236 connect_vec[1].type = IN;
239 connect_vec[0].type = IN;
240 connect_vec[1].type = OUT;
246 return connect_vec[1].type;
250 if ( (_a <= x+22)&&(_a >= x+10) && (_b <=y+10)&&(_b > y) ) {//arriba-izquierda v
251 if ( is_connected ) return connect_vec[1].type;
252 connect_vec[0].type = is_other_connection_area( get_position_x()+get_image()->get_width()+5, get_position_y()+get_image()->get_height() - 16, &_item);
253 switch ( connect_vec[0].type ) {
255 connect_vec[0].type = OUT;
256 connect_vec[1].type = IN;
259 connect_vec[0].type = IN;
260 connect_vec[1].type = OUT;
266 return connect_vec[1].type;
269 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
270 if (is_connected ) return connect_vec[0].type;
271 connect_vec[1].type = is_other_connection_area( get_position_x() + 16, get_position_y() - 5,& _item);
272 switch ( connect_vec[1].type ) {
274 connect_vec[0].type = IN;
275 connect_vec[1].type = OUT;
278 connect_vec[0].type = OUT;
279 connect_vec[1].type = IN;
285 return connect_vec[0].type;
289 if ( (_a <= x+image->get_width()-1)&&(_a >= x+image->get_width()-10) && (_b <=y+22)&&(_b>=y+10) ) {//arriba-derecha h
290 if ( is_connected ) return connect_vec[1].type;
291 connect_vec[0].type = is_other_connection_area( get_position_x() + 16, get_position_y()+get_image()->get_height() + 5, &_item);
292 switch ( connect_vec[0].type ) {
294 connect_vec[0].type = OUT;
295 connect_vec[1].type = IN;
298 connect_vec[0].type = IN;
299 connect_vec[1].type = OUT;
305 return connect_vec[1].type;
308 if ( (_a <= x+22)&&(_a>=x+10)&&(_b<=y+image->get_height()-1)&&(_b>=y+image->get_height()-10) ) {// abajo-izquierda v
309 if ( is_connected ) return connect_vec[0].type;
310 connect_vec[1].type = is_other_connection_area( get_position_x()+get_image()->get_width()+5, get_position_y() +16,& _item);
311 switch ( connect_vec[1].type ) {
313 connect_vec[0].type = IN;
314 connect_vec[1].type = OUT;
317 connect_vec[0].type = OUT;
318 connect_vec[1].type = IN;
324 return connect_vec[0].type;
330 void Splitter::set_default_connector()
332 connect_vec[0].type = UNDEF;
333 connect_vec[1].type = UNDEF;