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;
42 /*******************************************************************************
43  * Class GerberGenerator
44  ******************************************************************************/
52 class GerberGenerator final {
53  Q_DECLARE_TR_FUNCTIONS(GerberGenerator)
55 public:
56  // Public Types
57  // enum class FileFunction {Copper, SolderMask, Glue, Paste, KeepOut, Plated,
58  // NonPlated, Profile, DrillMap};
59  enum class LayerPolarity { Positive, Negative };
61  // Constructors / Destructor
62  GerberGenerator() = delete;
63  GerberGenerator(const GerberGenerator& other) = delete;
64  GerberGenerator(const QString& projName, const Uuid& projUuid,
65  const QString& projRevision) noexcept;
66  ~GerberGenerator() noexcept;
68  // Getters
69  const QString& toStr() const noexcept { return mOutput; }
71  // Plot Methods
72  void setLayerPolarity(LayerPolarity p) noexcept;
73  void drawLine(const Point& start, const Point& end,
74  const UnsignedLength& width) noexcept;
75  void drawCircleOutline(const Circle& circle) noexcept;
76  void drawCircleArea(const Circle& circle) noexcept;
77  void drawPathOutline(const Path& path,
78  const UnsignedLength& lineWidth) noexcept;
79  void drawPathArea(const Path& path) noexcept;
80  void flashCircle(const Point& pos, const UnsignedLength& dia,
81  const UnsignedLength& hole) noexcept;
82  void flashRect(const Point& pos, const UnsignedLength& w,
83  const UnsignedLength& h, const Angle& rot,
84  const UnsignedLength& hole) noexcept;
85  void flashObround(const Point& pos, const UnsignedLength& w,
86  const UnsignedLength& h, const Angle& rot,
87  const UnsignedLength& hole) noexcept;
88  void flashRegularPolygon(const Point& pos, const UnsignedLength& dia, int n,
89  const Angle& rot,
90  const UnsignedLength& hole) noexcept;
92  // General Methods
93  void reset() noexcept;
94  void generate();
95  void saveToFile(const FilePath& filepath) const;
97  // Operator Overloadings
98  GerberGenerator& operator=(const GerberGenerator& rhs) = delete;
100 private:
101  // Private Methods
102  void setCurrentAperture(int number) noexcept;
103  void setRegionModeOn() noexcept;
104  void setRegionModeOff() noexcept;
105  void setMultiQuadrantArcModeOn() noexcept;
106  void setMultiQuadrantArcModeOff() noexcept;
107  void switchToLinearInterpolationModeG01() noexcept;
110  void moveToPosition(const Point& pos) noexcept;
111  void linearInterpolateToPosition(const Point& pos) noexcept;
112  void circularInterpolateToPosition(const Point& start, const Point& center,
113  const Point& end) noexcept;
114  void flashAtPosition(const Point& pos) noexcept;
115  void printHeader() noexcept;
116  void printApertureList() noexcept;
117  void printContent() noexcept;
118  void printFooter() noexcept;
119  QString calcOutputMd5Checksum() const noexcept;
121  // Static Methods
122  static QString escapeString(const QString& str) noexcept;
124  // Metadata
125  QString mProjectId;
129  // Gerber Data
130  QString mOutput;
131  QString mContent;
135 };
137 /*******************************************************************************
138  * End of File
139  ******************************************************************************/
141 } // namespace librepcb
Definition: gerbergenerator.h:59
void printContent() noexcept
Definition: gerbergenerator.cpp:326
void setCurrentAperture(int number) noexcept
Definition: gerbergenerator.cpp:218
void drawCircleOutline(const Circle &circle) noexcept
Definition: gerbergenerator.cpp:82
QString calcOutputMd5Checksum() const noexcept
Definition: gerbergenerator.cpp:340
void flashAtPosition(const Point &pos) noexcept
Definition: gerbergenerator.cpp:281
void switchToCircularCcwInterpolationModeG03() noexcept
Definition: gerbergenerator.cpp:255
void flashCircle(const Point &pos, const UnsignedLength &dia, const UnsignedLength &hole) noexcept
Definition: gerbergenerator.cpp:163
void setRegionModeOff() noexcept
Definition: gerbergenerator.cpp:229
void printHeader() noexcept
Definition: gerbergenerator.cpp:286
QString mOutput
Definition: gerbergenerator.h:130
void printApertureList() noexcept
Definition: gerbergenerator.cpp:322
void drawPathArea(const Path &path) noexcept
Definition: gerbergenerator.cpp:128
Uuid mProjectUuid
Definition: gerbergenerator.h:126
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:259
QString mProjectRevision
Definition: gerbergenerator.h:127
QString mProjectId
Definition: gerbergenerator.h:125
void generate()
Definition: gerbergenerator.cpp:202
void saveToFile(const FilePath &filepath) const
Definition: gerbergenerator.cpp:210
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:269
void setMultiQuadrantArcModeOff() noexcept
Definition: gerbergenerator.cpp:240
void reset() noexcept
Definition: gerbergenerator.cpp:195
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:169
bool mMultiQuadrantArcModeOn
Definition: gerbergenerator.h:134
void linearInterpolateToPosition(const Point &pos) noexcept
Definition: gerbergenerator.cpp:264
void switchToCircularCwInterpolationModeG02() noexcept
Definition: gerbergenerator.cpp:251
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:176
const QString & toStr() const noexcept
Definition: gerbergenerator.h:69
void setLayerPolarity(LayerPolarity p) noexcept
Definition: gerbergenerator.cpp:61
static QString escapeString(const QString &str) noexcept
Definition: gerbergenerator.cpp:352
int mCurrentApertureNumber
Definition: gerbergenerator.h:133
void printFooter() noexcept
Definition: gerbergenerator.cpp:332
QString mContent
Definition: gerbergenerator.h:131
The Uuid class is a replacement for QUuid to get UUID strings without {} braces.
Definition: uuid.h:58
The GerberGenerator class.
Definition: gerbergenerator.h:52
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:132
void setRegionModeOn() noexcept
Definition: gerbergenerator.cpp:225
The GerberApertureList class.
Definition: gerberaperturelist.h:45
void switchToLinearInterpolationModeG01() noexcept
Definition: gerbergenerator.cpp:247
void setMultiQuadrantArcModeOn() noexcept
Definition: gerbergenerator.cpp:233
void flashRegularPolygon(const Point &pos, const UnsignedLength &dia, int n, const Angle &rot, const UnsignedLength &hole) noexcept
Definition: gerbergenerator.cpp:183
type_safe::constrained_type< Length, UnsignedLengthConstraint, UnsignedLengthVerifier > UnsignedLength
Definition: length.h:659