]> git.llucax.com Git - z.facultad/75.42/plaqui.git/blob - Constructor/src/constructor.cpp
Se actualiza documentacion:
[z.facultad/75.42/plaqui.git] / Constructor / src / constructor.cpp
1 #include "constructor.h"
2
3 Constructor::Constructor(BaseObjectType* cobject, const Glib::RefPtr<Gnome::Glade::Xml>& refGlade):Gtk::Window(cobject)
4 {
5         id = 0;
6         saved = false;
7         set_title("Constructor");
8         Gtk::Label *lbl_plaqui_version;
9         Gtk::Image *plaqui_logo;
10         Gtk::MenuItem *mnu_about;
11         Gtk::Button *close_about;
12         
13         plaqui_logo = 0;
14         lbl_plaqui_version = 0;
15         refGlade->get_widget("lbl_plaqui_version", lbl_plaqui_version);
16         refGlade->get_widget("plaqui_logo", plaqui_logo);
17         plaqui_logo->set(PACKAGE_DATA_DIR"/plaqui-constructor/pixmaps/logo.png");
18
19         refGlade->get_widget("plaqui_logo", plaqui_logo);
20         // Calculo número de revisión.
21         std::string rev = "$Rev$";
22         rev = rev.substr(6, rev.length() - 8);
23         std::string s = "PlaQui Constructor versión " VERSION " (revisión ";
24         s += rev + ")"; 
25         lbl_plaqui_version->set_text(Glib::locale_to_utf8(s));
26         
27         refGlade->get_widget("dlgAbout", dlg_about);
28         refGlade->get_widget("close_about", close_about);
29         refGlade->get_widget("mnu_about", mnu_about);
30         
31         // Cargo todas las imagenes de los iconos de los botones
32         ico_canio = Gdk::Pixbuf::create_from_file(PACKAGE_DATA_DIR"/plaqui-constructor/pixmaps/canio_n.png");
33         ico_y     = Gdk::Pixbuf::create_from_file(PACKAGE_DATA_DIR"/plaqui-constructor/pixmaps/y_n.png");
34         ico_codo  = Gdk::Pixbuf::create_from_file(PACKAGE_DATA_DIR"/plaqui-constructor/pixmaps/codo_o.png");
35         ico_tanque  = Gdk::Pixbuf::create_from_file(PACKAGE_DATA_DIR"/plaqui-constructor/pixmaps/tanque_e.png");
36         ico_exclusa = Gdk::Pixbuf::create_from_file(PACKAGE_DATA_DIR"/plaqui-constructor/pixmaps/exclusa_h.png");
37         ico_drain = Gdk::Pixbuf::create_from_file(PACKAGE_DATA_DIR"/plaqui-constructor/pixmaps/drain_n.png");
38         ico_bomba = Gdk::Pixbuf::create_from_file(PACKAGE_DATA_DIR"/plaqui-constructor/pixmaps/bomba_e.png");
39         ico_and = Gdk::Pixbuf::create_from_file(PACKAGE_DATA_DIR"/plaqui-constructor/pixmaps/and_e.png");
40         ico_or = Gdk::Pixbuf::create_from_file(PACKAGE_DATA_DIR"/plaqui-constructor/pixmaps/or_e.png");
41         ico_not = Gdk::Pixbuf::create_from_file(PACKAGE_DATA_DIR"/plaqui-constructor/pixmaps/not_e.png");
42         
43         //Obtengo todos los widgets de la ventana principal.
44         refGlade->get_widget("btn_canio", btn_canio);
45         refGlade->get_widget("btn_codo", btn_codo);
46         refGlade->get_widget("btn_y", btn_y);
47         refGlade->get_widget("btn_tanque",btn_tanque);
48         refGlade->get_widget("btn_bomba", btn_bomba);
49         refGlade->get_widget("btn_exclusa", btn_exclusa);
50         refGlade->get_widget("btn_drain", btn_drain);
51         refGlade->get_widget("btn_and", btn_and);
52         refGlade->get_widget("btn_or", btn_or);
53         refGlade->get_widget("btn_not", btn_not);
54         refGlade->get_widget("main_menu_quit",main_menu_quit);
55         refGlade->get_widget("main_menu_new",main_menu_new);
56         refGlade->get_widget("main_menu_open",main_menu_open);
57         refGlade->get_widget("main_menu_save",main_menu_save);
58         refGlade->get_widget("edit_menu_del",edit_menu_del);
59         refGlade->get_widget("chk_btn_logica",chk_btn_logica);
60         refGlade->get_widget("file_open_selection",file_open_selection);
61         refGlade->get_widget("file_selection",file_selection);
62         refGlade->get_widget("combo_entry",combo_entry);
63         refGlade->get_widget("btn_check",btn_check);
64         refGlade->get_widget("dlg_connect", dlg_connect);
65         refGlade->get_widget("btn_dlg_close", btn_dlg_close);
66         refGlade->get_widget("dlg_label", dlg_label);
67         refGlade->get_widget("quick_btn_new", quick_btn_new);
68         refGlade->get_widget("quick_btn_save", quick_btn_save);
69         refGlade->get_widget("quick_btn_open", quick_btn_open);
70         refGlade->get_widget("edit_menu_delete_all", edit_menu_delete_all);
71         refGlade->get_widget("btn_find", btn_find);
72         refGlade->get_widget("status_bar", status_bar);
73         
74         //Obtengo el area de trabajo, la cual tiene definida su propia clase.
75         refGlade->get_widget_derived("workplace", workplace);  //fixed
76         
77         //Targets
78         listTargets.push_back( Gtk::TargetEntry("STRING") );
79         listTargets.push_back( Gtk::TargetEntry("text/plain") );
80         listTargets.push_back( Gtk::TargetEntry("POINTER") );
81         listTargets.push_back( Gtk::TargetEntry("application/pointer") );
82         
83         // Le indico cuales son los botones  desde los cuales se puede hacer un drag.
84         mnu_about->signal_activate().connect( SigC::slot(*dlg_about, &Gtk::Widget::show) );
85         close_about->signal_clicked().connect( SigC::slot(*dlg_about, &Gtk::Widget::hide) );
86         btn_canio->drag_source_set(listTargets);
87         btn_y->drag_source_set(listTargets);
88         btn_codo->drag_source_set(listTargets);
89         btn_tanque->drag_source_set(listTargets);
90         btn_bomba->drag_source_set(listTargets);
91         btn_drain->drag_source_set(listTargets);
92         btn_exclusa->drag_source_set(listTargets);
93         btn_and->drag_source_set(listTargets);
94         btn_or->drag_source_set(listTargets);
95         btn_not->drag_source_set(listTargets);
96         
97         //Conecto las señales de cada boton con su correspondiente metodo.
98         btn_canio->signal_drag_data_get().connect( SigC::slot(*this, &Constructor::on_btn_canio_drag_get));
99         btn_bomba->signal_drag_data_get().connect( SigC::slot(*this, &Constructor::on_btn_bomba_drag_get));
100         btn_exclusa->signal_drag_data_get().connect( SigC::slot(*this, &Constructor::on_btn_exclusa_drag_get));
101         btn_y->signal_drag_data_get().connect( SigC::slot(*this, &Constructor::on_btn_y_drag_get));
102         btn_codo->signal_drag_data_get().connect( SigC::slot(*this, &Constructor::on_btn_codo_drag_get));
103         btn_tanque->signal_drag_data_get().connect( SigC::slot(*this, &Constructor::on_btn_tanque_drag_get));
104         btn_drain->signal_drag_data_get().connect( SigC::slot(*this, &Constructor::on_btn_drain_drag_get));
105         btn_and->signal_drag_data_get().connect( SigC::slot(*this, &Constructor::on_btn_and_drag_get));
106         btn_or->signal_drag_data_get().connect( SigC::slot(*this, &Constructor::on_btn_or_drag_get));
107         btn_not->signal_drag_data_get().connect( SigC::slot(*this, &Constructor::on_btn_not_drag_get));
108         btn_check->signal_clicked().connect(SigC::slot(*this,&Constructor::on_btn_check_clicked));
109         btn_dlg_close->signal_clicked().connect(SigC::slot(*this,&Constructor::on_btn_dlg_connect_clicked));
110         btn_find->signal_clicked().connect(SigC::slot(*this,&Constructor::on_btn_find_clicked));        
111         chk_btn_logica->signal_clicked().connect(SigC::slot(*this, &Constructor::on_chk_btn_logica_clicked));
112         quick_btn_new->signal_clicked().connect(SigC::slot(*this, &Constructor::on_quick_btn_new_clicked));
113         quick_btn_save->signal_clicked().connect(SigC::slot(*this, &Constructor::on_quick_btn_save_clicked));
114         quick_btn_open->signal_clicked().connect(SigC::slot(*this, &Constructor::on_main_menu_open));
115         
116         main_menu_quit->signal_activate().connect(SigC::slot(*this, &Constructor::on_main_menu_quit));
117         main_menu_new->signal_activate().connect(SigC::slot(*this, &Constructor::on_quick_btn_new_clicked));
118         main_menu_open->signal_activate().connect(SigC::slot(*this, &Constructor::on_main_menu_open));
119         main_menu_save->signal_activate().connect(SigC::slot(*this, &Constructor::on_main_menu_save));
120         edit_menu_del->signal_activate().connect(SigC::slot(*this,&Constructor::on_edit_menu_del));
121         edit_menu_delete_all->signal_activate().connect(SigC::slot(*this,&Constructor::on_quick_btn_delete_all_clicked));
122         
123         //Obtengo y conecto los botones del dialogo de Salvar/Cargar un archivo.
124         btn_file_cancel = file_selection->get_cancel_button();
125         btn_file_ok = file_selection->get_ok_button();
126         btn_file_ok->signal_clicked().connect(SigC::slot(*this,&Constructor::on_btn_file_ok_clicked));
127         btn_file_cancel->signal_clicked().connect(SigC::slot(*this,&Constructor::on_btn_file_cancel_clicked));
128         btn_open_cancel = file_open_selection->get_cancel_button();
129         btn_open_ok = file_open_selection->get_ok_button();
130         btn_open_ok->signal_clicked().connect(SigC::slot(*this,&Constructor::on_load_from_xml));
131         btn_open_cancel->signal_clicked().connect(SigC::slot(*this,&Constructor::on_btn_open_cancel_clicked));
132
133         // Señales para cambiar el icono cuando empieza el drag.
134         btn_canio->signal_drag_begin().connect( SigC::slot(*this, &Constructor::on_canio_drag_begin));
135         btn_y->signal_drag_begin().connect( SigC::slot(*this, &Constructor::on_y_drag_begin));
136         btn_codo->signal_drag_begin().connect( SigC::slot(*this, &Constructor::on_codo_drag_begin));
137         btn_tanque->signal_drag_begin().connect( SigC::slot(*this, &Constructor::on_tanque_drag_begin));
138         btn_bomba->signal_drag_begin().connect( SigC::slot(*this, &Constructor::on_bomba_drag_begin));
139         btn_exclusa->signal_drag_begin().connect( SigC::slot(*this, &Constructor::on_exclusa_drag_begin));
140         btn_drain->signal_drag_begin().connect( SigC::slot(*this, &Constructor::on_drain_drag_begin));
141         btn_and->signal_drag_begin().connect( SigC::slot(*this, &Constructor::on_and_drag_begin));
142         btn_or->signal_drag_begin().connect( SigC::slot(*this, &Constructor::on_or_drag_begin));
143         btn_not->signal_drag_begin().connect( SigC::slot(*this, &Constructor::on_not_drag_begin));
144         workplace->drag_dest_set(listTargets);
145         workplace->signal_drag_data_received().connect( SigC::slot(*this, &Constructor::on_item_drop_drag_received) );  
146         // Apunto la lista del area de trabajo a la lista de items en el Constructor
147         workplace->listaItems = &listaItems;    
148         workplace->lista_logic_Items = &lista_logic_Items;      
149         workplace->logica = &logica;
150         logica = false;
151 }
152
153 Constructor::~Constructor()
154 {
155         // elimina todos los items 
156         Constructor::on_edit_menu_delete_all();
157 }
158
159 // Definicion de los metodos para obtener el icono al realizar un drag.
160 void Constructor::on_btn_canio_drag_get(const Glib::RefPtr<Gdk::DragContext>& context, GtkSelectionData* selection_data, guint info, guint time)
161 {
162         gtk_selection_data_set (selection_data, selection_data->target, 8, (const guchar*)"canio_n.png", 12);
163 }
164
165 void Constructor::on_btn_y_drag_get(const Glib::RefPtr<Gdk::DragContext>& context, GtkSelectionData* selection_data, guint info, guint time)
166 {
167         gtk_selection_data_set(selection_data, selection_data->target, 8,(const guchar*)"y_n.png",8);
168 }
169
170 void Constructor::on_btn_codo_drag_get(const Glib::RefPtr<Gdk::DragContext>& context, GtkSelectionData* selection_data, guint info, guint time)
171 {
172         gtk_selection_data_set(selection_data, selection_data->target, 8 ,(const guchar*)"codo_o.png",10);
173 }
174
175 void Constructor::on_btn_tanque_drag_get(const Glib::RefPtr<Gdk::DragContext>& context, GtkSelectionData* selection_data, guint info, guint time)
176 {
177         gtk_selection_data_set(selection_data, selection_data->target, 8,(const guchar*)"tanque_e.png",12);
178 }
179
180 void Constructor::on_btn_bomba_drag_get(const Glib::RefPtr<Gdk::DragContext>& context, GtkSelectionData* selection_data, guint info, guint time)
181 {
182         gtk_selection_data_set(selection_data, selection_data->target, 8,(const guchar*)"bomba_e.png",11);
183 }
184
185 void Constructor::on_btn_exclusa_drag_get(const Glib::RefPtr<Gdk::DragContext>& context, GtkSelectionData* selection_data, guint info, guint time)
186 {
187         gtk_selection_data_set(selection_data, selection_data->target, 8,(const guchar*)"exclusa_h.png",13);
188 }
189
190 void Constructor::on_btn_drain_drag_get(const Glib::RefPtr<Gdk::DragContext>& context, GtkSelectionData* selection_data, guint info, guint time)
191 {
192         gtk_selection_data_set(selection_data, selection_data->target, 8,(const guchar*)"drain_n.png",11);
193 }
194
195 void Constructor::on_btn_and_drag_get(const Glib::RefPtr<Gdk::DragContext>& context, GtkSelectionData* selection_data, guint info, guint time)
196 {
197         gtk_selection_data_set(selection_data, selection_data->target, 8,(const guchar*)"and_e.png",9);
198 }
199
200 void Constructor::on_btn_or_drag_get(const Glib::RefPtr<Gdk::DragContext>& context, GtkSelectionData* selection_data, guint info, guint time)
201 {
202         gtk_selection_data_set(selection_data, selection_data->target, 8,(const guchar*)"or_e.png",8);
203 }
204
205 void Constructor::on_btn_not_drag_get(const Glib::RefPtr<Gdk::DragContext>& context, GtkSelectionData* selection_data, guint info, guint time)
206 {
207         gtk_selection_data_set(selection_data, selection_data->target, 8,(const guchar*)"not_e.png",9);
208 }
209
210 //Sale del programa.
211 void Constructor::on_main_menu_quit()
212 {
213         delete this;
214         Gtk::Main::quit();
215         //hide();
216 }
217
218 // Carga de un archivo XML
219 void Constructor::on_main_menu_open()
220 {
221         // Conecto el boton OK para llamar al cargar del XML
222         file_open_selection->show();
223 }
224
225 // Salva un archivo XML
226 void Constructor::on_main_menu_save()
227 {
228         // Conecto el boton OK para llamar al salvar
229         Glib::ustring name;
230         if ( ! check_connection(name) ) {
231                 dlg_connect->set_title("Error");
232                 dlg_label->set_text("El elemento "+name+" no esta conectado\n\t\tcorrectamente");
233                 dlg_connect->show();
234         } else  
235                 file_selection->show();
236 }
237
238 // Elimina el item apuntado desde el menu principal
239 void Constructor::on_edit_menu_del()
240
241         workplace->delete_item(WorkPlace::pointed);
242 }
243
244 // Elimina todos lo items
245 void Constructor::on_edit_menu_delete_all()
246 {
247         std::list<CItem *>::iterator i = listaItems.begin();
248         while ( i != listaItems.end() ) {
249                 (*i)->workplace->delete_item((*i)->get_id());
250                 i = listaItems.begin();
251         }
252         i = lista_logic_Items.begin();
253         while ( i != lista_logic_Items.end() ) {
254                 (*i)->workplace->delete_item((*i)->get_id());
255                 i=lista_logic_Items.begin();
256         }
257         id = 0;
258         list_pointed.clear();
259         list_pointed.push_back(" ");
260         combo_entry->set_popdown_strings(list_pointed);
261         combo_entry->get_entry()->set_text("");
262 }
263
264 // Al presionarse el check button "logica"
265 void Constructor::on_chk_btn_logica_clicked()
266 {
267         logica = !logica;
268         CItem::logic_connect = !CItem::logic_connect;
269         workplace->queue_draw();
270 }
271
272 // Metodo que levanta el archivo XML y crea todos los items agregandolos a las listas correspondientes
273 void Constructor::on_load_from_xml()
274 {
275         on_edit_menu_delete_all();
276         file_name = file_open_selection->get_filename();
277
278         /* Parseo de ejemplo de un XML desde archivo */
279         xmlDocPtr document;
280         document = xmlParseFile(file_name.c_str());
281         if (document == NULL) {
282                 std::cout<<"NO SE PUDO CARGAR EL ARCHIVO"<<std::endl;
283                 // TODO : dar un aviso de que no se pudo abrir el archivo!!
284                 return;
285         }
286
287         /* bien, el archivo se parseo bien! */
288         xmlNodePtr nodo, items;
289         nodo = document->children;
290
291         // Recorro los items
292         CItem *current;
293         if (strcmp((char *)nodo->name, "planta") == 0) {
294                 items = nodo->children;
295                 while (items != NULL) {
296                         current = NULL;
297                         if (items->type == XML_ELEMENT_NODE) {
298                                 std::cout << "ITEM" << std::endl;
299                                 if (xmlStrcmp(items->name, BAD_CAST"bomba")==0) {
300                                         current = loadBomba(items);
301                                 } else if (xmlStrcmp(items->name, BAD_CAST"tubo")==0) {
302                                         current = loadConduct(items);
303                                 } else if (xmlStrcmp(items->name, BAD_CAST"codo")==0) {
304                                         current = loadCodo(items);
305                                 } else if (xmlStrcmp(items->name, BAD_CAST"exclusa")==0) {
306                                         current = loadExclusa(items);
307                                 } else if (xmlStrcmp(items->name, BAD_CAST"tanque")==0) {
308                                         current = loadTank(items);
309                                 } else if (xmlStrcmp(items->name, BAD_CAST"empalme")==0) {
310                                         current = loadUnion(items);
311                                 } else if (xmlStrcmp(items->name, BAD_CAST"drenaje")==0) {
312                                         current = loadDrain(items);
313                                 } else if (xmlStrcmp(items->name, BAD_CAST"and")==0) {
314                                         current = loadAnd(items);
315                                 } else if (xmlStrcmp(items->name, BAD_CAST"not")==0) {
316                                         current = loadNot(items);
317                                 } else if (xmlStrcmp(items->name, BAD_CAST"or")==0) {
318                                         current = loadOr(items);
319                                 }
320
321                                 if (current != NULL) {
322                                         if (! current->is_logic )
323                                                 listaItems.push_back(current);
324                                         else {
325                                                 lista_logic_Items.push_back(current);
326                                         }
327                                         // Agrego y conecto la bomba
328                                         current->drag_source_set(listTargets);
329                                         workplace->put(*current, current->get_position_x(), current->get_position_y());
330                                         //Apunto al workplace
331                                         current->workplace= workplace;
332                                         //Apunto a la lista.
333                                         current->combo_entry = combo_entry;
334                                         //Apunto a la lista de apuntados
335                                         current->list_pointed = &list_pointed;
336                                         //Apunto a la listaItems.
337                                         current->listaItems = &listaItems;
338                                         //Apunto a la lista de items logicos
339                                         current->lista_logic_Items = &lista_logic_Items;
340                                         //Apunto a la barra de estado
341                                         current->status_bar = status_bar;
342                                         // Conecto las señales
343                                         current->signal_drag_data_get().connect( SigC::slot(*this, &Constructor::on_item_drag_data_get));
344                                         current->signal_drag_begin().connect(SigC::bind( SigC::slot(*this, &Constructor::on_item_drag_begin), current));
345                                         current->show();        
346                                 }
347                         }
348                         items = items->next;
349                 }
350                 
351                 // Crea las lineas que conectan la parte logica.
352                 create_lines(document->children);
353                 xmlFreeDoc(document);
354                 workplace->update_logic_position();
355                 workplace->queue_draw();
356         } else {
357                 std::cout<< "EL XML NO ES VALIDO" << std::endl;
358                 // TODO : avisar que el XML no es valido!!
359         }
360         std::cout << "CARGA COMPLETA" << std::endl;
361         file_open_selection->hide();
362         
363         // Seteo el id en el maximo mas uno de todos los id cargados, para que quede bien cuando se agregan nuevos items en un proyecto 
364         // cargado desde un archivo.
365         int id_1 = -1 , id_2 = -1;
366         std::list<CItem *>::iterator i = listaItems.begin();
367         while ( i != listaItems.end() ){
368                 if ( (*i)->get_id() >= id_1 ) 
369                         id_1 = (*i)->get_id();
370         i++;
371         }
372         id_1++;
373         
374         i = lista_logic_Items.begin();
375         while ( i != lista_logic_Items.end() ){
376                 if ( (*i)->get_id() >= id_2 ) 
377                         id_2 = (*i)->get_id();
378         i++;
379         }
380         id_2++;
381         if ( id_1 < id_2 ) id = id_2;
382         else id = id_1;
383 }
384
385 // Recorre todo los items los cuales conocen la manera de salvarse en un archivo XML.
386 void Constructor::on_btn_file_ok_clicked()
387 {
388         std::list<CItem *>::iterator i = listaItems.begin();
389         file_name = file_selection->get_filename();
390         Glib::ustring name;
391         if ( (archivo = fopen( file_name.c_str(), "w+")) != NULL ){
392                 fprintf(archivo, "<?xml version=\"1.0\" encoding=\"iso-8859-1\" ?>\n");
393                 fprintf (archivo,"<planta>\n");
394                 while ( i != listaItems.end() ){
395                         (*i)->save(archivo);
396                         i++;
397                 }
398                 i = lista_logic_Items.begin();
399                 while ( i != lista_logic_Items.end() ) {
400                         (*i)->save(archivo);
401                         i++;
402                 }
403                 fprintf(archivo,"</planta>\n");
404                 saved = true;
405                 fclose(archivo);
406         } else 
407                 std::cout<<"NO SE ABRIO EL ARCHIVO"<<std::endl;
408         file_selection->hide();
409 }
410
411 // Salva el archivo, si no estaba salvado muestra el dialogo, si no sobreescribe el ultimo archivo salvado.
412 void Constructor::on_quick_btn_save_clicked()
413 {
414         if ( ! saved ) {
415                 on_main_menu_save();
416         } else {
417                 on_btn_file_ok_clicked();
418         }
419 }
420         
421 // Limpia la pantalla para comenzar un nuevo proyecto.
422 void Constructor::on_quick_btn_new_clicked()
423 {
424         on_quick_btn_delete_all_clicked();
425         saved = false;
426 }
427
428 // Borra todos los items pero desde otro boton.
429 void Constructor::on_quick_btn_delete_all_clicked()
430 {
431         on_edit_menu_delete_all();
432 }       
433
434 // busca en la lista el nombre del item que aparece en el cuadro de texto y si lo encuentra dibuja un recuadro para mostrarlo.
435 void Constructor::on_btn_find_clicked()
436 {
437         CItem * temp = NULL;
438         std::list<CItem *>::iterator i = listaItems.begin();
439         while ( i !=listaItems.end() ) {
440                 if ( (*i)->get_name()  == combo_entry->get_entry()->get_text() ) {
441                         temp = *i;
442                         break;
443                 }
444                 i++;
445         }
446         
447         i = lista_logic_Items.begin();
448         while ( i !=lista_logic_Items.end() ) {
449                 if ( (*i)->get_name()  == combo_entry->get_entry()->get_text() ) {
450                         temp = *i;
451                         break;
452                 }
453                 i++;
454         }
455         if ( temp != NULL )
456         workplace->get_window()->draw_rectangle(workplace->get_style()->get_black_gc(), false , temp->get_position_x()-5, temp->get_position_y()-5,
457                                                                                                                                                 temp->get_image()->get_width()+10, temp->get_image()->get_height()+10);
458 }
459
460 // Oculta el dialogo.
461 void Constructor::on_btn_file_cancel_clicked()
462 {
463         file_selection->hide();
464 }
465
466 //Muestra el dialogo para seleccionar archivo
467 void Constructor::on_btn_open_cancel_clicked()
468 {
469         file_open_selection->hide();
470 }
471
472 // Oculta el dialogo
473 void Constructor::on_btn_dlg_connect_clicked()
474 {
475         dlg_connect->hide();
476 }
477
478 //Metodos que permiten que el icono sea el del items durante el drag 
479 void Constructor::on_canio_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)
480 {
481         context->set_icon(ico_canio, 5, 5); 
482 }
483
484 void Constructor::on_y_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)
485 {
486         context->set_icon(ico_y, 5, 5); 
487 }
488
489 void Constructor::on_codo_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)
490 {
491         context->set_icon(ico_codo, 5, 5); 
492 }
493
494 void Constructor::on_tanque_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)
495 {
496         context->set_icon(ico_tanque, 5, 5); 
497 }
498
499 void Constructor::on_bomba_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)
500 {
501         context->set_icon(ico_bomba, 5, 5); 
502 }
503
504 void Constructor::on_exclusa_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)
505 {
506         context->set_icon(ico_exclusa, 5, 5); 
507 }
508
509 void Constructor::on_drain_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)
510 {
511         context->set_icon(ico_drain, 5, 5); 
512 }
513
514 void Constructor::on_and_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)
515 {
516         context->set_icon(ico_and, 5, 5); 
517 }
518
519 void Constructor::on_or_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)
520 {
521         context->set_icon(ico_or, 5, 5); 
522 }
523
524 void Constructor::on_not_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)
525 {
526         context->set_icon(ico_not, 5, 5); 
527 }
528
529 void Constructor::on_item_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context, CItem *item)
530 {
531         context->set_icon(item->get_image(), 5, 5);
532 }
533
534 void Constructor::on_item_drag_data_get(const Glib::RefPtr<Gdk::DragContext>& context, GtkSelectionData* selection_data, guint info, guint time)
535 {       
536         gtk_selection_data_set (selection_data, selection_data->target, 10, (const guchar*)"item_codo.png", 13);
537 }
538
539 // Si un item es movido encima de otro este metodo devueve falso. De esta manera no podran encimarse items.
540 bool Constructor::can_drop(CItem *item, int _x, int _y)
541 {
542         std::list<CItem*>::iterator  i = listaItems.begin();
543         while( i != listaItems.end() ) {
544                 CItem *temp = *i;
545                 if ( temp->get_id() != item->get_id()   ) {
546                         if (  (temp->is_occupied_area(_x, _y))  ||  
547                                 ( temp->is_occupied_area(_x+item->get_image()->get_width()-1, _y+item->get_image()->get_height()-1))  ||
548                                 ( temp->is_occupied_area(_x, _y+item->get_image()->get_height()-1)) ||
549                                 ( temp->is_occupied_area(_x+item->get_image()->get_width()-1, _y) ) ) 
550                                 return false;
551                         else i++;
552                 }
553                 else i++;
554         }
555         return true;
556 }
557
558 //Cada vez que se realiza un drag o un drop este metodo es invocado.
559 //Aca se validan las posiciones de los items y se crean si no estaban en el area de trabajo.
560 void Constructor::on_item_drop_drag_received(const Glib::RefPtr<Gdk::DragContext>& context, int x, int y, GtkSelectionData* selection_data, guint info, guint time)
561 {
562         workplace->update_logic_position();
563         workplace->queue_draw();
564         if ( !logica ) {
565                 /* Ajusto coordenada x e y para que caigan en un lugar de una cuadricula de 32x32 */
566                 int i,j;
567                 // el +1 es para evitar un bug cuando se selecciona muy cerce de la
568                 // separacion de 2 cuadritos
569                 i = (x+1)/32;
570                 j = (y+1)/32;
571                 // El drag es de un item
572                 if (selection_data->format == 10) {
573                         if (can_drop(((CItem*)drag_get_source_widget(context)),i*32, j*32)){
574                                 ((CItem*)drag_get_source_widget(context))->set_position(i*32, j*32);
575                                 workplace->move(*drag_get_source_widget(context), i*32, j*32);
576                         }
577                 }
578
579                 // El Drag es desde la barra de tareas
580                 if ((selection_data->length >= 0) && (selection_data->format == 8))     {
581                         CItem *a;
582                         if (strcmp((const char *)selection_data->data, "codo_o.png")==0) 
583                         a = new Splitter();
584                         else    if (strcmp((const char *)selection_data->data, "canio_n.png")==0) 
585                         a = new Conduct();
586                         else if (strcmp((const char *)selection_data->data, "y_n.png")==0) 
587                         a = new Union();
588                         else if (strcmp((const char *)selection_data->data, "tanque_e.png")==0) 
589                         a = new Cistern();
590                         else if (strcmp((const char *)selection_data->data, "bomba_e.png")==0) 
591                         a =new Pump();
592                         else if (strcmp((const char *)selection_data->data, "exclusa_h.png")==0) 
593                         a = new Exclusa();
594                         else if (strcmp((const char *)selection_data->data, "drain_n.png")==0) 
595                         a = new Drain();
596                         else if (strcmp((const char *)selection_data->data, "and_e.png")==0){ 
597                         a = new And(); a->is_logic = true;
598                         } else if (strcmp((const char *)selection_data->data, "or_e.png")==0) {
599                                 a = new Or(); a->is_logic = true;
600                                 } else if (strcmp((const char *)selection_data->data, "not_e.png")==0) {
601                                         a = new Not(); a->is_logic = true;
602                                         }
603                 
604                         char char_id[10];
605                         sprintf(char_id,"%d",id);
606                         a->set_id(id++);                
607                         a->set_name( a->get_name()+char_id );
608                         if ( can_drop(a, i*32, j*32) ) {
609                                 workplace->put(*a, i*32, j*32);
610                                 //Apunto al workplace
611                                 a->workplace = workplace;
612                                 //Apunto a la lista.
613                                 a->combo_entry = combo_entry;
614                                 //Apunto a la lista de apuntados
615                                 a->list_pointed = &list_pointed;
616                                 //Apunto a la listaItems.
617                                 a->listaItems = &listaItems;
618                                 //Apunto a la barra de estado
619                                 a->status_bar = status_bar;
620                                 //Apunto a la lista de items logicos
621                                 a->lista_logic_Items = &lista_logic_Items;
622                                 //Seteo la posicion del item
623                                 a->set_position(i*32,j*32);
624                                 // Seteo la lista de tipos de drags 
625                                 a->drag_source_set(listTargets);
626                                 // Conecto las señales
627                                 a->signal_drag_data_get().connect( SigC::slot(*this, &Constructor::on_item_drag_data_get));
628                                 // Utilizo el SigC::bind para que el callback on_drag_begin acepte un
629                                 // parametro extra, en este caso un CItem *. Esto se hace para
630                                 // que cuando el usuario quiera mover un item, saber que item es
631                                 // y pedirle su ícono para mostrar cono icono durante la operacion,
632                                 // Esto va a permitir, que si un widget tiene una imagen rotara o algo
633                                 // raro se vea el widget tal cual.
634                                 a->signal_drag_begin().connect(SigC::bind( SigC::slot(*this, &Constructor::on_item_drag_begin), a));
635                                 a->show();      
636                                 if (! a->is_logic )
637                                         listaItems.push_back(a);
638                                 else 
639                                         lista_logic_Items.push_back(a);
640                         } else {
641                                         id--;
642                                         delete a;
643                                 }
644                 }
645                 context->drag_finish(false, false, time);
646         }
647         workplace->update_logic_position();
648         workplace->queue_draw();
649 }
650
651 // Cuando se presiona el boton "Verificar Conexiones" esta funcion es invocada
652 //Muestra un dialogo de error en caso de que no esten bien conectados y un dialogo
653 //de exito si lo estan.
654 void Constructor::on_btn_check_clicked()
655 {
656         Glib::ustring name;
657         if ( ! check_connection(name) ) {
658                 dlg_connect->set_title("Error");
659                 dlg_label->set_text("El elemento "+name+" no esta conectado\n\t\tcorrectamente");
660                 dlg_connect->show();
661         } else {
662                 dlg_connect->set_title("Conexion");
663                 dlg_label->set_text("Los elementos estan conectados\n\t\tcorrectamente");
664                 dlg_connect->show();
665         }
666 }
667
668 //Verifica que todos los items esten correctamente conectados en sus extremos.
669 //Cada item verifica su conexion en forma independiente.
670 bool Constructor::check_connection(Glib::ustring& name)
671 {
672         std::list<CItem *>::iterator i = listaItems.begin();
673         while ( i != listaItems.end() ){
674                 (*i)->set_default_connector();
675                 (*i)->is_connected = false;
676                 i++;
677         }
678         i = listaItems.begin();
679         if ( !listaItems.empty() ) {
680                 while ( i != listaItems.end() ) {
681                         CItem *temp = *i;
682                         std::cout<< "item="<<temp->get_name()<<" "<<"check= "<<temp->check_connection()<<std::endl;
683                         if ( !temp->check_connection() ) {
684                                 name = temp->get_name();
685                                 return false;
686                         }       
687                 i++;
688                 }
689         }
690         std::cout<<"check_connection logic"<<std::endl;
691         std::list<CItem *>::iterator j = lista_logic_Items.begin();
692         while ( j != lista_logic_Items.end() ) {
693                 if ( !(*j)->check_connection() ) {
694                         name = (*j)->get_name();
695                         return false;
696                 }
697                 j++;
698         }
699         return true;
700 }       
701
702
703 //Los siguientes metodos son utilizados para levantar cada item desde el XML
704
705 Not *Constructor::loadNot(xmlNodePtr nodo)
706 {
707         std::string name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
708         std::string id = (char *)xmlGetProp(nodo, BAD_CAST"id");
709         int orientacion=0, x, y;
710
711         nodo = nodo->children;
712         while (nodo != NULL) {
713                 if (nodo->type == XML_ELEMENT_NODE) {
714                         if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
715                                 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
716                         } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
717                                 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
718                         } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
719                                 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
720                         }
721                 }
722                 nodo = nodo->next;
723         }
724
725         Not *p = new Not(orientacion);
726         p->set_position(x,y);
727         p->set_id( atoi(id.c_str()) );
728         p->set_name(name);
729
730         return p;
731 }
732
733 Or *Constructor::loadOr(xmlNodePtr nodo)
734 {
735         std::string name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
736         std::string id = (char *)xmlGetProp(nodo, BAD_CAST"id");
737         int orientacion=0, x, y;
738
739         nodo = nodo->children;
740         while (nodo != NULL) {
741                 if (nodo->type == XML_ELEMENT_NODE) {
742                         if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
743                                 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
744                         } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
745                                 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
746                         } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
747                                 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
748                         }
749                 }
750                 nodo = nodo->next;
751         }
752
753         Or *p = new Or(orientacion);
754         p->set_position(x,y);
755         p->set_id( atoi(id.c_str()) );
756         p->set_name(name);
757
758         return p;
759 }
760
761 And *Constructor::loadAnd(xmlNodePtr nodo)
762 {
763         std::string name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
764         std::string id = (char *)xmlGetProp(nodo, BAD_CAST"id");
765         int orientacion=0, x, y;
766         float flujo;
767         xmlNodePtr inicial = nodo;
768
769         nodo = nodo->children;
770         while (nodo != NULL) {
771                 if (nodo->type == XML_ELEMENT_NODE) {
772                         if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
773                                 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
774                         } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
775                                 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
776                         } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
777                                 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
778                         }
779                 }
780                 nodo = nodo->next;
781         }
782
783         And *p = new And(orientacion);
784         p->set_position(x,y);
785         p->set_id( atoi(id.c_str()) );
786         p->set_name(name);
787         return p;
788 }
789
790 Pump *Constructor::loadBomba(xmlNodePtr nodo)
791 {
792         std::string name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
793         std::string id = (char *)xmlGetProp(nodo, BAD_CAST"id");
794         int orientacion=0, x, y;
795         float flujo;
796         Gdk::Color color;
797
798         nodo = nodo->children;
799         while (nodo != NULL) {
800                 if (nodo->type == XML_ELEMENT_NODE) {
801                         if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
802                                 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
803                         } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
804                                 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
805                         } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
806                                 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
807                         } else if (xmlStrcmp(nodo->name, BAD_CAST"entrega") == 0) {
808                                 flujo = atof( (char *)XML_GET_CONTENT(nodo->children) );
809                         } else if (xmlStrcmp(nodo->name, BAD_CAST"color") == 0) {
810                                 color = loadColor(nodo->children);
811                         }
812                 }
813                 nodo = nodo->next;
814         }
815
816         Pump *p = new Pump(orientacion);
817         p->set_position(x,y);
818         p->set_entrega(flujo);
819         p->set_id( atoi(id.c_str()) );
820         p->set_name(name);
821         p->set_liquid_color(color);
822
823         return p;
824 }
825
826 Gdk::Color Constructor::loadColor(xmlNodePtr nodo)
827 {
828         gushort r,g,b;
829         while (nodo != NULL) {
830                 if (nodo->type == XML_ELEMENT_NODE) {
831                         if (xmlStrcmp(nodo->name, BAD_CAST"rojo")==0)
832                                 r = atoi( (char *)XML_GET_CONTENT(nodo->children) );
833                         if (xmlStrcmp(nodo->name, BAD_CAST"verde")==0)
834                                 g = atoi( (char *)XML_GET_CONTENT(nodo->children) );
835                         if (xmlStrcmp(nodo->name, BAD_CAST"azul")==0)
836                                 b = atoi( (char *)XML_GET_CONTENT(nodo->children) );
837                 }
838                 nodo = nodo->next;
839         }
840         Gdk::Color c;
841         c.set_rgb(r,g,b);
842         std::cout << r << "  " << g << " " << b << std::endl;
843         return c;
844 }
845
846 Conduct *Constructor::loadConduct(xmlNodePtr nodo)
847 {
848         std::string name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
849         std::string id = (char *)xmlGetProp(nodo, BAD_CAST"id");
850         int orientacion=0, x, y;
851         float flujo;
852
853         nodo = nodo->children;
854         while (nodo != NULL) {
855                 if (nodo->type == XML_ELEMENT_NODE) {
856                         if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
857                                 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
858                         } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
859                                 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
860                         } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
861                                 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
862                         } else if (xmlStrcmp(nodo->name, BAD_CAST"caudal") == 0) {
863                                 flujo = atof( (char *)XML_GET_CONTENT(nodo->children) );
864                         }
865                 }
866                 nodo = nodo->next;
867         }
868
869         Conduct *p = new Conduct(orientacion);
870         p->set_position(x,y);
871         p->set_caudal(flujo);
872         p->set_id( atoi(id.c_str()) );
873         p->set_name(name);
874
875         return p;
876 }
877
878 Exclusa *Constructor::loadExclusa(xmlNodePtr nodo)
879 {
880         std::string name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
881         std::string id = (char *)xmlGetProp(nodo, BAD_CAST"id");
882         std::string estado;
883         int orientacion=0, x, y;
884         float flujo;
885
886         nodo = nodo->children;
887         while (nodo != NULL) {
888                 if (nodo->type == XML_ELEMENT_NODE) {
889                         if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
890                                 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
891                         } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
892                                 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
893                         } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
894                                 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
895                         } else if (xmlStrcmp(nodo->name, BAD_CAST"estado") == 0) {
896                                 estado = (char *)XML_GET_CONTENT(nodo->children);
897                         }
898                 }
899                 nodo = nodo->next;
900         }
901
902         Exclusa *p = new Exclusa(orientacion);
903         p->set_position(x,y);
904         p->set_id( atoi(id.c_str()) );
905         p->set_name(name);
906         p->set_estado( estado == "1" );
907
908         return p;
909 }
910
911 Cistern *Constructor::loadTank(xmlNodePtr nodo)
912 {
913         std::string name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
914         std::string id = (char *)xmlGetProp(nodo, BAD_CAST"id");
915         int orientacion=0, x, y;
916         float liquido,capacidad;
917         Gdk::Color color;
918
919         nodo = nodo->children;
920         while (nodo != NULL) {
921                 if (nodo->type == XML_ELEMENT_NODE) {
922                         if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
923                                 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
924                         } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
925                                 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
926                         } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
927                                 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
928                         } else if (xmlStrcmp(nodo->name, BAD_CAST"capacidad") == 0) {
929                                 capacidad = atof ((char *)XML_GET_CONTENT(nodo->children) );
930                         } else if (xmlStrcmp(nodo->name, BAD_CAST"inicial") == 0) {
931                                 liquido = atof ((char *)XML_GET_CONTENT(nodo->children) );
932                         } else if (xmlStrcmp(nodo->name, BAD_CAST"color") == 0) {
933                                 color = loadColor(nodo->children);
934                         }
935                 }
936                 nodo = nodo->next;
937         }
938
939         Cistern *p = new Cistern(orientacion);
940         p->set_position(x,y);
941         p->set_id( atoi(id.c_str()) );
942         p->set_name(name);
943         p->set_capacidad(capacidad);
944         p->set_contenido_inicial(liquido);
945         p->set_liquid_color(color);
946         return p;
947 }
948
949 Union *Constructor::loadUnion(xmlNodePtr nodo)
950 {
951         std::string name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
952         std::string id = (char *)xmlGetProp(nodo, BAD_CAST"id");
953         std::string tipo;
954         int orientacion=0, x, y;
955         float caudal;
956
957         nodo = nodo->children;
958         while (nodo != NULL) {
959                 if (nodo->type == XML_ELEMENT_NODE) {
960                         if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
961                                 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
962                         } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
963                                 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
964                         } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
965                                 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
966                         } else if (xmlStrcmp(nodo->name, BAD_CAST"caudal") == 0) {
967                                 caudal = atof ((char *)XML_GET_CONTENT(nodo->children) );
968                         } else if (xmlStrcmp(nodo->name, BAD_CAST"tipo") == 0) {
969                                 tipo = (char *)XML_GET_CONTENT(nodo->children);
970                         }
971                 }
972                 nodo = nodo->next;
973         }
974
975         Union *p = new Union(orientacion);
976         p->set_position(x,y);
977         p->set_id( atoi(id.c_str()) );
978         p->set_name(name);
979         p->set_caudal(caudal);
980         p->is_union = (tipo == "union");
981
982         return p;
983 }
984
985 Drain *Constructor::loadDrain(xmlNodePtr nodo)
986 {
987         std::string name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
988         std::string id = (char *)xmlGetProp(nodo, BAD_CAST"id");
989         int orientacion=0, x, y;
990
991         nodo = nodo->children;
992         while (nodo != NULL) {
993                 if (nodo->type == XML_ELEMENT_NODE) {
994                         if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
995                                 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
996                         } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
997                                 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
998                         } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
999                                 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
1000                         }
1001                 }
1002                 nodo = nodo->next;
1003         }
1004
1005         Drain *p = new Drain(orientacion);
1006         p->set_position(x,y);
1007         p->set_id( atoi(id.c_str()) );
1008         p->set_name(name);
1009
1010         return p;
1011 }
1012
1013 Splitter *Constructor::loadCodo(xmlNodePtr nodo)
1014 {
1015         std::string name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
1016         std::string id = (char *)xmlGetProp(nodo, BAD_CAST"id");
1017         int orientacion=0, x, y;
1018         float caudal;
1019
1020         nodo = nodo->children;
1021         while (nodo != NULL) {
1022                 if (nodo->type == XML_ELEMENT_NODE) {
1023                         if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
1024                                 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
1025                         } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
1026                                 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
1027                         } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
1028                                 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
1029                         } else if (xmlStrcmp(nodo->name, BAD_CAST"caudal") == 0) {
1030                                 caudal = atof( (char *)XML_GET_CONTENT(nodo->children) );
1031                         }
1032                 }
1033                 nodo = nodo->next;
1034         }
1035
1036         Splitter *p = new Splitter(orientacion);
1037         p->set_position(x,y);
1038         p->set_id( atoi(id.c_str()) );
1039         p->set_name(name);
1040         p->set_caudal(caudal);
1041
1042         return p;
1043 }
1044
1045 void Constructor::create_lines(xmlNodePtr nodo)
1046 {
1047         std::string name;
1048         
1049         nodo = nodo->children;
1050         while (nodo != NULL) {
1051                 if (nodo->type == XML_ELEMENT_NODE) {
1052                         if (xmlStrcmp(nodo->name, BAD_CAST"and")==0) {
1053                                 name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
1054                                 std::cout << name << std::endl;
1055                                 create_line(nodo->children, workplace->get_logic_id(name));
1056                         } else if (xmlStrcmp(nodo->name, BAD_CAST"not")==0) {
1057                                 name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
1058                                 std::cout << name << std::endl;
1059                                 create_line(nodo->children, workplace->get_logic_id(name));
1060                         } else if (xmlStrcmp(nodo->name, BAD_CAST"or")==0) {
1061                                 name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
1062                                 std::cout << name << std::endl;
1063                                 create_line(nodo->children, workplace->get_logic_id(name));
1064                         }
1065                 }
1066                 nodo = nodo->next;
1067         }
1068 }
1069
1070 //Levanta las lineas desde el archvo XML 
1071 void Constructor::create_line(xmlNodePtr nodo, int logic_id)
1072 {
1073         std::string otro;
1074         std::cout << "Buscando lineas ..." << std::endl;
1075         while (nodo != NULL) {
1076                 if (nodo->type == XML_ELEMENT_NODE) {
1077                         if (xmlStrcmp(nodo->name, BAD_CAST"salida")==0) {
1078                                 otro = (char *)XML_GET_CONTENT(nodo->children);
1079                                 t_line tmp_line;
1080                                 tmp_line.logic_id = logic_id;
1081                                 //workplace->get_logic_item(logic_id)->set_out_connected(true);
1082                                 if (workplace->get_item_id(otro) != -1) {
1083                                         tmp_line.store_id = workplace->get_item_id(otro);
1084                                         std::cout << otro << " se conecta a una compuerta" << std::endl;
1085                                         workplace->lista_lineas_in.push_back(tmp_line);
1086                                 } else {
1087                                         /* Como no era un item, debe ser una compuerta */
1088                                         tmp_line.store_id = workplace->get_logic_id(otro);
1089                                         workplace->lista_lineas_logic.push_back(tmp_line);
1090                                 }
1091                         } else if (xmlStrcmp(nodo->name, BAD_CAST"entrada")==0) {
1092                                 otro = (char *)XML_GET_CONTENT(nodo->children);
1093                                 t_line tmp_line;
1094                                 tmp_line.logic_id = logic_id;
1095                                 if (workplace->get_item_id(otro) != -1) {
1096                                         tmp_line.store_id = workplace->get_item_id(otro);
1097                                         /* Tengo que ver si es un tanque, para setearlo correctamente */
1098                                         if (dynamic_cast<Cistern *>(workplace->get_item(workplace->get_item_id(otro)))) {
1099                                                 std::string donde = (char *)xmlGetProp(nodo, BAD_CAST"id");
1100                                                 tmp_line.cistern_out1 = true;
1101                                                 if (donde == "inferior") {
1102                                                         tmp_line.cistern_out1 = false;
1103                                                 }
1104                                         }
1105                                         workplace->lista_lineas_out.push_back(tmp_line);
1106                                         std::cout << otro << " se conecta a una compuerta" << std::endl;
1107                                 } else {
1108                                         /* Como no era un item, debe ser una compuerta */
1109                                         tmp_line.store_id = workplace->get_logic_id(otro);
1110                                         workplace->lista_lineas_logic.push_back(tmp_line);
1111                                 }
1112                         }
1113                 }
1114                 nodo = nodo->next;
1115         }
1116 }