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