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);
{
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<x>%d</x>\n",x);
+ sprintf(c_y,"\t\t<y>%d</y>\n",y);
+ sprintf(c_id,"%d",ID);
+ sprintf(c_cap,"\t\t<capacidad>%.2f</capacidad>\n", capacidad);
+ sprintf(c_ini,"\t\t<inicial>%.2f</inicial>\n", contenido_inicial);
+ sprintf(c_img,"\t\t<orientacion>%d</orientacion>\n",imgActual);
+ Glib::ustring dato;
+ dato = "\t<tanque nombre=\""+name+"\" id=\"";
+ dato += c_id;
+ dato += "\">\n";
+ dato += c_cap;
+ dato += c_ini;
+ dato += c_img;
+ dato += c_x;
+ dato += c_y;
+ dato += "\t</tanque>\n";
+ fprintf(archivo,dato.c_str());
+}
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;
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);
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<x>%d</x>\n",x);
+ sprintf(c_y,"\t\t<y>%d</y>\n",y);
+ sprintf(c_id,"%d",ID);
+ sprintf(c_caudal,"\t\t<caudal>%.2f</caudal>\n", caudal_max);
+ sprintf(c_img,"\t\t<orientacion>%d</orientacion>\n",imgActual);
+ Glib::ustring dato;
+ dato = "\t<tubo nombre=\""+name+"\" id=\"";
+ dato += c_id;
+ dato += "\">\n";
+ dato += c_caudal;
+ dato += c_img;
+ dato += c_x;
+ dato += c_y;
+ dato += "\t</tubo>\n";
+ fprintf(archivo,dato.c_str());
+}
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;
refGlade->get_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") );
chk_btn_logica->signal_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;
//hide();
}
+void Constructor::on_main_menu_save()
+{
+ file_selection->show();
+}
+
void Constructor::on_edit_menu_del()
{
// hay que meter algo aca.
logica = !logica;
}
+void Constructor::on_btn_file_ok_clicked()
+{
+ std::list<CItem *>::iterator i = listaItems.begin();
+ std::string file_name = file_selection->get_filename();
+ if ( (archivo = fopen( file_name.c_str(), "w+")) != NULL ){
+ fprintf (archivo,"<planta>\n");
+ while ( i != listaItems.end() ){
+ CItem *temp = *i;
+ temp->save(archivo);
+ i++;
+ }
+ fprintf(archivo,"</planta>\n");
+ } else
+ std::cout<<"NO SE ABRIO EL ARCHIVO"<<std::endl;
+ fclose(archivo);
+ file_selection->hide();
+}
+
+void Constructor::on_btn_file_cancel_clicked()
+{
+ file_selection->hide();
+}
+
void Constructor::on_canio_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)
{
context->set_icon(ico_canio, 5, 5);
a = new Union();
else if (strcmp((const char *)selection_data->data, "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
</child>
<child>
- <widget class="GtkImageMenuItem" id="save1">
+ <widget class="GtkImageMenuItem" id="main_menu_save">
<property name="visible">True</property>
<property name="label">gtk-save</property>
<property name="use_stock">True</property>
<property name="enable_arrows_always">False</property>
<child internal-child="entry">
- <widget class="GtkEntry" id="combo-entry1">
+ <widget class="GtkEntry" id="combo_entry">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="editable">True</property>
</child>
</widget>
-<widget class="GtkFileSelection" id="fileselection1">
+<widget class="GtkFileSelection" id="file_selection">
<property name="border_width">10</property>
<property name="title" translatable="yes">Select File</property>
- <property name="type">GTK_WINDOW_POPUP</property>
- <property name="window_position">GTK_WIN_POS_NONE</property>
+ <property name="type">GTK_WINDOW_TOPLEVEL</property>
+ <property name="window_position">GTK_WIN_POS_CENTER</property>
<property name="modal">False</property>
<property name="resizable">True</property>
<property name="destroy_with_parent">False</property>
#include <gtkmm/fixed.h>
#include <gtkmm/scrolledwindow.h>
#include <gtkmm/checkbutton.h>
+#include <gtkmm/fileselection.h>
+#include <gtkmm/entry.h>
#include "workplace.h"
#include "item.h"
#include "splitter.h"
public:
Constructor(BaseObjectType* cobject, const Glib::RefPtr<Gnome::Glade::Xml>& 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<Gdk::Pixbuf> ico_canio, ico_y, ico_codo, ico_tanque;
std::list<Gtk::TargetEntry> listTargets;
virtual void on_btn_codo_drag_get(const Glib::RefPtr<Gdk::DragContext>& context, GtkSelectionData* selection_data, guint info, guint time);
virtual void on_btn_tanque_drag_get(const Glib::RefPtr<Gdk::DragContext>& 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<Gdk::DragContext>& context);
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;
+}
#include <gtkmm.h>
#include <gdkmm.h>
#include <libglademm.h>
+#include <gtkmm/entry.h>
#include "itemptywnd.h"
class WorkPlace;
virtual void on_menu_popup_eliminar();
virtual void on_menu_popup_conectar();
Glib::RefPtr<Gdk::Pixbuf> 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;
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);
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<x>%d</x>\n",x);
+ sprintf(c_y,"\t\t<y>%d</y>\n",y);
+ sprintf(c_id,"%d",ID);
+ sprintf(c_caudal,"\t\t<caudal>%.2f</caudal>\n", caudal_max);
+ sprintf(c_img,"\t\t<orientacion>%d</orientacion>\n",imgActual);
+ Glib::ustring dato;
+ dato = "\t<codo nombre=\""+name+"\" id=\"";
+ dato += c_id;
+ dato += "\">\n";
+ dato += c_caudal;
+ dato += c_img;
+ dato += c_x;
+ dato += c_y;
+ dato += "\t</codo>\n";
+ fprintf(archivo,dato.c_str());
+}
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;
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);
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<x>%d</x>\n",x);
+ sprintf(c_y,"\t\t<y>%d</y>\n",y);
+ sprintf(c_id,"%d",ID);
+ sprintf(c_caudal,"\t\t<caudal>%.2f</caudal>\n", caudal_max);
+ sprintf(c_img,"\t\t<orientacion>%d</orientacion>\n",imgActual);
+ Glib::ustring dato;
+ dato = "\t<union nombre=\""+name+"\" id=\"";
+ dato += c_id;
+ dato += "\">\n";
+ dato += c_caudal;
+ dato += c_img;
+ dato += c_x;
+ dato += c_y;
+ dato += "\t</union>\n";
+ fprintf(archivo,dato.c_str());
+}
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;