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"
15 Principal::Principal(BaseObjectType *co, const Glib::RefPtr<Gnome::Glade::Xml> &rg):Gtk::Window(co),refXml(rg)
17 Gtk::MenuItem *conect=0, *exit=0, *about=0, *mnu_prop=0;
18 Gtk::Button *btn_get=0, *bar_connect=0;
20 txt_target = txt_command = txt_args = 0;
22 lbl_nombre = lbl_color = lbl_flujo = 0;
24 rg->get_widget("lbl_nombre", lbl_nombre);
25 rg->get_widget("mnu_file_connect", conect);
26 rg->get_widget("mnu_file_exit", exit);
27 rg->get_widget("mnu_help_about", about);
28 rg->get_widget("mnu_prop", mnu_prop);
29 rg->get_widget_derived("dlgConectar", dlg_conectar);
30 rg->get_widget("btn_get", btn_get);
31 rg->get_widget("txt_view", txt_view);
32 rg->get_widget("txt_target", txt_target);
33 rg->get_widget("txt_command", txt_command);
34 rg->get_widget("txt_args", txt_args);
35 rg->get_widget("bar_connect", bar_connect);
36 rg->get_widget("work_place", work_place);
37 rg->get_widget("ico_conected", ico_conected);
39 dlg_conectar->get_ok_button()->signal_clicked().connect( SigC::slot(*this, &Principal::on_dlg_connect_ok) );
40 mnu_prop->signal_activate().connect( SigC::slot(*this, &Principal::on_mnu_prop));
41 conect->signal_activate().connect( SigC::slot(*this, &Principal::on_mnu_file_connect));
42 bar_connect->signal_clicked().connect( SigC::slot(*this, &Principal::on_mnu_file_connect));
43 exit->signal_activate().connect( SigC::slot(*this, &Principal::on_mnu_file_exit));
44 about->signal_activate().connect( SigC::slot(*this, &Principal::on_mnu_help_about));
45 btn_get->signal_clicked().connect( SigC::slot(*this, &Principal::on_get_clicked) );
50 Principal::~Principal()
55 void Principal::on_dlg_connect_ok()
57 if (conexion == NULL) {
60 conexion = new PlaQui::Server::ControlClient(dlg_conectar->get_server_name(), dlg_conectar->get_server_port());
63 txt_view->get_buffer()->insert_at_cursor("NO SE PUDO CREAR OBJETO\n");
69 // Conecto las señales
70 conexion->signal_ok_received().connect( SigC::slot(*this, &Principal::on_conexion_ok) );
71 conexion->signal_error_received().connect( SigC::slot(*this, &Principal::on_conexion_error) );
72 conexion->signal_connected().connect( SigC::slot(*this, &Principal::on_conexion_connected) );
73 conexion->signal_finished().connect( SigC::slot(*this, &Principal::on_conexion_finished) );
79 txt_view->get_buffer()->insert_at_cursor("no se puede correr conexion->run()!!!\n");
82 txt_view->get_buffer()->insert_at_cursor("YA ESTAS CONECTADO\n");
87 void Principal::on_mnu_file_exit()
92 void Principal::on_mnu_file_connect()
97 void Principal::on_mnu_help_about()
99 // preparo para leer el archivo ChangeLog
100 /* Glib::RefPtr<Gnome::Glade::Xml> xml;
102 Glib::RefPtr<Gtk::TextBuffer> log_buffer;
103 Glib::RefPtr<Glib::IOChannel> log_io;
105 log_buffer = Gtk::TextBuffer::create();
106 log_io = Glib::IOChannel::create_from_file("../ChangeLog", "r");
107 while (log_io->read_line(line) != Glib::IO_STATUS_EOF) {
108 log_buffer->insert_at_cursor(line);
112 xml = Gnome::Glade::Xml::create("client.glade", "dlgAbout");
114 catch(const Gnome::Glade::XmlError &ex) {
115 std::cerr << ex.what() << std::endl;
118 Gtk::Window *dlg = 0;
119 Gtk::Button *btn_cerrar = 0;
120 Gtk::TextView *txt_changelog = 0;
121 xml->get_widget("dlgAbout", dlg);
122 xml->get_widget("btn_close", btn_cerrar);
123 xml->get_widget("txt_changelog", txt_changelog);
124 btn_cerrar->signal_clicked().connect(SigC::slot(*dlg, &Gtk::Dialog::hide));
125 txt_changelog->set_buffer(log_buffer);
129 bool Principal::on_item_clicked(GdkEventButton *e, ViewItem *i)
131 lbl_nombre->set_text(i->get_name());
132 txt_view->get_buffer()->insert_at_cursor("Selecciono ");
133 txt_view->get_buffer()->insert_at_cursor(i->get_name());
134 txt_view->get_buffer()->insert_at_cursor("\n");
137 void Principal::on_conexion_connected()
139 txt_view->get_buffer()->insert_at_cursor("CONNECTED\n");
140 ico_conected->set( Gtk::Stock::YES , Gtk::IconSize(Gtk::ICON_SIZE_LARGE_TOOLBAR));
143 void Principal::on_conexion_finished()
145 txt_view->get_buffer()->insert_at_cursor("HANG UP\n");
146 ico_conected->set( Gtk::Stock::NO , Gtk::IconSize(Gtk::ICON_SIZE_LARGE_TOOLBAR));
150 void Principal::on_conexion_ok()
152 txt_view->get_buffer()->insert_at_cursor("El server dice que ta' todo ok!\n");
155 void Principal::on_conexion_error(unsigned code)
161 txt_view->get_buffer()->insert_at_cursor("El server dice que hay error : ");
162 txt_view->get_buffer()->insert_at_cursor(s);
163 txt_view->get_buffer()->insert_at_cursor("\n");
167 void Principal::on_get_clicked()
169 if (conexion == NULL) {
170 txt_view->get_buffer()->insert_at_cursor("SIN CONEXION\n");
174 PlaQui::Server::Command command(txt_target->get_text(), txt_command->get_text());
175 command.add_arg( txt_args->get_text() );
176 txt_view->get_buffer()->insert_at_cursor("Enviando comando\n");
178 conexion->send(command);
181 txt_view->get_buffer()->insert_at_cursor("EXCEPTION EN conexion->send !!\n");
186 void Principal::on_mnu_prop()
188 /* Parseo de ejemplo de un XML desde archivo */
190 document = xmlParseFile("test.xml");
191 if (document == NULL) {
195 /* bien, el archivo se parseo bien! */
196 xmlNodePtr nodo, items;
197 nodo = document->children;
199 if (strcmp((char *)nodo->name, "planta") == 0) {
200 items = nodo->children;
201 while (items != NULL) {
202 if (items->type == XML_ELEMENT_NODE) {
203 if (xmlStrcmp(items->name, BAD_CAST"bomba")==0) {
205 } else if (xmlStrcmp(items->name, BAD_CAST"codo")==0) {
207 } else if (xmlStrcmp(items->name, BAD_CAST"tubo")==0) {
209 } else if (xmlStrcmp(items->name, BAD_CAST"exclusa")==0) {
211 } else if (xmlStrcmp(items->name, BAD_CAST"tanque")==0) {
213 } else if (xmlStrcmp(items->name, BAD_CAST"empalme")==0) {
222 void Principal::loadBomba(xmlNodePtr nodo)
224 Glib::ustring name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
225 int orientacion=0, x, y;
227 nodo = nodo->children;
228 while (nodo != NULL) {
229 if (nodo->type == XML_ELEMENT_NODE) {
230 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
231 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
232 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
233 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
234 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
235 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
241 // listo, ya recolecte todos los datos, ahora creo el objeto!
242 ViewPump *b = Gtk::manage( new ViewPump(name, orientacion) );
243 b->signal_button_press_event().connect(SigC::bind( SigC::slot(*this, &Principal::on_item_clicked), b) );
244 b->set_position(x,y);
245 work_place->put(*b, x, y);
247 // los agrego al hash
251 void Principal::loadCodo(xmlNodePtr nodo)
253 std::string name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
254 int orientacion=0, x, y;
256 nodo = nodo->children;
257 while (nodo != NULL) {
258 if (nodo->type == XML_ELEMENT_NODE) {
259 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
260 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
261 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
262 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
263 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
264 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
270 // listo, ya recolecte todos los datos, ahora creo el objeto!
271 ViewItem *b = Gtk::manage( new ViewCodo(name, orientacion) );
272 b->signal_button_press_event().connect(SigC::bind( SigC::slot(*this, &Principal::on_item_clicked), b) );
273 b->set_position(x,y);
274 work_place->put(*b, x, y);
276 // los agrego al hash
280 void Principal::loadConduct(xmlNodePtr nodo)
282 Glib::ustring name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
283 int orientacion=0, x, y;
285 nodo = nodo->children;
286 while (nodo != NULL) {
287 if (nodo->type == XML_ELEMENT_NODE) {
288 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
289 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
290 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
291 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
292 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
293 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
299 // listo, ya recolecte todos los datos, ahora creo el objeto!
300 ViewConduct *b = Gtk::manage( new ViewConduct(name, orientacion) );
301 b->signal_button_press_event().connect(SigC::bind( SigC::slot(*this, &Principal::on_item_clicked), b) );
302 b->set_position(x,y);
303 work_place->put(*b, x, y);
305 // los agrego al hash
309 void Principal::loadExclusa(xmlNodePtr nodo)
311 Glib::ustring name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
312 int orientacion=0, x, y;
314 nodo = nodo->children;
315 while (nodo != NULL) {
316 if (nodo->type == XML_ELEMENT_NODE) {
317 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
318 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
319 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
320 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
321 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
322 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
328 // listo, ya recolecte todos los datos, ahora creo el objeto!
329 ViewExclusa *b = Gtk::manage( new ViewExclusa(name, orientacion) );
330 b->signal_button_press_event().connect(SigC::bind( SigC::slot(*this, &Principal::on_item_clicked), b) );
331 b->set_position(x,y);
332 work_place->put(*b, x, y);
334 // los agrego al hash
338 void Principal::loadTank(xmlNodePtr nodo)
340 Glib::ustring name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
341 int orientacion=0, x, y;
343 nodo = nodo->children;
344 while (nodo != NULL) {
345 if (nodo->type == XML_ELEMENT_NODE) {
346 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
347 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
348 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
349 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
350 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
351 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
357 // listo, ya recolecte todos los datos, ahora creo el objeto!
358 ViewTank *b = Gtk::manage( new ViewTank(name, orientacion) );
359 b->signal_button_press_event().connect(SigC::bind( SigC::slot(*this, &Principal::on_item_clicked), b) );
360 b->set_position(x,y);
361 work_place->put(*b, x, y);
363 // los agrego al hash
367 void Principal::loadUnion(xmlNodePtr nodo)
369 Glib::ustring name = (char *)xmlGetProp(nodo, BAD_CAST"nombre");
370 int orientacion=0, x, y;
372 nodo = nodo->children;
373 while (nodo != NULL) {
374 if (nodo->type == XML_ELEMENT_NODE) {
375 if (xmlStrcmp(nodo->name, BAD_CAST"orientacion") == 0) {
376 orientacion = atoi( (char *)XML_GET_CONTENT(nodo->children) );
377 } else if (xmlStrcmp(nodo->name, BAD_CAST"x") == 0) {
378 x = atoi( (char *)XML_GET_CONTENT(nodo->children) );
379 } else if (xmlStrcmp(nodo->name, BAD_CAST"y") == 0) {
380 y = atoi( (char *)XML_GET_CONTENT(nodo->children) );
386 // listo, ya recolecte todos los datos, ahora creo el objeto!
387 ViewUnion *b = Gtk::manage( new ViewUnion(name, orientacion) );
388 b->signal_button_release_event().connect(SigC::bind( SigC::slot(*this, &Principal::on_item_clicked), b) );
389 b->set_position(x,y);
390 work_place->put(*b, x, y);
392 // los agrego al hash