LibrePCB Developers Documentation
openglscenebuilder.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_OPENGLSCENEBUILDER_H
21#define LIBREPCB_EDITOR_OPENGLSCENEBUILDER_H
22
23/*******************************************************************************
24 * Includes
25 ******************************************************************************/
27#include <polyclipping/clipper.hpp>
28
29#include <QtCore>
30
31#include <memory>
32
33/*******************************************************************************
34 * Namespace / Forward Declarations
35 ******************************************************************************/
36namespace librepcb {
37namespace editor {
38
39class OpenGlObject;
40class OpenGlTriangleObject;
41
42/*******************************************************************************
43 * Class OpenGlSceneBuilder
44 ******************************************************************************/
45
49class OpenGlSceneBuilder final : public QObject {
50 Q_OBJECT
51
52public:
53 // Types
54 typedef std::tuple<qreal, qreal, qreal> Color;
55 typedef QMap<Color, QVector<QVector3D>> StepModel;
56
57 // Constructors / Destructor
58 OpenGlSceneBuilder(QObject* parent = nullptr) noexcept;
59 OpenGlSceneBuilder(const OpenGlSceneBuilder& other) = delete;
60 ~OpenGlSceneBuilder() noexcept;
61
62 // General Methods
63
67 void start(std::shared_ptr<SceneData3D> data) noexcept;
68
75 bool isBusy() const noexcept;
76
80 void waitForFinished() noexcept;
81
85 void cancel() noexcept;
86
87 // Operator Overloadings
88 OpenGlSceneBuilder& operator=(const OpenGlSceneBuilder& rhs) = delete;
89
90signals:
91 void started();
92 void finished(QString errorMsg);
93 void objectAdded(std::shared_ptr<librepcb::editor::OpenGlObject> obj);
94 void objectRemoved(std::shared_ptr<librepcb::editor::OpenGlObject> obj);
95 void objectUpdated(std::shared_ptr<librepcb::editor::OpenGlObject> obj);
96
97private: // Methods
98 void run(std::shared_ptr<SceneData3D> data) noexcept;
99 ClipperLib::Paths getPaths(const std::shared_ptr<SceneData3D>& data,
100 const QStringList layers) const;
101 QVector<QVector3D> extrude(const ClipperLib::Paths& paths, qreal z,
102 qreal height, qreal scaleFactor, bool faces = true,
103 bool edges = true, bool closed = true) const;
104 static QVector<QVector3D> tesselate(const ClipperLib::Path& path, qreal z,
105 qreal scaleFactor);
106 void publishTriangleData(const QString& id, const QColor& color,
107 const QVector<QVector3D>& triangles);
108 void publishDevice(const SceneData3D::DeviceData& obj,
109 const QByteArray& stepContent, qreal z, qreal scaleFactor,
110 qreal alpha);
111
112private: // Data
114 QFuture<void> mFuture;
115 bool mAbort;
116
117 // Thread data.
118 QHash<QString, std::shared_ptr<OpenGlTriangleObject>> mBoardObjects;
119 QHash<Uuid, QMap<Color, std::shared_ptr<OpenGlTriangleObject>>> mDevices;
120 QHash<QByteArray, StepModel> mStepModels;
121};
122
123/*******************************************************************************
124 * End of File
125 ******************************************************************************/
126
127} // namespace editor
128} // namespace librepcb
129
130#endif
The Path class represents a list of vertices connected by straight lines or circular arc segments.
Definition: path.h:58
3D scene data representing a board with package models
Definition: scenedata3d.h:53
The Uuid class is a replacement for QUuid to get UUID strings without {} braces.
Definition: uuid.h:58
Represents one 3D object in an OpenGL 3D model.
Definition: openglobject.h:43
Asynchronously generates a 3D board scene for OpenGL rendering.
Definition: openglscenebuilder.h:49
void objectAdded(std::shared_ptr< librepcb::editor::OpenGlObject > obj)
QHash< QByteArray, StepModel > mStepModels
Cache.
Definition: openglscenebuilder.h:120
void cancel() noexcept
Cancel the build.
Definition: openglscenebuilder.cpp:97
bool isBusy() const noexcept
Check if there is currently a build in progress.
Definition: openglscenebuilder.cpp:88
bool mAbort
Definition: openglscenebuilder.h:115
QHash< QString, std::shared_ptr< OpenGlTriangleObject > > mBoardObjects
Definition: openglscenebuilder.h:118
QMap< Color, QVector< QVector3D > > StepModel
Definition: openglscenebuilder.h:55
void finished(QString errorMsg)
void start(std::shared_ptr< SceneData3D > data) noexcept
Start building scene asynchronously.
Definition: openglscenebuilder.cpp:79
OpenGlSceneBuilder(QObject *parent=nullptr) noexcept
Definition: openglscenebuilder.cpp:66
static QVector< QVector3D > tesselate(const ClipperLib::Path &path, qreal z, qreal scaleFactor)
Definition: openglscenebuilder.cpp:375
void objectRemoved(std::shared_ptr< librepcb::editor::OpenGlObject > obj)
QVector< QVector3D > extrude(const ClipperLib::Paths &paths, qreal z, qreal height, qreal scaleFactor, bool faces=true, bool edges=true, bool closed=true) const
Definition: openglscenebuilder.cpp:316
QFuture< void > mFuture
Definition: openglscenebuilder.h:114
void waitForFinished() noexcept
Wait (block) until the build is finished.
Definition: openglscenebuilder.cpp:93
QHash< Uuid, QMap< Color, std::shared_ptr< OpenGlTriangleObject > > > mDevices
Definition: openglscenebuilder.h:119
std::tuple< qreal, qreal, qreal > Color
Definition: openglscenebuilder.h:54
const PositiveLength mMaxArcTolerance
Definition: openglscenebuilder.h:113
void objectUpdated(std::shared_ptr< librepcb::editor::OpenGlObject > obj)
void publishDevice(const SceneData3D::DeviceData &obj, const QByteArray &stepContent, qreal z, qreal scaleFactor, qreal alpha)
Definition: openglscenebuilder.cpp:424
void publishTriangleData(const QString &id, const QColor &color, const QVector< QVector3D > &triangles)
Definition: openglscenebuilder.cpp:409
void run(std::shared_ptr< SceneData3D > data) noexcept
Definition: openglscenebuilder.cpp:107
ClipperLib::Paths getPaths(const std::shared_ptr< SceneData3D > &data, const QStringList layers) const
Definition: openglscenebuilder.cpp:305
Asynchronously generates a 3D board scene for OpenGL rendering.
Definition: opengltriangleobject.h:46
Definition: occmodel.cpp:77
type_safe::constrained_type< Length, PositiveLengthConstraint, PositiveLengthVerifier > PositiveLength
Definition: length.h:812