1 #include "constructor.h"
3 Constructor::Constructor(BaseObjectType* cobject, const Glib::RefPtr<Gnome::Glade::Xml>& refGlade):Gtk::Window(cobject)
6 set_title("Constructor");
9 ico_canio = Gdk::Pixbuf::create_from_file(PACKAGE_DATA_DIR"/plaqui-constructor/pixmaps/canio_n.png");
10 ico_y = Gdk::Pixbuf::create_from_file(PACKAGE_DATA_DIR"/plaqui-constructor/pixmaps/y_n.png");
11 ico_codo = Gdk::Pixbuf::create_from_file(PACKAGE_DATA_DIR"/plaqui-constructor/pixmaps/codo_o.png");
12 ico_tanque = Gdk::Pixbuf::create_from_file(PACKAGE_DATA_DIR"/plaqui-constructor/pixmaps/tanque_e.png");
13 ico_exclusa = Gdk::Pixbuf::create_from_file(PACKAGE_DATA_DIR"/plaqui-constructor/pixmaps/exclusa_h.png");
14 ico_drain = Gdk::Pixbuf::create_from_file(PACKAGE_DATA_DIR"/plaqui-constructor/pixmaps/drain_n.png");
15 ico_bomba = Gdk::Pixbuf::create_from_file(PACKAGE_DATA_DIR"/plaqui-constructor/pixmaps/bomba_e.png");
16 ico_and = Gdk::Pixbuf::create_from_file(PACKAGE_DATA_DIR"/plaqui-constructor/pixmaps/and_e.png");
17 ico_or = Gdk::Pixbuf::create_from_file(PACKAGE_DATA_DIR"/plaqui-constructor/pixmaps/or_e.png");
18 ico_not = Gdk::Pixbuf::create_from_file(PACKAGE_DATA_DIR"/plaqui-constructor/pixmaps/not_e.png");
20 refGlade->get_widget("btn_canio", btn_canio);
21 refGlade->get_widget("btn_codo", btn_codo);
22 refGlade->get_widget("btn_y", btn_y);
23 refGlade->get_widget("btn_tanque",btn_tanque);
24 refGlade->get_widget("btn_bomba", btn_bomba);
25 refGlade->get_widget("btn_exclusa", btn_exclusa);
26 refGlade->get_widget("btn_drain", btn_drain);
27 refGlade->get_widget("btn_and", btn_and);
28 refGlade->get_widget("btn_or", btn_or);
29 refGlade->get_widget("btn_not", btn_not);
30 refGlade->get_widget("main_menu_quit",main_menu_quit);
31 refGlade->get_widget("main_menu_open",main_menu_open);
32 refGlade->get_widget("main_menu_save",main_menu_save);
33 refGlade->get_widget("edit_menu_del",edit_menu_del);
34 refGlade->get_widget("chk_btn_logica",chk_btn_logica);
35 refGlade->get_widget("file_open_selection",file_open_selection);
36 refGlade->get_widget("file_selection",file_selection);
37 refGlade->get_widget("combo_entry",combo_entry);
38 refGlade->get_widget("btn_check",btn_check);
39 refGlade->get_widget("dlg_connect", dlg_connect);
40 refGlade->get_widget("btn_dlg_close", btn_dlg_close);
41 refGlade->get_widget("dlg_label", dlg_label);
43 refGlade->get_widget_derived("workplace", workplace); //fixed
46 listTargets.push_back( Gtk::TargetEntry("STRING") );
47 listTargets.push_back( Gtk::TargetEntry("text/plain") );
48 listTargets.push_back( Gtk::TargetEntry("POINTER") );
49 listTargets.push_back( Gtk::TargetEntry("application/pointer") );
51 btn_canio->drag_source_set(listTargets);
52 btn_y->drag_source_set(listTargets);
53 btn_codo->drag_source_set(listTargets);
54 btn_tanque->drag_source_set(listTargets);
55 btn_bomba->drag_source_set(listTargets);
56 btn_drain->drag_source_set(listTargets);
57 btn_exclusa->drag_source_set(listTargets);
58 btn_and->drag_source_set(listTargets);
59 btn_or->drag_source_set(listTargets);
60 btn_not->drag_source_set(listTargets);
62 btn_canio->signal_drag_data_get().connect( SigC::slot(*this, &Constructor::on_btn_canio_drag_get));
63 btn_bomba->signal_drag_data_get().connect( SigC::slot(*this, &Constructor::on_btn_bomba_drag_get));
64 btn_exclusa->signal_drag_data_get().connect( SigC::slot(*this, &Constructor::on_btn_exclusa_drag_get));
65 btn_y->signal_drag_data_get().connect( SigC::slot(*this, &Constructor::on_btn_y_drag_get));
66 btn_codo->signal_drag_data_get().connect( SigC::slot(*this, &Constructor::on_btn_codo_drag_get));
67 btn_tanque->signal_drag_data_get().connect( SigC::slot(*this, &Constructor::on_btn_tanque_drag_get));
68 btn_drain->signal_drag_data_get().connect( SigC::slot(*this, &Constructor::on_btn_drain_drag_get));
69 btn_and->signal_drag_data_get().connect( SigC::slot(*this, &Constructor::on_btn_and_drag_get));
70 btn_or->signal_drag_data_get().connect( SigC::slot(*this, &Constructor::on_btn_or_drag_get));
71 btn_not->signal_drag_data_get().connect( SigC::slot(*this, &Constructor::on_btn_not_drag_get));
72 btn_check->signal_clicked().connect(SigC::slot(*this,&Constructor::on_btn_check_clicked));
73 btn_dlg_close->signal_clicked().connect(SigC::slot(*this,&Constructor::on_btn_dlg_connect_clicked));
74 chk_btn_logica->signal_clicked().connect(SigC::slot(*this, &Constructor::on_chk_btn_clicked));
76 main_menu_quit->signal_activate().connect(SigC::slot(*this, &Constructor::on_main_menu_quit));
77 main_menu_open->signal_activate().connect(SigC::slot(*this, &Constructor::on_main_menu_open));
78 main_menu_save->signal_activate().connect(SigC::slot(*this, &Constructor::on_main_menu_save));
79 edit_menu_del->signal_activate().connect(SigC::slot(*this,&Constructor::on_edit_menu_del));
81 btn_file_cancel = file_selection->get_cancel_button();
82 btn_file_ok = file_selection->get_ok_button();
83 btn_file_ok->signal_clicked().connect(SigC::slot(*this,&Constructor::on_btn_file_ok_clicked));
84 btn_file_cancel->signal_clicked().connect(SigC::slot(*this,&Constructor::on_btn_file_cancel_clicked));
86 btn_open_cancel = file_open_selection->get_cancel_button();
87 btn_open_ok = file_open_selection->get_ok_button();
88 btn_open_ok->signal_clicked().connect(SigC::slot(*this,&Constructor::on_load_from_xml));
89 btn_open_cancel->signal_clicked().connect(SigC::slot(*this,&Constructor::on_btn_open_cancel_clicked));
91 // Señales para cambiar el icono cuando empieza el drag.
92 btn_canio->signal_drag_begin().connect( SigC::slot(*this, &Constructor::on_canio_drag_begin));
93 btn_y->signal_drag_begin().connect( SigC::slot(*this, &Constructor::on_y_drag_begin));
94 btn_codo->signal_drag_begin().connect( SigC::slot(*this, &Constructor::on_codo_drag_begin));
95 btn_tanque->signal_drag_begin().connect( SigC::slot(*this, &Constructor::on_tanque_drag_begin));
96 btn_bomba->signal_drag_begin().connect( SigC::slot(*this, &Constructor::on_bomba_drag_begin));
97 btn_exclusa->signal_drag_begin().connect( SigC::slot(*this, &Constructor::on_exclusa_drag_begin));
98 btn_drain->signal_drag_begin().connect( SigC::slot(*this, &Constructor::on_drain_drag_begin));
99 btn_and->signal_drag_begin().connect( SigC::slot(*this, &Constructor::on_and_drag_begin));
100 btn_or->signal_drag_begin().connect( SigC::slot(*this, &Constructor::on_or_drag_begin));
101 btn_not->signal_drag_begin().connect( SigC::slot(*this, &Constructor::on_not_drag_begin));
102 workplace->drag_dest_set(listTargets);
103 workplace->signal_drag_data_received().connect( SigC::slot(*this, &Constructor::on_item_drop_drag_received) );
104 workplace->listaItems = &listaItems;
105 workplace->lista_logic_Items = &lista_logic_Items;
109 Constructor::~Constructor()
111 std::list<CItem *>::iterator i = listaItems.begin();
112 while ( i != listaItems.end() ){
116 i = listaItems.begin();
120 void Constructor::on_btn_canio_drag_get(const Glib::RefPtr<Gdk::DragContext>& context, GtkSelectionData* selection_data, guint info, guint time)
122 gtk_selection_data_set (selection_data, selection_data->target, 8, (const guchar*)"canio_n.png", 12);
125 void Constructor::on_btn_y_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*)"y_n.png",8);
130 void Constructor::on_btn_codo_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*)"codo_o.png",10);
135 void Constructor::on_btn_tanque_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*)"tanque_e.png",12);
140 void Constructor::on_btn_bomba_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*)"bomba_e.png",11);
145 void Constructor::on_btn_exclusa_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*)"exclusa_h.png",13);
150 void Constructor::on_btn_drain_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*)"drain_n.png",11);
155 void Constructor::on_btn_and_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*)"and_e.png",9);
160 void Constructor::on_btn_or_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*)"or_e.png",8);
165 void Constructor::on_btn_not_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*)"not_e.png",9);
171 void Constructor::on_main_menu_quit()
178 void Constructor::on_main_menu_open()
180 // Conecto el boton OK para llamar al cargar del XML
181 file_open_selection->show();
184 void Constructor::on_main_menu_save()
186 // Conecto el boton OK para llamar al salvar
187 file_selection->show();
190 void Constructor::on_edit_menu_del()
191 { // OJO que borra al primero que encuentra con el mismo nombre!!!
192 std::list<CItem *>::iterator i = listaItems.begin();
193 Glib::ustring pointed = combo_entry->get_text();
194 while ( i != listaItems.end() ){
196 if ( temp->get_name() == pointed ){
197 workplace->delete_item(temp->get_id());
204 void Constructor::on_chk_btn_clicked()
209 void Constructor::on_load_from_xml()
211 std::string file_name = file_open_selection->get_filename();
213 /* Parseo de ejemplo de un XML desde archivo */
215 document = xmlParseFile(file_name.c_str());
216 if (document == NULL) {
217 // TODO : dar un aviso de que no se pudo abrir el archivo!!
221 /* bien, el archivo se parseo bien! */
222 xmlNodePtr nodo, items;
223 nodo = document->children;
227 if (strcmp((char *)nodo->name, "planta") == 0) {
228 items = nodo->children;
229 while (items != NULL) {
231 if (items->type == XML_ELEMENT_NODE) {
232 std::cout << "ITEM" << std::endl;
233 if (xmlStrcmp(items->name, BAD_CAST"bomba")==0) {
234 current = loadBomba(items);
235 } else if (xmlStrcmp(items->name, BAD_CAST"tubo")==0) {
236 current = loadConduct(items);
237 } else if (xmlStrcmp(items->name, BAD_CAST"codo")==0) {
238 current = loadCodo(items);
239 } else if (xmlStrcmp(items->name, BAD_CAST"exclusa")==0) {
240 current = loadExclusa(items);
241 } else if (xmlStrcmp(items->name, BAD_CAST"tanque")==0) {
242 current = loadTank(items);
243 } else if (xmlStrcmp(items->name, BAD_CAST"empalme")==0) {
244 current = loadUnion(items);
245 } else if (xmlStrcmp(items->name, BAD_CAST"drenaje")==0) {
246 current = loadDrain(items);
249 if (current != NULL) {
250 // Agrego y conecto la bomba
251 listaItems.push_back(current);
252 current->drag_source_set(listTargets);
253 workplace->put(*current, current->get_position_x(), current->get_position_y());
254 //Apunto al workplace
255 current->workplace= workplace;
257 current->combo_entry = combo_entry;
258 //Apunto a la listaItems.
259 current->listaItems = &listaItems;
260 //Apunto a la lista de items logicos
261 current->lista_logic_Items = &lista_logic_Items;
262 // Conecto las señales
263 current->signal_drag_data_get().connect( SigC::slot(*this, &Constructor::on_item_drag_data_get));
264 current->signal_drag_begin().connect(SigC::bind( SigC::slot(*this, &Constructor::on_item_drag_begin), current));
271 // TODO : avisar que el XML no es valido!!
273 std::cout << "CARGA COMPLETA" << std::endl;
274 file_open_selection->hide();
276 void Constructor::on_btn_file_ok_clicked()
278 std::list<CItem *>::iterator i = listaItems.begin();
279 std::string file_name = file_selection->get_filename();
280 if ( (archivo = fopen( file_name.c_str(), "w+")) != NULL ){
281 fprintf(archivo, "<?xml version=\"1.0\" encoding=\"iso-8859-1\" ?>\n");
282 fprintf (archivo,"<planta>\n");
283 while ( i != listaItems.end() ){
288 fprintf(archivo,"</planta>\n");
290 std::cout<<"NO SE ABRIO EL ARCHIVO"<<std::endl;
292 file_selection->hide();
295 void Constructor::on_btn_file_cancel_clicked()
297 file_selection->hide();
300 void Constructor::on_btn_open_cancel_clicked()
302 file_open_selection->hide();
305 void Constructor::on_btn_dlg_connect_clicked()
310 void Constructor::on_canio_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)
312 context->set_icon(ico_canio, 5, 5);
315 void Constructor::on_y_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)
317 context->set_icon(ico_y, 5, 5);
320 void Constructor::on_codo_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)
322 context->set_icon(ico_codo, 5, 5);
325 void Constructor::on_tanque_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)
327 context->set_icon(ico_tanque, 5, 5);
330 void Constructor::on_bomba_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)
332 context->set_icon(ico_bomba, 5, 5);
335 void Constructor::on_exclusa_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)
337 context->set_icon(ico_exclusa, 5, 5);
340 void Constructor::on_drain_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)
342 context->set_icon(ico_drain, 5, 5);
345 void Constructor::on_and_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)
347 context->set_icon(ico_and, 5, 5);
350 void Constructor::on_or_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)
352 context->set_icon(ico_or, 5, 5);
355 void Constructor::on_not_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)
357 context->set_icon(ico_not, 5, 5);
360 void Constructor::on_item_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context, CItem *item)
363 context->set_icon(item->get_image(), 5, 5);
364 workplace->on_expose_event(&e);
367 void Constructor::on_item_drag_data_get(const Glib::RefPtr<Gdk::DragContext>& context, GtkSelectionData* selection_data, guint info, guint time)
369 gtk_selection_data_set (selection_data, selection_data->target, 10, (const guchar*)"item_codo.png", 13);
372 bool Constructor::can_drop(CItem *item, int _x, int _y)
374 std::list<CItem*>::iterator i = listaItems.begin();
375 while( i != listaItems.end() ) {
377 if ( temp->get_id() != item->get_id() ) {
378 if ( (temp->is_occupied_area(_x, _y)) ||
379 ( temp->is_occupied_area(_x+item->get_image()->get_width()-1, _y+item->get_image()->get_height()-1)) ||
380 ( temp->is_occupied_area(_x, _y+item->get_image()->get_height()-1)) ||
381 ( temp->is_occupied_area(_x+item->get_image()->get_width()-1, _y) ) )
390 void Constructor::on_item_drop_drag_received(const Glib::RefPtr<Gdk::DragContext>& context, int x, int y, GtkSelectionData* selection_data, guint info, guint time)
393 /* Ajusto coordenada x e y para que caigan en un lugar de una cuadricula de 32x32 */
395 // el +1 es para evitar un bug cuando se selecciona muy cerce de la
396 // separacion de 2 cuadritos
399 // El drag es de un item
400 if (selection_data->format == 10) {
401 if (can_drop(((CItem*)drag_get_source_widget(context)),i*32, j*32)){
402 ((CItem*)drag_get_source_widget(context))->set_position(i*32, j*32);
403 workplace->move(*drag_get_source_widget(context), i*32, j*32);
407 // El Drag es desde la barra de tareas
408 if ((selection_data->length >= 0) && (selection_data->format == 8)) {
410 if (strcmp((const char *)selection_data->data, "codo_o.png")==0)
412 else if (strcmp((const char *)selection_data->data, "canio_n.png")==0)
414 else if (strcmp((const char *)selection_data->data, "y_n.png")==0)
416 else if (strcmp((const char *)selection_data->data, "tanque_e.png")==0)
418 else if (strcmp((const char *)selection_data->data, "bomba_e.png")==0)
420 else if (strcmp((const char *)selection_data->data, "exclusa_h.png")==0)
422 else if (strcmp((const char *)selection_data->data, "drain_n.png")==0)
424 else if (strcmp((const char *)selection_data->data, "and_e.png")==0){
425 a = new And(); a->is_logic = true;
426 } else if (strcmp((const char *)selection_data->data, "or_e.png")==0) {
427 a = new Or(); a->is_logic = true;
428 } else if (strcmp((const char *)selection_data->data, "not_e.png")==0) {
429 a = new Not(); a->is_logic = true;
433 sprintf(char_id,"%d",id);
435 a->set_name( a->get_name()+char_id );
436 if ( can_drop(a, i*32, j*32) ) {
437 workplace->put(*a, i*32, j*32);
438 //Apunto al workplace
439 a->workplace= workplace;
441 a->combo_entry = combo_entry;
442 //Apunto a la listaItems.
443 a->listaItems = &listaItems;
444 //Apunto a la lista de items logicos
445 a->lista_logic_Items = &lista_logic_Items;
446 //Seteo la posicion del item
447 a->set_position(i*32,j*32);
448 // Seteo la lista de tipos de drags
449 a->drag_source_set(listTargets);
450 // Conecto las señales
451 a->signal_drag_data_get().connect( SigC::slot(*this, &Constructor::on_item_drag_data_get));
452 // Utilizo el SigC::bind para que el callback on_drag_begin acepte un
453 // parametro extra, en este caso un CItem *. Esto se hace para
454 // que cuando el usuario quiera mover un item, saber que item es
455 // y pedirle su ícono para mostrar cono icono durante la operacion,
456 // Esto va a permitir, que si un widget tiene una imagen rotara o algo
457 // raro se vea el widget tal cual.
458 a->signal_drag_begin().connect(SigC::bind( SigC::slot(*this, &Constructor::on_item_drag_begin), a));
461 listaItems.push_back(a);
463 lista_logic_Items.push_back(a);
469 context->drag_finish(false, false, time);
473 void Constructor::on_btn_check_clicked()
475 std::list<CItem *>::iterator i = listaItems.begin();
476 while ( i != listaItems.end() ){
477 (*i)->set_default_connector();
478 (*i)->is_connected = false;
482 i = listaItems.begin();
483 if ( !listaItems.empty() ) {
484 while ( i != listaItems.end() ) {
486 std::cout<< "item="<<temp->get_name()<<" "<<"check= "<<temp->check_connection()<<std::endl;
487 if ( !temp->check_connection() ) {
488 dlg_connect->set_title("Error");
489 dlg_label->set_text("Los elementos no estan conectados\n\t\tcorrectamente");
495 dlg_connect->set_title("Conexion");
496 dlg_label->set_text("Los elementos estan conectados\n\t\tcorrectamente");
501 Pump *Constructor::loadBomba(xmlNodePtr nodo)
503 std::string name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
504 std::string id = (char *)xmlGetProp(nodo, BAD_CAST"id");
505 int orientacion=0, x, y;
508 nodo = nodo->children;
509 while (nodo != NULL) {
510 if (nodo->type == XML_ELEMENT_NODE) {
511 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
512 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
513 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
514 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
515 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
516 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
517 } else if (xmlStrcmp(nodo->name, BAD_CAST"entrega") == 0) {
518 flujo = atof( (char *)XML_GET_CONTENT(nodo->children) );
519 } else if (xmlStrcmp(nodo->name, BAD_CAST"color") == 0) {
526 Pump *p = new Pump(orientacion);
527 p->set_position(x,y);
528 p->set_entrega(flujo);
529 p->set_id( atoi(id.c_str()) );
535 Conduct *Constructor::loadConduct(xmlNodePtr nodo)
537 std::string name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
538 std::string id = (char *)xmlGetProp(nodo, BAD_CAST"id");
539 int orientacion=0, x, y;
542 nodo = nodo->children;
543 while (nodo != NULL) {
544 if (nodo->type == XML_ELEMENT_NODE) {
545 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
546 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
547 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
548 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
549 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
550 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
551 } else if (xmlStrcmp(nodo->name, BAD_CAST"caudal") == 0) {
552 flujo = atof( (char *)XML_GET_CONTENT(nodo->children) );
558 Conduct *p = new Conduct(orientacion);
559 p->set_position(x,y);
560 p->set_caudal(flujo);
561 p->set_id( atoi(id.c_str()) );
567 Exclusa *Constructor::loadExclusa(xmlNodePtr nodo)
569 std::string name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
570 std::string id = (char *)xmlGetProp(nodo, BAD_CAST"id");
572 int orientacion=0, x, y;
575 nodo = nodo->children;
576 while (nodo != NULL) {
577 if (nodo->type == XML_ELEMENT_NODE) {
578 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
579 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
580 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
581 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
582 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
583 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
584 } else if (xmlStrcmp(nodo->name, BAD_CAST"estado") == 0) {
585 estado = (char *)XML_GET_CONTENT(nodo->children);
591 Exclusa *p = new Exclusa(orientacion);
592 p->set_position(x,y);
593 p->set_id( atoi(id.c_str()) );
595 p->set_estado( estado == "1" );
600 Cistern *Constructor::loadTank(xmlNodePtr nodo)
602 std::string name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
603 std::string id = (char *)xmlGetProp(nodo, BAD_CAST"id");
604 int orientacion=0, x, y;
605 float liquido,capacidad;
607 nodo = nodo->children;
608 while (nodo != NULL) {
609 if (nodo->type == XML_ELEMENT_NODE) {
610 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
611 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
612 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
613 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
614 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
615 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
616 } else if (xmlStrcmp(nodo->name, BAD_CAST"capacidad") == 0) {
617 capacidad = atof ((char *)XML_GET_CONTENT(nodo->children) );
618 } else if (xmlStrcmp(nodo->name, BAD_CAST"inicial") == 0) {
619 liquido = atof ((char *)XML_GET_CONTENT(nodo->children) );
625 Cistern *p = new Cistern(orientacion);
626 p->set_position(x,y);
627 p->set_id( atoi(id.c_str()) );
629 p->set_capacidad(capacidad);
630 p->set_contenido_inicial(liquido);
635 Union *Constructor::loadUnion(xmlNodePtr nodo)
637 std::string name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
638 std::string id = (char *)xmlGetProp(nodo, BAD_CAST"id");
640 int orientacion=0, x, y;
643 nodo = nodo->children;
644 while (nodo != NULL) {
645 if (nodo->type == XML_ELEMENT_NODE) {
646 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
647 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
648 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
649 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
650 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
651 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
652 } else if (xmlStrcmp(nodo->name, BAD_CAST"caudal") == 0) {
653 caudal = atof ((char *)XML_GET_CONTENT(nodo->children) );
654 } else if (xmlStrcmp(nodo->name, BAD_CAST"tipo") == 0) {
655 tipo = (char *)XML_GET_CONTENT(nodo->children);
661 Union *p = new Union(orientacion);
662 p->set_position(x,y);
663 p->set_id( atoi(id.c_str()) );
665 p->set_caudal(caudal);
666 p->is_union = (tipo == "union");
671 Drain *Constructor::loadDrain(xmlNodePtr nodo)
673 std::string name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
674 std::string id = (char *)xmlGetProp(nodo, BAD_CAST"id");
675 int orientacion=0, x, y;
677 nodo = nodo->children;
678 while (nodo != NULL) {
679 if (nodo->type == XML_ELEMENT_NODE) {
680 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
681 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
682 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
683 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
684 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
685 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
691 Drain *p = new Drain(orientacion);
692 p->set_position(x,y);
693 p->set_id( atoi(id.c_str()) );
699 Splitter *Constructor::loadCodo(xmlNodePtr nodo)
701 std::string name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
702 std::string id = (char *)xmlGetProp(nodo, BAD_CAST"id");
703 int orientacion=0, x, y;
706 nodo = nodo->children;
707 while (nodo != NULL) {
708 if (nodo->type == XML_ELEMENT_NODE) {
709 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
710 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
711 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
712 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
713 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
714 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
715 } else if (xmlStrcmp(nodo->name, BAD_CAST"caudal") == 0) {
716 caudal = atof( (char *)XML_GET_CONTENT(nodo->children) );
722 Splitter *p = new Splitter(orientacion);
723 p->set_position(x,y);
724 p->set_id( atoi(id.c_str()) );
726 p->set_caudal(caudal);