BornAgain  1.19.79
Simulate and fit neutron and x-ray scattering at grazing incidence
canvas.h
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file GUI/ba3d/view/canvas.h
6 //! @brief Defines Canvas class
7 //!
8 //! @homepage http://www.bornagainproject.org
9 //! @license GNU General Public License v3 or higher (see COPYING)
10 //! @copyright Forschungszentrum Jülich GmbH 2018
11 //! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS)
12 //
13 // ************************************************************************************************
14 
15 #ifndef BORNAGAIN_GUI_BA3D_VIEW_CANVAS_H
16 #define BORNAGAIN_GUI_BA3D_VIEW_CANVAS_H
17 
18 #include "GUI/ba3d/def.h"
19 #include <QHash>
20 
21 #include <QOpenGLFunctions>
22 #include <QOpenGLShaderProgram>
23 #include <QOpenGLWidget>
24 
25 namespace GUI::RealSpace {
26 
27 class Camera;
28 class Program;
29 class Model;
30 class Geometry;
31 class Buffer;
32 class Object;
33 
34 class Canvas : public QOpenGLWidget, protected QOpenGLFunctions {
35  Q_OBJECT
36  friend class Object;
37 
38 public:
39  Canvas();
40  ~Canvas() override;
41 
42  void setBgColor(QColor const&);
43 
44  // active things, owned elsewhere, may be nullptr
45  void setCamera(Camera*);
46  void setProgram(Program*);
47  void setModel(Model*);
48  Model* getModel();
49 
50  // Toolbar Actions
51  void defaultView();
52  void sideView();
53  void topView();
54 
55  // Flying Camera implementation (similar to Blender's camera system)
56  void horizontalCameraTurn(float angle);
57  void verticalCameraTurn(float angle);
58 
59  Camera* cam() { return camera; }
60 
61 private:
62  QRect viewport;
64  int currentZoomLevel; // current configuration of mousewheel w.r.t to default (0) configuration
65 
66  void setCamera(bool full = true);
67 
68  void initializeGL() override;
69  void resizeGL(int, int) override;
70  void paintGL() override;
71 
72  QPoint e_last; // latest mouse event's (x,y) screen coordinates
73  QMatrix4x4 matModel, matProj;
74  QVector3D unproject(QPoint const&);
75 
77  void mousePressEvent(QMouseEvent*) override;
78  void mouseMoveEvent(QMouseEvent*) override;
79  void mouseReleaseEvent(QMouseEvent*) override;
80  void wheelEvent(QWheelEvent*) override;
81 
85 
86  QMetaObject::Connection modelUpdated;
87 
88  QHash<Geometry const*, Buffer*> buffers;
89  void releaseBuffer(Geometry const*);
90  void releaseBuffers();
91 
92  void draw(QColor const&, QMatrix4x4 const&, Geometry const&);
93 
94  void cleanup();
95  bool isInitialized() const;
96 
98 };
99 
100 } // namespace GUI::RealSpace
101 
102 #endif // BORNAGAIN_GUI_BA3D_VIEW_CANVAS_H
void mouseMoveEvent(QMouseEvent *) override
Definition: canvas.cpp:214
void mouseReleaseEvent(QMouseEvent *) override
Definition: canvas.cpp:244
Program * program
Definition: canvas.h:83
void wheelEvent(QWheelEvent *) override
Definition: canvas.cpp:252
QVector3D unproject(QPoint const &)
Definition: canvas.cpp:187
QHash< Geometry const *, Buffer * > buffers
Definition: canvas.h:88
void draw(QColor const &, QMatrix4x4 const &, Geometry const &)
Definition: canvas.cpp:282
enum GUI::RealSpace::Canvas::@0 mouseButton
void mousePressEvent(QMouseEvent *) override
Definition: canvas.cpp:193
void initializeGL() override
Definition: canvas.cpp:128
void releaseBuffer(Geometry const *)
Definition: canvas.cpp:270
void setCamera(Camera *)
Definition: canvas.cpp:80
bool isInitialized() const
Definition: canvas.cpp:312
QMetaObject::Connection modelUpdated
Definition: canvas.h:86
QMatrix4x4 matModel
Definition: canvas.h:73
Camera * cam()
Definition: canvas.h:59
void paintGL() override
Definition: canvas.cpp:149
void setBgColor(QColor const &)
Definition: canvas.cpp:72
void setProgram(Program *)
Definition: canvas.cpp:86
void verticalCameraTurn(float angle)
Definition: canvas.cpp:436
void horizontalCameraTurn(float angle)
Definition: canvas.cpp:391
void setModel(Model *)
Definition: canvas.cpp:94
~Canvas() override
Definition: canvas.cpp:67
void resizeGL(int, int) override
Definition: canvas.cpp:141
QMatrix4x4 matProj
Definition: canvas.h:73
A geometric object.
Definition: object.h:28
Definitions in namespace GUI::RealSpace.