]> git.llucax.com Git - z.facultad/75.42/plaqui.git/commitdiff
* Se agrega ejemplo de carga desde un archivo XML. Para operar, copiar un xml
authorRicardo Markiewicz <gazer.arg@gmail.com>
Sat, 15 Nov 2003 17:45:38 +0000 (17:45 +0000)
committerRicardo Markiewicz <gazer.arg@gmail.com>
Sat, 15 Nov 2003 17:45:38 +0000 (17:45 +0000)
   al directorio del ejecutable, renombrarlo como text.xml, luego cargar la
   aplicacion e ir al menu Ver->Propiedades. Esto carga solo las bombas y los
   codos que tenga el circuito por ahora !
 * Se agregan las imagenes en /pixmaps (por ahora copien codo_*.png y
   bomba*.png al directorio src para poder cargar del XML)

28 files changed:
Client/include/item.h [new file with mode: 0644]
Client/include/item_bomba.h [new file with mode: 0644]
Client/include/item_codo.h [new file with mode: 0644]
Client/include/principal.h
Client/pixmaps/bomba_e.png [new file with mode: 0644]
Client/pixmaps/bomba_o.png [new file with mode: 0644]
Client/pixmaps/canio_n.png [new file with mode: 0644]
Client/pixmaps/canio_s.png [new file with mode: 0644]
Client/pixmaps/codo_e.png [new file with mode: 0644]
Client/pixmaps/codo_n.png [new file with mode: 0644]
Client/pixmaps/codo_o.png [new file with mode: 0644]
Client/pixmaps/codo_s.png [new file with mode: 0644]
Client/pixmaps/exclusa_h.png [new file with mode: 0644]
Client/pixmaps/exclusa_s.png [new file with mode: 0644]
Client/pixmaps/tanque_e.png [new file with mode: 0644]
Client/pixmaps/tanque_o.png [new file with mode: 0644]
Client/pixmaps/y_e.png [new file with mode: 0644]
Client/pixmaps/y_n.png [new file with mode: 0644]
Client/pixmaps/y_o.png [new file with mode: 0644]
Client/pixmaps/y_s.png [new file with mode: 0644]
Client/src/Makefile.am
Client/src/client.glade
Client/src/item.cpp [new file with mode: 0644]
Client/src/item_bomba.cpp [new file with mode: 0644]
Client/src/item_codo.cpp [new file with mode: 0644]
Client/src/principal.cpp
Model/src/simulador.cpp
docs/clases.dia

diff --git a/Client/include/item.h b/Client/include/item.h
new file mode 100644 (file)
index 0000000..341039d
--- /dev/null
@@ -0,0 +1,25 @@
+#ifndef _ITEM_H_
+#define _ITEM_H_
+
+#include <iostream>
+#include <gtkmm/drawingarea.h>
+#include <gtkmm.h>
+#include <gdkmm.h>
+#include <libglademm.h>
+#include <gtkmm/entry.h>
+
+class Item:public Gtk::DrawingArea {
+public:
+       Item(Glib::ustring _name);
+       virtual ~Item();
+       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;
+       int x, y;
+};
+
+#endif
diff --git a/Client/include/item_bomba.h b/Client/include/item_bomba.h
new file mode 100644 (file)
index 0000000..119dda3
--- /dev/null
@@ -0,0 +1,13 @@
+#ifndef _ITEM_BOMBA_H_
+#define _ITEM_BOMBA_H_
+
+#include "item.h"
+
+// Hago una clase porque despues van a tener comportamientos distintos!
+class Bomba:public Item {
+public:
+       Bomba(Glib::ustring _name, int orientacion);
+       virtual ~Bomba();
+};
+
+#endif
diff --git a/Client/include/item_codo.h b/Client/include/item_codo.h
new file mode 100644 (file)
index 0000000..6c4d7c8
--- /dev/null
@@ -0,0 +1,13 @@
+#ifndef _ITEM_CODO_H_
+#define _ITEM_CODO_H_
+
+#include "item.h"
+
+// Hago una clase porque despues van a tener comportamientos distintos!
+class Codo:public Item {
+public:
+       Codo(Glib::ustring _name, int orientacion);
+       virtual ~Codo();
+};
+
+#endif
index 80dd6910373f57f50c82b3cf841c8e43c02ff43b..420d111ac57e859c6b3face8a3a475c128b50a30 100644 (file)
@@ -7,6 +7,9 @@
 #include <libglademm.h>
 #include "dlg_conectar.h"
 #include "plaqui/server/controlclient.h"
