KiCad PCB EDA Suite
Loading...
Searching...
No Matches
gendrill_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, see <https://www.gnu.org/licenses/>.
19 */
20
25#ifndef GENDRILL_WRITER_BASE_H
26#define GENDRILL_WRITER_BASE_H
27
28// holes can have an attribute in Excellon drill files, similar to attributes
29// in Gerber X2 format
30// They are only comments for a better identification of holes (vias, pads...)
31// Set to 1 to add these comments and 0 to not use these comments
32#define USE_ATTRIB_FOR_HOLES 1
33
34#include <optional>
35#include <string>
36#include <vector>
37
38#include <layer_ids.h>
39#include <plotters/plotter.h>
40#include <padstack.h>
41
42
43class BOARD;
44class BOARD_ITEM;
45class OUTPUTFORMATTER;
46class PAGE_INFO;
47class REPORTER;
48
49// hole attribute, mainly to identify vias and pads and add this info as comment
50// in NC drill files
52{
53 HOLE_UNKNOWN, // uninitialized type
54 HOLE_VIA_THROUGH, // a via hole (always plated) from top to bottom
55 HOLE_VIA_BURIED, // a via hole (always plated) not through hole
56 HOLE_VIA_BACKDRILL, // a via hole created by a backdrill operation
57 HOLE_PAD, // a plated or not plated pad hole
58 HOLE_PAD_CASTELLATED, // a plated castelleted pad hole
59 HOLE_PAD_PRESSFIT, // a plated press-fit pad hole
60 HOLE_MECHANICAL // a mechanical pad (provided, not used)
61};
62
63// Via Protection features according to IPC-4761.
75
76// the DRILL_TOOL class handles tools used in the excellon drill file:
78{
79public:
80 int m_Diameter; // the diameter of the used tool
81 // (for oblong, the smaller size)
82 int m_TotalCount; // how many times it is used (round and oblong)
83 int m_OvalCount; // oblong count
84 bool m_Hole_NotPlated; // Is the hole plated or not plated
85 HOLE_ATTRIBUTE m_HoleAttribute; // Attribute (used in Excellon drill file)
86 bool m_IsBackdrill; // True when drilling a backdrill span
87 bool m_HasPostMachining; // True if any hole for this tool has post-machining
88 std::optional<int> m_MinStubLength; // Minimum stub length for this tool (IU)
89 std::optional<int> m_MaxStubLength; // Maximum stub length for this tool (IU)
90
91public:
92 DRILL_TOOL( int aDiameter, bool a_NotPlated )
93 {
94 m_TotalCount = 0;
95 m_OvalCount = 0;
96 m_Diameter = aDiameter;
97 m_Hole_NotPlated = a_NotPlated;
99 m_IsBackdrill = false;
100 m_HasPostMachining = false;
101 }
102};
103
104
113{
114public:
146
147public:
148 BOARD_ITEM* m_ItemParent; // The pad or via parent of this hole
149 int m_Hole_Diameter; // hole value, and for oblong: min(hole size x, hole
150 // size y).
151 int m_Tool_Reference; // Tool reference for this hole = 1 ... n (values <=0
152 // must not be used).
153 VECTOR2I m_Hole_Size; // hole size for oblong holes
154 EDA_ANGLE m_Hole_Orient; // Hole rotation (= pad rotation) for oblong holes
155 int m_Hole_Shape; // hole shape: round (0) or oval (1)
156 VECTOR2I m_Hole_Pos; // hole position
157 PCB_LAYER_ID m_Hole_Bottom_Layer; // hole ending layer (usually back layer)
158 PCB_LAYER_ID m_Hole_Top_Layer; // hole starting layer (usually front layer):
159 // m_Hole_Top_Layer < m_Hole_Bottom_Layer
160 bool m_Hole_NotPlated; // hole not plated. Must be in a specific drill file or
161 // section.
162 HOLE_ATTRIBUTE m_HoleAttribute; // Attribute, used in Excellon drill file and to sort holes
163 // by type.
164 bool m_Hole_Filled; // True if the hole is filled
165 bool m_Hole_Capped; // True if the hole is capped
166 bool m_Hole_Top_Covered; // True if the hole is covered on the top layer
167 bool m_Hole_Bot_Covered; // True if the hole is covered on the bottom layer
168 bool m_Hole_Top_Plugged; // True if the hole is plugged on the top layer
169 bool m_Hole_Bot_Plugged; // True if the hole is plugged on the bottom layer
170 bool m_Hole_Top_Tented; // True if the hole is tented on the top layer
171 bool m_Hole_Bot_Tented; // True if the hole is tented on the bottom layer
172 bool m_IsBackdrill; // True if the hole is a backdrill
174 int m_FrontPostMachiningSize; // Post-machining size
175 int m_FrontPostMachiningDepth; // Post-machining depth
176 int m_FrontPostMachiningAngle; // Post-machining angle
178 int m_BackPostMachiningSize; // Post-machining size
179 int m_BackPostMachiningDepth; // Post-machining depth
180 int m_BackPostMachiningAngle; // Post-machining angle
181 PCB_LAYER_ID m_DrillStart; // Start layer for backdrills
182 PCB_LAYER_ID m_DrillEnd; // End layer for backdrills
183 std::optional<int> m_StubLength; // Stub length for backdrills
184
185
186};
187
188
189typedef std::pair<PCB_LAYER_ID, PCB_LAYER_ID> DRILL_LAYER_PAIR;
190
191
193{
195 {
198 m_IsBackdrill = false;
199 m_IsNonPlatedFile = false;
200 }
201
202 DRILL_SPAN( PCB_LAYER_ID aStartLayer, PCB_LAYER_ID aEndLayer, bool aIsBackdrill,
203 bool aIsNonPlated )
204 {
205 m_StartLayer = aStartLayer;
206 m_EndLayer = aEndLayer;
207 m_IsBackdrill = aIsBackdrill;
208 m_IsNonPlatedFile = aIsNonPlated;
209 }
210
215
220
222 {
223 return m_StartLayer;
224 }
225
227 {
228 return m_EndLayer;
229 }
230
232 {
234 }
235
236 bool operator<( const DRILL_SPAN& aOther ) const
237 {
238 if( TopLayer() != aOther.TopLayer() )
239 return TopLayer() < aOther.TopLayer();
240
241 if( BottomLayer() != aOther.BottomLayer() )
242 return BottomLayer() < aOther.BottomLayer();
243
244 if( m_IsBackdrill != aOther.m_IsBackdrill )
245 return m_IsBackdrill && !aOther.m_IsBackdrill;
246
248 return m_IsNonPlatedFile && !aOther.m_IsNonPlatedFile;
249
250 if( m_StartLayer != aOther.m_StartLayer )
251 return m_StartLayer < aOther.m_StartLayer;
252
253 return m_EndLayer < aOther.m_EndLayer;
254 }
255
260};
261
262
267{
268public:
269 DRILL_PRECISION( int l = 2, int r = 4 )
270 {
271 m_Lhs = l; m_Rhs = r;
272 }
273
274
276 {
277 wxString text;
278
279 text << m_Lhs << wxT( ":" ) << m_Rhs;
280 return text;
281 }
282
283 int m_Lhs; // Left digit number (integer value of coordinates)
284 int m_Rhs; // Right digit number (decimal value of coordinates)
285};
286
287
294{
295public:
296 enum ZEROS_FMT { // Zero format in coordinates
297 DECIMAL_FORMAT, // Floating point coordinates
298 SUPPRESS_LEADING, // Suppress leading zeros
299 SUPPRESS_TRAILING, // Suppress trailing zeros
300 KEEP_ZEROS // keep zeros
301 };
302
303 enum TYPE_FILE { // type of holes in file: PTH, NPTH, mixed
304 PTH_FILE, // PTH only, this is the default also for blind/buried holes
305 NPTH_FILE, // NPTH only
306 MIXED_FILE // PHT+NPTH (mixed)
307 };
308
310 {
311 }
312
319 void SetMergeOption( bool aMerge ) { m_merge_PTH_NPTH = aMerge; }
320
325
333 void SetPageInfo( const PAGE_INFO* aPageInfo ) { m_pageInfo = aPageInfo; }
334
343 {
344 m_mapFileFmt = aMapFmt;
345 }
346
356 bool CreateMapFilesSet( const wxString& aPlotDirectory, REPORTER* aReporter = nullptr );
357
406 bool GenDrillReportFile( const wxString& aFullFileName, REPORTER* aReporter = nullptr );
407
411 wxString GetDrillFileExt() const { return m_drillFileExtension; }
412
413protected:
425 bool genDrillMapFile( const wxString& aFullFileName, PLOT_FORMAT aFormat );
426
439 void buildHolesList( const DRILL_SPAN& aSpan, bool aGenerateNPTH_list );
440
441 int getHolesCount() const { return m_holeListBuffer.size(); }
442
452 bool plotDrillMarks( PLOTTER* aPlotter );
453
455 std::vector<DRILL_SPAN> getUniqueLayerPairs() const;
456
463 unsigned printToolSummary( FILE* out, bool aSummaryNPTH ) const;
464
470 const std::string layerPairName( DRILL_LAYER_PAIR aPair ) const;
471
476 const std::string layerName( PCB_LAYER_ID aLayer ) const;
477
487 virtual const wxString getDrillFileName( const DRILL_SPAN& aSpan, bool aNPTH,
488 bool aMerge_PTH_NPTH ) const;
489
490
497 virtual const wxString getProtectionFileName( const DRILL_SPAN& aSpan,
498 IPC4761_FEATURES aFeature ) const;
499
500
512 const wxString BuildFileFunctionAttributeString( const DRILL_SPAN& aSpan,
513 TYPE_FILE aHoleType,
514 bool aCompatNCdrill = false ) const;
515
516
517protected:
518 // Use derived classes to build a fully initialized GENDRILL_WRITER_BASE class.
520 {
521 m_pcb = aPcb;
522 m_conversionUnits = 1.0;
523 m_unitsMetric = true;
525 m_pageInfo = nullptr;
526 m_merge_PTH_NPTH = false;
528 }
529
531 wxString m_drillFileExtension; // .drl or .gbr, depending on format
532 bool m_unitsMetric; // true = mm, false = inches
533 ZEROS_FMT m_zeroFormat; // the zero format option for output file
534 DRILL_PRECISION m_precision; // The current coordinate precision (not
535 // used in decimal format).
536 double m_conversionUnits; // scaling factor to convert the board
537 // unites to Excellon/Gerber units (i.e
538 // inches or mm)
539 VECTOR2I m_offset; // Drill offset coordinates
540 bool m_merge_PTH_NPTH; // True to generate only one drill file
541 std::vector<HOLE_INFO> m_holeListBuffer; // Buffer containing holes
542 std::vector<DRILL_TOOL> m_toolListBuffer; // Buffer containing tools
543
544 PLOT_FORMAT m_mapFileFmt; // the format of the map drill file,
545 // if this map is needed
546 const PAGE_INFO* m_pageInfo; // the page info used to plot drill maps
547 // If NULL, use a A4 page format
548};
549
550#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:81
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:372
Helper to handle drill precision format in excellon files.
DRILL_PRECISION(int l=2, int r=4)
std::optional< int > m_MinStubLength
HOLE_ATTRIBUTE m_HoleAttribute
DRILL_TOOL(int aDiameter, bool a_NotPlated)
std::optional< int > m_MaxStubLength
wxString GetDrillFileExt() const
Returns the file extension of the drill writer format.
virtual const wxString getProtectionFileName(const DRILL_SPAN &aSpan, IPC4761_FEATURES aFeature) const
const PAGE_INFO * m_pageInfo
void SetMapFileFormat(PLOT_FORMAT aMapFmt)
Initialize the format for the drill map file.
std::vector< HOLE_INFO > m_holeListBuffer
void buildHolesList(const DRILL_SPAN &aSpan, bool aGenerateNPTH_list)
Create the list of holes and tools for a given board.
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_SPAN > getUniqueLayerPairs() const
Get unique layer pairs by examining the micro and blind_buried vias.
std::vector< DRILL_TOOL > m_toolListBuffer
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
unsigned printToolSummary(FILE *out, bool aSummaryNPTH) const
Print m_toolListBuffer[] tools to aOut and returns total hole count.
virtual const wxString getDrillFileName(const DRILL_SPAN &aSpan, bool aNPTH, bool aMerge_PTH_NPTH) 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.
const wxString BuildFileFunctionAttributeString(const DRILL_SPAN &aSpan, TYPE_FILE aHoleType, bool aCompatNCdrill=false) const
bool GenDrillReportFile(const wxString &aFullFileName, REPORTER *aReporter=nullptr)
Create a plain text report file giving a list of drill values and drill count for through holes,...
PAD_DRILL_POST_MACHINING_MODE m_FrontPostMachining
PCB_LAYER_ID m_Hole_Bottom_Layer
std::optional< int > m_StubLength
PCB_LAYER_ID m_DrillEnd
PCB_LAYER_ID m_Hole_Top_Layer
HOLE_ATTRIBUTE m_HoleAttribute
PCB_LAYER_ID m_DrillStart
BOARD_ITEM * m_ItemParent
PAD_DRILL_POST_MACHINING_MODE m_BackPostMachining
EDA_ANGLE m_Hole_Orient
An interface used to output 8 bit text in a convenient way.
Definition richio.h:291
Describe the page size and margins of a paper page on which to eventually print or plot.
Definition page_info.h:75
Base plotter engine class.
Definition plotter.h:133
A pure virtual class used to derive REPORTER objects from.
Definition reporter.h:71
static constexpr EDA_ANGLE ANGLE_0
Definition eda_angle.h:411
std::pair< PCB_LAYER_ID, PCB_LAYER_ID > DRILL_LAYER_PAIR
static const bool FILLED
Definition gr_basic.cpp:30
PCB_LAYER_ID
A quick note on layer IDs:
Definition layer_ids.h:56
@ B_Cu
Definition layer_ids.h:61
@ UNDEFINED_LAYER
Definition layer_ids.h:57
@ F_Cu
Definition layer_ids.h:60
PAD_DRILL_POST_MACHINING_MODE
Definition padstack.h:76
PLOT_FORMAT
The set of supported output plot formats.
Definition plotter.h:60
DRILL_LAYER_PAIR Pair() const
DRILL_SPAN(PCB_LAYER_ID aStartLayer, PCB_LAYER_ID aEndLayer, bool aIsBackdrill, bool aIsNonPlated)
PCB_LAYER_ID DrillEndLayer() const
PCB_LAYER_ID m_EndLayer
PCB_LAYER_ID TopLayer() const
PCB_LAYER_ID DrillStartLayer() const
PCB_LAYER_ID BottomLayer() const
PCB_LAYER_ID m_StartLayer
bool operator<(const DRILL_SPAN &aOther) const
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:683