LibrePCB Developers Documentation
boardgerberexport.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_BOARDGERBEREXPORT_H
21 #define LIBREPCB_CORE_BOARDGERBEREXPORT_H
22 
23 /*******************************************************************************
24  * Includes
25  ******************************************************************************/
26 #include "../../export/excellongenerator.h"
27 #include "../../export/gerbergenerator.h"
28 #include "../../fileio/filepath.h"
29 #include "../../types/length.h"
30 
31 #include <optional/tl/optional.hpp>
32 
33 #include <QtCore>
34 
35 #include <functional>
36 #include <memory>
37 
38 /*******************************************************************************
39  * Namespace / Forward Declarations
40  ******************************************************************************/
41 namespace librepcb {
42 
43 class BI_Device;
44 class BI_FootprintPad;
45 class BI_Via;
46 class Board;
47 class BoardFabricationOutputSettings;
48 class Circle;
49 class GerberGenerator;
50 class Layer;
51 class Polygon;
52 class Project;
53 
54 /*******************************************************************************
55  * Class BoardGerberExport
56  ******************************************************************************/
57 
61 class BoardGerberExport final : public QObject {
62  Q_OBJECT
63 
64 public:
65  enum class BoardSide { Top, Bottom };
66  typedef std::pair<const Layer*, const Layer*> LayerPair;
67  typedef std::function<void(const FilePath&)> BeforeWriteCallback;
68 
69  // Constructors / Destructor
70  BoardGerberExport() = delete;
71  BoardGerberExport(const BoardGerberExport& other) = delete;
72  explicit BoardGerberExport(const Board& board) noexcept;
73  ~BoardGerberExport() noexcept;
74 
75  // Getters
77  const BoardFabricationOutputSettings& settings) const noexcept;
78  const QVector<FilePath>& getWrittenFiles() const noexcept {
79  return mWrittenFiles;
80  }
81 
82  // Setters
83  void setRemoveObsoleteFiles(bool remove);
84  void setBeforeWriteCallback(BeforeWriteCallback cb);
85 
86  // General Methods
87  void exportPcbLayers(const BoardFabricationOutputSettings& settings) const;
88  void exportComponentLayer(BoardSide side, const Uuid& assemblyVariant,
89  const FilePath& filePath) const;
90 
91  // Operator Overloadings
92  BoardGerberExport& operator=(const BoardGerberExport& rhs) = delete;
93 
94 private:
95  // Private Methods
96  void exportDrillsMerged(const BoardFabricationOutputSettings& settings) const;
97  void exportDrillsNpth(const BoardFabricationOutputSettings& settings) const;
98  void exportDrillsPth(const BoardFabricationOutputSettings& settings) const;
100  const BoardFabricationOutputSettings& settings) const;
102  const BoardFabricationOutputSettings& settings) const;
104  const BoardFabricationOutputSettings& settings) const;
106  const BoardFabricationOutputSettings& settings) const;
108  const BoardFabricationOutputSettings& settings) const;
110  const BoardFabricationOutputSettings& settings) const;
112  const BoardFabricationOutputSettings& settings) const;
114  const BoardFabricationOutputSettings& settings) const;
116  const BoardFabricationOutputSettings& settings) const;
118  const BoardFabricationOutputSettings& settings) const;
120  const BoardFabricationOutputSettings& settings) const;
121 
122  int drawNpthDrills(ExcellonGenerator& gen) const;
123  int drawPthDrills(ExcellonGenerator& gen) const;
124  QMap<LayerPair, QList<const BI_Via*> > getBlindBuriedVias() const;
125  void drawLayer(GerberGenerator& gen, const Layer& layer) const;
126  void drawVia(GerberGenerator& gen, const BI_Via& via, const Layer& layer,
127  const QString& netName) const;
128  void drawDevice(GerberGenerator& gen, const BI_Device& device,
129  const Layer& layer) const;
130  void drawFootprintPad(GerberGenerator& gen, const BI_FootprintPad& pad,
131  const Layer& layer) const;
132  void drawPolygon(GerberGenerator& gen, const Layer& layer,
133  const Path& outline, const UnsignedLength& lineWidth,
134  bool fill, GerberGenerator::Function function,
135  const tl::optional<QString>& net,
136  const QString& component) const;
137  QVector<Path> getComponentOutlines(const BI_Device& device,
138  const Layer& layer) const;
139 
140  std::unique_ptr<ExcellonGenerator> createExcellonGenerator(
141  const BoardFabricationOutputSettings& settings,
142  ExcellonGenerator::Plating plating) const;
143  FilePath getOutputFilePath(QString path) const noexcept;
144  QString getAttributeValue(const QString& key) const noexcept;
145  void trackFileBeforeWrite(const FilePath& fp) const;
146 
147  // Static Methods
148  static UnsignedLength calcWidthOfLayer(const UnsignedLength& width,
149  const Layer& layer) noexcept;
150 
151  // Private Member Variables
153  const Board& mBoard;
155  BeforeWriteCallback mBeforeWriteCallback;
156  QDateTime mCreationDateTime;
157  QString mProjectName;
159  mutable const Layer* mCurrentStartLayer;
160  mutable const Layer* mCurrentEndLayer;
161  mutable QVector<FilePath> mWrittenFiles;
162 };
163 
164 /*******************************************************************************
165  * End of File
166  ******************************************************************************/
167 
168 } // namespace librepcb
169 
170 #endif
void drawDevice(GerberGenerator &gen, const BI_Device &device, const Layer &layer) const
Definition: boardgerberexport.cpp:773
bool mRemoveObsoleteFiles
Definition: boardgerberexport.h:154
BoardGerberExport & operator=(const BoardGerberExport &rhs)=delete
void trackFileBeforeWrite(const FilePath &fp) const
Definition: boardgerberexport.cpp:1092
The BoardGerberExport class.
Definition: boardgerberexport.h:61
void drawFootprintPad(GerberGenerator &gen, const BI_FootprintPad &pad, const Layer &layer) const
Definition: boardgerberexport.cpp:863
std::pair< const Layer *, const Layer * > LayerPair
Definition: boardgerberexport.h:66
Definition: occmodel.cpp:77
The BI_Device class.
Definition: bi_device.h:57
std::unique_ptr< ExcellonGenerator > createExcellonGenerator(const BoardFabricationOutputSettings &settings, ExcellonGenerator::Plating plating) const
Definition: boardgerberexport.cpp:1038
void exportComponentLayer(BoardSide side, const Uuid &assemblyVariant, const FilePath &filePath) const
Definition: boardgerberexport.cpp:138
void exportLayerBottomSilkscreen(const BoardFabricationOutputSettings &settings) const
Definition: boardgerberexport.cpp:511
void exportDrillsPth(const BoardFabricationOutputSettings &settings) const
Definition: boardgerberexport.cpp:345
std::function< void(const FilePath &)> BeforeWriteCallback
Definition: boardgerberexport.h:67
void exportLayerTopSolderMask(const BoardFabricationOutputSettings &settings) const
Definition: boardgerberexport.cpp:449
void exportLayerTopSilkscreen(const BoardFabricationOutputSettings &settings) const
Definition: boardgerberexport.cpp:487
void setBeforeWriteCallback(BeforeWriteCallback cb)
Definition: boardgerberexport.cpp:110
The Layer class provides all supported geometry layers.
Definition: layer.h:40
QVector< Path > getComponentOutlines(const BI_Device &device, const Layer &layer) const
Definition: boardgerberexport.cpp:1005
int drawNpthDrills(ExcellonGenerator &gen) const
Definition: boardgerberexport.cpp:573
void setRemoveObsoleteFiles(bool remove)
Definition: boardgerberexport.cpp:106
void exportLayerTopCopper(const BoardFabricationOutputSettings &settings) const
Definition: boardgerberexport.cpp:398
void drawVia(GerberGenerator &gen, const BI_Via &via, const Layer &layer, const QString &netName) const
Definition: boardgerberexport.cpp:749
const Board & mBoard
Definition: boardgerberexport.h:153
const Layer * mCurrentEndLayer
Definition: boardgerberexport.h:160
The ExcellonGenerator class.
Definition: excellongenerator.h:47
void exportPcbLayers(const BoardFabricationOutputSettings &settings) const
Definition: boardgerberexport.cpp:118
void exportDrillsBlindBuried(const BoardFabricationOutputSettings &settings) const
Definition: boardgerberexport.cpp:363
int mCurrentInnerCopperLayer
Definition: boardgerberexport.h:158
The Board class represents a PCB of a project and is always part of a circuit.
Definition: board.h:73
QMap< LayerPair, QList< const BI_Via * > > getBlindBuriedVias() const
Definition: boardgerberexport.cpp:631
FilePath getOutputDirectory(const BoardFabricationOutputSettings &settings) const noexcept
Definition: boardgerberexport.cpp:96
void drawLayer(GerberGenerator &gen, const Layer &layer) const
Definition: boardgerberexport.cpp:645
void exportDrillsNpth(const BoardFabricationOutputSettings &settings) const
Definition: boardgerberexport.cpp:319
QDateTime mCreationDateTime
Definition: boardgerberexport.h:156
This class represents absolute, well-formatted paths to files or directories.
Definition: filepath.h:129
void exportLayerBottomSolderPaste(const BoardFabricationOutputSettings &settings) const
Definition: boardgerberexport.cpp:554
void exportLayerBoardOutlines(const BoardFabricationOutputSettings &settings) const
Definition: boardgerberexport.cpp:384
void exportLayerBottomSolderMask(const BoardFabricationOutputSettings &settings) const
Definition: boardgerberexport.cpp:468
GerberApertureList::Function Function
Definition: gerbergenerator.h:59
The Project class represents a whole (opened) project with all its content.
Definition: project.h:71
FilePath getOutputFilePath(QString path) const noexcept
Definition: boardgerberexport.cpp:1048
The Path class represents a list of vertices connected by straight lines or circular arc segments...
Definition: path.h:58
QString mProjectName
Definition: boardgerberexport.h:157
void exportDrillsMerged(const BoardFabricationOutputSettings &settings) const
Definition: boardgerberexport.cpp:300
Plating
Definition: excellongenerator.h:52
static UnsignedLength calcWidthOfLayer(const UnsignedLength &width, const Layer &layer) noexcept
Definition: boardgerberexport.cpp:1103
void drawPolygon(GerberGenerator &gen, const Layer &layer, const Path &outline, const UnsignedLength &lineWidth, bool fill, GerberGenerator::Function function, const tl::optional< QString > &net, const QString &component) const
Definition: boardgerberexport.cpp:982
The BoardFabricationOutputSettings class.
Definition: boardfabricationoutputsettings.h:43
void exportLayerBottomCopper(const BoardFabricationOutputSettings &settings) const
Definition: boardgerberexport.cpp:412
QString getAttributeValue(const QString &key) const noexcept
Definition: boardgerberexport.cpp:1063
const Project & mProject
Definition: boardgerberexport.h:152
The Uuid class is a replacement for QUuid to get UUID strings without {} braces.
Definition: uuid.h:58
BeforeWriteCallback mBeforeWriteCallback
Definition: boardgerberexport.h:155
The GerberGenerator class.
Definition: gerbergenerator.h:51
const QVector< FilePath > & getWrittenFiles() const noexcept
Definition: boardgerberexport.h:78
void exportLayerInnerCopper(const BoardFabricationOutputSettings &settings) const
Definition: boardgerberexport.cpp:427
void exportLayerTopSolderPaste(const BoardFabricationOutputSettings &settings) const
Definition: boardgerberexport.cpp:535
const Layer * mCurrentStartLayer
Definition: boardgerberexport.h:159
~BoardGerberExport() noexcept
Definition: boardgerberexport.cpp:89
int drawPthDrills(ExcellonGenerator &gen) const
Definition: boardgerberexport.cpp:596
QVector< FilePath > mWrittenFiles
Definition: boardgerberexport.h:161
The BI_Via class.
Definition: bi_via.h:44
The BI_FootprintPad class.
Definition: bi_footprintpad.h:48
type_safe::constrained_type< Length, UnsignedLengthConstraint, UnsignedLengthVerifier > UnsignedLength
Definition: length.h:696
BoardSide
Definition: boardgerberexport.h:65