LibrePCB Developers Documentation
gerbergenerator.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_GERBERGENERATOR_H
21#define LIBREPCB_CORE_GERBERGENERATOR_H
22
23/*******************************************************************************
24 * Includes
25 ******************************************************************************/
26#include "../fileio/filepath.h"
27#include "../types/length.h"
28#include "../types/uuid.h"
29#include "gerberaperturelist.h"
30#include "gerberattribute.h"
31
32#include <QtCore>
33
34/*******************************************************************************
35 * Namespace / Forward Declarations
36 ******************************************************************************/
37namespace librepcb {
38
39class Angle;
40class GerberAttributeWriter;
41class Path;
42class Point;
43
44/*******************************************************************************
45 * Class GerberGenerator
46 ******************************************************************************/
47
51class GerberGenerator final {
52 Q_DECLARE_TR_FUNCTIONS(GerberGenerator)
53
54public:
55 // Public Types
61
62 // Constructors / Destructor
63 GerberGenerator() = delete;
64 GerberGenerator(const GerberGenerator& other) = delete;
65 GerberGenerator(const QDateTime& creationDate, const QString& projName,
66 const Uuid& projUuid, const QString& projRevision) noexcept;
67 ~GerberGenerator() noexcept;
68
69 // Getters
70 const QString& toStr() const noexcept { return mOutput; }
71
72 // Plot Methods
73 void setFileFunctionOutlines(bool plated) noexcept;
74 void setFileFunctionCopper(int layer, CopperSide side,
75 Polarity polarity) noexcept;
76 void setFileFunctionSolderMask(BoardSide side, Polarity polarity) noexcept;
77 void setFileFunctionLegend(BoardSide side, Polarity polarity) noexcept;
78 void setFileFunctionPaste(BoardSide side, Polarity polarity) noexcept;
79 void setFileFunctionComponent(int layer, BoardSide side) noexcept;
80 void setLayerPolarity(Polarity p) noexcept;
81 void drawLine(const Point& start, const Point& end,
82 const UnsignedLength& width, Function function,
83 const tl::optional<QString>& net,
84 const QString& component) noexcept;
85 void drawPathOutline(const Path& path, const UnsignedLength& lineWidth,
86 Function function, const tl::optional<QString>& net,
87 const QString& component) noexcept;
88 void drawPathArea(const Path& path, Function function,
89 const tl::optional<QString>& net,
90 const QString& component) noexcept;
91 void drawComponentOutline(const Path& path, const Angle& rot,
92 const QString& designator, const QString& value,
93 MountType mountType, const QString& manufacturer,
94 const QString& mpn, const QString& footprintName,
95 Function function) noexcept;
96 void flashCircle(const Point& pos, const PositiveLength& dia,
97 Function function, const tl::optional<QString>& net,
98 const QString& component, const QString& pin,
99 const QString& signal) noexcept;
100 void flashRect(const Point& pos, const PositiveLength& w,
101 const PositiveLength& h, const UnsignedLength& radius,
102 const Angle& rot, Function function,
103 const tl::optional<QString>& net, const QString& component,
104 const QString& pin, const QString& signal) noexcept;
105 void flashObround(const Point& pos, const PositiveLength& w,
106 const PositiveLength& h, const Angle& rot,
107 Function function, const tl::optional<QString>& net,
108 const QString& component, const QString& pin,
109 const QString& signal) noexcept;
110 void flashOctagon(const Point& pos, const PositiveLength& w,
111 const PositiveLength& h, const UnsignedLength& radius,
112 const Angle& rot, Function function,
113 const tl::optional<QString>& net, const QString& component,
114 const QString& pin, const QString& signal) noexcept;
115 void flashOutline(const Point& pos, const StraightAreaPath& path,
116 const Angle& rot, Function function,
117 const tl::optional<QString>& net, const QString& component,
118 const QString& pin, const QString& signal) noexcept;
119 void flashComponent(const Point& pos, const Angle& rot,
120 const QString& designator, const QString& value,
121 MountType mountType, const QString& manufacturer,
122 const QString& mpn,
123 const QString& footprintName) noexcept;
124 void flashComponentPin(const Point& pos, const Angle& rot,
125 const QString& designator, const QString& value,
126 MountType mountType, const QString& manufacturer,
127 const QString& mpn, const QString& footprintName,
128 const QString& pin, const QString& signal,
129 bool isPin1) noexcept;
130
131 // General Methods
132 void generate();
133 void saveToFile(const FilePath& filepath) const;
134
135 // Operator Overloadings
137
138private:
139 // Private Methods
141 Function apertureFunction, const tl::optional<QString>& netName,
142 const QString& componentDesignator, const QString& pinName,
143 const QString& pinSignal, const QString& componentValue,
144 const tl::optional<MountType>& componentMountType,
145 const QString& componentManufacturer, const QString& componentMpn,
146 const QString& componentFootprint,
147 const tl::optional<Angle>& componentRotation) noexcept;
148 void setCurrentAperture(int number) noexcept;
149 void setRegionModeOn() noexcept;
150 void setRegionModeOff() noexcept;
154 void moveToPosition(const Point& pos) noexcept;
155 void linearInterpolateToPosition(const Point& pos) noexcept;
156 void circularInterpolateToPosition(const Point& start, const Point& center,
157 const Point& end) noexcept;
158 void interpolateBetween(const Vertex& from, const Vertex& to) noexcept;
159 void flashAtPosition(const Point& pos) noexcept;
160 void printHeader() noexcept;
161 void printApertureList() noexcept;
162 void printContent() noexcept;
163 void printFooter() noexcept;
164 QString calcOutputMd5Checksum() const noexcept;
165
166 // Metadata
168
169 // Gerber Data
170 QString mOutput;
171 QString mContent;
175};
176
177/*******************************************************************************
178 * End of File
179 ******************************************************************************/
180
181} // namespace librepcb
182
183#endif
The Angle class is used to represent an angle (for example 12.75 degrees)
Definition: angle.h:78
This class represents absolute, well-formatted paths to files or directories.
Definition: filepath.h:129
A helper class to generate the aperture definitions for a Gerber file.
Definition: gerberaperturelist.h:68
tl::optional< GerberAttribute::ApertureFunction > Function
Definition: gerberaperturelist.h:73
A Gerber X2 attribute.
Definition: gerberattribute.h:43
MountType
Definition: gerberattribute.h:52
BoardSide
Definition: gerberattribute.h:50
Polarity
Definition: gerberattribute.h:49
CopperSide
Definition: gerberattribute.h:51
A helper class to generate Gerber X2 attributes.
Definition: gerberattributewriter.h:45
The GerberGenerator class.
Definition: gerbergenerator.h:51
void setFileFunctionCopper(int layer, CopperSide side, Polarity polarity) noexcept
Definition: gerbergenerator.cpp:73
void saveToFile(const FilePath &filepath) const
Definition: gerbergenerator.cpp:403
GerberAttribute::CopperSide CopperSide
Definition: gerbergenerator.h:58
void flashCircle(const Point &pos, const PositiveLength &dia, Function function, const tl::optional< QString > &net, const QString &component, const QString &pin, const QString &signal) noexcept
Definition: gerbergenerator.cpp:236
void switchToLinearInterpolationModeG01() noexcept
Definition: gerbergenerator.cpp:473
void printApertureList() noexcept
Definition: gerbergenerator.cpp:556
const QString & toStr() const noexcept
Definition: gerbergenerator.h:70
GerberApertureList::Function Function
Definition: gerbergenerator.h:59
int mCurrentApertureNumber
Definition: gerbergenerator.h:174
~GerberGenerator() noexcept
Definition: gerbergenerator.cpp:62
void generate()
Definition: gerbergenerator.cpp:395
GerberGenerator(const GerberGenerator &other)=delete
void linearInterpolateToPosition(const Point &pos) noexcept
Definition: gerbergenerator.cpp:490
void interpolateBetween(const Vertex &from, const Vertex &to) noexcept
Definition: gerbergenerator.cpp:504
void drawPathOutline(const Path &path, const UnsignedLength &lineWidth, Function function, const tl::optional< QString > &net, const QString &component) noexcept
Definition: gerbergenerator.cpp:139
void flashOctagon(const Point &pos, const PositiveLength &w, const PositiveLength &h, const UnsignedLength &radius, const Angle &rot, Function function, const tl::optional< QString > &net, const QString &component, const QString &pin, const QString &signal) noexcept
Definition: gerbergenerator.cpp:303
GerberAttribute::MountType MountType
Definition: gerbergenerator.h:60
void moveToPosition(const Point &pos) noexcept
Definition: gerbergenerator.cpp:485
void switchToCircularCcwInterpolationModeG03() noexcept
Definition: gerbergenerator.cpp:481
void setLayerPolarity(Polarity p) noexcept
Definition: gerbergenerator.cpp:102
void setFileFunctionSolderMask(BoardSide side, Polarity polarity) noexcept
Definition: gerbergenerator.cpp:79
void setFileFunctionComponent(int layer, BoardSide side) noexcept
Definition: gerbergenerator.cpp:97
void drawPathArea(const Path &path, Function function, const tl::optional< QString > &net, const QString &component) noexcept
Definition: gerbergenerator.cpp:169
void setCurrentAperture(int number) noexcept
Definition: gerbergenerator.cpp:458
void printContent() noexcept
Definition: gerbergenerator.cpp:562
GerberGenerator & operator=(const GerberGenerator &rhs)=delete
void flashComponent(const Point &pos, const Angle &rot, const QString &designator, const QString &value, MountType mountType, const QString &manufacturer, const QString &mpn, const QString &footprintName) noexcept
Definition: gerbergenerator.cpp:348
GerberAttribute::BoardSide BoardSide
Definition: gerbergenerator.h:57
QString mContent
Definition: gerbergenerator.h:171
void printFooter() noexcept
Definition: gerbergenerator.cpp:568
QString calcOutputMd5Checksum() const noexcept
Definition: gerbergenerator.cpp:577
void setFileFunctionLegend(BoardSide side, Polarity polarity) noexcept
Definition: gerbergenerator.cpp:85
void flashOutline(const Point &pos, const StraightAreaPath &path, const Angle &rot, Function function, const tl::optional< QString > &net, const QString &component, const QString &pin, const QString &signal) noexcept
Definition: gerbergenerator.cpp:326
void setRegionModeOn() noexcept
Definition: gerbergenerator.cpp:465
void flashAtPosition(const Point &pos) noexcept
Definition: gerbergenerator.cpp:522
void printHeader() noexcept
Definition: gerbergenerator.cpp:527
void flashObround(const Point &pos, const PositiveLength &w, const PositiveLength &h, const Angle &rot, Function function, const tl::optional< QString > &net, const QString &component, const QString &pin, const QString &signal) noexcept
Definition: gerbergenerator.cpp:281
void setFileFunctionOutlines(bool plated) noexcept
Definition: gerbergenerator.cpp:69
void flashRect(const Point &pos, const PositiveLength &w, const PositiveLength &h, const UnsignedLength &radius, const Angle &rot, Function function, const tl::optional< QString > &net, const QString &component, const QString &pin, const QString &signal) noexcept
Definition: gerbergenerator.cpp:258
void setRegionModeOff() noexcept
Definition: gerbergenerator.cpp:469
void flashComponentPin(const Point &pos, const Angle &rot, const QString &designator, const QString &value, MountType mountType, const QString &manufacturer, const QString &mpn, const QString &footprintName, const QString &pin, const QString &signal, bool isPin1) noexcept
Definition: gerbergenerator.cpp:370
void circularInterpolateToPosition(const Point &start, const Point &center, const Point &end) noexcept
Definition: gerbergenerator.cpp:495
void drawLine(const Point &start, const Point &end, const UnsignedLength &width, Function function, const tl::optional< QString > &net, const QString &component) noexcept
Definition: gerbergenerator.cpp:118
void setFileFunctionPaste(BoardSide side, Polarity polarity) noexcept
Definition: gerbergenerator.cpp:91
QString mOutput
Definition: gerbergenerator.h:170
void drawComponentOutline(const Path &path, const Angle &rot, const QString &designator, const QString &value, MountType mountType, const QString &manufacturer, const QString &mpn, const QString &footprintName, Function function) noexcept
Definition: gerbergenerator.cpp:205
QScopedPointer< GerberApertureList > mApertureList
Definition: gerbergenerator.h:173
QVector< GerberAttribute > mFileAttributes
Definition: gerbergenerator.h:167
void setCurrentAttributes(Function apertureFunction, const tl::optional< QString > &netName, const QString &componentDesignator, const QString &pinName, const QString &pinSignal, const QString &componentValue, const tl::optional< MountType > &componentMountType, const QString &componentManufacturer, const QString &componentMpn, const QString &componentFootprint, const tl::optional< Angle > &componentRotation) noexcept
Definition: gerbergenerator.cpp:414
QScopedPointer< GerberAttributeWriter > mAttributeWriter
Definition: gerbergenerator.h:172
GerberAttribute::Polarity Polarity
Definition: gerbergenerator.h:56
void switchToCircularCwInterpolationModeG02() noexcept
Definition: gerbergenerator.cpp:477
The Path class represents a list of vertices connected by straight lines or circular arc segments.
Definition: path.h:58
The Point class is used to represent a point/coordinate/vector, for example (1.2mm; 5....
Definition: point.h:79
The Uuid class is a replacement for QUuid to get UUID strings without {} braces.
Definition: uuid.h:58
The Vertex class.
Definition: vertex.h:44
Definition: occmodel.cpp:77
type_safe::constrained_type< Length, PositiveLengthConstraint, PositiveLengthVerifier > PositiveLength
Definition: length.h:812
type_safe::constrained_type< Length, UnsignedLengthConstraint, UnsignedLengthVerifier > UnsignedLength
Definition: length.h:696
type_safe::constrained_type< Path, StraightAreaPathConstraint, StraightAreaPathVerifier > StraightAreaPath
Definition: path.h:265