]> git.llucax.com Git - z.facultad/75.42/plaqui.git/blob - Constructor/src/splitter.cpp
Se mejora y completa el manual de usuario del Construtor.
[z.facultad/75.42/plaqui.git] / Constructor / src / splitter.cpp
1 #include "splitter.h"
2
3 Splitter::Splitter(int orientacion)
4 {
5         in_x = -1;
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;
12         switch (imgActual) {
13                 case 1:
14                         image = imageN;
15                         break;
16                 case 2:
17                         image = imageE;
18                         break;
19                 case 3:
20                         image = imageS;
21                         break;
22                 default: 
23                         imgActual = 0;
24                         image = imageO;                 
25         }
26         set_size_request(image->get_width(), image->get_height());
27         property_wnd->set_title("Propiedades del Codo");        
28         name = "codo";
29         Connector temp;
30         temp.id_dest = -1;
31         temp.type = UNDEF;
32         connect_vec.push_back(temp);
33         connect_vec.push_back(temp);
34 }
35
36 Splitter::~Splitter()
37 {
38 }
39
40 bool Splitter::on_button_press_event(GdkEventButton *event)
41 {
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;
48                 char f[10];
49                 Glib::ustring text;
50                 sprintf(f,"%.1f",caudal_max);
51                 text = name+"  Caudal Maximo: ";
52                 text += f;
53                 status_bar->push ( text, 0);
54         }
55         
56         if ((event->type == GDK_BUTTON_PRESS) && ( event->button == 2)){
57                 image = null;   
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);
59                 imgActual++;
60                 switch (imgActual) {
61                         case 1:
62                                 image = imageN;
63                                 break;
64                         case 2:
65                                 image = imageE;
66                                 break;
67                         case 3:
68                                 image = imageS;
69                                 break;
70                         default: 
71                                 imgActual = 0;
72                                 image = imageO;                 
73                 }
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);
76         }
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.
80         }
81         
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 );
85                 property_wnd->show();
86         }
87         return true;
88 }
89 void Splitter::on_menu_popup_rotar()
90 {
91         GdkEventButton event; 
92         event.type = GDK_BUTTON_PRESS;
93         event.button = 2;
94         Splitter::on_button_press_event(&event);
95 }
96
97 void Splitter::on_menu_popup_propiedades()
98 {
99         GdkEventButton event;
100         event.type = GDK_2BUTTON_PRESS;
101         event.button = 1;
102         Splitter::on_button_press_event(&event);
103 }
104
105 void Splitter::save(FILE *archivo)
106 {
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";
111         else
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";
115         else
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);
122         Glib::ustring dato;
123         dato = "\t<codo nombre=\""+name+"\" id=\"";
124         dato += c_id;
125         dato += "\">\n";
126         dato += c_caudal;
127         dato += "\t\t<conector>\n"+con0 + con1+"\t\t</conector>\n";
128         dato += c_img;
129         dato += c_x; 
130         dato += c_y;
131         dato += "\t</codo>\n";
132         fprintf(archivo,dato.c_str());  
133 }
134
135 bool Splitter::check_connection()
136 {
137         ConnectorType aux, aux1, aux2;
138         CItem *_item0, *_item1;
139         switch (get_img_actual()) {
140                         case 0:
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
143                                 break;  
144                         case 1:
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
147                                 break;
148                         case 2:
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
151                                 break;
152                         case 3:
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
155         }
156         if ((aux2 != UNDEF) && (aux1 != UNDEF)) {
157                 if (!is_connected) {
158                         connect_vec[0].type = aux2;
159                         connect_vec[1].type = aux1;
160                 }
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) );
164         }
165         return is_connected = false;
166 }
167
168 ConnectorType Splitter::get_connector_type(int _a, int _b)
169 {
170         CItem *_item;
171         switch (imgActual) {
172                 case 0: 
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 ) {
177                                         case IN: 
178                                                 connect_vec[0].type = IN;
179                                                 connect_vec[1].type = OUT;
180                                         break;
181                                         case OUT:
182                                                 connect_vec[0].type = OUT;
183                                                 connect_vec[1].type = IN;
184                                         break;
185                                         case UNDEF:
186                                                 return UNDEF;
187                                 }
188                                 is_connected = true;
189                                 return connect_vec[0].type;
190                         }
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 ) {
195                                         case IN: 
196                                                 connect_vec[0].type = OUT;
197                                                 connect_vec[1].type = IN;
198                                                 break;
199                                         case OUT:
200                                                 connect_vec[0].type = IN;
201                                                 connect_vec[1].type = OUT;
202                                                 break;
203                                         case UNDEF:
204                                                 return UNDEF;
205                                 }
206                                 is_connected = true;
207                                 return connect_vec[1].type;
208                         }
209                 break;
210                 case 1:
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 ) {
215                                         case IN: 
216                                                 connect_vec[0].type = IN;
217                                                 connect_vec[1].type = OUT;
218                                         break;
219                                         case OUT:
220                                                 connect_vec[0].type = OUT;
221                                                 connect_vec[1].type = IN;
222                                         break;
223                                         case UNDEF:
224                                                 return UNDEF;
225                                 }
226                                 is_connected = true;
227                                 return connect_vec[0].type;
228                         }
229                                         
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 ) {
234                                         case IN: 
235                                                 connect_vec[0].type = OUT;
236                                                 connect_vec[1].type = IN;
237                                                 break;
238                                         case OUT:
239                                                 connect_vec[0].type = IN;
240                                                 connect_vec[1].type = OUT;
241                                                 break;
242                                         case UNDEF:
243                                                 return UNDEF;
244                                 }
245                                 is_connected = true;
246                                 return connect_vec[1].type;
247                         }
248                 break;
249                 case 2:
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 ) {
254                                         case IN: 
255                                                 connect_vec[0].type = OUT;
256                                                 connect_vec[1].type = IN;
257                                                 break;
258                                         case OUT:
259                                                 connect_vec[0].type = IN;
260                                                 connect_vec[1].type = OUT;
261                                                 break;
262                                         case UNDEF:
263                                                 return UNDEF;
264                                 }
265                                 is_connected = true;
266                                 return connect_vec[1].type;
267                         }
268
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 ) {
273                                         case IN: 
274                                                 connect_vec[0].type = IN;
275                                                 connect_vec[1].type = OUT;
276                                         break;
277                                         case OUT:
278                                                 connect_vec[0].type = OUT;
279                                                 connect_vec[1].type = IN;
280                                         break;
281                                         case UNDEF:
282                                                 return UNDEF;
283                                 }
284                                 is_connected = true;
285                                 return connect_vec[0].type;
286                         }
287                         break;
288                 case 3:
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 ) {
293                                         case IN: 
294                                                 connect_vec[0].type = OUT;
295                                                 connect_vec[1].type = IN;
296                                                 break;
297                                         case OUT:
298                                                 connect_vec[0].type = IN;
299                                                 connect_vec[1].type = OUT;
300                                                 break;
301                                         case UNDEF:
302                                                 return UNDEF;
303                                 }
304                                 is_connected = true;
305                                 return connect_vec[1].type;
306                         }
307                                 
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 ) {
312                                         case IN: 
313                                                 connect_vec[0].type = IN;
314                                                 connect_vec[1].type = OUT;
315                                         break;
316                                         case OUT:
317                                                 connect_vec[0].type = OUT;
318                                                 connect_vec[1].type = IN;
319                                         break;
320                                         case UNDEF:
321                                                 return UNDEF;
322                                 }
323                                 is_connected = true;
324                                 return connect_vec[0].type;
325                         }
326         }
327         return UNDEF;
328 }       
329
330 void Splitter::set_default_connector()
331 {
332         connect_vec[0].type = UNDEF;
333         connect_vec[1].type = UNDEF;
334 }