]> git.llucax.com Git - z.facultad/75.42/plaqui.git/blob - Constructor/src/union.cpp
corregi las imagenes del manual del usuario y agregue una mas
[z.facultad/75.42/plaqui.git] / Constructor / src / union.cpp
1 #include "union.h"
2
3 Union::Union(int orientacion)
4 {
5         in_x = -1;
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;
12         switch (imgActual) {
13                 case 1:
14                         image = imageE;
15                         break;
16                 case 2:
17                         image = imageS;
18                         break;
19                 case 3:
20                         image = imageO;
21                         break;
22                 default: 
23                         imgActual = 0;
24                         image = imageN;                 
25         }
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;
31         name = "union";
32         Connector temp;
33         temp.id_dest = -1;
34         temp.type = IN;
35         connect_vec.push_back(temp); //izquierda
36         connect_vec.push_back(temp); //derecha
37         temp.type = OUT;
38         connect_vec.push_back(temp); //medio
39 }
40
41 Union::~Union()
42 {
43 }
44
45 bool Union::on_button_press_event(GdkEventButton *event)
46 {
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;
53                 char f[10];
54                 Glib::ustring text;
55                 sprintf(f,"%.1f",caudal_max);
56                 text = name+"  Caudal Maximo: ";
57                 text += f;
58                 status_bar->push ( text, 0);
59         }
60         
61         if ((event->type == GDK_BUTTON_PRESS) && (event->button == 2 )){
62                 image = null;   
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);
64                 imgActual++;
65                 switch (imgActual) {
66                         case 1:
67                                 image = imageE;
68                                 break;
69                         case 2:
70                                 image = imageS;
71                                 break;
72                         case 3:
73                                 image = imageO;
74                                 break;
75                         default: 
76                                 imgActual = 0;
77                                 image = imageN;                 
78                 }
79                 set_size_request(image->get_width(), image->get_height());              
80                 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);
81         }
82         if ((event->type == GDK_BUTTON_PRESS) && ( event->button == 3)){
83                 menu_popup.popup(event->button, event->time);
84                  return true; //It has been handled.
85         }
86         
87         if ((event->type == GDK_2BUTTON_PRESS) && ( event->button == 1)){
88                 property_wnd->spin_caudal->set_value( caudal_max );
89                 property_wnd->txt_item_name->set_text( name );
90                 if (is_union) property_wnd->rd_btn_union->set_active(true);
91                 property_wnd->show();
92         }
93         return true;
94 }
95
96 void Union::on_menu_popup_rotar()
97 {
98         GdkEventButton event; 
99         event.type = GDK_BUTTON_PRESS;
100         event.button = 2;
101         Union::on_button_press_event(&event);
102 }
103
104 void Union::on_menu_popup_propiedades()
105 {
106         GdkEventButton event; 
107         event.type = GDK_2BUTTON_PRESS;
108         event.button = 1;
109         Union::on_button_press_event(&event);
110 }
111
112 void Union::save(FILE *archivo)
113 {
114         char c_id[50], c_caudal[50], c_x[50], c_y[50], c_img[50];
115         Glib::ustring  con0, con1, con2, c_type;
116         if (is_union){
117                 con0 = "\t\t\t<entrada>"+get_other_name(connect_vec[0].id_dest)+"</entrada>\n";
118                 con1 = "\t\t\t<entrada>"+get_other_name(connect_vec[1].id_dest)+"</entrada>\n";
119                 con2 = "\t\t\t<salida>"+get_other_name(connect_vec[2].id_dest)+"</salida>\n";
120                 c_type = "\t\t<tipo>union</tipo>\n";
121         } else {
122                 con0 = "\t\t\t<salida>"+get_other_name(connect_vec[0].id_dest)+"</salida>\n";
123                 con1 = "\t\t\t<salida>"+get_other_name(connect_vec[1].id_dest)+"</salida>\n";
124                 con2 = "\t\t\t<entrada>"+get_other_name(connect_vec[2].id_dest)+"</entrada>\n";         
125                 c_type = "\t\t<tipo>division</tipo>\n";
126         }
127         sprintf(c_x,"\t\t<x>%d</x>\n",x);
128         sprintf(c_y,"\t\t<y>%d</y>\n",y);
129         sprintf(c_id,"%d",ID);
130         sprintf(c_caudal,"\t\t<caudal>%.2f</caudal>\n", caudal_max);
131         sprintf(c_img,"\t\t<orientacion>%d</orientacion>\n",imgActual);
132         Glib::ustring dato;
133         dato = "\t<empalme nombre=\""+name+"\" id=\"";
134         dato += c_id;
135         dato += "\">\n";
136         dato += c_type;
137         dato += "\t\t<conector>\n"+con0+con1+con2+"\t\t</conector>\n";
138         dato += c_caudal;
139         dato += c_img;
140         dato += c_x; 
141         dato += c_y;
142         dato += "\t</empalme>\n";
143         fprintf(archivo,dato.c_str());  
144 }
145
146 bool Union::check_connection()
147 {
148         CItem * _item0, *_item1, *_item2;
149         ConnectorType temp0, temp1, temp2;
150         std::cout << get_img_actual() << std::endl;
151         switch (get_img_actual()) {
152                         case 0:
153                                 temp0 = is_other_connection_area( get_position_x() - 5, get_position_y() +16, &_item0);
154                                 temp1 = is_other_connection_area( get_position_x()+get_image()->get_width()+5, get_position_y()+16, &_item1);
155                                 temp2 = is_other_connection_area( get_position_x()+get_image()->get_width()/2, get_position_y()+get_image()->get_height()+5, &_item2);
156                                 break;
157                         case 1:
158                                 temp2 = is_other_connection_area( get_position_x()-5, get_position_y()+get_image()->get_height()/2, &_item2);
159                                 temp0 = is_other_connection_area( get_position_x()+get_image()->get_width()-16, get_position_y()-5, &_item0);
160                                 temp1 = is_other_connection_area( get_position_x()+get_image()->get_width()-16, get_position_y()+get_image()->get_height()+5,& _item1);
161                                 break;
162                         case 2:
163                                 temp1 = is_other_connection_area( get_position_x()-5, get_position_y()+get_image()->get_height()-16,& _item1);
164                                 temp2 = is_other_connection_area( get_position_x()+get_image()->get_width()/2, get_position_y()-5, &_item2);
165                                 temp0 = is_other_connection_area( get_position_x()+get_image()->get_width()+5, get_position_y()+get_image()->get_height()-16, &_item0);
166                                 break;
167                         case 3:
168                                 temp1 = is_other_connection_area( get_position_x()+16, get_position_y()-5, &_item1);
169                                 temp2 = is_other_connection_area( get_position_x()+get_image()->get_width()+5, get_position_y()+get_image()->get_height()/2,& _item2);
170                                 temp0 = is_other_connection_area( get_position_x()+16, get_position_y()+get_image()->get_height()+5, &_item0);
171         }
172         if ( is_union ) {
173                 if ( temp0 == OUT && temp1 == OUT && temp2 == IN ) {
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);
178                 }
179         } else {
180                 if ( temp0 == IN && temp1 == IN && temp2 == OUT ) {
181                         connect_vec[0].id_dest = _item0->get_id();
182                         connect_vec[1].id_dest = _item1->get_id();
183                         connect_vec[2].id_dest = _item2->get_id();
184                         return (is_connected = true);
185                 }
186         }
187         return is_connected;
188 }
189
190 ConnectorType Union::get_connector_type(int _a, int _b)
191 {
192         switch ( imgActual) {
193                 case 0: if ((_a <= x+10) && (_a > x+1) && (_b<= y + 22) && (_b >= y+10))
194                                                 return connect_vec[0].type;
195                                         if ((_a <= x+image->get_width()-1) && (_a >= x+image->get_width()-10)&&(_b <= y+22) && (_b >= y+10))
196                                                 return connect_vec[1].type;
197                                         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)) 
198                                                 return connect_vec[2].type;
199                                         break;
200                 case 1: if ((_a <= x+image->get_width()-10) && (_a >= x+image->get_width() -22) && (_b<= y + 10) && (_b > y ))
201                                                 return connect_vec[0].type;
202                                         if ((_a <= x +10) && (_a > x )&&(_b <= y+image->get_height()/2+5 ) && (_b >= y+image->get_height()/2-5))
203                                                 return connect_vec[2].type;
204                                         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))
205                                                 return connect_vec[1].type;
206                                         break;
207                 case 2: if ((_a <= x+10) && (_a > x) && (_b<= y+image->get_height()-10) && (_b >= y+image->get_height()-22))
208                                                 return connect_vec[1].type;
209                                         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))
210                                                 return connect_vec[0].type;
211                                         if ((_a <= x+image->get_width()/2 + 5)&&( _a>= x+image->get_width()/2 - 5) && (_b<=y+10)&&(_b > y))
212                                                 return connect_vec[2].type;
213                                         break;
214                 case 3: if ((_a <= x+22) && (_a >= x+10) && (_b<= y + 10) && (_b > y ))
215                                                 return connect_vec[1].type;
216                                         if ((_a <= x+22) && (_a >= x+10 )&&(_b <= y+image->get_height()-1 ) && (_b >= y+image->get_height()-10))
217                                                 return connect_vec[0].type;
218                                         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))
219                                                 return connect_vec[2].type;
220         }
221         return UNDEF;
222 }
223
224 void Union::set_default_connector()
225 {
226         if (is_union) {
227                 connect_vec[0].type = IN;
228                 connect_vec[1].type = IN;
229                 connect_vec[2].type = OUT;
230         } else {
231                 connect_vec[0].type = OUT;
232                 connect_vec[1].type = OUT;
233                 connect_vec[2].type = IN;
234         }
235 }