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; // physically lowest layer reached by the hole
158 PCB_LAYER_ID m_Hole_Top_Layer; // physically highest layer reached by the hole
159 bool m_Hole_NotPlated; // hole not plated. Must be in a specific drill file or
160 // section.
161 HOLE_ATTRIBUTE m_HoleAttribute; // Attribute, used in Excellon drill file and to sort holes
162 // by type.
163 bool m_Hole_Filled; // True if the hole is filled
164 bool m_Hole_Capped; // True if the hole is capped
165 bool m_Hole_Top_Covered; // True if the hole is covered on the top layer
166 bool m_Hole_Bot_Covered; // True if the hole is covered on the bottom layer
167 bool m_Hole_Top_Plugged; // True if the hole is plugged on the top layer
168 bool m_Hole_Bot_Plugged; // True if the hole is plugged on the bottom layer
169 bool m_Hole_Top_Tented; // True if the hole is tented on the top layer
170 bool m_Hole_Bot_Tented; // True if the hole is tented on the bottom layer
171 bool m_IsBackdrill; // True if the hole is a backdrill
173 int m_FrontPostMachiningSize; // Post-machining size
174 int m_FrontPostMachiningDepth; // Post-machining depth
175 int m_FrontPostMachiningAngle; // Post-machining angle
177 int m_BackPostMachiningSize; // Post-machining size
178 int m_BackPostMachiningDepth; // Post-machining depth
179 int m_BackPostMachiningAngle; // Post-machining angle
180 PCB_LAYER_ID m_DrillStart; // Start layer for backdrills
181 PCB_LAYER_ID m_DrillEnd; // End layer for backdrills
182 std::optional<int> m_StubLength; // Stub length for backdrills
183
184
185};
186
187
188typedef std::pair<PCB_LAYER_ID, PCB_LAYER_ID> DRILL_LAYER_PAIR;
189
190
192{
194 {
197 m_IsBackdrill = false;
198 m_IsNonPlatedFile = false;
199 }
200
201 DRILL_SPAN( PCB_LAYER_ID aStartLayer, PCB_LAYER_ID aEndLayer, bool aIsBackdrill,
202 bool aIsNonPlated )
203 {
204 m_StartLayer = aStartLayer;
205 m_EndLayer = aEndLayer;
206 m_IsBackdrill = aIsBackdrill;
207 m_IsNonPlatedFile = aIsNonPlated;
208 }
209
211 {
212 // B_Cu (id=2) is numerically less than inner layers (id>=4), but is physically
213 // at the bottom of the stack. Use IsCopperLayerLowerThan for correct ordering.
215 }
216
221
223 {
224 return m_StartLayer;
225 }
226
228 {
229 return m_EndLayer;
230 }
231
233 {
235 }
236
237 bool operator<( const DRILL_SPAN& aOther ) const
238 {
239 if( TopLayer() != aOther.TopLayer() )
240 return TopLayer() < aOther.TopLayer();
241
242 if( BottomLayer() != aOther.BottomLayer() )
243 return BottomLayer() < aOther.BottomLayer();
244
245 if( m_IsBackdrill != aOther.m_IsBackdrill )
246 return m_IsBackdrill && !aOther.m_IsBackdrill;
247
249 return m_IsNonPlatedFile && !aOther.m_IsNonPlatedFile;
250
251 if( m_StartLayer != aOther.m_StartLayer )
252 return m_StartLayer < aOther.m_StartLayer;
253
254 return m_EndLayer < aOther.m_EndLayer;
255 }
256
261};
262
263
268{
269public:
270 DRILL_PRECISION( int l = 2, int r = 4 )
271 {
272 m_Lhs = l; m_Rhs = r;
273 }
274
275
277 {
278 wxString text;
279
280 text << m_Lhs << wxT( ":" ) << m_Rhs;
281 return text;
282 }
283
284 int m_Lhs; // Left digit number (integer value of coordinates)
285 int m_Rhs; // Right digit number (decimal value of coordinates)
286};
287
288
295{
296public:
297 enum ZEROS_FMT { // Zero format in coordinates
298 DECIMAL_FORMAT, // Floating point coordinates
299 SUPPRESS_LEADING, // Suppress leading zeros
300 SUPPRESS_TRAILING, // Suppress trailing zeros
301 KEEP_ZEROS // keep zeros
302 };
303
304 enum TYPE_FILE { // type of holes in file: PTH, NPTH, mixed
305 PTH_FILE, // PTH only, this is the default also for blind/buried holes
306 NPTH_FILE, // NPTH only
307 MIXED_FILE // PHT+NPTH (mixed)
308 };
309
311 {
312 }
313
320 void SetMergeOption( bool aMerge ) { m_merge_PTH_NPTH = aMerge; }
321
326
334 void SetPageInfo( const PAGE_INFO* aPageInfo ) { m_pageInfo = aPageInfo; }
335
344 {
345 m_mapFileFmt = aMapFmt;
346 }
347
357 bool CreateMapFilesSet( const wxString& aPlotDirectory, REPORTER* aReporter = nullptr );
358
407 bool GenDrillReportFile( const wxString& aFullFileName, REPORTER* aReporter = nullptr );
408
412 wxString GetDrillFileExt() const { return m_drillFileExtension; }
413
414protected:
426 bool genDrillMapFile( const wxString& aFullFileName, PLOT_FORMAT aFormat );
427
440 void buildHolesList( const DRILL_SPAN& aSpan, bool aGenerateNPTH_list );
441
442 int getHolesCount() const { return m_holeListBuffer.size(); }
443
453 bool plotDrillMarks( PLOTTER* aPlotter );
454
456 std::vector<DRILL_SPAN> getUniqueLayerPairs() const;
457
465
472 unsigned printToolSummary( FILE* out, TOOL_SUMMARY aSummary ) const;
473
479 const std::string layerPairName( DRILL_LAYER_PAIR aPair ) const;
480
485 const std::string layerName( PCB_LAYER_ID aLayer ) const;
486
496 virtual const wxString getDrillFileName( const DRILL_SPAN& aSpan, bool aNPTH,
497 bool aMerge_PTH_NPTH ) const;
498
499
506 virtual const wxString getProtectionFileName( const DRILL_SPAN& aSpan,
507 IPC4761_FEATURES aFeature ) const;
508
509
521 const wxString BuildFileFunctionAttributeString( const DRILL_SPAN& aSpan,
522 TYPE_FILE aHoleType,
523 bool aCompatNCdrill = false ) const;
524
525
526protected:
527 // Use derived classes to build a fully initialized GENDRILL_WRITER_BASE class.
529 {
530 m_pcb = aPcb;
531 m_conversionUnits = 1.0;
532 m_unitsMetric = true;
534 m_pageInfo = nullptr;
535 m_merge_PTH_NPTH = false;
537 }
538
540 wxString m_drillFileExtension; // .drl or .gbr, depending on format
541 bool m_unitsMetric; // true = mm, false = inches
542 ZEROS_FMT m_zeroFormat; // the zero format option for output file
543 DRILL_PRECISION m_precision; // The current coordinate precision (not
544 // used in decimal format).
545 double m_conversionUnits; // scaling factor to convert the board
546 // unites to Excellon/Gerber units (i.e
547 // inches or mm)
548 VECTOR2I m_offset; // Drill offset coordinates
549 bool m_merge_PTH_NPTH; // True to generate only one drill file
550 std::vector<HOLE_INFO> m_holeListBuffer; // Buffer containing holes
551 std::vector<DRILL_TOOL> m_toolListBuffer; // Buffer containing tools
552
553 PLOT_FORMAT m_mapFileFmt; // the format of the map drill file,
554 // if this map is needed
555 const PAGE_INFO* m_pageInfo; // the page info used to plot drill maps
556 // If NULL, use a A4 page format
557};
558
559#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:83
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:373
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
unsigned printToolSummary(FILE *out, TOOL_SUMMARY aSummary) const
Print m_toolListBuffer[] tools to aOut and returns total hole count.
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
TOOL_SUMMARY
Selects which subset of m_toolListBuffer a summary covers.
@ UNPLATED
Non-plated holes, excluding backdrills.
@ BACKDRILL
Backdrills, which are non-plated by construction.
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
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:72
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
bool IsCopperLayerLowerThan(PCB_LAYER_ID aLayerA, PCB_LAYER_ID aLayerB)
Return true if copper aLayerA is placed lower than aLayerB, false otherwise.
Definition layer_ids.h:830
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