1 #include "constructor.h"
3 Constructor::Constructor(BaseObjectType* cobject, const Glib::RefPtr<Gnome::Glade::Xml>& refGlade):Gtk::Window(cobject)
7 set_title("Constructor");
10 ico_canio = Gdk::Pixbuf::create_from_file(PACKAGE_DATA_DIR"/plaqui-constructor/pixmaps/canio_n.png");
11 ico_y = Gdk::Pixbuf::create_from_file(PACKAGE_DATA_DIR"/plaqui-constructor/pixmaps/y_n.png");
12 ico_codo = Gdk::Pixbuf::create_from_file(PACKAGE_DATA_DIR"/plaqui-constructor/pixmaps/codo_o.png");
13 ico_tanque = Gdk::Pixbuf::create_from_file(PACKAGE_DATA_DIR"/plaqui-constructor/pixmaps/tanque_e.png");
14 ico_exclusa = Gdk::Pixbuf::create_from_file(PACKAGE_DATA_DIR"/plaqui-constructor/pixmaps/exclusa_h.png");
15 ico_drain = Gdk::Pixbuf::create_from_file(PACKAGE_DATA_DIR"/plaqui-constructor/pixmaps/drain_n.png");
16 ico_bomba = Gdk::Pixbuf::create_from_file(PACKAGE_DATA_DIR"/plaqui-constructor/pixmaps/bomba_e.png");
17 ico_and = Gdk::Pixbuf::create_from_file(PACKAGE_DATA_DIR"/plaqui-constructor/pixmaps/and_e.png");
18 ico_or = Gdk::Pixbuf::create_from_file(PACKAGE_DATA_DIR"/plaqui-constructor/pixmaps/or_e.png");
19 ico_not = Gdk::Pixbuf::create_from_file(PACKAGE_DATA_DIR"/plaqui-constructor/pixmaps/not_e.png");
21 refGlade->get_widget("btn_canio", btn_canio);
22 refGlade->get_widget("btn_codo", btn_codo);
23 refGlade->get_widget("btn_y", btn_y);
24 refGlade->get_widget("btn_tanque",btn_tanque);
25 refGlade->get_widget("btn_bomba", btn_bomba);
26 refGlade->get_widget("btn_exclusa", btn_exclusa);
27 refGlade->get_widget("btn_drain", btn_drain);
28 refGlade->get_widget("btn_and", btn_and);
29 refGlade->get_widget("btn_or", btn_or);
30 refGlade->get_widget("btn_not", btn_not);
31 refGlade->get_widget("main_menu_quit",main_menu_quit);
32 refGlade->get_widget("main_menu_new",main_menu_new);
33 refGlade->get_widget("main_menu_open",main_menu_open);
34 refGlade->get_widget("main_menu_save",main_menu_save);
35 refGlade->get_widget("edit_menu_del",edit_menu_del);
36 refGlade->get_widget("chk_btn_logica",chk_btn_logica);
37 refGlade->get_widget("file_open_selection",file_open_selection);
38 refGlade->get_widget("file_selection",file_selection);
39 refGlade->get_widget("combo_entry",combo_entry);
40 refGlade->get_widget("btn_check",btn_check);
41 refGlade->get_widget("dlg_connect", dlg_connect);
42 refGlade->get_widget("btn_dlg_close", btn_dlg_close);
43 refGlade->get_widget("dlg_label", dlg_label);
44 refGlade->get_widget("quick_btn_new", quick_btn_new);
45 refGlade->get_widget("quick_btn_save", quick_btn_save);
46 refGlade->get_widget("quick_btn_open", quick_btn_open);
47 refGlade->get_widget("edit_menu_delete_all", edit_menu_delete_all);
48 refGlade->get_widget("btn_find", btn_find);
50 refGlade->get_widget_derived("workplace", workplace); //fixed
53 listTargets.push_back( Gtk::TargetEntry("STRING") );
54 listTargets.push_back( Gtk::TargetEntry("text/plain") );
55 listTargets.push_back( Gtk::TargetEntry("POINTER") );
56 listTargets.push_back( Gtk::TargetEntry("application/pointer") );
58 btn_canio->drag_source_set(listTargets);
59 btn_y->drag_source_set(listTargets);
60 btn_codo->drag_source_set(listTargets);
61 btn_tanque->drag_source_set(listTargets);
62 btn_bomba->drag_source_set(listTargets);
63 btn_drain->drag_source_set(listTargets);
64 btn_exclusa->drag_source_set(listTargets);
65 btn_and->drag_source_set(listTargets);
66 btn_or->drag_source_set(listTargets);
67 btn_not->drag_source_set(listTargets);
69 btn_canio->signal_drag_data_get().connect( SigC::slot(*this, &Constructor::on_btn_canio_drag_get));
70 btn_bomba->signal_drag_data_get().connect( SigC::slot(*this, &Constructor::on_btn_bomba_drag_get));
71 btn_exclusa->signal_drag_data_get().connect( SigC::slot(*this, &Constructor::on_btn_exclusa_drag_get));
72 btn_y->signal_drag_data_get().connect( SigC::slot(*this, &Constructor::on_btn_y_drag_get));
73 btn_codo->signal_drag_data_get().connect( SigC::slot(*this, &Constructor::on_btn_codo_drag_get));
74 btn_tanque->signal_drag_data_get().connect( SigC::slot(*this, &Constructor::on_btn_tanque_drag_get));
75 btn_drain->signal_drag_data_get().connect( SigC::slot(*this, &Constructor::on_btn_drain_drag_get));
76 btn_and->signal_drag_data_get().connect( SigC::slot(*this, &Constructor::on_btn_and_drag_get));
77 btn_or->signal_drag_data_get().connect( SigC::slot(*this, &Constructor::on_btn_or_drag_get));
78 btn_not->signal_drag_data_get().connect( SigC::slot(*this, &Constructor::on_btn_not_drag_get));
79 btn_check->signal_clicked().connect(SigC::slot(*this,&Constructor::on_btn_check_clicked));
80 btn_dlg_close->signal_clicked().connect(SigC::slot(*this,&Constructor::on_btn_dlg_connect_clicked));
81 btn_find->signal_clicked().connect(SigC::slot(*this,&Constructor::on_btn_find_clicked));
82 chk_btn_logica->signal_clicked().connect(SigC::slot(*this, &Constructor::on_chk_btn_logica_clicked));
83 quick_btn_new->signal_clicked().connect(SigC::slot(*this, &Constructor::on_quick_btn_new_clicked));
84 quick_btn_save->signal_clicked().connect(SigC::slot(*this, &Constructor::on_quick_btn_save_clicked));
85 quick_btn_open->signal_clicked().connect(SigC::slot(*this, &Constructor::on_main_menu_open));
87 main_menu_quit->signal_activate().connect(SigC::slot(*this, &Constructor::on_main_menu_quit));
88 main_menu_new->signal_activate().connect(SigC::slot(*this, &Constructor::on_quick_btn_new_clicked));
89 main_menu_open->signal_activate().connect(SigC::slot(*this, &Constructor::on_main_menu_open));
90 main_menu_save->signal_activate().connect(SigC::slot(*this, &Constructor::on_main_menu_save));
91 edit_menu_del->signal_activate().connect(SigC::slot(*this,&Constructor::on_edit_menu_del));
92 edit_menu_delete_all->signal_activate().connect(SigC::slot(*this,&Constructor::on_quick_btn_delete_all_clicked));
94 btn_file_cancel = file_selection->get_cancel_button();
95 btn_file_ok = file_selection->get_ok_button();
96 btn_file_ok->signal_clicked().connect(SigC::slot(*this,&Constructor::on_btn_file_ok_clicked));
97 btn_file_cancel->signal_clicked().connect(SigC::slot(*this,&Constructor::on_btn_file_cancel_clicked));
99 btn_open_cancel = file_open_selection->get_cancel_button();
100 btn_open_ok = file_open_selection->get_ok_button();
101 btn_open_ok->signal_clicked().connect(SigC::slot(*this,&Constructor::on_load_from_xml));
102 btn_open_cancel->signal_clicked().connect(SigC::slot(*this,&Constructor::on_btn_open_cancel_clicked));
104 // Señales para cambiar el icono cuando empieza el drag.
105 btn_canio->signal_drag_begin().connect( SigC::slot(*this, &Constructor::on_canio_drag_begin));
106 btn_y->signal_drag_begin().connect( SigC::slot(*this, &Constructor::on_y_drag_begin));
107 btn_codo->signal_drag_begin().connect( SigC::slot(*this, &Constructor::on_codo_drag_begin));
108 btn_tanque->signal_drag_begin().connect( SigC::slot(*this, &Constructor::on_tanque_drag_begin));
109 btn_bomba->signal_drag_begin().connect( SigC::slot(*this, &Constructor::on_bomba_drag_begin));
110 btn_exclusa->signal_drag_begin().connect( SigC::slot(*this, &Constructor::on_exclusa_drag_begin));
111 btn_drain->signal_drag_begin().connect( SigC::slot(*this, &Constructor::on_drain_drag_begin));
112 btn_and->signal_drag_begin().connect( SigC::slot(*this, &Constructor::on_and_drag_begin));
113 btn_or->signal_drag_begin().connect( SigC::slot(*this, &Constructor::on_or_drag_begin));
114 btn_not->signal_drag_begin().connect( SigC::slot(*this, &Constructor::on_not_drag_begin));
115 workplace->drag_dest_set(listTargets);
116 workplace->signal_drag_data_received().connect( SigC::slot(*this, &Constructor::on_item_drop_drag_received) );
117 workplace->listaItems = &listaItems;
118 workplace->lista_logic_Items = &lista_logic_Items;
119 workplace->logica = &logica;
123 Constructor::~Constructor()
125 Constructor::on_edit_menu_delete_all();
128 void Constructor::on_btn_canio_drag_get(const Glib::RefPtr<Gdk::DragContext>& context, GtkSelectionData* selection_data, guint info, guint time)
130 gtk_selection_data_set (selection_data, selection_data->target, 8, (const guchar*)"canio_n.png", 12);
133 void Constructor::on_btn_y_drag_get(const Glib::RefPtr<Gdk::DragContext>& context, GtkSelectionData* selection_data, guint info, guint time)
135 gtk_selection_data_set(selection_data, selection_data->target, 8,(const guchar*)"y_n.png",8);
138 void Constructor::on_btn_codo_drag_get(const Glib::RefPtr<Gdk::DragContext>& context, GtkSelectionData* selection_data, guint info, guint time)
140 gtk_selection_data_set(selection_data, selection_data->target, 8 ,(const guchar*)"codo_o.png",10);
143 void Constructor::on_btn_tanque_drag_get(const Glib::RefPtr<Gdk::DragContext>& context, GtkSelectionData* selection_data, guint info, guint time)
145 gtk_selection_data_set(selection_data, selection_data->target, 8,(const guchar*)"tanque_e.png",12);
148 void Constructor::on_btn_bomba_drag_get(const Glib::RefPtr<Gdk::DragContext>& context, GtkSelectionData* selection_data, guint info, guint time)
150 gtk_selection_data_set(selection_data, selection_data->target, 8,(const guchar*)"bomba_e.png",11);
153 void Constructor::on_btn_exclusa_drag_get(const Glib::RefPtr<Gdk::DragContext>& context, GtkSelectionData* selection_data, guint info, guint time)
155 gtk_selection_data_set(selection_data, selection_data->target, 8,(const guchar*)"exclusa_h.png",13);
158 void Constructor::on_btn_drain_drag_get(const Glib::RefPtr<Gdk::DragContext>& context, GtkSelectionData* selection_data, guint info, guint time)
160 gtk_selection_data_set(selection_data, selection_data->target, 8,(const guchar*)"drain_n.png",11);
163 void Constructor::on_btn_and_drag_get(const Glib::RefPtr<Gdk::DragContext>& context, GtkSelectionData* selection_data, guint info, guint time)
165 gtk_selection_data_set(selection_data, selection_data->target, 8,(const guchar*)"and_e.png",9);
168 void Constructor::on_btn_or_drag_get(const Glib::RefPtr<Gdk::DragContext>& context, GtkSelectionData* selection_data, guint info, guint time)
170 gtk_selection_data_set(selection_data, selection_data->target, 8,(const guchar*)"or_e.png",8);
173 void Constructor::on_btn_not_drag_get(const Glib::RefPtr<Gdk::DragContext>& context, GtkSelectionData* selection_data, guint info, guint time)
175 gtk_selection_data_set(selection_data, selection_data->target, 8,(const guchar*)"not_e.png",9);
179 void Constructor::on_main_menu_quit()
186 void Constructor::on_main_menu_open()
188 // Conecto el boton OK para llamar al cargar del XML
189 file_open_selection->show();
192 void Constructor::on_main_menu_save()
194 // Conecto el boton OK para llamar al salvar
196 if ( ! check_connection(name) ) {
197 dlg_connect->set_title("Error");
198 dlg_label->set_text("El elemento "+name+" no esta conectado\n\t\tcorrectamente");
201 file_selection->show();
204 void Constructor::on_edit_menu_del()
206 workplace->delete_item(WorkPlace::pointed);
209 void Constructor::on_edit_menu_delete_all()
211 std::list<CItem *>::iterator i = listaItems.begin();
212 while ( i != listaItems.end() ) {
213 (*i)->workplace->delete_item((*i)->get_id());
214 i = listaItems.begin();
216 i = lista_logic_Items.begin();
217 while ( i != lista_logic_Items.end() ) {
218 (*i)->workplace->delete_item((*i)->get_id());
219 i=lista_logic_Items.begin();
222 list_pointed.clear();
223 list_pointed.push_back(" ");
224 combo_entry->set_popdown_strings(list_pointed);
225 combo_entry->get_entry()->set_text("");
228 void Constructor::on_chk_btn_logica_clicked()
231 CItem::logic_connect = !CItem::logic_connect;
232 workplace->queue_draw();
235 void Constructor::on_load_from_xml()
237 on_edit_menu_delete_all();
238 file_name = file_open_selection->get_filename();
240 /* Parseo de ejemplo de un XML desde archivo */
242 document = xmlParseFile(file_name.c_str());
243 if (document == NULL) {
244 // TODO : dar un aviso de que no se pudo abrir el archivo!!
248 /* bien, el archivo se parseo bien! */
249 xmlNodePtr nodo, items;
250 nodo = document->children;
254 if (strcmp((char *)nodo->name, "planta") == 0) {
255 items = nodo->children;
256 while (items != NULL) {
258 if (items->type == XML_ELEMENT_NODE) {
259 std::cout << "ITEM" << std::endl;
260 if (xmlStrcmp(items->name, BAD_CAST"bomba")==0) {
261 current = loadBomba(items);
262 } else if (xmlStrcmp(items->name, BAD_CAST"tubo")==0) {
263 current = loadConduct(items);
264 } else if (xmlStrcmp(items->name, BAD_CAST"codo")==0) {
265 current = loadCodo(items);
266 } else if (xmlStrcmp(items->name, BAD_CAST"exclusa")==0) {
267 current = loadExclusa(items);
268 } else if (xmlStrcmp(items->name, BAD_CAST"tanque")==0) {
269 current = loadTank(items);
270 } else if (xmlStrcmp(items->name, BAD_CAST"empalme")==0) {
271 current = loadUnion(items);
272 } else if (xmlStrcmp(items->name, BAD_CAST"drenaje")==0) {
273 current = loadDrain(items);
276 if (current != NULL) {
277 // Agrego y conecto la bomba
278 listaItems.push_back(current);
279 current->drag_source_set(listTargets);
280 workplace->put(*current, current->get_position_x(), current->get_position_y());
281 //Apunto al workplace
282 current->workplace= workplace;
284 current->combo_entry = combo_entry;
285 //Apunto a la lista de apuntados
286 current->list_pointed = &list_pointed;
287 //Apunto a la listaItems.
288 current->listaItems = &listaItems;
289 //Apunto a la lista de items logicos
290 current->lista_logic_Items = &lista_logic_Items;
291 // Conecto las señales
292 current->signal_drag_data_get().connect( SigC::slot(*this, &Constructor::on_item_drag_data_get));
293 current->signal_drag_begin().connect(SigC::bind( SigC::slot(*this, &Constructor::on_item_drag_begin), current));
299 xmlFreeDoc(document);
301 // TODO : avisar que el XML no es valido!!
303 std::cout << "CARGA COMPLETA" << std::endl;
304 file_open_selection->hide();
305 id = listaItems.size()+lista_logic_Items.size()+1;
308 void Constructor::on_btn_file_ok_clicked()
310 std::list<CItem *>::iterator i = listaItems.begin();
311 file_name = file_selection->get_filename();
313 if ( (archivo = fopen( file_name.c_str(), "w+")) != NULL ){
314 fprintf(archivo, "<?xml version=\"1.0\" encoding=\"iso-8859-1\" ?>\n");
315 fprintf (archivo,"<planta>\n");
316 while ( i != listaItems.end() ){
320 i = lista_logic_Items.begin();
321 while ( i != lista_logic_Items.end() ) {
325 fprintf(archivo,"</planta>\n");
329 std::cout<<"NO SE ABRIO EL ARCHIVO"<<std::endl;
330 file_selection->hide();
333 void Constructor::on_quick_btn_save_clicked()
338 on_btn_file_ok_clicked();
342 void Constructor::on_quick_btn_new_clicked()
344 on_quick_btn_delete_all_clicked();
348 void Constructor::on_quick_btn_delete_all_clicked()
350 on_edit_menu_delete_all();
353 void Constructor::on_btn_find_clicked()
356 std::list<CItem *>::iterator i = listaItems.begin();
357 while ( i !=listaItems.end() ) {
358 if ( (*i)->get_name() == combo_entry->get_entry()->get_text() ) {
365 i = lista_logic_Items.begin();
366 while ( i !=lista_logic_Items.end() ) {
367 if ( (*i)->get_name() == combo_entry->get_entry()->get_text() ) {
374 workplace->get_window()->draw_rectangle(workplace->get_style()->get_black_gc(), false , temp->get_position_x()-5, temp->get_position_y()-5,
375 temp->get_image()->get_width()+10, temp->get_image()->get_height()+10);
378 void Constructor::on_btn_file_cancel_clicked()
380 file_selection->hide();
383 void Constructor::on_btn_open_cancel_clicked()
385 file_open_selection->hide();
388 void Constructor::on_btn_dlg_connect_clicked()
393 void Constructor::on_canio_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)
395 context->set_icon(ico_canio, 5, 5);
398 void Constructor::on_y_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)
400 context->set_icon(ico_y, 5, 5);
403 void Constructor::on_codo_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)
405 context->set_icon(ico_codo, 5, 5);
408 void Constructor::on_tanque_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)
410 context->set_icon(ico_tanque, 5, 5);
413 void Constructor::on_bomba_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)
415 context->set_icon(ico_bomba, 5, 5);
418 void Constructor::on_exclusa_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)
420 context->set_icon(ico_exclusa, 5, 5);
423 void Constructor::on_drain_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)
425 context->set_icon(ico_drain, 5, 5);
428 void Constructor::on_and_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)
430 context->set_icon(ico_and, 5, 5);
433 void Constructor::on_or_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)
435 context->set_icon(ico_or, 5, 5);
438 void Constructor::on_not_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)
440 context->set_icon(ico_not, 5, 5);
443 void Constructor::on_item_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context, CItem *item)
445 context->set_icon(item->get_image(), 5, 5);
448 void Constructor::on_item_drag_data_get(const Glib::RefPtr<Gdk::DragContext>& context, GtkSelectionData* selection_data, guint info, guint time)
450 gtk_selection_data_set (selection_data, selection_data->target, 10, (const guchar*)"item_codo.png", 13);
453 bool Constructor::can_drop(CItem *item, int _x, int _y)
455 std::list<CItem*>::iterator i = listaItems.begin();
456 while( i != listaItems.end() ) {
458 if ( temp->get_id() != item->get_id() ) {
459 if ( (temp->is_occupied_area(_x, _y)) ||
460 ( temp->is_occupied_area(_x+item->get_image()->get_width()-1, _y+item->get_image()->get_height()-1)) ||
461 ( temp->is_occupied_area(_x, _y+item->get_image()->get_height()-1)) ||
462 ( temp->is_occupied_area(_x+item->get_image()->get_width()-1, _y) ) )
471 void Constructor::on_item_drop_drag_received(const Glib::RefPtr<Gdk::DragContext>& context, int x, int y, GtkSelectionData* selection_data, guint info, guint time)
473 workplace->update_logic_position();
474 workplace->queue_draw();
476 /* Ajusto coordenada x e y para que caigan en un lugar de una cuadricula de 32x32 */
478 // el +1 es para evitar un bug cuando se selecciona muy cerce de la
479 // separacion de 2 cuadritos
482 // El drag es de un item
483 if (selection_data->format == 10) {
484 if (can_drop(((CItem*)drag_get_source_widget(context)),i*32, j*32)){
485 ((CItem*)drag_get_source_widget(context))->set_position(i*32, j*32);
486 workplace->move(*drag_get_source_widget(context), i*32, j*32);
490 // El Drag es desde la barra de tareas
491 if ((selection_data->length >= 0) && (selection_data->format == 8)) {
493 if (strcmp((const char *)selection_data->data, "codo_o.png")==0)
495 else if (strcmp((const char *)selection_data->data, "canio_n.png")==0)
497 else if (strcmp((const char *)selection_data->data, "y_n.png")==0)
499 else if (strcmp((const char *)selection_data->data, "tanque_e.png")==0)
501 else if (strcmp((const char *)selection_data->data, "bomba_e.png")==0)
503 else if (strcmp((const char *)selection_data->data, "exclusa_h.png")==0)
505 else if (strcmp((const char *)selection_data->data, "drain_n.png")==0)
507 else if (strcmp((const char *)selection_data->data, "and_e.png")==0){
508 a = new And(); a->is_logic = true;
509 } else if (strcmp((const char *)selection_data->data, "or_e.png")==0) {
510 a = new Or(); a->is_logic = true;
511 } else if (strcmp((const char *)selection_data->data, "not_e.png")==0) {
512 a = new Not(); a->is_logic = true;
516 sprintf(char_id,"%d",id);
518 a->set_name( a->get_name()+char_id );
519 if ( can_drop(a, i*32, j*32) ) {
520 workplace->put(*a, i*32, j*32);
521 //Apunto al workplace
522 a->workplace = workplace;
524 a->combo_entry = combo_entry;
525 //Apunto a la lista de apuntados
526 a->list_pointed = &list_pointed;
527 //Apunto a la listaItems.
528 a->listaItems = &listaItems;
529 //Apunto a la lista de items logicos
530 a->lista_logic_Items = &lista_logic_Items;
531 //Seteo la posicion del item
532 a->set_position(i*32,j*32);
533 // Seteo la lista de tipos de drags
534 a->drag_source_set(listTargets);
535 // Conecto las señales
536 a->signal_drag_data_get().connect( SigC::slot(*this, &Constructor::on_item_drag_data_get));
537 // Utilizo el SigC::bind para que el callback on_drag_begin acepte un
538 // parametro extra, en este caso un CItem *. Esto se hace para
539 // que cuando el usuario quiera mover un item, saber que item es
540 // y pedirle su ícono para mostrar cono icono durante la operacion,
541 // Esto va a permitir, que si un widget tiene una imagen rotara o algo
542 // raro se vea el widget tal cual.
543 a->signal_drag_begin().connect(SigC::bind( SigC::slot(*this, &Constructor::on_item_drag_begin), a));
546 listaItems.push_back(a);
548 lista_logic_Items.push_back(a);
554 context->drag_finish(false, false, time);
556 workplace->update_logic_position();
557 workplace->queue_draw();
560 void Constructor::on_btn_check_clicked()
563 if ( ! check_connection(name) ) {
564 dlg_connect->set_title("Error");
565 dlg_label->set_text("El elemento "+name+" no esta conectado\n\t\tcorrectamente");
568 dlg_connect->set_title("Conexion");
569 dlg_label->set_text("Los elementos estan conectados\n\t\tcorrectamente");
575 bool Constructor::check_connection(Glib::ustring& name)
577 std::list<CItem *>::iterator i = listaItems.begin();
578 while ( i != listaItems.end() ){
579 (*i)->set_default_connector();
580 (*i)->is_connected = false;
583 i = listaItems.begin();
584 if ( !listaItems.empty() ) {
585 while ( i != listaItems.end() ) {
587 std::cout<< "item="<<temp->get_name()<<" "<<"check= "<<temp->check_connection()<<std::endl;
588 if ( !temp->check_connection() ) {
589 name = temp->get_name();
595 std::cout<<"check_connection logic"<<std::endl;
596 std::list<CItem *>::iterator j = lista_logic_Items.begin();
597 while ( j != lista_logic_Items.end() ) {
598 if ( !(*j)->check_connection() ) {
599 name = (*j)->get_name();
607 Pump *Constructor::loadBomba(xmlNodePtr nodo)
609 std::string name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
610 std::string id = (char *)xmlGetProp(nodo, BAD_CAST"id");
611 int orientacion=0, x, y;
614 nodo = nodo->children;
615 while (nodo != NULL) {
616 if (nodo->type == XML_ELEMENT_NODE) {
617 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
618 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
619 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
620 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
621 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
622 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
623 } else if (xmlStrcmp(nodo->name, BAD_CAST"entrega") == 0) {
624 flujo = atof( (char *)XML_GET_CONTENT(nodo->children) );
625 } else if (xmlStrcmp(nodo->name, BAD_CAST"color") == 0) {
632 Pump *p = new Pump(orientacion);
633 p->set_position(x,y);
634 p->set_entrega(flujo);
635 p->set_id( atoi(id.c_str()) );
641 Conduct *Constructor::loadConduct(xmlNodePtr nodo)
643 std::string name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
644 std::string id = (char *)xmlGetProp(nodo, BAD_CAST"id");
645 int orientacion=0, x, y;
648 nodo = nodo->children;
649 while (nodo != NULL) {
650 if (nodo->type == XML_ELEMENT_NODE) {
651 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
652 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
653 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
654 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
655 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
656 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
657 } else if (xmlStrcmp(nodo->name, BAD_CAST"caudal") == 0) {
658 flujo = atof( (char *)XML_GET_CONTENT(nodo->children) );
664 Conduct *p = new Conduct(orientacion);
665 p->set_position(x,y);
666 p->set_caudal(flujo);
667 p->set_id( atoi(id.c_str()) );
673 Exclusa *Constructor::loadExclusa(xmlNodePtr nodo)
675 std::string name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
676 std::string id = (char *)xmlGetProp(nodo, BAD_CAST"id");
678 int orientacion=0, x, y;
681 nodo = nodo->children;
682 while (nodo != NULL) {
683 if (nodo->type == XML_ELEMENT_NODE) {
684 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
685 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
686 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
687 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
688 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
689 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
690 } else if (xmlStrcmp(nodo->name, BAD_CAST"estado") == 0) {
691 estado = (char *)XML_GET_CONTENT(nodo->children);
697 Exclusa *p = new Exclusa(orientacion);
698 p->set_position(x,y);
699 p->set_id( atoi(id.c_str()) );
701 p->set_estado( estado == "1" );
706 Cistern *Constructor::loadTank(xmlNodePtr nodo)
708 std::string name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
709 std::string id = (char *)xmlGetProp(nodo, BAD_CAST"id");
710 int orientacion=0, x, y;
711 float liquido,capacidad;
713 nodo = nodo->children;
714 while (nodo != NULL) {
715 if (nodo->type == XML_ELEMENT_NODE) {
716 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
717 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
718 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
719 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
720 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
721 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
722 } else if (xmlStrcmp(nodo->name, BAD_CAST"capacidad") == 0) {
723 capacidad = atof ((char *)XML_GET_CONTENT(nodo->children) );
724 } else if (xmlStrcmp(nodo->name, BAD_CAST"inicial") == 0) {
725 liquido = atof ((char *)XML_GET_CONTENT(nodo->children) );
731 Cistern *p = new Cistern(orientacion);
732 p->set_position(x,y);
733 p->set_id( atoi(id.c_str()) );
735 p->set_capacidad(capacidad);
736 p->set_contenido_inicial(liquido);
741 Union *Constructor::loadUnion(xmlNodePtr nodo)
743 std::string name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
744 std::string id = (char *)xmlGetProp(nodo, BAD_CAST"id");
746 int orientacion=0, x, y;
749 nodo = nodo->children;
750 while (nodo != NULL) {
751 if (nodo->type == XML_ELEMENT_NODE) {
752 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
753 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
754 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
755 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
756 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
757 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
758 } else if (xmlStrcmp(nodo->name, BAD_CAST"caudal") == 0) {
759 caudal = atof ((char *)XML_GET_CONTENT(nodo->children) );
760 } else if (xmlStrcmp(nodo->name, BAD_CAST"tipo") == 0) {
761 tipo = (char *)XML_GET_CONTENT(nodo->children);
767 Union *p = new Union(orientacion);
768 p->set_position(x,y);
769 p->set_id( atoi(id.c_str()) );
771 p->set_caudal(caudal);
772 p->is_union = (tipo == "union");
777 Drain *Constructor::loadDrain(xmlNodePtr nodo)
779 std::string name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
780 std::string id = (char *)xmlGetProp(nodo, BAD_CAST"id");
781 int orientacion=0, x, y;
783 nodo = nodo->children;
784 while (nodo != NULL) {
785 if (nodo->type == XML_ELEMENT_NODE) {
786 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
787 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
788 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
789 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
790 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
791 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
797 Drain *p = new Drain(orientacion);
798 p->set_position(x,y);
799 p->set_id( atoi(id.c_str()) );
805 Splitter *Constructor::loadCodo(xmlNodePtr nodo)
807 std::string name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
808 std::string id = (char *)xmlGetProp(nodo, BAD_CAST"id");
809 int orientacion=0, x, y;
812 nodo = nodo->children;
813 while (nodo != NULL) {
814 if (nodo->type == XML_ELEMENT_NODE) {
815 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
816 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
817 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
818 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
819 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
820 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
821 } else if (xmlStrcmp(nodo->name, BAD_CAST"caudal") == 0) {
822 caudal = atof( (char *)XML_GET_CONTENT(nodo->children) );
828 Splitter *p = new Splitter(orientacion);
829 p->set_position(x,y);
830 p->set_id( atoi(id.c_str()) );
832 p->set_caudal(caudal);