OpenHantek
glscope.h
Go to the documentation of this file.
1 // SPDX-License-Identifier: GPL-2.0+
2 
3 #pragma once
4 
5 #include <memory>
6 #include <list>
7 
8 #include <QtGlobal>
9 #include <QOpenGLBuffer>
10 #include <QOpenGLFunctions>
11 #include <QOpenGLShaderProgram>
12 #include <QOpenGLVertexArrayObject>
13 #include <QOpenGLWidget>
14 
15 #include "glscopegraph.h"
16 #include "hantekdso/enums.h"
17 #include "hantekprotocol/types.h"
18 
19 struct DsoSettingsView;
20 struct DsoSettingsScope;
22 class PPresult;
23 
25 class GlScope : public QOpenGLWidget {
26  Q_OBJECT
27 
28  public:
30  QWidget *parent = nullptr);
32  QWidget *parent = nullptr);
33 
38  static void fixOpenGLversion(QSurfaceFormat::RenderableType t=QSurfaceFormat::DefaultRenderableType);
43  void showData(std::shared_ptr<PPresult> newData);
44  void updateCursor(unsigned index = 0);
45  void cursorSelected(unsigned index) { selectedCursor = index; updateCursor(index); }
46 
47  protected:
51  GlScope(DsoSettingsScope *scope, DsoSettingsView *view, QWidget *parent = nullptr);
52  ~GlScope() override;
53  GlScope(const GlScope&) = delete;
54 
56  void initializeGL() override;
57 
59  void paintGL() override;
60 
64  void resizeGL(int width, int height) override;
65 
66  void mousePressEvent(QMouseEvent *event) override;
67  void mouseMoveEvent(QMouseEvent *event) override;
68  void mouseReleaseEvent(QMouseEvent *event) override;
69  void paintEvent(QPaintEvent *event) override;
70 
72  void drawGrid();
74  void drawMarkers();
75  void generateVertices(unsigned marker, const DsoSettingsScopeCursor &cursor);
76  void drawVertices(QOpenGLFunctions *gl, unsigned marker, QColor color);
77 
78  void drawVoltageChannelGraph(ChannelID channel, Graph &graph, int historyIndex);
79  void drawHistogramChannelGraph(ChannelID channel, Graph &graph, int historyIndex);
80  void drawSpectrumChannelGraph(ChannelID channel, Graph &graph, int historyIndex);
81  QPointF eventToPosition(QMouseEvent *event);
82  signals:
83  void markerMoved(unsigned cursorIndex, unsigned marker);
84 
85  private:
86  // User settings
89  bool zoomed = false;
90 
91  // Marker
92  const unsigned NO_MARKER = UINT_MAX;
93  #pragma pack(push, 1)
94  struct Vertices {
95  QVector3D a, b, c, d;
96  };
97  #pragma pack(pop)
98  const unsigned VERTICES_ARRAY_SIZE = sizeof(Vertices) / sizeof(QVector3D);
99  std::vector<Vertices> vaMarker;
101  QOpenGLBuffer m_marker;
102  QOpenGLVertexArrayObject m_vaoMarker;
103 
104  // Cursors
105  std::vector<DsoSettingsScopeCursor *> cursorInfo;
106  unsigned selectedCursor = 0;
107 
108  // Grid
109  QOpenGLBuffer m_grid;
110  QOpenGLVertexArrayObject m_vaoGrid[3];
111  GLsizei gridDrawCounts[3];
112  void generateGrid(QOpenGLShaderProgram *program);
113  void draw4Cross( std::vector<QVector3D> &va, int section, float x, float y );
114 
115 
116  // Graphs
117  std::list<Graph> m_GraphHistory;
118  unsigned currentGraphInHistory = 0;
119 
120  // OpenGL shader, matrix, var-locations
121  unsigned int GLSLversion = 150;
122  bool shaderCompileSuccess = false;
123  QString errorMessage;
124  std::unique_ptr<QOpenGLShaderProgram> m_program;
125  QMatrix4x4 pmvMatrix;
130 };
std::list< Graph > m_GraphHistory
Definition: glscope.h:117
void generateGrid(QOpenGLShaderProgram *program)
Definition: glscope.cpp:470
unsigned selectedMarker
Definition: glscope.h:100
unsigned int GLSLversion
Definition: glscope.h:121
void drawSpectrumChannelGraph(ChannelID channel, Graph &graph, int historyIndex)
Definition: glscope.cpp:664
std::vector< DsoSettingsScopeCursor * > cursorInfo
Definition: glscope.h:105
void updateCursor(unsigned index=0)
Definition: glscope.cpp:382
int colorLocation
Definition: glscope.h:126
static void fixOpenGLversion(QSurfaceFormat::RenderableType t=QSurfaceFormat::DefaultRenderableType)
Definition: glscope.cpp:38
void mouseReleaseEvent(QMouseEvent *event) override
Definition: glscope.cpp:167
DsoSettingsScope * scope
Definition: glscope.h:87
std::unique_ptr< QOpenGLShaderProgram > m_program
Definition: glscope.h:124
bool zoomed
Definition: glscope.h:89
std::vector< Vertices > vaMarker
Definition: glscope.h:99
void resizeGL(int width, int height) override
Resize the widget.
Definition: glscope.cpp:436
int vertexLocation
Definition: glscope.h:127
DsoSettingsView * view
Definition: glscope.h:88
QVector3D a
Definition: glscope.h:95
int selectionLocation
Definition: glscope.h:129
void markerMoved(unsigned cursorIndex, unsigned marker)
Definition: glscope.h:94
QOpenGLBuffer m_marker
Definition: glscope.h:101
QVector3D b
Definition: glscope.h:95
void draw4Cross(std::vector< QVector3D > &va, int section, float x, float y)
Definition: glscope.cpp:457
~GlScope() override
Definition: glscope.cpp:86
void drawHistogramChannelGraph(ChannelID channel, Graph &graph, int historyIndex)
Definition: glscope.cpp:653
void generateVertices(unsigned marker, const DsoSettingsScopeCursor &cursor)
Definition: glscope.cpp:333
void drawMarkers()
Draw vertical lines at marker positions.
Definition: glscope.cpp:615
QMatrix4x4 pmvMatrix
projection, view matrix
Definition: glscope.h:125
bool shaderCompileSuccess
Definition: glscope.h:122
void initializeGL() override
Initializes OpenGL output.
Definition: glscope.cpp:193
QVector3D d
Definition: glscope.h:95
const unsigned NO_MARKER
Definition: glscope.h:92
QOpenGLBuffer m_grid
Definition: glscope.h:109
QOpenGLVertexArrayObject m_vaoMarker
Definition: glscope.h:102
void mouseMoveEvent(QMouseEvent *event) override
Definition: glscope.cpp:148
QVector3D c
Definition: glscope.h:95
void drawVoltageChannelGraph(ChannelID channel, Graph &graph, int historyIndex)
Definition: glscope.cpp:642
const unsigned VERTICES_ARRAY_SIZE
Definition: glscope.h:98
Holds the cursor parameters.
Definition: scopesettings.h:16
QPointF eventToPosition(QMouseEvent *event)
Definition: glscope.cpp:88
unsigned currentGraphInHistory
Definition: glscope.h:118
OpenGL accelerated widget that displays the oscilloscope screen.
Definition: glscope.h:25
void drawVertices(QOpenGLFunctions *gl, unsigned marker, QColor color)
Definition: glscope.cpp:605
Definition: glscopegraph.h:16
void drawGrid()
Draw the grid.
Definition: glscope.cpp:582
Holds all view settings.
Definition: viewsettings.h:30
static GlScope * createNormal(DsoSettingsScope *scope, DsoSettingsView *view, QWidget *parent=nullptr)
Definition: glscope.cpp:26
void showData(std::shared_ptr< PPresult > newData)
Definition: glscope.cpp:314
unsigned ChannelID
Definition: types.h:6
int matrixLocation
Definition: glscope.h:128
QString errorMessage
Definition: glscope.h:123
Holds the settings for the oscilloscope.
Definition: scopesettings.h:75
void paintGL() override
Draw the graphs, marker and the grid.
Definition: glscope.cpp:394
GlScope(DsoSettingsScope *scope, DsoSettingsView *view, QWidget *parent=nullptr)
Initializes the scope widget.
Definition: glscope.cpp:57
QOpenGLVertexArrayObject m_vaoGrid[3]
Definition: glscope.h:110
unsigned selectedCursor
Definition: glscope.h:106
static GlScope * createZoomed(DsoSettingsScope *scope, DsoSettingsView *view, QWidget *parent=nullptr)
Definition: glscope.cpp:32
void paintEvent(QPaintEvent *event) override
Definition: glscope.cpp:179
GLsizei gridDrawCounts[3]
Definition: glscope.h:111
void cursorSelected(unsigned index)
Definition: glscope.h:45
Post processing results.
Definition: ppresult.h:36
void mousePressEvent(QMouseEvent *event) override
Definition: glscope.cpp:100