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();
323 int id_1 = -1 , id_2 = -1;
324 std::list<CItem *>::iterator i = listaItems.begin();
325 while ( i != listaItems.end() ){
326 if ( (*i)->get_id() >= id_1 )
327 id_1 = (*i)->get_id();
332 i = lista_logic_Items.begin();
333 while ( i != lista_logic_Items.end() ){
334 if ( (*i)->get_id() >= id_2 )
335 id_2 = (*i)->get_id();
339 if ( id_1 < id_2 ) id = id_2;
343 void Constructor::on_btn_file_ok_clicked()
345 std::list<CItem *>::iterator i = listaItems.begin();
346 file_name = file_selection->get_filename();
348 if ( (archivo = fopen( file_name.c_str(), "w+")) != NULL ){
349 fprintf(archivo, "<?xml version=\"1.0\" encoding=\"iso-8859-1\" ?>\n");
350 fprintf (archivo,"<planta>\n");
351 while ( i != listaItems.end() ){
355 i = lista_logic_Items.begin();
356 while ( i != lista_logic_Items.end() ) {
360 fprintf(archivo,"</planta>\n");
364 std::cout<<"NO SE ABRIO EL ARCHIVO"<<std::endl;
365 file_selection->hide();
368 void Constructor::on_quick_btn_save_clicked()
373 on_btn_file_ok_clicked();
377 void Constructor::on_quick_btn_new_clicked()
379 on_quick_btn_delete_all_clicked();
383 void Constructor::on_quick_btn_delete_all_clicked()
385 on_edit_menu_delete_all();
388 void Constructor::on_btn_find_clicked()
391 std::list<CItem *>::iterator i = listaItems.begin();
392 while ( i !=listaItems.end() ) {
393 if ( (*i)->get_name() == combo_entry->get_entry()->get_text() ) {
400 i = lista_logic_Items.begin();
401 while ( i !=lista_logic_Items.end() ) {
402 if ( (*i)->get_name() == combo_entry->get_entry()->get_text() ) {
409 workplace->get_window()->draw_rectangle(workplace->get_style()->get_black_gc(), false , temp->get_position_x()-5, temp->get_position_y()-5,
410 temp->get_image()->get_width()+10, temp->get_image()->get_height()+10);
413 void Constructor::on_btn_file_cancel_clicked()
415 file_selection->hide();
418 void Constructor::on_btn_open_cancel_clicked()
420 file_open_selection->hide();
423 void Constructor::on_btn_dlg_connect_clicked()
428 void Constructor::on_canio_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)
430 context->set_icon(ico_canio, 5, 5);
433 void Constructor::on_y_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)
435 context->set_icon(ico_y, 5, 5);
438 void Constructor::on_codo_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)
440 context->set_icon(ico_codo, 5, 5);
443 void Constructor::on_tanque_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)
445 context->set_icon(ico_tanque, 5, 5);
448 void Constructor::on_bomba_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)
450 context->set_icon(ico_bomba, 5, 5);
453 void Constructor::on_exclusa_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)
455 context->set_icon(ico_exclusa, 5, 5);
458 void Constructor::on_drain_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)
460 context->set_icon(ico_drain, 5, 5);
463 void Constructor::on_and_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)
465 context->set_icon(ico_and, 5, 5);
468 void Constructor::on_or_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)
470 context->set_icon(ico_or, 5, 5);
473 void Constructor::on_not_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)
475 context->set_icon(ico_not, 5, 5);
478 void Constructor::on_item_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context, CItem *item)
480 context->set_icon(item->get_image(), 5, 5);
483 void Constructor::on_item_drag_data_get(const Glib::RefPtr<Gdk::DragContext>& context, GtkSelectionData* selection_data, guint info, guint time)
485 gtk_selection_data_set (selection_data, selection_data->target, 10, (const guchar*)"item_codo.png", 13);
488 bool Constructor::can_drop(CItem *item, int _x, int _y)
490 std::list<CItem*>::iterator i = listaItems.begin();
491 while( i != listaItems.end() ) {
493 if ( temp->get_id() != item->get_id() ) {
494 if ( (temp->is_occupied_area(_x, _y)) ||
495 ( temp->is_occupied_area(_x+item->get_image()->get_width()-1, _y+item->get_image()->get_height()-1)) ||
496 ( temp->is_occupied_area(_x, _y+item->get_image()->get_height()-1)) ||
497 ( temp->is_occupied_area(_x+item->get_image()->get_width()-1, _y) ) )
506 void Constructor::on_item_drop_drag_received(const Glib::RefPtr<Gdk::DragContext>& context, int x, int y, GtkSelectionData* selection_data, guint info, guint time)
508 workplace->update_logic_position();
509 workplace->queue_draw();
511 /* Ajusto coordenada x e y para que caigan en un lugar de una cuadricula de 32x32 */
513 // el +1 es para evitar un bug cuando se selecciona muy cerce de la
514 // separacion de 2 cuadritos
517 // El drag es de un item
518 if (selection_data->format == 10) {
519 if (can_drop(((CItem*)drag_get_source_widget(context)),i*32, j*32)){
520 ((CItem*)drag_get_source_widget(context))->set_position(i*32, j*32);
521 workplace->move(*drag_get_source_widget(context), i*32, j*32);
525 // El Drag es desde la barra de tareas
526 if ((selection_data->length >= 0) && (selection_data->format == 8)) {
528 if (strcmp((const char *)selection_data->data, "codo_o.png")==0)
530 else if (strcmp((const char *)selection_data->data, "canio_n.png")==0)
532 else if (strcmp((const char *)selection_data->data, "y_n.png")==0)
534 else if (strcmp((const char *)selection_data->data, "tanque_e.png")==0)
536 else if (strcmp((const char *)selection_data->data, "bomba_e.png")==0)
538 else if (strcmp((const char *)selection_data->data, "exclusa_h.png")==0)
540 else if (strcmp((const char *)selection_data->data, "drain_n.png")==0)
542 else if (strcmp((const char *)selection_data->data, "and_e.png")==0){
543 a = new And(); a->is_logic = true;
544 } else if (strcmp((const char *)selection_data->data, "or_e.png")==0) {
545 a = new Or(); a->is_logic = true;
546 } else if (strcmp((const char *)selection_data->data, "not_e.png")==0) {
547 a = new Not(); a->is_logic = true;
551 sprintf(char_id,"%d",id);
553 a->set_name( a->get_name()+char_id );
554 if ( can_drop(a, i*32, j*32) ) {
555 workplace->put(*a, i*32, j*32);
556 //Apunto al workplace
557 a->workplace = workplace;
559 a->combo_entry = combo_entry;
560 //Apunto a la lista de apuntados
561 a->list_pointed = &list_pointed;
562 //Apunto a la listaItems.
563 a->listaItems = &listaItems;
564 //Apunto a la barra de estado
565 a->status_bar = status_bar;
566 //Apunto a la lista de items logicos
567 a->lista_logic_Items = &lista_logic_Items;
568 //Seteo la posicion del item
569 a->set_position(i*32,j*32);
570 // Seteo la lista de tipos de drags
571 a->drag_source_set(listTargets);
572 // Conecto las señales
573 a->signal_drag_data_get().connect( SigC::slot(*this, &Constructor::on_item_drag_data_get));
574 // Utilizo el SigC::bind para que el callback on_drag_begin acepte un
575 // parametro extra, en este caso un CItem *. Esto se hace para
576 // que cuando el usuario quiera mover un item, saber que item es
577 // y pedirle su ícono para mostrar cono icono durante la operacion,
578 // Esto va a permitir, que si un widget tiene una imagen rotara o algo
579 // raro se vea el widget tal cual.
580 a->signal_drag_begin().connect(SigC::bind( SigC::slot(*this, &Constructor::on_item_drag_begin), a));
583 listaItems.push_back(a);
585 lista_logic_Items.push_back(a);
591 context->drag_finish(false, false, time);
593 workplace->update_logic_position();
594 workplace->queue_draw();
597 void Constructor::on_btn_check_clicked()
600 if ( ! check_connection(name) ) {
601 dlg_connect->set_title("Error");
602 dlg_label->set_text("El elemento "+name+" no esta conectado\n\t\tcorrectamente");
605 dlg_connect->set_title("Conexion");
606 dlg_label->set_text("Los elementos estan conectados\n\t\tcorrectamente");
612 bool Constructor::check_connection(Glib::ustring& name)
614 std::list<CItem *>::iterator i = listaItems.begin();
615 while ( i != listaItems.end() ){
616 (*i)->set_default_connector();
617 (*i)->is_connected = false;
620 i = listaItems.begin();
621 if ( !listaItems.empty() ) {
622 while ( i != listaItems.end() ) {
624 std::cout<< "item="<<temp->get_name()<<" "<<"check= "<<temp->check_connection()<<std::endl;
625 if ( !temp->check_connection() ) {
626 name = temp->get_name();
632 std::cout<<"check_connection logic"<<std::endl;
633 std::list<CItem *>::iterator j = lista_logic_Items.begin();
634 while ( j != lista_logic_Items.end() ) {
635 if ( !(*j)->check_connection() ) {
636 name = (*j)->get_name();
644 Not *Constructor::loadNot(xmlNodePtr nodo)
646 std::string name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
647 std::string id = (char *)xmlGetProp(nodo, BAD_CAST"id");
648 int orientacion=0, x, y;
650 nodo = nodo->children;
651 while (nodo != NULL) {
652 if (nodo->type == XML_ELEMENT_NODE) {
653 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
654 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
655 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
656 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
657 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
658 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
664 Not *p = new Not(orientacion);
665 p->set_position(x,y);
666 p->set_id( atoi(id.c_str()) );
672 Or *Constructor::loadOr(xmlNodePtr nodo)
674 std::string name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
675 std::string id = (char *)xmlGetProp(nodo, BAD_CAST"id");
676 int orientacion=0, x, y;
678 nodo = nodo->children;
679 while (nodo != NULL) {
680 if (nodo->type == XML_ELEMENT_NODE) {
681 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
682 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
683 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
684 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
685 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
686 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
692 Or *p = new Or(orientacion);
693 p->set_position(x,y);
694 p->set_id( atoi(id.c_str()) );
700 And *Constructor::loadAnd(xmlNodePtr nodo)
702 std::string name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
703 std::string id = (char *)xmlGetProp(nodo, BAD_CAST"id");
704 int orientacion=0, x, y;
706 xmlNodePtr inicial = nodo;
708 nodo = nodo->children;
709 while (nodo != NULL) {
710 if (nodo->type == XML_ELEMENT_NODE) {
711 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
712 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
713 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
714 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
715 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
716 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
722 And *p = new And(orientacion);
723 p->set_position(x,y);
724 p->set_id( atoi(id.c_str()) );
729 Pump *Constructor::loadBomba(xmlNodePtr nodo)
731 std::string name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
732 std::string id = (char *)xmlGetProp(nodo, BAD_CAST"id");
733 int orientacion=0, x, y;
736 nodo = nodo->children;
737 while (nodo != NULL) {
738 if (nodo->type == XML_ELEMENT_NODE) {
739 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
740 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
741 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
742 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
743 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
744 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
745 } else if (xmlStrcmp(nodo->name, BAD_CAST"entrega") == 0) {
746 flujo = atof( (char *)XML_GET_CONTENT(nodo->children) );
747 } else if (xmlStrcmp(nodo->name, BAD_CAST"color") == 0) {
754 Pump *p = new Pump(orientacion);
755 p->set_position(x,y);
756 p->set_entrega(flujo);
757 p->set_id( atoi(id.c_str()) );
763 Conduct *Constructor::loadConduct(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 flujo = atof( (char *)XML_GET_CONTENT(nodo->children) );
786 Conduct *p = new Conduct(orientacion);
787 p->set_position(x,y);
788 p->set_caudal(flujo);
789 p->set_id( atoi(id.c_str()) );
795 Exclusa *Constructor::loadExclusa(xmlNodePtr nodo)
797 std::string name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
798 std::string id = (char *)xmlGetProp(nodo, BAD_CAST"id");
800 int orientacion=0, x, y;
803 nodo = nodo->children;
804 while (nodo != NULL) {
805 if (nodo->type == XML_ELEMENT_NODE) {
806 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
807 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
808 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
809 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
810 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
811 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
812 } else if (xmlStrcmp(nodo->name, BAD_CAST"estado") == 0) {
813 estado = (char *)XML_GET_CONTENT(nodo->children);
819 Exclusa *p = new Exclusa(orientacion);
820 p->set_position(x,y);
821 p->set_id( atoi(id.c_str()) );
823 p->set_estado( estado == "1" );
828 Cistern *Constructor::loadTank(xmlNodePtr nodo)
830 std::string name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
831 std::string id = (char *)xmlGetProp(nodo, BAD_CAST"id");
832 int orientacion=0, x, y;
833 float liquido,capacidad;
835 nodo = nodo->children;
836 while (nodo != NULL) {
837 if (nodo->type == XML_ELEMENT_NODE) {
838 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
839 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
840 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
841 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
842 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
843 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
844 } else if (xmlStrcmp(nodo->name, BAD_CAST"capacidad") == 0) {
845 capacidad = atof ((char *)XML_GET_CONTENT(nodo->children) );
846 } else if (xmlStrcmp(nodo->name, BAD_CAST"inicial") == 0) {
847 liquido = atof ((char *)XML_GET_CONTENT(nodo->children) );
853 Cistern *p = new Cistern(orientacion);
854 p->set_position(x,y);
855 p->set_id( atoi(id.c_str()) );
857 p->set_capacidad(capacidad);
858 p->set_contenido_inicial(liquido);
863 Union *Constructor::loadUnion(xmlNodePtr nodo)
865 std::string name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
866 std::string id = (char *)xmlGetProp(nodo, BAD_CAST"id");
868 int orientacion=0, x, y;
871 nodo = nodo->children;
872 while (nodo != NULL) {
873 if (nodo->type == XML_ELEMENT_NODE) {
874 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
875 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
876 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
877 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
878 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
879 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
880 } else if (xmlStrcmp(nodo->name, BAD_CAST"caudal") == 0) {
881 caudal = atof ((char *)XML_GET_CONTENT(nodo->children) );
882 } else if (xmlStrcmp(nodo->name, BAD_CAST"tipo") == 0) {
883 tipo = (char *)XML_GET_CONTENT(nodo->children);
889 Union *p = new Union(orientacion);
890 p->set_position(x,y);
891 p->set_id( atoi(id.c_str()) );
893 p->set_caudal(caudal);
894 p->is_union = (tipo == "union");
899 Drain *Constructor::loadDrain(xmlNodePtr nodo)
901 std::string name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
902 std::string id = (char *)xmlGetProp(nodo, BAD_CAST"id");
903 int orientacion=0, x, y;
905 nodo = nodo->children;
906 while (nodo != NULL) {
907 if (nodo->type == XML_ELEMENT_NODE) {
908 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
909 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
910 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
911 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
912 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
913 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
919 Drain *p = new Drain(orientacion);
920 p->set_position(x,y);
921 p->set_id( atoi(id.c_str()) );
927 Splitter *Constructor::loadCodo(xmlNodePtr nodo)
929 std::string name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
930 std::string id = (char *)xmlGetProp(nodo, BAD_CAST"id");
931 int orientacion=0, x, y;
934 nodo = nodo->children;
935 while (nodo != NULL) {
936 if (nodo->type == XML_ELEMENT_NODE) {
937 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
938 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
939 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
940 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
941 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
942 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
943 } else if (xmlStrcmp(nodo->name, BAD_CAST"caudal") == 0) {
944 caudal = atof( (char *)XML_GET_CONTENT(nodo->children) );
950 Splitter *p = new Splitter(orientacion);
951 p->set_position(x,y);
952 p->set_id( atoi(id.c_str()) );
954 p->set_caudal(caudal);
959 void Constructor::create_lines(xmlNodePtr nodo)
963 nodo = nodo->children;
964 while (nodo != NULL) {
965 if (nodo->type == XML_ELEMENT_NODE) {
966 if (xmlStrcmp(nodo->name, BAD_CAST"and")==0) {
967 name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
968 std::cout << name << std::endl;
969 create_line(nodo->children, workplace->get_logic_id(name));
970 } else if (xmlStrcmp(nodo->name, BAD_CAST"not")==0) {
971 name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
972 std::cout << name << std::endl;
973 create_line(nodo->children, workplace->get_logic_id(name));
974 } else if (xmlStrcmp(nodo->name, BAD_CAST"or")==0) {
975 name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
976 std::cout << name << std::endl;
977 create_line(nodo->children, workplace->get_logic_id(name));
984 void Constructor::create_line(xmlNodePtr nodo, int logic_id)
987 std::cout << "Buscando lineas ..." << std::endl;
988 while (nodo != NULL) {
989 if (nodo->type == XML_ELEMENT_NODE) {
990 if (xmlStrcmp(nodo->name, BAD_CAST"salida")==0) {
991 otro = (char *)XML_GET_CONTENT(nodo->children);
993 tmp_line.logic_id = logic_id;
994 //workplace->get_logic_item(logic_id)->set_out_connected(true);
995 tmp_line.store_id = workplace->get_item_id(otro);
996 std::cout << otro << " " << tmp_line.logic_id << " " << tmp_line.store_id << std::endl;
997 workplace->lista_lineas_in.push_back(tmp_line);
998 } else if (xmlStrcmp(nodo->name, BAD_CAST"entrada")==0) {
999 otro = (char *)XML_GET_CONTENT(nodo->children);
1001 tmp_line.logic_id = logic_id;
1002 tmp_line.store_id = workplace->get_item_id(otro);
1003 workplace->lista_lineas_out.push_back(tmp_line);
1004 std::cout << otro << " " << tmp_line.logic_id << " " << tmp_line.store_id << std::endl;