KiCad PCB EDA Suite
Loading...
Searching...
No Matches
gendrill_file_writer_base.h
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 1992-2017 Jean_Pierre Charras <jp.charras at wanadoo.fr>
5 * Copyright (C) 1992-2021 KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, you may find one here:
19 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20 * or you may search the http://www.gnu.org website for the version 2 license,
21 * or you may write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 */
24
29#ifndef GENDRILL_FILE_WRITER_BASE_H
30#define GENDRILL_FILE_WRITER_BASE_H
31
32// holes can have an attribute in Excellon drill files, similar to attributes
33// in Gerber X2 format
34// They are only comments for a better identification of holes (vias, pads...)
35// Set to 1 to add these comments and 0 to not use these comments
36#define USE_ATTRIB_FOR_HOLES 1
37
38#include <vector>
39
40class BOARD_ITEM;
41
42// hole attribute, mainly to identify vias and pads and add this info as comment
43// in NC drill files
45{
46 HOLE_UNKNOWN, // uninitialized type
47 HOLE_VIA_THROUGH, // a via hole (always plated) from top to bottom
48 HOLE_VIA_BURIED, // a via hole (always plated) not through hole
49 HOLE_PAD, // a plated or not plated pad hole
50 HOLE_MECHANICAL // a mechanical pad (provided, not used)
51};
52
53
54// the DRILL_TOOL class handles tools used in the excellon drill file:
56{
57public:
58 int m_Diameter; // the diameter of the used tool
59 // (for oblong, the smaller size)
60 int m_TotalCount; // how many times it is used (round and oblong)
61 int m_OvalCount; // oblong count
62 bool m_Hole_NotPlated; // Is the hole plated or not plated
63 HOLE_ATTRIBUTE m_HoleAttribute; // Attribute (used in Excellon drill file)
64
65public:
66 DRILL_TOOL( int aDiameter, bool a_NotPlated )
67 {
68 m_TotalCount = 0;
69 m_OvalCount = 0;
70 m_Diameter = aDiameter;
71 m_Hole_NotPlated = a_NotPlated;
72 m_HoleAttribute = HOLE_ATTRIBUTE::HOLE_UNKNOWN;
73 }
74};
75
76
85{
86public:
88 {
89 m_ItemParent = nullptr;
90 m_Hole_NotPlated = false;
94 m_Hole_Shape = 0;
97 m_HoleAttribute = HOLE_ATTRIBUTE::HOLE_UNKNOWN;
98 }
99
100public:
101 BOARD_ITEM* m_ItemParent; // The pad or via parent of this hole
102 int m_Hole_Diameter; // hole value, and for oblong: min(hole size x, hole
103 // size y).
104 int m_Tool_Reference; // Tool reference for this hole = 1 ... n (values <=0
105 // must not be used).
106 VECTOR2I m_Hole_Size; // hole size for oblong holes
107 EDA_ANGLE m_Hole_Orient; // Hole rotation (= pad rotation) for oblong holes
108 int m_Hole_Shape; // hole shape: round (0) or oval (1)
109 VECTOR2I m_Hole_Pos; // hole position
110 PCB_LAYER_ID m_Hole_Bottom_Layer; // hole ending layer (usually back layer)
111 PCB_LAYER_ID m_Hole_Top_Layer; // hole starting layer (usually front layer):
112 // m_Hole_Top_Layer < m_Hole_Bottom_Layer
113 bool m_Hole_NotPlated; // hole not plated. Must be in a specific drill file or
114 // section.
115 HOLE_ATTRIBUTE m_HoleAttribute; // Attribute, used in Excellon drill file and to sort holes
116 // by type.
117};
118
119
124{
125public:
126 DRILL_PRECISION( int l = 2, int r = 4 )
127 {
128 m_Lhs = l; m_Rhs = r;
129 }
130
131
133 {
134 wxString text;
135
136 text << m_Lhs << wxT( ":" ) << m_Rhs;
137 return text;
138 }
139
140 int m_Lhs; // Left digit number (integer value of coordinates)
141 int m_Rhs; // Right digit number (decimal value of coordinates)
142};
143
144
145typedef std::pair<PCB_LAYER_ID, PCB_LAYER_ID> DRILL_LAYER_PAIR;
146
153{
154public:
155 enum ZEROS_FMT { // Zero format in coordinates
156 DECIMAL_FORMAT, // Floating point coordinates
157 SUPPRESS_LEADING, // Suppress leading zeros
158 SUPPRESS_TRAILING, // Suppress trailing zeros
159 KEEP_ZEROS // keep zeros
160 };
161
162 enum TYPE_FILE { // type of holes in file: PTH, NPTH, mixed
163 PTH_FILE, // PTH only, this is the default also for blind/buried holes
164 NPTH_FILE, // NPTH only
165 MIXED_FILE // PHT+NPTH (mixed)
166 };
167
169 {
170 }
171
178 void SetMergeOption( bool aMerge ) { m_merge_PTH_NPTH = aMerge; }
179
184
192 void SetPageInfo( const PAGE_INFO* aPageInfo ) { m_pageInfo = aPageInfo; }
193
202 {
203 m_mapFileFmt = aMapFmt;
204 }
205
215 bool CreateMapFilesSet( const wxString& aPlotDirectory, REPORTER* aReporter = nullptr );
216
265 bool GenDrillReportFile( const wxString& aFullFileName );
266
270 wxString GetDrillFileExt() const { return m_drillFileExtension; }
271
272protected:
284 bool genDrillMapFile( const wxString& aFullFileName, PLOT_FORMAT aFormat );
285
298 void buildHolesList( DRILL_LAYER_PAIR aLayerPair, bool aGenerateNPTH_list );
299
300 int getHolesCount() const { return m_holeListBuffer.size(); }
301
311 bool plotDrillMarks( PLOTTER* aPlotter );
312
314 std::vector<DRILL_LAYER_PAIR> getUniqueLayerPairs() const;
315
322 unsigned printToolSummary( OUTPUTFORMATTER& aOut, bool aSummaryNPTH ) const;
323
329 const std::string layerPairName( DRILL_LAYER_PAIR aPair ) const;
330
335 const std::string layerName( PCB_LAYER_ID aLayer ) const;
336
346 virtual const wxString getDrillFileName( DRILL_LAYER_PAIR aPair, bool aNPTH,
347 bool aMerge_PTH_NPTH ) const;
348
349
361 const wxString BuildFileFunctionAttributeString( DRILL_LAYER_PAIR aLayerPair,
362 TYPE_FILE aHoleType,
363 bool aCompatNCdrill = false ) const;
364
365
366protected:
367 // Use derived classes to build a fully initialized GENDRILL_WRITER_BASE class.
369 {
370 m_pcb = aPcb;
371 m_conversionUnits = 1.0;
372 m_unitsMetric = true;
373 m_mapFileFmt = PLOT_FORMAT::PDF;
374 m_pageInfo = nullptr;
375 m_merge_PTH_NPTH = false;
377 }
378
380 wxString m_drillFileExtension; // .drl or .gbr, depending on format
381 bool m_unitsMetric; // true = mm, false = inches
382 ZEROS_FMT m_zeroFormat; // the zero format option for output file
383 DRILL_PRECISION m_precision; // The current coordinate precision (not
384 // used in decimal format).
385 double m_conversionUnits; // scaling factor to convert the board
386 // unites to Excellon/Gerber units (i.e
387 // inches or mm)
388 VECTOR2I m_offset; // Drill offset coordinates
389 bool m_merge_PTH_NPTH; // True to generate only one drill file
390 std::vector<HOLE_INFO> m_holeListBuffer; // Buffer containing holes
391 std::vector<DRILL_TOOL> m_toolListBuffer; // Buffer containing tools
392
393 PLOT_FORMAT m_mapFileFmt; // the format of the map drill file,
394 // if this map is needed
395 const PAGE_INFO* m_pageInfo; // the page info used to plot drill maps
396 // If NULL, use a A4 page format
397};
398
399#endif // #define GENDRILL_FILE_WRITER_BASE_H
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:77
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:281
Helper to handle drill precision format in excellon files.
DRILL_PRECISION(int l=2, int r=4)
HOLE_ATTRIBUTE m_HoleAttribute
DRILL_TOOL(int aDiameter, bool a_NotPlated)
Create drill maps and drill reports and drill files.
wxString GetDrillFileExt() const
Returns the file extension of the drill writer format.
std::vector< DRILL_LAYER_PAIR > getUniqueLayerPairs() const
Get unique layer pairs by examining the micro and blind_buried vias.
virtual const wxString getDrillFileName(DRILL_LAYER_PAIR aPair, bool aNPTH, bool aMerge_PTH_NPTH) const
void SetMapFileFormat(PLOT_FORMAT aMapFmt)
Initialize the format for the drill map file.
void buildHolesList(DRILL_LAYER_PAIR aLayerPair, bool aGenerateNPTH_list)
Create the list of holes and tools for a given board.
const wxString BuildFileFunctionAttributeString(DRILL_LAYER_PAIR aLayerPair, TYPE_FILE aHoleType, bool aCompatNCdrill=false) const
unsigned printToolSummary(OUTPUTFORMATTER &aOut, bool aSummaryNPTH) const
Print m_toolListBuffer[] tools to aOut and returns total hole count.
std::vector< HOLE_INFO > m_holeListBuffer
bool genDrillMapFile(const wxString &aFullFileName, PLOT_FORMAT aFormat)
Plot a map of drill marks for holes.
VECTOR2I GetOffset()
Return the plot offset (usually the position of the drill/place origin).
std::vector< DRILL_TOOL > m_toolListBuffer
bool GenDrillReportFile(const wxString &aFullFileName)
Create a plain text report file giving a list of drill values and drill count for through holes,...
const std::string layerPairName(DRILL_LAYER_PAIR aPair) const
bool CreateMapFilesSet(const wxString &aPlotDirectory, REPORTER *aReporter=nullptr)
Create the full set of map files for the board, in PS, PDF ... format (use SetMapFileFormat() to sele...
void SetMergeOption(bool aMerge)
Set the option to make separate drill files for PTH and NPTH.
const std::string layerName(PCB_LAYER_ID aLayer) const
bool plotDrillMarks(PLOTTER *aPlotter)
Write the drill marks in HPGL, POSTSCRIPT or other supported formats/.
void SetPageInfo(const PAGE_INFO *aPageInfo)
Set the page info used to plot drill maps.
Handle hole which must be drilled (diameter, position and layers).
PCB_LAYER_ID m_Hole_Bottom_Layer
PCB_LAYER_ID m_Hole_Top_Layer
HOLE_ATTRIBUTE m_HoleAttribute
BOARD_ITEM * m_ItemParent
An interface used to output 8 bit text in a convenient way.
Definition: richio.h:322
Describe the page size and margins of a paper page on which to eventually print or plot.
Definition: page_info.h:59
Base plotter engine class.
Definition: plotter.h:104
A pure virtual class used to derive REPORTER objects from.
Definition: reporter.h:71
static constexpr EDA_ANGLE ANGLE_0
Definition: eda_angle.h:435
std::pair< PCB_LAYER_ID, PCB_LAYER_ID > DRILL_LAYER_PAIR
PCB_LAYER_ID
A quick note on layer IDs:
Definition: layer_ids.h:60
@ B_Cu
Definition: layer_ids.h:95
@ F_Cu
Definition: layer_ids.h:64
PLOT_FORMAT
The set of supported output plot formats.
Definition: plotter.h:64