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_GERBERGENERATOR_H
21 #define LIBREPCB_GERBERGENERATOR_H
22 
23 /*******************************************************************************
24  * Includes
25  ******************************************************************************/
26 #include "../exceptions.h"
27 #include "../fileio/filepath.h"
28 #include "../units/all_length_units.h"
29 #include "../uuid.h"
30 #include "gerberaperturelist.h"
31 #include "gerberattribute.h"
32 
33 #include <QtCore>
34 
35 /*******************************************************************************
36  * Namespace / Forward Declarations
37  ******************************************************************************/
38 namespace librepcb {
39 
40 class Path;
41 class GerberAttributeWriter;
42 
43 /*******************************************************************************
44  * Class GerberGenerator
45  ******************************************************************************/
46 
50 class GerberGenerator final {
51  Q_DECLARE_TR_FUNCTIONS(GerberGenerator)
52 
53 public:
54  // Public Types
59 
60  // Constructors / Destructor
61  GerberGenerator() = delete;
62  GerberGenerator(const GerberGenerator& other) = delete;
63  GerberGenerator(const QDateTime& creationDate, const QString& projName,
64  const Uuid& projUuid, const QString& projRevision) noexcept;
65  ~GerberGenerator() noexcept;
66 
67  // Getters
68  const QString& toStr() const noexcept { return mOutput; }
69 
70  // Plot Methods
71  void setFileFunctionOutlines(bool plated) noexcept;
72  void setFileFunctionCopper(int layer, CopperSide side,
73  Polarity polarity) noexcept;
74  void setFileFunctionSolderMask(BoardSide side, Polarity polarity) noexcept;
75  void setFileFunctionLegend(BoardSide side, Polarity polarity) noexcept;
76  void setFileFunctionPaste(BoardSide side, Polarity polarity) noexcept;
77  void setLayerPolarity(Polarity p) noexcept;
78  void drawLine(const Point& start, const Point& end,
79  const UnsignedLength& width, Function function,
80  const tl::optional<QString>& net,
81  const QString& component) noexcept;
82  void drawPathOutline(const Path& path, const UnsignedLength& lineWidth,
83  Function function, const tl::optional<QString>& net,
84  const QString& component) noexcept;
85  void drawPathArea(const Path& path, Function function,
86  const tl::optional<QString>& net,
87  const QString& component) noexcept;
88  void flashCircle(const Point& pos, const PositiveLength& dia,
89  Function function, const tl::optional<QString>& net,
90  const QString& component, const QString& pin,
91  const QString& signal) noexcept;
92  void flashRect(const Point& pos, const PositiveLength& w,
93  const PositiveLength& h, const Angle& rot, Function function,
94  const tl::optional<QString>& net, const QString& component,
95  const QString& pin, const QString& signal) noexcept;
96  void flashObround(const Point& pos, const PositiveLength& w,
97  const PositiveLength& h, const Angle& rot,
98  Function function, const tl::optional<QString>& net,
99  const QString& component, const QString& pin,
100  const QString& signal) noexcept;
101  void flashOctagon(const Point& pos, const PositiveLength& w,
102  const PositiveLength& h, const Angle& rot,
103  Function function, const tl::optional<QString>& net,
104  const QString& component, const QString& pin,
105  const QString& signal) noexcept;
106 
107  // General Methods
108  void generate();
109  void saveToFile(const FilePath& filepath) const;
110 
111  // Operator Overloadings
112  GerberGenerator& operator=(const GerberGenerator& rhs) = delete;
113 
114 private:
115  // Private Methods
116  void setCurrentAttributes(Function apertureFunction,
117  const tl::optional<QString>& netName,
118  const QString& componentDesignator,
119  const QString& pinName,
120  const QString& pinSignal) noexcept;
121  void setCurrentAperture(int number) noexcept;
122  void setRegionModeOn() noexcept;
123  void setRegionModeOff() noexcept;
124  void switchToLinearInterpolationModeG01() noexcept;
127  void moveToPosition(const Point& pos) noexcept;
128  void linearInterpolateToPosition(const Point& pos) noexcept;
129  void circularInterpolateToPosition(const Point& start, const Point& center,
130  const Point& end) noexcept;
131  void interpolateBetween(const Vertex& from, const Vertex& to) noexcept;
132  void flashAtPosition(const Point& pos) noexcept;
133  void printHeader() noexcept;
134  void printApertureList() noexcept;
135  void printContent() noexcept;
136  void printFooter() noexcept;
137  QString calcOutputMd5Checksum() const noexcept;
138 
139  // Metadata
140  QVector<GerberAttribute> mFileAttributes;
141 
142  // Gerber Data
143  QString mOutput;
144  QString mContent;
145  QScopedPointer<GerberAttributeWriter> mAttributeWriter;
146  QScopedPointer<GerberApertureList> mApertureList;
148 };
149 
150 /*******************************************************************************
151  * End of File
152  ******************************************************************************/
153 
154 } // namespace librepcb
155 
156 #endif
QScopedPointer< GerberAttributeWriter > mAttributeWriter
Definition: gerbergenerator.h:145
void setFileFunctionSolderMask(BoardSide side, Polarity polarity) noexcept
Definition: gerbergenerator.cpp:78
QVector< GerberAttribute > mFileAttributes
Definition: gerbergenerator.h:140
void printContent() noexcept
Definition: gerbergenerator.cpp:390
The Vertex class.
Definition: vertex.h:43
void flashRect(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:195
void setCurrentAperture(int number) noexcept
Definition: gerbergenerator.cpp:285
void saveToFile(const FilePath &filepath) const
Definition: gerbergenerator.cpp:255
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:211
QString calcOutputMd5Checksum() const noexcept
Definition: gerbergenerator.cpp:405
void flashAtPosition(const Point &pos) noexcept
Definition: gerbergenerator.cpp:350
void switchToCircularCcwInterpolationModeG03() noexcept
Definition: gerbergenerator.cpp:308
Definition: airwiresbuilder.cpp:32
void setRegionModeOff() noexcept
Definition: gerbergenerator.cpp:296
void printHeader() noexcept
Definition: gerbergenerator.cpp:355
QString mOutput
Definition: gerbergenerator.h:143
Polarity
Definition: gerberattribute.h:48
void printApertureList() noexcept
Definition: gerbergenerator.cpp:384
The Angle class is used to represent an angle (for example 12.75 degrees)
Definition: angle.h:78
GerberGenerator & operator=(const GerberGenerator &rhs)=delete
~GerberGenerator() noexcept
Definition: gerbergenerator.cpp:61
void setLayerPolarity(Polarity p) noexcept
Definition: gerbergenerator.cpp:96
void setFileFunctionOutlines(bool plated) noexcept
Definition: gerbergenerator.cpp:68
CopperSide
Definition: gerberattribute.h:50
void flashOctagon(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:227
void setFileFunctionCopper(int layer, CopperSide side, Polarity polarity) noexcept
Definition: gerbergenerator.cpp:72
void setFileFunctionLegend(BoardSide side, Polarity polarity) noexcept
Definition: gerbergenerator.cpp:84
The Point class is used to represent a point/coordinate/vector, for example (1.2mm; 5...
Definition: point.h:78
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:110
void moveToPosition(const Point &pos) noexcept
Definition: gerbergenerator.cpp:312
void drawPathArea(const Path &path, Function function, const tl::optional< QString > &net, const QString &component) noexcept
Definition: gerbergenerator.cpp:149
tl::optional< GerberAttribute::ApertureFunction > Function
Definition: gerberaperturelist.h:72
void generate()
Definition: gerbergenerator.cpp:247
void circularInterpolateToPosition(const Point &start, const Point &center, const Point &end) noexcept
Definition: gerbergenerator.cpp:322
This class represents absolute, well-formatted paths to files or directories.
Definition: filepath.h:127
void linearInterpolateToPosition(const Point &pos) noexcept
Definition: gerbergenerator.cpp:317
void drawPathOutline(const Path &path, const UnsignedLength &lineWidth, Function function, const tl::optional< QString > &net, const QString &component) noexcept
Definition: gerbergenerator.cpp:125
GerberApertureList::Function Function
Definition: gerbergenerator.h:58
void switchToCircularCwInterpolationModeG02() noexcept
Definition: gerbergenerator.cpp:304
The Path class represents a list of vertices connected by straight lines or circular arc segments...
Definition: path.h:53
BoardSide
Definition: gerberattribute.h:49
const QString & toStr() const noexcept
Definition: gerbergenerator.h:68
type_safe::constrained_type< Length, PositiveLengthConstraint, PositiveLengthVerifier > PositiveLength
Definition: length.h:792
int mCurrentApertureNumber
Definition: gerbergenerator.h:147
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:179
void interpolateBetween(const Vertex &from, const Vertex &to) noexcept
Definition: gerbergenerator.cpp:331
void printFooter() noexcept
Definition: gerbergenerator.cpp:396
QString mContent
Definition: gerbergenerator.h:144
The Uuid class is a replacement for QUuid to get UUID strings without {} braces.
Definition: uuid.h:58
void setCurrentAttributes(Function apertureFunction, const tl::optional< QString > &netName, const QString &componentDesignator, const QString &pinName, const QString &pinSignal) noexcept
Definition: gerbergenerator.cpp:263
void setFileFunctionPaste(BoardSide side, Polarity polarity) noexcept
Definition: gerbergenerator.cpp:90
The GerberGenerator class.
Definition: gerbergenerator.h:50
QScopedPointer< GerberApertureList > mApertureList
Definition: gerbergenerator.h:146
void setRegionModeOn() noexcept
Definition: gerbergenerator.cpp:292
void switchToLinearInterpolationModeG01() noexcept
Definition: gerbergenerator.cpp:300
type_safe::constrained_type< Length, UnsignedLengthConstraint, UnsignedLengthVerifier > UnsignedLength
Definition: length.h:672