From: Nicolás Dimov Date: Wed, 5 Nov 2003 03:06:27 +0000 (+0000) Subject: casi no se solapan items, y ademas se pueden eliminar X-Git-Tag: svn_import~349 X-Git-Url: https://git.llucax.com/z.facultad/75.42/plaqui.git/commitdiff_plain/67143e098c00b0ee414bde39a78441d8e11fed8b?ds=sidebyside casi no se solapan items, y ademas se pueden eliminar --- diff --git a/Constructor/cistern.cpp b/Constructor/cistern.cpp index 1764a40..1495443 100644 --- a/Constructor/cistern.cpp +++ b/Constructor/cistern.cpp @@ -49,6 +49,8 @@ bool Cistern::on_button_press_event(GdkEventButton *event) } if ((event->type == GDK_2BUTTON_PRESS) && (event->button ==1)){ + cistern_pty_wnd->spin_caudal->set_value((double)x); + cistern_pty_wnd->spin_fluido_max->set_value((double)y); cistern_pty_wnd->show(); } return true; @@ -64,8 +66,9 @@ void Cistern::on_menu_popup_rotar() void Cistern::on_menu_popup_propiedades() { - cistern_pty_wnd->spin_caudal->set_value(caudal); - cistern_pty_wnd->spin_fluido_max->set_value(fluido_max); +// cistern_pty_wnd->spin_caudal->set_value(caudal); +// cistern_pty_wnd->spin_fluido_max->set_value(fluido_max); + std::cout<< "posicion = "<< x <<" "<< y < class Cistern : public CItem { public: diff --git a/Constructor/constructor.cpp b/Constructor/constructor.cpp index caa74f8..2f11221 100644 --- a/Constructor/constructor.cpp +++ b/Constructor/constructor.cpp @@ -3,6 +3,7 @@ Constructor::Constructor(BaseObjectType* cobject, const Glib::RefPtr& refGlade):Gtk::Window(cobject) { + id = 0; set_title("Constructor"); @@ -16,6 +17,7 @@ Constructor::Constructor(BaseObjectType* cobject, const Glib::RefPtrget_widget("btn_y", btn_y); refGlade->get_widget("btn_tanque",btn_tanque); refGlade->get_widget("main_menu_quit",main_menu_quit); + refGlade->get_widget("edit_menu_del",edit_menu_del); refGlade->get_widget_derived("workplace", workplace); //fixed @@ -38,6 +40,7 @@ Constructor::Constructor(BaseObjectType* cobject, const Glib::RefPtrsignal_drag_data_get().connect( SigC::slot(*this, &Constructor::on_btn_tanque_drag_get)); main_menu_quit->signal_activate().connect(SigC::slot(*this, &Constructor::on_main_menu_quit)); + edit_menu_del->signal_activate().connect(SigC::slot(*this,&Constructor::on_edit_menu_del)); // Señales para cambiar el icono cuando empieza el drag. btn_canio->signal_drag_begin().connect( SigC::slot(*this, &Constructor::on_canio_drag_begin)); @@ -48,11 +51,22 @@ Constructor::Constructor(BaseObjectType* cobject, const Glib::RefPtrdrag_dest_set(listTargets); workplace->signal_drag_data_received().connect( SigC::slot(*this, &Constructor::on_item_drop_drag_received) ); + workplace->listaItems = &listaItems; } Constructor::~Constructor() { + std::list::iterator i = listaItems.begin(); + std::cout << "ok" << std::endl; + while ( i != listaItems.end() ){ + CItem *temp = *i; + listaItems.erase(i); + std::cout << "Elimnando ... " << std::endl; + delete temp; + i = listaItems.begin(); + } } + void Constructor::on_btn_canio_drag_get(const Glib::RefPtr& context, GtkSelectionData* selection_data, guint info, guint time) { gtk_selection_data_set (selection_data, selection_data->target, 8, (const guchar*)"item_canio.png", 14); @@ -75,9 +89,14 @@ void Constructor::on_btn_tanque_drag_get(const Glib::RefPtr& c void Constructor::on_main_menu_quit() { - Gtk::Main::quit(); + //Gtk::Main::quit(); + hide(); } +void Constructor::on_edit_menu_del() +{ + // hay que meter algo aca. +} void Constructor::on_canio_drag_begin(const Glib::RefPtr& context) { context->set_icon(ico_canio, 5, 5); @@ -108,6 +127,24 @@ void Constructor::on_item_drag_data_get(const Glib::RefPtr& co gtk_selection_data_set (selection_data, selection_data->target, 10, (const guchar*)"item_codo.png", 13); } +bool Constructor::can_drop(CItem *item, int x, int y) +{ + std::list::iterator i = listaItems.begin(); + while( i != listaItems.end() ) { + CItem *temp = *i; + if ( temp->get_id() != item->get_id() ) { + if ( (temp->is_occupied_area(x, y)) || + ( temp->is_occupied_area(x+item->get_image()->get_width()-1, y+item->get_image()->get_height()-1)) || + ( temp->is_occupied_area(x, y+item->get_image()->get_height()-1)) || + ( temp->is_occupied_area(x+item->get_image()->get_width()-1, y) ) ) + return false; + else i++; + } + else i++; + } + return true; +} + void Constructor::on_item_drop_drag_received(const Glib::RefPtr& context, int x, int y, GtkSelectionData* selection_data, guint info, guint time) { /* Ajusto coordenada x e y para que caigan en un lugar de una cuadricula de 32x32 */ @@ -118,7 +155,10 @@ void Constructor::on_item_drop_drag_received(const Glib::RefPtrformat == 10) { - workplace->move(*drag_get_source_widget(context), i*32, j*32); + if (can_drop(((CItem*)drag_get_source_widget(context)),i*32, j*32)){ + ((CItem*)drag_get_source_widget(context))->set_position(i*32, j*32); + workplace->move(*drag_get_source_widget(context), i*32, j*32); + } } // El Drag es desde la barra de tareas @@ -126,17 +166,24 @@ void Constructor::on_item_drop_drag_received(const Glib::RefPtrdata, "item_codo.png")==0) - a = Gtk::manage( new Splitter() ); + a = new Splitter();//Gtk::manage( new Splitter() ); else if (strcmp((const char *)selection_data->data, "item_canio.png")==0) - a = Gtk::manage( new Conduct() ); + a = new Conduct();//Gtk::manage( new Conduct() ); else if (strcmp((const char *)selection_data->data, "item_y.png")==0) - a = Gtk::manage( new Union() ); + a = new Union();//Gtk::manage( new Union() ); else if (strcmp((const char *)selection_data->data, "item_tanque.png")==0) - a = Gtk::manage( new Cistern() ); + a = new Cistern();//Gtk::manage( new Cistern() ); else - a = Gtk::manage( new CItem((const char *)selection_data->data) ); - + a = new CItem();//Gtk::manage( new CItem((const char *)selection_data->data) ); + //Seteo el ID del item + a->set_id(++id); + std::cout << can_drop(a, i*32, j*32) <<" --- tamanio lista = "<< listaItems.size()<< "item = "<get_id()<put(*a, i*32, j*32); + //Apunto al workplace + a->workplace= workplace; + //Seteo la posicion del item + a->set_position(i*32,j*32); // Seteo la lista de tipos de drags a->drag_source_set(listTargets); // Conecto las señales @@ -151,6 +198,10 @@ void Constructor::on_item_drop_drag_received(const Glib::RefPtrsignal_drag_begin().connect(SigC::bind( SigC::slot(*this, &Constructor::on_item_drag_begin), a)); a->show(); listaItems.push_back(a); + } else { + id--; + delete a; + } } context->drag_finish(false, false, time); } diff --git a/Constructor/constructor.glade b/Constructor/constructor.glade index 9703aa6..fd59385 100644 --- a/Constructor/constructor.glade +++ b/Constructor/constructor.glade @@ -124,7 +124,7 @@ - + True gtk-delete True @@ -167,6 +167,93 @@ + + + True + True + 0 + + + + 125 + True + Buscar Item + False + False + GTK_JUSTIFY_LEFT + False + False + 0.5 + 0.5 + 0 + 0 + + + 0 + False + False + + + + + + True + False + True + False + True + False + + + + True + True + True + True + 0 + + True + * + False + + + + + + True + GTK_SELECTION_BROWSE + + + + + 0 + False + True + + + + + + True + True + gtk-find + True + GTK_RELIEF_NORMAL + + + 0 + False + False + + + + + 0 + False + False + + + True @@ -203,57 +290,13 @@ GTK_RELIEF_NORMAL - + True + ico_canio.png 0.5 0.5 - 0 - 0 - - - - True - False - 2 - - - - True - ico_canio.png - 0.5 - 0.5 - 0 - 0 - - - 0 - False - False - - - - - - True - Canio - True - False - GTK_JUSTIFY_LEFT - False - False - 0.5 - 0.5 - 0 - 0 - - - 0 - False - False - - - - + 0 + 0 @@ -267,57 +310,13 @@ GTK_RELIEF_NORMAL - + True + ico_codo.png 0.5 0.5 - 0 - 0 - - - - True - False - 2 - - - - True - ico_codo.png - 0.5 - 0.5 - 0 - 0 - - - 0 - False - False - - - - - - True - Codo - True - False - GTK_JUSTIFY_LEFT - False - False - 0.5 - 0.5 - 0 - 0 - - - 0 - False - False - - - - + 0 + 0 @@ -331,58 +330,13 @@ GTK_RELIEF_NORMAL - + True + ico_y.png 0.5 0.5 - 0 - 0 - - - - True - False - 2 - - - - True - ico_y.png - 0.5 - 0.5 - 0 - 0 - - - 0 - False - False - - - - - - True - Division -Empalme - True - False - GTK_JUSTIFY_LEFT - False - False - 0.5 - 0.5 - 0 - 0 - - - 0 - False - False - - - - + 0 + 0 @@ -396,57 +350,13 @@ Empalme GTK_RELIEF_NORMAL - + True + ico_tanque.png 0.5 0.5 - 0 - 0 - - - - True - False - 2 - - - - True - ico_tanque.png - 0.5 - 0.5 - 0 - 0 - - - 0 - False - False - - - - - - True - Tanque - True - False - GTK_JUSTIFY_LEFT - False - False - 0.5 - 0.5 - 0 - 0 - - - 0 - False - False - - - - + 0 + 0 @@ -494,6 +404,53 @@ Empalme True + + + + True + GTK_BUTTONBOX_SPREAD + 0 + + + + True + True + True + button2 + True + GTK_RELIEF_NORMAL + + + + + + True + True + True + button3 + True + GTK_RELIEF_NORMAL + + + + + + True + True + True + button4 + True + GTK_RELIEF_NORMAL + + + + + 0 + False + False + GTK_PACK_END + + @@ -542,26 +499,26 @@ Empalme - + True True True - gtk-ok + gtk-apply True GTK_RELIEF_NORMAL - -5 + -10 - + True True True - gtk-apply + gtk-ok True GTK_RELIEF_NORMAL - -10 + -5 @@ -592,7 +549,7 @@ Empalme GTK_UPDATE_ALWAYS False False - 0 0 100 0.1 10 10 + 0 0 10000 0.1 10 10 1 @@ -613,7 +570,7 @@ Empalme GTK_UPDATE_ALWAYS False False - 0 0 100 0.1 10 10 + 0 0 10000 0.1 10 10 1 diff --git a/Constructor/constructor.h b/Constructor/constructor.h index fe959fe..08cd3e2 100644 --- a/Constructor/constructor.h +++ b/Constructor/constructor.h @@ -2,6 +2,7 @@ #ifndef _CONSTRUCTOR_H_ #define _CONSTRUCTOR_H_ +#include #include #include #include @@ -21,15 +22,17 @@ class Constructor : public Gtk::Window { Constructor(BaseObjectType* cobject, const Glib::RefPtr& refGlade); virtual ~Constructor(); protected: + int id; // / defino los elementos de la ventana. Gtk::Button *btn_canio, *btn_codo, *btn_y, *btn_tanque; - Gtk::ImageMenuItem *main_menu_quit; + Gtk::ImageMenuItem *main_menu_quit, *edit_menu_del; WorkPlace *workplace; Glib::RefPtr ico_canio, ico_y, ico_codo, ico_tanque; std::list listTargets; Glib::RefPtr ico_last; std::list listaItems; + bool can_drop(CItem *, int , int); // /señales de control para los elementos de la ventana. virtual void on_btn_canio_drag_get(const Glib::RefPtr& context, GtkSelectionData* selection_data, guint info, guint time); @@ -37,7 +40,8 @@ class Constructor : public Gtk::Window { virtual void on_btn_codo_drag_get(const Glib::RefPtr& context, GtkSelectionData* selection_data, guint info, guint time); virtual void on_btn_tanque_drag_get(const Glib::RefPtr& context, GtkSelectionData* selection_data, guint info, guint time); virtual void on_main_menu_quit(); - + virtual void on_edit_menu_del(); + // señales para cambiar el icono. virtual void on_canio_drag_begin(const Glib::RefPtr& context); virtual void on_y_drag_begin(const Glib::RefPtr& context); diff --git a/Constructor/item.cpp b/Constructor/item.cpp index e17038b..b526867 100644 --- a/Constructor/item.cpp +++ b/Constructor/item.cpp @@ -12,15 +12,18 @@ CItem::CItem() menu_image_propiedades.set(Gtk::Stock::PREFERENCES, Gtk::ICON_SIZE_MENU); menu_image_delete.set(Gtk::Stock::CANCEL, Gtk::ICON_SIZE_MENU); menu_image_rotar.set(Gtk::Stock::REFRESH, Gtk::ICON_SIZE_MENU); + menu_image_linea.set(Gtk::Stock::CONVERT, Gtk::ICON_SIZE_MENU); Gtk::Menu::MenuList& menulist = menu_popup.items(); menulist.push_back( Gtk::Menu_Helpers::ImageMenuElem("Propiedades",menu_image_propiedades, SigC::slot(*this, &CItem::on_menu_popup_propiedades) ) ); menulist.push_back( Gtk::Menu_Helpers::ImageMenuElem("Rotar", menu_image_rotar ,SigC::slot(*this, &CItem::on_menu_popup_rotar) ) ); menulist.push_back( Gtk::Menu_Helpers::ImageMenuElem("Eliminar", menu_image_delete,SigC::slot(*this, &CItem::on_menu_popup_eliminar) ) ) ; + menulist.push_back( Gtk::Menu_Helpers::ImageMenuElem("Conectar", menu_image_linea,SigC::slot(*this, &CItem::on_menu_popup_conectar) ) ) ; menu_popup.accelerate(*this); } CItem::~CItem() { + std::cout << "Item Die" << std::endl; } bool CItem::on_expose_event(GdkEventExpose* event) @@ -44,4 +47,42 @@ void CItem::on_menu_popup_rotar() void CItem::on_menu_popup_eliminar() { + workplace->delete_item(ID); +} + +void CItem::on_menu_popup_conectar() +{ +} + +void CItem::set_position(int x, int y) +{ + this->x = x; + this->y = y; +} + +int CItem::get_position_x() +{ + return x; +} + +int CItem::get_position_y() +{ + return y; +} + +bool CItem::is_occupied_area(int a, int b) +{ + if ( (a >= x ) && ( a < x+image->get_width()) && (b >= y) && (b < y+image->get_height()) ) + return true; + else return false; +} + +void CItem::set_id(int id) +{ + ID = id; +} + +int CItem::get_id() +{ + return ID; } diff --git a/Constructor/item.h b/Constructor/item.h index 7a4bd31..1e188c1 100644 --- a/Constructor/item.h +++ b/Constructor/item.h @@ -9,23 +9,36 @@ #include #include #include "propertywnd.h" +#include "workplace.h" +class WorkPlace; class CItem:public Gtk::DrawingArea { public: CItem(); CItem(const char *filename); - ~CItem(); + virtual ~CItem(); virtual bool on_expose_event(GdkEventExpose* event); virtual void on_menu_popup_propiedades(); virtual void on_menu_popup_rotar(); virtual void on_menu_popup_eliminar(); + virtual void on_menu_popup_conectar(); Glib::RefPtr get_image() { return image; } + void set_position(int, int); + int get_position_x(); + int get_position_y(); + bool is_occupied_area(int, int); + void set_id(int); + int get_id(); + // habria que ocultarla.......................................... + WorkPlace *workplace; protected: + int ID; Gtk::Menu menu_popup; - Gtk::Image menu_image_delete, menu_image_rotar, menu_image_propiedades; + Gtk::Image menu_image_delete, menu_image_rotar, menu_image_propiedades, menu_image_linea; Glib::RefPtr image; PropertyWnd *property_wnd; + int x, y; }; #endif diff --git a/Constructor/union.cpp b/Constructor/union.cpp index 427c672..f1bee2f 100644 --- a/Constructor/union.cpp +++ b/Constructor/union.cpp @@ -37,8 +37,7 @@ bool Union::on_button_press_event(GdkEventButton *event) imgActual = 0; image = imageN; } - get_size_request(w, h); - set_size_request(h, w); + set_size_request(image->get_width(), image->get_height()); image->render_to_drawable(get_window(),get_style()->get_black_gc(),0,0,0,0,image->get_width(),image->get_height(),Gdk::RGB_DITHER_NONE,0,0); } if ((event->type == GDK_BUTTON_PRESS) && ( event->button == 3)){ @@ -55,7 +54,3 @@ void Union::on_menu_popup_rotar() event.button = 2; Union::on_button_press_event(&event); } - -void Union::on_menu_popup_eliminar() -{ -} diff --git a/Constructor/union.h b/Constructor/union.h index aba6543..c5426e0 100644 --- a/Constructor/union.h +++ b/Constructor/union.h @@ -10,7 +10,6 @@ class Union : public CItem { virtual ~Union(); virtual bool on_button_press_event(GdkEventButton *event); virtual void on_menu_popup_rotar(); - virtual void on_menu_popup_eliminar(); private: int imgActual; diff --git a/Constructor/workplace.cpp b/Constructor/workplace.cpp index f3874e3..519dcd4 100644 --- a/Constructor/workplace.cpp +++ b/Constructor/workplace.cpp @@ -1,12 +1,8 @@ - - #include "workplace.h" -#include "item.h" + WorkPlace::WorkPlace( BaseObjectType* cobject, const Glib::RefPtr &refGlade):Gtk::Fixed(cobject) { - } - bool WorkPlace::on_expose_event(GdkEventExpose *e) { int x, y; @@ -20,3 +16,23 @@ bool WorkPlace::on_expose_event(GdkEventExpose *e) } return true; } + + +bool WorkPlace::on_button_pressed(GdkEventButton *e) +{ + return true; +} + +void WorkPlace::delete_item(int id) +{ + std::list::iterator i = listaItems->begin(); + while ( i != listaItems->end() ){ + CItem *temp = *i; + if ( temp->get_id() == id ){ + listaItems->erase(i); + delete temp; + break; + } + i++; + } +} diff --git a/Constructor/workplace.h b/Constructor/workplace.h index 8a26e1d..7054a35 100644 --- a/Constructor/workplace.h +++ b/Constructor/workplace.h @@ -6,12 +6,19 @@ #include #include #include +#include "item.h" + +class CItem; class WorkPlace:public Gtk::Fixed { public: WorkPlace(BaseObjectType* cobject, const Glib::RefPtr &refGlade); virtual ~WorkPlace() {} virtual bool on_expose_event(GdkEventExpose *); + virtual bool on_button_pressed(GdkEventButton *); + void delete_item(int); + + std::list *listaItems; }; #endif