LibrePCB Developers Documentation
Loading...
Searching...
No Matches
graphicsoutputjob.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_CORE_GRAPHICSOUTPUTJOB_H
21#define LIBREPCB_CORE_GRAPHICSOUTPUTJOB_H
22
23/*******************************************************************************
24 * Includes
25 ******************************************************************************/
26#include "../export/graphicsexportsettings.h"
27#include "../types/simplestring.h"
28#include "../workspace/theme.h"
29#include "outputjob.h"
30
31#include <QtCore>
32#include <QtGui>
33
34#include <memory>
35#include <optional>
36
37/*******************************************************************************
38 * Namespace / Forward Declarations
39 ******************************************************************************/
40namespace librepcb {
41
42/*******************************************************************************
43 * Class GraphicsOutputJob
44 ******************************************************************************/
45
49class GraphicsOutputJob final : public OutputJob {
50 Q_DECLARE_TR_FUNCTIONS(GraphicsOutputJob)
51
52public:
55
56 struct Content {
57 // Types
58 enum class Preset {
59 None,
64 };
65 enum class Type {
67 Board,
68 AssemblyGuide, // Reserved for future use.
69 };
70
71 // Common options.
73 QString title;
74 std::optional<QString> pageSizeKey; // nullopt = auto
80 bool rotate;
81 bool mirror;
82 std::optional<UnsignedRatio> scale;
87 QMap<QString, QColor> layers;
90
91 // Arbitrary options for forward compatibility in case we really need to
92 // add new settings in a minor release. Supported options:
93 // - realistic: If present, render boards in realistic mode
94 QMap<QString, QList<SExpression>> options;
95
96 Content(Preset preset) noexcept
98 title(),
99 pageSizeKey(std::nullopt),
101 marginLeft(10000000), // 10mm
102 marginTop(10000000), // 10mm
103 marginRight(10000000), // 10mm
104 marginBottom(10000000), // 10mm
105 rotate(false),
106 mirror(false),
107 scale(std::nullopt), // Fit in page
108 pixmapDpi(600),
109 monochrome(false),
110 backgroundColor(Qt::transparent),
111 minLineWidth(100000),
112 layers(),
113 boards(BoardSet::set({std::nullopt})),
114 assemblyVariants(AssemblyVariantSet::set({std::nullopt})),
115 options() {
116 QSet<QString> enabledLayers;
117 if (preset == Preset::Schematic) {
119 title = tr("Schematic");
120 boards = BoardSet::set({std::nullopt});
121 assemblyVariants = AssemblyVariantSet::set({std::nullopt});
122 enabledLayers = {
136 };
137 } else if (preset != Preset::None) {
139 if (preset == Preset::BoardAssemblyTop) {
140 title = tr("Assembly Top");
141 mirror = false;
142 } else if (preset == Preset::BoardAssemblyBottom) {
143 title = tr("Assembly Bottom");
144 mirror = true;
145 } else {
146 title = tr("Board");
147 mirror = false;
148 }
149 boards = BoardSet::onlyDefault();
150 assemblyVariants = AssemblyVariantSet::set({std::nullopt});
151 enabledLayers = {
161 };
162 if (preset != Preset::BoardAssemblyBottom) {
163 enabledLayers += {
169 };
170 }
171 if (preset != Preset::BoardAssemblyTop) {
172 enabledLayers += {
178 };
179 }
180 if (preset == Preset::BoardImage) {
181 enabledLayers += {
185 };
186 }
187 }
188 GraphicsExportSettings defaultSettings;
189 foreach (const auto& pair, defaultSettings.getColors()) {
190 if (enabledLayers.contains(pair.first)) {
191 layers.insert(pair.first, pair.second);
192 }
193 }
194 }
195 Content(const Content& other) = default;
196 Content& operator=(const Content& rhs) = default;
197 bool operator==(const Content& rhs) const noexcept {
198 return (type == rhs.type) //
199 && (title == rhs.title) //
200 && (pageSizeKey == rhs.pageSizeKey) // break
201 && (orientation == rhs.orientation) // break
202 && (marginLeft == rhs.marginLeft) // break
203 && (marginTop == rhs.marginTop) // break
204 && (marginRight == rhs.marginRight) // break
205 && (marginBottom == rhs.marginBottom) // break
206 && (rotate == rhs.rotate) // break
207 && (mirror == rhs.mirror) // break
208 && (scale == rhs.scale) // break
209 && (pixmapDpi == rhs.pixmapDpi) // break
210 && (monochrome == rhs.monochrome) // break
211 && (backgroundColor == rhs.backgroundColor) // break
212 && (minLineWidth == rhs.minLineWidth) // break
213 && (layers == rhs.layers) // break
214 && (boards == rhs.boards) // break
215 && (assemblyVariants == rhs.assemblyVariants) // break
216 && (options == rhs.options) // break
217 ;
218 }
219 bool operator!=(const Content& rhs) const noexcept {
220 return !(*this == rhs);
221 }
222 };
223
224 // Constructors / Destructor
225 GraphicsOutputJob(const GraphicsOutputJob& other) noexcept;
226 explicit GraphicsOutputJob(const SExpression& node);
227 virtual ~GraphicsOutputJob() noexcept;
228
229 // Getters
230 virtual QString getTypeTr() const noexcept override;
231 virtual QIcon getTypeIcon() const noexcept override;
232 const SimpleString& getDocumentTitle() const noexcept {
233 return mDocumentTitle;
234 }
235 const QList<Content> getContent() const noexcept { return mContent; }
236 const QString& getOutputPath() const noexcept { return mOutputPath; }
237
238 // Setters
239 void setDocumentTitle(const SimpleString& title) noexcept;
240 void setContent(const QList<Content>& content) noexcept;
241 void setOutputPath(const QString& path) noexcept;
242
243 // General Methods
244 static QString getTypeName() noexcept { return "graphics"; }
245 static QString getTypeTrStatic() noexcept { return tr("PDF/Image"); }
246 virtual std::shared_ptr<OutputJob> cloneShared() const noexcept override;
247
248 // Operator Overloadings
249 GraphicsOutputJob& operator=(const GraphicsOutputJob& rhs) = delete;
250
251 // Static Methods
252 static std::shared_ptr<GraphicsOutputJob> schematicPdf() noexcept;
253 static std::shared_ptr<GraphicsOutputJob> boardAssemblyPdf() noexcept;
254
255private: // Methods
256 GraphicsOutputJob() noexcept;
257 virtual void serializeDerived(SExpression& root) const override;
258 virtual bool equals(const OutputJob& rhs) const noexcept override;
259
260private: // Data
263 QString mOutputPath;
264};
265
266/*******************************************************************************
267 * End of File
268 ******************************************************************************/
269
270} // namespace librepcb
271
272#endif
Orientation
Definition graphicsexportsettings.h:54
PDF/Image output job.
Definition graphicsoutputjob.h:49
QList< Content > mContent
Definition graphicsoutputjob.h:262
SimpleString mDocumentTitle
Definition graphicsoutputjob.h:261
virtual QString getTypeTr() const noexcept override
Definition graphicsoutputjob.cpp:137
void setOutputPath(const QString &path) noexcept
Definition graphicsoutputjob.cpp:169
ObjectSet< std::optional< Uuid > > BoardSet
Definition graphicsoutputjob.h:53
virtual bool equals(const OutputJob &rhs) const noexcept override
Definition graphicsoutputjob.cpp:261
void setContent(const QList< Content > &content) noexcept
Definition graphicsoutputjob.cpp:162
static QString getTypeName() noexcept
Definition graphicsoutputjob.h:244
const SimpleString & getDocumentTitle() const noexcept
Definition graphicsoutputjob.h:232
static std::shared_ptr< GraphicsOutputJob > boardAssemblyPdf() noexcept
Definition graphicsoutputjob.cpp:198
virtual ~GraphicsOutputJob() noexcept
Definition graphicsoutputjob.cpp:130
static QString getTypeTrStatic() noexcept
Definition graphicsoutputjob.h:245
QString mOutputPath
Definition graphicsoutputjob.h:263
virtual QIcon getTypeIcon() const noexcept override
Definition graphicsoutputjob.cpp:141
virtual void serializeDerived(SExpression &root) const override
Definition graphicsoutputjob.cpp:212
const QString & getOutputPath() const noexcept
Definition graphicsoutputjob.h:236
ObjectSet< std::optional< Uuid > > AssemblyVariantSet
Definition graphicsoutputjob.h:54
virtual std::shared_ptr< OutputJob > cloneShared() const noexcept override
Definition graphicsoutputjob.cpp:180
GraphicsOutputJob() noexcept
Definition graphicsoutputjob.cpp:70
void setDocumentTitle(const SimpleString &title) noexcept
Definition graphicsoutputjob.cpp:155
const QList< Content > getContent() const noexcept
Definition graphicsoutputjob.h:235
static std::shared_ptr< GraphicsOutputJob > schematicPdf() noexcept
Definition graphicsoutputjob.cpp:188
Base class for all output job types.
Definition outputjob.h:50
The SExpression class.
Definition sexpression.h:69
Definition occmodel.cpp:76
type_safe::constrained_type< Length, UnsignedLengthConstraint, UnsignedLengthVerifier > UnsignedLength
Definition length.h:694
type_safe::constrained_type< QString, SimpleStringConstraint, SimpleStringVerifier > SimpleString
Definition simplestring.h:79
Definition uuid.h:186
Definition graphicsoutputjob.h:56
bool mirror
Definition graphicsoutputjob.h:81
Type
Definition graphicsoutputjob.h:65
QMap< QString, QList< SExpression > > options
Definition graphicsoutputjob.h:94
bool rotate
Definition graphicsoutputjob.h:80
UnsignedLength marginBottom
Definition graphicsoutputjob.h:79
bool monochrome
Definition graphicsoutputjob.h:84
std::optional< QString > pageSizeKey
Definition graphicsoutputjob.h:74
QColor backgroundColor
Definition graphicsoutputjob.h:85
UnsignedLength minLineWidth
Definition graphicsoutputjob.h:86
std::optional< UnsignedRatio > scale
Definition graphicsoutputjob.h:82
AssemblyVariantSet assemblyVariants
Definition graphicsoutputjob.h:89
Content(Preset preset) noexcept
Definition graphicsoutputjob.h:96
Content(const Content &other)=default
uint pixmapDpi
Definition graphicsoutputjob.h:83
bool operator==(const Content &rhs) const noexcept
Definition graphicsoutputjob.h:197
UnsignedLength marginTop
Definition graphicsoutputjob.h:77
Content & operator=(const Content &rhs)=default
UnsignedLength marginLeft
Definition graphicsoutputjob.h:76
QString title
Definition graphicsoutputjob.h:73
bool operator!=(const Content &rhs) const noexcept
Definition graphicsoutputjob.h:219
Type type
Definition graphicsoutputjob.h:72
GraphicsExportSettings::Orientation orientation
Definition graphicsoutputjob.h:75
QMap< QString, QColor > layers
Definition graphicsoutputjob.h:87
Preset
Definition graphicsoutputjob.h:58
BoardSet boards
Definition graphicsoutputjob.h:88
UnsignedLength marginRight
Definition graphicsoutputjob.h:78
Definition outputjob.h:65
static constexpr const char * sBoardPlatedCutouts
Definition theme.h:86
static constexpr const char * sSchematicPinNumbers
Definition theme.h:78
static constexpr const char * sBoardCopperTop
Definition theme.h:123
static constexpr const char * sSchematicComments
Definition theme.h:67
static constexpr const char * sBoardGrabAreasTop
Definition theme.h:109
static constexpr const char * sSchematicGrabAreas
Definition theme.h:70
static constexpr const char * sBoardDocumentationBot
Definition theme.h:104
static constexpr const char * sBoardValuesTop
Definition theme.h:99
static constexpr const char * sSchematicDocumentation
Definition theme.h:66
static constexpr const char * sBoardDocumentationTop
Definition theme.h:103
static constexpr const char * sSchematicPinNames
Definition theme.h:77
static constexpr const char * sSchematicPinLines
Definition theme.h:76
static constexpr const char * sBoardDocumentation
Definition theme.h:94
static constexpr const char * sBoardValuesBot
Definition theme.h:100
static constexpr const char * sSchematicNames
Definition theme.h:72
static constexpr const char * sBoardNamesTop
Definition theme.h:97
static constexpr const char * sBoardMeasures
Definition theme.h:92
static constexpr const char * sBoardGrabAreasBot
Definition theme.h:110
static constexpr const char * sBoardNamesBot
Definition theme.h:98
static constexpr const char * sBoardPads
Definition theme.h:88
static constexpr const char * sSchematicNetLabels
Definition theme.h:64
static constexpr const char * sBoardVias
Definition theme.h:89
static constexpr const char * sSchematicGuide
Definition theme.h:68
static constexpr const char * sBoardFrames
Definition theme.h:84
static constexpr const char * sBoardComments
Definition theme.h:95
static constexpr const char * sBoardGuide
Definition theme.h:96
static constexpr const char * sBoardLegendTop
Definition theme.h:101
static constexpr const char * sBoardOutlines
Definition theme.h:85
static constexpr const char * sBoardLegendBot
Definition theme.h:102
static constexpr const char * sSchematicOutlines
Definition theme.h:69
static constexpr const char * sSchematicFrames
Definition theme.h:62
static constexpr const char * sSchematicValues
Definition theme.h:73
static constexpr const char * sBoardCopperBot
Definition theme.h:125
static constexpr const char * sBoardHoles
Definition theme.h:87
static constexpr const char * sSchematicWires
Definition theme.h:63