OpenHantek
Loading...
Searching...
No Matches
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"
18
19struct DsoSettingsView;
20struct DsoSettingsScope;
22class PPresult;
23
24#define GLES100 "1.00 ES"
25#define GLSL120 "1.20"
26#define GLSL150 "1.50"
27
29class 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;
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;
127
128 // OpenGL shader, matrix, var-locations
129 static QString OpenGLversion;
130 static QString GLSLversion;
131 QString renderInfo;
134 std::unique_ptr< QOpenGLShaderProgram > m_program;
135 QMatrix4x4 pmvMatrix;
140};
void generateVertices(int marker, const DsoSettingsScopeCursor &cursor)
Definition glscope.cpp:472
void rightMouseEvent(QMouseEvent *event)
Definition glscope.cpp:130
static QString getOpenGLversion()
Definition glscope.cpp:33
void drawGrid()
Draw the grid.
Definition glscope.cpp:767
int selectedCursor
Definition glscope.h:113
std::list< Graph > m_GraphHistory
Definition glscope.h:125
static GlScope * createZoomed(DsoSettingsScope *scope, DsoSettingsView *view, QWidget *parent=nullptr)
Definition glscope.cpp:98
int matrixLocation
Definition glscope.h:138
void drawHistogramChannelGraph(ChannelID channel, Graph &graph, int historyIndex)
Definition glscope.cpp:854
GLsizei gridDrawCounts[gridItems]
Definition glscope.h:120
DsoSettingsView * view
Definition glscope.h:95
void drawSpectrumChannelGraph(ChannelID channel, Graph &graph, int historyIndex)
Definition glscope.cpp:867
QString errorMessage
Definition glscope.h:133
bool shaderCompileSuccess
Definition glscope.h:132
GlScope(DsoSettingsScope *scope, DsoSettingsView *view, QWidget *parent=nullptr)
Initializes the scope widget.
Definition glscope.cpp:66
void markerMoved(int cursorIndex, int marker)
void showData(std::shared_ptr< PPresult > newData)
Definition glscope.cpp:448
void drawVoltageChannelGraph(ChannelID channel, Graph &graph, int historyIndex)
Definition glscope.cpp:841
static QString GLSLversion
Definition glscope.h:130
void generateGrid(int index=-1, double value=0.0, bool pressed=false)
Definition glscope.cpp:619
void selectCursor(int index)
Definition glscope.cpp:509
std::vector< DsoSettingsScopeCursor * > cursorInfo
Definition glscope.h:112
QOpenGLVertexArrayObject m_vaoGrid[gridItems]
Definition glscope.h:119
void drawMarkers()
Draw vertical lines at marker positions.
Definition glscope.cpp:813
void cursorMeasurement(QPointF measurePosition=QPointF(), QPoint globalPosition=QPoint(), bool status=false)
int selectionLocation
Definition glscope.h:139
void mouseMoveEvent(QMouseEvent *event) override
Definition glscope.cpp:202
const int NO_MARKER
Definition glscope.h:99
QString renderInfo
Definition glscope.h:131
std::unique_ptr< QOpenGLShaderProgram > m_program
Definition glscope.h:134
static QString OpenGLversion
Definition glscope.h:129
DsoSettingsScope * scope
Definition glscope.h:94
void draw4Cross(std::vector< QVector3D > &va, int section, float x, float y)
Definition glscope.cpp:602
std::vector< Vertices > vaMarker
Definition glscope.h:106
~GlScope() override
Definition glscope.cpp:83
QMatrix4x4 pmvMatrix
projection, view matrix
Definition glscope.h:135
bool rightMouseInside
Definition glscope.h:114
QColor triggerLineColor
Definition glscope.h:122
static const int gridItems
Definition glscope.h:118
int vertexLocation
Definition glscope.h:137
QOpenGLBuffer m_grid
Definition glscope.h:117
unsigned currentGraphInHistory
Definition glscope.h:126
int selectedMarker
Definition glscope.h:107
void resizeGL(int width, int height) override
Resize the widget.
Definition glscope.cpp:578
const int VERTICES_ARRAY_SIZE
Definition glscope.h:105
static GlScope * createNormal(DsoSettingsScope *scope, DsoSettingsView *view, QWidget *parent=nullptr)
Definition glscope.cpp:90
static void useOpenGLSLversion(QString version=GLSL120)
Definition glscope.cpp:49
void wheelEvent(QWheelEvent *event) override
Definition glscope.cpp:280
void drawVertices(QOpenGLFunctions *gl, int marker, QColor color)
Definition glscope.cpp:802
int colorLocation
Definition glscope.h:136
void paintGL() override
Draw the graphs, marker and the grid.
Definition glscope.cpp:529
void initializeGL() override
Initializes OpenGL output.
Definition glscope.cpp:341
QOpenGLVertexArrayObject m_vaoMarker
Definition glscope.h:109
void paintEvent(QPaintEvent *event) override
Definition glscope.cpp:325
QOpenGLBuffer m_marker
Definition glscope.h:108
QPointF posToScopePos(QPointF pos)
Definition glscope.cpp:116
void mousePressEvent(QMouseEvent *event) override
Definition glscope.cpp:147
void mouseReleaseEvent(QMouseEvent *event) override
Definition glscope.cpp:226
static QString getGLSLversion()
Definition glscope.h:38
GlScope(const GlScope &)=delete
void setVisible(bool visible) override
Definition glscope.cpp:105
void mouseDoubleClickEvent(QMouseEvent *event) override
Definition glscope.cpp:247
bool zoomed
Definition glscope.h:96
void updateCursor(int index=0)
Definition glscope.cpp:515
Post processing results.
Definition ppresult.h:43
#define GLSL120
Definition glscope.h:25
Holds the cursor parameters.
Definition scopesettings.h:16
Holds the settings for the oscilloscope.
Definition scopesettings.h:100
Holds all view settings.
Definition viewsettings.h:35
Definition glscope.h:101
QVector3D c
Definition glscope.h:102
QVector3D a
Definition glscope.h:102
QVector3D d
Definition glscope.h:102
QVector3D b
Definition glscope.h:102
Definition glscopegraph.h:16
unsigned ChannelID
Definition types.h:6