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);
49 refGlade->get_widget_derived("workplace", workplace); //fixed
52 listTargets.push_back( Gtk::TargetEntry("STRING") );
53 listTargets.push_back( Gtk::TargetEntry("text/plain") );
54 listTargets.push_back( Gtk::TargetEntry("POINTER") );
55 listTargets.push_back( Gtk::TargetEntry("application/pointer") );
57 btn_canio->drag_source_set(listTargets);
58 btn_y->drag_source_set(listTargets);
59 btn_codo->drag_source_set(listTargets);
60 btn_tanque->drag_source_set(listTargets);
61 btn_bomba->drag_source_set(listTargets);
62 btn_drain->drag_source_set(listTargets);
63 btn_exclusa->drag_source_set(listTargets);
64 btn_and->drag_source_set(listTargets);
65 btn_or->drag_source_set(listTargets);
66 btn_not->drag_source_set(listTargets);
68 btn_canio->signal_drag_data_get().connect( SigC::slot(*this, &Constructor::on_btn_canio_drag_get));
69 btn_bomba->signal_drag_data_get().connect( SigC::slot(*this, &Constructor::on_btn_bomba_drag_get));
70 btn_exclusa->signal_drag_data_get().connect( SigC::slot(*this, &Constructor::on_btn_exclusa_drag_get));
71 btn_y->signal_drag_data_get().connect( SigC::slot(*this, &Constructor::on_btn_y_drag_get));
72 btn_codo->signal_drag_data_get().connect( SigC::slot(*this, &Constructor::on_btn_codo_drag_get));
73 btn_tanque->signal_drag_data_get().connect( SigC::slot(*this, &Constructor::on_btn_tanque_drag_get));
74 btn_drain->signal_drag_data_get().connect( SigC::slot(*this, &Constructor::on_btn_drain_drag_get));
75 btn_and->signal_drag_data_get().connect( SigC::slot(*this, &Constructor::on_btn_and_drag_get));
76 btn_or->signal_drag_data_get().connect( SigC::slot(*this, &Constructor::on_btn_or_drag_get));
77 btn_not->signal_drag_data_get().connect( SigC::slot(*this, &Constructor::on_btn_not_drag_get));
78 btn_check->signal_clicked().connect(SigC::slot(*this,&Constructor::on_btn_check_clicked));
79 btn_dlg_close->signal_clicked().connect(SigC::slot(*this,&Constructor::on_btn_dlg_connect_clicked));
80 chk_btn_logica->signal_clicked().connect(SigC::slot(*this, &Constructor::on_chk_btn_clicked));
81 quick_btn_new->signal_clicked().connect(SigC::slot(*this, &Constructor::on_quick_btn_new_clicked));
82 quick_btn_save->signal_clicked().connect(SigC::slot(*this, &Constructor::on_quick_btn_save_clicked));
83 quick_btn_open->signal_clicked().connect(SigC::slot(*this, &Constructor::on_main_menu_open));
85 main_menu_quit->signal_activate().connect(SigC::slot(*this, &Constructor::on_main_menu_quit));
86 main_menu_new->signal_activate().connect(SigC::slot(*this, &Constructor::on_quick_btn_new_clicked));
87 main_menu_open->signal_activate().connect(SigC::slot(*this, &Constructor::on_main_menu_open));
88 main_menu_save->signal_activate().connect(SigC::slot(*this, &Constructor::on_main_menu_save));
89 edit_menu_del->signal_activate().connect(SigC::slot(*this,&Constructor::on_edit_menu_del));
90 edit_menu_delete_all->signal_activate().connect(SigC::slot(*this,&Constructor::on_quick_btn_delete_all_clicked));
92 btn_file_cancel = file_selection->get_cancel_button();
93 btn_file_ok = file_selection->get_ok_button();
94 btn_file_ok->signal_clicked().connect(SigC::slot(*this,&Constructor::on_btn_file_ok_clicked));
95 btn_file_cancel->signal_clicked().connect(SigC::slot(*this,&Constructor::on_btn_file_cancel_clicked));
97 btn_open_cancel = file_open_selection->get_cancel_button();
98 btn_open_ok = file_open_selection->get_ok_button();
99 btn_open_ok->signal_clicked().connect(SigC::slot(*this,&Constructor::on_load_from_xml));
100 btn_open_cancel->signal_clicked().connect(SigC::slot(*this,&Constructor::on_btn_open_cancel_clicked));
102 // Señales para cambiar el icono cuando empieza el drag.
103 btn_canio->signal_drag_begin().connect( SigC::slot(*this, &Constructor::on_canio_drag_begin));
104 btn_y->signal_drag_begin().connect( SigC::slot(*this, &Constructor::on_y_drag_begin));
105 btn_codo->signal_drag_begin().connect( SigC::slot(*this, &Constructor::on_codo_drag_begin));
106 btn_tanque->signal_drag_begin().connect( SigC::slot(*this, &Constructor::on_tanque_drag_begin));
107 btn_bomba->signal_drag_begin().connect( SigC::slot(*this, &Constructor::on_bomba_drag_begin));
108 btn_exclusa->signal_drag_begin().connect( SigC::slot(*this, &Constructor::on_exclusa_drag_begin));
109 btn_drain->signal_drag_begin().connect( SigC::slot(*this, &Constructor::on_drain_drag_begin));
110 btn_and->signal_drag_begin().connect( SigC::slot(*this, &Constructor::on_and_drag_begin));
111 btn_or->signal_drag_begin().connect( SigC::slot(*this, &Constructor::on_or_drag_begin));
112 btn_not->signal_drag_begin().connect( SigC::slot(*this, &Constructor::on_not_drag_begin));
113 workplace->drag_dest_set(listTargets);
114 workplace->signal_drag_data_received().connect( SigC::slot(*this, &Constructor::on_item_drop_drag_received) );
115 workplace->listaItems = &listaItems;
116 workplace->lista_logic_Items = &lista_logic_Items;
120 Constructor::~Constructor()
122 Constructor::on_edit_menu_delete_all();
125 void Constructor::on_btn_canio_drag_get(const Glib::RefPtr<Gdk::DragContext>& context, GtkSelectionData* selection_data, guint info, guint time)
127 gtk_selection_data_set (selection_data, selection_data->target, 8, (const guchar*)"canio_n.png", 12);
130 void Constructor::on_btn_y_drag_get(const Glib::RefPtr<Gdk::DragContext>& context, GtkSelectionData* selection_data, guint info, guint time)
132 gtk_selection_data_set(selection_data, selection_data->target, 8,(const guchar*)"y_n.png",8);
135 void Constructor::on_btn_codo_drag_get(const Glib::RefPtr<Gdk::DragContext>& context, GtkSelectionData* selection_data, guint info, guint time)
137 gtk_selection_data_set(selection_data, selection_data->target, 8 ,(const guchar*)"codo_o.png",10);
140 void Constructor::on_btn_tanque_drag_get(const Glib::RefPtr<Gdk::DragContext>& context, GtkSelectionData* selection_data, guint info, guint time)
142 gtk_selection_data_set(selection_data, selection_data->target, 8,(const guchar*)"tanque_e.png",12);
145 void Constructor::on_btn_bomba_drag_get(const Glib::RefPtr<Gdk::DragContext>& context, GtkSelectionData* selection_data, guint info, guint time)
147 gtk_selection_data_set(selection_data, selection_data->target, 8,(const guchar*)"bomba_e.png",11);
150 void Constructor::on_btn_exclusa_drag_get(const Glib::RefPtr<Gdk::DragContext>& context, GtkSelectionData* selection_data, guint info, guint time)
152 gtk_selection_data_set(selection_data, selection_data->target, 8,(const guchar*)"exclusa_h.png",13);
155 void Constructor::on_btn_drain_drag_get(const Glib::RefPtr<Gdk::DragContext>& context, GtkSelectionData* selection_data, guint info, guint time)
157 gtk_selection_data_set(selection_data, selection_data->target, 8,(const guchar*)"drain_n.png",11);
160 void Constructor::on_btn_and_drag_get(const Glib::RefPtr<Gdk::DragContext>& context, GtkSelectionData* selection_data, guint info, guint time)
162 gtk_selection_data_set(selection_data, selection_data->target, 8,(const guchar*)"and_e.png",9);
165 void Constructor::on_btn_or_drag_get(const Glib::RefPtr<Gdk::DragContext>& context, GtkSelectionData* selection_data, guint info, guint time)
167 gtk_selection_data_set(selection_data, selection_data->target, 8,(const guchar*)"or_e.png",8);
170 void Constructor::on_btn_not_drag_get(const Glib::RefPtr<Gdk::DragContext>& context, GtkSelectionData* selection_data, guint info, guint time)
172 gtk_selection_data_set(selection_data, selection_data->target, 8,(const guchar*)"not_e.png",9);
176 void Constructor::on_main_menu_quit()
183 void Constructor::on_main_menu_open()
185 // Conecto el boton OK para llamar al cargar del XML
186 file_open_selection->show();
189 void Constructor::on_main_menu_save()
191 // Conecto el boton OK para llamar al salvar
192 file_selection->show();
195 void Constructor::on_edit_menu_del()
197 workplace->delete_item(WorkPlace::pointed);
200 void Constructor::on_edit_menu_delete_all()
202 std::list<CItem *>::iterator i = listaItems.begin();
203 while ( i != listaItems.end() ) {
204 (*i)->workplace->delete_item((*i)->get_id());
205 i = listaItems.begin();
207 i = lista_logic_Items.begin();
208 while ( i != lista_logic_Items.end() ) {
209 (*i)->workplace->delete_item((*i)->get_id());
210 i=lista_logic_Items.begin();
215 void Constructor::on_chk_btn_clicked()
218 CItem::logic_connect = !CItem::logic_connect;
221 void Constructor::on_load_from_xml()
223 on_edit_menu_delete_all();
224 file_name = file_open_selection->get_filename();
226 /* Parseo de ejemplo de un XML desde archivo */
228 document = xmlParseFile(file_name.c_str());
229 if (document == NULL) {
230 // TODO : dar un aviso de que no se pudo abrir el archivo!!
234 /* bien, el archivo se parseo bien! */
235 xmlNodePtr nodo, items;
236 nodo = document->children;
240 if (strcmp((char *)nodo->name, "planta") == 0) {
241 items = nodo->children;
242 while (items != NULL) {
244 if (items->type == XML_ELEMENT_NODE) {
245 std::cout << "ITEM" << std::endl;
246 if (xmlStrcmp(items->name, BAD_CAST"bomba")==0) {
247 current = loadBomba(items);
248 } else if (xmlStrcmp(items->name, BAD_CAST"tubo")==0) {
249 current = loadConduct(items);
250 } else if (xmlStrcmp(items->name, BAD_CAST"codo")==0) {
251 current = loadCodo(items);
252 } else if (xmlStrcmp(items->name, BAD_CAST"exclusa")==0) {
253 current = loadExclusa(items);
254 } else if (xmlStrcmp(items->name, BAD_CAST"tanque")==0) {
255 current = loadTank(items);
256 } else if (xmlStrcmp(items->name, BAD_CAST"empalme")==0) {
257 current = loadUnion(items);
258 } else if (xmlStrcmp(items->name, BAD_CAST"drenaje")==0) {
259 current = loadDrain(items);
262 if (current != NULL) {
263 // Agrego y conecto la bomba
264 listaItems.push_back(current);
265 current->drag_source_set(listTargets);
266 workplace->put(*current, current->get_position_x(), current->get_position_y());
267 //Apunto al workplace
268 current->workplace= workplace;
270 current->combo_entry = combo_entry;
271 //Apunto a la listaItems.
272 current->listaItems = &listaItems;
273 //Apunto a la lista de items logicos
274 current->lista_logic_Items = &lista_logic_Items;
275 // Conecto las señales
276 current->signal_drag_data_get().connect( SigC::slot(*this, &Constructor::on_item_drag_data_get));
277 current->signal_drag_begin().connect(SigC::bind( SigC::slot(*this, &Constructor::on_item_drag_begin), current));
284 // TODO : avisar que el XML no es valido!!
286 std::cout << "CARGA COMPLETA" << std::endl;
287 file_open_selection->hide();
288 id = listaItems.size()+lista_logic_Items.size()+1;
291 void Constructor::on_btn_file_ok_clicked()
293 std::list<CItem *>::iterator i = listaItems.begin();
294 file_name = file_selection->get_filename();
295 if ( (archivo = fopen( file_name.c_str(), "w+")) != NULL ){
296 fprintf(archivo, "<?xml version=\"1.0\" encoding=\"iso-8859-1\" ?>\n");
297 fprintf (archivo,"<planta>\n");
298 while ( i != listaItems.end() ){
302 i = lista_logic_Items.begin();
303 while ( i != lista_logic_Items.end() ) {
307 fprintf(archivo,"</planta>\n");
310 std::cout<<"NO SE ABRIO EL ARCHIVO"<<std::endl;
312 file_selection->hide();
315 void Constructor::on_quick_btn_save_clicked()
320 on_btn_file_ok_clicked();
324 void Constructor::on_quick_btn_new_clicked()
326 on_quick_btn_delete_all_clicked();
330 void Constructor::on_quick_btn_delete_all_clicked()
332 std::list<CItem *>::iterator i = listaItems.begin();
333 while ( i != listaItems.end() ){
337 i = listaItems.begin();
339 i = lista_logic_Items.begin();
340 while ( i != lista_logic_Items.end() ){
342 lista_logic_Items.erase(i);
344 i = lista_logic_Items.begin();
349 void Constructor::on_btn_file_cancel_clicked()
351 file_selection->hide();
354 void Constructor::on_btn_open_cancel_clicked()
356 file_open_selection->hide();
359 void Constructor::on_btn_dlg_connect_clicked()
364 void Constructor::on_canio_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)
366 context->set_icon(ico_canio, 5, 5);
369 void Constructor::on_y_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)
371 context->set_icon(ico_y, 5, 5);
374 void Constructor::on_codo_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)
376 context->set_icon(ico_codo, 5, 5);
379 void Constructor::on_tanque_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)
381 context->set_icon(ico_tanque, 5, 5);
384 void Constructor::on_bomba_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)
386 context->set_icon(ico_bomba, 5, 5);
389 void Constructor::on_exclusa_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)
391 context->set_icon(ico_exclusa, 5, 5);
394 void Constructor::on_drain_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)
396 context->set_icon(ico_drain, 5, 5);
399 void Constructor::on_and_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)
401 context->set_icon(ico_and, 5, 5);
404 void Constructor::on_or_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)
406 context->set_icon(ico_or, 5, 5);
409 void Constructor::on_not_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)
411 context->set_icon(ico_not, 5, 5);
414 void Constructor::on_item_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context, CItem *item)
416 context->set_icon(item->get_image(), 5, 5);
419 void Constructor::on_item_drag_data_get(const Glib::RefPtr<Gdk::DragContext>& context, GtkSelectionData* selection_data, guint info, guint time)
421 gtk_selection_data_set (selection_data, selection_data->target, 10, (const guchar*)"item_codo.png", 13);
424 bool Constructor::can_drop(CItem *item, int _x, int _y)
426 std::list<CItem*>::iterator i = listaItems.begin();
427 while( i != listaItems.end() ) {
429 if ( temp->get_id() != item->get_id() ) {
430 if ( (temp->is_occupied_area(_x, _y)) ||
431 ( temp->is_occupied_area(_x+item->get_image()->get_width()-1, _y+item->get_image()->get_height()-1)) ||
432 ( temp->is_occupied_area(_x, _y+item->get_image()->get_height()-1)) ||
433 ( temp->is_occupied_area(_x+item->get_image()->get_width()-1, _y) ) )
442 void Constructor::on_item_drop_drag_received(const Glib::RefPtr<Gdk::DragContext>& context, int x, int y, GtkSelectionData* selection_data, guint info, guint time)
444 workplace->update_logic_position();
445 workplace->queue_draw();
447 /* Ajusto coordenada x e y para que caigan en un lugar de una cuadricula de 32x32 */
449 // el +1 es para evitar un bug cuando se selecciona muy cerce de la
450 // separacion de 2 cuadritos
453 // El drag es de un item
454 if (selection_data->format == 10) {
455 if (can_drop(((CItem*)drag_get_source_widget(context)),i*32, j*32)){
456 ((CItem*)drag_get_source_widget(context))->set_position(i*32, j*32);
457 workplace->move(*drag_get_source_widget(context), i*32, j*32);
461 // El Drag es desde la barra de tareas
462 if ((selection_data->length >= 0) && (selection_data->format == 8)) {
464 if (strcmp((const char *)selection_data->data, "codo_o.png")==0)
466 else if (strcmp((const char *)selection_data->data, "canio_n.png")==0)
468 else if (strcmp((const char *)selection_data->data, "y_n.png")==0)
470 else if (strcmp((const char *)selection_data->data, "tanque_e.png")==0)
472 else if (strcmp((const char *)selection_data->data, "bomba_e.png")==0)
474 else if (strcmp((const char *)selection_data->data, "exclusa_h.png")==0)
476 else if (strcmp((const char *)selection_data->data, "drain_n.png")==0)
478 else if (strcmp((const char *)selection_data->data, "and_e.png")==0){
479 a = new And(); a->is_logic = true;
480 } else if (strcmp((const char *)selection_data->data, "or_e.png")==0) {
481 a = new Or(); a->is_logic = true;
482 } else if (strcmp((const char *)selection_data->data, "not_e.png")==0) {
483 a = new Not(); a->is_logic = true;
487 sprintf(char_id,"%d",id);
489 a->set_name( a->get_name()+char_id );
490 if ( can_drop(a, i*32, j*32) ) {
491 workplace->put(*a, i*32, j*32);
492 //Apunto al workplace
493 a->workplace= workplace;
495 a->combo_entry = combo_entry;
496 //Apunto a la listaItems.
497 a->listaItems = &listaItems;
498 //Apunto a la lista de items logicos
499 a->lista_logic_Items = &lista_logic_Items;
500 //Seteo la posicion del item
501 a->set_position(i*32,j*32);
502 // Seteo la lista de tipos de drags
503 a->drag_source_set(listTargets);
504 // Conecto las señales
505 a->signal_drag_data_get().connect( SigC::slot(*this, &Constructor::on_item_drag_data_get));
506 // Utilizo el SigC::bind para que el callback on_drag_begin acepte un
507 // parametro extra, en este caso un CItem *. Esto se hace para
508 // que cuando el usuario quiera mover un item, saber que item es
509 // y pedirle su ícono para mostrar cono icono durante la operacion,
510 // Esto va a permitir, que si un widget tiene una imagen rotara o algo
511 // raro se vea el widget tal cual.
512 a->signal_drag_begin().connect(SigC::bind( SigC::slot(*this, &Constructor::on_item_drag_begin), a));
515 listaItems.push_back(a);
517 lista_logic_Items.push_back(a);
523 context->drag_finish(false, false, time);
525 workplace->update_logic_position();
526 workplace->queue_draw();
529 void Constructor::on_btn_check_clicked()
531 std::list<CItem *>::iterator i = listaItems.begin();
532 while ( i != listaItems.end() ){
533 (*i)->set_default_connector();
534 (*i)->is_connected = false;
538 i = listaItems.begin();
539 if ( !listaItems.empty() ) {
540 while ( i != listaItems.end() ) {
542 std::cout<< "item="<<temp->get_name()<<" "<<"check= "<<temp->check_connection()<<std::endl;
543 if ( !temp->check_connection() ) {
544 dlg_connect->set_title("Error");
545 dlg_label->set_text("El elemento "+temp->get_name()+" no esta conectado\n\t\tcorrectamente");
551 dlg_connect->set_title("Conexion");
552 dlg_label->set_text("Los elementos estan conectados\n\t\tcorrectamente");
555 std::cout<<"check_connection logic"<<std::endl;
556 std::list<CItem *>::iterator j = lista_logic_Items.begin();
557 while ( j != lista_logic_Items.end() ) {
558 (*j)->check_connection();
565 Pump *Constructor::loadBomba(xmlNodePtr nodo)
567 std::string name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
568 std::string id = (char *)xmlGetProp(nodo, BAD_CAST"id");
569 int orientacion=0, x, y;
572 nodo = nodo->children;
573 while (nodo != NULL) {
574 if (nodo->type == XML_ELEMENT_NODE) {
575 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
576 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
577 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
578 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
579 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
580 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
581 } else if (xmlStrcmp(nodo->name, BAD_CAST"entrega") == 0) {
582 flujo = atof( (char *)XML_GET_CONTENT(nodo->children) );
583 } else if (xmlStrcmp(nodo->name, BAD_CAST"color") == 0) {
590 Pump *p = new Pump(orientacion);
591 p->set_position(x,y);
592 p->set_entrega(flujo);
593 p->set_id( atoi(id.c_str()) );
599 Conduct *Constructor::loadConduct(xmlNodePtr nodo)
601 std::string name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
602 std::string id = (char *)xmlGetProp(nodo, BAD_CAST"id");
603 int orientacion=0, x, y;
606 nodo = nodo->children;
607 while (nodo != NULL) {
608 if (nodo->type == XML_ELEMENT_NODE) {
609 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
610 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
611 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
612 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
613 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
614 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
615 } else if (xmlStrcmp(nodo->name, BAD_CAST"caudal") == 0) {
616 flujo = atof( (char *)XML_GET_CONTENT(nodo->children) );
622 Conduct *p = new Conduct(orientacion);
623 p->set_position(x,y);
624 p->set_caudal(flujo);
625 p->set_id( atoi(id.c_str()) );
631 Exclusa *Constructor::loadExclusa(xmlNodePtr nodo)
633 std::string name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
634 std::string id = (char *)xmlGetProp(nodo, BAD_CAST"id");
636 int orientacion=0, x, y;
639 nodo = nodo->children;
640 while (nodo != NULL) {
641 if (nodo->type == XML_ELEMENT_NODE) {
642 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
643 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
644 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
645 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
646 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
647 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
648 } else if (xmlStrcmp(nodo->name, BAD_CAST"estado") == 0) {
649 estado = (char *)XML_GET_CONTENT(nodo->children);
655 Exclusa *p = new Exclusa(orientacion);
656 p->set_position(x,y);
657 p->set_id( atoi(id.c_str()) );
659 p->set_estado( estado == "1" );
664 Cistern *Constructor::loadTank(xmlNodePtr nodo)
666 std::string name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
667 std::string id = (char *)xmlGetProp(nodo, BAD_CAST"id");
668 int orientacion=0, x, y;
669 float liquido,capacidad;
671 nodo = nodo->children;
672 while (nodo != NULL) {
673 if (nodo->type == XML_ELEMENT_NODE) {
674 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
675 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
676 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
677 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
678 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
679 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
680 } else if (xmlStrcmp(nodo->name, BAD_CAST"capacidad") == 0) {
681 capacidad = atof ((char *)XML_GET_CONTENT(nodo->children) );
682 } else if (xmlStrcmp(nodo->name, BAD_CAST"inicial") == 0) {
683 liquido = atof ((char *)XML_GET_CONTENT(nodo->children) );
689 Cistern *p = new Cistern(orientacion);
690 p->set_position(x,y);
691 p->set_id( atoi(id.c_str()) );
693 p->set_capacidad(capacidad);
694 p->set_contenido_inicial(liquido);
699 Union *Constructor::loadUnion(xmlNodePtr nodo)
701 std::string name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
702 std::string id = (char *)xmlGetProp(nodo, BAD_CAST"id");
704 int orientacion=0, x, y;
707 nodo = nodo->children;
708 while (nodo != NULL) {
709 if (nodo->type == XML_ELEMENT_NODE) {
710 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
711 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
712 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
713 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
714 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
715 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
716 } else if (xmlStrcmp(nodo->name, BAD_CAST"caudal") == 0) {
717 caudal = atof ((char *)XML_GET_CONTENT(nodo->children) );
718 } else if (xmlStrcmp(nodo->name, BAD_CAST"tipo") == 0) {
719 tipo = (char *)XML_GET_CONTENT(nodo->children);
725 Union *p = new Union(orientacion);
726 p->set_position(x,y);
727 p->set_id( atoi(id.c_str()) );
729 p->set_caudal(caudal);
730 p->is_union = (tipo == "union");
735 Drain *Constructor::loadDrain(xmlNodePtr nodo)
737 std::string name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
738 std::string id = (char *)xmlGetProp(nodo, BAD_CAST"id");
739 int orientacion=0, x, y;
741 nodo = nodo->children;
742 while (nodo != NULL) {
743 if (nodo->type == XML_ELEMENT_NODE) {
744 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
745 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
746 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
747 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
748 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
749 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
755 Drain *p = new Drain(orientacion);
756 p->set_position(x,y);
757 p->set_id( atoi(id.c_str()) );
763 Splitter *Constructor::loadCodo(xmlNodePtr nodo)
765 std::string name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
766 std::string id = (char *)xmlGetProp(nodo, BAD_CAST"id");
767 int orientacion=0, x, y;
770 nodo = nodo->children;
771 while (nodo != NULL) {
772 if (nodo->type == XML_ELEMENT_NODE) {
773 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
774 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
775 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
776 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
777 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
778 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
779 } else if (xmlStrcmp(nodo->name, BAD_CAST"caudal") == 0) {
780 caudal = atof( (char *)XML_GET_CONTENT(nodo->children) );
786 Splitter *p = new Splitter(orientacion);
787 p->set_position(x,y);
788 p->set_id( atoi(id.c_str()) );
790 p->set_caudal(caudal);