LibrePCB Developers Documentation
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 <optional/tl/optional.hpp>
32
33#include <QtCore>
34#include <QtGui>
35
36#include <memory>
37
38/*******************************************************************************
39 * Namespace / Forward Declarations
40 ******************************************************************************/
41namespace librepcb {
42
43/*******************************************************************************
44 * Class GraphicsOutputJob
45 ******************************************************************************/
46
50class GraphicsOutputJob final : public OutputJob {
51 Q_DECLARE_TR_FUNCTIONS(GraphicsOutputJob)
52
53public:
56
57 struct Content {
58 // Types
59 enum class Preset {
60 None,
62 BoardImage,
63 BoardAssemblyTop,
64 BoardAssemblyBottom,
65 };
66 enum class Type {
68 Board,
69 AssemblyGuide, // Reserved for future use.
70 };
71
72 // Common options.
74 QString title;
75 tl::optional<QString> pageSizeKey; // nullopt = auto
81 bool rotate;
82 bool mirror;
83 tl::optional<UnsignedRatio> scale;
88 QMap<QString, QColor> layers;
91
92 // Arbitrary options for forward compatibility in case we really need to
93 // add new settings in a minor release. Supported options:
94 // - realistic: If present, render boards in realistic mode
95 QMap<QString, QList<SExpression>> options;
96
97 Content(Preset preset) noexcept
99 title(),
100 pageSizeKey(tl::nullopt),
102 marginLeft(10000000), // 10mm
103 marginTop(10000000), // 10mm
104 marginRight(10000000), // 10mm
105 marginBottom(10000000), // 10mm
106 rotate(false),
107 mirror(false),
108 scale(tl::nullopt), // Fit in page
109 pixmapDpi(600),
110 monochrome(false),
111 backgroundColor(Qt::transparent),
112 minLineWidth(100000),
113 layers(),
114 boards(BoardSet::set({tl::nullopt})),
116 options() {
117 QSet<QString> enabledLayers;
118 if (preset == Preset::Schematic) {
120 title = tr("Schematic");
121 boards = BoardSet::set({tl::nullopt});
123 enabledLayers = {
137 };
138 } else if (preset != Preset::None) {
140 if (preset == Preset::BoardAssemblyTop) {
141 title = tr("Assembly Top");
142 mirror = false;
143 } else if (preset == Preset::BoardAssemblyBottom) {
144 title = tr("Assembly Bottom");
145 mirror = true;
146 } else {
147 title = tr("Board");
148 mirror = false;
149 }
152 enabledLayers = {
162 };
163 if (preset != Preset::BoardAssemblyBottom) {
164 enabledLayers += {
170 };
171 }
172 if (preset != Preset::BoardAssemblyTop) {
173 enabledLayers += {
179 };
180 }
181 if (preset == Preset::BoardImage) {
182 enabledLayers += {
186 };
187 }
188 }
189 GraphicsExportSettings defaultSettings;
190 foreach (const auto& pair, defaultSettings.getColors()) {
191 if (enabledLayers.contains(pair.first)) {
192 layers.insert(pair.first, pair.second);
193 }
194 }
195 }
196 Content(const Content& other) = default;
197 Content& operator=(const Content& rhs) = default;
198 bool operator==(const Content& rhs) const noexcept {
199 return (type == rhs.type) //
200 && (title == rhs.title) //
201 && (pageSizeKey == rhs.pageSizeKey) // break
202 && (orientation == rhs.orientation) // break
203 && (marginLeft == rhs.marginLeft) // break
204 && (marginTop == rhs.marginTop) // break
205 && (marginRight == rhs.marginRight) // break
206 && (marginBottom == rhs.marginBottom) // break
207 && (rotate == rhs.rotate) // break
208 && (mirror == rhs.mirror) // break
209 && (scale == rhs.scale) // break
210 && (pixmapDpi == rhs.pixmapDpi) // break
211 && (monochrome == rhs.monochrome) // break
212 && (backgroundColor == rhs.backgroundColor) // break
213 && (minLineWidth == rhs.minLineWidth) // break
214 && (layers == rhs.layers) // break
215 && (boards == rhs.boards) // break
216 && (assemblyVariants == rhs.assemblyVariants) // break
217 && (options == rhs.options) // break
218 ;
219 }
220 bool operator!=(const Content& rhs) const noexcept {
221 return !(*this == rhs);
222 }
223 };
224
225 // Constructors / Destructor
226 GraphicsOutputJob(const GraphicsOutputJob& other) noexcept;
227 explicit GraphicsOutputJob(const SExpression& node);
228 virtual ~GraphicsOutputJob() noexcept;
229
230 // Getters
231 virtual QString getTypeTr() const noexcept override;
232 virtual QIcon getTypeIcon() const noexcept override;
233 const SimpleString& getDocumentTitle() const noexcept {
234 return mDocumentTitle;
235 }
236 const QList<Content> getContent() const noexcept { return mContent; }
237 const QString& getOutputPath() const noexcept { return mOutputPath; }
238
239 // Setters
240 void setDocumentTitle(const SimpleString& title) noexcept;
241 void setContent(const QList<Content>& content) noexcept;
242 void setOutputPath(const QString& path) noexcept;
243
244 // General Methods
245 static QString getTypeName() noexcept { return "graphics"; }
246 static QString getTypeTrStatic() noexcept { return tr("PDF/Image"); }
247 virtual std::shared_ptr<OutputJob> cloneShared() const noexcept override;
248
249 // Operator Overloadings
250 GraphicsOutputJob& operator=(const GraphicsOutputJob& rhs) = delete;
251
252 // Static Methods
253 static std::shared_ptr<GraphicsOutputJob> schematicPdf() noexcept;
254 static std::shared_ptr<GraphicsOutputJob> boardAssemblyPdf() noexcept;
255
256private: // Methods
257 GraphicsOutputJob() noexcept;
258 virtual void serializeDerived(SExpression& root) const override;
259 virtual bool equals(const OutputJob& rhs) const noexcept override;
260
261private: // Data
264 QString mOutputPath;
265};
266
267/*******************************************************************************
268 * End of File
269 ******************************************************************************/
270
271} // namespace librepcb
272
273#endif
The Board class represents a PCB of a project and is always part of a circuit.
Definition: board.h:73
Orientation
Definition: graphicsexportsettings.h:54
PDF/Image output job.
Definition: graphicsoutputjob.h:50
QList< Content > mContent
Definition: graphicsoutputjob.h:263
SimpleString mDocumentTitle
Definition: graphicsoutputjob.h:262
virtual QString getTypeTr() const noexcept override
Definition: graphicsoutputjob.cpp:137
void setOutputPath(const QString &path) noexcept
Definition: graphicsoutputjob.cpp:169
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:245
const SimpleString & getDocumentTitle() const noexcept
Definition: graphicsoutputjob.h:233
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:246
QString mOutputPath
Definition: graphicsoutputjob.h:264
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:237
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:236
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
The Schematic class represents one schematic page of a project and is always part of a circuit.
Definition: schematic.h:74
Definition: occmodel.cpp:77
type_safe::constrained_type< Length, UnsignedLengthConstraint, UnsignedLengthVerifier > UnsignedLength
Definition: length.h:696
type_safe::constrained_type< QString, SimpleStringConstraint, SimpleStringVerifier > SimpleString
Definition: simplestring.h:80
Definition: graphicsoutputjob.h:57
bool mirror
Definition: graphicsoutputjob.h:82
tl::optional< QString > pageSizeKey
Definition: graphicsoutputjob.h:75
Type
Definition: graphicsoutputjob.h:66
QMap< QString, QList< SExpression > > options
Definition: graphicsoutputjob.h:95
bool rotate
Definition: graphicsoutputjob.h:81
UnsignedLength marginBottom
Definition: graphicsoutputjob.h:80
bool monochrome
Definition: graphicsoutputjob.h:85
QColor backgroundColor
Definition: graphicsoutputjob.h:86
UnsignedLength minLineWidth
Definition: graphicsoutputjob.h:87
AssemblyVariantSet assemblyVariants
Definition: graphicsoutputjob.h:90
Content(Preset preset) noexcept
Definition: graphicsoutputjob.h:97
Content(const Content &other)=default
uint pixmapDpi
Definition: graphicsoutputjob.h:84
bool operator==(const Content &rhs) const noexcept
Definition: graphicsoutputjob.h:198
UnsignedLength marginTop
Definition: graphicsoutputjob.h:78
Content & operator=(const Content &rhs)=default
UnsignedLength marginLeft
Definition: graphicsoutputjob.h:77
QString title
Definition: graphicsoutputjob.h:74
bool operator!=(const Content &rhs) const noexcept
Definition: graphicsoutputjob.h:220
Type type
Definition: graphicsoutputjob.h:73
tl::optional< UnsignedRatio > scale
Definition: graphicsoutputjob.h:83
GraphicsExportSettings::Orientation orientation
Definition: graphicsoutputjob.h:76
QMap< QString, QColor > layers
Definition: graphicsoutputjob.h:88
Preset
Definition: graphicsoutputjob.h:59
BoardSet boards
Definition: graphicsoutputjob.h:89
UnsignedLength marginRight
Definition: graphicsoutputjob.h:79
Definition: outputjob.h:65
static ObjectSet set(const QSet< T > &set) noexcept
Definition: outputjob.h:113
static ObjectSet onlyDefault() noexcept
Definition: outputjob.h:110
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