9 #include "item_conduct.h"
10 #include "item_exclusa.h"
11 #include "item_tank.h"
12 #include "item_pump.h"
13 #include "item_union.h"
14 #include "item_drain.h"
16 Principal::Principal(BaseObjectType *co, const Glib::RefPtr<Gnome::Glade::Xml> &rg):Gtk::Window(co),refXml(rg)
18 Gtk::MenuItem *conect=0, *exit=0, *about=0, *mnu_prop=0;
19 Gtk::Button *btn_get=0, *bar_connect=0;
21 txt_target = txt_command = txt_args = 0;
23 lbl_nombre = lbl_color = lbl_flujo = 0;
25 rg->get_widget("lbl_nombre", lbl_nombre);
26 rg->get_widget("mnu_file_connect", conect);
27 rg->get_widget("mnu_file_exit", exit);
28 rg->get_widget("mnu_help_about", about);
29 rg->get_widget("mnu_prop", mnu_prop);
30 rg->get_widget_derived("dlgConectar", dlg_conectar);
31 rg->get_widget("btn_get", btn_get);
32 rg->get_widget("txt_view", txt_view);
33 rg->get_widget("txt_target", txt_target);
34 rg->get_widget("txt_command", txt_command);
35 rg->get_widget("txt_args", txt_args);
36 rg->get_widget("bar_connect", bar_connect);
37 rg->get_widget("work_place", work_place);
38 rg->get_widget("ico_conected", ico_conected);
40 dlg_conectar->get_ok_button()->signal_clicked().connect( SigC::slot(*this, &Principal::on_dlg_connect_ok) );
41 mnu_prop->signal_activate().connect( SigC::slot(*this, &Principal::on_mnu_prop));
42 conect->signal_activate().connect( SigC::slot(*this, &Principal::on_mnu_file_connect));
43 bar_connect->signal_clicked().connect( SigC::slot(*this, &Principal::on_mnu_file_connect));
44 exit->signal_activate().connect( SigC::slot(*this, &Principal::on_mnu_file_exit));
45 about->signal_activate().connect( SigC::slot(*this, &Principal::on_mnu_help_about));
46 btn_get->signal_clicked().connect( SigC::slot(*this, &Principal::on_get_clicked) );
51 Principal::~Principal()
56 void Principal::on_dlg_connect_ok()
58 if (conexion == NULL) {
61 conexion = new PlaQui::Server::ControlClient(dlg_conectar->get_server_name(), dlg_conectar->get_server_port());
64 txt_view->get_buffer()->insert_at_cursor("NO SE PUDO CREAR OBJETO\n");
70 // Conecto las señales
71 conexion->signal_ok_received().connect( SigC::slot(*this, &Principal::on_conexion_ok) );
72 conexion->signal_error_received().connect( SigC::slot(*this, &Principal::on_conexion_error) );
73 conexion->signal_connected().connect( SigC::slot(*this, &Principal::on_conexion_connected) );
74 conexion->signal_finished().connect( SigC::slot(*this, &Principal::on_conexion_finished) );
80 txt_view->get_buffer()->insert_at_cursor("no se puede correr conexion->run()!!!\n");
83 txt_view->get_buffer()->insert_at_cursor("YA ESTAS CONECTADO\n");
88 void Principal::on_mnu_file_exit()
93 void Principal::on_mnu_file_connect()
98 void Principal::on_mnu_help_about()
100 // preparo para leer el archivo ChangeLog
101 /* Glib::RefPtr<Gnome::Glade::Xml> xml;
103 Glib::RefPtr<Gtk::TextBuffer> log_buffer;
104 Glib::RefPtr<Glib::IOChannel> log_io;
106 log_buffer = Gtk::TextBuffer::create();
107 log_io = Glib::IOChannel::create_from_file("../ChangeLog", "r");
108 while (log_io->read_line(line) != Glib::IO_STATUS_EOF) {
109 log_buffer->insert_at_cursor(line);
113 xml = Gnome::Glade::Xml::create("client.glade", "dlgAbout");
115 catch(const Gnome::Glade::XmlError &ex) {
116 std::cerr << ex.what() << std::endl;
119 Gtk::Window *dlg = 0;
120 Gtk::Button *btn_cerrar = 0;
121 Gtk::TextView *txt_changelog = 0;
122 xml->get_widget("dlgAbout", dlg);
123 xml->get_widget("btn_close", btn_cerrar);
124 xml->get_widget("txt_changelog", txt_changelog);
125 btn_cerrar->signal_clicked().connect(SigC::slot(*dlg, &Gtk::Dialog::hide));
126 txt_changelog->set_buffer(log_buffer);
130 bool Principal::on_item_clicked(GdkEventButton *e, ViewItem *i)
132 lbl_nombre->set_text(i->get_name());
133 txt_view->get_buffer()->insert_at_cursor("Selecciono ");
134 txt_view->get_buffer()->insert_at_cursor(i->get_name());
135 txt_view->get_buffer()->insert_at_cursor("\n");
138 void Principal::on_conexion_connected()
140 txt_view->get_buffer()->insert_at_cursor("CONNECTED\n");
141 ico_conected->set( Gtk::Stock::YES , Gtk::IconSize(Gtk::ICON_SIZE_LARGE_TOOLBAR));
144 void Principal::on_conexion_finished()
146 txt_view->get_buffer()->insert_at_cursor("HANG UP\n");
147 ico_conected->set( Gtk::Stock::NO , Gtk::IconSize(Gtk::ICON_SIZE_LARGE_TOOLBAR));
151 void Principal::on_conexion_ok(const std::string &body)
153 std::cout << body << std::endl;
154 txt_view->get_buffer()->insert_at_cursor("<IN>\n");
155 txt_view->get_buffer()->insert_at_cursor(Glib::locale_to_utf8(body));
156 txt_view->get_buffer()->insert_at_cursor("</IN>\n");
159 void Principal::on_conexion_error(unsigned code)
165 txt_view->get_buffer()->insert_at_cursor("El server dice que hay error : ");
166 txt_view->get_buffer()->insert_at_cursor(s);
167 txt_view->get_buffer()->insert_at_cursor("\n");
171 void Principal::on_get_clicked()
173 if (conexion == NULL) {
174 txt_view->get_buffer()->insert_at_cursor("SIN CONEXION\n");
179 PlaQui::Server::Command command(txt_target->get_text(), txt_command->get_text());
180 command.add_arg( txt_args->get_text() );
181 txt_view->get_buffer()->insert_at_cursor("Enviando comando\n");
183 conexion->send(command);
186 txt_view->get_buffer()->insert_at_cursor("EXCEPTION EN conexion->send !!\n");
191 void Principal::on_mnu_prop()
193 /* Parseo de ejemplo de un XML desde archivo */
195 document = xmlParseFile("test.xml");
196 if (document == NULL) {
200 /* bien, el archivo se parseo bien! */
201 xmlNodePtr nodo, items;
202 nodo = document->children;
204 if (strcmp((char *)nodo->name, "planta") == 0) {
205 items = nodo->children;
206 while (items != NULL) {
207 if (items->type == XML_ELEMENT_NODE) {
208 if (xmlStrcmp(items->name, BAD_CAST"bomba")==0) {
210 } else if (xmlStrcmp(items->name, BAD_CAST"codo")==0) {
212 } else if (xmlStrcmp(items->name, BAD_CAST"tubo")==0) {
214 } else if (xmlStrcmp(items->name, BAD_CAST"exclusa")==0) {
216 } else if (xmlStrcmp(items->name, BAD_CAST"tanque")==0) {
218 } else if (xmlStrcmp(items->name, BAD_CAST"empalme")==0) {
220 } else if (xmlStrcmp(items->name, BAD_CAST"drenaje")==0) {
230 void Principal::loadBomba(xmlNodePtr nodo)
232 Glib::ustring name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
233 int orientacion=0, x, y;
235 nodo = nodo->children;
236 while (nodo != NULL) {
237 if (nodo->type == XML_ELEMENT_NODE) {
238 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
239 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
240 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
241 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
242 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
243 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
249 // listo, ya recolecte todos los datos, ahora creo el objeto!
250 ViewPump *b = Gtk::manage( new ViewPump(name, orientacion) );
251 b->signal_button_press_event().connect(SigC::bind( SigC::slot(*this, &Principal::on_item_clicked), b) );
252 b->set_position(x,y);
253 work_place->put(*b, x, y);
255 // los agrego al hash
259 void Principal::loadCodo(xmlNodePtr nodo)
261 std::string name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
262 int orientacion=0, x, y;
264 nodo = nodo->children;
265 while (nodo != NULL) {
266 if (nodo->type == XML_ELEMENT_NODE) {
267 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
268 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
269 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
270 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
271 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
272 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
278 // listo, ya recolecte todos los datos, ahora creo el objeto!
279 ViewItem *b = Gtk::manage( new ViewCodo(name, orientacion) );
280 b->signal_button_press_event().connect(SigC::bind( SigC::slot(*this, &Principal::on_item_clicked), b) );
281 b->set_position(x,y);
282 work_place->put(*b, x, y);
284 // los agrego al hash
288 void Principal::loadConduct(xmlNodePtr nodo)
290 Glib::ustring name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
291 int orientacion=0, x, y;
293 nodo = nodo->children;
294 while (nodo != NULL) {
295 if (nodo->type == XML_ELEMENT_NODE) {
296 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
297 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
298 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
299 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
300 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
301 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
307 // listo, ya recolecte todos los datos, ahora creo el objeto!
308 ViewConduct *b = Gtk::manage( new ViewConduct(name, orientacion) );
309 b->signal_button_press_event().connect(SigC::bind( SigC::slot(*this, &Principal::on_item_clicked), b) );
310 b->set_position(x,y);
311 work_place->put(*b, x, y);
313 // los agrego al hash
317 void Principal::loadExclusa(xmlNodePtr nodo)
319 Glib::ustring name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
320 int orientacion=0, x, y;
322 nodo = nodo->children;
323 while (nodo != NULL) {
324 if (nodo->type == XML_ELEMENT_NODE) {
325 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
326 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
327 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
328 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
329 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
330 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
336 // listo, ya recolecte todos los datos, ahora creo el objeto!
337 ViewExclusa *b = Gtk::manage( new ViewExclusa(name, orientacion) );
338 b->signal_button_press_event().connect(SigC::bind( SigC::slot(*this, &Principal::on_item_clicked), b) );
339 b->set_position(x,y);
340 work_place->put(*b, x, y);
342 // los agrego al hash
346 void Principal::loadTank(xmlNodePtr nodo)
348 Glib::ustring name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
349 int orientacion=0, x, y;
351 nodo = nodo->children;
352 while (nodo != NULL) {
353 if (nodo->type == XML_ELEMENT_NODE) {
354 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
355 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
356 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
357 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
358 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
359 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
365 // listo, ya recolecte todos los datos, ahora creo el objeto!
366 ViewTank *b = Gtk::manage( new ViewTank(name, orientacion) );
367 b->signal_button_press_event().connect(SigC::bind( SigC::slot(*this, &Principal::on_item_clicked), b) );
368 b->set_position(x,y);
369 work_place->put(*b, x, y);
371 // los agrego al hash
375 void Principal::loadUnion(xmlNodePtr nodo)
377 Glib::ustring name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
378 int orientacion=0, x, y;
380 nodo = nodo->children;
381 while (nodo != NULL) {
382 if (nodo->type == XML_ELEMENT_NODE) {
383 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
384 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
385 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
386 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
387 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
388 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
394 // listo, ya recolecte todos los datos, ahora creo el objeto!
395 ViewUnion *b = Gtk::manage( new ViewUnion(name, orientacion) );
396 b->signal_button_release_event().connect(SigC::bind( SigC::slot(*this, &Principal::on_item_clicked), b) );
397 b->set_position(x,y);
398 work_place->put(*b, x, y);
400 // los agrego al hash
404 void Principal::loadDrain(xmlNodePtr nodo)
406 Glib::ustring name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
407 int orientacion=0, x, y;
409 nodo = nodo->children;
410 while (nodo != NULL) {
411 if (nodo->type == XML_ELEMENT_NODE) {
412 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
413 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
414 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
415 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
416 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
417 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
423 // listo, ya recolecte todos los datos, ahora creo el objeto!
424 ViewDrain *b = Gtk::manage( new ViewDrain(name, orientacion) );
425 b->signal_button_release_event().connect(SigC::bind( SigC::slot(*this, &Principal::on_item_clicked), b) );
426 b->set_position(x,y);
427 work_place->put(*b, x, y);
429 // los agrego al hash