]> git.llucax.com Git - z.facultad/75.42/plaqui.git/blob - Constructor/src/splitter.cpp
Se ponen flags del compilador para libxml2 con pkg-config.
[z.facultad/75.42/plaqui.git] / Constructor / src / splitter.cpp
1 #include "splitter.h"
2
3 Splitter::Splitter(int orientacion)
4 {
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;
11         switch (imgActual) {
12                 case 1:
13                         image = imageN;
14                         break;
15                 case 2:
16                         image = imageE;
17                         break;
18                 case 3:
19                         image = imageS;
20                         break;
21                 default: 
22                         imgActual = 0;
23                         image = imageO;                 
24         }
25         set_size_request(image->get_width(), image->get_height());
26         property_wnd->set_title("Propiedades del Codo");        
27         name = "codo";
28         Connector temp;
29         temp.id_dest = -1;
30         temp.type = UNDEF;
31         connect_vec.push_back(temp);
32         connect_vec.push_back(temp);
33 }
34
35 Splitter::~Splitter()
36 {
37 }
38
39 bool Splitter::on_button_press_event(GdkEventButton *event)
40 {
41         if ((event->type == GDK_BUTTON_PRESS) && ( event->button == 1))
42                 combo_entry->set_text(name);
43         
44         if ((event->type == GDK_BUTTON_PRESS) && ( event->button == 2)){
45                 image = null;   
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);
47                 imgActual++;
48                 switch (imgActual) {
49                         case 1:
50                                 image = imageN;
51                                 break;
52                         case 2:
53                                 image = imageE;
54                                 break;
55                         case 3:
56                                 image = imageS;
57                                 break;
58                         default: 
59                                 imgActual = 0;
60                                 image = imageO;                 
61                 }
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);
64         }
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.
68         }
69         
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 );
73                 property_wnd->show();
74         }
75         return true;
76 }
77 void Splitter::on_menu_popup_rotar()
78 {
79         GdkEventButton event; 
80         event.type = GDK_BUTTON_PRESS;
81         event.button = 2;
82         Splitter::on_button_press_event(&event);
83 }
84
85 void Splitter::on_menu_popup_propiedades()
86 {
87         GdkEventButton event;
88         event.type = GDK_2BUTTON_PRESS;
89         event.button = 1;
90         Splitter::on_button_press_event(&event);
91 }
92
93 void Splitter::save(FILE *archivo)
94 {
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";
99         else
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";
103         else
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);
110         Glib::ustring dato;
111         dato = "\t<codo nombre=\""+name+"\" id=\"";
112         dato += c_id;
113         dato += "\">\n";
114         dato += c_caudal;
115         dato += "\t\t<conector>\n"+con0 + con1+"\t\t</conector>\n";
116         dato += c_img;
117         dato += c_x; 
118         dato += c_y;
119         dato += "\t</codo>\n";
120         fprintf(archivo,dato.c_str());  
121 }
122
123 bool Splitter::check_connection()
124 {
125         ConnectorType aux;
126         CItem *_item0, *_item1;
127         switch (get_img_actual()) {
128                         case 0:
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
131                                 break;  
132                         case 1:
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
135                                 break;
136                         case 2:
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
139                                 break;
140                         case 3:
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
143         }
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) );
151         }
152         else return is_connected;
153 }
154
155 ConnectorType Splitter::get_connector_type(int _a, int _b)
156 {
157         CItem *_item;
158         if ( ! is_connected ) {
159                 switch (imgActual) {
160                         case 0: 
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);
165                                 break;
166                         case 1:
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);
171                                  break;
172                         case 2:
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);
177                                 break;
178                         case 3:
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);
183                 }
184         } else {
185                 switch (imgActual) {
186                         case 0: 
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;
191                                 break;
192                         case 1:
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;
197                                  break;
198                         case 2:
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;
203                                 break;
204                         case 3:
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;
209                 }
210         }
211         return UNDEF;
212 }       
213
214 void Splitter::set_default_connector()
215 {
216         connect_vec[0].type = UNDEF;
217         connect_vec[1].type = UNDEF;
218 }