LibrePCB Developers Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 
31 #include <QtCore>
32 
33 /*******************************************************************************
34  * Namespace / Forward Declarations
35  ******************************************************************************/
36 namespace librepcb {
37 
38 class Circle;
39 class Path;
40 class GerberApertureList;
41 
42 /*******************************************************************************
43  * Class GerberGenerator
44  ******************************************************************************/
45 
55 class GerberGenerator final {
56  Q_DECLARE_TR_FUNCTIONS(GerberGenerator)
57 
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 };
63 
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;
70 
71  // Getters
72  const QString& toStr() const noexcept { return mOutput; }
73 
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 
95  // General Methods
96  void reset() noexcept;
97  void generate();
98  void saveToFile(const FilePath& filepath) const;
99 
100  // Operator Overloadings
101  GerberGenerator& operator=(const GerberGenerator& rhs) = delete;
102 
103 private:
104  // Private Methods
105  void setCurrentAperture(int number) noexcept;
106  void setRegionModeOn() noexcept;
107  void setRegionModeOff() noexcept;
108  void setMultiQuadrantArcModeOn() noexcept;
109  void setMultiQuadrantArcModeOff() noexcept;
110  void switchToLinearInterpolationModeG01() noexcept;
113  void moveToPosition(const Point& pos) noexcept;
114  void linearInterpolateToPosition(const Point& pos) noexcept;
115  void circularInterpolateToPosition(const Point& start, const Point& center,
116  const Point& end) noexcept;
117  void flashAtPosition(const Point& pos) noexcept;
118  void printHeader() noexcept;
119  void printApertureList() noexcept;
120  void printContent() noexcept;
121  void printFooter() noexcept;
122  QString calcOutputMd5Checksum() const noexcept;
123 
124  // Static Methods
125  static QString escapeString(const QString& str) noexcept;
126 
127  // Metadata
128  QString mProjectId;
131 
132  // Gerber Data
133  QString mOutput;
134  QString mContent;
138 };
139 
140 /*******************************************************************************
141  * End of File
142  ******************************************************************************/
143 
144 } // namespace librepcb
145 
146 #endif // LIBREPCB_GERBERGENERATOR_H
LayerPolarity
Definition: gerbergenerator.h:62
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:133
void printApertureList() noexcept
Definition: gerbergenerator.cpp:322
void drawPathArea(const Path &path) noexcept
Definition: gerbergenerator.cpp:128
Uuid mProjectUuid
Definition: gerbergenerator.h:129
The Angle class is used to represent an angle (for example 12.75 degrees)
Definition: angle.h:81
~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:81
void moveToPosition(const Point &pos) noexcept
Definition: gerbergenerator.cpp:259
QString mProjectRevision
Definition: gerbergenerator.h:130
QString mProjectId
Definition: gerbergenerator.h:128
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:76
This class represents absolute, well-formatted paths to files or directories.
Definition: filepath.h:130
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:137
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:72
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:136
void printFooter() noexcept
Definition: gerbergenerator.cpp:332
QString mContent
Definition: gerbergenerator.h:134
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:135
void setRegionModeOn() noexcept
Definition: gerbergenerator.cpp:225
The GerberApertureList class.
Definition: gerberaperturelist.h:48
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:662