]> git.llucax.com Git - z.facultad/75.42/plaqui.git/blobdiff - Client/src/principal.cpp
Se agrega la consante INFINITO pendiente desde el primer commit :-)
[z.facultad/75.42/plaqui.git] / Client / src / principal.cpp
index 46ec40b3cb913471c37403fb829c9e620a916f80..7b441eec9ef970bbe0a7e79c557ca59de00b7134 100644 (file)
@@ -16,6 +16,8 @@
 #include <unistd.h>
 #include <glibmm/thread.h>
 
+#define INFINITO 99999999
+
 Principal::Principal(BaseObjectType *co, const Glib::RefPtr<Gnome::Glade::Xml> &rg):Gtk::Window(co),refXml(rg)
 {
        Gtk::MenuItem *conect=0, *exit=0, *about=0, *mnu_prop=0, *mnu_disconnect=0;
@@ -71,6 +73,10 @@ Principal::Principal(BaseObjectType *co, const Glib::RefPtr<Gnome::Glade::Xml> &
        update_ui.connect( SigC::slot(*this, &Principal::update_items_prop ) );
        load_xml_dispatch.connect( SigC::slot(*this, &Principal::loadXML ) );
        gc = Gdk::GC::create(get_window());
+       color_low = Gdk::Color("blue");
+       color_high = Gdk::Color("red");
+       Gtk::Widget::get_default_colormap()->alloc_color(color_low);
+       Gtk::Widget::get_default_colormap()->alloc_color(color_high);
 }
 
 Principal::~Principal()
@@ -80,7 +86,7 @@ Principal::~Principal()
        }
        // Espera a que termine realmente.
        while (conexion) {
-               Glib::usleep(10000); // 10 milisegundos
+               Glib::usleep(100000); // 0,1 segundo
        }
 }
 
@@ -105,6 +111,11 @@ bool Principal::on_workplace_expose_event(GdkEventExpose *e)
                                ViewItem *tmp = find_item(*linea);
                                x2 = tmp->x + tmp->out_x;
                                y2 = tmp->y + tmp->out_y;
+                               if (tmp->get_open()) {
+                                       gc->set_foreground(color_high);
+                               } else {
+                                       gc->set_foreground(color_low);
+                               }
                                gc->set_line_attributes(3, Gdk::LINE_SOLID, Gdk::CAP_NOT_LAST, Gdk::JOIN_MITER);
                                window->draw_line(gc, x2+tmp->item_offset_x, y2+tmp->item_offset_y, x2+tmp->item_offset_x, y1+i->second->offset_y);
                                window->draw_line(gc, x2+tmp->item_offset_x, y1+i->second->offset_y, x1+i->second->offset_x, y1+i->second->offset_y);
@@ -117,6 +128,11 @@ bool Principal::on_workplace_expose_event(GdkEventExpose *e)
                                ViewItem *tmp = find_item(*linea);
                                x2 = tmp->x + tmp->in_x;
                                y2 = tmp->y + tmp->in_y;
+                               if (i->second->get_open()) {
+                                       gc->set_foreground(color_high);
+                               } else {
+                                       gc->set_foreground(color_low);
+                               }
                                gc->set_line_attributes(3, Gdk::LINE_SOLID, Gdk::CAP_NOT_LAST, Gdk::JOIN_MITER);
                                window->draw_line(gc, x1+i->second->offset_x, y1+i->second->offset_y, x1+i->second->offset_x, y2+tmp->item_offset_y);
                                window->draw_line(gc, x1+i->second->offset_x, y2+tmp->item_offset_y, x2+tmp->item_offset_x, y2+tmp->item_offset_y);
@@ -155,6 +171,7 @@ void Principal::on_dlg_connect_ok()
 
                // Conecto las señales
                conexion->signal_ok_received().connect( SigC::slot(*this, &Principal::on_conexion_ok) );
+               conexion->signal_error().connect( SigC::slot(*this, &Principal::on_conexion_fatal_error) );
                conexion->signal_error_received().connect( SigC::slot(*this, &Principal::on_conexion_error) );
                conexion->signal_finished().connect( SigC::slot(*this, &Principal::on_conexion_finished) );
                conexion->signal_frame_received().connect(SigC::slot(*this, &Principal::on_conexion_frame));
@@ -173,9 +190,16 @@ void Principal::on_dlg_connect_ok()
 
 void Principal::on_mnu_file_exit()
 {
+       on_mnu_file_disconnect();
        Gtk::Main::quit();
 }
 
