PCB Environment: /home/chr/devel/PhD/Environment/pub/PCBEnv/pcbenv/cxx/UI/GLWidget.hpp Source File

PCB Environment 2

Loading...
Searching...
No Matches
GLWidget.hpp
1
2#ifndef GYM_PCB_UI_GLWIDGET_H
3#define GYM_PCB_UI_GLWIDGET_H
4
5#include "Py.hpp"
6#include <QOpenGLWidget>
7#include <QOpenGLFunctions_4_3_Core>
8#include <QPainter>
9#include <QElapsedTimer>
10#include "Camera.hpp"
11#include "Shaders.hpp"
12#include <set>
13
14class Object;
15class Component;
16class Pin;
17class Net;
18class PCBoard;
19class PCBoardMesh;
20class NavMesh;
21namespace ui {
22class NavGrid;
23} // namespace ui
24class RatsNest;
25class RoutePainter;
26class RoutePainterLines;
27class TriList;
28class ViaPainter;
29class UIApplication;
30class UIActions;
31class Window;
32
33 class GLWidget : public QOpenGLWidget, public QOpenGLFunctions_4_3_Core
34{
35 Q_OBJECT
36
37private:
38 GLWidget(Window *parent, UIActions *A);
39 ~GLWidget();
40public:
41 static GLWidget *createInstance(Window *, UIActions *);
42 static void deleteInstance();
43 static GLWidget *getInstance() { return sInstance; }
44
45 PCBoard *getPCB() const { return mPCB.get(); }
46
47 void setPCB(const std::shared_ptr<PCBoard>&);
48 void setBottomView(bool b);
49 void setLayerAlpha(int z, float a);
50
51 void scheduleSnapshot(const std::string &savePath) { mSnapshotSavePath = savePath; }
52
53 bool areFootprintsShown() const { return mShowFootprints; }
54 bool areGridLinesShown() const { return mShowGridLines; }
55 bool areGridPointsShown() const { return mShowGridPoints; }
56 bool isRatsNestShown() const { return mShowRatsNest; }
57 bool isTriangulationShown() const { return mShowTriangulation; }
58 bool isRatsNestLimited() const { return mLimitRatsNest; }
59
60 void onKeyRelease(QKeyEvent *);
61public slots:
62 void animate();
63 void resetZoom();
64 void focusOn(const Object&);
65 void showFootprints(bool b) { mShowFootprints = b; }
66 void showGridLines(bool b) { mShowGridLines = b; }
67 void showGridPoints(bool b);
68 void showRatsNest(bool b) { mShowRatsNest = b; }
69 void showTriangulation(bool b) { mShowTriangulation = b; }
70 void showGridAStar(bool b);
71 void setLimitRatsNest(bool b);
72
73protected:
74 void initializeGL() override;
75
76 void paintEvent(QPaintEvent *) override;
77 void paintGL() override;
78 void paintQt(QPainter *, QPaintEvent *);
79
80 void resizeEvent(QResizeEvent *) override;
81 void mouseMoveEvent(QMouseEvent *) override;
82 void mousePressEvent(QMouseEvent *) override;
83 void mouseReleaseEvent(QMouseEvent *) override;
84 void wheelEvent(QWheelEvent *) override;
85
86private:
87 float m_dt;
88 float m_FPS{0};
89 QElapsedTimer mFrameTimer;
90
91 Camera mCamera;
92
93 uint32_t mDirty{0};
94 uint32_t ackDirtyMask() { auto m = mDirty; mDirty = 0; return m; }
95
96 std::shared_ptr<PCBoard> mPCB;
97 Shaders mShaderCache;
98 std::unique_ptr<NavMesh> mNavMesh;
99 std::unique_ptr<ui::NavGrid> mNavGrid;
100 std::unique_ptr<PCBoardMesh> mBoardMain[2];
101 std::unique_ptr<PCBoardMesh> mBoardPins[2];
102 std::unique_ptr<RatsNest> mRatsNest;
103 std::unique_ptr<RoutePainter> mRoutePainter;
104 std::unique_ptr<RoutePainter> mRoutePainterPreview;
105 std::unique_ptr<RoutePainterLines> mRoutePainterLines;
106 std::unique_ptr<TriList> mTriList;
107 std::unique_ptr<ViaPainter> mViaPainter;
108 std::unique_ptr<ViaPainter> mViaPainterPreview;
109 void resetSceneNodes();
110
111 uint mViewLayer{0};
112 bool mShowGridPoints{true};
113 bool mShowGridAStar{false};
114 bool mShowGridLines{true};
115 bool mShowFootprints{true};
116 bool mShowRatsNest{true};
117 bool mShowTriangulation{true};
118 bool mBottomView{false};
119 bool mLimitRatsNest{false};
120
121 float mFootprintFillAlphaBase{0.2f};
122 float mFootprintLineAlphaBase{1.0f};
123 float mPinFillAlphaBase{0.7f};
124 float mPinLineAlphaBase{0.0f};
125
126 struct {
127 QPoint pos;
128 QPoint posDown;
129 } mMouse;
130 QPointF getNormalizedCursorPos() const;
131 QPointF normalizedPos(const QPoint&) const;
132 QPoint pixelPos(const QPointF&) const;
133 QPoint worldPosToPixels(const Point_2&) const;
134 Point_2 pixelsToWorldPos(QPoint) const;
135
136 struct Selection {
137 void add(Object *);
138 void clearObjects();
139 void clear();
140 bool setHover(Component *, bool select);
141 bool setHover(Pin *);
142 QRect rect;
143 std::set<Object *> objects;
144 struct {
145 Component *C{0};
146 Pin *P{0};
147 Net *N{0};
148 } hover;
149 } mSelection;
150 uint getFirstLayerForSelection() const;
151 Object *selectAt(const Point_2&) const;
152 void updateHoverSelection();
153 void updateRectangleSelection(bool append);
154 void clearRectangleSelection();
155
156 UIActions *const mActions;
157
158 void drawInfo(QPainter *);
159 void drawCosts(QPainter *);
160 void highlightSelected(QPainter&);
161
162 void saveSnapshot();
163 std::string mSnapshotSavePath;
164
165private:
166 static GLWidget *sInstance;
167};
168
169#endif // GYM_PCB_UI_GLWIDGET_H
Camera
Definition Camera.hpp:15
Component
Definition Component.hpp:18
NavMesh
Definition NavMesh.hpp:15
Net
Definition Net.hpp:19
Object
Definition Object.hpp:12
PCBoardMesh
Definition PCBoardMesh.hpp:14
PCBoard
Definition PCBoard.hpp:36
Pin
Definition Pin.hpp:18
RatsNest
Definition RatsNest.hpp:16
RoutePainterLines
Definition RoutePainterLines.hpp:12
RoutePainter
Definition RoutePainter.hpp:13
Shaders
Definition Shaders.hpp:8
TriList
Definition TriList.hpp:13
UIActions
WARNING: The non-async UIActions functions are expected to be non-concurrent.
Definition Actions.hpp:48
UIApplication
Definition Application.hpp:41
ViaPainter
Definition ViaPainter.hpp:13
Window
Definition Window.hpp:21
ui::NavGrid
Definition NavGrid.hpp:16