+#include <libxml/parser.h>
+#include "item_bomba.h"
+#include "item_codo.h"
 
 class Principal:public Gtk::Window {
 public:
@@ -16,6 +19,10 @@ public:
 protected:
        PlaQui::Server::ControlClient *conexion;
 
+       // Funciones de carga del XML
+       void loadBomba(xmlNodePtr nodo);
+       void loadCodo(xmlNodePtr nodo);
+
        // Archivo XML del Padre
        Glib::RefPtr<Gnome::Glade::Xml> refXml;
 
@@ -23,6 +30,7 @@ protected:
        DlgConectar *dlg_conectar;
        Gtk::Entry *txt_target, *txt_command, *txt_args;
        Gtk::TextView *txt_view;
+       Gtk::Fixed *work_place;
 
        // Callbacks del menu y la barra
        virtual void on_mnu_file_exit();
@@ -30,6 +38,7 @@ protected:
        virtual void on_mnu_help_about();
        virtual void on_dlg_connect_ok();
        virtual void on_get_clicked();
+       virtual void on_mnu_prop();
        // Callbacks para las conexiones
        void on_conexion_ok();
        void on_conexion_error(unsigned code);
diff --git a/Client/pixmaps/bomba_e.png b/Client/pixmaps/bomba_e.png
new file mode 100644 (file)
index 0000000..2d7dc9b
Binary files /dev/null and b/Client/pixmaps/bomba_e.png differ
diff --git a/Client/pixmaps/bomba_o.png b/Client/pixmaps/bomba_o.png
new file mode 100644 (file)
index 0000000..080ed6d
Binary files /dev/null and b/Client/pixmaps/bomba_o.png differ
diff --git a/Client/pixmaps/canio_n.png b/Client/pixmaps/canio_n.png
new file mode 100644 (file)
index 0000000..75a09eb
Binary files /dev/null and b/Client/pixmaps/canio_n.png differ
diff --git a/Client/pixmaps/canio_s.png b/Client/pixmaps/canio_s.png
new file mode 100644 (file)
index 0000000..3f33ea9
Binary files /dev/null and b/Client/pixmaps/canio_s.png differ
diff --git a/Client/pixmaps/codo_e.png b/Client/pixmaps/codo_e.png
new file mode 100644 (file)
index 0000000..3e924dc
Binary files /dev/null and b/Client/pixmaps/codo_e.png differ
diff --git a/Client/pixmaps/codo_n.png b/Client/pixmaps/codo_n.png
new file mode 100644 (file)
index 0000000..1cc9b68
Binary files /dev/null and b/Client/pixmaps/codo_n.png differ
diff --git a/Client/pixmaps/codo_o.png b/Client/pixmaps/codo_o.png
new file mode 100644 (file)
index 0000000..7f9705c
Binary files /dev/null and b/Client/pixmaps/codo_o.png differ
diff --git a/Client/pixmaps/codo_s.png b/Client/pixmaps/codo_s.png
new file mode 100644 (file)
index 0000000..3a0eece
Binary files /dev/null and b/Client/pixmaps/codo_s.png differ
diff --git a/Client/pixmaps/exclusa_h.png b/Client/pixmaps/exclusa_h.png
new file mode 100644 (file)
index 0000000..157f713
Binary files /dev/null and b/Client/pixmaps/exclusa_h.png differ
diff --git a/Client/pixmaps/exclusa_s.png b/Client/pixmaps/exclusa_s.png
new file mode 100644 (file)
index 0000000..06ddf61
Binary files /dev/null and b/Client/pixmaps/exclusa_s.png differ
diff --git a/Client/pixmaps/tanque_e.png b/Client/pixmaps/tanque_e.png
new file mode 100644 (file)
index 0000000..b78315a
Binary files /dev/null and b/Client/pixmaps/tanque_e.png differ
diff --git a/Client/pixmaps/tanque_o.png b/Client/pixmaps/tanque_o.png
new file mode 100644 (file)
index 0000000..e2d8c3e
Binary files /dev/null and b/Client/pixmaps/tanque_o.png differ
diff --git a/Client/pixmaps/y_e.png b/Client/pixmaps/y_e.png
new file mode 100644 (file)
index 0000000..8e6cae6
Binary files /dev/null and b/Client/pixmaps/y_e.png differ
diff --git a/Client/pixmaps/y_n.png b/Client/pixmaps/y_n.png
new file mode 100644 (file)
index 0000000..9921794
Binary files /dev/null and b/Client/pixmaps/y_n.png differ
diff --git a/Client/pixmaps/y_o.png b/Client/pixmaps/y_o.png
new file mode 100644 (file)
index 0000000..1d167f5
Binary files /dev/null and b/Client/pixmaps/y_o.png differ
diff --git a/Client/pixmaps/y_s.png b/Client/pixmaps/y_s.png
new file mode 100644 (file)
index 0000000..3e402dd
Binary files /dev/null and b/Client/pixmaps/y_s.png differ
index e47e463b926c01efd6389b4ade011da42f4c2c96..f41c909820e9578c98184f84c39d508c5c6e4866 100644 (file)
@@ -11,7 +11,10 @@ bin_PROGRAMS = plaqui-client
 
 plaqui_client_SOURCES = main.cpp \
                                                                                                principal.cpp \
-                                                                                               dlg_conectar.cpp
+                                                                                               dlg_conectar.cpp \
+                                                                                               item.cpp \
+                                                                                               item_bomba.cpp \
+                                                                                               item_codo.cpp
 
 plaqui_client_LDADD = @PACKAGE_LIBS@ ../../Server/src/server.a -lsocket++ 
 
index 353d6e1256ad8a52fdf39caed8851e7c988f021d..b236d75bfbe3f837afb03781b72add425e0192e0 100644 (file)
@@ -83,7 +83,7 @@
                <widget class="GtkMenu" id="menuitem3_menu">
 
                  <child>
-                   <widget class="GtkImageMenuItem" id="propiedades1">
+                   <widget class="GtkImageMenuItem" id="mnu_prop">
                      <property name="visible">True</property>
                      <property name="label" translatable="yes">Propiedades</property>
                      <property name="use_underline">True</property>
diff --git a/Client/src/item.cpp b/Client/src/item.cpp
new file mode 100644 (file)
index 0000000..18c2fee
--- /dev/null
@@ -0,0 +1,37 @@
+#include "item.h"
+
+
+Item::Item(Glib::ustring _name):Gtk::DrawingArea()
+{
+       //image = Gdk::Pixbuf::create_from_file(filename);
+       name = _name;
+       //set_size_request(image->get_width(), image->get_height());
+}
+
+Item::~Item()
+{
+}
+
+bool Item::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)
+{
+       x = _x;
+       y = _y;
+}
+
+void Item::set_name(Glib::ustring _name)
+{
+       name = _name;
+}
+
+Glib::ustring Item::get_name()
+{
+       return name;
+}
+
diff --git a/Client/src/item_bomba.cpp b/Client/src/item_bomba.cpp
new file mode 100644 (file)
index 0000000..6c249fc
--- /dev/null
@@ -0,0 +1,19 @@
+
+#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
new file mode 100644 (file)
index 0000000..76aefe1
--- /dev/null
@@ -0,0 +1,25 @@
+
+#include "item_codo.h"
+
+Codo::Codo(Glib::ustring _name, int orientacion):Item(_name)
+{
+       switch (orientacion) {
+               case 0:
+                       image = Gdk::Pixbuf::create_from_file("codo_o.png");
+               break;
+               case 1:
+                       image = Gdk::Pixbuf::create_from_file("codo_n.png");
+               break;
+               case 2:
+                       image = Gdk::Pixbuf::create_from_file("codo_e.png");
+               break;
+               case 3:
+                       image = Gdk::Pixbuf::create_from_file("codo_s.png");
+       }
+       set_size_request(image->get_width(), image->get_height());
+}
+
+Codo::~Codo()
+{
+}
+
index 70c36adadf93d1d46ec19b5d1574e428c05aaa95..a68ee6e46d66b28bec9c85abc8f9876810e7cd5c 100644 (file)
@@ -8,14 +8,16 @@
 
 Principal::Principal(BaseObjectType *co, const Glib::RefPtr<Gnome::Glade::Xml> &rg):Gtk::Window(co),refXml(rg)
 {
-       Gtk::MenuItem *conect=0, *exit=0, *about=0;
+       Gtk::MenuItem *conect=0, *exit=0, *about=0, *mnu_prop=0;
        Gtk::Button *btn_get=0, *bar_connect=0;
        txt_view = 0;
        txt_target = txt_command = txt_args = 0;
-       
+       work_place = 0;
+
        rg->get_widget("mnu_file_connect", conect);
        rg->get_widget("mnu_file_exit", exit);
        rg->get_widget("mnu_help_about", about);
+       rg->get_widget("mnu_prop", mnu_prop);
        rg->get_widget_derived("dlgConectar", dlg_conectar);
        rg->get_widget("btn_get", btn_get);
        rg->get_widget("txt_view", txt_view);
@@ -23,8 +25,10 @@ Principal::Principal(BaseObjectType *co, const Glib::RefPtr<Gnome::Glade::Xml> &
        rg->get_widget("txt_command", txt_command);
        rg->get_widget("txt_args", txt_args);
        rg->get_widget("bar_connect", bar_connect);
+       rg->get_widget("work_place", work_place);
 
        dlg_conectar->get_ok_button()->signal_clicked().connect( SigC::slot(*this, &Principal::on_dlg_connect_ok) );
+       mnu_prop->signal_activate().connect( SigC::slot(*this, &Principal::on_mnu_prop));
        conect->signal_activate().connect( SigC::slot(*this, &Principal::on_mnu_file_connect));
        bar_connect->signal_clicked().connect( SigC::slot(*this, &Principal::on_mnu_file_connect));
        exit->signal_activate().connect( SigC::slot(*this, &Principal::on_mnu_file_exit));
@@ -147,3 +151,89 @@ void Principal::on_get_clicked()
 
 }
 
+void Principal::on_mnu_prop()
+{
+       /* Parseo de ejemplo de un XML desde archivo */
+       xmlDocPtr document;
+       document = xmlParseFile("test.xml");
+       if (document == NULL) {
+               printf("Error al parsear test.xml\n");
+               return;
+       }
+
+       /* bien, el archivo se parseo bien! */
+       xmlNodePtr nodo, items;
+       nodo = document->children;
+
+       if (strcmp((char *)nodo->name, "planta") == 0) {
+               items = nodo->children;
+               while (items != NULL) {
+                       if (items->type == XML_ELEMENT_NODE) {
+                               if (strcmp((char *)items->name, "bomba")==0) {
+                                       loadBomba(items);
+                               } else if (strcmp((char *)items->name, "codo")==0) {
+                                       loadCodo(items);
+                               }
+                       }
+                       items = items->next;
+               }
+       } else {
+               printf("NO ES UNA PLANTA\n");
+       }
+       
+
+       printf("Fin parseo!!\n");
+}
+
+void Principal::loadBomba(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!
+       Bomba *b = Gtk::manage( new Bomba(name, orientacion) );
+       b->set_position(x,y);
+       work_place->put(*b, x, y);
+       b->show();
+}
+
+void Principal::loadCodo(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!
+       Codo *b = Gtk::manage( new Codo(name, orientacion) );
+       b->set_position(x,y);
+       work_place->put(*b, x, y);
+       b->show();
+}
+
index b3a93b1391f1bac799a403211041e48c05c3ebb1..91287112445e4fb27d9d08b59d0711b300875983 100644 (file)
@@ -61,7 +61,7 @@ void Simulador::add_tank(const std::string &name)
        Tank *p = new Tank(name);
        p->set_capacity(100);
        p->set_max_flow(10);
-       p->set_litros(50);
+       p->set_litros(10);
        tank_lst.push_back(p);
        items.push_back(p);
 }
index bfc8ef4fc423b8f425f46443a8737ee16e4e72d5..a67827001a37459260a5abb0062d533dfcde6c4e 100644 (file)
Binary files a/docs/clases.dia and b/docs/clases.dia differ