+bool Principal::on_delete_event(GdkEventAny *e)
+{
+       on_mnu_file_exit();
+       return false;
+}
+
 void Principal::on_btn_activar_clicked()
 {
        if ((conexion == NULL) || (last_selected == NULL)) return;
@@ -275,7 +299,7 @@ void Principal::update_items_prop()
        for(i=mapItems.begin(); i!=mapItems.end(); i++) {
                i->second->queue_draw();
        }
-
+       work_place->queue_draw();
 }
 
 void Principal::on_conexion_frame(const std::string &frame)
@@ -314,14 +338,29 @@ void Principal::on_conexion_ok(const std::string &body)
        }
 }
 
-void Principal::on_conexion_error(unsigned code)
+void Principal::on_conexion_fatal_error(const PlaQui::Server::ControlClient::Error& code, const std::string& desc)
+{
+       std::stringstream a;
+       std::string s;
+       a << code;
+       a >> s;
+       txt_view->get_buffer()->insert_at_cursor("Error de red nro. ");
+       txt_view->get_buffer()->insert_at_cursor(s);
+       txt_view->get_buffer()->insert_at_cursor(": ");
+       txt_view->get_buffer()->insert_at_cursor(desc);
+       txt_view->get_buffer()->insert_at_cursor("\n");
+}
+
+void Principal::on_conexion_error(unsigned code, const std::string& desc)
 {
        std::stringstream a;
        std::string s;
        a << code;
        a >> s;
-       txt_view->get_buffer()->insert_at_cursor("El server dice que hay error : ");
+       txt_view->get_buffer()->insert_at_cursor("El server dice que hay error nro. ");
        txt_view->get_buffer()->insert_at_cursor(s);
+       txt_view->get_buffer()->insert_at_cursor(": ");
+       txt_view->get_buffer()->insert_at_cursor(desc);
        txt_view->get_buffer()->insert_at_cursor("\n");
 }
 
@@ -744,7 +783,11 @@ void Principal::read_status_xml(const std::string &frame)
                                        tmp_b = get_bool_from_xml(items->children);
                                        item_name = (char *)xmlGetProp(items, BAD_CAST"name");
                                        mapItems[item_name]->set_open(tmp_b);
-                               }  else if (xmlStrcmp(items->name, BAD_CAST"color")==0) {
+                               } else if (xmlStrcmp(items->name, BAD_CAST"logic")==0) {
+                                       tmp_b = get_bool_from_xml(items->children);
+                                       item_name = (char *)xmlGetProp(items, BAD_CAST"name");
+                                       mapItems[item_name]->set_open(tmp_b);
+                               } else if (xmlStrcmp(items->name, BAD_CAST"color")==0) {
                                        item_name = (char *)xmlGetProp(items, BAD_CAST"name");
                                        mapItems[item_name]->set_color( get_rgb_from_xml(items->children) );
                                } else if (xmlStrcmp(items->name, BAD_CAST"tank")==0) {
@@ -776,7 +819,7 @@ void Principal::read_status_xml(const std::string &frame)
 
 Gdk::Color Principal::get_rgb_from_xml(xmlNodePtr nodo)
 {
-       unsigned r,g,b;
+       gushort r,g,b;
        while (nodo != NULL) {
                if (nodo->type == XML_ELEMENT_NODE) {
                        if (xmlStrcmp(nodo->name, BAD_CAST"r")==0)
@@ -788,14 +831,15 @@ Gdk::Color Principal::get_rgb_from_xml(xmlNodePtr nodo)
                }
                nodo = nodo->next;
        }
-       r = 65535 * r / 255;
-       g = 65535 * g / 255;
-       b = 65535 * b / 255;
+       r = static_cast<gushort>(65535 * (r / 255.0f));
+       g = static_cast<gushort>(65535 * (g / 255.0f));
+       b = static_cast<gushort>(65535 * (b / 255.0f));
        Gdk::Color c;
        c.set_rgb(r,g,b);
 
        return c;
 }
+
 float Principal::get_float_from_xml(xmlNodePtr nodo)
 {
        float tmp = -1;
@@ -808,6 +852,7 @@ float Principal::get_float_from_xml(xmlNodePtr nodo)
                }
                nodo = nodo->next;
        }
+       if (tmp == INFINITO) tmp = 0;
        return tmp;
 }