From 43fc1b3f57852f2af098fa7411e83220015aaa6f Mon Sep 17 00:00:00 2001 From: Ricardo Markiewicz Date: Sun, 16 Nov 2003 22:09:44 +0000 Subject: [PATCH 1/1] * Cliente carga todos los widgets (falta exclusa!) * Los Items ahora son Gtk::EventBox con una imagen dentro, para poder atender los clicks * El cliente ya casi esta tarminado, en cuanto a visualizar una planta se refiere. Falta agregar escuchar al server --- Client/include/item.h | 11 +- Client/include/item_codo.h | 6 +- Client/include/item_conduct.h | 13 ++ Client/include/item_exclusa.h | 13 ++ Client/include/{item_bomba.h => item_pump.h} | 6 +- Client/include/item_tank.h | 13 ++ Client/include/item_union.h | 13 ++ Client/include/principal.h | 17 ++- Client/src/Makefile.am | 8 +- Client/src/client.glade | 4 +- Client/src/item.cpp | 20 +-- Client/src/item_bomba.cpp | 19 --- Client/src/item_codo.cpp | 15 +- Client/src/item_conduct.cpp | 20 +++ Client/src/item_exclusa.cpp | 20 +++ Client/src/item_pump.cpp | 20 +++ Client/src/item_tank.cpp | 20 +++ Client/src/item_union.cpp | 27 ++++ Client/src/principal.cpp | 144 ++++++++++++++++++- 19 files changed, 350 insertions(+), 59 deletions(-) create mode 100644 Client/include/item_conduct.h create mode 100644 Client/include/item_exclusa.h rename Client/include/{item_bomba.h => item_pump.h} (60%) create mode 100644 Client/include/item_tank.h create mode 100644 Client/include/item_union.h delete mode 100644 Client/src/item_bomba.cpp create mode 100644 Client/src/item_conduct.cpp create mode 100644 Client/src/item_exclusa.cpp create mode 100644 Client/src/item_pump.cpp create mode 100644 Client/src/item_tank.cpp create mode 100644 Client/src/item_union.cpp diff --git a/Client/include/item.h b/Client/include/item.h index 341039d..c77df41 100644 --- a/Client/include/item.h +++ b/Client/include/item.h @@ -8,18 +8,19 @@ #include #include -class Item:public Gtk::DrawingArea { +class ViewItem:public Gtk::EventBox { public: - Item(Glib::ustring _name); - virtual ~Item(); - virtual bool on_expose_event(GdkEventExpose* event); + ViewItem(Glib::ustring _name); + virtual ~ViewItem(); +// virtual bool on_expose_event(GdkEventExpose* event); Glib::ustring get_name(); void set_position(int _x, int _y); void set_name(Glib::ustring _name); protected: Glib::ustring name; - Glib::RefPtr image; + Gtk::Image image; int x, y; }; #endif + diff --git a/Client/include/item_codo.h b/Client/include/item_codo.h index 6c4d7c8..ccd47af 100644 --- a/Client/include/item_codo.h +++ b/Client/include/item_codo.h @@ -4,10 +4,10 @@ #include "item.h" // Hago una clase porque despues van a tener comportamientos distintos! -class Codo:public Item { +class ViewCodo:public ViewItem { public: - Codo(Glib::ustring _name, int orientacion); - virtual ~Codo(); + ViewCodo(Glib::ustring _name, int orientacion); + virtual ~ViewCodo(); }; #endif diff --git a/Client/include/item_conduct.h b/Client/include/item_conduct.h new file mode 100644 index 0000000..4c0ddfc --- /dev/null +++ b/Client/include/item_conduct.h @@ -0,0 +1,13 @@ +#ifndef _ITEM_CONDUCT_H_ +#define _ITEM_CONDUCT_H_ + +#include "item.h" + +// Hago una clase porque despues van a tener comportamientos distintos! +class ViewConduct:public ViewItem { +public: + ViewConduct(Glib::ustring _name, int orientacion); + virtual ~ViewConduct(); +}; + +#endif diff --git a/Client/include/item_exclusa.h b/Client/include/item_exclusa.h new file mode 100644 index 0000000..b86216b --- /dev/null +++ b/Client/include/item_exclusa.h @@ -0,0 +1,13 @@ +#ifndef _ITEM_EXCLUSA_H_ +#define _ITEM_EXCLUSA_H_ + +#include "item.h" + +// Hago una clase porque despues van a tener comportamientos distintos! +class ViewExclusa:public ViewItem { +public: + ViewExclusa(Glib::ustring _name, int orientacion); + virtual ~ViewExclusa(); +}; + +#endif diff --git a/Client/include/item_bomba.h b/Client/include/item_pump.h similarity index 60% rename from Client/include/item_bomba.h rename to Client/include/item_pump.h index 119dda3..8fd4864 100644 --- a/Client/include/item_bomba.h +++ b/Client/include/item_pump.h @@ -4,10 +4,10 @@ #include "item.h" // Hago una clase porque despues van a tener comportamientos distintos! -class Bomba:public Item { +class ViewPump:public ViewItem { public: - Bomba(Glib::ustring _name, int orientacion); - virtual ~Bomba(); + ViewPump(Glib::ustring _name, int orientacion); + virtual ~ViewPump(); }; #endif diff --git a/Client/include/item_tank.h b/Client/include/item_tank.h new file mode 100644 index 0000000..ae4a2fd --- /dev/null +++ b/Client/include/item_tank.h @@ -0,0 +1,13 @@ +#ifndef _ITEM_TANK_H_ +#define _ITEM_TANK_H_ + +#include "item.h" + +// Hago una clase porque despues van a tener comportamientos distintos! +class ViewTank:public ViewItem { +public: + ViewTank(Glib::ustring _name, int orientacion); + virtual ~ViewTank(); +}; + +#endif diff --git a/Client/include/item_union.h b/Client/include/item_union.h new file mode 100644 index 0000000..e99d4af --- /dev/null +++ b/Client/include/item_union.h @@ -0,0 +1,13 @@ +#ifndef _ITEM_UNION_H_ +#define _ITEM_UNION_H_ + +#include "item.h" + +// Hago una clase porque despues van a tener comportamientos distintos! +class ViewUnion:public ViewItem { +public: + ViewUnion(Glib::ustring _name, int orientacion); + virtual ~ViewUnion(); +}; + +#endif diff --git a/Client/include/principal.h b/Client/include/principal.h index 420d111..f18735c 100644 --- a/Client/include/principal.h +++ b/Client/include/principal.h @@ -8,8 +8,8 @@ #include "dlg_conectar.h" #include "plaqui/server/controlclient.h" #include -#include "item_bomba.h" -#include "item_codo.h" +#include +#include "item.h" class Principal:public Gtk::Window { public: @@ -18,11 +18,19 @@ public: protected: PlaQui::Server::ControlClient *conexion; + // Utilizo un map para no tener que buscar un item + // en una lista cada vez que quiero actualizar su propiedad. + // Simplemente lo busco como map["nombre"] + std::map mapItems; // Funciones de carga del XML void loadBomba(xmlNodePtr nodo); void loadCodo(xmlNodePtr nodo); - + void loadConduct(xmlNodePtr nodo); + void loadExclusa(xmlNodePtr nodo); + void loadTank(xmlNodePtr nodo); + void loadUnion(xmlNodePtr nodo); + // Archivo XML del Padre Glib::RefPtr refXml; @@ -39,6 +47,9 @@ protected: virtual void on_dlg_connect_ok(); virtual void on_get_clicked(); virtual void on_mnu_prop(); + + virtual bool on_item_clicked(GdkEventButton *, ViewItem *); + // Callbacks para las conexiones void on_conexion_ok(); void on_conexion_error(unsigned code); diff --git a/Client/src/Makefile.am b/Client/src/Makefile.am index f41c909..686e912 100644 --- a/Client/src/Makefile.am +++ b/Client/src/Makefile.am @@ -13,8 +13,12 @@ plaqui_client_SOURCES = main.cpp \ principal.cpp \ dlg_conectar.cpp \ item.cpp \ - item_bomba.cpp \ - item_codo.cpp + item_pump.cpp \ + item_codo.cpp \ + item_conduct.cpp \ + item_exclusa.cpp \ + item_tank.cpp \ + item_union.cpp plaqui_client_LDADD = @PACKAGE_LIBS@ ../../Server/src/server.a -lsocket++ diff --git a/Client/src/client.glade b/Client/src/client.glade index b236d75..abd0e25 100644 --- a/Client/src/client.glade +++ b/Client/src/client.glade @@ -222,7 +222,7 @@ 290 - + True True GTK_POLICY_ALWAYS @@ -245,7 +245,7 @@ True - True + False diff --git a/Client/src/item.cpp b/Client/src/item.cpp index 18c2fee..418647e 100644 --- a/Client/src/item.cpp +++ b/Client/src/item.cpp @@ -1,36 +1,36 @@ #include "item.h" -Item::Item(Glib::ustring _name):Gtk::DrawingArea() +ViewItem::ViewItem(Glib::ustring _name):Gtk::EventBox(),image() { - //image = Gdk::Pixbuf::create_from_file(filename); name = _name; - //set_size_request(image->get_width(), image->get_height()); + set_events(Gdk::BUTTON_PRESS_MASK); + add(image); } -Item::~Item() +ViewItem::~ViewItem() { } - -bool Item::on_expose_event(GdkEventExpose* event) +/* +bool ViewItem::on_expose_event(GdkEventExpose* event) { 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 true; } - -void Item::set_position(int _x, int _y) +*/ +void ViewItem::set_position(int _x, int _y) { x = _x; y = _y; } -void Item::set_name(Glib::ustring _name) +void ViewItem::set_name(Glib::ustring _name) { name = _name; } -Glib::ustring Item::get_name() +Glib::ustring ViewItem::get_name() { return name; } diff --git a/Client/src/item_bomba.cpp b/Client/src/item_bomba.cpp deleted file mode 100644 index 6c249fc..0000000 --- a/Client/src/item_bomba.cpp +++ /dev/null @@ -1,19 +0,0 @@ - -#include "item_bomba.h" - -Bomba::Bomba(Glib::ustring _name, int orientacion):Item(_name) -{ - switch (orientacion) { - case 0: - image = Gdk::Pixbuf::create_from_file("bomba_e.png"); - break; - case 1: - image = Gdk::Pixbuf::create_from_file("bomba_o.png"); - } - set_size_request(image->get_width(), image->get_height()); -} - -Bomba::~Bomba() -{ -} - diff --git a/Client/src/item_codo.cpp b/Client/src/item_codo.cpp index 76aefe1..8b088f8 100644 --- a/Client/src/item_codo.cpp +++ b/Client/src/item_codo.cpp @@ -1,25 +1,26 @@ #include "item_codo.h" -Codo::Codo(Glib::ustring _name, int orientacion):Item(_name) +ViewCodo::ViewCodo(Glib::ustring _name, int orientacion):ViewItem(_name) { switch (orientacion) { case 0: - image = Gdk::Pixbuf::create_from_file("codo_o.png"); + image.set("codo_o.png"); break; case 1: - image = Gdk::Pixbuf::create_from_file("codo_n.png"); + image.set("codo_n.png"); break; case 2: - image = Gdk::Pixbuf::create_from_file("codo_e.png"); + image.set("codo_e.png"); break; case 3: - image = Gdk::Pixbuf::create_from_file("codo_s.png"); + image.set("codo_s.png"); } - set_size_request(image->get_width(), image->get_height()); + image.show(); + set_size_request(); } -Codo::~Codo() +ViewCodo::~ViewCodo() { } diff --git a/Client/src/item_conduct.cpp b/Client/src/item_conduct.cpp new file mode 100644 index 0000000..a5dd59d --- /dev/null +++ b/Client/src/item_conduct.cpp @@ -0,0 +1,20 @@ + +#include "item_conduct.h" + +ViewConduct::ViewConduct(Glib::ustring _name, int orientacion):ViewItem(_name) +{ + switch (orientacion) { + case 0: + image.set("canio_n.png"); + break; + case 1: + image.set("canio_s.png"); + } + image.show(); + set_size_request(); +} + +ViewConduct::~ViewConduct() +{ +} + diff --git a/Client/src/item_exclusa.cpp b/Client/src/item_exclusa.cpp new file mode 100644 index 0000000..aac6a1d --- /dev/null +++ b/Client/src/item_exclusa.cpp @@ -0,0 +1,20 @@ + +#include "item_exclusa.h" + +ViewExclusa::ViewExclusa(Glib::ustring _name, int orientacion):ViewItem(_name) +{ + switch (orientacion) { + case 0: + image.set("exclusa_h.png"); + break; + case 1: + image.set("exclusa_s.png"); + } + image.show(); + set_size_request(); +} + +ViewExclusa::~ViewExclusa() +{ +} + diff --git a/Client/src/item_pump.cpp b/Client/src/item_pump.cpp new file mode 100644 index 0000000..201ce2d --- /dev/null +++ b/Client/src/item_pump.cpp @@ -0,0 +1,20 @@ + +#include "item_pump.h" + +ViewPump::ViewPump(Glib::ustring _name, int orientacion):ViewItem(_name) +{ + switch (orientacion) { + case 0: + image.set("bomba_e.png"); + break; + case 1: + image.set("bomba_o.png"); + } + image.show(); + set_size_request(); +} + +ViewPump::~ViewPump() +{ +} + diff --git a/Client/src/item_tank.cpp b/Client/src/item_tank.cpp new file mode 100644 index 0000000..88b8eda --- /dev/null +++ b/Client/src/item_tank.cpp @@ -0,0 +1,20 @@ + +#include "item_tank.h" + +ViewTank::ViewTank(Glib::ustring _name, int orientacion):ViewItem(_name) +{ + switch (orientacion) { + case 0: + image.set("tanque_e.png"); + break; + case 1: + image.set("tanque_o.png"); + } + image.show(); + set_size_request(); +} + +ViewTank::~ViewTank() +{ +} + diff --git a/Client/src/item_union.cpp b/Client/src/item_union.cpp new file mode 100644 index 0000000..814bb2b --- /dev/null +++ b/Client/src/item_union.cpp @@ -0,0 +1,27 @@ + +#include "item_union.h" +#include + +ViewUnion::ViewUnion(Glib::ustring _name, int orientacion):ViewItem(_name) +{ + switch (orientacion) { + case 0: + image.set("y_n.png"); + break; + case 1: + image.set("y_e.png"); + break; + case 2: + image.set("y_s.png"); + break; + case 3: + image.set("y_o.png"); + } + image.show(); + set_size_request(); +} + +ViewUnion::~ViewUnion() +{ +} + diff --git a/Client/src/principal.cpp b/Client/src/principal.cpp index a68ee6e..4250709 100644 --- a/Client/src/principal.cpp +++ b/Client/src/principal.cpp @@ -5,6 +5,12 @@ #include #include #include +#include "item_codo.h" +#include "item_conduct.h" +#include "item_exclusa.h" +#include "item_tank.h" +#include "item_pump.h" +#include "item_union.h" Principal::Principal(BaseObjectType *co, const Glib::RefPtr &rg):Gtk::Window(co),refXml(rg) { @@ -115,6 +121,13 @@ void Principal::on_mnu_help_about() dlg->show();*/ } +bool Principal::on_item_clicked(GdkEventButton *e, ViewItem *i) +{ + txt_view->get_buffer()->insert_at_cursor("Item : "); + txt_view->get_buffer()->insert_at_cursor(i->get_name()); + txt_view->get_buffer()->insert_at_cursor("\n"); +} + void Principal::on_conexion_ok() { txt_view->get_buffer()->insert_at_cursor("El server dice que ta' todo ok!\n"); @@ -157,7 +170,6 @@ void Principal::on_mnu_prop() xmlDocPtr document; document = xmlParseFile("test.xml"); if (document == NULL) { - printf("Error al parsear test.xml\n"); return; } @@ -169,11 +181,22 @@ void Principal::on_mnu_prop() items = nodo->children; while (items != NULL) { if (items->type == XML_ELEMENT_NODE) { - if (strcmp((char *)items->name, "bomba")==0) { + if (xmlStrcmp(items->name, BAD_CAST"bomba")==0) { loadBomba(items); - } else if (strcmp((char *)items->name, "codo")==0) { + } else if (xmlStrcmp(items->name, BAD_CAST"codo")==0) { loadCodo(items); + } else if (xmlStrcmp(items->name, BAD_CAST"tubo")==0) { + loadConduct(items); + } else if (xmlStrcmp(items->name, BAD_CAST"exclusa")==0) { + loadExclusa(items); + } else if (xmlStrcmp(items->name, BAD_CAST"tanque")==0) { + loadTank(items); + } else if (xmlStrcmp(items->name, BAD_CAST"empalme")==0) { + loadUnion(items); } + + + } items = items->next; } @@ -205,13 +228,43 @@ void Principal::loadBomba(xmlNodePtr nodo) } // listo, ya recolecte todos los datos, ahora creo el objeto! - Bomba *b = Gtk::manage( new Bomba(name, orientacion) ); + ViewPump *b = Gtk::manage( new ViewPump(name, orientacion) ); + b->signal_button_press_event().connect(SigC::bind( SigC::slot(*this, &Principal::on_item_clicked), b) ); b->set_position(x,y); work_place->put(*b, x, y); b->show(); } void Principal::loadCodo(xmlNodePtr nodo) +{ + std::string name = (char *)xmlGetProp(nodo, BAD_CAST"nombre"); + int orientacion=0, x, y; + + nodo = nodo->children; + while (nodo != NULL) { + if (nodo->type == XML_ELEMENT_NODE) { + if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) { + orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) ); + } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) { + x = atoi( (char *)XML_GET_CONTENT(nodo->children) ); + } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) { + y = atoi( (char *)XML_GET_CONTENT(nodo->children) ); + } + } + nodo = nodo->next; + } + + // listo, ya recolecte todos los datos, ahora creo el objeto! + ViewItem *b = Gtk::manage( new ViewCodo(name, orientacion) ); + b->signal_button_press_event().connect(SigC::bind( SigC::slot(*this, &Principal::on_item_clicked), b) ); + b->set_position(x,y); + work_place->put(*b, x, y); + b->show(); + // los agrego al hash + //mapItems.insert(name, b); +} + +void Principal::loadConduct(xmlNodePtr nodo) { Glib::ustring name = (char *)xmlGetProp(nodo, BAD_CAST"nombre"); int orientacion=0, x, y; @@ -231,9 +284,90 @@ void Principal::loadCodo(xmlNodePtr nodo) } // listo, ya recolecte todos los datos, ahora creo el objeto! - Codo *b = Gtk::manage( new Codo(name, orientacion) ); + ViewConduct *b = Gtk::manage( new ViewConduct(name, orientacion) ); + b->signal_button_press_event().connect(SigC::bind( SigC::slot(*this, &Principal::on_item_clicked), b) ); b->set_position(x,y); work_place->put(*b, x, y); b->show(); } +void Principal::loadExclusa(xmlNodePtr nodo) +{ + Glib::ustring name = (char *)xmlGetProp(nodo, BAD_CAST"nombre"); + int orientacion=0, x, y; + + nodo = nodo->children; + while (nodo != NULL) { + if (nodo->type == XML_ELEMENT_NODE) { + if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) { + orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) ); + } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) { + x = atoi( (char *)XML_GET_CONTENT(nodo->children) ); + } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) { + y = atoi( (char *)XML_GET_CONTENT(nodo->children) ); + } + } + nodo = nodo->next; + } + + // listo, ya recolecte todos los datos, ahora creo el objeto! + ViewExclusa *b = Gtk::manage( new ViewExclusa(name, orientacion) ); + b->signal_button_press_event().connect(SigC::bind( SigC::slot(*this, &Principal::on_item_clicked), b) ); + b->set_position(x,y); + work_place->put(*b, x, y); + b->show(); +} + +void Principal::loadTank(xmlNodePtr nodo) +{ + Glib::ustring name = (char *)xmlGetProp(nodo, BAD_CAST"nombre"); + int orientacion=0, x, y; + + nodo = nodo->children; + while (nodo != NULL) { + if (nodo->type == XML_ELEMENT_NODE) { + if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) { + orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) ); + } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) { + x = atoi( (char *)XML_GET_CONTENT(nodo->children) ); + } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) { + y = atoi( (char *)XML_GET_CONTENT(nodo->children) ); + } + } + nodo = nodo->next; + } + + // listo, ya recolecte todos los datos, ahora creo el objeto! + ViewTank *b = Gtk::manage( new ViewTank(name, orientacion) ); + b->signal_button_press_event().connect(SigC::bind( SigC::slot(*this, &Principal::on_item_clicked), b) ); + b->set_position(x,y); + work_place->put(*b, x, y); + b->show(); +} + +void Principal::loadUnion(xmlNodePtr nodo) +{ + Glib::ustring name = (char *)xmlGetProp(nodo, BAD_CAST"nombre"); + int orientacion=0, x, y; + + nodo = nodo->children; + while (nodo != NULL) { + if (nodo->type == XML_ELEMENT_NODE) { + if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) { + orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) ); + } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) { + x = atoi( (char *)XML_GET_CONTENT(nodo->children) ); + } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) { + y = atoi( (char *)XML_GET_CONTENT(nodo->children) ); + } + } + nodo = nodo->next; + } + + // listo, ya recolecte todos los datos, ahora creo el objeto! + ViewUnion *b = Gtk::manage( new ViewUnion(name, orientacion) ); + b->signal_button_release_event().connect(SigC::bind( SigC::slot(*this, &Principal::on_item_clicked), b) ); + b->set_position(x,y); + work_place->put(*b, x, y); + b->show(); +} -- 2.43.0