LibrePCB Developers Documentation
Loading...
Searching...
No Matches
openglview.h
Go to the documentation of this file.
1/*
2 * LibrePCB - Professional EDA for everyone!
3 * Copyright (C) 2013 LibrePCB Developers, see AUTHORS.md for contributors.
4 * https://librepcb.org/
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#ifndef LIBREPCB_EDITOR_OPENGLVIEW_H
21#define LIBREPCB_EDITOR_OPENGLVIEW_H
22
23/*******************************************************************************
24 * Includes
25 ******************************************************************************/
26#include <QtCore>
27#include <QtOpenGL>
28#include <QtOpenGLWidgets>
29#include <QtWidgets>
30
31#include <memory>
32
33/*******************************************************************************
34 * Namespace / Forward Declarations
35 ******************************************************************************/
36namespace librepcb {
37namespace editor {
38
39class OpenGlObject;
40class WaitingSpinnerWidget;
41
42/*******************************************************************************
43 * Class OpenGlView
44 ******************************************************************************/
45
49class OpenGlView final : public QOpenGLWidget, protected QOpenGLFunctions {
50 Q_OBJECT
51
52public:
53 // Constructors / Destructor
54 explicit OpenGlView(QWidget* parent = nullptr) noexcept;
55 OpenGlView(const OpenGlView& other) = delete;
56 virtual ~OpenGlView() noexcept;
57
58 // Getters
59 qint64 getIdleTimeMs() const noexcept { return mIdleTimeMs; }
60
61 // General Methods
62 void addObject(std::shared_ptr<OpenGlObject> obj) noexcept;
63 void removeObject(std::shared_ptr<OpenGlObject> obj) noexcept;
64 void setObjects(const QVector<std::shared_ptr<OpenGlObject>>& objs) noexcept;
65 void zoomIn() noexcept;
66 void zoomOut() noexcept;
67 void zoomAll() noexcept;
68 void startSpinning() noexcept;
69 void stopSpinning(QString errorMsg) noexcept;
70
71 // Operator Overloadings
72 OpenGlView& operator=(const OpenGlView& rhs) = delete;
73
74protected:
75 void mousePressEvent(QMouseEvent* e) override;
76 void mouseMoveEvent(QMouseEvent* e) override;
77 void wheelEvent(QWheelEvent* e) override;
78 void smoothTo(qreal fov, const QPointF& center,
79 const QMatrix4x4& transform) noexcept;
80 void initializeGL() override;
81 void resizeGL(int w, int h) override;
82 void paintGL() override;
83
84private:
85 void zoom(const QPointF& center, qreal factor) noexcept;
86 QPointF toNormalizedPos(const QPointF& pos) const noexcept;
87 QPointF toModelPos(const QPointF& pos) const noexcept;
88
89private:
90 QScopedPointer<QVBoxLayout> mLayout;
91 QScopedPointer<QLabel> mErrorLabel;
93 QOpenGLShaderProgram mProgram;
97 QMatrix4x4 mTransform;
103
104 // Transform Animation
106 qreal fov;
107 QPointF center;
108 QMatrix4x4 transform;
109 };
112 QScopedPointer<QVariantAnimation> mAnimation;
113
114 // Content
115 QVector<std::shared_ptr<OpenGlObject>> mObjects;
116
117 // Static Variables
118 static constexpr qreal sCameraPosZ = 5.0;
119 static constexpr qreal sInitialFov = 15.0;
120 static constexpr qreal sZoomStepFactor = 1.3;
121};
122
123/*******************************************************************************
124 * End of File
125 ******************************************************************************/
126
127} // namespace editor
128} // namespace librepcb
129
130#endif
OpenGL 3D viewer widget.
Definition openglview.h:49
QVector< std::shared_ptr< OpenGlObject > > mObjects
Definition openglview.h:115
static constexpr qreal sCameraPosZ
Definition openglview.h:118
void zoomAll() noexcept
Definition openglview.cpp:136
QOpenGLShaderProgram mProgram
Definition openglview.h:93
OpenGlView(const OpenGlView &other)=delete
void resizeGL(int w, int h) override
Definition openglview.cpp:263
void setObjects(const QVector< std::shared_ptr< OpenGlObject > > &objs) noexcept
Definition openglview.cpp:122
void addObject(std::shared_ptr< OpenGlObject > obj) noexcept
Definition openglview.cpp:112
qreal mProjectionAspectRatio
Definition openglview.h:94
void removeObject(std::shared_ptr< OpenGlObject > obj) noexcept
Definition openglview.cpp:117
void mousePressEvent(QMouseEvent *e) override
Definition openglview.cpp:159
virtual ~OpenGlView() noexcept
Definition openglview.cpp:102
void mouseMoveEvent(QMouseEvent *e) override
Definition openglview.cpp:166
TransformData mAnimationDataDelta
Definition openglview.h:111
void zoomOut() noexcept
Definition openglview.cpp:132
QMatrix4x4 mTransform
Definition openglview.h:97
void paintGL() override
Definition openglview.cpp:267
void smoothTo(qreal fov, const QPointF &center, const QMatrix4x4 &transform) noexcept
Definition openglview.cpp:210
void wheelEvent(QWheelEvent *e) override
Definition openglview.cpp:203
void stopSpinning(QString errorMsg) noexcept
Definition openglview.cpp:145
bool mInitialized
Definition openglview.h:92
QMatrix4x4 mMousePressTransform
Definition openglview.h:99
qint64 mIdleTimeMs
Definition openglview.h:101
void zoomIn() noexcept
Definition openglview.cpp:128
QScopedPointer< WaitingSpinnerWidget > mWaitingSpinner
Definition openglview.h:102
QPoint mMousePressPosition
Definition openglview.h:98
void startSpinning() noexcept
Definition openglview.cpp:141
QScopedPointer< QLabel > mErrorLabel
Definition openglview.h:91
QScopedPointer< QVariantAnimation > mAnimation
Definition openglview.h:112
static constexpr qreal sZoomStepFactor
Definition openglview.h:120
void initializeGL() override
Definition openglview.cpp:229
QPointF mMousePressCenter
Definition openglview.h:100
QPointF mProjectionCenter
Definition openglview.h:96
QScopedPointer< QVBoxLayout > mLayout
Definition openglview.h:90
TransformData mAnimationDataStart
Definition openglview.h:110
qreal mProjectionFov
Definition openglview.h:95
qint64 getIdleTimeMs() const noexcept
Definition openglview.h:59
void zoom(const QPointF &center, qreal factor) noexcept
Definition openglview.cpp:300
QPointF toModelPos(const QPointF &pos) const noexcept
Definition openglview.cpp:319
QPointF toNormalizedPos(const QPointF &pos) const noexcept
Definition openglview.cpp:313
static constexpr qreal sInitialFov
Definition openglview.h:119
A widget drawing a rotating spinner to indicate an ongoing operation.
Definition waitingspinnerwidget.h:52
Definition occmodel.cpp:76
qreal fov
Definition openglview.h:106
QMatrix4x4 transform
Definition openglview.h:108
QPointF center
Definition openglview.h:107