]> git.llucax.com Git - z.facultad/75.42/plaqui.git/blob - Constructor/src/splitter.cpp
Se agrega una pequeña mejora al dibujo de las lineas. Tengo pensado mejorarlas
[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                 combo_entry->set_text(name);
44                 WorkPlace::pointed = ID;
45         }
46         
47         if ((event->type == GDK_BUTTON_PRESS) && ( event->button == 2)){
48                 image = null;   
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);
50                 imgActual++;
51                 switch (imgActual) {
52                         case 1:
53                                 image = imageN;
54                                 break;
55                         case 2:
56                                 image = imageE;
57                                 break;
58                         case 3:
59                                 image = imageS;
60                                 break;
61                         default: 
62                                 imgActual = 0;
63                                 image = imageO;                 
64                 }
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);
67         }
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.
71         }
72         
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 );
76                 property_wnd->show();
77         }
78         return true;
79 }
80 void Splitter::on_menu_popup_rotar()
81 {
82         GdkEventButton event; 
83         event.type = GDK_BUTTON_PRESS;
84         event.button = 2;
85         Splitter::on_button_press_event(&event);
86 }
87
88 void Splitter::on_menu_popup_propiedades()
89 {
90         GdkEventButton event;
91         event.type = GDK_2BUTTON_PRESS;
92         event.button = 1;
93         Splitter::on_button_press_event(&event);
94 }
95
96 void Splitter::save(FILE *archivo)
97 {
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";
102         else
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";
106         else
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);
113         Glib::ustring dato;
114         dato = "\t<codo nombre=\""+name+"\" id=\"";
115         dato += c_id;
116         dato += "\">\n";
117         dato += c_caudal;
118         dato += "\t\t<conector>\n"+con0 + con1+"\t\t</conector>\n";
119         dato += c_img;
120         dato += c_x; 
121         dato += c_y;
122         dato += "\t</codo>\n";
123         fprintf(archivo,dato.c_str());  
124 }
125
126 bool Splitter::check_connection()
127 {
128         ConnectorType aux;
129         CItem *_item0, *_item1;
130         switch (get_img_actual()) {
131                         case 0:
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
134                                 break;  
135                         case 1:
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
138                                 break;
139                         case 2:
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
142                                 break;
143                         case 3:
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
146         }
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) );
154         }
155         else return is_connected;
156 }
157
158 ConnectorType Splitter::get_connector_type(int _a, int _b)
159 {
160         CItem *_item;
161         if ( ! is_connected ) {
162                 switch (imgActual) {
163                         case 0: 
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);
168                                 break;
169                         case 1:
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);
174                                  break;
175                         case 2:
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);
180                                 break;
181                         case 3:
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);
186                 }
187         } else {
188                 switch (imgActual) {
189                         case 0: 
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;
194                                 break;
195                         case 1:
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;
200                                  break;
201                         case 2:
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;
206                                 break;
207                         case 3:
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;
212                 }
213         }
214         return UNDEF;
215 }       
216
217 void Splitter::set_default_connector()
218 {
219         connect_vec[0].type = UNDEF;
220         connect_vec[1].type = UNDEF;
221 }