The Inspector (GNU Radio module gr-inspector)
inspector_form.h
Go to the documentation of this file.
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2019 Free Software Foundation, Inc.
4  *
5  * This is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 3, or (at your option)
8  * any later version.
9  *
10  * This software is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this software; see the file COPYING. If not, write to
17  * the Free Software Foundation, Inc., 51 Franklin Street,
18  * Boston, MA 02110-1301, USA.
19  */
20 
21 #ifndef GR_INSPECTOR_INSPECTOR_SINK_H
22 #define GR_INSPECTOR_INSPECTOR_SINK_H
23 
24 #include <gnuradio/thread/thread.h>
25 
26 #include <gnuradio/msg_queue.h>
27 #include <QTimer>
28 #include <QtGui>
29 #include <QtWidgets>
30 
31 #include <qwt_plot.h>
32 #include <qwt_plot_curve.h>
33 #include <qwt_plot_grid.h>
34 #include <qwt_plot_layout.h>
35 #include <qwt_plot_zoomer.h>
36 #include <qwt_symbol.h>
37 
38 #include "signal_marker.h"
39 
40 namespace gr {
41 namespace inspector {
42 
43 class Zoomer : public QwtPlotZoomer
44 {
45 public:
46  Zoomer(int xAxis, int yAxis, QWidget* canvas) : QwtPlotZoomer(xAxis, yAxis, canvas)
47  {
48  // setSelectionFlags(QwtPicker::DragSelection | QwtPicker::CornerToCorner);
49  setTrackerMode(QwtPicker::AlwaysOn);
50  setRubberBand(QwtPicker::RectRubberBand);
51  QPen pen =
52  QPen(QColor(100, 100, 100), 1, Qt::DashLine, Qt::RoundCap, Qt::RoundJoin);
53  setTrackerPen(pen);
54  setRubberBandPen(pen);
55 
56  // RightButton: zoom out by 1
57  // Ctrl+RightButton: zoom out to full size
58 
59 #if QT_VERSION < 0x040000
60  setMousePattern(
61  QwtEventPattern::MouseSelect2, Qt::RightButton, Qt::ControlButton);
62 #else
63  setMousePattern(
64  QwtEventPattern::MouseSelect2, Qt::RightButton, Qt::ControlModifier);
65 #endif
66  setMousePattern(QwtEventPattern::MouseSelect3, Qt::RightButton);
67  setMousePattern(
68  QwtEventPattern::MouseSelect1, Qt::LeftButton, Qt::ControlModifier);
69  }
70 };
71 
72 class inspector_form : public QWidget
73 {
74  Q_OBJECT
75 
76 public:
77  void set_axis_x(float start, float stop);
78  void msg_received();
79  void set_cfreq(float freq);
80  void detach_markers();
81  void mousePressEvent(QMouseEvent* eventPress);
82  void mouseReleaseEvent(QMouseEvent* eventRelease);
83  void mouseMoveEvent(QMouseEvent* eventMove);
84  void spawn_signal_selector();
85  void add_msg_queue(float cfreq, float bandwidth);
86  float freq_to_x(float freq);
87  float x_to_freq(float x);
88  void add_analysis_text(int signal, std::string text);
89 
90  void drawOverlay();
91  void draw_analysis_text();
92  inspector_form(int fft_len,
93  std::vector<double>* buffer,
94  std::vector<std::vector<float>>* rf_map,
95  bool* manual,
96  gr::msg_queue* msg_queue,
97  int* rf_unit,
98  QWidget* parent);
99  ~inspector_form();
100 
101 private:
102  enum markerType { NONE, LEFT, CENTER, RIGHT };
103 
104  bool change_flag;
105  int d_interval, d_fft_len, d_marker_count;
106  int* d_rf_unit;
107  bool* d_manual;
108  std::vector<float> d_axis_x, d_axis_y;
109  std::vector<double>* d_buffer;
110  float d_max, d_min, d_cfreq, d_mouse_offset;
111  double* d_freq;
112  std::map<int, std::string> d_analysis_texts;
113  std::vector<std::vector<float>>* d_rf_map;
114  markerType d_clicked_marker;
115  QList<signal_marker*> d_markers;
116  QwtSymbol* d_symbol;
117  Zoomer* d_zoomer;
118  QwtPlot* d_plot;
119  QwtScaleWidget* d_scale;
120  QwtPlotCurve* d_curve;
121  QTimer* d_timer;
122  QwtPlotGrid* d_grid;
123  QGridLayout* d_layout;
124 
125  QCheckBox* d_manual_cb;
126  gr::msg_queue* d_msg_queue;
127 
128  gr::thread::mutex d_mutex;
129 
130 protected:
131  void resizeEvent(QResizeEvent* event);
132 
133 public slots:
134  void refresh();
135  void manual_cb_clicked(int state);
136 };
137 
138 
139 } // namespace inspector
140 } // namespace gr
141 
142 #endif // GR_INSPECTOR_INSPECTOR_SINK_H
Definition: inspector_form.h:72
Definition: inspector_form.h:43
Definition: inspector_form.h:40
Zoomer(int xAxis, int yAxis, QWidget *canvas)
Definition: inspector_form.h:46