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 The 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_PAD_CASTELLATED, // a plated castelleted pad hole
51 HOLE_PAD_PRESSFIT, // a plated press-fit pad hole
52 HOLE_MECHANICAL // a mechanical pad (provided, not used)
53};
54
55// Via Protection features according to IPC-4761.
56enum class IPC4761_FEATURES : int
57{
58 FILLED,
59 CAPPED,
66};
67
68// the DRILL_TOOL class handles tools used in the excellon drill file:
70{
71public:
72 int m_Diameter; // the diameter of the used tool
73 // (for oblong, the smaller size)
74 int m_TotalCount; // how many times it is used (round and oblong)
75 int m_OvalCount; // oblong count
76 bool m_Hole_NotPlated; // Is the hole plated or not plated
77 HOLE_ATTRIBUTE m_HoleAttribute; // Attribute (used in Excellon drill file)
78
79public:
80 DRILL_TOOL( int aDiameter, bool a_NotPlated )
81 {
82 m_TotalCount = 0;
83 m_OvalCount = 0;
84 m_Diameter = aDiameter;
85 m_Hole_NotPlated = a_NotPlated;
86 m_HoleAttribute = HOLE_ATTRIBUTE::HOLE_UNKNOWN;
87 }
88};
89
90
99{
100public:
102 {
103 m_ItemParent = nullptr;
104 m_Hole_NotPlated = false;
105 m_Hole_Diameter = 0;
108 m_Hole_Shape = 0;
111 m_HoleAttribute = HOLE_ATTRIBUTE::HOLE_UNKNOWN;
112 m_Hole_Filled = false;
113 m_Hole_Capped = false;
114 m_Hole_Top_Covered = false;
115 m_Hole_Bot_Covered = false;
116 m_Hole_Top_Plugged = false;
117 m_Hole_Bot_Plugged = false;
118 m_Hole_Top_Tented = false;
119 m_Hole_Bot_Tented = false;
120 }
121
122public:
123 BOARD_ITEM* m_ItemParent; // The pad or via parent of this hole
124 int m_Hole_Diameter; // hole value, and for oblong: min(hole size x, hole
125 // size y).
126 int m_Tool_Reference; // Tool reference for this hole = 1 ... n (values <=0
127 // must not be used).
128 VECTOR2I m_Hole_Size; // hole size for oblong holes
129 EDA_ANGLE m_Hole_Orient; // Hole rotation (= pad rotation) for oblong holes
130 int m_Hole_Shape; // hole shape: round (0) or oval (1)
131 VECTOR2I m_Hole_Pos; // hole position
132 PCB_LAYER_ID m_Hole_Bottom_Layer; // hole ending layer (usually back layer)
133 PCB_LAYER_ID m_Hole_Top_Layer; // hole starting layer (usually front layer):
134 // m_Hole_Top_Layer < m_Hole_Bottom_Layer
135 bool m_Hole_NotPlated; // hole not plated. Must be in a specific drill file or
136 // section.
137 HOLE_ATTRIBUTE m_HoleAttribute; // Attribute, used in Excellon drill file and to sort holes
138 // by type.
139
140 bool m_Hole_Filled; // hole should be filled
141 bool m_Hole_Capped; // hole should be capped
142 bool m_Hole_Top_Covered; // hole should be covered on top
143 bool m_Hole_Bot_Covered; // hole should be covered on bottom
144 bool m_Hole_Top_Plugged; // hole should be plugged on top
145 bool m_Hole_Bot_Plugged; // hole should be plugged on bottom
146 bool m_Hole_Top_Tented; // hole should be tented on top
147 bool m_Hole_Bot_Tented; // hole should be tented on bottom
148};
149
150
155{
156public:
157 DRILL_PRECISION( int l = 2, int r = 4 )
158 {
159 m_Lhs = l; m_Rhs = r;
160 }
161
162
164 {
165 wxString text;
166
167 text << m_Lhs << wxT( ":" ) << m_Rhs;
168 return text;
169 }
170
171 int m_Lhs; // Left digit number (integer value of coordinates)
172 int m_Rhs; // Right digit number (decimal value of coordinates)
173};
174
175
176typedef std::pair<PCB_LAYER_ID, PCB_LAYER_ID> DRILL_LAYER_PAIR;
177
184{
185public:
186 enum ZEROS_FMT { // Zero format in coordinates
187 DECIMAL_FORMAT, // Floating point coordinates
188 SUPPRESS_LEADING, // Suppress leading zeros
189 SUPPRESS_TRAILING, // Suppress trailing zeros
190 KEEP_ZEROS // keep zeros
191 };
192
193 enum TYPE_FILE { // type of holes in file: PTH, NPTH, mixed
194 PTH_FILE, // PTH only, this is the default also for blind/buried holes
195 NPTH_FILE, // NPTH only
196 MIXED_FILE // PHT+NPTH (mixed)
197 };
198
200 {
201 }
202
209 void SetMergeOption( bool aMerge ) { m_merge_PTH_NPTH = aMerge; }
210
215
223 void SetPageInfo( const PAGE_INFO* aPageInfo ) { m_pageInfo = aPageInfo; }
224
233 {
234 m_mapFileFmt = aMapFmt;
235 }
236
246 bool CreateMapFilesSet( const wxString& aPlotDirectory, REPORTER* aReporter = nullptr );
247
296 bool GenDrillReportFile( const wxString& aFullFileName );
297
301 wxString GetDrillFileExt() const { return m_drillFileExtension; }
302
303protected:
315 bool genDrillMapFile( const wxString& aFullFileName, PLOT_FORMAT aFormat );
316
329 void buildHolesList( DRILL_LAYER_PAIR aLayerPair, bool aGenerateNPTH_list );
330
331 int getHolesCount() const { return m_holeListBuffer.size(); }
332
342 bool plotDrillMarks( PLOTTER* aPlotter );
343
345 std::vector<DRILL_LAYER_PAIR> getUniqueLayerPairs() const;
346
353 unsigned printToolSummary( OUTPUTFORMATTER& aOut, bool aSummaryNPTH ) const;
354
360 const std::string layerPairName( DRILL_LAYER_PAIR aPair ) const;
361
366 const std::string layerName( PCB_LAYER_ID aLayer ) const;
367
377 virtual const wxString getDrillFileName( DRILL_LAYER_PAIR aPair, bool aNPTH,
378 bool aMerge_PTH_NPTH ) const;
379
380
387 virtual const wxString getProtectionFileName( DRILL_LAYER_PAIR aPair,
388 IPC4761_FEATURES aFeature ) const;
389
390
402 const wxString BuildFileFunctionAttributeString( DRILL_LAYER_PAIR aLayerPair,
403 TYPE_FILE aHoleType,
404 bool aCompatNCdrill = false ) const;
405
406
407protected:
408 // Use derived classes to build a fully initialized GENDRILL_WRITER_BASE class.
410 {
411 m_pcb = aPcb;
412 m_conversionUnits = 1.0;
413 m_unitsMetric = true;
414 m_mapFileFmt = PLOT_FORMAT::PDF;
415 m_pageInfo = nullptr;
416 m_merge_PTH_NPTH = false;
418 }
419
421 wxString m_drillFileExtension; // .drl or .gbr, depending on format
422 bool m_unitsMetric; // true = mm, false = inches
423 ZEROS_FMT m_zeroFormat; // the zero format option for output file
424 DRILL_PRECISION m_precision; // The current coordinate precision (not
425 // used in decimal format).
426 double m_conversionUnits; // scaling factor to convert the board
427 // unites to Excellon/Gerber units (i.e
428 // inches or mm)
429 VECTOR2I m_offset; // Drill offset coordinates
430 bool m_merge_PTH_NPTH; // True to generate only one drill file
431 std::vector<HOLE_INFO> m_holeListBuffer; // Buffer containing holes
432 std::vector<DRILL_TOOL> m_toolListBuffer; // Buffer containing tools
433
434 PLOT_FORMAT m_mapFileFmt; // the format of the map drill file,
435 // if this map is needed
436 const PAGE_INFO* m_pageInfo; // the page info used to plot drill maps
437 // If NULL, use a A4 page format
438};
439
440#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:79
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:317
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.
virtual const wxString getProtectionFileName(DRILL_LAYER_PAIR aPair, IPC4761_FEATURES aFeature) const
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 PDF, 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:121
A pure virtual class used to derive REPORTER objects from.
Definition: reporter.h:73
static constexpr EDA_ANGLE ANGLE_0
Definition: eda_angle.h:411
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:65
@ F_Cu
Definition: layer_ids.h:64
PLOT_FORMAT
The set of supported output plot formats.
Definition: plotter.h:64