LibrePCB Developers Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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  ******************************************************************************/
53 class GerberGenerator final {
54  Q_DECLARE_TR_FUNCTIONS(GerberGenerator)
56 public:
57  // Public Types
58  // enum class FileFunction {Copper, SolderMask, Glue, Paste, KeepOut, Plated,
59  // NonPlated, Profile, DrillMap};
60  enum class LayerPolarity { Positive, Negative };
62  // Constructors / Destructor
63  GerberGenerator() = delete;
64  GerberGenerator(const GerberGenerator& other) = delete;
65  GerberGenerator(const QString& projName, const Uuid& projUuid,
66  const QString& projRevision) noexcept;
67  ~GerberGenerator() noexcept;
69  // Getters
70  const QString& toStr() const noexcept { return mOutput; }
72  // Plot Methods
73  void setLayerPolarity(LayerPolarity p) noexcept;
74  void drawLine(const Point& start, const Point& end,
75  const UnsignedLength& width) noexcept;
76  void drawCircleOutline(const Circle& circle) noexcept;
77  void drawCircleArea(const Circle& circle) noexcept;
78  void drawPathOutline(const Path& path,
79  const UnsignedLength& lineWidth) noexcept;
80  void drawPathArea(const Path& path) noexcept;
81  void flashCircle(const Point& pos, const UnsignedLength& dia,
82  const UnsignedLength& hole) noexcept;
83  void flashRect(const Point& pos, const UnsignedLength& w,
84  const UnsignedLength& h, const Angle& rot,
85  const UnsignedLength& hole) noexcept;
86  void flashObround(const Point& pos, const UnsignedLength& w,
87  const UnsignedLength& h, const Angle& rot,
88  const UnsignedLength& hole) noexcept;
89  void flashRegularPolygon(const Point& pos, const UnsignedLength& dia, int n,
90  const Angle& rot,
91  const UnsignedLength& hole) noexcept;
92  void flashOctagon(const Point& pos, const UnsignedLength& w,
93  const UnsignedLength& h, const UnsignedLength& edge,
94  const Angle& rot, const UnsignedLength& hole) noexcept;
96  // General Methods
97  void reset() noexcept;
98  void generate();
99  void saveToFile(const FilePath& filepath) const;
101  // Operator Overloadings
102  GerberGenerator& operator=(const GerberGenerator& rhs) = delete;
104 private:
105  // Private Methods
106  void setCurrentAperture(int number) noexcept;
107  void setRegionModeOn() noexcept;
108  void setRegionModeOff() noexcept;
109  void setMultiQuadrantArcModeOn() noexcept;
110  void setMultiQuadrantArcModeOff() noexcept;
111  void switchToLinearInterpolationModeG01() noexcept;
114  void moveToPosition(const Point& pos) noexcept;
115  void linearInterpolateToPosition(const Point& pos) noexcept;
116  void circularInterpolateToPosition(const Point& start, const Point& center,
117  const Point& end) noexcept;
118  void interpolateBetween(const Vertex& from, const Vertex& to) noexcept;
119  void flashAtPosition(const Point& pos) noexcept;
120  void printHeader() noexcept;
121  void printApertureList() noexcept;
122  void printContent() noexcept;
123  void printFooter() noexcept;
124  QString calcOutputMd5Checksum() const noexcept;
126  // Static Methods
127  static QString escapeString(const QString& str) noexcept;
129  // Metadata
130  QString mProjectId;
134  // Gerber Data
135  QString mOutput;
136  QString mContent;
140 };
142 /*******************************************************************************
143  * End of File
144  ******************************************************************************/
146 } // namespace librepcb
Definition: gerbergenerator.h:60
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
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
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:135
void printApertureList() noexcept
Definition: gerbergenerator.cpp:315
void drawPathArea(const Path &path) noexcept
Definition: gerbergenerator.cpp:110
Uuid mProjectUuid
Definition: gerbergenerator.h:131
The Angle class is used to represent an angle (for example 12.75 degrees)
Definition: angle.h:78
~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:132
QString mProjectId
Definition: gerbergenerator.h:130
void generate()
Definition: gerbergenerator.cpp:174
void saveToFile(const FilePath &filepath) const
Definition: gerbergenerator.cpp:182
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:139
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:70
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:138
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:136
The Uuid class is a replacement for QUuid to get UUID strings without {} braces.
Definition: uuid.h:58
The GerberGenerator class.
Definition: gerbergenerator.h:53
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:137
void setRegionModeOn() noexcept
Definition: gerbergenerator.cpp:197
The GerberApertureList class.
Definition: gerberaperturelist.h:45
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:659