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_CORE_GERBERGENERATOR_H
21 #define LIBREPCB_CORE_GERBERGENERATOR_H
22 
23 /*******************************************************************************
24  * Includes
25  ******************************************************************************/
26 #include "../fileio/filepath.h"
27 #include "../types/length.h"
28 #include "../types/uuid.h"
29 #include "gerberaperturelist.h"
30 #include "gerberattribute.h"
31 
32 #include <QtCore>
33 
34 /*******************************************************************************
35  * Namespace / Forward Declarations
36  ******************************************************************************/
37 namespace librepcb {
38 
39 class Angle;
40 class GerberAttributeWriter;
41 class Path;
42 class Point;
43 
44 /*******************************************************************************
45  * Class GerberGenerator
46  ******************************************************************************/
47 
51 class GerberGenerator final {
52  Q_DECLARE_TR_FUNCTIONS(GerberGenerator)
53 
54 public:
55  // Public Types
60 
61  // Constructors / Destructor
62  GerberGenerator() = delete;
63  GerberGenerator(const GerberGenerator& other) = delete;
64  GerberGenerator(const QDateTime& creationDate, const QString& projName,
65  const Uuid& projUuid, const QString& projRevision) noexcept;
66  ~GerberGenerator() noexcept;
67 
68  // Getters
69  const QString& toStr() const noexcept { return mOutput; }
70 
71  // Plot Methods
72  void setFileFunctionOutlines(bool plated) noexcept;
73  void setFileFunctionCopper(int layer, CopperSide side,
74  Polarity polarity) noexcept;
75  void setFileFunctionSolderMask(BoardSide side, Polarity polarity) noexcept;
76  void setFileFunctionLegend(BoardSide side, Polarity polarity) noexcept;
77  void setFileFunctionPaste(BoardSide side, Polarity polarity) noexcept;
78  void setLayerPolarity(Polarity p) noexcept;
79  void drawLine(const Point& start, const Point& end,
80  const UnsignedLength& width, Function function,
81  const tl::optional<QString>& net,
82  const QString& component) noexcept;
83  void drawPathOutline(const Path& path, const UnsignedLength& lineWidth,
84  Function function, const tl::optional<QString>& net,
85  const QString& component) noexcept;
86  void drawPathArea(const Path& path, Function function,
87  const tl::optional<QString>& net,
88  const QString& component) noexcept;
89  void flashCircle(const Point& pos, const PositiveLength& dia,
90  Function function, const tl::optional<QString>& net,
91  const QString& component, const QString& pin,
92  const QString& signal) noexcept;
93  void flashRect(const Point& pos, const PositiveLength& w,
94  const PositiveLength& h, const Angle& rot, Function function,
95  const tl::optional<QString>& net, const QString& component,
96  const QString& pin, const QString& signal) noexcept;
97  void flashObround(const Point& pos, const PositiveLength& w,
98  const PositiveLength& h, const Angle& rot,
99  Function function, const tl::optional<QString>& net,
100  const QString& component, const QString& pin,
101  const QString& signal) noexcept;
102  void flashOctagon(const Point& pos, const PositiveLength& w,
103  const PositiveLength& h, const Angle& rot,
104  Function function, const tl::optional<QString>& net,
105  const QString& component, const QString& pin,
106  const QString& signal) noexcept;
107 
108  // General Methods
109  void generate();
110  void saveToFile(const FilePath& filepath) const;
111 
112  // Operator Overloadings
113  GerberGenerator& operator=(const GerberGenerator& rhs) = delete;
114 
115 private:
116  // Private Methods
117  void setCurrentAttributes(Function apertureFunction,
118  const tl::optional<QString>& netName,
119  const QString& componentDesignator,
120  const QString& pinName,
121  const QString& pinSignal) noexcept;
122  void setCurrentAperture(int number) noexcept;
123  void setRegionModeOn() noexcept;
124  void setRegionModeOff() noexcept;
125  void switchToLinearInterpolationModeG01() noexcept;
128  void moveToPosition(const Point& pos) noexcept;
129  void linearInterpolateToPosition(const Point& pos) noexcept;
130  void circularInterpolateToPosition(const Point& start, const Point& center,
131  const Point& end) noexcept;
132  void interpolateBetween(const Vertex& from, const Vertex& to) noexcept;
133  void flashAtPosition(const Point& pos) noexcept;
134  void printHeader() noexcept;
135  void printApertureList() noexcept;
136  void printContent() noexcept;
137  void printFooter() noexcept;
138  QString calcOutputMd5Checksum() const noexcept;
139 
140  // Metadata
141  QVector<GerberAttribute> mFileAttributes;
142 
143  // Gerber Data
144  QString mOutput;
145  QString mContent;
146  QScopedPointer<GerberAttributeWriter> mAttributeWriter;
147  QScopedPointer<GerberApertureList> mApertureList;
149 };
150 
151 /*******************************************************************************
152  * End of File
153  ******************************************************************************/
154 
155 } // namespace librepcb
156 
157 #endif
QScopedPointer< GerberAttributeWriter > mAttributeWriter
Definition: gerbergenerator.h:146
void setFileFunctionSolderMask(BoardSide side, Polarity polarity) noexcept
Definition: gerbergenerator.cpp:78
QVector< GerberAttribute > mFileAttributes
Definition: gerbergenerator.h:141
void printContent() noexcept
Definition: gerbergenerator.cpp:390
The Vertex class.
Definition: vertex.h:44
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:34
void setRegionModeOff() noexcept
Definition: gerbergenerator.cpp:296
void printHeader() noexcept
Definition: gerbergenerator.cpp:355
QString mOutput
Definition: gerbergenerator.h:144
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:73
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:59
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:69
type_safe::constrained_type< Length, PositiveLengthConstraint, PositiveLengthVerifier > PositiveLength
Definition: length.h:793
int mCurrentApertureNumber
Definition: gerbergenerator.h:148
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:145
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:51
QScopedPointer< GerberApertureList > mApertureList
Definition: gerbergenerator.h:147
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:673