From 796708eefb056b936274da15c7af2c7d709c9249 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Nicol=C3=A1s=20Dimov?= Date: Tue, 18 Nov 2003 02:44:49 +0000 Subject: [PATCH 1/1] para que lo vean --- Constructor/cistern.cpp | 15 ++++++++++- Constructor/constructor.cpp | 51 ++++++++++++++++++++++--------------- Constructor/constructor.h | 2 +- Constructor/item.cpp | 6 ++++- Constructor/item.h | 22 +++++++++++++++- Constructor/or.cpp | 11 ++++++-- Constructor/or.h | 2 ++ Constructor/workplace.cpp | 21 +++++++++++---- Constructor/workplace.h | 11 ++++---- 9 files changed, 104 insertions(+), 37 deletions(-) diff --git a/Constructor/cistern.cpp b/Constructor/cistern.cpp index 433f030..5f2a4fa 100644 --- a/Constructor/cistern.cpp +++ b/Constructor/cistern.cpp @@ -30,8 +30,21 @@ Cistern::~Cistern() bool Cistern::on_button_press_event(GdkEventButton *event) { - if ((event->type == GDK_BUTTON_PRESS) && ( event->button == 1)) + GdkEventExpose e; + CItem *logic_item; + t_line tmp_line; + if ((event->type == GDK_BUTTON_PRESS) && ( event->button == 1)) { combo_entry->set_text(name); + if (CItem::logic_connect) { + std::cout<get_logic_item(CItem::quien); + tmp_line.store = this; + workplace->lista_lineas.push_back(tmp_line); + workplace->on_expose_event(&e); + + } + CItem::logic_connect = false; + } if ((event->type == GDK_BUTTON_PRESS) && ( event->button ==2)){ image = null; diff --git a/Constructor/constructor.cpp b/Constructor/constructor.cpp index 241abdb..67e1a08 100644 --- a/Constructor/constructor.cpp +++ b/Constructor/constructor.cpp @@ -94,6 +94,7 @@ 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; + workplace->listaItems = &lista_logic_Items; logica = false; } @@ -271,7 +272,9 @@ void Constructor::on_not_drag_begin(const Glib::RefPtr& contex void Constructor::on_item_drag_begin(const Glib::RefPtr& context, CItem *item) { + GdkEventExpose e; context->set_icon(item->get_image(), 5, 5); + workplace->on_expose_event(&e); } void Constructor::on_item_drag_data_get(const Glib::RefPtr& context, GtkSelectionData* selection_data, guint info, guint time) @@ -318,29 +321,30 @@ void Constructor::on_item_drop_drag_received(const Glib::RefPtrlength >= 0) && (selection_data->format == 8)) { CItem *a; if (strcmp((const char *)selection_data->data, "codo_o.png")==0) - a = new Splitter(); - else if (strcmp((const char *)selection_data->data, "canio_n.png")==0) - a = new Conduct(); - else if (strcmp((const char *)selection_data->data, "y_n.png")==0) - a = new Union(); - else if (strcmp((const char *)selection_data->data, "tanque_e.png")==0) - a = new Cistern(); - else if (strcmp((const char *)selection_data->data, "bomba_e.png")==0) - a =new Pump(); - else if (strcmp((const char *)selection_data->data, "exclusa_h.png")==0) - a = new Exclusa(); - else if (strcmp((const char *)selection_data->data, "drain_n.png")==0) - a = new Drain(); - else if (strcmp((const char *)selection_data->data, "and_e.png")==0) - a = new And(); - else if (strcmp((const char *)selection_data->data, "or_e.png")==0) - a = new Or(); - else if (strcmp((const char *)selection_data->data, "not_e.png")==0) - a = new Not(); + a = new Splitter(); + else if (strcmp((const char *)selection_data->data, "canio_n.png")==0) + a = new Conduct(); + else if (strcmp((const char *)selection_data->data, "y_n.png")==0) + a = new Union(); + else if (strcmp((const char *)selection_data->data, "tanque_e.png")==0) + a = new Cistern(); + else if (strcmp((const char *)selection_data->data, "bomba_e.png")==0) + a =new Pump(); + else if (strcmp((const char *)selection_data->data, "exclusa_h.png")==0) + a = new Exclusa(); + else if (strcmp((const char *)selection_data->data, "drain_n.png")==0) + a = new Drain(); + else if (strcmp((const char *)selection_data->data, "and_e.png")==0){ + a = new And(); a->is_logic = true; + } else if (strcmp((const char *)selection_data->data, "or_e.png")==0) { + a = new Or(); a->is_logic = true; + } else if (strcmp((const char *)selection_data->data, "not_e.png")==0) { + a = new Not(); a->is_logic = true; + } char char_id[10]; sprintf(char_id,"%d",id); - a->set_id(++id); + a->set_id(id++); a->set_name( a->get_name()+char_id ); if ( can_drop(a, i*32, j*32) ) { workplace->put(*a, i*32, j*32); @@ -350,6 +354,8 @@ void Constructor::on_item_drop_drag_received(const Glib::RefPtrcombo_entry = combo_entry; //Apunto a la listaItems. a->listaItems = &listaItems; + //Apunto a la lista de items logicos + a->lista_logic_Items = &lista_logic_Items; //Seteo la posicion del item a->set_position(i*32,j*32); // Seteo la lista de tipos de drags @@ -364,7 +370,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); + if (! a->is_logic ) + listaItems.push_back(a); + else + lista_logic_Items.push_back(a); } else { id--; delete a; diff --git a/Constructor/constructor.h b/Constructor/constructor.h index 64f8a06..b406ce5 100644 --- a/Constructor/constructor.h +++ b/Constructor/constructor.h @@ -45,7 +45,7 @@ class Constructor : public Gtk::Window { Glib::RefPtr ico_canio, ico_y, ico_codo, ico_tanque, ico_bomba, ico_exclusa, ico_drain, ico_and, ico_or, ico_not; Glib::RefPtr ico_last; std::list listTargets; - std::list listaItems; + std::list listaItems, lista_logic_Items; WorkPlace *workplace; bool logica; bool can_drop(CItem *, int , int); diff --git a/Constructor/item.cpp b/Constructor/item.cpp index cd53614..77eefda 100644 --- a/Constructor/item.cpp +++ b/Constructor/item.cpp @@ -1,5 +1,8 @@ #include "item.h" -#include "workplace.h" + +bool CItem:: logic_connect = false; +int CItem::quien = -1; + CItem::CItem(const char *filename):Gtk::DrawingArea() { @@ -15,6 +18,7 @@ CItem::CItem() caudal_max = 0.0; is_union = true; is_connected = false; + is_logic =false; property_wnd->item = this; menu_image_propiedades.set(Gtk::Stock::PREFERENCES, Gtk::ICON_SIZE_MENU); menu_image_delete.set(Gtk::Stock::CANCEL, Gtk::ICON_SIZE_MENU); diff --git a/Constructor/item.h b/Constructor/item.h index 87ddb01..34f9ecd 100644 --- a/Constructor/item.h +++ b/Constructor/item.h @@ -10,6 +10,7 @@ #include #include #include "itemptywnd.h" +#include "workplace.h" ///Tipo de estado en el que pueden estar los conectores de un item typedef enum { UNDEF, IN, OUT } ConnectorType; @@ -29,7 +30,7 @@ class Connector { } }; -class WorkPlace; +//class WorkPlace; class CItem:public Gtk::DrawingArea { public: @@ -103,12 +104,22 @@ public: ///Puntero a la lista de items std::list *listaItems; + ///Puntero a la lista de Items logicos + std::list *lista_logic_Items; + ///TODO poner esto en Union y crear una ventana nueva de propiedades bool is_union; ///indica si el item ya esta conectado con sus conectores bien definidos bool is_connected; + ///Indica si es una compuerta logica + bool is_logic; + + ///Indica si puede realizarse la conexion logica con una compuerta + static bool logic_connect; + static int quien; + /**Vector de connectores donde se mantiene la siguiente referencia: * indice 0 = "arriba/izquierda" para la exclusa, el tubo, el codo, el empalme y el tanque. * "derecha" para la bomba. @@ -123,22 +134,31 @@ public: protected: ///Indica el numero que le corresponde a la imagen actual del item. int imgActual; + ///Numero "unico" que identifica al item. int ID; + ///Nombre del item Glib::ustring name; + ///Caudal maximo que puede contener un item. double caudal_max; + ///Menu flotante del item Gtk::Menu menu_popup; + ///Lista de opciones del menu flotante Gtk::Menu::MenuList menulist; + ///Imagenes del menu flotante Gtk::Image menu_image_delete, menu_image_rotar, menu_image_propiedades, menu_image_linea; + ///Puntero a la imagen del item Glib::RefPtr image; + ///Puntero a la ventana de propiedades del item ItemPtyWnd *property_wnd; + ///Posicion del item en el area de trabajo int x, y; }; diff --git a/Constructor/or.cpp b/Constructor/or.cpp index b480188..0c0631b 100644 --- a/Constructor/or.cpp +++ b/Constructor/or.cpp @@ -20,8 +20,10 @@ Or::~Or() bool Or::on_button_press_event(GdkEventButton *event) { - if ((event->type == GDK_BUTTON_PRESS) && ( event->button == 1)) + if ((event->type == GDK_BUTTON_PRESS) && ( event->button == 1)) { + std::cout<set_text(name); + } if ((event->type == GDK_BUTTON_PRESS) && ( event->button == 2)){ image = null; @@ -50,6 +52,7 @@ bool Or::on_button_press_event(GdkEventButton *event) } return true; } + void Or::on_menu_popup_rotar() { GdkEventButton event; @@ -58,7 +61,11 @@ void Or::on_menu_popup_rotar() Or::on_button_press_event(&event); } - +void Or::on_menu_popup_conectar() +{ + CItem::logic_connect = true; + CItem::quien = ID; +} void Or::save(FILE *archivo) { diff --git a/Constructor/or.h b/Constructor/or.h index 9da1cd2..10b9234 100644 --- a/Constructor/or.h +++ b/Constructor/or.h @@ -9,8 +9,10 @@ class Or : public CItem { virtual ~Or(); virtual bool on_button_press_event(GdkEventButton *event); virtual void on_menu_popup_rotar(); + virtual void on_menu_popup_conectar(); virtual void save(FILE *archivo); virtual bool check_connection(); + std::list connected_items; private: Glib::RefPtr imageN; // 0 Glib::RefPtr imageS; // 1 diff --git a/Constructor/workplace.cpp b/Constructor/workplace.cpp index 1e7ceab..e1fa47d 100644 --- a/Constructor/workplace.cpp +++ b/Constructor/workplace.cpp @@ -1,9 +1,8 @@ #include "workplace.h" +#include "item.h" WorkPlace::WorkPlace( BaseObjectType* cobject, const Glib::RefPtr &refGlade):Gtk::Fixed(cobject) { - refGlade->get_widget_derived("viewport",viewport); - viewport->workplace = this; } WorkPlace::~WorkPlace() @@ -22,12 +21,12 @@ bool WorkPlace::on_expose_event(GdkEventExpose *event) get_window()->draw_point (get_style()->get_black_gc(), x-1,y); } -/* std::list::iterator i = lista_lineas.begin(); + std::list::iterator i = lista_lineas.begin(); while ( i != lista_lineas.end() ) { t_line temp = *i; - get_window()->draw_line (get_style()->get_black_gc(), temp.x,temp.y,temp.w,temp.z); + get_window()->draw_line (get_style()->get_black_gc(), temp.logic->get_position_x(),temp.logic->get_position_y(), temp.store->get_position_x(),temp.store->get_position_y()); i++; - }*/ + } return true; } @@ -44,3 +43,15 @@ void WorkPlace::delete_item(int _id) i++; } } + +CItem* WorkPlace::get_logic_item(int _id) +{ + std::list::iterator i = lista_logic_Items->begin(); + while ( i != lista_logic_Items->end() ){ + CItem *temp = *i; + if ( temp->get_id() == _id ) + return temp; + i++; + } + return NULL; +} diff --git a/Constructor/workplace.h b/Constructor/workplace.h index c3e2901..896e908 100644 --- a/Constructor/workplace.h +++ b/Constructor/workplace.h @@ -5,11 +5,12 @@ #include #include #include -#include "activezone.h" -#include "item.h" class CItem; -class ActiveZone; + +typedef struct { + CItem *logic, *store; +}t_line; class WorkPlace:public Gtk::Fixed { public: @@ -17,9 +18,9 @@ class WorkPlace:public Gtk::Fixed { virtual ~WorkPlace(); virtual bool on_expose_event(GdkEventExpose *event); void delete_item(int _id); - std::list *listaItems; + CItem *get_logic_item(int _id); + std::list *listaItems, *lista_logic_Items; std::list lista_lineas; - ActiveZone *viewport; }; #endif -- 2.43.0