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);
49 refGlade->get_widget("status_bar", status_bar);
51 refGlade->get_widget_derived("workplace", workplace); //fixed
54 listTargets.push_back( Gtk::TargetEntry("STRING") );
55 listTargets.push_back( Gtk::TargetEntry("text/plain") );
56 listTargets.push_back( Gtk::TargetEntry("POINTER") );
57 listTargets.push_back( Gtk::TargetEntry("application/pointer") );
59 btn_canio->drag_source_set(listTargets);
60 btn_y->drag_source_set(listTargets);
61 btn_codo->drag_source_set(listTargets);
62 btn_tanque->drag_source_set(listTargets);
63 btn_bomba->drag_source_set(listTargets);
64 btn_drain->drag_source_set(listTargets);
65 btn_exclusa->drag_source_set(listTargets);
66 btn_and->drag_source_set(listTargets);
67 btn_or->drag_source_set(listTargets);
68 btn_not->drag_source_set(listTargets);
70 btn_canio->signal_drag_data_get().connect( SigC::slot(*this, &Constructor::on_btn_canio_drag_get));
71 btn_bomba->signal_drag_data_get().connect( SigC::slot(*this, &Constructor::on_btn_bomba_drag_get));
72 btn_exclusa->signal_drag_data_get().connect( SigC::slot(*this, &Constructor::on_btn_exclusa_drag_get));
73 btn_y->signal_drag_data_get().connect( SigC::slot(*this, &Constructor::on_btn_y_drag_get));
74 btn_codo->signal_drag_data_get().connect( SigC::slot(*this, &Constructor::on_btn_codo_drag_get));
75 btn_tanque->signal_drag_data_get().connect( SigC::slot(*this, &Constructor::on_btn_tanque_drag_get));
76 btn_drain->signal_drag_data_get().connect( SigC::slot(*this, &Constructor::on_btn_drain_drag_get));
77 btn_and->signal_drag_data_get().connect( SigC::slot(*this, &Constructor::on_btn_and_drag_get));
78 btn_or->signal_drag_data_get().connect( SigC::slot(*this, &Constructor::on_btn_or_drag_get));
79 btn_not->signal_drag_data_get().connect( SigC::slot(*this, &Constructor::on_btn_not_drag_get));
80 btn_check->signal_clicked().connect(SigC::slot(*this,&Constructor::on_btn_check_clicked));
81 btn_dlg_close->signal_clicked().connect(SigC::slot(*this,&Constructor::on_btn_dlg_connect_clicked));
82 btn_find->signal_clicked().connect(SigC::slot(*this,&Constructor::on_btn_find_clicked));
83 chk_btn_logica->signal_clicked().connect(SigC::slot(*this, &Constructor::on_chk_btn_logica_clicked));
84 quick_btn_new->signal_clicked().connect(SigC::slot(*this, &Constructor::on_quick_btn_new_clicked));
85 quick_btn_save->signal_clicked().connect(SigC::slot(*this, &Constructor::on_quick_btn_save_clicked));
86 quick_btn_open->signal_clicked().connect(SigC::slot(*this, &Constructor::on_main_menu_open));
88 main_menu_quit->signal_activate().connect(SigC::slot(*this, &Constructor::on_main_menu_quit));
89 main_menu_new->signal_activate().connect(SigC::slot(*this, &Constructor::on_quick_btn_new_clicked));
90 main_menu_open->signal_activate().connect(SigC::slot(*this, &Constructor::on_main_menu_open));
91 main_menu_save->signal_activate().connect(SigC::slot(*this, &Constructor::on_main_menu_save));
92 edit_menu_del->signal_activate().connect(SigC::slot(*this,&Constructor::on_edit_menu_del));
93 edit_menu_delete_all->signal_activate().connect(SigC::slot(*this,&Constructor::on_quick_btn_delete_all_clicked));
95 btn_file_cancel = file_selection->get_cancel_button();
96 btn_file_ok = file_selection->get_ok_button();
97 btn_file_ok->signal_clicked().connect(SigC::slot(*this,&Constructor::on_btn_file_ok_clicked));
98 btn_file_cancel->signal_clicked().connect(SigC::slot(*this,&Constructor::on_btn_file_cancel_clicked));
100 btn_open_cancel = file_open_selection->get_cancel_button();
101 btn_open_ok = file_open_selection->get_ok_button();
102 btn_open_ok->signal_clicked().connect(SigC::slot(*this,&Constructor::on_load_from_xml));
103 btn_open_cancel->signal_clicked().connect(SigC::slot(*this,&Constructor::on_btn_open_cancel_clicked));
105 // Señales para cambiar el icono cuando empieza el drag.
106 btn_canio->signal_drag_begin().connect( SigC::slot(*this, &Constructor::on_canio_drag_begin));
107 btn_y->signal_drag_begin().connect( SigC::slot(*this, &Constructor::on_y_drag_begin));
108 btn_codo->signal_drag_begin().connect( SigC::slot(*this, &Constructor::on_codo_drag_begin));
109 btn_tanque->signal_drag_begin().connect( SigC::slot(*this, &Constructor::on_tanque_drag_begin));
110 btn_bomba->signal_drag_begin().connect( SigC::slot(*this, &Constructor::on_bomba_drag_begin));
111 btn_exclusa->signal_drag_begin().connect( SigC::slot(*this, &Constructor::on_exclusa_drag_begin));
112 btn_drain->signal_drag_begin().connect( SigC::slot(*this, &Constructor::on_drain_drag_begin));
113 btn_and->signal_drag_begin().connect( SigC::slot(*this, &Constructor::on_and_drag_begin));
114 btn_or->signal_drag_begin().connect( SigC::slot(*this, &Constructor::on_or_drag_begin));
115 btn_not->signal_drag_begin().connect( SigC::slot(*this, &Constructor::on_not_drag_begin));
116 workplace->drag_dest_set(listTargets);
117 workplace->signal_drag_data_received().connect( SigC::slot(*this, &Constructor::on_item_drop_drag_received) );
118 workplace->listaItems = &listaItems;
119 workplace->lista_logic_Items = &lista_logic_Items;
120 workplace->logica = &logica;
124 Constructor::~Constructor()
126 Constructor::on_edit_menu_delete_all();
129 void Constructor::on_btn_canio_drag_get(const Glib::RefPtr<Gdk::DragContext>& context, GtkSelectionData* selection_data, guint info, guint time)
131 gtk_selection_data_set (selection_data, selection_data->target, 8, (const guchar*)"canio_n.png", 12);
134 void Constructor::on_btn_y_drag_get(const Glib::RefPtr<Gdk::DragContext>& context, GtkSelectionData* selection_data, guint info, guint time)
136 gtk_selection_data_set(selection_data, selection_data->target, 8,(const guchar*)"y_n.png",8);
139 void Constructor::on_btn_codo_drag_get(const Glib::RefPtr<Gdk::DragContext>& context, GtkSelectionData* selection_data, guint info, guint time)
141 gtk_selection_data_set(selection_data, selection_data->target, 8 ,(const guchar*)"codo_o.png",10);
144 void Constructor::on_btn_tanque_drag_get(const Glib::RefPtr<Gdk::DragContext>& context, GtkSelectionData* selection_data, guint info, guint time)
146 gtk_selection_data_set(selection_data, selection_data->target, 8,(const guchar*)"tanque_e.png",12);
149 void Constructor::on_btn_bomba_drag_get(const Glib::RefPtr<Gdk::DragContext>& context, GtkSelectionData* selection_data, guint info, guint time)
151 gtk_selection_data_set(selection_data, selection_data->target, 8,(const guchar*)"bomba_e.png",11);
154 void Constructor::on_btn_exclusa_drag_get(const Glib::RefPtr<Gdk::DragContext>& context, GtkSelectionData* selection_data, guint info, guint time)
156 gtk_selection_data_set(selection_data, selection_data->target, 8,(const guchar*)"exclusa_h.png",13);
159 void Constructor::on_btn_drain_drag_get(const Glib::RefPtr<Gdk::DragContext>& context, GtkSelectionData* selection_data, guint info, guint time)
161 gtk_selection_data_set(selection_data, selection_data->target, 8,(const guchar*)"drain_n.png",11);
164 void Constructor::on_btn_and_drag_get(const Glib::RefPtr<Gdk::DragContext>& context, GtkSelectionData* selection_data, guint info, guint time)
166 gtk_selection_data_set(selection_data, selection_data->target, 8,(const guchar*)"and_e.png",9);
169 void Constructor::on_btn_or_drag_get(const Glib::RefPtr<Gdk::DragContext>& context, GtkSelectionData* selection_data, guint info, guint time)
171 gtk_selection_data_set(selection_data, selection_data->target, 8,(const guchar*)"or_e.png",8);
174 void Constructor::on_btn_not_drag_get(const Glib::RefPtr<Gdk::DragContext>& context, GtkSelectionData* selection_data, guint info, guint time)
176 gtk_selection_data_set(selection_data, selection_data->target, 8,(const guchar*)"not_e.png",9);
180 void Constructor::on_main_menu_quit()
187 void Constructor::on_main_menu_open()
189 // Conecto el boton OK para llamar al cargar del XML
190 file_open_selection->show();
193 void Constructor::on_main_menu_save()
195 // Conecto el boton OK para llamar al salvar
197 if ( ! check_connection(name) ) {
198 dlg_connect->set_title("Error");
199 dlg_label->set_text("El elemento "+name+" no esta conectado\n\t\tcorrectamente");
202 file_selection->show();
205 void Constructor::on_edit_menu_del()
207 workplace->delete_item(WorkPlace::pointed);
210 void Constructor::on_edit_menu_delete_all()
212 std::list<CItem *>::iterator i = listaItems.begin();
213 while ( i != listaItems.end() ) {
214 (*i)->workplace->delete_item((*i)->get_id());
215 i = listaItems.begin();
217 i = lista_logic_Items.begin();
218 while ( i != lista_logic_Items.end() ) {
219 (*i)->workplace->delete_item((*i)->get_id());
220 i=lista_logic_Items.begin();
223 list_pointed.clear();
224 list_pointed.push_back(" ");
225 combo_entry->set_popdown_strings(list_pointed);
226 combo_entry->get_entry()->set_text("");
229 void Constructor::on_chk_btn_logica_clicked()
232 CItem::logic_connect = !CItem::logic_connect;
233 workplace->queue_draw();
236 void Constructor::on_load_from_xml()
238 on_edit_menu_delete_all();
239 file_name = file_open_selection->get_filename();
241 /* Parseo de ejemplo de un XML desde archivo */
243 document = xmlParseFile(file_name.c_str());
244 if (document == NULL) {
245 // TODO : dar un aviso de que no se pudo abrir el archivo!!
249 /* bien, el archivo se parseo bien! */
250 xmlNodePtr nodo, items;
251 nodo = document->children;
255 if (strcmp((char *)nodo->name, "planta") == 0) {
256 items = nodo->children;
257 while (items != NULL) {
259 if (items->type == XML_ELEMENT_NODE) {
260 std::cout << "ITEM" << std::endl;
261 if (xmlStrcmp(items->name, BAD_CAST"bomba")==0) {
262 current = loadBomba(items);
263 } else if (xmlStrcmp(items->name, BAD_CAST"tubo")==0) {
264 current = loadConduct(items);
265 } else if (xmlStrcmp(items->name, BAD_CAST"codo")==0) {
266 current = loadCodo(items);
267 } else if (xmlStrcmp(items->name, BAD_CAST"exclusa")==0) {
268 current = loadExclusa(items);
269 } else if (xmlStrcmp(items->name, BAD_CAST"tanque")==0) {
270 current = loadTank(items);
271 } else if (xmlStrcmp(items->name, BAD_CAST"empalme")==0) {
272 current = loadUnion(items);
273 } else if (xmlStrcmp(items->name, BAD_CAST"drenaje")==0) {
274 current = loadDrain(items);
275 } else if (xmlStrcmp(items->name, BAD_CAST"and")==0) {
276 current = loadAnd(items);
277 } else if (xmlStrcmp(items->name, BAD_CAST"not")==0) {
278 current = loadNot(items);
279 } else if (xmlStrcmp(items->name, BAD_CAST"or")==0) {
280 current = loadOr(items);
283 if (current != NULL) {
284 if (! current->is_logic )
285 listaItems.push_back(current);
287 lista_logic_Items.push_back(current);
289 // Agrego y conecto la bomba
290 current->drag_source_set(listTargets);
291 workplace->put(*current, current->get_position_x(), current->get_position_y());
292 //Apunto al workplace
293 current->workplace= workplace;
295 current->combo_entry = combo_entry;
296 //Apunto a la lista de apuntados
297 current->list_pointed = &list_pointed;
298 //Apunto a la listaItems.
299 current->listaItems = &listaItems;
300 //Apunto a la lista de items logicos
301 current->lista_logic_Items = &lista_logic_Items;
302 //Apunto a la barra de estado
303 current->status_bar = status_bar;
304 // Conecto las señales
305 current->signal_drag_data_get().connect( SigC::slot(*this, &Constructor::on_item_drag_data_get));
306 current->signal_drag_begin().connect(SigC::bind( SigC::slot(*this, &Constructor::on_item_drag_begin), current));
313 create_lines(document->children);
314 xmlFreeDoc(document);
315 workplace->update_logic_position();
316 workplace->queue_draw();
318 // TODO : avisar que el XML no es valido!!
320 std::cout << "CARGA COMPLETA" << std::endl;
321 file_open_selection->hide();
322 id = listaItems.size()+lista_logic_Items.size()+2;
325 void Constructor::on_btn_file_ok_clicked()
327 std::list<CItem *>::iterator i = listaItems.begin();
328 file_name = file_selection->get_filename();
330 if ( (archivo = fopen( file_name.c_str(), "w+")) != NULL ){
331 fprintf(archivo, "<?xml version=\"1.0\" encoding=\"iso-8859-1\" ?>\n");
332 fprintf (archivo,"<planta>\n");
333 while ( i != listaItems.end() ){
337 i = lista_logic_Items.begin();
338 while ( i != lista_logic_Items.end() ) {
342 fprintf(archivo,"</planta>\n");
346 std::cout<<"NO SE ABRIO EL ARCHIVO"<<std::endl;
347 file_selection->hide();
350 void Constructor::on_quick_btn_save_clicked()
355 on_btn_file_ok_clicked();
359 void Constructor::on_quick_btn_new_clicked()
361 on_quick_btn_delete_all_clicked();
365 void Constructor::on_quick_btn_delete_all_clicked()
367 on_edit_menu_delete_all();
370 void Constructor::on_btn_find_clicked()
373 std::list<CItem *>::iterator i = listaItems.begin();
374 while ( i !=listaItems.end() ) {
375 if ( (*i)->get_name() == combo_entry->get_entry()->get_text() ) {
382 i = lista_logic_Items.begin();
383 while ( i !=lista_logic_Items.end() ) {
384 if ( (*i)->get_name() == combo_entry->get_entry()->get_text() ) {
391 workplace->get_window()->draw_rectangle(workplace->get_style()->get_black_gc(), false , temp->get_position_x()-5, temp->get_position_y()-5,
392 temp->get_image()->get_width()+10, temp->get_image()->get_height()+10);
395 void Constructor::on_btn_file_cancel_clicked()
397 file_selection->hide();
400 void Constructor::on_btn_open_cancel_clicked()
402 file_open_selection->hide();
405 void Constructor::on_btn_dlg_connect_clicked()
410 void Constructor::on_canio_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)
412 context->set_icon(ico_canio, 5, 5);
415 void Constructor::on_y_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)
417 context->set_icon(ico_y, 5, 5);
420 void Constructor::on_codo_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)
422 context->set_icon(ico_codo, 5, 5);
425 void Constructor::on_tanque_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)
427 context->set_icon(ico_tanque, 5, 5);
430 void Constructor::on_bomba_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)
432 context->set_icon(ico_bomba, 5, 5);
435 void Constructor::on_exclusa_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)
437 context->set_icon(ico_exclusa, 5, 5);
440 void Constructor::on_drain_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)
442 context->set_icon(ico_drain, 5, 5);
445 void Constructor::on_and_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)
447 context->set_icon(ico_and, 5, 5);
450 void Constructor::on_or_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)
452 context->set_icon(ico_or, 5, 5);
455 void Constructor::on_not_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)
457 context->set_icon(ico_not, 5, 5);
460 void Constructor::on_item_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context, CItem *item)
462 context->set_icon(item->get_image(), 5, 5);
465 void Constructor::on_item_drag_data_get(const Glib::RefPtr<Gdk::DragContext>& context, GtkSelectionData* selection_data, guint info, guint time)
467 gtk_selection_data_set (selection_data, selection_data->target, 10, (const guchar*)"item_codo.png", 13);
470 bool Constructor::can_drop(CItem *item, int _x, int _y)
472 std::list<CItem*>::iterator i = listaItems.begin();
473 while( i != listaItems.end() ) {
475 if ( temp->get_id() != item->get_id() ) {
476 if ( (temp->is_occupied_area(_x, _y)) ||
477 ( temp->is_occupied_area(_x+item->get_image()->get_width()-1, _y+item->get_image()->get_height()-1)) ||
478 ( temp->is_occupied_area(_x, _y+item->get_image()->get_height()-1)) ||
479 ( temp->is_occupied_area(_x+item->get_image()->get_width()-1, _y) ) )
488 void Constructor::on_item_drop_drag_received(const Glib::RefPtr<Gdk::DragContext>& context, int x, int y, GtkSelectionData* selection_data, guint info, guint time)
490 workplace->update_logic_position();
491 workplace->queue_draw();
493 /* Ajusto coordenada x e y para que caigan en un lugar de una cuadricula de 32x32 */
495 // el +1 es para evitar un bug cuando se selecciona muy cerce de la
496 // separacion de 2 cuadritos
499 // El drag es de un item
500 if (selection_data->format == 10) {
501 if (can_drop(((CItem*)drag_get_source_widget(context)),i*32, j*32)){
502 ((CItem*)drag_get_source_widget(context))->set_position(i*32, j*32);
503 workplace->move(*drag_get_source_widget(context), i*32, j*32);
507 // El Drag es desde la barra de tareas
508 if ((selection_data->length >= 0) && (selection_data->format == 8)) {
510 if (strcmp((const char *)selection_data->data, "codo_o.png")==0)
512 else if (strcmp((const char *)selection_data->data, "canio_n.png")==0)
514 else if (strcmp((const char *)selection_data->data, "y_n.png")==0)
516 else if (strcmp((const char *)selection_data->data, "tanque_e.png")==0)
518 else if (strcmp((const char *)selection_data->data, "bomba_e.png")==0)
520 else if (strcmp((const char *)selection_data->data, "exclusa_h.png")==0)
522 else if (strcmp((const char *)selection_data->data, "drain_n.png")==0)
524 else if (strcmp((const char *)selection_data->data, "and_e.png")==0){
525 a = new And(); a->is_logic = true;
526 } else if (strcmp((const char *)selection_data->data, "or_e.png")==0) {
527 a = new Or(); a->is_logic = true;
528 } else if (strcmp((const char *)selection_data->data, "not_e.png")==0) {
529 a = new Not(); a->is_logic = true;
533 sprintf(char_id,"%d",id);
535 a->set_name( a->get_name()+char_id );
536 if ( can_drop(a, i*32, j*32) ) {
537 workplace->put(*a, i*32, j*32);
538 //Apunto al workplace
539 a->workplace = workplace;
541 a->combo_entry = combo_entry;
542 //Apunto a la lista de apuntados
543 a->list_pointed = &list_pointed;
544 //Apunto a la listaItems.
545 a->listaItems = &listaItems;
546 //Apunto a la barra de estado
547 a->status_bar = status_bar;
548 //Apunto a la lista de items logicos
549 a->lista_logic_Items = &lista_logic_Items;
550 //Seteo la posicion del item
551 a->set_position(i*32,j*32);
552 // Seteo la lista de tipos de drags
553 a->drag_source_set(listTargets);
554 // Conecto las señales
555 a->signal_drag_data_get().connect( SigC::slot(*this, &Constructor::on_item_drag_data_get));
556 // Utilizo el SigC::bind para que el callback on_drag_begin acepte un
557 // parametro extra, en este caso un CItem *. Esto se hace para
558 // que cuando el usuario quiera mover un item, saber que item es
559 // y pedirle su ícono para mostrar cono icono durante la operacion,
560 // Esto va a permitir, que si un widget tiene una imagen rotara o algo
561 // raro se vea el widget tal cual.
562 a->signal_drag_begin().connect(SigC::bind( SigC::slot(*this, &Constructor::on_item_drag_begin), a));
565 listaItems.push_back(a);
567 lista_logic_Items.push_back(a);
573 context->drag_finish(false, false, time);
575 workplace->update_logic_position();
576 workplace->queue_draw();
579 void Constructor::on_btn_check_clicked()
582 if ( ! check_connection(name) ) {
583 dlg_connect->set_title("Error");
584 dlg_label->set_text("El elemento "+name+" no esta conectado\n\t\tcorrectamente");
587 dlg_connect->set_title("Conexion");
588 dlg_label->set_text("Los elementos estan conectados\n\t\tcorrectamente");
594 bool Constructor::check_connection(Glib::ustring& name)
596 std::list<CItem *>::iterator i = listaItems.begin();
597 while ( i != listaItems.end() ){
598 (*i)->set_default_connector();
599 (*i)->is_connected = false;
602 i = listaItems.begin();
603 if ( !listaItems.empty() ) {
604 while ( i != listaItems.end() ) {
606 std::cout<< "item="<<temp->get_name()<<" "<<"check= "<<temp->check_connection()<<std::endl;
607 if ( !temp->check_connection() ) {
608 name = temp->get_name();
614 std::cout<<"check_connection logic"<<std::endl;
615 std::list<CItem *>::iterator j = lista_logic_Items.begin();
616 while ( j != lista_logic_Items.end() ) {
617 if ( !(*j)->check_connection() ) {
618 name = (*j)->get_name();
626 Not *Constructor::loadNot(xmlNodePtr nodo)
628 std::string name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
629 std::string id = (char *)xmlGetProp(nodo, BAD_CAST"id");
630 int orientacion=0, x, y;
632 nodo = nodo->children;
633 while (nodo != NULL) {
634 if (nodo->type == XML_ELEMENT_NODE) {
635 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
636 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
637 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
638 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
639 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
640 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
646 Not *p = new Not(orientacion);
647 p->set_position(x,y);
648 p->set_id( atoi(id.c_str()) );
654 Or *Constructor::loadOr(xmlNodePtr nodo)
656 std::string name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
657 std::string id = (char *)xmlGetProp(nodo, BAD_CAST"id");
658 int orientacion=0, x, y;
660 nodo = nodo->children;
661 while (nodo != NULL) {
662 if (nodo->type == XML_ELEMENT_NODE) {
663 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
664 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
665 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
666 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
667 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
668 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
674 Or *p = new Or(orientacion);
675 p->set_position(x,y);
676 p->set_id( atoi(id.c_str()) );
682 And *Constructor::loadAnd(xmlNodePtr nodo)
684 std::string name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
685 std::string id = (char *)xmlGetProp(nodo, BAD_CAST"id");
686 int orientacion=0, x, y;
688 xmlNodePtr inicial = nodo;
690 nodo = nodo->children;
691 while (nodo != NULL) {
692 if (nodo->type == XML_ELEMENT_NODE) {
693 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
694 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
695 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
696 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
697 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
698 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
704 And *p = new And(orientacion);
705 p->set_position(x,y);
706 p->set_id( atoi(id.c_str()) );
711 Pump *Constructor::loadBomba(xmlNodePtr nodo)
713 std::string name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
714 std::string id = (char *)xmlGetProp(nodo, BAD_CAST"id");
715 int orientacion=0, x, y;
718 nodo = nodo->children;
719 while (nodo != NULL) {
720 if (nodo->type == XML_ELEMENT_NODE) {
721 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
722 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
723 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
724 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
725 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
726 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
727 } else if (xmlStrcmp(nodo->name, BAD_CAST"entrega") == 0) {
728 flujo = atof( (char *)XML_GET_CONTENT(nodo->children) );
729 } else if (xmlStrcmp(nodo->name, BAD_CAST"color") == 0) {
736 Pump *p = new Pump(orientacion);
737 p->set_position(x,y);
738 p->set_entrega(flujo);
739 p->set_id( atoi(id.c_str()) );
745 Conduct *Constructor::loadConduct(xmlNodePtr nodo)
747 std::string name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
748 std::string id = (char *)xmlGetProp(nodo, BAD_CAST"id");
749 int orientacion=0, x, y;
752 nodo = nodo->children;
753 while (nodo != NULL) {
754 if (nodo->type == XML_ELEMENT_NODE) {
755 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
756 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
757 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
758 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
759 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
760 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
761 } else if (xmlStrcmp(nodo->name, BAD_CAST"caudal") == 0) {
762 flujo = atof( (char *)XML_GET_CONTENT(nodo->children) );
768 Conduct *p = new Conduct(orientacion);
769 p->set_position(x,y);
770 p->set_caudal(flujo);
771 p->set_id( atoi(id.c_str()) );
777 Exclusa *Constructor::loadExclusa(xmlNodePtr nodo)
779 std::string name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
780 std::string id = (char *)xmlGetProp(nodo, BAD_CAST"id");
782 int orientacion=0, x, y;
785 nodo = nodo->children;
786 while (nodo != NULL) {
787 if (nodo->type == XML_ELEMENT_NODE) {
788 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
789 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
790 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
791 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
792 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
793 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
794 } else if (xmlStrcmp(nodo->name, BAD_CAST"estado") == 0) {
795 estado = (char *)XML_GET_CONTENT(nodo->children);
801 Exclusa *p = new Exclusa(orientacion);
802 p->set_position(x,y);
803 p->set_id( atoi(id.c_str()) );
805 p->set_estado( estado == "1" );
810 Cistern *Constructor::loadTank(xmlNodePtr nodo)
812 std::string name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
813 std::string id = (char *)xmlGetProp(nodo, BAD_CAST"id");
814 int orientacion=0, x, y;
815 float liquido,capacidad;
817 nodo = nodo->children;
818 while (nodo != NULL) {
819 if (nodo->type == XML_ELEMENT_NODE) {
820 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
821 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
822 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
823 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
824 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
825 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
826 } else if (xmlStrcmp(nodo->name, BAD_CAST"capacidad") == 0) {
827 capacidad = atof ((char *)XML_GET_CONTENT(nodo->children) );
828 } else if (xmlStrcmp(nodo->name, BAD_CAST"inicial") == 0) {
829 liquido = atof ((char *)XML_GET_CONTENT(nodo->children) );
835 Cistern *p = new Cistern(orientacion);
836 p->set_position(x,y);
837 p->set_id( atoi(id.c_str()) );
839 p->set_capacidad(capacidad);
840 p->set_contenido_inicial(liquido);
845 Union *Constructor::loadUnion(xmlNodePtr nodo)
847 std::string name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
848 std::string id = (char *)xmlGetProp(nodo, BAD_CAST"id");
850 int orientacion=0, x, y;
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 caudal = atof ((char *)XML_GET_CONTENT(nodo->children) );
864 } else if (xmlStrcmp(nodo->name, BAD_CAST"tipo") == 0) {
865 tipo = (char *)XML_GET_CONTENT(nodo->children);
871 Union *p = new Union(orientacion);
872 p->set_position(x,y);
873 p->set_id( atoi(id.c_str()) );
875 p->set_caudal(caudal);
876 p->is_union = (tipo == "union");
881 Drain *Constructor::loadDrain(xmlNodePtr nodo)
883 std::string name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
884 std::string id = (char *)xmlGetProp(nodo, BAD_CAST"id");
885 int orientacion=0, x, y;
887 nodo = nodo->children;
888 while (nodo != NULL) {
889 if (nodo->type == XML_ELEMENT_NODE) {
890 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
891 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
892 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
893 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
894 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
895 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
901 Drain *p = new Drain(orientacion);
902 p->set_position(x,y);
903 p->set_id( atoi(id.c_str()) );
909 Splitter *Constructor::loadCodo(xmlNodePtr nodo)
911 std::string name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
912 std::string id = (char *)xmlGetProp(nodo, BAD_CAST"id");
913 int orientacion=0, x, y;
916 nodo = nodo->children;
917 while (nodo != NULL) {
918 if (nodo->type == XML_ELEMENT_NODE) {
919 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
920 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
921 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
922 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
923 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
924 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
925 } else if (xmlStrcmp(nodo->name, BAD_CAST"caudal") == 0) {
926 caudal = atof( (char *)XML_GET_CONTENT(nodo->children) );
932 Splitter *p = new Splitter(orientacion);
933 p->set_position(x,y);
934 p->set_id( atoi(id.c_str()) );
936 p->set_caudal(caudal);
941 void Constructor::create_lines(xmlNodePtr nodo)
945 nodo = nodo->children;
946 while (nodo != NULL) {
947 if (nodo->type == XML_ELEMENT_NODE) {
948 if (xmlStrcmp(nodo->name, BAD_CAST"and")==0) {
949 name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
950 std::cout << name << std::endl;
951 create_line(nodo->children, workplace->get_logic_id(name));
952 } else if (xmlStrcmp(nodo->name, BAD_CAST"not")==0) {
953 name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
954 std::cout << name << std::endl;
955 create_line(nodo->children, workplace->get_logic_id(name));
956 } else if (xmlStrcmp(nodo->name, BAD_CAST"or")==0) {
957 name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
958 std::cout << name << std::endl;
959 create_line(nodo->children, workplace->get_logic_id(name));
966 void Constructor::create_line(xmlNodePtr nodo, int logic_id)
969 std::cout << "Buscando lineas ..." << std::endl;
970 while (nodo != NULL) {
971 if (nodo->type == XML_ELEMENT_NODE) {
972 if (xmlStrcmp(nodo->name, BAD_CAST"salida")==0) {
973 otro = (char *)XML_GET_CONTENT(nodo->children);
975 tmp_line.logic_id = logic_id;
976 //workplace->get_logic_item(logic_id)->set_out_connected(true);
977 tmp_line.store_id = workplace->get_item_id(otro);
978 std::cout << otro << " " << tmp_line.logic_id << " " << tmp_line.store_id << std::endl;
979 workplace->lista_lineas_in.push_back(tmp_line);
980 } else if (xmlStrcmp(nodo->name, BAD_CAST"entrada")==0) {
981 otro = (char *)XML_GET_CONTENT(nodo->children);
983 tmp_line.logic_id = logic_id;
984 tmp_line.store_id = workplace->get_item_id(otro);
985 workplace->lista_lineas_out.push_back(tmp_line);
986 std::cout << otro << " " << tmp_line.logic_id << " " << tmp_line.store_id << std::endl;