OpenHantek
glscope.h
Go to the documentation of this file.
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 
3 #pragma once
4 
5 #include <list>
6 #include <memory>
7 
8 #include <QOpenGLBuffer>
9 #include <QOpenGLFunctions>
10 #include <QOpenGLShaderProgram>
11 #include <QOpenGLVertexArrayObject>
12 #include <QOpenGLWidget>
13 #include <QtGlobal>
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 
24 #define GLES100 "1.00 ES"
25 #define GLSL120 "1.20"
26 #define GLSL150 "1.50"
27 
29 class GlScope : public QOpenGLWidget {
30  Q_OBJECT
31 
32  public:
33  static GlScope *createNormal( DsoSettingsScope *scope, DsoSettingsView *view, QWidget *parent = nullptr );
34  static GlScope *createZoomed( DsoSettingsScope *scope, DsoSettingsView *view, QWidget *parent = nullptr );
35 
36  static void useOpenGLSLversion( QString version = GLSL120 );
37  static QString getOpenGLversion();
38  static QString getGLSLversion() { return GLSLversion; }
43  void showData( std::shared_ptr< PPresult > newData );
44  void selectCursor( int index );
45  void updateCursor( int index = 0 );
46  void generateGrid( int index = -1, double value = 0.0, bool pressed = false );
47  void setVisible( bool visible ) override;
48 
49  protected:
53  GlScope( DsoSettingsScope *scope, DsoSettingsView *view, QWidget *parent = nullptr );
54  ~GlScope() override;
55  GlScope( const GlScope & ) = delete;
56 
58  void initializeGL() override;
59 
61  void paintGL() override;
62 
66  void resizeGL( int width, int height ) override;
67 
68  void mousePressEvent( QMouseEvent *event ) override;
69  void mouseMoveEvent( QMouseEvent *event ) override;
70  void mouseReleaseEvent( QMouseEvent *event ) override;
71  void mouseDoubleClickEvent( QMouseEvent *event ) override;
72  void wheelEvent( QWheelEvent *event ) override;
73  void paintEvent( QPaintEvent *event ) override;
74 
76  void drawGrid();
78  void drawMarkers();
79  void generateVertices( int marker, const DsoSettingsScopeCursor &cursor );
80  void drawVertices( QOpenGLFunctions *gl, int marker, QColor color );
81 
82  void drawVoltageChannelGraph( ChannelID channel, Graph &graph, int historyIndex );
83  void drawHistogramChannelGraph( ChannelID channel, Graph &graph, int historyIndex );
84  void drawSpectrumChannelGraph( ChannelID channel, Graph &graph, int historyIndex );
85  QPointF posToScopePos( QPointF pos );
86  void rightMouseEvent( QMouseEvent *event );
87 
88  signals:
89  void markerMoved( int cursorIndex, int marker );
90  void cursorMeasurement( QPointF measurePosition = QPointF(), QPoint globalPosition = QPoint(), bool status = false );
91 
92  private:
93  // User settings
96  bool zoomed = false;
97 
98  // Marker
99  const int NO_MARKER = INT_MAX;
100 #pragma pack( push, 1 )
101  struct Vertices {
102  QVector3D a, b, c, d;
103  };
104 #pragma pack( pop )
105  const int VERTICES_ARRAY_SIZE = sizeof( Vertices ) / sizeof( QVector3D );
106  std::vector< Vertices > vaMarker;
108  QOpenGLBuffer m_marker;
109  QOpenGLVertexArrayObject m_vaoMarker;
110 
111  // Cursors
112  std::vector< DsoSettingsScopeCursor * > cursorInfo;
113  int selectedCursor = 0;
114  bool rightMouseInside = false;
115 
116  // Grid
117  QOpenGLBuffer m_grid;
118  static const int gridItems = 4;
119  QOpenGLVertexArrayObject m_vaoGrid[ gridItems ];
121  void draw4Cross( std::vector< QVector3D > &va, int section, float x, float y );
122  QColor triggerLineColor = QColor( "black" );
123 
124  // Graphs
125  std::list< Graph > m_GraphHistory;
126  unsigned currentGraphInHistory = 0;
127 
128  // OpenGL shader, matrix, var-locations
129  static QString OpenGLversion;
130  static QString GLSLversion;
131  QString renderInfo;
132  bool shaderCompileSuccess = false;
133  QString errorMessage;
134  std::unique_ptr< QOpenGLShaderProgram > m_program;
135  QMatrix4x4 pmvMatrix;
140 };
const int VERTICES_ARRAY_SIZE
Definition: glscope.h:105
void selectCursor(int index)
Definition: glscope.cpp:549
int selectedCursor
Definition: glscope.h:113
int selectedMarker
Definition: glscope.h:107
QOpenGLVertexArrayObject m_vaoGrid[gridItems]
Definition: glscope.h:119
void drawSpectrumChannelGraph(ChannelID channel, Graph &graph, int historyIndex)
Definition: glscope.cpp:907
int colorLocation
Definition: glscope.h:136
void mouseReleaseEvent(QMouseEvent *event) override
Definition: glscope.cpp:226
DsoSettingsScope * scope
Definition: glscope.h:94
std::vector< DsoSettingsScopeCursor *> cursorInfo
Definition: glscope.h:112
std::unique_ptr< QOpenGLShaderProgram > m_program
Definition: glscope.h:134
bool zoomed
Definition: glscope.h:96
const int NO_MARKER
Definition: glscope.h:99
void setVisible(bool visible) override
Definition: glscope.cpp:105
void resizeGL(int width, int height) override
Resize the widget.
Definition: glscope.cpp:618
int vertexLocation
Definition: glscope.h:137
void wheelEvent(QWheelEvent *event) override
Definition: glscope.cpp:280
DsoSettingsView * view
Definition: glscope.h:95
static QString getGLSLversion()
Definition: glscope.h:38
QVector3D a
Definition: glscope.h:102
int selectionLocation
Definition: glscope.h:139
Definition: glscope.h:101
std::vector< Vertices > vaMarker
Definition: glscope.h:106
void generateVertices(int marker, const DsoSettingsScopeCursor &cursor)
Definition: glscope.cpp:512
QOpenGLBuffer m_marker
Definition: glscope.h:108
QVector3D b
Definition: glscope.h:102
void draw4Cross(std::vector< QVector3D > &va, int section, float x, float y)
Definition: glscope.cpp:642
~GlScope() override
Definition: glscope.cpp:83
QString renderInfo
Definition: glscope.h:131
void drawHistogramChannelGraph(ChannelID channel, Graph &graph, int historyIndex)
Definition: glscope.cpp:894
void drawMarkers()
Draw vertical lines at marker positions.
Definition: glscope.cpp:853
QMatrix4x4 pmvMatrix
projection, view matrix
Definition: glscope.h:135
bool shaderCompileSuccess
Definition: glscope.h:132
void initializeGL() override
Initializes OpenGL output.
Definition: glscope.cpp:341
QVector3D d
Definition: glscope.h:102
QOpenGLBuffer m_grid
Definition: glscope.h:117
QOpenGLVertexArrayObject m_vaoMarker
Definition: glscope.h:109
void updateCursor(int index=0)
Definition: glscope.cpp:555
QColor triggerLineColor
Definition: glscope.h:122
void mouseMoveEvent(QMouseEvent *event) override
Definition: glscope.cpp:202
QVector3D c
Definition: glscope.h:102
void drawVoltageChannelGraph(ChannelID channel, Graph &graph, int historyIndex)
Definition: glscope.cpp:881
Holds the cursor parameters.
Definition: scopesettings.h:16
unsigned currentGraphInHistory
Definition: glscope.h:126
bool rightMouseInside
Definition: glscope.h:114
OpenGL accelerated widget that displays the oscilloscope screen.
Definition: glscope.h:29
Definition: glscopegraph.h:16
void drawGrid()
Draw the grid.
Definition: glscope.cpp:807
Holds all view settings.
Definition: viewsettings.h:35
void markerMoved(int cursorIndex, int marker)
void mouseDoubleClickEvent(QMouseEvent *event) override
Definition: glscope.cpp:247
static GlScope * createNormal(DsoSettingsScope *scope, DsoSettingsView *view, QWidget *parent=nullptr)
Definition: glscope.cpp:90
void generateGrid(int index=-1, double value=0.0, bool pressed=false)
Definition: glscope.cpp:659
void showData(std::shared_ptr< PPresult > newData)
Definition: glscope.cpp:488
static const int gridItems
Definition: glscope.h:118
unsigned ChannelID
Definition: types.h:6
int matrixLocation
Definition: glscope.h:138
void cursorMeasurement(QPointF measurePosition=QPointF(), QPoint globalPosition=QPoint(), bool status=false)
static QString getOpenGLversion()
Definition: glscope.cpp:33
QString errorMessage
Definition: glscope.h:133
void rightMouseEvent(QMouseEvent *event)
Definition: glscope.cpp:130
GLsizei gridDrawCounts[gridItems]
Definition: glscope.h:120
Holds the settings for the oscilloscope.
Definition: scopesettings.h:100
void paintGL() override
Draw the graphs, marker and the grid.
Definition: glscope.cpp:569
GlScope(DsoSettingsScope *scope, DsoSettingsView *view, QWidget *parent=nullptr)
Initializes the scope widget.
Definition: glscope.cpp:66
static QString OpenGLversion
Definition: glscope.h:129
void drawVertices(QOpenGLFunctions *gl, int marker, QColor color)
Definition: glscope.cpp:842
static GlScope * createZoomed(DsoSettingsScope *scope, DsoSettingsView *view, QWidget *parent=nullptr)
Definition: glscope.cpp:98
std::list< Graph > m_GraphHistory
Definition: glscope.h:125
void paintEvent(QPaintEvent *event) override
Definition: glscope.cpp:325
#define GLSL120
Definition: glscope.h:25
static void useOpenGLSLversion(QString version=GLSL120)
Definition: glscope.cpp:49
QPointF posToScopePos(QPointF pos)
Definition: glscope.cpp:116
static QString GLSLversion
Definition: glscope.h:130
Post processing results.
Definition: ppresult.h:43
void mousePressEvent(QMouseEvent *event) override
Definition: glscope.cpp:147