window2.cc
Go to the documentation of this file.
00001 /*------------------------------------------------------------------------
00002  *---------------------           WMPSNIFFER          --------------------
00003  *------------------------------------------------------------------------
00004  *                                                         V7.0B  11/05/10
00005  *
00006  *
00007  *  File: window2.cc
00008  *  Authors: Danilo Tardioli
00009  *  ----------------------------------------------------------------------
00010  *  Copyright (C) 2000-2012, Universidad de Zaragoza, SPAIN
00011  *
00012  *  Contact Addresses: Danilo Tardioli                   dantard@unizar.es
00013  *
00014  *  RT-WMP is free software; you can  redistribute it and/or  modify it
00015  *  under the terms of the GNU General Public License  as published by the
00016  *  Free Software Foundation;  either  version 2, or (at  your option) any
00017  *  later version.
00018  *
00019  *  RT-WMP  is distributed  in the  hope  that  it will be   useful, but
00020  *  WITHOUT  ANY  WARRANTY;     without  even the   implied   warranty  of
00021  *  MERCHANTABILITY  or  FITNESS FOR A  PARTICULAR PURPOSE.    See the GNU
00022  *  General Public License for more details.
00023  *
00024  *  You should have received  a  copy of  the  GNU General Public  License
00025  *  distributed with RT-WMP;  see file COPYING.   If not,  write to the
00026  *  Free Software  Foundation,  59 Temple Place  -  Suite 330,  Boston, MA
00027  *  02111-1307, USA.
00028  *
00029  *  As a  special exception, if you  link this  unit  with other  files to
00030  *  produce an   executable,   this unit  does  not  by  itself cause  the
00031  *  resulting executable to be covered by the  GNU General Public License.
00032  *  This exception does  not however invalidate  any other reasons why the
00033  *  executable file might be covered by the GNU Public License.
00034  *
00035  *----------------------------------------------------------------------*/
00036 
00037 #include "config.h"
00038 #include "window2.hh"
00039 #include "window2.hh"
00040 #include "wmp_config.h"
00041 
00042 #include "core/include/frames.h"
00043 #include "core/interface/Msg.h"
00044 #include "math.h"
00045 #include "wmp_specific.hh"
00046 #include "bridge.hh"
00047 #include "main_window.hh"
00048 #include <sstream>
00049 #include <gtkmm/dialog.h>
00050 #include <gtkmm/stock.h>
00051 #include <gtkmm/filechooserdialog.h>
00052 #include "statistics.h"
00053 
00054 void window2::on_button10_clicked() {
00055         Glib::RefPtr<Gtk::Clipboard> refClipboard = Gtk::Clipboard::get();
00056         refClipboard->set_text(oss.str().c_str());
00057         std::ostringstream fn;
00058         Gtk::FileChooserDialog dialog("Please choose a Filename",
00059                         Gtk::FILE_CHOOSER_ACTION_SAVE);
00060         dialog.set_transient_for(*this);
00061         dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
00062         dialog.add_button(Gtk::Stock::OK, Gtk::RESPONSE_OK);
00063         Gtk::FileFilter filter_vis;
00064         filter_vis.set_name("log files (*.wlg)");
00065         filter_vis.add_pattern("*.wlg");
00066         dialog.add_filter(filter_vis);
00067         int result = dialog.run();
00068         if (result == Gtk::RESPONSE_CANCEL)
00069                 return;
00070         FILE * f = fopen(dialog.get_filename().c_str(), "w+");
00071         //fprintf(f,"%s", oss.str().c_str());
00072         fclose(f);
00073 }
00074 
00075 void window2::on_button11_clicked() {
00076         show_statistics_from_values();
00077 }
00078 
00079 void window2::on_button12_clicked() {
00080         range_setted = 0;
00081         hide();
00082 }
00083 #include "icon.h"
00084 window2::window2(main_window* mw) :
00085         window2_glade() {
00086         set_icon(Gdk::Pixbuf::create_from_xpm_data(icon));
00087         this->mw = mw;
00088         button10->hide();
00089         set_size_request(600, 600);
00090         treeview2->signal_cursor_changed().connect(sigc::mem_fun(*this,
00091                         &window2::on_cursor_changed));
00092         m_refTreeModel = Gtk::TreeStore::create(m_Columns);
00093         treeview2->set_model(m_refTreeModel);
00094         treeview2->append_column("Message                       ",
00095                         m_Columns.m_col_name);
00096         treeview2->append_column("Value", m_Columns.m_col_value);
00097         set_keep_above(true);
00098         range_setted = 0;
00099 
00100         Gtk::Menu::MenuList& menulist = m_Menu_Popup.items();
00101         menulist.push_back(Gtk::Menu_Helpers::MenuElem("_Write to file", sigc::mem_fun(
00102                         *this, &window2::write_to_file)));
00103         menulist.push_back(Gtk::Menu_Helpers::MenuElem("_Time Graph", sigc::mem_fun(
00104                         *this, &window2::time_graph)));
00105         menulist.push_back(Gtk::Menu_Helpers::MenuElem("_Distribution Graph (Auto)", sigc::mem_fun(
00106                         *this, &window2::dist_graph)));
00107         menulist.push_back(Gtk::Menu_Helpers::MenuElem("_Distribution Graph (1000 bin)", sigc::mem_fun(
00108                         *this, &window2::dist_graph_1000)));
00109         menulist.push_back(Gtk::Menu_Helpers::MenuElem("_Distribution Graph (100 bin)", sigc::mem_fun(
00110                         *this, &window2::dist_graph_100)));
00111         menulist.push_back(Gtk::Menu_Helpers::MenuElem("_Distribution Graph (10 bin)", sigc::mem_fun(
00112                                 *this, &window2::dist_graph_10)));
00113         menulist.push_back(Gtk::Menu_Helpers::MenuElem("_Distribution Graph (50% Auto)", sigc::mem_fun(
00114                                 *this, &window2::dist_graph_a5)));
00115         menulist.push_back(Gtk::Menu_Helpers::MenuElem("_Distribution Graph (50% 100 bin)", sigc::mem_fun(
00116                                 *this, &window2::dist_graph_100_5)));
00117 
00118 
00119         m_Menu_Popup.accelerate(*this);
00120 
00121 }
00122 void window2::write_to_file(){
00123         stat_write_to_file(rowSelected);
00124 }
00125 void window2::time_graph(){
00126         stat_plot_tg(rowSelected);
00127 }
00128 void window2::dist_graph(){
00129         stat_plot_hist(rowSelected,0,1);
00130 }
00131 void window2::dist_graph_1000(){
00132         stat_plot_hist(rowSelected,1000,1);
00133 }
00134 void window2::dist_graph_100(){
00135         stat_plot_hist(rowSelected,100,1);
00136 }
00137 void window2::dist_graph_10(){
00138         stat_plot_hist(rowSelected,10,1);
00139 }
00140 void window2::dist_graph_a5(){
00141         stat_plot_hist(rowSelected,0,0.5);
00142 }
00143 void window2::dist_graph_100_5(){
00144         stat_plot_hist(rowSelected,100,0.5);
00145 }
00146 
00147 void window2::row_append(int id, const char* txt, int value,const char* uni){
00148         long long llvalue=value;
00149         row_append(id,txt, llvalue, uni);
00150 }
00151 
00152 void window2::row_append(int id, const char* txt, long long value, const char*uni) {
00153         char v[64];
00154         sprintf(v, "%lld %s", value, uni);
00155         row = *(m_refTreeModel->append());
00156         row[m_Columns.m_col_id] = id;
00157         row[m_Columns.m_col_name] = txt;
00158         row[m_Columns.m_col_value] = v;
00159         oss << "\n" << txt << " " << v << "\n";
00160 }
00161 
00162 void window2::row_append(int id, const char* txt, const char*uni) {
00163         char v[64];
00164         sprintf(v, "%s", uni);
00165         row = *(m_refTreeModel->append());
00166         row[m_Columns.m_col_id] = id;
00167         row[m_Columns.m_col_name] = txt;
00168         row[m_Columns.m_col_value] = v;
00169         oss << "\n" << txt << " " << v << "\n";
00170 }
00171 
00172 /* button efz*/
00173 void window2::on_button22_clicked() {
00174         int nnodes = 1;
00175         fprintf(stderr,"bgn:%d end:%d\n", 22, 22);
00176 
00177         //io_open_sim_data(this->filename);
00178         if (nnodes > 0) {
00179                 int n = (int) to_sb->get_value();
00180                 int from = (int) from_sb->get_value();
00181 
00182 
00183                 io_go_to(from);
00184                 io_create_tmp_file();
00185                 char data[2500];
00186                 for (int i = from; i < n; i++) {
00187                         int bytes = io_read_next_sim_data(&data[0]);
00188                         if (bytes <= 0 || !io_write_on_tmp_file(data,bytes)){
00189                                 fprintf(stderr, "File End...\n");
00190                                 break;
00191                         }
00192                 }
00193                 io_close_tmp_file();
00194         }
00195         char cmd[256];
00196         sprintf(cmd, "cp tmp.vis %s", this->filename);
00197 
00198         if (system(cmd) == -1){
00199                 fprintf(stderr, "*** WARNING: Unable to execute 'cp tmp.vis %s'\n", this->filename);
00200         }
00201         mw->reset();
00202         range_setted = 0;
00203         this->show_statistics(0);
00204 }
00205 
00206 void window2::row_child_append(int id, const char* txt, int value,const char* uni){
00207         long long llvalue=value;
00208         row_child_append(id, txt, llvalue, uni);
00209 }
00210 void window2::row_child_append(int type, int id, const char* txt, int value, const char*uni){
00211         long long llvalue=value;
00212         row_child_append(type,id,txt,llvalue,uni);
00213 }
00214 
00215 void window2::row_child_append(int id, const char* txt, long long value, const char*uni) {
00216         row_child_append(NONE, id, txt, value, uni);
00217 }
00218 
00219 void window2::row_child_child_append(int id, const char* txt, long long value, const char*uni) {
00220         char v[64];
00221         sprintf(v, "%lld %s", value, uni);
00222         Gtk::TreeModel::iterator iter_child = m_refTreeModel->append(
00223                         subrow.children());
00224         (*iter_child)[m_Columns.m_col_id] = id;
00225         (*iter_child)[m_Columns.m_col_type] = NONE;
00226         (*iter_child)[m_Columns.m_col_name] = txt;
00227         (*iter_child)[m_Columns.m_col_value] = v;
00228 }
00229 
00230 void window2::row_child_append(int type, int id, const char* txt, long long value, const char*uni) {
00231         char v[64];
00232         if (uni != NULL) {
00233                 sprintf(v, "%lld %s", value, uni);
00234         }else{
00235                 sprintf(v, "%lld", value);
00236         }
00237         Gtk::TreeModel::iterator iter_child =
00238                         m_refTreeModel->append(row.children());
00239         subrow = (*iter_child);
00240         (*iter_child)[m_Columns.m_col_id] = id;
00241         (*iter_child)[m_Columns.m_col_type] = type;
00242         (*iter_child)[m_Columns.m_col_name] = txt;
00243         (*iter_child)[m_Columns.m_col_value] = v;
00244         if (uni != NULL) {
00245                 oss << txt << " " << v << "\n";
00246         }
00247 }
00248 
00249 void window2::row_append(int id, const char* txt, float value, const char*uni) {
00250         char v[64];
00251         sprintf(v, "%5.3f %s", value, uni);
00252         row = *(m_refTreeModel->append());
00253         row[m_Columns.m_col_id] = id;
00254         row[m_Columns.m_col_name] = txt;
00255         row[m_Columns.m_col_value] = v;
00256         oss << "\n" << txt << " " << v << "\n---------------\n";
00257 }
00258 
00260 
00261 
00262 void window2::row_child_append(int id, const char* txt, float value, const char*uni) {
00263         char v[64];
00264         sprintf(v, "%5.3f %s", value, uni);
00265         Gtk::TreeModel::iterator iter_child =
00266                         m_refTreeModel->append(row.children());
00267         subrow = *iter_child;
00268         (*iter_child)[m_Columns.m_col_id] = id;
00269         (*iter_child)[m_Columns.m_col_name] = txt;
00270         (*iter_child)[m_Columns.m_col_value] = v;
00271         oss << txt << " " << v << "\n";
00272 }
00273 
00274 void window2::show_statistics(char * filename) {
00275         statistics_init();
00276         m_refTreeModel->clear();
00277         int bgn = -1, end = -1;
00278         if (filename != NULL){
00279                 strcpy(this->filename, filename);
00280         }
00281         statistics_from_file(this->filename, bgn, end);
00282         statistics_publish(this);
00283         from_sb->set_value(bgn);
00284         to_sb->set_value(end);
00285 }
00286 
00287 void window2::show_statistics_from_values() {
00288         statistics_init();
00289         m_refTreeModel->clear();
00290         int bgn = from_sb->get_value();
00291         int end = to_sb->get_value();
00292         statistics_from_file(this->filename, bgn, end);
00293         statistics_publish(this);
00294 }
00295 char *  window2::getFileName(){
00296         return filename;
00297 }
00298 void window2::on_cursor_changed() {
00299 
00300         Glib::RefPtr<Gtk::TreeSelection> refTreeSelection =
00301                         treeview2->get_selection();
00302         Gtk::TreeModel::iterator iter = refTreeSelection->get_selected();
00303 
00304         if (iter) {
00305                 Gtk::TreeModel::Row row = *iter;
00306                 selected = row[m_Columns.m_col_id];
00307 //              fprintf(stderr, "Selected:%d\n", selected);
00308                 if (row[m_Columns.m_col_type] == MIN_V) {
00309                         from_sb->set_value(selected);
00310                 }
00311                 if (row[m_Columns.m_col_type] == MAX_V) {
00312                         to_sb->set_value(selected);
00313                 }
00314                 if (selected >= 0)
00315                         mw->notify_selection(selected);
00316 
00317                 std::string exp_name((Glib::ustring(row[m_Columns.m_col_name])).c_str());
00318                 rowSelected=row[m_Columns.m_col_uid];
00319         }
00320 
00321 
00322 
00323         //Glib::RefPtr<Gtk::Clipboard> refClipboard = Gtk::Clipboard::get();
00324         //refClipboard->set_text("hola");
00325 
00326         /*FILE *  a = popen("gnuplot","w");
00327         fprintf(a,"plot 'dat.dat'\n");
00328         fflush(a);
00329 */
00330 }
00331 
00332 
00333 
00334 
00335 bool window2::on_treeview2_button_press_event(GdkEventButton *ev) {
00336         if ((ev->type == GDK_BUTTON_PRESS) && (ev->button == 3)) {
00337                 if (stat_ask_plotter(rowSelected)){
00338                         m_Menu_Popup.popup(ev->button, ev->time);
00339                 }
00340         }
00341 
00342         return false;
00343 }
00344 
00345 void window2::on_button21_clicked() {
00346         int a,b;
00347         statistics_get_fez(a, b);
00348         from_sb->set_value(a);
00349         to_sb->set_value(b);
00350         show_statistics_from_values();
00351 }
00352 
00353 void window2::on_button20_clicked() {
00354         show_statistics();
00355 }
00356 
00357 
00359 
00360 void window2::root() {
00361         level = 0;
00362         xrow_name.clear();
00363 }
00364 
00365 void window2::subSectionBegin() {
00366         level ++;
00367 }
00368 
00369 void window2::subSectionEnd() {
00370         level --;
00371         xrow_name.erase(xrow_name.end());
00372 }
00373 
00374 void window2::row_create(std::string txt1, std::string txt2, int pos, int uid) {
00375         if (level == 0){
00376                 xrow = row_level[0] = *(m_refTreeModel->append());
00377         }else{
00378                 xrow = row_level[level] = *(m_refTreeModel->append(row_level[level-1].children()));
00379         }
00380         xrow[m_Columns.m_col_id] = pos;
00381         xrow[m_Columns.m_col_uid] = uid;
00382         xrow[m_Columns.m_col_name] = txt1;
00383         xrow[m_Columns.m_col_value] = txt2;
00384         xrow_name.resize(level+1);
00385         xrow_name.at(level) = txt1;
00386 }
00387 
00388 std::string window2::getCurrentRowName(){
00389         std::string s = "";
00390         for (int i= 0 ; i< level;i++){
00391                 if (i!=0){
00392                         s+= "::";
00393                 }
00394                 s+= xrow_name.at(i);
00395         }
00396 
00397         return s;
00398 }
00399 


ros_rt_wmp_sniffer
Author(s): Danilo Tardioli, dantard@unizar.es
autogenerated on Mon Oct 6 2014 08:27:57