]> git.llucax.com Git - z.facultad/75.42/plaqui.git/commitdiff
* Cliente carga todos los widgets (falta exclusa!)
authorRicardo Markiewicz <gazer.arg@gmail.com>
Sun, 16 Nov 2003 22:09:44 +0000 (22:09 +0000)
committerRicardo Markiewicz <gazer.arg@gmail.com>
Sun, 16 Nov 2003 22:09:44 +0000 (22:09 +0000)
 * 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

19 files changed:
Client/include/item.h
Client/include/item_codo.h
Client/include/item_conduct.h [new file with mode: 0644]
Client/include/item_exclusa.h [new file with mode: 0644]
Client/include/item_pump.h [moved from Client/include/item_bomba.h with 60% similarity]
Client/include/item_tank.h [new file with mode: 0644]
Client/include/item_union.h [new file with mode: 0644]
Client/include/principal.h
Client/src/Makefile.am
Client/src/client.glade
Client/src/item.cpp
Client/src/item_bomba.cpp [deleted file]
Client/src/item_codo.cpp
Client/src/item_conduct.cpp [new file with mode: 0644]
Client/src/item_exclusa.cpp [new file with mode: 0644]
Client/src/item_pump.cpp [new file with mode: 0644]
Client/src/item_tank.cpp [new file with mode: 0644]
Client/src/item_union.cpp [new file with mode: 0644]
Client/src/principal.cpp

index 341039dedc4c8b32ae1192e7db083d5b4b9a7567..c77df412cfcae4e1430466547bba192363e1cdb1 100644 (file)
@@ -8,18 +8,19 @@
 #include <libglademm.h>
 #include <gtkmm/entry.h>
 
-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<Gdk::Pixbuf> image;
+       Gtk::Image image;
        int x, y;
 };
 
 #endif
+
index 6c4d7c8b2887a3e79434df61ad853f2c10f569fd..ccd47af187d9f352f7c5ac5db7faab1ded9eaf8c 100644 (file)
@@ -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 (file)
index 0000000..4c0ddfc
--- /dev/null
@@ -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 (file)
index 0000000..b86216b
--- /dev/null
@@ -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
similarity index 60%
rename from Client/include/item_bomba.h
rename to Client/include/item_pump.h
index 119dda3854ed0364be599068601ab79281de2dc2..8fd486444f61639903a4d0b3885095a1573c6877 100644 (file)
@@ -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 (file)
index 0000000..ae4a2fd
--- /dev/null
@@ -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 (file)
index 0000000..e99d4af
--- /dev/null
@@ -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
index 420d111ac57e859c6b3face8a3a475c128b50a30..f18735cbe942d6125a9e6fc9f02a65d9c18e070f 100644 (file)
@@ -8,8 +8,8 @@
 #include "dlg_conectar.h"
 #include "plaqui/server/controlclient.h"
 #include <libxml/parser.h>
-#include "item_bomba.h"
-#include "item_codo.h"
+#include <map>
+#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<const std::string, ViewItem *> 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<Gnome::Glade::Xml> 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);
index f41c909820e9578c98184f84c39d508c5c6e4866..686e9126d37b4afbe3a8a38ebb43ae08613d4e04 100644 (file)
@@ -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++ 
 
index b236d75bfbe3f837afb03781b72add425e0192e0..abd0e2576fb7177be2c06366822c721a4cded993 100644 (file)
              <property name="position">290</property>
 
              <child>
-               <widget class="GtkScrolledWindow" id="scrolledwindow1">
+               <widget class="GtkScrolledWindow" id="scrolledwindow4">
                  <property name="visible">True</property>
                  <property name="can_focus">True</property>
                  <property name="hscrollbar_policy">GTK_POLICY_ALWAYS</property>
                </widget>
                <packing>
                  <property name="shrink">True</property>
-                 <property name="resize">True</property>
+                 <property name="resize">False</property>
                </packing>
              </child>
 
index 18c2fee409cbede7e6137e876c44d7879d98d492..418647ec589f1bccd80856d16504a7bd2e89af34 100644 (file)
@@ -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 (file)
index 6c249fc..0000000
+++ /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()
-{
-}
-
index 76aefe1461b6a02587e56ea44d433db6c516a978..8b088f8ea566f58db6e032f0e33467897a87747d 100644 (file)
@@ -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 (file)
index 0000000..a5dd59d
--- /dev/null
@@ -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 (file)
index 0000000..aac6a1d
--- /dev/null
@@ -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 (file)
index 0000000..201ce2d
--- /dev/null
@@ -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 (file)
index 0000000..88b8eda
--- /dev/null
@@ -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 (file)
index 0000000..814bb2b
--- /dev/null
@@ -0,0 +1,27 @@
+
+#include "item_union.h"
+#include <iostream>
+
+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()
+{
+}
+
index a68ee6e46d66b28bec9c85abc8f9876810e7cd5c..42507094f23c3bb3f3e8615b6f00958cbce8c108 100644 (file)
@@ -5,6 +5,12 @@
 #include <iostream>
 #include <sstream>
 #include <string>
+#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<Gnome::Glade::Xml> &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();
+}