From: Nicolás Dimov Date: Sun, 9 Nov 2003 23:36:37 +0000 (+0000) Subject: ahora si se puede guardar un archivo, igual todavia hay que definir bien el formato X-Git-Tag: svn_import~320 X-Git-Url: https://git.llucax.com/z.facultad/75.42/plaqui.git/commitdiff_plain/44b4462a9330a34738100db1408ba6517a29a299?ds=sidebyside ahora si se puede guardar un archivo, igual todavia hay que definir bien el formato --- diff --git a/Constructor/cistern.cpp b/Constructor/cistern.cpp index 81d0fad..41073c1 100644 --- a/Constructor/cistern.cpp +++ b/Constructor/cistern.cpp @@ -22,6 +22,9 @@ Cistern::~Cistern() bool Cistern::on_button_press_event(GdkEventButton *event) { + if ((event->type == GDK_BUTTON_PRESS) && ( event->button == 1)) + combo_entry->set_text(name); + if ((event->type == GDK_BUTTON_PRESS) && ( event->button ==2)){ image = null; 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); @@ -87,3 +90,25 @@ double Cistern::get_contenido_inicial() { return contenido_inicial; } + +void Cistern::save(FILE *archivo) +{ + char c_id[50], c_cap[50], c_x[50], c_y[50], c_img[50], c_ini[50]; + sprintf(c_x,"\t\t%d\n",x); + sprintf(c_y,"\t\t%d\n",y); + sprintf(c_id,"%d",ID); + sprintf(c_cap,"\t\t%.2f\n", capacidad); + sprintf(c_ini,"\t\t%.2f\n", contenido_inicial); + sprintf(c_img,"\t\t%d\n",imgActual); + Glib::ustring dato; + dato = "\t\n"; + dato += c_cap; + dato += c_ini; + dato += c_img; + dato += c_x; + dato += c_y; + dato += "\t\n"; + fprintf(archivo,dato.c_str()); +} diff --git a/Constructor/cistern.h b/Constructor/cistern.h index 2bb8c98..7b552d2 100644 --- a/Constructor/cistern.h +++ b/Constructor/cistern.h @@ -17,6 +17,7 @@ class Cistern : public CItem { double get_capacidad(); void set_contenido_inicial(double _ini); double get_contenido_inicial(); + virtual void save(FILE *archivo); protected: double capacidad, contenido_inicial; int imgActual; diff --git a/Constructor/conduct.cpp b/Constructor/conduct.cpp index aa1c092..1daf356 100644 --- a/Constructor/conduct.cpp +++ b/Constructor/conduct.cpp @@ -18,6 +18,9 @@ Conduct::~Conduct() bool Conduct::on_button_press_event(GdkEventButton *event) { int w, h; + if ((event->type == GDK_BUTTON_PRESS) && ( event->button == 1)) + combo_entry->set_text(name); + if ((event->type == GDK_BUTTON_PRESS) && ( event->button ==2)){ image = null; 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); @@ -62,3 +65,23 @@ void Conduct::on_menu_popup_propiedades() event.button = 1; Conduct::on_button_press_event(&event); } + +void Conduct::save(FILE *archivo) +{ + char c_id[50], c_caudal[50], c_x[50], c_y[50], c_img[50]; + sprintf(c_x,"\t\t%d\n",x); + sprintf(c_y,"\t\t%d\n",y); + sprintf(c_id,"%d",ID); + sprintf(c_caudal,"\t\t%.2f\n", caudal_max); + sprintf(c_img,"\t\t%d\n",imgActual); + Glib::ustring dato; + dato = "\t\n"; + dato += c_caudal; + dato += c_img; + dato += c_x; + dato += c_y; + dato += "\t\n"; + fprintf(archivo,dato.c_str()); +} diff --git a/Constructor/conduct.h b/Constructor/conduct.h index 78878a8..84007ed 100644 --- a/Constructor/conduct.h +++ b/Constructor/conduct.h @@ -10,6 +10,7 @@ class Conduct : public CItem { virtual bool on_button_press_event(GdkEventButton *event); virtual void on_menu_popup_rotar(); virtual void on_menu_popup_propiedades(); + virtual void save(FILE *archivo); private: int imgActual; diff --git a/Constructor/constructor.cpp b/Constructor/constructor.cpp index 7553c91..e8180b0 100644 --- a/Constructor/constructor.cpp +++ b/Constructor/constructor.cpp @@ -17,13 +17,14 @@ 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("main_menu_save",main_menu_save); refGlade->get_widget("edit_menu_del",edit_menu_del); refGlade->get_widget("chk_btn_logica",chk_btn_logica); + refGlade->get_widget("file_selection",file_selection); + refGlade->get_widget("combo_entry",combo_entry); refGlade->get_widget_derived("workplace", workplace); //fixed - - //Targets listTargets.push_back( Gtk::TargetEntry("STRING") ); listTargets.push_back( Gtk::TargetEntry("text/plain") ); @@ -42,15 +43,20 @@ Constructor::Constructor(BaseObjectType* cobject, const Glib::RefPtrsignal_clicked().connect(SigC::slot(*this, &Constructor::on_chk_btn_clicked)); main_menu_quit->signal_activate().connect(SigC::slot(*this, &Constructor::on_main_menu_quit)); + main_menu_save->signal_activate().connect(SigC::slot(*this, &Constructor::on_main_menu_save)); edit_menu_del->signal_activate().connect(SigC::slot(*this,&Constructor::on_edit_menu_del)); + + btn_file_cancel = file_selection->get_cancel_button(); + btn_file_ok = file_selection->get_ok_button(); + btn_file_cancel->signal_clicked().connect(SigC::slot(*this,&Constructor::on_btn_file_cancel_clicked)); + btn_file_ok->signal_clicked().connect(SigC::slot(*this,&Constructor::on_btn_file_ok_clicked)); // Señales para cambiar el icono cuando empieza el drag. btn_canio->signal_drag_begin().connect( SigC::slot(*this, &Constructor::on_canio_drag_begin)); btn_y->signal_drag_begin().connect( SigC::slot(*this, &Constructor::on_y_drag_begin)); btn_codo->signal_drag_begin().connect( SigC::slot(*this, &Constructor::on_codo_drag_begin)); btn_tanque->signal_drag_begin().connect( SigC::slot(*this, &Constructor::on_tanque_drag_begin)); - - + workplace->drag_dest_set(listTargets); workplace->signal_drag_data_received().connect( SigC::slot(*this, &Constructor::on_item_drop_drag_received) ); workplace->listaItems = &listaItems; @@ -97,6 +103,11 @@ void Constructor::on_main_menu_quit() //hide(); } +void Constructor::on_main_menu_save() +{ + file_selection->show(); +} + void Constructor::on_edit_menu_del() { // hay que meter algo aca. @@ -107,6 +118,29 @@ void Constructor::on_chk_btn_clicked() logica = !logica; } +void Constructor::on_btn_file_ok_clicked() +{ + std::list::iterator i = listaItems.begin(); + std::string file_name = file_selection->get_filename(); + if ( (archivo = fopen( file_name.c_str(), "w+")) != NULL ){ + fprintf (archivo,"\n"); + while ( i != listaItems.end() ){ + CItem *temp = *i; + temp->save(archivo); + i++; + } + fprintf(archivo,"\n"); + } else + std::cout<<"NO SE ABRIO EL ARCHIVO"<hide(); +} + +void Constructor::on_btn_file_cancel_clicked() +{ + file_selection->hide(); +} + void Constructor::on_canio_drag_begin(const Glib::RefPtr& context) { context->set_icon(ico_canio, 5, 5); @@ -183,16 +217,20 @@ void Constructor::on_item_drop_drag_received(const Glib::RefPtrdata, "item_tanque.png")==0) a = new Cistern(); - else - a = new CItem(); + //Seteo el ID del item Glib::ustring name("item"); + // FIXME + char char_id[10]; + sprintf(char_id," %d",id); a->set_id(++id); - a->set_name( name ); + a->set_name( name+char_id ); if ( can_drop(a, i*32, j*32) ) { workplace->put(*a, i*32, j*32); //Apunto al workplace a->workplace= workplace; + //Apunto a la lista. + a->combo_entry = combo_entry; //Seteo la posicion del item a->set_position(i*32,j*32); // Seteo la lista de tipos de drags diff --git a/Constructor/constructor.glade b/Constructor/constructor.glade index 5325328..db62ae0 100644 --- a/Constructor/constructor.glade +++ b/Constructor/constructor.glade @@ -60,7 +60,7 @@ - + True gtk-save True @@ -205,7 +205,7 @@ False - + True True True @@ -877,11 +877,11 @@ - + 10 Select File - GTK_WINDOW_POPUP - GTK_WIN_POS_NONE + GTK_WINDOW_TOPLEVEL + GTK_WIN_POS_CENTER False True False diff --git a/Constructor/constructor.h b/Constructor/constructor.h index a0de6bc..f9b5bf3 100644 --- a/Constructor/constructor.h +++ b/Constructor/constructor.h @@ -11,6 +11,8 @@ #include #include #include +#include +#include #include "workplace.h" #include "item.h" #include "splitter.h" @@ -22,12 +24,16 @@ class Constructor : public Gtk::Window { public: Constructor(BaseObjectType* cobject, const Glib::RefPtr& refGlade); virtual ~Constructor(); + private: + FILE *archivo; protected: int id; // / defino los elementos de la ventana. - Gtk::Button *btn_canio, *btn_codo, *btn_y, *btn_tanque; - Gtk::ImageMenuItem *main_menu_quit, *edit_menu_del; + Gtk::Button *btn_canio, *btn_codo, *btn_y, *btn_tanque, *btn_file_ok, *btn_file_cancel; + Gtk::ImageMenuItem *main_menu_quit, *edit_menu_del, *main_menu_save; Gtk::CheckButton *chk_btn_logica; + Gtk::FileSelection *file_selection; + Gtk::Entry *combo_entry; WorkPlace *workplace; Glib::RefPtr ico_canio, ico_y, ico_codo, ico_tanque; std::list listTargets; @@ -42,8 +48,11 @@ 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_main_menu_save(); virtual void on_edit_menu_del(); virtual void on_chk_btn_clicked(); + virtual void on_btn_file_ok_clicked(); + virtual void on_btn_file_cancel_clicked(); // señales para cambiar el icono. virtual void on_canio_drag_begin(const Glib::RefPtr& context); diff --git a/Constructor/item.cpp b/Constructor/item.cpp index 08af2cf..79515ff 100644 --- a/Constructor/item.cpp +++ b/Constructor/item.cpp @@ -65,49 +65,70 @@ void CItem::set_position(int _x, int _y) this->y = _y; } -int CItem::get_position_x() +void CItem::set_id(int _id) { - return x; + ID = _id; } -int CItem::get_position_y() +void CItem::set_caudal(double _caudal) { - return y; + caudal_max = _caudal; } -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_name(Glib::ustring _name) +{ + name = _name; } -void CItem::set_id(int _id) +void CItem::set_conector_in(int _in) { - ID = _id; + conector_in = _in; } -int CItem::get_id() +void CItem::set_conector_out(int _out) { - return ID; + conector_out = _out; } -void CItem::set_caudal(double _caudal) +int CItem::get_position_x() { - caudal_max = _caudal; + return x; } -double CItem::get_caudal() +int CItem::get_position_y() { - return caudal_max; + return y; } -void CItem::set_name(Glib::ustring _name) +int CItem::get_id() { - name = _name; + return ID; } +double CItem::get_caudal() +{ + return caudal_max; +} + + Glib::ustring CItem::get_name() { return name; } + +int CItem::get_conector_in() +{ + return conector_in; +} + +int CItem::get_conector_out() +{ + return conector_out; +} + +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; +} diff --git a/Constructor/item.h b/Constructor/item.h index 9b8eabd..3c78eaf 100644 --- a/Constructor/item.h +++ b/Constructor/item.h @@ -8,6 +8,7 @@ #include #include #include +#include #include "itemptywnd.h" class WorkPlace; @@ -23,19 +24,25 @@ public: virtual void on_menu_popup_eliminar(); virtual void on_menu_popup_conectar(); Glib::RefPtr get_image() { return image; } - void set_position(int _x, int _y); + virtual void save(FILE *archivo) = 0; int get_position_x(); int get_position_y(); - bool is_occupied_area(int _a, int _b); - void set_id(int _id); int get_id(); - void set_caudal(double _caudal); + int get_conector_in(); + int get_conector_out(); double get_caudal(); + void set_position(int _x, int _y); + void set_id(int _id); + void set_caudal(double _caudal); void set_name(Glib::ustring _name); + void set_conector_in(int _in); + void set_conector_out(int _out); + bool is_occupied_area(int _a, int _b); Glib::ustring get_name(); WorkPlace *workplace; + Gtk::Entry *combo_entry; protected: - int ID; + int ID, conector_in, conector_out; Glib::ustring name; double caudal_max; Gtk::Menu menu_popup; diff --git a/Constructor/splitter.cpp b/Constructor/splitter.cpp index a9510de..71241ba 100644 --- a/Constructor/splitter.cpp +++ b/Constructor/splitter.cpp @@ -19,6 +19,9 @@ Splitter::~Splitter() bool Splitter::on_button_press_event(GdkEventButton *event) { + if ((event->type == GDK_BUTTON_PRESS) && ( event->button == 1)) + combo_entry->set_text(name); + if ((event->type == GDK_BUTTON_PRESS) && ( event->button == 2)){ image = null; 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); @@ -67,3 +70,23 @@ void Splitter::on_menu_popup_propiedades() event.button = 1; Splitter::on_button_press_event(&event); } + +void Splitter::save(FILE *archivo) +{ + char c_id[50], c_caudal[50], c_x[50], c_y[50], c_img[50]; + sprintf(c_x,"\t\t%d\n",x); + sprintf(c_y,"\t\t%d\n",y); + sprintf(c_id,"%d",ID); + sprintf(c_caudal,"\t\t%.2f\n", caudal_max); + sprintf(c_img,"\t\t%d\n",imgActual); + Glib::ustring dato; + dato = "\t\n"; + dato += c_caudal; + dato += c_img; + dato += c_x; + dato += c_y; + dato += "\t\n"; + fprintf(archivo,dato.c_str()); +} diff --git a/Constructor/splitter.h b/Constructor/splitter.h index fac9059..b8f55d4 100644 --- a/Constructor/splitter.h +++ b/Constructor/splitter.h @@ -10,6 +10,7 @@ class Splitter : public CItem { virtual bool on_button_press_event(GdkEventButton *event); virtual void on_menu_popup_rotar(); virtual void on_menu_popup_propiedades(); + virtual void save(FILE *archivo); private: int imgActual; diff --git a/Constructor/union.cpp b/Constructor/union.cpp index 6c5301a..82a5140 100644 --- a/Constructor/union.cpp +++ b/Constructor/union.cpp @@ -19,6 +19,9 @@ Union::~Union() bool Union::on_button_press_event(GdkEventButton *event) { + if ((event->type == GDK_BUTTON_PRESS) && ( event->button == 1)) + combo_entry->set_text(name); + if ((event->type == GDK_BUTTON_PRESS) && (event->button == 2 )){ image = null; 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); @@ -68,3 +71,23 @@ void Union::on_menu_popup_propiedades() event.button = 1; Union::on_button_press_event(&event); } + +void Union::save(FILE *archivo) +{ + char c_id[50], c_caudal[50], c_x[50], c_y[50], c_img[50]; + sprintf(c_x,"\t\t%d\n",x); + sprintf(c_y,"\t\t%d\n",y); + sprintf(c_id,"%d",ID); + sprintf(c_caudal,"\t\t%.2f\n", caudal_max); + sprintf(c_img,"\t\t%d\n",imgActual); + Glib::ustring dato; + dato = "\t\n"; + dato += c_caudal; + dato += c_img; + dato += c_x; + dato += c_y; + dato += "\t\n"; + fprintf(archivo,dato.c_str()); +} diff --git a/Constructor/union.h b/Constructor/union.h index 5f6279b..aa435b6 100644 --- a/Constructor/union.h +++ b/Constructor/union.h @@ -11,6 +11,7 @@ class Union : public CItem { virtual bool on_button_press_event(GdkEventButton *event); virtual void on_menu_popup_rotar(); virtual void on_menu_popup_propiedades(); + virtual void save(FILE *archivo); private: int imgActual;