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");
176 PlaQui::Server::Command command(txt_target->get_text(), txt_command->get_text());
177 command.add_arg( txt_args->get_text() );
178 txt_view->get_buffer()->insert_at_cursor("Enviando comando\n");
180 conexion->send(command);
183 txt_view->get_buffer()->insert_at_cursor("EXCEPTION EN conexion->send !!\n");
188 void Principal::on_mnu_prop()
190 /* Parseo de ejemplo de un XML desde archivo */
192 document = xmlParseFile("test.xml");
193 if (document == NULL) {
197 /* bien, el archivo se parseo bien! */
198 xmlNodePtr nodo, items;
199 nodo = document->children;
201 if (strcmp((char *)nodo->name, "planta") == 0) {
202 items = nodo->children;
203 while (items != NULL) {
204 if (items->type == XML_ELEMENT_NODE) {
205 if (xmlStrcmp(items->name, BAD_CAST"bomba")==0) {
207 } else if (xmlStrcmp(items->name, BAD_CAST"codo")==0) {
209 } else if (xmlStrcmp(items->name, BAD_CAST"tubo")==0) {
211 } else if (xmlStrcmp(items->name, BAD_CAST"exclusa")==0) {
213 } else if (xmlStrcmp(items->name, BAD_CAST"tanque")==0) {
215 } else if (xmlStrcmp(items->name, BAD_CAST"empalme")==0) {
217 } else if (xmlStrcmp(items->name, BAD_CAST"drenaje")==0) {
227 void Principal::loadBomba(xmlNodePtr nodo)
229 Glib::ustring name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
230 int orientacion=0, x, y;
232 nodo = nodo->children;
233 while (nodo != NULL) {
234 if (nodo->type == XML_ELEMENT_NODE) {
235 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
236 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
237 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
238 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
239 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
240 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
246 // listo, ya recolecte todos los datos, ahora creo el objeto!
247 ViewPump *b = Gtk::manage( new ViewPump(name, orientacion) );
248 b->signal_button_press_event().connect(SigC::bind( SigC::slot(*this, &Principal::on_item_clicked), b) );
249 b->set_position(x,y);
250 work_place->put(*b, x, y);
252 // los agrego al hash
256 void Principal::loadCodo(xmlNodePtr nodo)
258 std::string name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
259 int orientacion=0, x, y;
261 nodo = nodo->children;
262 while (nodo != NULL) {
263 if (nodo->type == XML_ELEMENT_NODE) {
264 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
265 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
266 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
267 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
268 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
269 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
275 // listo, ya recolecte todos los datos, ahora creo el objeto!
276 ViewItem *b = Gtk::manage( new ViewCodo(name, orientacion) );
277 b->signal_button_press_event().connect(SigC::bind( SigC::slot(*this, &Principal::on_item_clicked), b) );
278 b->set_position(x,y);
279 work_place->put(*b, x, y);
281 // los agrego al hash
285 void Principal::loadConduct(xmlNodePtr nodo)
287 Glib::ustring name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
288 int orientacion=0, x, y;
290 nodo = nodo->children;
291 while (nodo != NULL) {
292 if (nodo->type == XML_ELEMENT_NODE) {
293 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
294 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
295 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
296 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
297 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
298 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
304 // listo, ya recolecte todos los datos, ahora creo el objeto!
305 ViewConduct *b = Gtk::manage( new ViewConduct(name, orientacion) );
306 b->signal_button_press_event().connect(SigC::bind( SigC::slot(*this, &Principal::on_item_clicked), b) );
307 b->set_position(x,y);
308 work_place->put(*b, x, y);
310 // los agrego al hash
314 void Principal::loadExclusa(xmlNodePtr nodo)
316 Glib::ustring name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
317 int orientacion=0, x, y;
319 nodo = nodo->children;
320 while (nodo != NULL) {
321 if (nodo->type == XML_ELEMENT_NODE) {
322 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
323 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
324 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
325 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
326 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
327 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
333 // listo, ya recolecte todos los datos, ahora creo el objeto!
334 ViewExclusa *b = Gtk::manage( new ViewExclusa(name, orientacion) );
335 b->signal_button_press_event().connect(SigC::bind( SigC::slot(*this, &Principal::on_item_clicked), b) );
336 b->set_position(x,y);
337 work_place->put(*b, x, y);
339 // los agrego al hash
343 void Principal::loadTank(xmlNodePtr nodo)
345 Glib::ustring name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
346 int orientacion=0, x, y;
348 nodo = nodo->children;
349 while (nodo != NULL) {
350 if (nodo->type == XML_ELEMENT_NODE) {
351 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
352 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
353 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
354 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
355 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
356 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
362 // listo, ya recolecte todos los datos, ahora creo el objeto!
363 ViewTank *b = Gtk::manage( new ViewTank(name, orientacion) );
364 b->signal_button_press_event().connect(SigC::bind( SigC::slot(*this, &Principal::on_item_clicked), b) );
365 b->set_position(x,y);
366 work_place->put(*b, x, y);
368 // los agrego al hash
372 void Principal::loadUnion(xmlNodePtr nodo)
374 Glib::ustring name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
375 int orientacion=0, x, y;
377 nodo = nodo->children;
378 while (nodo != NULL) {
379 if (nodo->type == XML_ELEMENT_NODE) {
380 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
381 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
382 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
383 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
384 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
385 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
391 // listo, ya recolecte todos los datos, ahora creo el objeto!
392 ViewUnion *b = Gtk::manage( new ViewUnion(name, orientacion) );
393 b->signal_button_release_event().connect(SigC::bind( SigC::slot(*this, &Principal::on_item_clicked), b) );
394 b->set_position(x,y);
395 work_place->put(*b, x, y);
397 // los agrego al hash
401 void Principal::loadDrain(xmlNodePtr nodo)
403 Glib::ustring name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
404 int orientacion=0, x, y;
406 nodo = nodo->children;
407 while (nodo != NULL) {
408 if (nodo->type == XML_ELEMENT_NODE) {
409 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
410 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
411 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
412 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
413 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
414 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
420 // listo, ya recolecte todos los datos, ahora creo el objeto!
421 ViewDrain *b = Gtk::manage( new ViewDrain(name, orientacion) );
422 b->signal_button_release_event().connect(SigC::bind( SigC::slot(*this, &Principal::on_item_clicked), b) );
423 b->set_position(x,y);
424 work_place->put(*b, x, y);
426 // los agrego al hash