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()
153 txt_view->get_buffer()->insert_at_cursor("El server dice que ta' todo ok!\n");
156 void Principal::on_conexion_error(unsigned code)
162 txt_view->get_buffer()->insert_at_cursor("El server dice que hay error : ");
163 txt_view->get_buffer()->insert_at_cursor(s);
164 txt_view->get_buffer()->insert_at_cursor("\n");
168 void Principal::on_get_clicked()
170 if (conexion == NULL) {
171 txt_view->get_buffer()->insert_at_cursor("SIN CONEXION\n");
175 PlaQui::Server::Command command(txt_target->get_text(), txt_command->get_text());
176 command.add_arg( txt_args->get_text() );
177 txt_view->get_buffer()->insert_at_cursor("Enviando comando\n");
179 conexion->send(command);
182 txt_view->get_buffer()->insert_at_cursor("EXCEPTION EN conexion->send !!\n");
187 void Principal::on_mnu_prop()
189 /* Parseo de ejemplo de un XML desde archivo */
191 document = xmlParseFile("test.xml");
192 if (document == NULL) {
196 /* bien, el archivo se parseo bien! */
197 xmlNodePtr nodo, items;
198 nodo = document->children;
200 if (strcmp((char *)nodo->name, "planta") == 0) {
201 items = nodo->children;
202 while (items != NULL) {
203 if (items->type == XML_ELEMENT_NODE) {
204 if (xmlStrcmp(items->name, BAD_CAST"bomba")==0) {
206 } else if (xmlStrcmp(items->name, BAD_CAST"codo")==0) {
208 } else if (xmlStrcmp(items->name, BAD_CAST"tubo")==0) {
210 } else if (xmlStrcmp(items->name, BAD_CAST"exclusa")==0) {
212 } else if (xmlStrcmp(items->name, BAD_CAST"tanque")==0) {
214 } else if (xmlStrcmp(items->name, BAD_CAST"empalme")==0) {
216 } else if (xmlStrcmp(items->name, BAD_CAST"drenaje")==0) {
226 void Principal::loadBomba(xmlNodePtr nodo)
228 Glib::ustring name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
229 int orientacion=0, x, y;
231 nodo = nodo->children;
232 while (nodo != NULL) {
233 if (nodo->type == XML_ELEMENT_NODE) {
234 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
235 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
236 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
237 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
238 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
239 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
245 // listo, ya recolecte todos los datos, ahora creo el objeto!
246 ViewPump *b = Gtk::manage( new ViewPump(name, orientacion) );
247 b->signal_button_press_event().connect(SigC::bind( SigC::slot(*this, &Principal::on_item_clicked), b) );
248 b->set_position(x,y);
249 work_place->put(*b, x, y);
251 // los agrego al hash
255 void Principal::loadCodo(xmlNodePtr nodo)
257 std::string name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
258 int orientacion=0, x, y;
260 nodo = nodo->children;
261 while (nodo != NULL) {
262 if (nodo->type == XML_ELEMENT_NODE) {
263 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
264 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
265 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
266 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
267 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
268 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
274 // listo, ya recolecte todos los datos, ahora creo el objeto!
275 ViewItem *b = Gtk::manage( new ViewCodo(name, orientacion) );
276 b->signal_button_press_event().connect(SigC::bind( SigC::slot(*this, &Principal::on_item_clicked), b) );
277 b->set_position(x,y);
278 work_place->put(*b, x, y);
280 // los agrego al hash
284 void Principal::loadConduct(xmlNodePtr nodo)
286 Glib::ustring name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
287 int orientacion=0, x, y;
289 nodo = nodo->children;
290 while (nodo != NULL) {
291 if (nodo->type == XML_ELEMENT_NODE) {
292 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
293 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
294 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
295 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
296 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
297 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
303 // listo, ya recolecte todos los datos, ahora creo el objeto!
304 ViewConduct *b = Gtk::manage( new ViewConduct(name, orientacion) );
305 b->signal_button_press_event().connect(SigC::bind( SigC::slot(*this, &Principal::on_item_clicked), b) );
306 b->set_position(x,y);
307 work_place->put(*b, x, y);
309 // los agrego al hash
313 void Principal::loadExclusa(xmlNodePtr nodo)
315 Glib::ustring name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
316 int orientacion=0, x, y;
318 nodo = nodo->children;
319 while (nodo != NULL) {
320 if (nodo->type == XML_ELEMENT_NODE) {
321 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
322 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
323 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
324 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
325 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
326 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
332 // listo, ya recolecte todos los datos, ahora creo el objeto!
333 ViewExclusa *b = Gtk::manage( new ViewExclusa(name, orientacion) );
334 b->signal_button_press_event().connect(SigC::bind( SigC::slot(*this, &Principal::on_item_clicked), b) );
335 b->set_position(x,y);
336 work_place->put(*b, x, y);
338 // los agrego al hash
342 void Principal::loadTank(xmlNodePtr nodo)
344 Glib::ustring name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
345 int orientacion=0, x, y;
347 nodo = nodo->children;
348 while (nodo != NULL) {
349 if (nodo->type == XML_ELEMENT_NODE) {
350 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
351 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
352 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
353 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
354 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
355 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
361 // listo, ya recolecte todos los datos, ahora creo el objeto!
362 ViewTank *b = Gtk::manage( new ViewTank(name, orientacion) );
363 b->signal_button_press_event().connect(SigC::bind( SigC::slot(*this, &Principal::on_item_clicked), b) );
364 b->set_position(x,y);
365 work_place->put(*b, x, y);
367 // los agrego al hash
371 void Principal::loadUnion(xmlNodePtr nodo)
373 Glib::ustring name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
374 int orientacion=0, x, y;
376 nodo = nodo->children;
377 while (nodo != NULL) {
378 if (nodo->type == XML_ELEMENT_NODE) {
379 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
380 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
381 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
382 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
383 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
384 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
390 // listo, ya recolecte todos los datos, ahora creo el objeto!
391 ViewUnion *b = Gtk::manage( new ViewUnion(name, orientacion) );
392 b->signal_button_release_event().connect(SigC::bind( SigC::slot(*this, &Principal::on_item_clicked), b) );
393 b->set_position(x,y);
394 work_place->put(*b, x, y);
396 // los agrego al hash
400 void Principal::loadDrain(xmlNodePtr nodo)
402 Glib::ustring name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
403 int orientacion=0, x, y;
405 nodo = nodo->children;
406 while (nodo != NULL) {
407 if (nodo->type == XML_ELEMENT_NODE) {
408 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
409 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
410 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
411 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
412 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
413 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
419 // listo, ya recolecte todos los datos, ahora creo el objeto!
420 ViewDrain *b = Gtk::manage( new ViewDrain(name, orientacion) );
421 b->signal_button_release_event().connect(SigC::bind( SigC::slot(*this, &Principal::on_item_clicked), b) );
422 b->set_position(x,y);
423 work_place->put(*b, x, y);
425 // los agrego al hash