From 551d0c744aaa1e33f000efb66b6f3f042966d21f Mon Sep 17 00:00:00 2001 From: =?utf8?q?Nicol=C3=A1s=20Dimov?= Date: Tue, 11 Nov 2003 03:58:20 +0000 Subject: [PATCH] ya no me acuerdo ni que cambie, pero va tomando forma esto, si el circuito que se arma es cerrado esta todo ok, si no te aparece un dialoguito que te dice que esta todo mal --- Constructor/cistern.cpp | 14 ++++++ Constructor/cistern.h | 2 +- Constructor/conduct.cpp | 16 +++++++ Constructor/conduct.h | 3 +- Constructor/constructor.cpp | 26 ++++++++++- Constructor/constructor.glade | 82 ++++++++++++++++++++++++++++++----- Constructor/constructor.h | 9 ++-- Constructor/item.cpp | 17 ++++++++ Constructor/item.h | 7 ++- Constructor/splitter.cpp | 26 +++++++++++ Constructor/splitter.h | 3 +- Constructor/union.cpp | 30 +++++++++++++ Constructor/union.h | 3 +- 13 files changed, 214 insertions(+), 24 deletions(-) diff --git a/Constructor/cistern.cpp b/Constructor/cistern.cpp index 41073c1..fe0e5dd 100644 --- a/Constructor/cistern.cpp +++ b/Constructor/cistern.cpp @@ -112,3 +112,17 @@ void Cistern::save(FILE *archivo) dato += "\t\n"; fprintf(archivo,dato.c_str()); } + +bool Cistern::check_connection() +{ + switch (get_img_actual()) { + case 0: + if ( is_other_occupied_area( get_position_x()+get_image()->get_width()+10 , get_position_y()+get_image()->get_height() -10) ) + return true; + break; + case 1: + if ( is_other_occupied_area( get_position_x() -10, get_position_y()+get_image()->get_height()-10) ) + return true; + } + return false; +} diff --git a/Constructor/cistern.h b/Constructor/cistern.h index 7b552d2..1bb290c 100644 --- a/Constructor/cistern.h +++ b/Constructor/cistern.h @@ -18,9 +18,9 @@ class Cistern : public CItem { void set_contenido_inicial(double _ini); double get_contenido_inicial(); virtual void save(FILE *archivo); + virtual bool check_connection(); protected: double capacidad, contenido_inicial; - int imgActual; Glib::RefPtr imageE; // 0 Glib::RefPtr imageO; // 1 Glib::RefPtr null; diff --git a/Constructor/conduct.cpp b/Constructor/conduct.cpp index 1daf356..2a582fb 100644 --- a/Constructor/conduct.cpp +++ b/Constructor/conduct.cpp @@ -85,3 +85,19 @@ void Conduct::save(FILE *archivo) dato += "\t\n"; fprintf(archivo,dato.c_str()); } + +bool Conduct::check_connection() +{ + switch (get_img_actual()) { + case 0: + if ( is_other_occupied_area( get_position_x()+get_image()->get_width()/2, get_position_y()+get_image()->get_height()+10) && + is_other_occupied_area( get_position_x()+get_image()->get_width()/2, get_position_y() - 10) ) + return true; + break; + case 1: + if ( is_other_occupied_area( get_position_x()-10, get_position_y()+get_image()->get_height()/2) && + is_other_occupied_area( get_position_x()+get_image()->get_width()+10, get_position_y()+get_image()->get_height()/2) ) + return true; + } + return false; +} diff --git a/Constructor/conduct.h b/Constructor/conduct.h index 84007ed..4937caf 100644 --- a/Constructor/conduct.h +++ b/Constructor/conduct.h @@ -11,9 +11,8 @@ class Conduct : public CItem { virtual void on_menu_popup_rotar(); virtual void on_menu_popup_propiedades(); virtual void save(FILE *archivo); + virtual bool check_connection(); private: - int imgActual; - Glib::RefPtr imageN; // 0 Glib::RefPtr imageS; // 1 Glib::RefPtr null; diff --git a/Constructor/constructor.cpp b/Constructor/constructor.cpp index e8180b0..98fbb78 100644 --- a/Constructor/constructor.cpp +++ b/Constructor/constructor.cpp @@ -1,4 +1,3 @@ -//constructor.cpp #include "constructor.h" Constructor::Constructor(BaseObjectType* cobject, const Glib::RefPtr& refGlade):Gtk::Window(cobject) @@ -22,6 +21,9 @@ Constructor::Constructor(BaseObjectType* cobject, const Glib::RefPtrget_widget("chk_btn_logica",chk_btn_logica); refGlade->get_widget("file_selection",file_selection); refGlade->get_widget("combo_entry",combo_entry); + refGlade->get_widget("btn_check",btn_check); + refGlade->get_widget("dlg_connect", dlg_connect); + refGlade->get_widget("btn_dlg_close", btn_dlg_close); refGlade->get_widget_derived("workplace", workplace); //fixed @@ -40,6 +42,8 @@ Constructor::Constructor(BaseObjectType* cobject, const Glib::RefPtrsignal_drag_data_get().connect( SigC::slot(*this, &Constructor::on_btn_y_drag_get)); btn_codo->signal_drag_data_get().connect( SigC::slot(*this, &Constructor::on_btn_codo_drag_get)); btn_tanque->signal_drag_data_get().connect( SigC::slot(*this, &Constructor::on_btn_tanque_drag_get)); + btn_check->signal_clicked().connect(SigC::slot(*this,&Constructor::on_btn_check_clicked)); + btn_dlg_close->signal_clicked().connect(SigC::slot(*this,&Constructor::on_btn_dlg_connect_clicked)); 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)); @@ -141,6 +145,11 @@ void Constructor::on_btn_file_cancel_clicked() file_selection->hide(); } +void Constructor::on_btn_dlg_connect_clicked() +{ + dlg_connect->hide(); +} + void Constructor::on_canio_drag_begin(const Glib::RefPtr& context) { context->set_icon(ico_canio, 5, 5); @@ -231,6 +240,8 @@ void Constructor::on_item_drop_drag_received(const Glib::RefPtrworkplace= workplace; //Apunto a la lista. a->combo_entry = combo_entry; + //Apunto a la listaItems. + a->listaItems = &listaItems; //Seteo la posicion del item a->set_position(i*32,j*32); // Seteo la lista de tipos de drags @@ -255,3 +266,16 @@ void Constructor::on_item_drop_drag_received(const Glib::RefPtrdrag_finish(false, false, time); } } + +void Constructor::on_btn_check_clicked() +{ + std::list::iterator i = listaItems.begin(); + while ( i != listaItems.end() ) { + CItem *temp = *i; + if ( !temp->check_connection() ) { + dlg_connect->show(); + break; + } + i++; + } +} diff --git a/Constructor/constructor.glade b/Constructor/constructor.glade index db62ae0..01b0743 100644 --- a/Constructor/constructor.glade +++ b/Constructor/constructor.glade @@ -174,19 +174,12 @@ 0 - - 125 + True - Buscar Item - False - False - GTK_JUSTIFY_LEFT - False - False - 0.5 - 0.5 - 0 - 0 + True + Verificar Conexionado + True + GTK_RELIEF_NORMAL 0 @@ -906,4 +899,69 @@ + + Error + GTK_WINDOW_TOPLEVEL + GTK_WIN_POS_CENTER + True + True + False + True + + + + True + False + 0 + + + + True + GTK_BUTTONBOX_SPREAD + + + + True + True + True + gtk-ok + True + GTK_RELIEF_NORMAL + -5 + + + + + 0 + False + True + GTK_PACK_END + + + + + + True + Los elementos no estan conectados + correctamente + False + False + GTK_JUSTIFY_FILL + False + False + 0.5 + 0.5 + 0 + 0 + + + 0 + True + True + + + + + + diff --git a/Constructor/constructor.h b/Constructor/constructor.h index f9b5bf3..d2c9d6f 100644 --- a/Constructor/constructor.h +++ b/Constructor/constructor.h @@ -29,16 +29,17 @@ class Constructor : public Gtk::Window { protected: int id; // / defino los elementos de la ventana. - Gtk::Button *btn_canio, *btn_codo, *btn_y, *btn_tanque, *btn_file_ok, *btn_file_cancel; + Gtk::Button *btn_canio, *btn_codo, *btn_y, *btn_tanque, *btn_file_ok, *btn_file_cancel, *btn_check, *btn_dlg_close; 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; + Gtk::Dialog *dlg_connect; Glib::RefPtr ico_canio, ico_y, ico_codo, ico_tanque; - std::list listTargets; Glib::RefPtr ico_last; + std::list listTargets; std::list listaItems; + WorkPlace *workplace; bool logica; bool can_drop(CItem *, int , int); // /señales de control para los elementos de la ventana. @@ -53,6 +54,8 @@ class Constructor : public Gtk::Window { virtual void on_chk_btn_clicked(); virtual void on_btn_file_ok_clicked(); virtual void on_btn_file_cancel_clicked(); + virtual void on_btn_check_clicked(); + virtual void on_btn_dlg_connect_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 79515ff..31d955d 100644 --- a/Constructor/item.cpp +++ b/Constructor/item.cpp @@ -126,9 +126,26 @@ int CItem::get_conector_out() return conector_out; } +int CItem::get_img_actual() +{ + return imgActual; +} + 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; } + +bool CItem::is_other_occupied_area(int _a, int _b) +{ + std::list::iterator i = listaItems->begin(); + while ( i != listaItems->end() ){ + CItem *temp = *i; + if ( temp->is_occupied_area(_a,_b) ) + return true; + i++; + } + return false; +} diff --git a/Constructor/item.h b/Constructor/item.h index 3c78eaf..facb96d 100644 --- a/Constructor/item.h +++ b/Constructor/item.h @@ -24,12 +24,12 @@ public: virtual void on_menu_popup_eliminar(); virtual void on_menu_popup_conectar(); Glib::RefPtr get_image() { return image; } - virtual void save(FILE *archivo) = 0; int get_position_x(); int get_position_y(); int get_id(); int get_conector_in(); int get_conector_out(); + int get_img_actual(); double get_caudal(); void set_position(int _x, int _y); void set_id(int _id); @@ -38,10 +38,15 @@ public: void set_conector_in(int _in); void set_conector_out(int _out); bool is_occupied_area(int _a, int _b); + bool is_other_occupied_area(int _a, int _b); + virtual void save(FILE *archivo) = 0; + virtual bool check_connection()=0; Glib::ustring get_name(); WorkPlace *workplace; Gtk::Entry *combo_entry; + std::list *listaItems; protected: + int imgActual; int ID, conector_in, conector_out; Glib::ustring name; double caudal_max; diff --git a/Constructor/splitter.cpp b/Constructor/splitter.cpp index 71241ba..5e61abd 100644 --- a/Constructor/splitter.cpp +++ b/Constructor/splitter.cpp @@ -90,3 +90,29 @@ void Splitter::save(FILE *archivo) dato += "\t\n"; fprintf(archivo,dato.c_str()); } + +bool Splitter::check_connection() +{ + switch (get_img_actual()) { + case 0: + if ( is_other_occupied_area( get_position_x()-10, get_position_y()+10) && + is_other_occupied_area( get_position_x()+get_image()->get_width()-10, +get_position_y()+get_image()->get_height() + 10) ) + return true; + break; + case 1: + if ( is_other_occupied_area( get_position_x()+get_image()->get_width() - 10, get_position_y() -10) && + is_other_occupied_area( get_position_x()-10, get_position_y()+get_image()->get_height()-10) ) + return true; + break; + case 2: + if ( is_other_occupied_area( get_position_x() + 10, get_position_y() -10) && + is_other_occupied_area( get_position_x()+get_image()->get_width()+10, get_position_y()+get_image()->get_height()-10) ) + return true; + break; + case 3: + if ( is_other_occupied_area( get_position_x()+get_image()->get_width()+10, get_position_y() +10) && + is_other_occupied_area( get_position_x() + 10, get_position_y()+get_image()->get_height() + 10) ) + return true; + } + return false; +} diff --git a/Constructor/splitter.h b/Constructor/splitter.h index b8f55d4..206aa24 100644 --- a/Constructor/splitter.h +++ b/Constructor/splitter.h @@ -11,9 +11,8 @@ class Splitter : public CItem { virtual void on_menu_popup_rotar(); virtual void on_menu_popup_propiedades(); virtual void save(FILE *archivo); + virtual bool check_connection(); private: - int imgActual; - Glib::RefPtr imageN; // 0 Glib::RefPtr imageS; // 1 Glib::RefPtr imageE; // 2 diff --git a/Constructor/union.cpp b/Constructor/union.cpp index 82a5140..3de8b90 100644 --- a/Constructor/union.cpp +++ b/Constructor/union.cpp @@ -91,3 +91,33 @@ void Union::save(FILE *archivo) dato += "\t\n"; fprintf(archivo,dato.c_str()); } + +bool Union::check_connection() +{ + switch (get_img_actual()) { + case 0: + if ( is_other_occupied_area( get_position_x() - 10, get_position_y() +10) && + is_other_occupied_area( get_position_x()+get_image()->get_width()+10, get_position_y()+10) && + is_other_occupied_area( get_position_x()+get_image()->get_width()/2, get_position_y()+get_image()->get_height()+10) ) + return true; + break; + case 1: + if ( is_other_occupied_area( get_position_x()-10, get_position_y()+get_image()->get_height()/2) && + is_other_occupied_area( get_position_x()+get_image()->get_width()-10, get_position_y()-10) && + is_other_occupied_area( get_position_x()+get_image()->get_width()-10, get_position_y()+get_image()->get_height()+10) ) + return true; + break; + case 2: + if ( is_other_occupied_area( get_position_x()-10, get_position_y()+get_image()->get_height()-10) && + is_other_occupied_area( get_position_x()+get_image()->get_width()/2, get_position_y()-10) && + is_other_occupied_area( get_position_x()+get_image()->get_width()+10, get_position_y()+get_image()->get_height()-10) ) + return true; + break; + case 3: + if ( is_other_occupied_area( get_position_x()+10, get_position_y()-10) && + is_other_occupied_area( get_position_x()+get_image()->get_width()+10, get_position_y()+get_image()->get_height()/2) && + is_other_occupied_area( get_position_x()+10, get_position_y()+get_image()->get_height()+10) ) + return true; + } + return false; +} diff --git a/Constructor/union.h b/Constructor/union.h index aa435b6..2376c79 100644 --- a/Constructor/union.h +++ b/Constructor/union.h @@ -12,9 +12,8 @@ class Union : public CItem { virtual void on_menu_popup_rotar(); virtual void on_menu_popup_propiedades(); virtual void save(FILE *archivo); + virtual bool check_connection(); private: - int imgActual; - Glib::RefPtr imageN; // 0 Glib::RefPtr imageS; // 1 Glib::RefPtr imageE; // 2 -- 2.43.0