LibrePCB Developers Documentation
Go to the documentation of this file.
1 /*
2  * LibrePCB - Professional EDA for everyone!
3  * Copyright (C) 2013 LibrePCB Developers, see for contributors.
4  *
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
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 <>.
18  */
23 /*******************************************************************************
24  * Includes
25  ******************************************************************************/
26 #include "../exceptions.h"
27 #include "../fileio/filepath.h"
28 #include "../units/all_length_units.h"
29 #include "../uuid.h"
31 #include <QtCore>
33 /*******************************************************************************
34  * Namespace / Forward Declarations
35  ******************************************************************************/
36 namespace librepcb {
38 class Circle;
39 class Path;
40 class GerberApertureList;
41 class Vertex;
43 /*******************************************************************************
44  * Class GerberGenerator
45  ******************************************************************************/
55 class GerberGenerator final {
56  Q_DECLARE_TR_FUNCTIONS(GerberGenerator)
58 public:
59  // Public Types
60  // enum class FileFunction {Copper, SolderMask, Glue, Paste, KeepOut, Plated,
61  // NonPlated, Profile, DrillMap};
62  enum class LayerPolarity { Positive, Negative };
64  // Constructors / Destructor
65  GerberGenerator() = delete;
66  GerberGenerator(const GerberGenerator& other) = delete;
67  GerberGenerator(const QString& projName, const Uuid& projUuid,
68  const QString& projRevision) noexcept;
69  ~GerberGenerator() noexcept;
71  // Getters
72  const QString& toStr() const noexcept { return mOutput; }
74  // Plot Methods
75  void setLayerPolarity(LayerPolarity p) noexcept;
76  void drawLine(const Point& start, const Point& end,
77  const UnsignedLength& width) noexcept;
78  void drawCircleOutline(const Circle& circle) noexcept;
79  void drawCircleArea(const Circle& circle) noexcept;
80  void drawPathOutline(const Path& path,
81  const UnsignedLength& lineWidth) noexcept;
82  void drawPathArea(const Path& path) noexcept;
83  void flashCircle(const Point& pos, const UnsignedLength& dia,
84  const UnsignedLength& hole) noexcept;
85  void flashRect(const Point& pos, const UnsignedLength& w,
86  const UnsignedLength& h, const Angle& rot,
87  const UnsignedLength& hole) noexcept;
88  void flashObround(const Point& pos, const UnsignedLength& w,
89  const UnsignedLength& h, const Angle& rot,
90  const UnsignedLength& hole) noexcept;
91  void flashRegularPolygon(const Point& pos, const UnsignedLength& dia, int n,
92  const Angle& rot,
93  const UnsignedLength& hole) noexcept;
94  void flashOctagon(const Point& pos, const UnsignedLength& w,
95  const UnsignedLength& h, const UnsignedLength& edge,
96  const Angle& rot, const UnsignedLength& hole) noexcept;
98  // General Methods
99  void reset() noexcept;
100  void generate();
101  void saveToFile(const FilePath& filepath) const;
103  // Operator Overloadings
104  GerberGenerator& operator=(const GerberGenerator& rhs) = delete;
106 private:
107  // Private Methods
108  void setCurrentAperture(int number) noexcept;
109  void setRegionModeOn() noexcept;
110  void setRegionModeOff() noexcept;
111  void setMultiQuadrantArcModeOn() noexcept;
112  void setMultiQuadrantArcModeOff() noexcept;
113  void switchToLinearInterpolationModeG01() noexcept;
116  void moveToPosition(const Point& pos) noexcept;
117  void linearInterpolateToPosition(const Point& pos) noexcept;
118  void circularInterpolateToPosition(const Point& start, const Point& center,
119  const Point& end) noexcept;
120  void interpolateBetween(const Vertex& from, const Vertex& to) noexcept;
121  void flashAtPosition(const Point& pos) noexcept;
122  void printHeader() noexcept;
123  void printApertureList() noexcept;
124  void printContent() noexcept;
125  void printFooter() noexcept;
126  QString calcOutputMd5Checksum() const noexcept;
128  // Static Methods
129  static QString escapeString(const QString& str) noexcept;
131  // Metadata
132  QString mProjectId;
136  // Gerber Data
137  QString mOutput;
138  QString mContent;
139  QScopedPointer<GerberApertureList> mApertureList;
142 };
144 /*******************************************************************************
145  * End of File
146  ******************************************************************************/
148 } // namespace librepcb
Definition: gerbergenerator.h:62
void printContent() noexcept
Definition: gerbergenerator.cpp:319
The Vertex class.
Definition: vertex.h:43
void setCurrentAperture(int number) noexcept
Definition: gerbergenerator.cpp:190
void drawCircleOutline(const Circle &circle) noexcept
Definition: gerbergenerator.cpp:82
void saveToFile(const FilePath &filepath) const
Definition: gerbergenerator.cpp:182
QString calcOutputMd5Checksum() const noexcept
Definition: gerbergenerator.cpp:333
void flashAtPosition(const Point &pos) noexcept
Definition: gerbergenerator.cpp:274
void switchToCircularCcwInterpolationModeG03() noexcept
Definition: gerbergenerator.cpp:227
Definition: airwiresbuilder.cpp:32
void flashCircle(const Point &pos, const UnsignedLength &dia, const UnsignedLength &hole) noexcept
Definition: gerbergenerator.cpp:127
void setRegionModeOff() noexcept
Definition: gerbergenerator.cpp:201
void printHeader() noexcept
Definition: gerbergenerator.cpp:279
QString mOutput
Definition: gerbergenerator.h:137
void printApertureList() noexcept
Definition: gerbergenerator.cpp:315
void drawPathArea(const Path &path) noexcept
Definition: gerbergenerator.cpp:110
Uuid mProjectUuid
Definition: gerbergenerator.h:133
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:54
The Point class is used to represent a point/coordinate/vector, for example (1.2mm; 5...
Definition: point.h:78
void moveToPosition(const Point &pos) noexcept
Definition: gerbergenerator.cpp:231
QString mProjectRevision
Definition: gerbergenerator.h:134
QString mProjectId
Definition: gerbergenerator.h:132
void generate()
Definition: gerbergenerator.cpp:174
void drawPathOutline(const Path &path, const UnsignedLength &lineWidth) noexcept
Definition: gerbergenerator.cpp:95
void circularInterpolateToPosition(const Point &start, const Point &center, const Point &end) noexcept
Definition: gerbergenerator.cpp:241
void setMultiQuadrantArcModeOff() noexcept
Definition: gerbergenerator.cpp:212
void reset() noexcept
Definition: gerbergenerator.cpp:167
void flashOctagon(const Point &pos, const UnsignedLength &w, const UnsignedLength &h, const UnsignedLength &edge, const Angle &rot, const UnsignedLength &hole) noexcept
Definition: gerbergenerator.cpp:155
The Circle class.
Definition: circle.h:47
This class represents absolute, well-formatted paths to files or directories.
Definition: filepath.h:127
void flashRect(const Point &pos, const UnsignedLength &w, const UnsignedLength &h, const Angle &rot, const UnsignedLength &hole) noexcept
Definition: gerbergenerator.cpp:133
bool mMultiQuadrantArcModeOn
Definition: gerbergenerator.h:141
void linearInterpolateToPosition(const Point &pos) noexcept
Definition: gerbergenerator.cpp:236
void switchToCircularCwInterpolationModeG02() noexcept
Definition: gerbergenerator.cpp:223
The Path class represents a list of vertices connected by straight lines or circular arc segments...
Definition: path.h:53
void flashObround(const Point &pos, const UnsignedLength &w, const UnsignedLength &h, const Angle &rot, const UnsignedLength &hole) noexcept
Definition: gerbergenerator.cpp:140
const QString & toStr() const noexcept
Definition: gerbergenerator.h:72
void setLayerPolarity(LayerPolarity p) noexcept
Definition: gerbergenerator.cpp:61
static QString escapeString(const QString &str) noexcept
Definition: gerbergenerator.cpp:345
int mCurrentApertureNumber
Definition: gerbergenerator.h:140
void interpolateBetween(const Vertex &from, const Vertex &to) noexcept
Definition: gerbergenerator.cpp:253
void printFooter() noexcept
Definition: gerbergenerator.cpp:325
QString mContent
Definition: gerbergenerator.h:138
The Uuid class is a replacement for QUuid to get UUID strings without {} braces.
Definition: uuid.h:58
The GerberGenerator class.
Definition: gerbergenerator.h:55
void drawCircleArea(const Circle &circle) noexcept
Definition: gerbergenerator.cpp:90
void drawLine(const Point &start, const Point &end, const UnsignedLength &width) noexcept
Definition: gerbergenerator.cpp:75
QScopedPointer< GerberApertureList > mApertureList
Definition: gerbergenerator.h:139
void setRegionModeOn() noexcept
Definition: gerbergenerator.cpp:197
void switchToLinearInterpolationModeG01() noexcept
Definition: gerbergenerator.cpp:219
void setMultiQuadrantArcModeOn() noexcept
Definition: gerbergenerator.cpp:205
void flashRegularPolygon(const Point &pos, const UnsignedLength &dia, int n, const Angle &rot, const UnsignedLength &hole) noexcept
Definition: gerbergenerator.cpp:147
type_safe::constrained_type< Length, UnsignedLengthConstraint, UnsignedLengthVerifier > UnsignedLength
Definition: length.h:673